Donner SVG main
0.8.0 · 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 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]

Public Member Functions

 TextBackendFull (FontManager &fontManager, Registry &registry)
 Construct a full text backend using the provided font manager and ECS 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< UnderlineMetrics > underlineMetrics (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< UnderlineMetrics > strikeoutMetrics (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< SubSuperMetrics > subSuperMetrics (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.
Path glyphOutline (FontHandle font, int glyphIndex, float scale, bool allowSyntheticOblique) const override
 Extract an outline with per-glyph synthetic-oblique permission.
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< BitmapGlyph > bitmapGlyph (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.
std::optional< BitmapGlyphMetrics > bitmapGlyphMetrics (FontHandle font, int glyphIndex, float scale) const override
 Query bounded bitmap metadata without materializing bitmap pixels.
std::optional< BitmapGlyph > bitmapGlyph (FontHandle font, int glyphIndex, float scale, const BitmapGlyphMetrics &admitted, std::size_t maximumRgbaBytes) const override
 Decode only after independently revalidating admitted metrics and the RGBA byte limit. This bounds converted RGBA storage, not every internal decoder allocation.
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.
ShapedRun shapeRun (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, TextOrientation textOrientation, FontVariant fontVariant, bool forceLogicalOrder) const override
 Shape a range with the resolved vertical text orientation.
ShapedRun shapeRunNoKerning (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, FontVariant fontVariant, bool forceLogicalOrder) const override
 Shape text with kerning disabled. Backends that cannot selectively disable kerning retain their normal shaping behavior.
ShapedRun shapeRunNoKerning (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, TextOrientation textOrientation, FontVariant fontVariant, bool forceLogicalOrder) const override
 Shape orientation-aware text with kerning disabled.
ShapedRun shapeRunInContext (FontHandle font, float fontSizePx, std::string_view spanText, const ShapingContext &context, size_t byteOffset, size_t byteLength, bool isVertical, TextOrientation textOrientation, FontVariant fontVariant, bool kerning) const override
 Shape [byteOffset, byteOffset + byteLength) as one part of context, such as one face's share of a chunk drawn with several faces.
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.
double crossSpanKern (FontHandle prevFont, float prevSizePx, FontHandle curFont, float curSizePx, uint32_t prevCodepoint, uint32_t curCodepoint, bool isVertical, TextOrientation textOrientation) const override
 Compute cross-span kerning with the resolved vertical orientation.
bool embeddedBitmapLoadingDisabledForTesting (FontHandle font) const
 Whether the HarfBuzz/FreeType glyph-load flags suppress embedded bitmap strikes.
std::size_t detectedContextBytesForTesting () const
 Total bytes of shaping context scanned to detect direction and script, a test seam that bounds the work shaping a chunk's ranges in context does.
std::size_t shapedBytesForTesting () const
 Total range bytes actually supplied to shaping, including fallback and analysis calls.
std::size_t delegatedVerticalOriginCallsForTesting () const
 Number of admitted untrusted-font vertical-origin parent callbacks.
std::size_t delegatedVerticalAdvanceCallsForTesting () const
 Number of admitted untrusted-font vertical-advance parent callbacks.
double crossSpanKern (FontHandle previousFont, float previousSize, FontHandle currentFont, float currentSize, uint32_t previousCodepoint, uint32_t currentCodepoint, bool vertical, TextOrientation orientation, const ShapingContext &context) const override
 Resolve a visual neighboring pair inside one shared directional shaping context.
Public Member Functions inherited from donner::svg::TextBackend
virtual bool requiresTrustedFontData () const
 Whether this backend may consume only fonts whose byte provenance is trusted.
virtual double crossSpanKernNoKerning (FontHandle, float, FontHandle, float, uint32_t, uint32_t, bool) const
 Compute cross-span kerning with kerning disabled.

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() [1/2]

std::optional< 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.

◆ bitmapGlyph() [2/2]

std::optional< BitmapGlyph > donner::svg::TextBackendFull::bitmapGlyph ( FontHandle font,
int glyphIndex,
float scale,
const BitmapGlyphMetrics & admitted,
std::size_t maximumRgbaBytes ) const
overridevirtual

Decode only after independently revalidating admitted metrics and the RGBA byte limit. This bounds converted RGBA storage, not every internal decoder allocation.

Parameters
fontFont to decode.
glyphIndexGlyph within the font.
scaleRequested scale.
admittedPreviously queried cost and placement metadata.
maximumRgbaBytesMaximum allowed converted RGBA storage bytes.

Reimplemented from donner::svg::TextBackend.

◆ bitmapGlyphMetrics()

std::optional< BitmapGlyphMetrics > donner::svg::TextBackendFull::bitmapGlyphMetrics ( FontHandle font,
int glyphIndex,
float scale ) const
overridevirtual

Query bounded bitmap metadata without materializing bitmap pixels.

Parameters
fontFont to query.
glyphIndexGlyph within the font.
scaleRequested scale.

Reimplemented from donner::svg::TextBackend.

◆ crossSpanKern() [1/3]

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.

◆ crossSpanKern() [2/3]

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

Compute cross-span kerning with the resolved vertical orientation.

Reimplemented from donner::svg::TextBackend.

◆ crossSpanKern() [3/3]

double donner::svg::TextBackendFull::crossSpanKern ( FontHandle previousFont,
float previousSize,
FontHandle currentFont,
float currentSize,
uint32_t previousCodepoint,
uint32_t currentCodepoint,
bool vertical,
TextOrientation orientation,
const ShapingContext & context ) const
overridevirtual

Resolve a visual neighboring pair inside one shared directional shaping context.

Reimplemented from donner::svg::TextBackend.

◆ embeddedBitmapLoadingDisabledForTesting()

bool donner::svg::TextBackendFull::embeddedBitmapLoadingDisabledForTesting ( FontHandle font) const
nodiscard

Whether the HarfBuzz/FreeType glyph-load flags suppress embedded bitmap strikes.

This narrow test seam verifies that document-provided fonts cannot make HarfBuzz metric callbacks decode embedded bitmap strikes.

◆ fontVMetrics()

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

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

Implements donner::svg::TextBackend.

◆ glyphOutline() [1/2]

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.

◆ glyphOutline() [2/2]

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

Extract an outline with per-glyph synthetic-oblique permission.

Parameters
fontFace whose glyph is extracted.
glyphIndexGlyph index in the face.
scaleFont-unit to pixel scale.
allowSyntheticObliqueWhether a synthesized oblique transform may be applied.
Returns
The glyph outline; native styles and variable axes are always preserved.

Reimplemented from 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() [1/2]

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.

◆ shapeRun() [2/2]

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

Shape a range with the resolved vertical text orientation.

Reimplemented from donner::svg::TextBackend.

◆ shapeRunInContext()

ShapedRun donner::svg::TextBackendFull::shapeRunInContext ( FontHandle font,
float fontSizePx,
std::string_view spanText,
const ShapingContext & context,
size_t byteOffset,
size_t byteLength,
bool isVertical,
TextOrientation textOrientation,
FontVariant fontVariant,
bool kerning ) const
overridevirtual

Shape [byteOffset, byteOffset + byteLength) as one part of context, such as one face's share of a chunk drawn with several faces.

A context-aware backend shapes the range with the surrounding characters as pre- and post-context and picks its direction, script and language as follows:

  • A range with no script of its own (punctuation, spaces, symbols) takes the context's direction, script and language, so neutrals mirror and order like their neighbors. When such a range contains decimal digits in a horizontal context, it keeps the context's script and language but runs left to right, as numbers do in right-to-left text.
  • A strong left-to-right range inside a vertically shaped context is shaped vertically.
  • A strong right-to-left range keeps its own horizontal direction.

A context no longer than the range adds nothing, and the range is shaped as by shapeRun. Other backends shape the range alone. Glyph clusters are byte offsets into spanText, as for shapeRun.

Parameters
fontFont to shape with.
fontSizePxFont size in pixels.
spanTextFull span text (UTF-8).
contextRange of spanText that contains the shaped range.
byteOffsetStart of the range to shape within spanText.
byteLengthLength of the range to shape.
isVerticalTrue for vertical writing mode.
textOrientationResolved vertical text orientation.
fontVariantFont variant (Normal or SmallCaps).
kerningFalse to shape with kerning disabled.

Reimplemented from donner::svg::TextBackend.

◆ shapeRunNoKerning() [1/2]

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

Shape text with kerning disabled. Backends that cannot selectively disable kerning retain their normal shaping behavior.

Reimplemented from donner::svg::TextBackend.

◆ shapeRunNoKerning() [2/2]

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

Shape orientation-aware text with kerning disabled.

Reimplemented from 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 file: