HomeUniDoc
...

Package unitype

Overview ▾

Package unitype supports loading and writing truetype fonts. Specifically intended for font validation, repairing, subsetting for use in PDF.

func ValidateBytes

func ValidateBytes(b []byte) error

ValidateBytes validates the turetype font represented by the byte stream.

func ValidateFile

func ValidateFile(filePath string) error

ValidateFile validates the truetype font given by `filePath`.

type CharCode

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

type Font

Font wraps font for outside access.

type Font struct {
    // contains filtered or unexported fields
}

func Parse

func Parse(rs io.ReadSeeker) (*Font, error)

Parse parses the truetype font from `rs` and returns a new Font.

func ParseFile

func ParseFile(filePath string) (*Font, error)

ParseFile parses the truetype font from file given by path.

func (*Font) GetCmap

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 (Font) GetGlyphDataOffset

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 (Font) GetNameByID

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 (*Font) Optimize

func (f *Font) Optimize() error

Optimize does some optimization such as reducing hmtx table.

func (*Font) PruneTables

func (f *Font) PruneTables(tables ...string) error

PruneTables prunes font tables `tables` by name from font. Currently supports: "cmap", "post", "name".

func (Font) String

func (f Font) String() string

String outputs some readable information about the font (table record stats).

func (*Font) Subset

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 (*Font) SubsetFirst

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 (*Font) SubsetKeepIndices

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 (*Font) SubsetKeepRunes

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 (Font) TableInfo

func (f Font) TableInfo(table string) string

TableInfo provides readable information regarding a table.

func (*Font) Write

func (f *Font) Write(w io.Writer) error

Write writes the font to `w`.

func (*Font) WriteFile

func (f *Font) WriteFile(outPath string) error

WriteFile writes the font to `outPath`.

type GlyphIndex

GlyphIndex or Glyph ID (GID) represent each glyph within a font.

type GlyphIndex uint16

type GlyphName

GlyphName is a representation of a glyph name, e.g. from Adobe's glyph list.

type GlyphName string

Subdirectories

Name Synopsis
..
truecli
cmd