Donner 0.5.0
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::svg::TextBackendFull Class Referencefinal

HarfBuzz + FreeType font backend. More...

#include "donner/svg/text/TextBackendFull.h"

Inheritance diagram for donner::svg::TextBackendFull:
[legend]
Collaboration diagram for donner::svg::TextBackendFull:
[legend]

Classes

struct  HbFontEntry
 Internal storage for a HarfBuzz font object backed by FreeType. The hb_font_t is created via hb_ft_font_create_referenced(), which holds a reference to the FT_Face. We also hold our own reference (from FT_New_Memory_Face). Destruction order: destroy hb_font first (decrefs FT_Face from 2->1), then FT_Done_Face (decrefs 1->0, frees). More...

Public Member Functions

 TextBackendFull (FontManager &fontManager, Registry &registry)
 TextBackendFull (const TextBackendFull &)=delete
TextBackendFull & operator= (const TextBackendFull &)=delete
FontVMetrics fontVMetrics (FontHandle font) const override
 Vertical metrics (ascent, descent, lineGap) in font design units.
float scaleForPixelHeight (FontHandle font, float pixelHeight) const override
 Scale factor: font design units → pixels, normalized to ascent−descent height. This is stbtt_ScaleForPixelHeight semantics.
float scaleForEmToPixels (FontHandle font, float pixelHeight) const override
 Scale factor: em units → pixels. Differs from scaleForPixelHeight when ascent−descent != unitsPerEm. This is the correct scale for CSS font-size.
std::optional< UnderlineMetricsunderlineMetrics (FontHandle font) const override
 Underline position/thickness from the 'post' table, in font design units. Returns std::nullopt if the table is missing.
std::optional< UnderlineMetricsstrikeoutMetrics (FontHandle font) const override
 Strikeout position/thickness from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.
std::optional< SubSuperMetricssubSuperMetrics (FontHandle font) const override
 Sub/superscript Y offsets from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.
Path glyphOutline (FontHandle font, int glyphIndex, float scale) const override
 Extract a glyph outline as a Path. Coordinates are in font units scaled by scale, with Y flipped for SVG's y-down convention.
bool isBitmapOnly (FontHandle font) const override
 Returns true if the font is bitmap-only (no vector outlines).
bool isCursive (uint32_t codepoint) const override
 Returns true if letter-spacing should be suppressed for this codepoint (cursive/connected scripts like Arabic). Simple backends return false.
bool hasSmallCapsFeature (FontHandle font) const override
 Returns true if the font has a native OpenType small-caps feature (smcp). If false, the engine synthesizes small-caps via uppercase + reduced size.
std::optional< BitmapGlyphbitmapGlyph (FontHandle font, int glyphIndex, float scale) const override
 Extract a bitmap glyph (CBDT/CBLC color emoji). Returns std::nullopt if the glyph is not a bitmap. Simple backends always return std::nullopt.
ShapedRun shapeRun (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, FontVariant fontVariant, bool forceLogicalOrder) const override
 Shape a range of text, producing glyph IDs with advances and kerning.
double crossSpanKern (FontHandle prevFont, float prevSizePx, FontHandle curFont, float curSizePx, uint32_t prevCodepoint, uint32_t curCodepoint, bool isVertical) const override
 Compute cross-span kerning between the last codepoint of the previous span and the first codepoint of the current span.

Detailed Description

HarfBuzz + FreeType font backend.

Provides full OpenType shaping (GSUB/GPOS), FreeType glyph outlines, cursive script detection, native small-caps queries, and bitmap glyph extraction (CBDT/CBLC).

Member Function Documentation

◆ bitmapGlyph()

std::optional< TextBackend::BitmapGlyph > donner::svg::TextBackendFull::bitmapGlyph ( FontHandle font,
int glyphIndex,
float scale ) const
overridevirtual

Extract a bitmap glyph (CBDT/CBLC color emoji). Returns std::nullopt if the glyph is not a bitmap. Simple backends always return std::nullopt.

Implements donner::svg::TextBackend.

◆ crossSpanKern()

double donner::svg::TextBackendFull::crossSpanKern ( FontHandle prevFont,
float prevSizePx,
FontHandle curFont,
float curSizePx,
uint32_t prevCodepoint,
uint32_t curCodepoint,
bool isVertical ) const
overridevirtual

