truetype

package
v0.0.0-...-160e1d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2015 License: Freetype Imports: 3 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

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

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

A Font represents a Truetype font.

func Parse

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

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

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

func (*Font) FUnitsPerEm

func (f *Font) FUnitsPerEm() int32

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

func (*Font) HMetric

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

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

func (*Font) Index

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

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

func (*Font) Kerning

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

Kerning returns the kerning for the given glyph pair.

func (*Font) VMetric

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

VMetric returns the vertical metrics for the glyph with the given index.

type FormatError

type FormatError string

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

func (FormatError) Error

func (e FormatError) Error() string

type GlyphBuf

type GlyphBuf struct {
	// AdvanceWidth is the glyph's advance width.
	AdvanceWidth int32
	// B is the glyph's bounding box.
	B Bounds
	// Point 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.
	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

func NewGlyphBuf() *GlyphBuf

NewGlyphBuf returns a newly allocated GlyphBuf.

func (*GlyphBuf) Load

func (g *GlyphBuf) Load(f *Font, scale int32, i Index, h 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.

type HMetric

type HMetric struct {
	AdvanceWidth, LeftSideBearing int32
}

An HMetric holds the horizontal metrics of a single glyph.

type Hinting

type Hinting int32

Hinting is the policy for snapping a glyph's contours to pixel boundaries.

const (
	// NoHinting means to not perform any hinting.
	NoHinting Hinting = iota
	// FullHinting means to use the font's hinting instructions.
	FullHinting
)

type Index

type Index uint16

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

type Point

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

type UnsupportedError string

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

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

type VMetric

type VMetric struct {
	AdvanceHeight, TopSideBearing int32
}

A VMetric holds the vertical metrics of a single glyph.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL