Documentation
¶
Overview ¶
Package cff reads and subsets CFF font programs: the Type 2 outlines of OpenType fonts with a "CFF " table, and those PDF files embed.
Index ¶
- Variables
- func EncodeDict(entries []DictEntry, replace func(DictEntry) ([]int, bool)) []byte
- func Index(items [][]byte) []byte
- func ParseDict(b []byte) map[int][]float64
- func Prune(data []byte, keep map[int]bool) ([]byte, error)
- func ReadIndex(b []byte, pos int) ([][]byte, int, error)
- func Subset(data []byte, keep map[int]bool) (out []byte, order []int, err error)
- type DictEntry
- type Font
Constants ¶
This section is empty.
Variables ¶
var ErrTooLong = errors.New("cff: charstrings run too long")
ErrTooLong is returned by Subset and Prune for a font whose charstrings run too long to follow, or leave too many operands on the stack.
var StandardEncoding = [256]string{}/* 256 elements not displayed */
StandardEncoding is Adobe's standard encoding (PDF 32000-1 Annex D): glyph name per code.
var StandardStrings = []string{} /* 391 elements not displayed */
StandardStrings are the 391 predefined CFF strings (CFF spec Appendix A).
Functions ¶
func EncodeDict ¶
cffEncodeDict writes entries back; replace returns new integer operands for an entry (written as 5-byte integers) or false to keep it as it was.
func ParseDict ¶
cffParseDict parses a CFF DICT into operator → operands. ParseDict reads a DICT into operator → operands (12 x is 1200+x).
func Prune ¶
Prune is Subset that keeps the glyph numbers: the glyphs not in keep (nor glyph 0 or a component of a kept seac accent) stay in the font, empty, so that tables which refer to glyphs by number (GSUB, GPOS, hmtx) stay valid. The subroutines only they call become a bare return.
func Subset ¶
Subset returns a CFF font program that holds only the glyphs in keep, glyph 0 and the components of seac accents, renumbered in their original order; order[newGID] is the old GID. Subroutines the kept glyphs do not call become a bare return (their numbers must not change). The charset keeps each glyph's name or CID, FDSelect is rebuilt, and a custom encoding is replaced by StandardEncoding: its codes point at old GIDs, and browsers map characters through the cmap anyway.
Dropping glyphs instead of emptying them matters for CFF: its CharStrings INDEX has an offset per glyph, and in a CJK font those offsets alone are far larger than the few glyphs a document uses (TrueType's loca has no such cost in WOFF2, which rebuilds it).
When a charstring cannot be followed (arithmetic operators, a subroutine number out of range) every subroutine is kept and only the glyphs are dropped. Charstrings that run longer than a font's size explains (subroutines that call subroutines many times over) are an error: ErrTooLong.
Types ¶
type DictEntry ¶
DictEntry is one operator of a DICT with its operands, kept as written.
func DictEntries ¶
type Font ¶
type Font struct {
Data []byte
NumGlyphs int
IsCID bool
Charset []int // gid → SID (or CID)
NameToGID map[string]int
CIDToGID map[int]int
Encoding map[int]int // code → gid (built-in encoding)
FontMatrix [6]float64
Strings []string
// Notice and Copyright strings of the Top DICT (the only license text a
// bare CFF program carries).
Notice, Copyright string
}
Font holds what the converters need from a CFF font program (bare, as PDF embeds it, or the CFF table of an OpenType font): glyph count, glyph names (or CIDs) per GID, the built-in encoding and the font matrix.