font

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause, Unlicense Imports: 15 Imported by: 12

Documentation

Index

Constants

View Source
const UseMarkFilteringSet = 1 << 4

Variables

This section is empty.

Functions

func LoadHeadTable

func LoadHeadTable(ld *loader.Loader, buffer []byte) (tables.Head, []byte, error)

LoadHeadTable loads the table corresponding to the 'head' tag. If a 'bhed' Apple table is present, it replaces the 'head' one.

'buffer' may be provided to reduce allocations; the return Head is guaranteed not to retain any reference on 'buffer'. If 'buffer' is nil or has not enough capacity, a new slice is allocated (and returned).

func LoadHmtx

func LoadHmtx(ld *loader.Loader, numGlyphs int) (*tables.Hhea, tables.Hmtx, error)

Types

type AATStateTable

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

AATStateTable supports both regular and extended AAT state machines

func (*AATStateTable) GetClass

func (st *AATStateTable) GetClass(glyph GID) uint16

GetClass return the class for the given glyph, with the correct default value.

func (*AATStateTable) GetEntry

func (st *AATStateTable) GetEntry(state, class uint16) tables.AATStateEntry

GetEntry return the entry for the given state and class, and handle invalid values (by returning an empty entry).

type Face

type Face struct {
	*Font

	// Coords are the current variable coordinates, expressed in normalized units.
	// It is empty for non variable fonts.
	// Use `SetVariations` to convert from design (user) space units.
	Coords []tables.Coord

	// Horizontal and vertical pixels-per-em (ppem), used to select bitmap sizes.
	XPpem, YPpem uint16
}

Face is a font with user-provided settings. It is a lightweight wrapper around *Font, NOT safe for concurrent use.

func (*Face) FontHExtents

func (f *Face) FontHExtents() (api.FontExtents, bool)

FontHExtents returns the extents of the font for horizontal text, or false it not available, in font units.

func (*Face) FontVExtents

func (f *Face) FontVExtents() (api.FontExtents, bool)

FontVExtents is the same as `FontHExtents`, but for vertical text.

func (*Face) GlyphData

func (f *Face) GlyphData(gid GID) api.GlyphData

GlyphData returns the glyph content for [gid], or nil if not found.

func (*Face) GlyphExtents

func (f *Face) GlyphExtents(glyph GID) (api.GlyphExtents, bool)

func (*Face) GlyphVOrigin

func (f *Face) GlyphVOrigin(glyph GID) (x, y int32, found bool)

func (*Face) HorizontalAdvance

func (f *Face) HorizontalAdvance(gid GID) float32

func (*Face) LineMetric

func (f *Face) LineMetric(metric api.LineMetric) float32

LineMetric returns the metric identified by `metric` (in fonts units).

func (*Face) SetVariations

func (face *Face) SetVariations(variations []Variation)

SetVariations applies a list of font-variation settings to a font, defaulting to the values given in the `fvar` table. Note that passing an empty slice will instead remove the coordinates.

func (*Face) VerticalAdvance

func (f *Face) VerticalAdvance(gid GID) float32

type Feature

type Feature struct {
	tables.Feature
	Tag Tag
}

type Font

type Font struct {
	// Cmap is the 'cmap' table
	Cmap api.Cmap

	GDEF tables.GDEF // An absent table has a nil GlyphClassDef
	Trak tables.Trak
	Ankr tables.Ankr
	Feat tables.Feat
	Ltag tables.Ltag
	Morx Morx
	Kern Kernx
	Kerx Kernx
	GSUB GSUB // An absent table has a nil slice of lookups
	GPOS GPOS // An absent table has a nil slice of lookups
	// contains filtered or unexported fields
}

Font represents one Opentype font file (or one sub font of a collection). It is an educated view of the underlying font file, optimized for quick access to information required by text layout engines.

All its methods are read-only and a *Font object is thus safe for concurrent use.

func NewFont

func NewFont(ld *loader.Loader) (*Font, error)

NewFont loads all the font tables, sanitizing them. An error is returned only when required tables 'cmap', 'head', 'maxp' are invalid (or missing). More control on errors is available by using package tables.

func (*Font) BitmapSizes

