Documentation
¶
Overview ¶
Package font reads font programs and returns glyph outlines and metrics. It knows nothing about PDF: a font is bytes in, outlines out.
Index ¶
- Variables
- func AddFontDir(dir string)
- func BidiLevels(text []rune, base int) []byte
- func BidiMirror(r rune) rune
- func BidiOrder(levels []byte) []int
- func Encoding(name string) *[256]string
- func IndexForName(name string) int
- func MacGlyphName(i int) string
- func MacRomanCode(r rune) int
- func NeedsBidi(s string) bool
- func NeedsShaping(s string) bool
- func RuneForName(name string) rune
- func StandardEncoding() *[256]string
- func StandardName(name string, serif, fixed, symbolic, bold, italic bool) string
- func StandardWidth(font, glyph string) float64
- func Upright(r rune) bool
- type Font
- func (f *Font) Advance(gid int) float32
- func (f *Font) BuiltinEncoding() *[256]string
- func (f *Font) DebugLayout() string
- func (f *Font) GIDForMacCode(code uint32) int
- func (f *Font) GIDForName(name string) int
- func (f *Font) GIDForRune(r rune) int
- func (f *Font) GIDForSymbolCode(code uint32) int
- func (f *Font) GlyphName(gid int) string
- func (f *Font) GlyphPath(gid int) *raster.Path
- func (f *Font) HasCmap() bool
- func (f *Font) HasGlyphNames() bool
- func (f *Font) NumGlyphs() int
- func (f *Font) Shape(text []rune, rtl bool) []Glyph
- func (f *Font) Shaped() bool
- type Glyph
- type Kind
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalid means the font program is damaged past use. ErrInvalid = errors.New("font: invalid font") // ErrUnsupported means the format is known but not handled. ErrUnsupported = errors.New("font: unsupported font") )
Errors returned by this package.
Functions ¶
func AddFontDir ¶
func AddFontDir(dir string)
AddFontDir adds a directory to the ones the system look-up searches. It has to be called before the first look-up to have any effect.
func BidiLevels ¶
BidiLevels is the embedding level of every character of one paragraph, the bidirectional algorithm of UAX #9 run end to end. base is 0 for a paragraph that runs left to right, 1 for one that runs right to left, and negative to take the direction from the text itself.
func BidiMirror ¶
BidiMirror is what rule L4 draws in place of a character that runs right to left, and the character itself where there is no other form.
func IndexForName ¶
IndexForName reads the gXX, GXX, glyphXX and cidXX conventions, which name a glyph by its number rather than by what it looks like.
func MacGlyphName ¶
MacGlyphName is the name a glyph has at index i of the standard Macintosh ordering, which is the order a TrueType font that has not rearranged its glyphs is in and what a version 1 post table means.
func MacRomanCode ¶
MacRomanCode returns the MacRoman code of a character, or -1.
func NeedsBidi ¶
NeedsBidi reports text with a character in it that does not run left to right, which is what the algorithm has anything to say about.
func NeedsShaping ¶
NeedsShaping reports text a font has to lay out itself: anything with a combining mark in it, and the scripts whose letters join, reorder or carry their vowels above and below. Everything else, Han and Kana among it, is one glyph a character and takes the shorter path.
func RuneForName ¶
RuneForName resolves a glyph name to a character through the Adobe Glyph List and the conventions that stand in for it: uniXXXX, uXXXX, a suffix after a dot, and a single character name.
func StandardEncoding ¶
func StandardEncoding() *[256]string
StandardEncoding is the encoding a simple font falls back to.
func StandardName ¶
StandardName maps a font name onto one of the fourteen, using the flags of the font descriptor to choose when the name says nothing. It returns "" for a name that cannot be resolved, which is never: Helvetica is last.
func StandardWidth ¶
StandardWidth returns the advance a base-14 font gives a glyph name, in units of a thousandth of an em, or -1.
Types ¶
type Font ¶
type Font struct {
Kind Kind
// Name is what the program calls itself, which is not the name the PDF
// font dictionary uses.
Name string
// Family is the family the program belongs to, which is the name a
// stylesheet asks for a font by.
Family string
// Weight is the usWeightClass of the program, 400 when it declares none,
// and Italic whether it is slanted.
Weight int
Italic bool
// UnitsPerEm is the glyph space of a TrueType font; a CFF or Type1 font
// carries a matrix instead.
UnitsPerEm int
// Matrix maps glyph space to text space, where one unit is the font size.
Matrix raster.Matrix
// Ascent and Descent are how far the em box reaches above and below the
// baseline, in text space, and default when the program declares neither.
Ascent, Descent float32
// XHeight is how tall a lower case x is, and SubOffset and SuperOffset
// how far the program puts a subscript below the baseline and a
// superscript above it, all in text space. Each is zero when the program
// says nothing, which is every program that is not an SFNT.
XHeight, SubOffset, SuperOffset float32
// CID is true for a CFF font keyed by CID rather than by name.
CID bool
// contains filtered or unexported fields
}
Font is a font program.
func Fallback ¶
Fallback returns a face the machine has that can draw r, nil when it has none. It is what a document in a script the base fourteen cannot draw needs.
func Standard ¶
Standard returns one of the fourteen fonts by its canonical name, or nil. One Font is kept per name and shared by every document that asks for it, which is what makes the base fourteen cost their glyph outlines once for the life of the process rather than once a document.
func SystemFont ¶
SystemFont returns a face the machine has for a family, and nil when it has none. A family with several weights and slants gives the nearest.
func (*Font) BuiltinEncoding ¶
BuiltinEncoding returns the code to glyph name table the program carries, or nil. Type1 fonts always have one and CFF fonts usually do.
func (*Font) DebugLayout ¶
DebugLayout reports what the layout tables of a font hold, for a comparison against another shaper.
func (*Font) GIDForMacCode ¶
GIDForMacCode looks a byte code up in a (1,0) Mac Roman character map.
func (*Font) GIDForName ¶
GIDForName returns the glyph with a name, or -1.
func (*Font) GIDForRune ¶
GIDForRune looks a Unicode value up in the font's character map, or -1.
func (*Font) GIDForSymbolCode ¶
GIDForSymbolCode looks a byte code up in a (3,0) symbol character map, which addresses the private use area with and without the F0 prefix.
func (*Font) GlyphPath ¶
GlyphPath returns the outline of a glyph in glyph space. The path is owned by the font and must not be modified.
A CID keyed CFF is addressed by CID rather than by glyph index, the convention FreeType uses; the charset maps it to the glyph inside.
func (*Font) HasCmap ¶
HasCmap reports whether the program carries a character map at all. One that does not is addressed by glyph index.
func (*Font) HasGlyphNames ¶
HasGlyphNames reports whether the program names its glyphs, which decides whether an encoding can be resolved through them.
Source Files
¶
- arabic_tables.go
- bidi.go
- bidi_tables.go
- brotli.go
- brotli_tables.go
- cff.go
- cffstrings_tables.go
- charstring.go
- decomp_tables.go
- encoding.go
- encodings_tables.go
- font.go
- glyf.go
- glyphlist_tables.go
- gpos.go
- gsub.go
- indic.go
- indic_tables.go
- macnames_tables.go
- mark_tables.go
- metrics_tables.go
- otlayout.go
- otmatch.go
- script.go
- sfnt.go
- shape.go
- stdfonts.go
- stdfonts_tables.go
- system.go
- t1charstring.go
- type1.go
- vertical.go
- vertical_tables.go
- woff.go
- woff2.go