sfnttest

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sfnttest builds a font file byte by byte.

A test that needs a real font needs either a binary nobody can review or a font whose every byte the test wrote itself, and this is the second. It is a package rather than a test file because two packages need it — the parser and subsetter in internal/sfnt, and the PDF backend that embeds what they produce — and a font builder copied into both would be two fonts that drift.

Four glyphs, one of them a composite, and a cmap in whichever of the two supported formats the caller asks for. It is enough to exercise the table directory, the metric tail, the composite closure and the glyph renumbering, and small enough that a failure names a byte rather than a font.

Index

Constants

View Source
const (
	UnitsPerEm = 1000
	NumGlyphs  = 4
)

The design grid and the glyph count of the font this package builds.

View Source
const (
	GlyphNotdef = 0
	GlyphA      = 1
	GlyphB      = 2
	GlyphComp   = 3
)

The glyphs: 0 is .notdef and empty, 1 and 2 are simple triangles, 3 is a composite of 1 and 2 — which is what makes the subset's closure and its renumbering testable at all. GlyphA is reached by 'A', GlyphB by 'B' and GlyphComp by 'Ä'.

Variables

View Source
var Advances = [NumGlyphs]uint16{500, 600, 700, 650}

Advances is the advance width of each glyph, in font units.

Functions

func CFFFont

func CFFFont() []byte

CFFFont builds a font whose outlines are CFF charstrings rather than glyf entries — an `.otf`, in the shape a reader meets one.

The CFF table's contents are a placeholder, and deliberately: nothing in figure interprets charstrings. What such a font exercises is the half that is figure's own — that the format is recognised, that it is reported as unsubsettable, and that the PDF wrapper written around it is the CID font a CFF program belongs in rather than the one a glyf program does.

func Cmap4

func Cmap4() []byte

Cmap4 maps 'A' and 'B' to glyphs 1 and 2 and 'Ä' to the composite, in the segmented format every Windows font carries.

func Cmap12

func Cmap12() []byte

Cmap12 is the same mapping in the flat format a font needs to reach past the Basic Multilingual Plane, plus one code point that actually is past it.

func Font

func Font(cmapTable []byte, numH int) []byte

Font assembles the whole file. numH is how many full horizontal metrics the hmtx table carries: fewer than the glyph count exercises the tail every reader has to expand, which is the one part of the format that is easy to read as though it were an array.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL