|
|
Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
|
Manages font loading, caching, and lookup for text rendering. More...
#include "donner/svg/resources/FontManager.h"
Public Member Functions | |
| FontManager (Registry ®istry) | |
Construct a FontManager tied to the provided ECS registry. | |
| ~FontManager () | |
| Destructor. | |
| 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). | |
| void | setFontProvider (const FontFamilyProvider *provider) |
| Attach an external font provider (typically a FontCatalog) consulted during findFont() for family names not satisfied by a registered @font-face rule, before falling back to the embedded Public Sans font. | |
Static Public Member Functions | |
| static void | SetDefaultFontProvider (const FontFamilyProvider *provider) |
| Set the process-wide default font provider. | |
| static const FontFamilyProvider * | DefaultFontProvider () |
| Returns the current process-wide default font provider (may be nullptr). | |
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). |
|
static |
Set the process-wide default font provider.
Every FontManager constructed afterwards adopts it (existing instances are unaffected). The editor installs its FontCatalog here so document render paths that create their own FontManager resolve embedded and system fonts without threading the catalog through every call site.
The provider is borrowed, not owned, and must outlive all FontManagers that adopt it.
|
inline |
Attach an external font provider (typically a FontCatalog) consulted during findFont() for family names not satisfied by a registered @font-face rule, before falling back to the embedded Public Sans font.
The provider is borrowed, not owned, and must outlive this FontManager. Pass nullptr to detach.
Resolution order for findFont(family):
| 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. |