Documentation
¶
Overview ¶
Package sfnt reads the font tables an embedded PDF font needs and builds a subset containing only the glyphs a document uses.
It reads tables and moves bytes. It does not map characters to glyphs: that mapping is the engine's, through the metrics it measured with, and a second implementation of it in the renderer is how a renderer comes to draw glyphs the printout never measured.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseNames ¶
ParseNames returns the best string for each name ID in a name table.
Windows records in English win, then any Windows record, then Macintosh, then Unicode. A face carrying several localised strings for one ID must not resolve to whichever happens to come last in the file.
Types ¶
type Font ¶
type Font struct {
// Tables holds the raw table data, by four-character tag.
Tables map[string][]byte
// TrueType reports whether the outlines are in a glyf table.
// A font with PostScript outlines carries CFF instead and cannot
// be embedded as the TrueType font program this package writes.
TrueType bool
Upem float64
NumGlyphs int
XMin, YMin, XMax, YMax int16
// Ascender is positive and Descender negative,
// whichever way the face wrote them. See readHhea.
Ascender, Descender int16
CapHeight int16
ItalicAngle float64
FixedPitch bool
WeightClass uint16
// PostScriptName is name ID 6, which is the name a PDF
// font dictionary carries, falling back to the family
// with its spaces removed the way a PostScript name is formed.
PostScriptName string
// contains filtered or unexported fields
}
Font is a parsed font file: its tables, and the values a PDF font descriptor asks for.
func (*Font) Advance ¶
Advance returns a glyph's advance width in font units, read from hmtx.
The last entry of hmtx covers every glyph after it, which is how a font with a run of equal-width glyphs at the end saves space.
func (*Font) SideBearing ¶
SideBearing returns a glyph's left side bearing in font units.
func (*Font) Subset ¶
Subset builds a font program holding only the given glyphs.
A glyph's position in glyphs is its index in the result, which is what lets a PDF address it by that index through an identity CID to glyph map. Composite glyphs pull their components in and are rewritten to point at the components' new indices; those extra glyphs land after the requested ones, so no requested glyph moves.