Documentation
¶
Overview ¶
Package fonttest builds small fonts for tests: a TrueType writer (so no licensed font binary has to be committed), WOFF and WOFF2 encoders and a few ready-made fonts whose glyphs are plain boxes with distinct widths and heights, which makes rendered text easy to recognise and compare.
Nothing outside tests imports this package, so it adds nothing to the binaries.
Index ¶
- Variables
- func Adv(c rune) int
- func Assemble(flavor uint32, tables map[string][]byte) []byte
- func Checksum(b []byte) uint32
- func StoredBrotli(b []byte) []byte
- func TransformGlyf(glyf, loca, head, maxp []byte, overlap bool) (out []byte, xMins []int)
- func WOFF(sfnt []byte, compress bool) []byte
- func WOFF2(sfnt []byte, o Options) []byte
- type Axis
- type Component
- type Font
- type Glyph
- type GlyphVar
- type HVAR
- type Lig
- type Options
- type Pt
- type Table
- type Tuple
- type VarSpec
Constants ¶
This section is empty.
Variables ¶
var ( //go:embed testdata/boxes.woff2 BoxesWOFF2 []byte //go:embed testdata/icons.woff2 IconsWOFF2 []byte )
BoxesWOFF2 and IconsWOFF2 are Boxes("Boxy", "Regular", 400, false) and Icons("Icony") as WOFF2 files compressed by a real brotli encoder (see TestGenerateFixtures).
Functions ¶
func StoredBrotli ¶
StoredBrotli wraps b in a valid brotli stream made of uncompressed meta-blocks.
func TransformGlyf ¶
TransformGlyf produces the WOFF2 transformed glyf table for glyf/loca and the xMin of every glyph.
Types ¶
type Font ¶
type Font struct {
Family, Style string
UPM int
Ascent int // hhea / typo ascender
Descent int // positive distance below the baseline
LineGap int
XHeight, Cap int
Weight int
Italic bool
Mono bool
Glyphs []Glyph // index 0 is .notdef
Cmap map[rune]int
Ligatures []Lig
// Kern pairs as GPOS-less legacy 'kern' table entries (left gid, right gid, value in font units).
Kern map[[2]int]int
// ShortLoca selects the short loca format when the glyph data allows it.
ShortLoca bool
// ExtraTables are added verbatim (e.g. fvar and gvar of a variable font).
ExtraTables map[string][]byte
}
Font describes a TrueType font.
func Boxes ¶
Boxes returns a font with a glyph for every printable ASCII character plus U+00E9 (a composite of 'e' and an accent), U+0416 and U+4E2D (so unicode range tests have distinct scripts). unitsPerEm is 1000, ascent 800, descent 200. Glyph height depends on the character: 'x'-height-like for lowercase, taller for capitals and digits. weight changes the horizontal thickness only through the advance (bold faces are 8% wider) so the face can be told apart.
func Icons ¶
Icons returns an icon font in the style of Material Icons: private use code points (U+E900..) draw icons, and ligatures turn the icon names ("home", "arrow_back", ...) into the same glyphs. The letters themselves draw nothing and have a tiny advance, as in the real font.
func VarBoxes ¶
VarBoxes is Boxes with a weight axis (wght 100..900, default 400): at the bold end (normalised +1) every glyph's right side moves right by 160 units and the advance grows by 160; at the light end (-1) the advance shrinks by 100. Deltas are given for all points, so the glyph outlines scale linearly with the coordinate. withHVAR chooses between advance deltas in HVAR and in the phantom points of gvar.
func (*Font) AddVariations ¶
AddVariations turns the font into a variable font.
type Glyph ¶
type Glyph struct {
Contours [][]Pt
Comps []Component
Adv int
Instr []byte // TrueType instructions (opaque bytes) of a simple glyph
}
Glyph is one glyph: simple (Contours) or composite (Comps).
type GlyphVar ¶
type GlyphVar struct {
Tuples []Tuple
}
GlyphVar is the variation data of one glyph.
type HVAR ¶
type HVAR struct {
Regions [][][3]float64 // [region][axis] = start, peak, end
Deltas [][]int // [glyph][region]
}
HVAR is a minimal horizontal metrics variation table: one region per entry of Regions (axis triples), advance deltas per glyph and region.
type Options ¶
type Options struct {
// Transform applies the glyf/loca transform (and the hmtx transform when
// the font allows it); otherwise the null transform is used.
Transform bool
// Brotli compresses the stream; nil uses uncompressed meta-blocks.
Brotli func([]byte) []byte
// Overlap sets the OVERLAP_SIMPLE bit of every simple glyph (option flag 1).
Overlap bool
}
Options for WOFF2.
type Table ¶
Table is one sfnt table.
func ParseTables ¶
ParseTables splits an sfnt into its tables in directory order.
type Tuple ¶
type Tuple struct {
Peak []float64 // embedded peak (normalised coordinates)
Start, End []float64 // intermediate region (both or none)
Points []int // touched points; nil means all points (with the four phantom points)
DX, DY []int // deltas of the listed points (or of all points)
}
Tuple is one gvar tuple variation of a glyph.