Donner 0.5.0
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::svg::TextBackend Class Referenceabstract

Abstract font backend for text rendering operations. More...

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

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

Classes

struct  BitmapGlyph
 Bitmap glyph data from color fonts (CBDT/CBLC). More...
struct  ShapedGlyph
 A single shaped glyph with advance and cluster info. More...
struct  ShapedRun
 Result of shaping a text range. More...

Public Member Functions

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< UnderlineMetricsunderlineMetrics (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< UnderlineMetricsstrikeoutMetrics (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< SubSuperMetricssubSuperMetrics (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 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< BitmapGlyphbitmapGlyph (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 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.

Detailed Description

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:


Class Documentation

◆ donner::svg::TextBackend::BitmapGlyph

struct donner::svg::TextBackend::BitmapGlyph

Bitmap glyph data from color fonts (CBDT/CBLC).

Collaboration diagram for donner::svg::TextBackend::BitmapGlyph:
[legend]
Class Members
double bearingX = 0 Horizontal offset from glyph origin.
double bearingY = 0 Vertical offset from baseline (positive = up).
int height = 0 Bitmap height in pixels.
vector< uint8_t > rgbaPixels RGBA pixel data (premultiplied alpha).
double scale = 1.0 Scale factor to apply.
int width = 0 Bitmap width in pixels.

◆ donner::svg::TextBackend::ShapedGlyph

struct donner::svg::TextBackend::ShapedGlyph

A single shaped glyph with advance and cluster info.

Class Members
uint32_t cluster = 0 Byte offset into the shaped text range.
float fontSizeScale = 1.0f < 1.0 for synthesized small-caps glyphs.
int glyphIndex = 0 Backend-specific glyph ID.
double xAdvance = 0 Nominal horizontal advance (without kerning).
double xKern = 0 Kerning adjustment to apply before this glyph.
double xOffset = 0 Horizontal offset (GPOS mark positioning; 0 for simple).
double yAdvance = 0 Nominal vertical advance (without kerning).
double yKern = 0 Kerning adjustment (vertical mode).
double yOffset = 0 Vertical offset (GPOS mark positioning; 0 for simple).

◆ donner::svg::TextBackend::ShapedRun

struct donner::svg::TextBackend::ShapedRun

Result of shaping a text range.

Collaboration diagram for donner::svg::TextBackend::ShapedRun:
[legend]
Class Members
vector< ShapedGlyph > glyphs

Member Function Documentation

◆ bitmapGlyph()

virtual std::optional< BitmapGlyph > donner::svg::TextBackend::bitmapGlyph ( FontHandle font,
int glyphIndex,
float scale ) const
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.

◆ crossSpanKern()

virtual double donner::svg::TextBackend::crossSpanKern ( FontHandle prevFont,
float prevSizePx,
FontHandle curFont,
float curSizePx,
uint32_t prevCodepoint,
uint32_t curCodepoint,
bool isVertical ) const
pure virtual

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

Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.

◆ fontVMetrics()

virtual FontVMetrics donner::svg::TextBackend::fontVMetrics ( FontHandle font) const
pure virtual

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

Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.

◆ glyphOutline()

virtual Path donner::svg::TextBackend::glyphOutline ( FontHandle font,
int glyphIndex,
float scale ) const
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.

◆ hasSmallCapsFeature()

virtual bool donner::svg::TextBackend::hasSmallCapsFeature ( FontHandle font) const
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.

◆ isBitmapOnly()

virtual bool donner::svg::TextBackend::isBitmapOnly ( FontHandle font) const
pure virtual

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

Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.

◆ isCursive()

virtual bool donner::svg::TextBackend::isCursive ( uint32_t codepoint) const
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.

◆ scaleForEmToPixels()

virtual float donner::svg::TextBackend::scaleForEmToPixels ( FontHandle font,
float pixelHeight ) const
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.

◆ scaleForPixelHeight()

virtual float donner::svg::TextBackend::scaleForPixelHeight ( FontHandle font,
float pixelHeight ) const
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.

◆ shapeRun()

virtual ShapedRun donner::svg::TextBackend::shapeRun ( FontHandle font,
float fontSizePx,
std::string_view spanText,
size_t byteOffset,
size_t byteLength,
bool isVertical,
FontVariant fontVariant,
bool forceLogicalOrder ) const
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.

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.

Implemented in donner::svg::TextBackendFull, and donner::svg::TextBackendSimple.

◆ strikeoutMetrics()

virtual std::optional< UnderlineMetrics > donner::svg::TextBackend::strikeoutMetrics ( FontHandle font) const
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.

◆ subSuperMetrics()

virtual std::optional< SubSuperMetrics > donner::svg::TextBackend::subSuperMetrics ( FontHandle font) const
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.

◆ underlineMetrics()

virtual std::optional< UnderlineMetrics > donner::svg::TextBackend::underlineMetrics ( FontHandle font) const
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.


The documentation for this class was generated from the following file: