const ( NameIDCopyright NameID = 0 NameIDFontFamily = 1 NameIDFontSubfamily = 2 NameIDUniqueSubfamilyID = 3 NameIDFontFullName = 4 NameIDNameTableVersion = 5 NameIDPostscriptName = 6 NameIDTrademarkNotice = 7 NameIDManufacturerName = 8 NameIDDesignerName = 9 NameIDFontDescription = 10 NameIDFontVendorURL = 11 NameIDFontDesignerURL = 12 NameIDFontLicense = 13 NameIDFontLicenseURL = 14 NameIDPreferredFamily = 16 NameIDPreferredSubfamily = 17 NameIDCompatibleName = 18 NameIDSampleText = 19 )
func NewFace(f *Font, opts *Options) font.Face
NewFace returns a new font.Face for the given Font.
A Font represents a Truetype font.
type Font struct {
// contains filtered or unexported fields
}
func Parse(ttf []byte) (font *Font, err error)
Parse returns a new Font for the given TTF or TTC data.
For TrueType Collections, the first font in the collection is parsed.
func (f *Font) Bounds(scale fixed.Int26_6) fixed.Rectangle26_6
Bounds returns the union of a Font's glyphs' bounds.
func (f *Font) FUnitsPerEm() int32
FUnitsPerEm returns the number of FUnits in a Font's em-square's side.
func (f *Font) HMetric(scale fixed.Int26_6, i Index) HMetric
HMetric returns the horizontal metrics for the glyph with the given index.
func (f *Font) Index(x rune) Index
Index returns a Font's index for the given rune.
func (f *Font) Kern(scale fixed.Int26_6, i0, i1 Index) fixed.Int26_6
Kern returns the horizontal adjustment for the given glyph pair. A positive kern means to move the glyphs further apart.
func (f *Font) Name(id NameID) string
Name returns the Font's name value for the given NameID. It returns "" if there was an error, or if that name was not found.
func (f *Font) VMetric(scale fixed.Int26_6, i Index) VMetric
VMetric returns the vertical metrics for the glyph with the given index.
A FormatError reports that the input is not a valid TrueType font.
type FormatError string
func (e FormatError) Error() string
A GlyphBuf holds a glyph's contours. A GlyphBuf can be re-used to load a series of glyphs from a Font.
type GlyphBuf struct { // AdvanceWidth is the glyph's advance width. AdvanceWidth fixed.Int26_6 // Bounds is the glyph's bounding box. Bounds fixed.Rectangle26_6 // Points contains all Points from all contours of the glyph. If hinting // was used to load a glyph then Unhinted contains those Points before they // were hinted, and InFontUnits contains those Points before they were // hinted and scaled. Points, Unhinted, InFontUnits []Point // Ends is the point indexes of the end point of each contour. The length // of Ends is the number of contours in the glyph. The i'th contour // consists of points Points[Ends[i-1]:Ends[i]], where Ends[-1] is // interpreted to mean zero. Ends []int // contains filtered or unexported fields }
func (g *GlyphBuf) Load(f *Font, scale fixed.Int26_6, i Index, h font.Hinting) error
Load loads a glyph's contours from a Font, overwriting any previously loaded contours for this GlyphBuf. scale is the number of 26.6 fixed point units in 1 em, i is the glyph index, and h is the hinting policy.
An HMetric holds the horizontal metrics of a single glyph.
type HMetric struct { AdvanceWidth, LeftSideBearing fixed.Int26_6 }
An Index is a Font's index of a rune.
type Index uint16
A NameID identifies a name table entry.
See https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
type NameID uint16
Options are optional arguments to NewFace.
type Options struct { // Size is the font size in points, as in "a 10 point font size". // // A zero value means to use a 12 point font size. Size float64 // DPI is the dots-per-inch resolution. // // A zero value means to use 72 DPI. DPI float64 // Hinting is how to quantize the glyph nodes. // // A zero value means to use no hinting. Hinting font.Hinting // GlyphCacheEntries is the number of entries in the glyph mask image // cache. // // If non-zero, it must be a power of 2. // // A zero value means to use 512 entries. GlyphCacheEntries int // SubPixelsX is the number of sub-pixel locations a glyph's dot is // quantized to, in the horizontal direction. For example, a value of 8 // means that the dot is quantized to 1/8th of a pixel. This quantization // only affects the glyph mask image, not its bounding box or advance // width. A higher value gives a more faithful glyph image, but reduces the // effectiveness of the glyph cache. // // If non-zero, it must be a power of 2, and be between 1 and 64 inclusive. // // A zero value means to use 4 sub-pixel locations. SubPixelsX int // SubPixelsY is the number of sub-pixel locations a glyph's dot is // quantized to, in the vertical direction. For example, a value of 8 // means that the dot is quantized to 1/8th of a pixel. This quantization // only affects the glyph mask image, not its bounding box or advance // width. A higher value gives a more faithful glyph image, but reduces the // effectiveness of the glyph cache. // // If non-zero, it must be a power of 2, and be between 1 and 64 inclusive. // // A zero value means to use 1 sub-pixel location. SubPixelsY int }
A Point is a co-ordinate pair plus whether it is 'on' a contour or an 'off' control point.
type Point struct { X, Y fixed.Int26_6 // The Flags' LSB means whether or not this Point is 'on' the contour. // Other bits are reserved for internal use. Flags uint32 }
An UnsupportedError reports that the input uses a valid but unimplemented TrueType feature.
type UnsupportedError string
func (e UnsupportedError) Error() string
A VMetric holds the vertical metrics of a single glyph.
type VMetric struct { AdvanceHeight, TopSideBearing fixed.Int26_6 }