func (font *Font) BitmapSizes() []api.BitmapSize

BitmapSizes returns the size of bitmap glyphs present in the font.

func (*Font) GetGlyphContourPoint

func (f *Font) GetGlyphContourPoint(glyph GID, pointIndex uint16) (x, y int32, ok bool)

func (*Font) GlyphHOrigin

func (f *Font) GlyphHOrigin(GID) (x, y int32, found bool)

func (*Font) GlyphName

func (f *Font) GlyphName(glyph GID) string

GlyphName returns the name of the given glyph, or an empty string if the glyph is invalid or has no name.

func (*Font) HasVerticalMetrics

func (f *Font) HasVerticalMetrics() bool

HasVerticalMetrics returns true if a the 'vmtx' table is present. If not, client should avoid calls to [VerticalAdvance], which will returns a defaut value.

func (*Font) NominalGlyph

func (f *Font) NominalGlyph(ch rune) (GID, bool)

NominalGlyph returns the glyph used to represent the given rune, or false if not found. Note that it only looks into the cmap, without taking account substitutions nor variation selectors.

func (*Font) NormalizeVariations

func (f *Font) NormalizeVariations(coords []float32) []VarCoord

NormalizeVariations normalize the given design-space coordinates. The minimum and maximum values for the axis are mapped to the interval [-1,1], with the default axis value mapped to 0.

Any additional scaling defined in the face's `avar` table is also applied, as described at https://docs.microsoft.com/en-us/typography/opentype/spec/avar.

This method panics if `coords` has not the correct length, that is the number of axis inf 'fvar'.

func (*Font) Upem

func (f *Font) Upem() uint16

Upem returns the units per em of the font file. This value is only relevant for scalable fonts.

func (*Font) VariationGlyph

func (f *Font) VariationGlyph(ch, varSelector rune) (GID, bool)

VariationGlyph retrieves the glyph ID for a specified Unicode code point followed by a specified Variation Selector code point, or false if not found

type GID

type GID = api.GID

type GPOS

type GPOS struct {
	Layout
	Lookups []GPOSLookup
}

type GPOSLookup

type GPOSLookup struct {
	LookupOptions
	Subtables []tables.GPOSLookup
}

type GSUB

type GSUB struct {
	Layout
	Lookups []GSUBLookup
}

type GSUBLookup

type GSUBLookup struct {
	LookupOptions
	Subtables []tables.GSUBLookup
}

type Kern0

type Kern0 []tables.Kernx0Record

func (Kern0) KernPair

func (kd Kern0) KernPair(left, right GID) int16

type Kern1

type Kern1 struct {
	Values  []int16 // After successful parsing, may be safely indexed by AATStateEntry.AsKernxIndex() from `Machine`
	Machine AATStateTable
}

type Kern2

type Kern2 tables.KerxData2

func (Kern2) KernPair

func (kd Kern2) KernPair(left, right GID) int16

type Kern3

type Kern3 tables.KernData3

func (Kern3) KernPair

func (kd Kern3) KernPair(left, right GID) int16

type Kern4

type Kern4 struct {
	Anchors tables.KerxAnchors
	Machine AATStateTable
	// contains filtered or unexported fields
}

func (Kern4) ActionType

func (k Kern4) ActionType() uint8

ActionType returns 0, 1 or 2 .

type Kern6

type Kern6 tables.KerxData6

func (Kern6) KernPair

func (kd Kern6) KernPair(left, right GID) int16

type KernSubtable

type KernSubtable struct {
	Data interface {
		// contains filtered or unexported methods
	}

	// IsExtended [true] for AAT `kerx` subtables, false for 'kern' subtables
	IsExtended bool

	// 0 for scalar values
	TupleCount int
	// contains filtered or unexported fields
}

KernSubtable represents a 'kern' or 'kerx' subtable.

func (KernSubtable) IsBackwards

func (k KernSubtable) IsBackwards() bool

IsBackwards returns true if state-table based should process the glyphs backwards.

func (KernSubtable) IsCrossStream

func (k KernSubtable) IsCrossStream() bool

IsCrossStream returns true if the subtable has cross-stream kerning values.

