|
|
Donner 0.5.0
Embeddable browser-grade SVG2 engine
|
Manages font loading, caching, and lookup for text rendering. More...
#include "donner/svg/resources/FontManager.h"
Classes | |
| struct | FontFaceComponent |
| struct | LoadedFontComponent |
Public Member Functions | |
| FontManager (Registry ®istry) | |
| FontManager (const FontManager &)=delete | |
| FontManager & | operator= (const FontManager &)=delete |
| FontManager (FontManager &&)=delete | |
| FontManager & | operator= (FontManager &&)=delete |
| void | addFontFace (const css::FontFace &face) |
| Register a @font-face declaration. | |
| void | setGenericFamilyMapping (std::string_view genericName, std::string_view realFamily) |
| Register a mapping from a CSS generic family name (serif, sans-serif, monospace, cursive, fantasy) to a real font family name registered via addFontFace(). | |
| FontHandle | findFont (std::string_view family) |
| Find or load a font matching the given family name. | |
| FontHandle | findFont (std::string_view family, int weight) |
| Find or load a font matching the given family name and weight. | |
| FontHandle | findFont (std::string_view family, int weight, int style, int stretch) |
| Find or load a font matching the given family name, weight, style, and stretch. | |
| FontHandle | loadFontData (std::span< const uint8_t > data) |
| Load a font from raw TTF/OTF/WOFF data. | |
| std::span< const uint8_t > | fontData (FontHandle handle) const |
| Get the raw font data bytes for a handle. | |
| size_t | numFaces () const |
| Get the number of registered @font-face rules. | |
| std::string_view | faceFamilyName (size_t index) const |
| Get the family name of a registered @font-face rule by index. | |
| FontHandle | fallbackFont () |
| Get the handle for the embedded fallback font (Public Sans). | |
Manages font loading, caching, and lookup for text rendering.
FontManager is the shared font infrastructure used by both the Skia and TinySkia backends. It handles:
FontManager uses entt entities to store font data, with one entity per registered @font-face rule or directly-loaded font. Text backends can cache parsed backend objects directly on the same entity.
| void donner::svg::FontManager::addFontFace | ( | const css::FontFace & | face | ) |
Register a @font-face declaration.
Sources are resolved lazily on first findFont() call for the corresponding family name.
| face | The parsed @font-face rule. |
| std::string_view donner::svg::FontManager::faceFamilyName | ( | size_t | index | ) | const |
Get the family name of a registered @font-face rule by index.
| index | Index into the registered faces (0 to numFaces()-1). |
| FontHandle donner::svg::FontManager::findFont | ( | std::string_view | family | ) |
Find or load a font matching the given family name.
Resolution order:
| family | Font family name to look up. |
| FontHandle donner::svg::FontManager::findFont | ( | std::string_view | family, |
| int | weight ) |
Find or load a font matching the given family name and weight.
| family | Font family name to look up. |
| weight | CSS font-weight value (100-900, 400=normal, 700=bold). |
| FontHandle donner::svg::FontManager::findFont | ( | std::string_view | family, |
| int | weight, | ||
| int | style, | ||
| int | stretch ) |
Find or load a font matching the given family name, weight, style, and stretch.
| family | Font family name to look up. |
| weight | CSS font-weight value (100-900, 400=normal, 700=bold). |
| style | CSS font-style value (0=normal, 1=italic, 2=oblique). |
| stretch | CSS font-stretch value (1-9, 5=normal, matching FontStretch enum). |
| std::span< const uint8_t > donner::svg::FontManager::fontData | ( | FontHandle | handle | ) | const |
Get the raw font data bytes for a handle.
This is useful for backends (like Skia) that need to create their own font objects from the raw data.
| handle | A valid FontHandle. |
| FontHandle donner::svg::FontManager::loadFontData | ( | std::span< const uint8_t > | data | ) |
Load a font from raw TTF/OTF/WOFF data.
The data is copied internally. The font is not associated with any family name; callers should use findFont() for name-based lookup.
| data | Raw font file bytes (TTF, OTF, or WOFF 1.0). |
| void donner::svg::FontManager::setGenericFamilyMapping | ( | std::string_view | genericName, |
| std::string_view | realFamily ) |
Register a mapping from a CSS generic family name (serif, sans-serif, monospace, cursive, fantasy) to a real font family name registered via addFontFace().
This allows findFont("sans-serif") to resolve to the specified family.
| genericName | The CSS generic family name (case-insensitive). |
| realFamily | The real family name to resolve to. |