Abstract font backend for text rendering operations. More...
#include "donner/svg/text/TextBackend.h"
Classes | |
| struct | BitmapGlyph |
| Bitmap glyph data from color fonts (CBDT/CBLC). More... | |
| struct | BitmapGlyphMetrics |
| Validated bitmap cost and placement metadata; not an authentication or cache identity token. More... | |
| struct | ShapedGlyph |
| A single shaped glyph with advance and cluster info. More... | |
| struct | ShapedRun |
| Result of shaping a text range. More... | |
| struct | ShapingContext |
| A byte range of the span text that surrounds a shaped range. More... | |
Public Member Functions | |
| virtual bool | requiresTrustedFontData () const |
| Whether this backend may consume only fonts whose byte provenance is trusted. | |
| virtual FontVMetrics | fontVMetrics (FontHandle font) const =0 |
| Vertical metrics (ascent, descent, lineGap) in font design units. | |
| virtual float | scaleForPixelHeight (FontHandle font, float pixelHeight) const =0 |
| Scale factor: font design units → pixels, normalized to ascent−descent height. This is stbtt_ScaleForPixelHeight semantics. | |
| virtual float | scaleForEmToPixels (FontHandle font, float pixelHeight) const =0 |
| Scale factor: em units → pixels. Differs from scaleForPixelHeight when ascent−descent != unitsPerEm. This is the correct scale for CSS font-size. | |
| virtual std::optional< UnderlineMetrics > | underlineMetrics (FontHandle font) const =0 |
| Underline position/thickness from the 'post' table, in font design units. Returns std::nullopt if the table is missing. | |
| virtual std::optional< UnderlineMetrics > | strikeoutMetrics (FontHandle font) const =0 |
| Strikeout position/thickness from the OS/2 table, in font design units. Returns std::nullopt if the table is missing. | |
| virtual std::optional< SubSuperMetrics > | subSuperMetrics (FontHandle font) const =0 |
| Sub/superscript Y offsets from the OS/2 table, in font design units. Returns std::nullopt if the table is missing. | |
| virtual Path | glyphOutline (FontHandle font, int glyphIndex, float scale) const =0 |
Extract a glyph outline as a Path. Coordinates are in font units scaled by scale, with Y flipped for SVG's y-down convention. | |
| virtual Path | glyphOutline (FontHandle font, int glyphIndex, float scale, bool allowSyntheticOblique) const |
| Extract an outline with per-glyph synthetic-oblique permission. | |
| virtual bool | isBitmapOnly (FontHandle font) const =0 |
| Returns true if the font is bitmap-only (no vector outlines). | |
| virtual bool | isCursive (uint32_t codepoint) const =0 |
| Returns true if letter-spacing should be suppressed for this codepoint (cursive/connected scripts like Arabic). Simple backends return false. | |
| virtual bool | hasSmallCapsFeature (FontHandle font) const =0 |
| Returns true if the font has a native OpenType small-caps feature (smcp). If false, the engine synthesizes small-caps via uppercase + reduced size. | |
| 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 std::optional< BitmapGlyph > | bitmapGlyph (FontHandle font, int glyphIndex, float scale) const =0 |
| Extract a bitmap glyph (CBDT/CBLC color emoji). Returns std::nullopt if the glyph is not a bitmap. Simple backends always return std::nullopt. | |
| virtual ShapedRun | shapeRun (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, FontVariant fontVariant, bool forceLogicalOrder) const =0 |
| Shape a range of text, producing glyph IDs with advances and kerning. | |
| virtual 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 |
| Shape a range with the resolved vertical text orientation. | |
| virtual ShapedRun | shapeRunNoKerning (FontHandle font, float fontSizePx, std::string_view spanText, size_t byteOffset, size_t byteLength, bool isVertical, FontVariant fontVariant, bool forceLogicalOrder) const |
| Shape text with kerning disabled. Backends that cannot selectively disable kerning retain their normal shaping behavior. | |
| virtual 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 |
| Shape orientation-aware text with kerning disabled. | |
| virtual 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 |
Shape [byteOffset, byteOffset + byteLength) as one part of context, such as one face's share of a chunk drawn with several faces. | |
| virtual double | crossSpanKern (FontHandle prevFont, float prevSizePx, FontHandle curFont, float curSizePx, uint32_t prevCodepoint, uint32_t curCodepoint, bool isVertical) const =0 |
| Compute cross-span kerning between the last codepoint of the previous span and the first codepoint of the current span. | |
| virtual double | crossSpanKern (FontHandle prevFont, float prevSizePx, FontHandle curFont, float curSizePx, uint32_t prevCodepoint, uint32_t curCodepoint, bool isVertical, TextOrientation textOrientation) const |
| Compute cross-span kerning with the resolved vertical orientation. | |
| virtual double | crossSpanKern (FontHandle previousFont, float previousSize, FontHandle currentFont, float currentSize, uint32_t previousCodepoint, uint32_t currentCodepoint, bool vertical, TextOrientation orientation, const ShapingContext &context) const |
| Resolve a visual neighboring pair inside one shared directional shaping context. | |
| virtual double | crossSpanKernNoKerning (FontHandle, float, FontHandle, float, uint32_t, uint32_t, bool) const |
| Compute cross-span kerning with kerning disabled. | |
Abstract font backend for text rendering operations.
Abstracts all font-engine-specific calls (stb_truetype, HarfBuzz+FreeType) behind a uniform interface. Used by TextEngine for layout and by renderers for glyph outlines and font metrics.
Implementations:
| struct donner::svg::TextBackend::BitmapGlyph |
Bitmap glyph data from color fonts (CBDT/CBLC).
| struct donner::svg::TextBackend::ShapedRun |
Result of shaping a text range.
| Class Members | ||
|---|---|---|
| optional< bool > | backward | Known source-group progression; absent when a backend leaves it implicit in its clusters. |
| vector< ShapedGlyph > | glyphs | |
| struct donner::svg::TextBackend::ShapingContext |
A byte range of the span text that surrounds a shaped range.
| Class Members | ||
|---|---|---|
| size_t | byteLength = 0 | Length of the context. Backend-defined shaping properties detected for the whole context. |
| size_t | byteOffset = 0 | Start of the context within the span text. |
| Detected | detected | Filled on first use, so the ranges of one context detect its properties once. |
| optional< bool > | rightToLeft | Resolved horizontal embedding parity; overrides every guessed shaping direction. |
| bool | suppressOptionalSubstitutions = false | Analysis-only shaping suppresses optional substitutions to propose emergency boundaries. |
| bool | suppressRligForAnalysis = false | Analysis-only rlig comparison for font-dependent lam-alef candidate groups. |
| WorkBudget * | work = nullptr | Aliases a planner-owned budget alive through all synchronous fragment shaping calls. |
|
pure virtual |
Extract a bitmap glyph (CBDT/CBLC color emoji). Returns std::nullopt if the glyph is not a bitmap. Simple backends always return std::nullopt.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Decode only after independently revalidating admitted metrics and the RGBA byte limit. This bounds converted RGBA storage, not every internal decoder allocation.
| font | Font to decode. |
| glyphIndex | Glyph within the font. |
| scale | Requested scale. |
| admitted | Previously queried cost and placement metadata. |
| maximumRgbaBytes | Maximum allowed converted RGBA storage bytes. |
Reimplemented in donner::svg::TextBackendFull.
|
inlinevirtual |
Query bounded bitmap metadata without materializing bitmap pixels.
| font | Font to query. |
| glyphIndex | Glyph within the font. |
| scale | Requested scale. |
Reimplemented in donner::svg::TextBackendFull.
|
pure virtual |
Compute cross-span kerning between the last codepoint of the previous span and the first codepoint of the current span.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Compute cross-span kerning with the resolved vertical orientation.
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Resolve a visual neighboring pair inside one shared directional shaping context.
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Vertical metrics (ascent, descent, lineGap) in font design units.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Extract a glyph outline as a Path. Coordinates are in font units scaled by scale, with Y flipped for SVG's y-down convention.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Extract an outline with per-glyph synthetic-oblique permission.
| font | Face whose glyph is extracted. |
| glyphIndex | Glyph index in the face. |
| scale | Font-unit to pixel scale. |
| allowSyntheticOblique | Whether a synthesized oblique transform may be applied. |
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Returns true if the font has a native OpenType small-caps feature (smcp). If false, the engine synthesizes small-caps via uppercase + reduced size.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Returns true if the font is bitmap-only (no vector outlines).
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Returns true if letter-spacing should be suppressed for this codepoint (cursive/connected scripts like Arabic). Simple backends return false.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Whether this backend may consume only fonts whose byte provenance is trusted.
Reimplemented in donner::svg::TextBackendSimple.
|
pure virtual |
Scale factor: em units → pixels. Differs from scaleForPixelHeight when ascent−descent != unitsPerEm. This is the correct scale for CSS font-size.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Scale factor: font design units → pixels, normalized to ascent−descent height. This is stbtt_ScaleForPixelHeight semantics.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
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.
| font | Font to shape with. |
| fontSizePx | Font size in pixels. |
| spanText | Full span text (UTF-8). |
| byteOffset | Start of the range to shape within spanText. |
| byteLength | Length of the range to shape. |
| isVertical | True for vertical writing mode. |
| fontVariant | Font variant (Normal or SmallCaps). |
| forceLogicalOrder | If true, return glyphs sorted by cluster (DOM order) rather than visual order. Used for per-character positioned RTL text. |
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Shape a range with the resolved vertical text orientation.
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
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 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.
| font | Font to shape with. |
| fontSizePx | Font size in pixels. |
| spanText | Full span text (UTF-8). |
| context | Range of spanText that contains the shaped range. |
| byteOffset | Start of the range to shape within spanText. |
| byteLength | Length of the range to shape. |
| isVertical | True for vertical writing mode. |
| textOrientation | Resolved vertical text orientation. |
| fontVariant | Font variant (Normal or SmallCaps). |
| kerning | False to shape with kerning disabled. |
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Shape text with kerning disabled. Backends that cannot selectively disable kerning retain their normal shaping behavior.
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
inlinevirtual |
Shape orientation-aware text with kerning disabled.
Reimplemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Strikeout position/thickness from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Sub/superscript Y offsets from the OS/2 table, in font design units. Returns std::nullopt if the table is missing.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.
|
pure virtual |
Underline position/thickness from the 'post' table, in font design units. Returns std::nullopt if the table is missing.
Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.