func (KernSubtable) IsHorizontal

func (k KernSubtable) IsHorizontal() bool

IsHorizontal returns true if the subtable has horizontal kerning values.

func (KernSubtable) IsVariation

func (k KernSubtable) IsVariation() bool

IsVariation returns true if the subtable has variation kerning values.

type Kernx

type Kernx []KernSubtable

Kernx represents a 'kern' or 'kerx' kerning table. It supports both Microsoft and Apple formats.

type Layout

type Layout struct {
	Scripts           []Script
	Features          []Feature
	FeatureVariations []tables.FeatureVariationRecord
}

shared between GSUB and GPOS

func (*Layout) FindFeatureIndex

func (la *Layout) FindFeatureIndex(featureTag Tag) (uint16, bool)

FindFeatureIndex fetches the index for a given feature tag in the GSUB or GPOS table. Returns false if not found

func (*Layout) FindScript

func (la *Layout) FindScript(script Tag) int

FindScript looks for [script] and return its index into the Scripts slice, or -1 if the tag is not found.

func (*Layout) FindVariationIndex

func (la *Layout) FindVariationIndex(coords []VarCoord) int

FindVariationIndex returns the first feature variation matching the specified variation coordinates, as an index in the `FeatureVariations` field. It returns `-1` if not found.

type LookupOptions

type LookupOptions struct {
	// Lookup qualifiers.
	Flag uint16
	// Index (base 0) into GDEF mark glyph sets structure,
	// meaningfull only if UseMarkFilteringSet is set.
	MarkFilteringSet uint16
}

func (LookupOptions) Props

func (lo LookupOptions) Props() uint32

Props returns a 32-bit integer where the lower 16-bit is `Flag` and the higher 16-bit is `MarkFilteringSet` if the lookup uses one.

type Morx

type Morx []MorxChain

type MorxChain

type MorxChain struct {
	Features     []tables.AATFeature
	Subtables    []MorxSubtable
	DefaultFlags uint32
}

type MorxContextualSubtable

type MorxContextualSubtable struct {
	Substitutions []tables.AATLookup
	Machine       AATStateTable
}

type MorxInsertionSubtable

type MorxInsertionSubtable struct {
	// After successul parsing, this array may be safely
	// indexed by the indexes and counts from Machine entries.
	Insertions []GID
	Machine    AATStateTable
}

type MorxLigatureSubtable

type MorxLigatureSubtable struct {
	LigatureAction []uint32
	Components     []uint16
	Ligatures      []GID
	Machine        AATStateTable
}

type MorxNonContextualSubtable

type MorxNonContextualSubtable struct {
	Class tables.AATLookup // the lookup value is interpreted as a GlyphIndex
}

type MorxRearrangementSubtable

type MorxRearrangementSubtable AATStateTable

type MorxSubtable

type MorxSubtable struct {
	Data interface {
		// contains filtered or unexported methods
	}
	Coverage uint8  // high byte of the coverage flag
	Flags    uint32 // Mask identifying which subtable this is.
}

type Script

type Script struct {
	tables.Script
	Tag Tag
}

type SimpleKerns

type SimpleKerns interface {
	// KernPair return the kern value for the given pair, or zero.
	// The value is expressed in glyph units and
	// is negative when glyphs should be closer.
	KernPair(left, right GID) int16
}

SimpleKerns store a compact form of the kerning values, which is restricted to (one direction) kerning pairs. It is only implemented by Kern0, Kern2, Kern3 and Kern6, where Kern1 and Kern4 requires a state machine to be interpreted.

type Tag

type Tag = loader.Tag

type VarCoord

type VarCoord = tables.Coord

Variation coordinates

type Variation

type Variation struct {
	Tag   Tag     // Variation-axis identifier tag
	Value float32 // In design units
}

Variation defines a value for a wanted variation axis.

Directories

Path Synopsis
cff
interpreter
Package psinterpreter implement a Postscript interpreter required to parse .CFF files, and Type1 and Type2 Charstrings.
Package psinterpreter implement a Postscript interpreter required to parse .CFF files, and Type1 and Type2 Charstrings.

Jump to

Keyboard shortcuts

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