Donner SVG main
0.8.0 · 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::svg::TextBackendSimple Class Referencefinal

stb_truetype-based font backend. More...

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

Inheritance diagram for donner::svg::TextBackendSimple:
[legend]

Public Member Functions

 TextBackendSimple (FontManager &fontManager, Registry &registry)
 Construct a simple text backend using the provided font manager and ECS registry.
bool requiresTrustedFontData () const override
 Whether this backend may consume only fonts whose byte provenance is trusted.
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.
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.
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 std::optional< BitmapGlyphMetrics > bitmapGlyphMetrics (FontHandle font, int glyphIndex, float scale) const
 Query bounded bitmap metadata without materializing bitmap pixels.
virtual std::optional< BitmapGlyph > bitmapGlyph (FontHandle font, int glyphIndex, float scale, const BitmapGlyphMetrics &admitted, std::size_t maximumRgbaBytes) const
 Decode only after independently revalidating admitted metrics and the RGBA byte limit. This bounds converted RGBA storage, not every internal decoder allocation.
virtual double crossSpanKernNoKerning (FontHandle, float, FontHandle, float, uint32_t, uint32_t, bool) const
 Compute cross-span kerning with kerning disabled.

Detailed Description

stb_truetype-based font backend.

Provides font metrics, glyph outlines, and table-derived data using stb_truetype. No GSUB/GPOS shaping, no bitmap glyph support, no cursive script detection.

Member Function Documentation

◆ bitmapGlyph()

std::optional< BitmapGlyph > donner::svg::TextBackendSimple::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() [1/3]

double donner::svg::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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.

◆ fontVMetrics()

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

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

Implements donner::svg::TextBackend.

◆ glyphOutline() [1/2]

Path donner::svg::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::isBitmapOnly ( FontHandle font) const
overridevirtual

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

Implements donner::svg::TextBackend.

◆ isCursive()

bool donner::svg::TextBackendSimple::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.

◆ requiresTrustedFontData()

bool donner::svg::TextBackendSimple::requiresTrustedFontData ( ) const
inlineoverridevirtual

Whether this backend may consume only fonts whose byte provenance is trusted.

Reimplemented from donner::svg::TextBackend.

◆ scaleForEmToPixels()

float donner::svg::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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::TextBackendSimple::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: