Donner 0.5.0
Embeddable browser-grade SVG2 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]
Collaboration diagram for donner::svg::TextBackendSimple:
[legend]

Public Member Functions

 TextBackendSimple (FontManager &fontManager, Registry &registry)
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

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< TextBackend::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()

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.

◆ fontVMetrics()

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

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

Implements donner::svg::TextBackend.

◆ glyphOutline()

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.

◆ 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.

◆ 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()

TextBackend::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.

◆ 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 files: