stb_truetype-based font backend. More...
#include "donner/svg/text/TextBackendSimple.h"
Public Member Functions | |
| TextBackendSimple (FontManager &fontManager, Registry ®istry) | |
| 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. | |
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.
|
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.
|
overridevirtual |
Compute cross-span kerning between the last codepoint of the previous span and the first codepoint of the current span.
Implements donner::svg::TextBackend.
|
overridevirtual |
Compute cross-span kerning with the resolved vertical orientation.
Reimplemented from donner::svg::TextBackend.
|
overridevirtual |
Resolve a visual neighboring pair inside one shared directional shaping context.
Reimplemented from donner::svg::TextBackend.
|
overridevirtual |
Vertical metrics (ascent, descent, lineGap) in font design units.
Implements donner::svg::TextBackend.
|
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.
|
overridevirtual |
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 from donner::svg::TextBackend.
|
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.
|
overridevirtual |
Returns true if the font is bitmap-only (no vector outlines).
Implements donner::svg::TextBackend.
|
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.
|
inlineoverridevirtual |
Whether this backend may consume only fonts whose byte provenance is trusted.
Reimplemented from donner::svg::TextBackend.
|
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.
|
overridevirtual |
Scale factor: font design units → pixels, normalized to ascent−descent height. This is stbtt_ScaleForPixelHeight semantics.
Implements donner::svg::TextBackend.
|
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.
| 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. |
Implements donner::svg::TextBackend.
|
overridevirtual |
Shape a range with the resolved vertical text orientation.
Reimplemented from donner::svg::TextBackend.
|
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 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 from donner::svg::TextBackend.
|
overridevirtual |
Shape text with kerning disabled. Backends that cannot selectively disable kerning retain their normal shaping behavior.
Reimplemented from donner::svg::TextBackend.
|
overridevirtual |
Shape orientation-aware text with kerning disabled.
Reimplemented from donner::svg::TextBackend.
|
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.
|
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.
|
overridevirtual |
Underline position/thickness from the 'post' table, in font design units. Returns std::nullopt if the table is missing.
Implements donner::svg::TextBackend.