go: github.com/janelia-flyem/go/freetype-go/freetype/truetype Index | Files

package truetype

import "github.com/janelia-flyem/go/freetype-go/freetype/truetype"

Package truetype provides a parser for the TTF and TTC file formats. Those formats are documented at http://developer.apple.com/fonts/TTRefMan/ and http://www.microsoft.com/typography/otspec/

Some of a font's methods provide lengths or co-ordinates, e.g. bounds, font metrics and control points. All these methods take a scale parameter, which is the number of device units in 1 em. For example, if 1 em is 10 pixels and 1 pixel is 64 units, then scale is 640. If the device space involves pixels, 64 units per pixel is recommended, since that is what the bytecode hinter uses when snapping point co-ordinates to the pixel grid.

To measure a TrueType font in ideal FUnit space, use scale equal to font.FUnitsPerEm().

Index

Package Files

glyph.go hint.go opcodes.go truetype.go

type Bounds Uses

type Bounds struct {
    XMin, YMin, XMax, YMax int32
}

A Bounds holds the co-ordinate range of one or more glyphs. The endpoints are inclusive.

type Font Uses

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

A Font represents a Truetype font.

func Parse Uses

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

func (f *Font) Bounds(scale int32) Bounds

Bounds returns the union of a Font's glyphs' bounds.

func (*Font) FUnitsPerEm Uses

func (f *Font) FUnitsPerEm() int32

FUnitsPerEm returns the number of FUnits in a Font's em-square's side.

func (*Font) HMetric Uses

func (f *Font) HMetric(scale int32, i Index) HMetric

HMetric returns the horizontal metrics for the glyph with the given index.

func (*Font) Index Uses

func (f *Font) Index(x rune) Index

Index returns a Font's index for the given rune.

func (*Font) Kerning Uses

func (f *Font) Kerning(scale int32, i0, i1 Index) int32

Kerning returns the kerning for the given glyph pair.

type FormatError Uses

type FormatError string

A FormatError reports that the input is not a valid TrueType font.

func (FormatError) Error Uses

func (e FormatError) Error() string

type GlyphBuf Uses

type GlyphBuf struct {
    // B is the glyph's bounding box.
    B   Bounds
    // Point contains all Points from all contours of the glyph. If a
    // Hinter 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.
    Point, Unhinted, InFontUnits []Point
    // End is the point indexes of the end point of each countour. The
    // length of End is the number of contours in the glyph. The i'th
    // contour consists of points Point[End[i-1]:End[i]], where End[-1]
    // is interpreted to mean zero.
    End []int
    // contains filtered or unexported fields
}

A GlyphBuf holds a glyph's contours. A GlyphBuf can be re-used to load a series of glyphs from a Font.

func NewGlyphBuf Uses

func NewGlyphBuf() *GlyphBuf

NewGlyphBuf returns a newly allocated GlyphBuf.

func (*GlyphBuf) Load Uses

func (g *GlyphBuf) Load(f *Font, scale int32, i Index, h *Hinter) 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. The Hinter is optional; if non-nil, then the resulting glyph will be hinted by the Font's bytecode instructions.

type HMetric Uses

type HMetric struct {
    AdvanceWidth    int32
    LeftSideBearing int32
}

An HMetric holds the horizontal metrics of a single glyph.

type Hinter Uses

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

Hinter implements bytecode hinting. Pass a Hinter to GlyphBuf.Load to hint the resulting glyph. A Hinter can be re-used to hint a series of glyphs from a Font.

type Index Uses

type Index uint16

An Index is a Font's index of a rune.

type Point Uses

type Point struct {
    X, Y int32
    // The Flags' LSB means whether or not this Point is ``on'' the contour.
    // Other bits are reserved for internal use.
    Flags uint32
}

A Point is a co-ordinate pair plus whether it is “on” a contour or an “off” control point.

type UnsupportedError Uses

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented TrueType feature.

func (UnsupportedError) Error Uses

func (e UnsupportedError) Error() string

Package truetype imports 3 packages (graph) and is imported by 5 packages. Updated 2016-07-18. Refresh now. Tools for package owners.