func ValidateBytes(b []byte) error
ValidateBytes validates the turetype font represented by the byte stream.
func ValidateFile(filePath string) error
ValidateFile validates the truetype font given by `filePath`.
CharCode is an internal typically 1-2 byte representation of a code. Its meaning depends on encoding context. Requires an accompanying cmapEncoder for mapping from/to runes.
type CharCode uint32
Font wraps font for outside access.
type Font struct {
// contains filtered or unexported fields
}
func Parse(rs io.ReadSeeker) (*Font, error)
Parse parses the truetype font from `rs` and returns a new Font.
func ParseFile(filePath string) (*Font, error)
ParseFile parses the truetype font from file given by path.
func (f *Font) GetCmap(platformID, encodingID int) map[rune]GlyphIndex
GetCmap returns the specific cmap specified by `platformID` and platform-specific `encodingID`. If not available, nil is returned. Used in PDF for decoding.
func (f Font) GetGlyphDataOffset(gid GlyphIndex) (offset int64, len int64, err error)
GetGlyphDataOffset returns offset for glyph index `gid`. The offset is relative to the beginning of the glyf table.
func (f Font) GetNameByID(nameID int) string
GetNameByID returns the first entry according to the name table with `nameID`. An empty string is returned otherwise (nothing found).
func (f *Font) LookupRunes(runes []rune) []GlyphIndex
LookupRunes looks up each rune in `rune` and returns a matching slice of glyph indices. When a rune is not found, a GID of 0 is used (notdef).
func (f *Font) Optimize() error
Optimize does some optimization such as reducing hmtx table.
func (f *Font) PruneTables(tables ...string) error
PruneTables prunes font tables `tables` by name from font. Currently supports: "cmap", "post", "name".
func (f Font) String() string
String outputs some readable information about the font (table record stats).
func (f *Font) Subset(indices []GlyphIndex) (newf *Font, oldnew map[GlyphIndex]GlyphIndex, err error)
Subset creates a subset of `f` including only glyph indices specified by `indices`. Returns the new subsetted font, a map of old to new GlyphIndex to GlyphIndex as the removal of glyphs requires reordering.
func (f *Font) SubsetFirst(numGlyphs int) (*Font, error)
SubsetFirst creates a subset of `f` limited to only the first `numGlyphs` glyphs. Prunes out the glyphs from the previous font beyond that number. NOTE: If any of the first numGlyphs depend on later glyphs, it can lead to incorrect rendering.
func (f *Font) SubsetKeepIndices(indices []GlyphIndex) (*Font, error)
SubsetKeepIndices prunes data for all GIDs outside of `indices`. The GIDs are maintained. This typically works well and is a simple way to prune most of the unnecessary data as the glyf table is usually the biggest by far.
func (f *Font) SubsetKeepRunes(runes []rune) (*Font, error)
SubsetKeepRunes prunes data for all GIDs except the ones corresponding to `runes`. The GIDs are maintained. Typically reduces glyf table size significantly.
func (f Font) TableInfo(table string) string
TableInfo provides readable information regarding a table.
func (f *Font) Write(w io.Writer) error
Write writes the font to `w`.
func (f *Font) WriteFile(outPath string) error
WriteFile writes the font to `outPath`.
GlyphIndex or Glyph ID (GID) represent each glyph within a font.
type GlyphIndex uint16
GlyphName is a representation of a glyph name, e.g. from Adobe's glyph list.
type GlyphName string