Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
SfntUtils.h File Reference
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <span>
#include <string_view>
#include "donner/base/fonts/CffOutlineComplexity.h"
Include dependency graph for SfntUtils.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::fonts::SfntValidationOptions
 Caller-selected limits for one sfnt validation. More...
struct  donner::fonts::SfntValidationMetrics
 Work and limiting outcome observed while validating one sfnt. More...
class  donner::fonts::SfntFont
 Validated, allocation-bounded index for one sfnt font. More...
struct  donner::fonts::SfntFont::TableRecord
 A table location validated against the original font byte span. More...
struct  donner::fonts::SfntFont::GlyphOutlineComplexity
 Allocation and CPU-work ceiling proved for one glyph outline. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

uint16_t donner::fonts::ReadBe16 (const uint8_t *p)
 Read a 16-bit big-endian unsigned integer from p.
uint32_t donner::fonts::ReadBe32 (const uint8_t *p)
 Read a 32-bit big-endian unsigned integer from p.
uint32_t donner::fonts::SfntTag (std::string_view tag)
 Convert a four-byte sfnt tag to its big-endian integer representation.
uint32_t donner::fonts::SfntTableChecksum (std::span< const uint8_t > data, uint32_t initial=0)
 Compute an sfnt table-directory checksum: the sum, modulo 2^32, of the table's big-endian 32-bit words, with a final partial word padded with zero bytes.
bool donner::fonts::ValidateSfnt (std::span< const uint8_t > data)
 Return true when data passes the bounded sfnt and outline validation policy.
std::optional< std::span< const uint8_t > > donner::fonts::FindSfntTable (std::span< const uint8_t > data, std::string_view tag)
 Return a bounded sfnt table by its four-byte tag.

Variables

constexpr size_t donner::fonts::kMaximumSfntTables = 4096
 Maximum number of entries accepted in an sfnt table directory.
constexpr size_t donner::fonts::kMaximumCompoundGlyphDepth = 32
 Maximum number of glyph frames reached while expanding a TrueType compound glyph.
constexpr size_t donner::fonts::kMaximumCompoundComponentRecords = 65536
 Maximum component records stored or expanded by one accepted TrueType font.
constexpr size_t donner::fonts::kMaximumSimpleGlyphPoints = 16 * 1024 * 1024
 Maximum simple-glyph points examined while validating one TrueType font.
constexpr size_t donner::fonts::kMaximumExpandedGlyphVertices = 1024 * 1024
 Maximum vertices that stb_truetype may allocate while expanding one TrueType glyph.
constexpr size_t donner::fonts::kMaximumGlyphOutlineWork = 16 * 1024 * 1024
 Maximum decode, transform, and prefix-copy work allowed for one TrueType glyph outline.

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

Function Documentation

◆ FindSfntTable()

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

Return a bounded sfnt table by its four-byte tag.

This compatibility helper performs a fresh, explicitly bounded validation. Repeated callers should retain a donner::fonts::SfntFont and call donner::fonts::SfntFont::findTable instead.

◆ SfntTableChecksum()

uint32_t donner::fonts::SfntTableChecksum ( std::span< const uint8_t > data,
uint32_t initial = 0 )

Compute an sfnt table-directory checksum: the sum, modulo 2^32, of the table's big-endian 32-bit words, with a final partial word padded with zero bytes.

Checksums of consecutive chunks add up, so a long table can be summed in pieces by passing each piece's result as the next piece's initial; every piece but the last must be a multiple of four bytes long.

Parameters
dataTable bytes, or the next chunk of them.
initialSum of the preceding chunks of the same table.
Returns
The checksum of everything summed so far.