freetype

package
v0.0.0-...-793ea6c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package freetype is a wrapper around the FreeType font rendering library.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotOpenResource          = errors.New("cannot open resource")
	ErrUnknownFileFormat           = errors.New("unknown file format")
	ErrInvalidFileFormat           = errors.New("broken file")
	ErrInvalidVersion              = errors.New("invalid FreeType version")
	ErrLowerModuleVersion          = errors.New("module version is too low")
	ErrInvalidArgument             = errors.New("invalid argument")
	ErrUnimplementedFeature        = errors.New("unimplemented feature")
	ErrInvalidTable                = errors.New("broken table")
	ErrInvalidOffset               = errors.New("broken offset within table")
	ErrArrayTooLarge               = errors.New("array allocation size too large")
	ErrMissingModule               = errors.New("missing module")
	ErrMissingProperty             = errors.New("missing property")
	ErrInvalidGlyphIndex           = errors.New("invalid glyph index")
	ErrInvalidCharacterCode        = errors.New("invalid character code")
	ErrInvalidGlyphFormat          = errors.New("unsupported glyph image format")
	ErrCannotRenderGlyph           = errors.New("cannot render this glyph format")
	ErrInvalidOutline              = errors.New("invalid outline")
	ErrInvalidComposite            = errors.New("invalid composite glyph")
	ErrTooManyHints                = errors.New("too many hints")
	ErrInvalidPixelSize            = errors.New("invalid pixel size")
	ErrInvalidHandle               = errors.New("invalid object handle")
	ErrInvalidLibraryHandle        = errors.New("invalid library handle")
	ErrInvalidDriverHandle         = errors.New("invalid module handle")
	ErrInvalidFaceHandle           = errors.New("invalid face handle")
	ErrInvalidSizeHandle           = errors.New("invalid size handle")
	ErrInvalidSlotHandle           = errors.New("invalid glyph slot handle")
	ErrInvalidCharMapHandle        = errors.New("invalid charmap handle")
	ErrInvalidCacheHandle          = errors.New("invalid cache manager handle")
	ErrInvalidStreamHandle         = errors.New("invalid stream handle")
	ErrTooManyDrivers              = errors.New("too many modules")
	ErrTooManyExtensions           = errors.New("too many extensions")
	ErrOutOfMemory                 = errors.New("out of memory")
	ErrUnlistedObject              = errors.New("unlisted object")
	ErrCannotOpenStream            = errors.New("cannot open stream")
	ErrInvalidStreamSeek           = errors.New("invalid stream seek")
	ErrInvalidStreamSkip           = errors.New("invalid stream skip")
	ErrInvalidStreamRead           = errors.New("invalid stream read")
	ErrInvalidStreamOperation      = errors.New("invalid stream operation")
	ErrInvalidFrameOperation       = errors.New("invalid frame operation")
	ErrNestedFrameAccess           = errors.New("nested frame access")
	ErrInvalidFrameRead            = errors.New("invalid frame read")
	ErrRasterUninitialized         = errors.New("raster uninitialized")
	ErrRasterCorrupted             = errors.New("raster corrupted")
	ErrRasterOverflow              = errors.New("raster overflow")
	ErrRasterNegativeHeight        = errors.New("negative height while rastering")
	ErrTooManyCaches               = errors.New("too many registered caches")
	ErrInvalidOpcode               = errors.New("invalid opcode")
	ErrTooFewArguments             = errors.New("too few arguments")
	ErrStackOverflow               = errors.New("stack overflow")
	ErrCodeOverflow                = errors.New("code overflow")
	ErrBadArgument                 = errors.New("bad argument")
	ErrDivideByZero                = errors.New("division by zero")
	ErrInvalidReference            = errors.New("invalid reference")
	ErrDebugOpCode                 = errors.New("found debug opcode")
	ErrENDFInExecStream            = errors.New("found ENDF opcode in execution stream")
	ErrNestedDEFS                  = errors.New("nested DEFS")
	ErrInvalidCodeRange            = errors.New("invalid code range")
	ErrExecutionTooLong            = errors.New("execution context too long")
	ErrTooManyFunctionDefs         = errors.New("too many function definitions")
	ErrTooManyInstructionDefs      = errors.New("too many instruction definitions")
	ErrTableMissing                = errors.New("SFNT font table missing")
	ErrHorizHeaderMissing          = errors.New("horizontal header (hhea) table missing")
	ErrLocationsMissing            = errors.New("locations (loca) table missing")
	ErrNameTableMissing            = errors.New("name table missing")
	ErrCMapTableMissing            = errors.New("character map (cmap) table missing")
	ErrHmtxTableMissing            = errors.New("horizontal metrics (hmtx) table missing")
	ErrPostTableMissing            = errors.New("PostScript (post) table missing")
	ErrInvalidHorizMetrics         = errors.New("invalid horizontal metrics")
	ErrInvalidCharMapFormat        = errors.New("invalid character map (cmap) format")
	ErrInvalidPPem                 = errors.New("invalid ppem value")
	ErrInvalidVertMetrics          = errors.New("invalid vertical metrics")
	ErrCouldNotFindContext         = errors.New("could not find context")
	ErrInvalidPostTableFormat      = errors.New("invalid PostScript (post) table format")
	ErrInvalidPostTable            = errors.New("invalid PostScript (post) table")
	ErrSyntaxError                 = errors.New("opcode syntax error")
	ErrStackUnderflow              = errors.New("argument stack underflow")
	ErrIgnore                      = errors.New("ignore")
	ErrNoUnicodeGlyphName          = errors.New("no Unicode glyph name found")
	ErrGlyphTooBig                 = errors.New("glyph to big for hinting")
	ErrMissingStartfontField       = errors.New("`STARTFONT' field missing")
	ErrMissingFontField            = errors.New("`FONT' field missing")
	ErrMissingSizeField            = errors.New("`SIZE' field missing")
	ErrMissingFontboundingboxField = errors.New("`FONTBOUNDINGBOX' field missing")
	ErrMissingCharsField           = errors.New("`CHARS' field missing")
	ErrMissingStartcharField       = errors.New("`STARTCHAR' field missing")
	ErrMissingEncodingField        = errors.New("`ENCODING' field missing")
	ErrMissingBbxField             = errors.New("`BBX' field missing")
	ErrBbxTooBig                   = errors.New("`BBX' too big")
	ErrCorruptedFontHeader         = errors.New("Font header corrupted or missing fields")
	ErrCorruptedFontGlyphs         = errors.New("Font glyphs corrupted or missing fields")
)

