Class FontRasterizer

Class Documentation

class FontRasterizer

CPU font operations owned by Engine.

Loading copies the font bytes; copies retain the same face and serialize its native state. Returned values own their storage and survive the rasterizer. No graphics context or resource provider is used.

Public Functions

FontRasterizer() = default

Construct an empty face.

Boolean conversion is false; properties are default, coverage false, metrics/rasterize absent and kerning zero.

inline explicit operator bool() const noexcept

Declaration: [[nodiscard]]

Return whether a native CPU face is retained.

Copies share serialized native state.

FontRasterProperties properties() const

Declaration: [[nodiscard]]

Return owned metadata under the shared face lock, or defaults for an empty handle.

bool covers(char32_t scalar) const

Declaration: [[nodiscard]]

Return whether this face maps a valid Unicode scalar to a nonzero glyph.

Empty handles, surrogates and out-of-range values return false; no fallback family is selected.

std::optional<FontRasterMetrics> metrics(FontRasterSize size) const

Declaration: [[nodiscard]]

Return copied raster-pixel metrics, or nullopt for empty/unsupported size.

Fixed-strike bitmap_scale describes downscaling. Shared face/cache access is serialized; allocation errors may propagate.

std::optional<FontRasterGlyph> rasterize(char32_t scalar, FontRasterSize size, FontRasterOptions options = {}) const

Declaration: [[nodiscard]]

Return owned top-to-bottom pixels and metrics.

Empty/invalid scalar, unsupported size/options or native raster failure returns nullopt; allocation failures propagate. A missing character uses the face’s native missing glyph: call covers() for explicit fallback policy. No graphics/provider calls occur.

float kerning(char32_t left, char32_t right, FontRasterSize size, bool unfitted = false) const

Declaration: [[nodiscard]]

Return horizontal pair adjustment in pixels.

Empty/invalid scalars, unsupported size, absent kerning or native failure return zero. unfitted requests unrounded native kerning; the shared face is serialized.

Public Static Functions

static FontRasterizer load(std::span<const unsigned char> bytes, std::uint32_t face_index = 0, std::uint32_t named_instance = 0, bool unicode_only = false)

Declaration: [[nodiscard]]

Copy bytes and open a retained CPU face, independent of the source buffer.

Empty/oversized bytes, face_index above 65535 or named_instance above 32767 reject. Invalid fonts/charmaps throw failed_operation; allocation errors propagate.

Parameters:
  • face_index – Zero-based collection face.

  • named_instance – Zero for default, otherwise native one-based named variation.

  • unicode_only – Require a Unicode character map when true; otherwise retain an existing map or try Apple Roman.

static FontRasterizer load(const Font &font, FontStyle style = {}, bool unicode_only = false)

Declaration: [[nodiscard]]

Open the selected primary family’s closest style, copying retained bytes.

Empty Font rejects. No discovery/path reopening occurs; named variation defaults to zero.

static FontRasterizer load(const FontFace &face, bool unicode_only = false)

Declaration: [[nodiscard]]

Open and copy this face’s bytes and collection index; the source Font need survive only the call.

Native named instance defaults to zero; errors follow byte loading.

static std::vector<FontVariation> variations(std::span<const unsigned char> bytes, std::uint32_t face_index = 0)

Declaration: [[nodiscard]]

Return owned named variations ordered by weight/width, empty when none are available.

Opens a temporary copied face; invalid source/index and allocation failures propagate.