Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::fonts::SfntFont Class Reference

Validated, allocation-bounded index for one sfnt font. More...

#include "donner/base/fonts/SfntUtils.h"

Classes

struct  TableRecord
 A table location validated against the original font byte span. More...
struct  GlyphOutlineComplexity
 Allocation and CPU-work ceiling proved for one glyph outline. More...

Public Member Functions

 SfntFont (SfntFont &&) noexcept
SfntFont & operator= (SfntFont &&) noexcept
 SfntFont (const SfntFont &)=delete
SfntFont & operator= (const SfntFont &)=delete
std::optional< std::span< const uint8_t > > findTable (std::span< const uint8_t > data, std::string_view tag) const
 Find a validated table in data.
bool hasTable (std::string_view tag) const
 Return true when the validated directory contains tag.
size_t numTables () const
 Number of validated directory entries.
size_t numGlyphs () const
 Number of glyphs with retained outline bounds, or zero when validation was unavailable.
std::optional< GlyphOutlineComplexityglyphOutlineComplexity (size_t glyphIndex) const
 Return the validation-time outline bound for a glyph.
size_t retainedBytes () const
 Exact dynamic bytes retained by the sorted directory and outline indexes.

Static Public Member Functions

static std::optional< SfntFont > Validate (std::span< const uint8_t > data, const SfntValidationOptions &options={}, SfntValidationMetrics *metrics=nullptr)
 Validate and index data.

Detailed Description

Validated, allocation-bounded index for one sfnt font.

Table records are sorted once, making lookup O(log T). TrueType glyf fonts also retain a validated loca index and are accepted only when every compound dependency is acyclic, at most kMaximumCompoundGlyphDepth frames deep, and within the expanded vertex and outline-work caps. The work model includes repeated and shared descendants, simple point decoding, component transforms, and stb_truetype's repeated prefix copies.

CFF and non-variable CFF2 outlines also receive bounded CharString validation. CFF tables must still be consumed by an exact-span parser such as FreeType; stb_truetype's CFF parser uses a synthetic 512 MiB span and must not be initialized for untrusted CFF fonts.


Class Documentation

◆ donner::fonts::SfntFont::TableRecord

struct donner::fonts::SfntFont::TableRecord

A table location validated against the original font byte span.

Class Members
uint32_t length = 0
uint32_t offset = 0
uint32_t tag = 0

◆ donner::fonts::SfntFont::GlyphOutlineComplexity

struct donner::fonts::SfntFont::GlyphOutlineComplexity

Allocation and CPU-work ceiling proved for one glyph outline.

Class Members
uint32_t maximumVertices = 0
uint32_t work = 0

Member Function Documentation

◆ findTable()

std::optional< std::span< const uint8_t > > donner::fonts::SfntFont::findTable ( std::span< const uint8_t > data,
std::string_view tag ) const

Find a validated table in data.

data must be the same immutable byte stream passed to Validate.

Parameters
dataOriginal sfnt byte stream.
tagFour-byte table tag.
Returns
A bounded table span, or std::nullopt when absent.

◆ Validate()

std::optional< SfntFont > donner::fonts::SfntFont::Validate ( std::span< const uint8_t > data,
const SfntValidationOptions & options = {},
SfntValidationMetrics * metrics = nullptr )
static

Validate and index data.

Parameters
dataComplete sfnt byte stream.
Returns
A cached index on success, or std::nullopt for malformed or over-limit input.

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