Compute cross-span kerning between the last codepoint of the previous span and the first codepoint of the current span.

Returns
Kern adjustment in pixels (added to pen position).

Implements donner::svg::TextBackend.

◆ fontVMetrics()

FontVMetrics donner::svg::TextBackendFull::fontVMetrics ( FontHandle font) const
overridevirtual

Vertical metrics (ascent, descent, lineGap) in font design units.

Implements donner::svg::TextBackend.

◆ glyphOutline()

Path donner::svg::TextBackendFull::glyphOutline ( FontHandle font,
int glyphIndex,
float scale ) const
overridevirtual

Extract a glyph outline as a Path. Coordinates are in font units scaled by scale, with Y flipped for SVG's y-down convention.

Implements donner::svg::TextBackend.

◆ hasSmallCapsFeature()

bool donner::svg::TextBackendFull::hasSmallCapsFeature ( FontHandle font) const
overridevirtual

Returns true if the font has a native OpenType small-caps feature (smcp). If false, the engine synthesizes small-caps via uppercase + reduced size.

Implements donner::svg::TextBackend.

◆ isBitmapOnly()

bool donner::svg::TextBackendFull::isBitmapOnly ( FontHandle font) const
overridevirtual

Returns true if the font is bitmap-only (no vector outlines).

Implements donner::svg::TextBackend.

◆ isCursive()

bool donner::svg::TextBackendFull::isCursive ( uint32_t codepoint) const
overridevirtual

Returns true if letter-spacing should be suppressed for this codepoint (cursive/connected scripts like Arabic). Simple backends return false.

Implements donner::svg::TextBackend.

◆ scaleForEmToPixels()

float donner::svg::TextBackendFull::scaleForEmToPixels ( FontHandle font,
float pixelHeight ) const
overridevirtual

Scale factor: em units → pixels. Differs from scaleForPixelHeight when ascent−descent != unitsPerEm. This is the correct scale for CSS font-size.

Implements donner::svg::TextBackend.

◆ scaleForPixelHeight()

float donner::svg::TextBackendFull::scaleForPixelHeight ( FontHandle font,
float pixelHeight ) const
overridevirtual

Scale factor: font design units → pixels, normalized to ascent−descent height. This is stbtt_ScaleForPixelHeight semantics.

Implements donner::svg::TextBackend.

◆ shapeRun()

TextBackend::ShapedRun donner::svg::TextBackendFull::shapeRun ( FontHandle font,
float fontSizePx,
std::string_view spanText,
size_t byteOffset,
size_t byteLength,
bool isVertical,
FontVariant fontVariant,
bool forceLogicalOrder ) const
overridevirtual

Shape a range of text, producing glyph IDs with advances and kerning.

The full span text and a byte range within it are provided so context-aware backends (HarfBuzz) can use surrounding context for GSUB/GPOS.

Parameters
fontFont to shape with.
fontSizePxFont size in pixels.
spanTextFull span text (UTF-8).
byteOffsetStart of the range to shape within spanText.
byteLengthLength of the range to shape.
isVerticalTrue for vertical writing mode.
fontVariantFont variant (Normal or SmallCaps).
forceLogicalOrderIf true, return glyphs sorted by cluster (DOM order) rather than visual order. Used for per-character positioned RTL text.
Returns
Shaped glyphs with advances, kerning, and cluster mapping.

Implements donner::svg::TextBackend.

◆ strikeoutMetrics()

std::optional< UnderlineMetrics > donner::svg::TextBackendFull::strikeoutMetrics ( FontHandle font) const
overridevirtual

Strikeout position/thickness from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.

Implements donner::svg::TextBackend.

◆ subSuperMetrics()

std::optional< SubSuperMetrics > donner::svg::TextBackendFull::subSuperMetrics ( FontHandle font) const
overridevirtual

Sub/superscript Y offsets from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.

Implements donner::svg::TextBackend.

◆ underlineMetrics()

std::optional< UnderlineMetrics > donner::svg::TextBackendFull::underlineMetrics ( FontHandle font) const
overridevirtual

Underline position/thickness from the 'post' table, in font design units. Returns std::nullopt if the table is missing.

Implements donner::svg::TextBackend.


The documentation for this class was generated from the following files: