Documentation
¶
Overview ¶
Package fontdb finds font files, resolves the family names documents ask for to faces that are available (directly, through metric-compatible substitutes, or through generic fallbacks), measures glyphs for text layout, and builds the subset font programs that get embedded.
Index ¶
- Constants
- Variables
- func Classify(name string) string
- func IsCJK(r rune) bool
- func Normalize(name string) string
- func SystemDirs() []string
- type DB
- type Face
- type Loaded
- func (l *Loaded) Advance(g uint16) float64
- func (l *Loaded) Bounds(g uint16) (r sfnt.Rect, ok bool)
- func (l *Loaded) CanSubset(ignoreFSType bool) bool
- func (l *Loaded) Embeddable() (embed, subset bool)
- func (l *Loaded) Glyph(r rune) (uint16, bool)
- func (l *Loaded) Has(r rune) bool
- func (l *Loaded) Math() *sfnt.Math
- func (l *Loaded) Outline(g uint16, pen sfnt.Pen) (ok bool)
- func (l *Loaded) Program(runes []rune, glyphs map[rune]uint16, noSubset, ignoreFSType bool) (data []byte, ok bool)
- func (l *Loaded) Size() int
- func (l *Loaded) UnitsPerEm() float64
- type Resolved
Constants ¶
const ( Sans = "sans-serif" Serif = "serif" Mono = "monospace" )
Generic families.
Variables ¶
var ErrNoGlyphs = errors.New("fontdb: font has no usable glyph data")
ErrNoGlyphs is returned for faces whose glyph data cannot be read.
Functions ¶
func IsCJK ¶
IsCJK reports whether r belongs to the East Asian scripts that Office lays out with the "ea" font: Han, kana, Hangul, Bopomofo, CJK symbols and punctuation, and the full-width forms.
func Normalize ¶
Normalize folds a family name for comparison: NFKC (full-width letters become ASCII), lower case, without spaces, hyphens and underscores.
func SystemDirs ¶
func SystemDirs() []string
SystemDirs returns the usual font directories of the platform.
Types ¶
type DB ¶
type DB struct {
Faces []*Face
// contains filtered or unexported fields
}
DB is a set of faces indexed by normalized family name.
func New ¶
New scans the fonts in fsys (when it is not nil), then those under dirs and, when system is true, the system directories. Scans of a directory are cached for the life of the process; fsys is scanned on every call.
func (*DB) Fallbacks ¶
Fallbacks returns faces to try, in order, for characters the resolved face lacks: CJK chains, the generic family, symbol fonts, then every other face so that a small private font directory is used completely.
func (*DB) Resolve ¶
Resolve maps a family request to a face: the family itself, a known substitute, a generic family of the same kind (serif, sans-serif, monospace; CJK chains when cjk is set), and finally any face at all.
func (*DB) ResolveMath ¶
ResolveMath maps a request for a formula font to a face with a MATH table: the family itself, then the other math fonts, then any face that has one. It returns nil when no available font has a MATH table.
type Face ¶
type Face struct {
Path string
Index int // index in a collection
Family string // English family name (typographic family when present)
Style string // English subfamily name
Weight int // OS/2 usWeightClass
Italic bool
Mono bool
CFF bool
Math bool // has a MATH table (a font for formulas)
// contains filtered or unexported fields
}
Face is one font in a file (a collection holds several).
func Match ¶
Match picks the face of a family closest to the requested weight and slant. synthBold / synthItalic report what the renderer has to fake.
type Loaded ¶
type Loaded struct {
Face *Face
Font *sfnt.Font
Data []byte // the whole file (the font's tables point into it)
// vertical metrics in em
Ascent, Descent float64
UnderlinePos, UnderTh float64
// CapHeight is the height of capital letters in em (estimated when
// the font does not say).
CapHeight float64
// contains filtered or unexported fields
}
Loaded is a face with its glyph data.
func (*Loaded) Bounds ¶
Bounds returns the bounding box of glyph g's outline in em (y up); ok is false for glyphs without an outline.
func (*Loaded) CanSubset ¶
CanSubset reports whether Program can drop unused glyphs (ignoreFSType as for Program).
func (*Loaded) Embeddable ¶
Embeddable reports whether the license bits allow embedding, and subsetting.
func (*Loaded) Outline ¶ added in v0.1.1
Outline draws the outline of glyph g with pen, in font units (y up); ok is false when the glyph cannot be read.
func (*Loaded) Program ¶
func (l *Loaded) Program(runes []rune, glyphs map[rune]uint16, noSubset, ignoreFSType bool) (data []byte, ok bool)
Program builds the font program to embed for the given characters: a subset holding just their glyphs, or the whole font (fonts whose license forbids subsetting or whose outlines cannot be subset, or all when noSubset is set), with a cmap for exactly those characters. glyphs maps more characters (private use ones) to glyphs that no character maps to, such as the larger variants of a math font's delimiters. The OS/2 fsType and the copyright and license strings of the font carry over. ok is false when the license forbids embedding; ignoreFSType embeds (and subsets) such fonts anyway, for callers that hold the rights to.
func (*Loaded) UnitsPerEm ¶
UnitsPerEm returns the size of the em in font units.