Functions

This section is empty.

Types

type Context

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

Context represents a single freetype context which must not be accessed concurrently (typically each thread/goroutine uses a single context).

func Init

func Init() (*Context, error)

Init initializes and returns a new freetype context, or returns a error.

func (*Context) Load

func (c *Context) Load(fontFileData []byte) (*Font, error)

Load loads and returns the given font file data and returns the loaded font or an error.

type Font

type Font struct {

	// Bounding box that is large enough to contain any glyph in the font face.
	// Expressed in font units.
	BBox image.Rectangle

	// The number of font units per EM square for this font face.
	// Expressed in font units.
	UnitsPerEm int

	// The typographic ascender of the face
	// Expressed in font units.
	Ascender int

	// The typographic descender of the face.
	// Expressed in font units.
	Descender int

	// The vertical distance between two consecutive baselines.
	// Expressed in font units.
	LineHeight int

	// The maximum advance width for all glyphs in this face.
	// This can be used to make word wrapping computations faster.
	// Expressed in font units.
	MaxAdvanceWidth int

	// The maximum advance height, for all glyphs in this face.
	// This is only relevant for vertical layouts, and is set to ‘height’
	// for fonts that do not provide vertical metrics.
	// Expressed in font units.
	MaxAdvanceHeight int

	// The position of the underline for this font face.
	// Expressed in font units.
	UnderlinePosition int

	// The thickness for the underline of this font face.
	// Expressed in font units.
	UnderlineThickness int
	// contains filtered or unexported fields
}

Font represents a single Freetype font.

func (*Font) Index

func (f *Font) Index(r rune) (glyphIndex uint)

Index returns the glyph index for the given rune.

func (*Font) Kerning

func (f *Font) Kerning(leftGlyph, rightGlyph rune) (x, y int, e error)

Kerning returns the X/Y kerning pair for the left and right horizontally aligned glyphs, or x=0, y=0, and a error.

func (*Font) Load

func (f *Font) Load(glyphIndex uint) (*Glyph, error)

Load loads the given glyph index into the font's glyph slot and returns the glyph.

func (*Font) SetSize

func (f *Font) SetSize(width, height, xResolution, yResolution int) error

SetSize sets the current size of the font given 26.6 width and height units and X/Y axis resolutions.

func (*Font) SetSizePixels

func (f *Font) SetSizePixels(width, height int) error

SetSizePixels sets the current size of the font given width and height pixel based units.

type Glyph

type Glyph struct {

	// Width and height of glyph.
	// Expressed in font units.
	Width, Height int

	// Horizontal and vertical glyph metrics.
	HMetrics, VMetrics GlyphMetrics
	// contains filtered or unexported fields
}

Glyph represents a single renderable glyph.

func (*Glyph) Image

func (g *Glyph) Image() (*GlyphImage, error)

Renders and returns a alpha image, it is returned as *GlyphImage because a reference internally must be held to this *Glyph.

The returned glyph image's data resides in a single slot held by the font this glyph came from, as such you must ensure you only use a single GlyphImage from the same font source at any given time (or make a copy of the returned image).

type GlyphImage

type GlyphImage struct {
	*image.Alpha
	// contains filtered or unexported fields
}

GlyphImage is literally just *image.Alpha, except it must hold a pointer internally to *Glyph to avoid a garbage collection invoking finalizers which free the image data.

type GlyphMetrics

type GlyphMetrics struct {
	// Left side bearing and top side bearing
	// X values extend to the right, and positive Y values downward.
	// Expressed in font units.
	BearingX, BearingY int

	// Advance (and unhinted advance) amount of glyph.
	// For horizontal metrics, a positive value means advancing to the right.
	// For vertical metrics, a positive value means advancing downward.
	// Expressed in font units.
	Advance, UnhintedAdvance int
}

GlyphMetrics contains metrics of a single glyph.

Jump to

Keyboard shortcuts

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