glyf

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-3.0 Imports: 6 Imported by: 2

Documentation

Overview

Package glyf reads and writes "glyf" and "loca" tables. https://docs.microsoft.com/en-us/typography/opentype/spec/glyf https://docs.microsoft.com/en-us/typography/opentype/spec/loca

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentFlag added in v0.4.0

type ComponentFlag uint16
const (
	FlagArg1And2AreWords        ComponentFlag = 0x0001
	FlagArgsAreXYValues         ComponentFlag = 0x0002
	FlagRoundXYToGrid           ComponentFlag = 0x0004
	FlagWeHaveAScale            ComponentFlag = 0x0008
	FlagMoreComponents          ComponentFlag = 0x0020
	FlagWeHaveAnXAndYScale      ComponentFlag = 0x0040
	FlagWeHaveATwoByTwo         ComponentFlag = 0x0080
	FlagWeHaveInstructions      ComponentFlag = 0x0100
	FlagUseMyMetrics            ComponentFlag = 0x0200
	FlagOverlapCompound         ComponentFlag = 0x0400
	FlagScaledComponentOffset   ComponentFlag = 0x0800
	FlagUnscaledComponentOffset ComponentFlag = 0x1000
)

The recognised values for the ComponentFlag field.

https://learn.microsoft.com/en-us/typography/opentype/spec/glyf#compositeGlyphFlags

func (ComponentFlag) String added in v0.4.0

func (f ComponentFlag) String() string

type CompositeGlyph

type CompositeGlyph struct {
	Components   []GlyphComponent
	Instructions []byte
}

CompositeGlyph is a composite glyph.

type Contour

type Contour []Point

A Contour describes a connected part of a glyph outline.

type Encoded

type Encoded struct {
	GlyfData   []byte
	LocaData   []byte
	LocaFormat int16
}

Encoded represents the data of a "glyf" and "loca" table.

type Glyph

type Glyph struct {
	funit.Rect16
	Data interface{} // either SimpleGlyph or CompositeGlyph
}

Glyph represents a single glyph in a TrueType font.

func (*Glyph) Components

func (g *Glyph) Components() []glyph.ID

Components returns the components of a composite glyph, or nil if the glyph is simple.

func (*Glyph) FixComponents

func (g *Glyph) FixComponents(newGid map[glyph.ID]glyph.ID) *Glyph

FixComponents changes the glyph component IDs of a composite glyph.

type GlyphComponent

type GlyphComponent struct {
	Flags      ComponentFlag
	GlyphIndex glyph.ID
	Data       []byte
}

GlyphComponent is a single component of a composite glyph.

https://learn.microsoft.com/en-us/typography/opentype/spec/glyf#composite-glyph-description

type GlyphInfo

type GlyphInfo struct {
	Contours     []Contour
	Instructions []byte
}

GlyphInfo contains the contours of a SimpleGlyph.

type Glyphs

type Glyphs []*Glyph

Glyphs contains a slice of TrueType glyph outlines. This represents the information stored in the "glyf" and "loca" tables of a TrueType font.

func Decode

func Decode(enc *Encoded) (Glyphs, error)

Decode converts the data from the "glyf" and "loca" tables into a slice of Glyphs. The value for locaFormat is specified in the indexToLocFormat entry in the "head" table.

func (Glyphs) Encode

func (gg Glyphs) Encode() *Encoded

Encode encodes the Glyphs into a "glyf" and "loca" table.

type Outlines

type Outlines struct {
	// Glyphs is a slice of glyph outlines in the font.
	Glyphs Glyphs

	// Widths contains the glyph widths, indexed by glyph ID.
	Widths []funit.Int16

	// Names, if non-nil, contains the glyph names.
	Names []string

	// Tables contains the raw contents of the "cvt ", "fpgm", "prep", "gasp"
	// tables.
	Tables map[string][]byte

	// Maxp contains information from the "maxp" table.
	Maxp *maxp.TTFInfo
}

Outlines stores the glyph data of a TrueType font.

type Point

type Point struct {
	X, Y    funit.Int16
	OnCurve bool
}

A Point is a point in a glyph outline

type SimpleGlyph

type SimpleGlyph struct {
	NumContours int16
	Encoded     []byte
}

SimpleGlyph is a simple glyph.

func (*SimpleGlyph) Decode

func (glyph *SimpleGlyph) Decode() (*GlyphInfo, error)

Decode returns the contours of a glyph.

Jump to

Keyboard shortcuts

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