Help us shape the future of Go! Take the 2026 Go Developer Survey

typeface

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package typeface reads the font files a deliverable ships and embeds: what each face is, how wide its text runs, whether it draws a character, and the forms Word (obfuscated TrueType) and PowerPoint (Embedded OpenType) embed, each compressed once per compile.

Index

Constants

View Source
const Symbols = "•–◦·☐☒□■❦❧◆—"

Symbols are the marks lfm sets: bullets, checkboxes, ornaments. Each falls back to one the font has.

Variables

This section is empty.

Functions

func Checkboxes

func Checkboxes(f *Family) (open, done, font string)

Checkboxes are the open and done marks of task lists, and the font that draws them: the family's when it has them, else Arial, whose WGL4 set has □ and ■ in every app (LibreOffice maps it to Liberation Sans).

func EOT

func EOT(face *Face) ([]byte, error)

EOT wraps a TrueType font as Embedded OpenType 2.1, uncompressed: the .fntdata a .pptx embeds. PowerPoint for Windows and Mac show the deck in its fonts from it; the header repeats the font's OS/2 and name facts.

func FontFaces

func FontFaces(prefix string, families ...*Family) string

FontFaces are the CSS @font-face rules of the families' faces, each family once, loaded from prefix plus the file's base name.

func Glyph

func Glyph(f *Family, marks ...rune) string

Glyph picks the first of the marks the family's regular face draws.

func Obfuscate

func Obfuscate(data []byte, key string) []byte

Obfuscate prepares a font for embedding in a .docx as ECMA-376 Part 1, 17.8.1 requires: the first 32 bytes XORed with the key's bytes in reverse order.

func Tables

func Tables(data []byte) (map[string][]byte, error)

Tables maps a font's table tags to their bytes.

Types

type Face

type Face struct {
	File          string // path below the deliverable folder
	Family        string // typographic family, as apps list it
	Weight        int    // 400 regular, 700 bold
	Italic        bool
	Embeddable    bool    // OS/2 fsType allows embedding in documents
	Natural       float64 // Word's single line height in em: (winAscent + winDescent) / unitsPerEm
	Typo          float64 // the typographic line in em, which Keynote and LibreOffice read
	AvgChar       float64 // average advance of running text in em
	TabularDigits bool    // 0-9 share one advance
	Serif         bool    // OS/2 family class 1-7
	Data          []byte
	Variable      bool // an fvar table: Word and Pages need static fonts
	// contains filtered or unexported fields
}

Face is one font file of the project: what it is and the metrics the layout and the design checks need.

func Read

func Read(file string, data []byte) (*Face, error)

Read parses a font file; file is its path for messages.

func (*Face) Covers

func (f *Face) Covers(r rune) bool

Covers reports whether the face draws r.

func (*Face) Has

func (f *Face) Has(r rune) bool

Has reports whether the face draws one of lfm's marks.

func (*Face) Slot

func (f *Face) Slot() string

Slot is where a face goes in a family: the four faces Word knows.

func (*Face) Width

func (f *Face) Width(s string, size float64) float64

Width is the advance of s at size in points, as apps set it without kerning: a little wider than kerned text, so a fit it allows is real. A character the face lacks counts as wide as an "M".

type Family

type Family struct {
	Name  string
	Faces map[string]*Face // by slot: Regular, Bold, Italic, BoldItalic
}

Family is the faces of one font family a deliverable ships.

func (*Family) Face

func (f *Family) Face(bold, italic bool) *Face

Face is the face a run in bold and italic is set in, the regular one where the family lacks it.

func (*Family) Regular

func (f *Family) Regular() *Face

Regular is the family's regular face; nil when it has none.

type Folder

type Folder struct {
	Dir      string
	Families map[string]*Family
	Licences map[string][]byte
}

Folder is the fonts a deliverable ships in its fonts folder: the families by name and the licence files that travel with them.

func Load

func Load(p project.Project, dir string, report Report) Folder

Load reads every font and licence file in dir, a folder below the project; a face lfm cannot embed is reported and left out.

func (Folder) Want

func (f Folder) Want(name, role, file string, line int, report Report) *Family

Want is the family a theme names for role (text or heading), reported at the concept's Look line when it is missing or lacks a face.

type Pack

type Pack struct {
	// contains filtered or unexported fields
}

Pack compresses each embedded face once per compile: every file of a set embeds the same fonts, and deflating them is most of a build.

func NewPack

func NewPack() *Pack

NewPack is an empty pack.

func (*Pack) EOT

func (p *Pack) EOT(face *Face) (*Packed, error)

EOT is the face as Embedded OpenType, deflated, as a .pptx embeds it.

func (*Pack) Obfuscated

func (p *Pack) Obfuscated(face *Face, key string) *Packed

Obfuscated is the face obfuscated with key and deflated, as a .docx embeds it.

type Packed

type Packed = zipx.Packed

Packed is a font part deflated once for every file that embeds it.

type Report

type Report func(file string, line int, fatal bool, message, hint string)

Report receives a finding about a font file: an error when fatal.

Jump to

Keyboard shortcuts

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