ot

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ot provides OpenType font table parsing.

Package ot provides OpenType font table parsing.

Index

Constants

View Source
const (
	// FeatureGlobalStart indicates feature applies from buffer start.
	FeatureGlobalStart uint = 0
	// FeatureGlobalEnd indicates feature applies to buffer end.
	FeatureGlobalEnd uint = ^uint(0)
)
View Source
const (
	GlyphClassUnclassified = 0 // Unclassified glyph
	GlyphClassBase         = 1 // Base glyph (single character, spacing glyph)
	GlyphClassLigature     = 2 // Ligature glyph (multiple characters, spacing glyph)
	GlyphClassMark         = 3 // Mark glyph (non-spacing combining glyph)
	GlyphClassComponent    = 4 // Component glyph (part of a ligature)
)

GlyphClass constants for GDEF glyph classification.

View Source
const (
	GPOSTypeSingle       = 1
	GPOSTypePair         = 2
	GPOSTypeCursive      = 3
	GPOSTypeMarkBase     = 4
	GPOSTypeMarkLig      = 5
	GPOSTypeMarkMark     = 6
	GPOSTypeContext      = 7
	GPOSTypeChainContext = 8
	GPOSTypeExtension    = 9
)

GPOS lookup types

View Source
const (
	ValueFormatXPlacement = 0x0001 // Horizontal adjustment for placement
	ValueFormatYPlacement = 0x0002 // Vertical adjustment for placement
	ValueFormatXAdvance   = 0x0004 // Horizontal adjustment for advance
	ValueFormatYAdvance   = 0x0008 // Vertical adjustment for advance
	ValueFormatXPlaDevice = 0x0010 // Device table for horizontal placement
	ValueFormatYPlaDevice = 0x0020 // Device table for vertical placement
	ValueFormatXAdvDevice = 0x0040 // Device table for horizontal advance
	ValueFormatYAdvDevice = 0x0080 // Device table for vertical advance
)

ValueFormat flags - determine which values are present in a ValueRecord

View Source
const (
	// LookupFlagRightToLeft indicates right-to-left cursive attachment.
	LookupFlagRightToLeft = 0x0001
	// LookupFlagIgnoreBaseGlyphs causes base glyphs to be skipped.
	LookupFlagIgnoreBaseGlyphs = 0x0002
	// LookupFlagIgnoreLigatures causes ligature glyphs to be skipped.
	LookupFlagIgnoreLigatures = 0x0004
	// LookupFlagIgnoreMarks causes mark glyphs to be skipped.
	LookupFlagIgnoreMarks = 0x0008
	// LookupFlagUseMarkFilteringSet indicates that MarkFilteringSet is used.
	LookupFlagUseMarkFilteringSet = 0x0010
	// LookupFlagMarkAttachTypeMask is the mask for mark attachment type filtering.
	LookupFlagMarkAttachTypeMask = 0xFF00
)

LookupFlag bit constants for GSUB/GPOS lookups.

View Source
const (
	AttachTypeNone    = 0
	AttachTypeMark    = 1
	AttachTypeCursive = 2
)

AttachType constants for glyph attachment

View Source
const (
	GSUBTypeSingle             = 1
	GSUBTypeMultiple           = 2
	GSUBTypeAlternate          = 3
	GSUBTypeLigature           = 4
	GSUBTypeContext            = 5
	GSUBTypeChainContext       = 6
	GSUBTypeExtension          = 7
	GSUBTypeReverseChainSingle = 8
)

GSUB lookup types

View Source
const NotCovered = ^uint32(0)

NotCovered is returned when a glyph is not in a coverage table.

Variables

View Source
var (
	TagKern = MakeTag('k', 'e', 'r', 'n') // Kerning
	TagMark = MakeTag('m', 'a', 'r', 'k') // Mark Positioning
	TagMkmk = MakeTag('m', 'k', 'm', 'k') // Mark-to-Mark Positioning
)

Common GPOS feature tags

View Source
var (
	TagLiga = MakeTag('l', 'i', 'g', 'a') // Standard Ligatures
	TagClig = MakeTag('c', 'l', 'i', 'g') // Contextual Ligatures
	TagDlig = MakeTag('d', 'l', 'i', 'g') // Discretionary Ligatures
	TagHlig = MakeTag('h', 'l', 'i', 'g') // Historical Ligatures
	TagCcmp = MakeTag('c', 'c', 'm', 'p') // Glyph Composition/Decomposition
	TagLocl = MakeTag('l', 'o', 'c', 'l') // Localized Forms
	TagRlig = MakeTag('r', 'l', 'i', 'g') // Required Ligatures
	TagSmcp = MakeTag('s', 'm', 'c', 'p') // Small Capitals
	TagCalt = MakeTag('c', 'a', 'l', 't') // Contextual Alternates
)

Common feature tags

View Source
var (
	ErrInvalidFont    = errors.New("invalid font data")
	ErrTableNotFound  = errors.New("table not found")
	ErrInvalidTable   = errors.New("invalid table data")
	ErrInvalidOffset  = errors.New("offset out of bounds")
	ErrInvalidFormat  = errors.New("unsupported format")
	ErrInvalidFeature = errors.New("invalid feature string")
)

Common errors

View Source
var (
	TagCmap = MakeTag('c', 'm', 'a', 'p')
	TagHead = MakeTag('h', 'e', 'a', 'd')
	TagHhea = MakeTag('h', 'h', 'e', 'a')
	TagHmtx = MakeTag('h', 'm', 't', 'x')
	TagMaxp = MakeTag('m', 'a', 'x', 'p')
	TagName = MakeTag('n', 'a', 'm', 'e')
	TagOS2  = MakeTag('O', 'S', '/', '2')
	TagPost = MakeTag('p', 'o', 's', 't')
	TagGlyf = MakeTag('g', 'l', 'y', 'f')
	TagLoca = MakeTag('l', 'o', 'c', 'a')
	TagGDEF = MakeTag('G', 'D', 'E', 'F')
	TagGSUB = MakeTag('G', 'S', 'U', 'B')
	TagGPOS = MakeTag('G', 'P', 'O', 'S')
	TagCvt  = MakeTag('c', 'v', 't', ' ')
	TagFpgm = MakeTag('f', 'p', 'g', 'm')
	TagPrep = MakeTag('p', 'r', 'e', 'p')
	TagGasp = MakeTag('g', 'a', 's', 'p')
)

Common OpenType tags

View Source
var TagCFF = MakeTag('C', 'F', 'F', ' ')

TagCFF is the table tag for CFF data.

Functions

func BuildLoca

func BuildLoca(offsets []uint32, useShort bool) []byte

BuildLoca builds a loca table from glyph offsets. If useShort is true, uses 16-bit format (offsets must be even and < 131072).

func ClearShaperCache

func ClearShaperCache()

ClearShaperCache clears the internal shaper cache. Call this if fonts are being released to allow garbage collection.

func GetGlyphName

func GetGlyphName(glyph GlyphID) string

GetGlyphName returns a debug name for a glyph (just the ID as string).

func RemapCharString

func RemapCharString(cs []byte, globalMap, localMap map[int]int, oldGlobalBias, oldLocalBias, newGlobalBias, newLocalBias int) []byte

RemapCharString rewrites a CharString with remapped subroutine numbers.

func RemapComposite

func RemapComposite(data []byte, glyphMap map[GlyphID]GlyphID) []byte

RemapComposite creates a new composite glyph with remapped component IDs.

func Shape

func Shape(font *Font, buf *Buffer, features []Feature) error

Shape is a convenience function that shapes text in a buffer using a font. It caches shapers internally for efficiency. This is similar to HarfBuzz's hb_shape() function.

Types

type AlternateSubst

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

AlternateSubst represents an Alternate Substitution subtable (1 -> 1 from set). It allows choosing one glyph from a set of alternatives.

func (*AlternateSubst) Apply

func (a *AlternateSubst) Apply(ctx *GSUBContext) int

Apply applies the alternate substitution. By default, it selects the first alternative (index 0). Use ApplyWithIndex to select a specific alternative.

func (*AlternateSubst) ApplyWithIndex

func (a *AlternateSubst) ApplyWithIndex(ctx *GSUBContext, altIndex int) int

ApplyWithIndex applies the alternate substitution with a specific alternate index. altIndex is 0-based (0 = first alternate, 1 = second, etc.)

func (*AlternateSubst) GetAlternates

func (a *AlternateSubst) GetAlternates(glyph GlyphID) []GlyphID

GetAlternates returns the available alternates for a glyph. Returns nil if the glyph is not covered.

func (*AlternateSubst) Mapping

func (a *AlternateSubst) Mapping() map[GlyphID][]GlyphID

Mapping returns the input->alternates mapping for glyph closure computation.

type Anchor

type Anchor struct {
	Format uint16
	X      int16 // X coordinate in design units
	Y      int16 // Y coordinate in design units
	// Format 2 adds: anchorPoint (contour point index)
	AnchorPoint uint16
}

Anchor represents an anchor point for mark positioning. It stores x,y coordinates in design units.

type AttachList

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

AttachList contains attachment points for glyphs.

type BaseArray

type BaseArray struct {
	Rows       int
	ClassCount int
	Anchors    [][]*Anchor // [row][class] -> Anchor (may be nil)
}

BaseArray contains anchors for base glyphs, organized as a matrix. Rows correspond to base glyphs (in BaseCoverage order). Columns correspond to mark classes (0 to classCount-1).

func (*BaseArray) GetAnchor

func (ba *BaseArray) GetAnchor(baseIndex, markClass int) *Anchor

GetAnchor returns the anchor for a given base glyph index and mark class.

type Buffer

type Buffer struct {
	Info      []GlyphInfo
	Pos       []GlyphPos
	Direction Direction
	Flags     BufferFlags

	// Script and Language for shaping (optional, can be auto-detected)
	Script   Tag
	Language Tag
}

Buffer holds a sequence of glyphs being shaped.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new empty buffer.

func (*Buffer) AddCodepoints

func (b *Buffer) AddCodepoints(codepoints []Codepoint)

AddCodepoints adds Unicode codepoints to the buffer.

func (*Buffer) AddString

func (b *Buffer) AddString(s string)

AddString adds a string to the buffer.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear removes all glyphs from the buffer.

func (*Buffer) GlyphIDs

func (b *Buffer) GlyphIDs() []GlyphID

GlyphIDs returns just the glyph IDs.

func (*Buffer) GuessSegmentProperties

func (b *Buffer) GuessSegmentProperties()

GuessSegmentProperties guesses direction, script, and language from buffer content. This is similar to HarfBuzz's hb_buffer_guess_segment_properties().

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of glyphs in the buffer.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset clears the buffer and resets all properties to defaults.

func (*Buffer) SetDirection

func (b *Buffer) SetDirection(dir Direction)

SetDirection sets the text direction.

type BufferFlags

type BufferFlags uint32

BufferFlags controls buffer behavior during shaping. These match HarfBuzz's hb_buffer_flags_t.

const (
	// BufferFlagDefault is the default buffer flag.
	BufferFlagDefault BufferFlags = 0
	// BufferFlagBOT indicates beginning of text paragraph.
	BufferFlagBOT BufferFlags = 1 << iota
	// BufferFlagEOT indicates end of text paragraph.
	BufferFlagEOT
	// BufferFlagPreserveDefaultIgnorables keeps default ignorable characters visible.
	BufferFlagPreserveDefaultIgnorables
	// BufferFlagRemoveDefaultIgnorables removes default ignorable characters from output.
	BufferFlagRemoveDefaultIgnorables
	// BufferFlagDoNotInsertDottedCircle prevents dotted circle insertion for invalid sequences.
	BufferFlagDoNotInsertDottedCircle
)

type CFF

type CFF struct {
	Name        string
	TopDict     TopDict
	Strings     []string // Custom strings (SID 391+)
	GlobalSubrs [][]byte // Global subroutines
	CharStrings [][]byte // Per-glyph CharStrings
	PrivateDict PrivateDict
	LocalSubrs  [][]byte  // Local subroutines
	Charset     []GlyphID // Glyph ID to SID mapping

	// CID fonts
	IsCID    bool
	FDArray  []FontDict
	FDSelect []byte
	// contains filtered or unexported fields
}

CFF represents a parsed CFF (Compact Font Format) table.

func ParseCFF

func ParseCFF(data []byte) (*CFF, error)

ParseCFF parses a CFF table from raw data.

func (*CFF) GetString

func (c *CFF) GetString(sid int) string

GetString returns the string for a given SID.

func (*CFF) NumGlyphs

func (c *CFF) NumGlyphs() int

NumGlyphs returns the number of glyphs in the CFF font.

type CaretValue

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

CaretValue represents a caret position within a ligature.

func (*CaretValue) Coordinate

func (cv *CaretValue) Coordinate() int16

Coordinate returns the coordinate value for a CaretValue (format 1 or 3).

func (*CaretValue) Format

func (cv *CaretValue) Format() uint16

Format returns the CaretValue format (1, 2, or 3).

func (*CaretValue) PointIndex

func (cv *CaretValue) PointIndex() uint16

PointIndex returns the contour point index for a CaretValue (format 2).

type ChainContextPos

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

ChainContextPos represents a Chaining Context Positioning subtable (GPOS Type 8). It matches backtrack, input, and lookahead sequences, then applies nested lookups.

func (*ChainContextPos) Apply

func (ccp *ChainContextPos) Apply(ctx *GPOSContext) bool

Apply applies chaining context positioning.

type ChainContextSubst

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

ChainContextSubst represents a Chaining Context Substitution subtable (GSUB Type 6). It enables substitution based on surrounding context (backtrack, input, lookahead).

func (*ChainContextSubst) Apply

func (ccs *ChainContextSubst) Apply(ctx *GSUBContext) int

Apply applies the chaining context substitution.

type ChainRule

type ChainRule struct {
	Backtrack     []GlyphID      // Backtrack sequence (in reverse order)
	Input         []GlyphID      // Input sequence (starting from second glyph)
	Lookahead     []GlyphID      // Lookahead sequence
	LookupRecords []LookupRecord // Lookups to apply
}

ChainRule represents a single chaining context rule.

type CharStringInterpreter

type CharStringInterpreter struct {

	// Closure tracking
	UsedGlobalSubrs map[int]bool
	UsedLocalSubrs  map[int]bool
	// contains filtered or unexported fields
}

CharStringInterpreter interprets CFF Type 2 CharStrings to find subroutine usage.

func NewCharStringInterpreter

func NewCharStringInterpreter(globalSubrs, localSubrs [][]byte) *CharStringInterpreter

NewCharStringInterpreter creates a new interpreter for finding subroutine usage.

func (*CharStringInterpreter) FindUsedSubroutines

func (i *CharStringInterpreter) FindUsedSubroutines(charstring []byte) error

FindUsedSubroutines executes a CharString to find all subroutine calls. This is a simplified interpreter that only tracks subr calls, not actual drawing.

type ClassDef

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

ClassDef maps glyph IDs to class values.

func ParseClassDef

func ParseClassDef(data []byte, offset int) (*ClassDef, error)

ParseClassDef parses a ClassDef table.

func (*ClassDef) GetClass

func (cd *ClassDef) GetClass(glyph GlyphID) int

GetClass returns the class for a glyph ID. Returns 0 (default class) if glyph not found.

func (*ClassDef) Mapping

func (cd *ClassDef) Mapping() map[GlyphID]uint16

Mapping returns a map from glyph ID to class for all glyphs in this ClassDef.

type Cmap

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

Cmap provides Unicode to glyph ID mapping.

func ParseCmap

func ParseCmap(data []byte) (*Cmap, error)

ParseCmap parses a cmap table.

func (*Cmap) Iter

func (c *Cmap) Iter() CmapIter

Iter returns an iterator over all cmap entries.

func (*Cmap) Lookup

func (c *Cmap) Lookup(cp Codepoint) (GlyphID, bool)

Lookup returns the glyph ID for a codepoint.

func (*Cmap) LookupVariation

func (c *Cmap) LookupVariation(cp Codepoint, vs Codepoint) (GlyphID, bool)

LookupVariation returns the glyph ID for a codepoint with variation selector. Returns the glyph ID and whether a specific variant was found. If no variant is found, falls back to the base codepoint lookup.

type CmapIter

type CmapIter interface {
	Next() bool
	Char() (rune, GlyphID)
}

CmapIter iterates over cmap entries.

type Codepoint

type Codepoint = uint32

Codepoint represents a Unicode codepoint.

type CompositeComponent

type CompositeComponent struct {
	GlyphID GlyphID
	Flags   uint16
	Arg1    int16
	Arg2    int16
	// Transform matrix components (optional)
	Scale   float32
	ScaleX  float32
	ScaleY  float32
	Scale01 float32
	Scale10 float32
}

CompositeComponent represents a component in a composite glyph.

type ContextPos

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

ContextPos represents a Context Positioning subtable (GPOS Type 7). It matches input sequences and applies nested positioning lookups.

func (*ContextPos) Apply

func (cp *ContextPos) Apply(ctx *GPOSContext) bool

Apply applies context positioning.

type ContextRule

type ContextRule struct {
	Input         []GlyphID      // Input sequence (starting from second glyph)
	LookupRecords []LookupRecord // Lookups to apply
}

ContextRule represents a single context rule.

type ContextSubst

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

ContextSubst represents a Context Substitution subtable (GSUB Type 5). It matches input sequences and applies nested lookups.

func (*ContextSubst) Apply

func (cs *ContextSubst) Apply(ctx *GSUBContext) int

Apply applies the context substitution.

type Coverage

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

Coverage represents an OpenType Coverage table. It maps glyph IDs to coverage indices.

func ParseCoverage

func ParseCoverage(data []byte, offset int) (*Coverage, error)

ParseCoverage parses a Coverage table from data at the given offset.

func (*Coverage) GetCoverage

func (c *Coverage) GetCoverage(glyph GlyphID) uint32

GetCoverage returns the coverage index for a glyph ID, or NotCovered if not found.

func (*Coverage) Glyphs

func (c *Coverage) Glyphs() []GlyphID

Glyphs returns all glyphs covered by this coverage table.

type CursivePos

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

CursivePos represents a Cursive Attachment subtable (GPOS Type 3). It connects glyphs in cursive scripts (like Arabic) by aligning exit anchors with entry anchors of adjacent glyphs.

func (*CursivePos) Apply

func (cp *CursivePos) Apply(ctx *GPOSContext) bool

Apply applies cursive positioning. It connects the current glyph's entry anchor to the previous glyph's exit anchor.

func (*CursivePos) Coverage

func (cp *CursivePos) Coverage() *Coverage

Coverage returns the coverage table for this subtable.

func (*CursivePos) EntryExitRecords

func (cp *CursivePos) EntryExitRecords() []EntryExitRecord

EntryExitRecords returns the entry/exit anchor records.

type Direction

type Direction int

Direction represents text direction.

const (
	DirectionInvalid Direction = 0
	DirectionLTR     Direction = 1
	DirectionRTL     Direction = 2
	DirectionTTB     Direction = 3
	DirectionBTT     Direction = 4
)

func GuessDirection

func GuessDirection(s string) Direction

GuessDirection guesses text direction from the content.

func (Direction) IsHorizontal

func (d Direction) IsHorizontal() bool

IsHorizontal returns true if the direction is horizontal (LTR or RTL).

type EntryExitRecord

type EntryExitRecord struct {
	EntryAnchor *Anchor // May be nil
	ExitAnchor  *Anchor // May be nil
}

EntryExitRecord holds entry and exit anchors for cursive attachment.

type Face

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

Face represents a font face with parsed tables for metrics. This is a higher-level abstraction that caches parsed tables.

func LoadFace

func LoadFace(r io.Reader, index int) (*Face, error)

LoadFace loads a font from an io.Reader and returns a Face.

func LoadFaceFromData

func LoadFaceFromData(data []byte, index int) (*Face, error)

LoadFaceFromData loads a font from byte data and returns a Face.

func NewFace

func NewFace(font *Font) (*Face, error)

NewFace creates a new Face from a Font, parsing required tables.

func (*Face) Ascender

func (f *Face) Ascender() int16

Ascender returns the typographic ascender in font units.

func (*Face) BBox

func (f *Face) BBox() (xMin, yMin, xMax, yMax int16)

BBox returns the font bounding box.

func (*Face) CapHeight

func (f *Face) CapHeight() int16

CapHeight returns the cap height in font units.

func (*Face) Cmap

func (f *Face) Cmap() *Cmap

Cmap returns the cmap table.

func (*Face) Descender

func (f *Face) Descender() int16

Descender returns the typographic descender in font units (usually negative).

func (*Face) FamilyName

func (f *Face) FamilyName() string

FamilyName returns the font family name.

func (*Face) GetHExtents

func (f *Face) GetHExtents() FontExtents

GetHExtents returns horizontal font extents.

func (*Face) HorizontalAdvance

func (f *Face) HorizontalAdvance(glyph GlyphID) float32

HorizontalAdvance returns the horizontal advance for a glyph in font units.

func (*Face) IsCFF

func (f *Face) IsCFF() bool

IsCFF returns true if the font uses CFF outlines.

func (*Face) IsFixedPitch

func (f *Face) IsFixedPitch() bool

IsFixedPitch returns true if the font is monospaced.

func (*Face) IsItalic

func (f *Face) IsItalic() bool

IsItalic returns true if the font is italic.

func (*Face) ItalicAngle

func (f *Face) ItalicAngle() int32

ItalicAngle returns the italic angle in degrees (fixed-point 16.16).

func (*Face) LineGap

func (f *Face) LineGap() int16

LineGap returns the line gap in font units.

func (*Face) PostscriptName

func (f *Face) PostscriptName() string

PostscriptName returns the PostScript name of the font.

func (*Face) Upem

func (f *Face) Upem() uint16

Upem returns the units per em.

func (*Face) WeightClass

func (f *Face) WeightClass() uint16

WeightClass returns the font weight class (100-900).

func (*Face) XHeight

func (f *Face) XHeight() int16

XHeight returns the x-height in font units.

type Feature

type Feature struct {
	Tag   Tag    // Feature tag (e.g., TagKern, TagLiga)
	Value uint32 // 0 = off, 1 = on, >1 for alternates
	Start uint   // Cluster start (inclusive), FeatureGlobalStart for beginning
	End   uint   // Cluster end (exclusive), FeatureGlobalEnd for end
}

Feature represents an OpenType feature with optional range. This matches HarfBuzz's hb_feature_t structure.

func DefaultFeatures

func DefaultFeatures() []Feature

DefaultFeatures returns the default features for shaping.

func FeatureFromString

func FeatureFromString(s string) (Feature, bool)

FeatureFromString parses a feature string like HarfBuzz. Supported formats:

  • "kern" -> kern=1 (on)
  • "kern=1" -> kern=1 (on)
  • "kern=0" -> kern=0 (off)
  • "-kern" -> kern=0 (off)
  • "+kern" -> kern=1 (on)
  • "aalt=2" -> aalt=2 (alternate #2)
  • "kern[3:5]" -> kern=1 for clusters 3-5
  • "kern[3:5]=0" -> kern=0 for clusters 3-5
  • "kern[3:]" -> kern=1 from cluster 3 to end
  • "kern[:5]" -> kern=1 from start to cluster 5

Returns false if the string cannot be parsed.

func NewFeature

func NewFeature(tag Tag, value uint32) Feature

NewFeature creates a feature that applies globally (entire buffer).

func NewFeatureOff

func NewFeatureOff(tag Tag) Feature

NewFeatureOff creates a feature that is disabled globally.

func NewFeatureOn

func NewFeatureOn(tag Tag) Feature

NewFeatureOn creates a feature that is enabled globally.

func ParseFeatures

func ParseFeatures(s string) []Feature

ParseFeatures parses a comma-separated list of features.

func (Feature) IsGlobal

func (f Feature) IsGlobal() bool

IsGlobal returns true if the feature applies to the entire buffer.

func (Feature) String

func (f Feature) String() string

String returns a string representation of the feature.

type FeatureList

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

FeatureList represents a GSUB/GPOS FeatureList.

func (*FeatureList) Count

func (f *FeatureList) Count() int

Count returns the number of features.

func (*FeatureList) FindFeature

func (f *FeatureList) FindFeature(tag Tag) []uint16

FindFeature finds a feature by tag and returns its lookup indices.

func (*FeatureList) GetFeature

func (f *FeatureList) GetFeature(index int) (*FeatureRecord, error)

GetFeature returns the feature record at the given index.

type FeatureRecord

type FeatureRecord struct {
	Tag     Tag
	Lookups []uint16
}

FeatureRecord represents a parsed feature record with its lookup indices. This is the internal representation from the font's FeatureList table.

type Font

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

Font represents an OpenType font.

func ParseFont

func ParseFont(data []byte, index int) (*Font, error)

ParseFont parses an OpenType font from data. For TrueType Collections (.ttc), use index to select a font.

func (*Font) HasTable

func (f *Font) HasTable(tag Tag) bool

HasTable returns true if the font has the given table.

func (*Font) NumGlyphs

func (f *Font) NumGlyphs() int

NumGlyphs returns the number of glyphs in the font. Returns 0 if maxp table is missing or invalid.

func (*Font) TableData

func (f *Font) TableData(tag Tag) ([]byte, error)

TableData returns the raw data for a table.

func (*Font) TableParser

func (f *Font) TableParser(tag Tag) (*Parser, error)

TableParser returns a parser for the given table.

type FontDict

type FontDict struct {
	Private [2]int // [size, offset]
}

FontDict contains per-font dictionary data (for CID fonts).

type FontExtents

type FontExtents struct {
	Ascender  int16 // Typographic ascender
	Descender int16 // Typographic descender (usually negative)
	LineGap   int16 // Line spacing gap
}

FontExtents contains font-wide extent values. This matches HarfBuzz's hb_font_extents_t.

type GDEF

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

GDEF represents the Glyph Definition table.

func ParseGDEF

func ParseGDEF(data []byte) (*GDEF, error)

ParseGDEF parses the GDEF table from raw data.

func (*GDEF) GetAttachPoints

func (g *GDEF) GetAttachPoints(glyph GlyphID) []uint16

GetAttachPoints returns the attachment point indices for a glyph. Returns nil if the glyph has no attachment points defined.

func (*GDEF) GetGlyphClass

func (g *GDEF) GetGlyphClass(glyph GlyphID) int

GetGlyphClass returns the glyph class for a glyph ID. Returns GlyphClassUnclassified (0) if no class is defined.

func (*GDEF) GetLigCaretCount

func (g *GDEF) GetLigCaretCount(glyph GlyphID) int

GetLigCaretCount returns the number of caret positions for a ligature glyph. Returns 0 if the glyph has no caret positions defined.

func (*GDEF) GetLigCarets

func (g *GDEF) GetLigCarets(glyph GlyphID) []CaretValue

GetLigCarets returns the caret values for a ligature glyph. Returns nil if the glyph has no caret positions defined.

func (*GDEF) GetMarkAttachClass

func (g *GDEF) GetMarkAttachClass(glyph GlyphID) int

GetMarkAttachClass returns the mark attachment class for a glyph ID. Returns 0 if no class is defined.

func (*GDEF) HasAttachList

func (g *GDEF) HasAttachList() bool

HasAttachList returns true if the GDEF table has an attachment point list.

func (*GDEF) HasGlyphClasses

func (g *GDEF) HasGlyphClasses() bool

HasGlyphClasses returns true if the GDEF table has glyph class definitions.

func (*GDEF) HasLigCaretList

func (g *GDEF) HasLigCaretList() bool

HasLigCaretList returns true if the GDEF table has a ligature caret list.

func (*GDEF) HasMarkAttachClasses

func (g *GDEF) HasMarkAttachClasses() bool

HasMarkAttachClasses returns true if the GDEF table has mark attachment class definitions.

func (*GDEF) HasMarkGlyphSets

func (g *GDEF) HasMarkGlyphSets() bool

HasMarkGlyphSets returns true if the GDEF table has mark glyph sets (version >= 1.2).

func (*GDEF) IsBaseGlyph

func (g *GDEF) IsBaseGlyph(glyph GlyphID) bool

IsBaseGlyph returns true if the glyph is classified as a base glyph.

func (*GDEF) IsComponentGlyph

func (g *GDEF) IsComponentGlyph(glyph GlyphID) bool

IsComponentGlyph returns true if the glyph is classified as a component glyph.

func (*GDEF) IsInMarkGlyphSet

func (g *GDEF) IsInMarkGlyphSet(glyph GlyphID, setIndex int) bool

IsInMarkGlyphSet returns true if the glyph is in the specified mark glyph set.

func (*GDEF) IsLigatureGlyph

func (g *GDEF) IsLigatureGlyph(glyph GlyphID) bool

IsLigatureGlyph returns true if the glyph is classified as a ligature glyph.

func (*GDEF) IsMarkGlyph

func (g *GDEF) IsMarkGlyph(glyph GlyphID) bool

IsMarkGlyph returns true if the glyph is classified as a mark glyph.

func (*GDEF) MarkGlyphSetCount

func (g *GDEF) MarkGlyphSetCount() int

MarkGlyphSetCount returns the number of mark glyph sets.

func (*GDEF) Version

func (g *GDEF) Version() (uint16, uint16)

Version returns the GDEF table version as (major, minor).

type GPOS

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

GPOS represents the Glyph Positioning table.

func ParseGPOS

func ParseGPOS(data []byte) (*GPOS, error)

ParseGPOS parses a GPOS table from data.

func (*GPOS) ApplyKerning

func (g *GPOS) ApplyKerning(glyphs []GlyphID) []GlyphPosition

ApplyKerning is a convenience method to apply pair positioning (kerning). This version does not use GDEF for glyph filtering.

func (*GPOS) ApplyKerningWithGDEF

func (g *GPOS) ApplyKerningWithGDEF(glyphs []GlyphID, gdef *GDEF) []GlyphPosition

ApplyKerningWithGDEF applies pair positioning with GDEF-based glyph filtering.

func (*GPOS) ApplyLookup

func (g *GPOS) ApplyLookup(lookupIndex int, glyphs []GlyphID, positions []GlyphPosition)

ApplyLookup applies a single lookup to the glyph/position arrays. This version does not use GDEF for glyph filtering.

func (*GPOS) ApplyLookupWithDirection

func (g *GPOS) ApplyLookupWithDirection(lookupIndex int, glyphs []GlyphID, positions []GlyphPosition, direction Direction)

ApplyLookupWithDirection applies a single lookup with the specified direction. This version does not use GDEF for glyph filtering.

func (*GPOS) ApplyLookupWithGDEF

func (g *GPOS) ApplyLookupWithGDEF(lookupIndex int, glyphs []GlyphID, positions []GlyphPosition, direction Direction, gdef *GDEF)

ApplyLookupWithGDEF applies a single lookup with GDEF-based glyph filtering.

func (*GPOS) GetLookup

func (g *GPOS) GetLookup(index int) *GPOSLookup

GetLookup returns the lookup at the given index.

func (*GPOS) NumLookups

func (g *GPOS) NumLookups() int

NumLookups returns the number of lookups.

func (*GPOS) ParseFeatureList

func (g *GPOS) ParseFeatureList() (*FeatureList, error)

ParseFeatureList parses a FeatureList from a GPOS table.

type GPOSChainRule

type GPOSChainRule struct {
	Backtrack     []GlyphID          // Backtrack sequence (in reverse order)
	Input         []GlyphID          // Input sequence (starting from second glyph)
	Lookahead     []GlyphID          // Lookahead sequence
	LookupRecords []GPOSLookupRecord // Lookups to apply
}

GPOSChainRule represents a single chaining context positioning rule.

type GPOSContext

type GPOSContext struct {
	Glyphs           []GlyphID
	Positions        []GlyphPosition
	Index            int
	Direction        Direction
	LookupFlag       uint16 // Current lookup flag
	GDEF             *GDEF  // GDEF table for glyph classification (may be nil)
	MarkFilteringSet int    // Mark filtering set index (-1 if not used)
}

GPOSContext provides context for GPOS application.

func (*GPOSContext) AdjustPosition

func (ctx *GPOSContext) AdjustPosition(index int, vr *ValueRecord)

AdjustPosition adjusts the position at the given index.

func (*GPOSContext) NextGlyph

func (ctx *GPOSContext) NextGlyph(startIndex int) int

NextGlyph returns the index of the next glyph that should not be skipped, starting from startIndex. Returns -1 if no such glyph exists.

func (*GPOSContext) PrevGlyph

func (ctx *GPOSContext) PrevGlyph(startIndex int) int

PrevGlyph returns the index of the previous glyph that should not be skipped, starting from startIndex (exclusive). Returns -1 if no such glyph exists.

func (*GPOSContext) ShouldSkipGlyph

func (ctx *GPOSContext) ShouldSkipGlyph(index int) bool

ShouldSkipGlyph returns true if the glyph at the given index should be skipped based on the current LookupFlag and GDEF glyph classification.

type GPOSContextRule

type GPOSContextRule struct {
	Input         []GlyphID          // Input sequence (starting from second glyph)
	LookupRecords []GPOSLookupRecord // Lookups to apply
}

GPOSContextRule represents a single rule in a context positioning rule set.

type GPOSLookup

type GPOSLookup struct {
	Type uint16
	Flag uint16

	MarkFilter uint16
	// contains filtered or unexported fields
}

GPOSLookup represents a GPOS lookup table.

func (*GPOSLookup) Subtables

func (l *GPOSLookup) Subtables() []GPOSSubtable

Subtables returns the subtables for this lookup.

type GPOSLookupRecord

type GPOSLookupRecord struct {
	SequenceIndex uint16 // Index into current glyph sequence (0-based)
	LookupIndex   uint16 // Lookup to apply
}

GPOSLookupRecord represents a lookup to apply at a specific position in a context.

type GPOSSubtable

type GPOSSubtable interface {
	// Apply applies the positioning to the glyphs at the current position.
	// Returns true if positioning was applied.
	Apply(ctx *GPOSContext) bool
}

GPOSSubtable is the interface for GPOS lookup subtables.

type GSUB

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

GSUB represents the Glyph Substitution table.

func ParseGSUB

func ParseGSUB(data []byte) (*GSUB, error)

ParseGSUB parses a GSUB table from data.

func (*GSUB) ApplyFeature

func (g *GSUB) ApplyFeature(tag Tag, glyphs []GlyphID) []GlyphID

ApplyFeature applies all lookups for a feature to the glyph sequence. This version does not use GDEF for glyph filtering.

func (*GSUB) ApplyFeatureWithGDEF

func (g *GSUB) ApplyFeatureWithGDEF(tag Tag, glyphs []GlyphID, gdef *GDEF) []GlyphID

ApplyFeatureWithGDEF applies all lookups for a feature with GDEF-based glyph filtering.

func (*GSUB) ApplyLookup

func (g *GSUB) ApplyLookup(lookupIndex int, glyphs []GlyphID) []GlyphID

ApplyLookup applies a single lookup to the glyph sequence. This version does not use GDEF for glyph filtering.

func (*GSUB) ApplyLookupReverse

func (g *GSUB) ApplyLookupReverse(lookupIndex int, glyphs []GlyphID) []GlyphID

ApplyLookupReverse applies this lookup in reverse order through the glyph buffer. This is the intended way to use ReverseChainSingleSubst. This version does not use GDEF for glyph filtering.

func (*GSUB) ApplyLookupReverseWithGDEF

func (g *GSUB) ApplyLookupReverseWithGDEF(lookupIndex int, glyphs []GlyphID, gdef *GDEF) []GlyphID

ApplyLookupReverseWithGDEF applies this lookup in reverse order with GDEF-based glyph filtering.

func (*GSUB) ApplyLookupWithGDEF

func (g *GSUB) ApplyLookupWithGDEF(lookupIndex int, glyphs []GlyphID, gdef *GDEF) []GlyphID

ApplyLookupWithGDEF applies a single lookup with GDEF-based glyph filtering.

func (*GSUB) GetLookup

func (g *GSUB) GetLookup(index int) *GSUBLookup

GetLookup returns the lookup at the given index.

func (*GSUB) NumLookups

func (g *GSUB) NumLookups() int

NumLookups returns the number of lookups in the GSUB table.

func (*GSUB) ParseFeatureList

func (g *GSUB) ParseFeatureList() (*FeatureList, error)

ParseFeatureList parses a FeatureList from a GSUB/GPOS table.

type GSUBContext

type GSUBContext struct {
	Glyphs []GlyphID // Current glyph sequence
	Index  int       // Current position

	// Lookup filtering
	LookupFlag       uint16 // Current lookup flag
	GDEF             *GDEF  // GDEF table for glyph classification (may be nil)
	MarkFilteringSet int    // Mark filtering set index (-1 if not used)

	// Output callbacks
	OnReplace  func(index int, newGlyph GlyphID)
	OnReplaces func(index int, newGlyphs []GlyphID)
	OnDelete   func(index int)
	OnLigate   func(index int, ligGlyph GlyphID, numGlyphs int)
}

GSUBContext provides context for GSUB application.

func (*GSUBContext) DeleteGlyph

func (ctx *GSUBContext) DeleteGlyph()

DeleteGlyph deletes the current glyph.

func (*GSUBContext) Ligate

func (ctx *GSUBContext) Ligate(ligGlyph GlyphID, numGlyphs int)

Ligate replaces numGlyphs at current position with a ligature.

func (*GSUBContext) NextGlyph

func (ctx *GSUBContext) NextGlyph(startIndex int) int

NextGlyph returns the index of the next glyph that should not be skipped, starting from startIndex. Returns -1 if no such glyph exists.

func (*GSUBContext) PrevGlyph

func (ctx *GSUBContext) PrevGlyph(startIndex int) int

PrevGlyph returns the index of the previous glyph that should not be skipped, starting from startIndex (exclusive). Returns -1 if no such glyph exists.

func (*GSUBContext) ReplaceGlyph

func (ctx *GSUBContext) ReplaceGlyph(newGlyph GlyphID)

ReplaceGlyph replaces the current glyph.

func (*GSUBContext) ReplaceGlyphs

func (ctx *GSUBContext) ReplaceGlyphs(newGlyphs []GlyphID)

ReplaceGlyphs replaces the current glyph with multiple glyphs.

func (*GSUBContext) ShouldSkipGlyph

func (ctx *GSUBContext) ShouldSkipGlyph(index int) bool

ShouldSkipGlyph returns true if the glyph at the given index should be skipped based on the current LookupFlag and GDEF glyph classification.

type GSUBLookup

type GSUBLookup struct {
	Type uint16
	Flag uint16

	MarkFilter uint16 // For flag & 0x10
	// contains filtered or unexported fields
}

GSUBLookup represents a GSUB lookup table.

func (*GSUBLookup) Subtables

func (l *GSUBLookup) Subtables() []GSUBSubtable

Subtables returns the lookup subtables.

type GSUBSubtable

type GSUBSubtable interface {
	// Apply applies the substitution to the glyph at the current position.
	// Returns the number of glyphs consumed (0 if not applied).
	Apply(ctx *GSUBContext) int
}

GSUBSubtable is the interface for GSUB lookup subtables.

type Glyf

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

Glyf represents the parsed glyf table (glyph data).

func ParseGlyf

func ParseGlyf(data []byte, loca *Loca) (*Glyf, error)

ParseGlyf parses the glyf table using a loca table.

func ParseGlyfFromFont

func ParseGlyfFromFont(font *Font) (*Glyf, error)

ParseGlyfFromFont parses both glyf and loca tables from a font.

func (*Glyf) GetComponents

func (g *Glyf) GetComponents(gid GlyphID) []GlyphID

GetComponents returns the component glyph IDs for a composite glyph. For simple glyphs, returns nil.

func (*Glyf) GetGlyph

func (g *Glyf) GetGlyph(gid GlyphID) *GlyphData

GetGlyph returns the glyph data for a glyph ID.

func (*Glyf) GetGlyphBytes

func (g *Glyf) GetGlyphBytes(gid GlyphID) []byte

GetGlyphBytes returns the raw bytes for a glyph.

type GlyphData

type GlyphData struct {
	Data             []byte
	NumberOfContours int16 // -1 for composite, >= 0 for simple
}

GlyphData represents the raw data for a single glyph.

func (*GlyphData) IsComposite

func (gd *GlyphData) IsComposite() bool

IsComposite returns true if the glyph is a composite glyph.

type GlyphExtents

type GlyphExtents struct {
	XBearing int16 // Left side of glyph from origin
	YBearing int16 // Top side of glyph from origin
	Width    int16 // Width of glyph
	Height   int16 // Height of glyph (usually negative)
}

GlyphExtents contains glyph extent values.

type GlyphID

type GlyphID = uint16

GlyphID represents a glyph index.

type GlyphInfo

type GlyphInfo struct {
	Codepoint  Codepoint // Original Unicode codepoint (0 if synthetic)
	GlyphID    GlyphID   // Glyph index in the font
	Cluster    int       // Cluster index (maps back to original text position)
	GlyphClass int       // GDEF glyph class (if available)
}

GlyphInfo holds information about a shaped glyph.

type GlyphPos

type GlyphPos struct {
	XAdvance int16 // Horizontal advance
	YAdvance int16 // Vertical advance
	XOffset  int16 // Horizontal offset
	YOffset  int16 // Vertical offset
}

GlyphPos holds positioning information for a shaped glyph.

type GlyphPosition

type GlyphPosition struct {
	XPlacement int16
	YPlacement int16
	XAdvance   int16
	YAdvance   int16
	// For mark attachment
	XOffset     int16 // Additional X offset (for marks)
	YOffset     int16 // Additional Y offset (for marks)
	AttachType  uint8 // Type of attachment (0=none, 1=mark, 2=cursive)
	AttachChain int16 // Offset to attached glyph (negative = before)
}

GlyphPosition holds positioning information for a glyph.

type Head struct {
	Version            uint32
	FontRevision       uint32
	CheckSumAdjustment uint32
	MagicNumber        uint32
	Flags              uint16
	UnitsPerEm         uint16
	Created            int64
	Modified           int64
	XMin               int16
	YMin               int16
	XMax               int16
	YMax               int16
	MacStyle           uint16
	LowestRecPPEM      uint16
	FontDirectionHint  int16
	IndexToLocFormat   int16
	GlyphDataFormat    int16
}

Head represents the font header table.

func ParseHead

func ParseHead(data []byte) (*Head, error)

ParseHead parses the head table.

type Hhea

type Hhea struct {
	Version             uint32
	Ascender            int16
	Descender           int16
	LineGap             int16
	AdvanceWidthMax     uint16
	MinLeftSideBearing  int16
	MinRightSideBearing int16
	XMaxExtent          int16
	CaretSlopeRise      int16
	CaretSlopeRun       int16
	CaretOffset         int16
	MetricDataFormat    int16
	NumberOfHMetrics    uint16
}

Hhea represents the horizontal header table.

func ParseHhea

func ParseHhea(data []byte) (*Hhea, error)

ParseHhea parses the hhea (horizontal header) table.

type Hmtx

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

Hmtx represents the horizontal metrics table.

func ParseHmtx

func ParseHmtx(data []byte, numberOfHMetrics, numGlyphs int) (*Hmtx, error)

ParseHmtx parses the hmtx table. It requires numberOfHMetrics from hhea and numGlyphs from maxp.

func ParseHmtxFromFont

func ParseHmtxFromFont(font *Font) (*Hmtx, error)

ParseHmtxFromFont is a convenience function that parses hmtx from a font, automatically reading hhea and maxp for required values.

func (*Hmtx) GetAdvanceWidth

func (h *Hmtx) GetAdvanceWidth(glyph GlyphID) uint16

GetAdvanceWidth returns the advance width for a glyph.

func (*Hmtx) GetLsb

func (h *Hmtx) GetLsb(glyph GlyphID) int16

GetLsb returns the left side bearing for a glyph.

func (*Hmtx) GetMetrics

func (h *Hmtx) GetMetrics(glyph GlyphID) (advanceWidth uint16, lsb int16)

GetMetrics returns both advance width and lsb for a glyph.

type LigCaretList

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

LigCaretList contains ligature caret positions.

type LigGlyph

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

LigGlyph contains caret values for a ligature glyph.

type Ligature

type Ligature struct {
	LigGlyph   GlyphID   // The resulting ligature glyph
	Components []GlyphID // Component glyphs (starting from second)
}

Ligature represents a single ligature rule.

type LigatureArray

type LigatureArray struct {
	Attachments []*LigatureAttach
}

LigatureArray contains LigatureAttach tables for multiple ligatures.

type LigatureAttach

type LigatureAttach struct {
	ComponentCount int         // Number of ligature components
	ClassCount     int         // Number of mark classes
	Anchors        [][]*Anchor // [component][class] -> Anchor (may be nil)
}

LigatureAttach contains anchors for one ligature glyph. It's organized as a matrix where: - Rows correspond to ligature components (in writing order) - Columns correspond to mark classes

func (*LigatureAttach) GetAnchor

func (la *LigatureAttach) GetAnchor(componentIndex, markClass int) *Anchor

GetAnchor returns the anchor for a given component index and mark class.

type LigatureSubst

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

LigatureSubst represents a Ligature Substitution subtable.

func (*LigatureSubst) Apply

func (l *LigatureSubst) Apply(ctx *GSUBContext) int

Apply applies the ligature substitution.

func (*LigatureSubst) Coverage

func (l *LigatureSubst) Coverage() *Coverage

Coverage returns the coverage table.

func (*LigatureSubst) LigatureSets

func (l *LigatureSubst) LigatureSets() [][]Ligature

LigatureSets returns the ligature sets.

type Loca

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

Loca represents the parsed loca table (index to location).

func ParseLoca

func ParseLoca(data []byte, numGlyphs int, indexToLocFormat int16) (*Loca, error)

ParseLoca parses the loca table. indexToLocFormat: 0 = short (16-bit), 1 = long (32-bit)

func (*Loca) GetOffset

func (l *Loca) GetOffset(gid GlyphID) (uint32, uint32, bool)

GetOffset returns the offset and length for a glyph. Returns (offset, length, ok)

func (*Loca) IsShort

func (l *Loca) IsShort() bool

IsShort returns true if using short (16-bit) format.

func (*Loca) NumGlyphs

func (l *Loca) NumGlyphs() int

NumGlyphs returns the number of glyphs.

type LongHorMetric

type LongHorMetric struct {
	AdvanceWidth uint16
	Lsb          int16 // Left side bearing
}

LongHorMetric contains the advance width and left side bearing for a glyph.

type LookupRecord

type LookupRecord struct {
	SequenceIndex uint16 // Index into current glyph sequence (0-based)
	LookupIndex   uint16 // Lookup to apply
}

LookupRecord specifies a lookup to apply at a specific position.

type MarkArray

type MarkArray struct {
	Records []MarkRecord
}

MarkArray contains an array of MarkRecords.

type MarkBasePos

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

MarkBasePos represents a Mark-to-Base Attachment subtable (GPOS Type 4). It positions mark glyphs relative to base glyphs using anchor points.

func (*MarkBasePos) Apply

func (m *MarkBasePos) Apply(ctx *GPOSContext) bool

Apply applies the mark-to-base positioning. It finds the preceding base glyph and positions the current mark relative to it.

func (*MarkBasePos) BaseArray

func (m *MarkBasePos) BaseArray() *BaseArray

BaseArray returns the base array.

func (*MarkBasePos) BaseCoverage

func (m *MarkBasePos) BaseCoverage() *Coverage

BaseCoverage returns the base coverage table.

func (*MarkBasePos) ClassCount

func (m *MarkBasePos) ClassCount() uint16

ClassCount returns the number of mark classes.

func (*MarkBasePos) MarkArray

func (m *MarkBasePos) MarkArray() *MarkArray

MarkArray returns the mark array.

func (*MarkBasePos) MarkCoverage

func (m *MarkBasePos) MarkCoverage() *Coverage

MarkCoverage returns the mark coverage table.

type MarkGlyphSetsDef

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

MarkGlyphSetsDef contains mark glyph set definitions.

type MarkLigPos

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

MarkLigPos represents a Mark-to-Ligature Attachment subtable (GPOS Type 5). It positions mark glyphs relative to ligature glyphs. Each ligature can have multiple components, and each component has its own anchor points.

func (*MarkLigPos) Apply

func (m *MarkLigPos) Apply(ctx *GPOSContext) bool

Apply applies the mark-to-ligature positioning. It finds the preceding ligature glyph and positions the current mark relative to the appropriate ligature component.

func (*MarkLigPos) ApplyWithComponent

func (m *MarkLigPos) ApplyWithComponent(ctx *GPOSContext, componentIndex int) bool

ApplyWithComponent applies the mark-to-ligature positioning with a specific component. If componentIndex is -1, it defaults to the last component.

func (*MarkLigPos) ClassCount

func (m *MarkLigPos) ClassCount() uint16

ClassCount returns the number of mark classes.

func (*MarkLigPos) LigatureArray

func (m *MarkLigPos) LigatureArray() *LigatureArray

LigatureArray returns the ligature array.

func (*MarkLigPos) LigatureCoverage

func (m *MarkLigPos) LigatureCoverage() *Coverage

LigatureCoverage returns the ligature coverage table.

func (*MarkLigPos) MarkArray

func (m *MarkLigPos) MarkArray() *MarkArray

MarkArray returns the mark array.

func (*MarkLigPos) MarkCoverage

func (m *MarkLigPos) MarkCoverage() *Coverage

MarkCoverage returns the mark coverage table.

type MarkMarkPos

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

MarkMarkPos represents a Mark-to-Mark Attachment subtable (GPOS Type 6). It positions mark glyphs (mark1) relative to preceding mark glyphs (mark2). This is used for stacking diacritics, e.g., placing an accent on top of another accent.

func (*MarkMarkPos) Apply

func (m *MarkMarkPos) Apply(ctx *GPOSContext) bool

Apply applies the mark-to-mark positioning. It finds the preceding mark glyph (mark2) and positions the current mark (mark1) relative to it.

func (*MarkMarkPos) ClassCount

func (m *MarkMarkPos) ClassCount() uint16

ClassCount returns the number of mark classes.

func (*MarkMarkPos) Mark1Array

func (m *MarkMarkPos) Mark1Array() *MarkArray

Mark1Array returns the mark array for mark1 glyphs.

func (*MarkMarkPos) Mark1Coverage

func (m *MarkMarkPos) Mark1Coverage() *Coverage

Mark1Coverage returns the coverage table for the attaching mark (mark1).

func (*MarkMarkPos) Mark2Array

func (m *MarkMarkPos) Mark2Array() *BaseArray

Mark2Array returns the anchor array for mark2 glyphs.

func (*MarkMarkPos) Mark2Coverage

func (m *MarkMarkPos) Mark2Coverage() *Coverage

Mark2Coverage returns the coverage table for the base mark (mark2).

type MarkRecord

type MarkRecord struct {
	Class  uint16  // Mark class
	Anchor *Anchor // Anchor for this mark
}

MarkRecord associates a mark glyph with a class and anchor.

type MultipleSubst

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

MultipleSubst represents a Multiple Substitution subtable (1 -> n).

func (*MultipleSubst) Apply

func (m *MultipleSubst) Apply(ctx *GSUBContext) int

Apply applies the multiple substitution.

func (*MultipleSubst) Mapping

func (m *MultipleSubst) Mapping() map[GlyphID][]GlyphID

Mapping returns the input->output mapping for glyph closure computation.

type Name

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

Name represents the name table.

func ParseName

func ParseName(data []byte) (*Name, error)

ParseName parses the name table.

func (*Name) FamilyName

func (n *Name) FamilyName() string

FamilyName returns the font family name (nameID 1).

func (*Name) FullName

func (n *Name) FullName() string

FullName returns the full font name (nameID 4).

func (*Name) Get

func (n *Name) Get(nameID uint16) string

Get returns the string for a nameID.

func (*Name) PostScriptName

func (n *Name) PostScriptName() string

PostScriptName returns the PostScript name (nameID 6).

type OS2

type OS2 struct {
	Version             uint16
	XAvgCharWidth       int16
	UsWeightClass       uint16
	UsWidthClass        uint16
	FsType              uint16
	YSubscriptXSize     int16
	YSubscriptYSize     int16
	YSubscriptXOffset   int16
	YSubscriptYOffset   int16
	YSuperscriptXSize   int16
	YSuperscriptYSize   int16
	YSuperscriptXOffset int16
	YSuperscriptYOffset int16
	YStrikeoutSize      int16
	YStrikeoutPosition  int16
	SFamilyClass        int16
	Panose              [10]byte
	UlUnicodeRange1     uint32
	UlUnicodeRange2     uint32
	UlUnicodeRange3     uint32
	UlUnicodeRange4     uint32
	AchVendID           [4]byte
	FsSelection         uint16
	UsFirstCharIndex    uint16
	UsLastCharIndex     uint16
	STypoAscender       int16
	STypoDescender      int16
	STypoLineGap        int16
	UsWinAscent         uint16
	UsWinDescent        uint16
	// Version 1+
	UlCodePageRange1 uint32
	UlCodePageRange2 uint32
	// Version 2+
	SxHeight      int16
	SCapHeight    int16
	UsDefaultChar uint16
	UsBreakChar   uint16
	UsMaxContext  uint16
}

OS2 represents the OS/2 table.

func ParseOS2

func ParseOS2(data []byte) (*OS2, error)

ParseOS2 parses the OS/2 table.

type PairClassRecord

type PairClassRecord struct {
	Value1 ValueRecord
	Value2 ValueRecord
}

PairClassRecord holds positioning values for a class pair.

type PairPos

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

PairPos represents a Pair Positioning subtable.

func (*PairPos) Apply

func (pp *PairPos) Apply(ctx *GPOSContext) bool

Apply applies pair positioning (kerning).

func (*PairPos) Class1Count

func (pp *PairPos) Class1Count() uint16

Class1Count returns the number of classes for first glyphs (format 2 only).

func (*PairPos) Class2Count

func (pp *PairPos) Class2Count() uint16

Class2Count returns the number of classes for second glyphs (format 2 only).

func (*PairPos) ClassDef1

func (pp *PairPos) ClassDef1() *ClassDef

ClassDef1 returns the class definition for first glyphs (format 2 only).

func (*PairPos) ClassDef2

func (pp *PairPos) ClassDef2() *ClassDef

ClassDef2 returns the class definition for second glyphs (format 2 only).

func (*PairPos) ClassMatrix

func (pp *PairPos) ClassMatrix() [][]PairClassRecord

ClassMatrix returns the class matrix (format 2 only).

func (*PairPos) Coverage

func (pp *PairPos) Coverage() *Coverage

Coverage returns the coverage table for this subtable.

func (*PairPos) Format

func (pp *PairPos) Format() uint16

Format returns the subtable format (1 or 2).

func (*PairPos) PairSets

func (pp *PairPos) PairSets() [][]PairValueRecord

PairSets returns the pair sets (format 1 only).

func (*PairPos) ValueFormat1

func (pp *PairPos) ValueFormat1() uint16

ValueFormat1 returns the value format for the first glyph.

func (*PairPos) ValueFormat2

func (pp *PairPos) ValueFormat2() uint16

ValueFormat2 returns the value format for the second glyph.

type PairValueRecord

type PairValueRecord struct {
	SecondGlyph GlyphID
	Value1      ValueRecord
	Value2      ValueRecord
}

PairValueRecord holds a pair of glyphs and their positioning values.

type Parser

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

Parser provides methods for reading binary OpenType data.

func NewParser

func NewParser(data []byte) *Parser

NewParser creates a parser for the given data.

func (*Parser) Bytes

func (p *Parser) Bytes(n int) ([]byte, error)

Bytes returns n bytes at the current offset and advances.

func (*Parser) Data

func (p *Parser) Data() []byte

Data returns the underlying byte slice.

func (*Parser) I16

func (p *Parser) I16() (int16, error)

I16 reads a big-endian int16 and advances.

func (*Parser) I16At

func (p *Parser) I16At(off int) (int16, error)

I16At reads a big-endian int16 at the given offset (doesn't advance).

func (*Parser) I32

func (p *Parser) I32() (int32, error)

I32 reads a big-endian int32 and advances.

func (*Parser) Offset

func (p *Parser) Offset() int

Offset returns the current offset.

func (*Parser) Remaining

func (p *Parser) Remaining() int

Remaining returns the number of bytes remaining.

func (*Parser) SetOffset

func (p *Parser) SetOffset(off int) error

SetOffset sets the current offset.

func (*Parser) Skip

func (p *Parser) Skip(n int) error

Skip advances the offset by n bytes.

func (*Parser) SubParser

func (p *Parser) SubParser(off, length int) (*Parser, error)

SubParser returns a parser for a sub-range of the data.

func (*Parser) SubParserFromOffset

func (p *Parser) SubParserFromOffset(off int) (*Parser, error)

SubParserFromOffset returns a parser starting at off to end of data.

func (*Parser) Tag

func (p *Parser) Tag() (Tag, error)

Tag reads a 4-byte tag and advances.

func (*Parser) U8

func (p *Parser) U8() (uint8, error)

U8 reads a uint8 and advances.

func (*Parser) U16

func (p *Parser) U16() (uint16, error)

U16 reads a big-endian uint16 and advances.

func (*Parser) U16At

func (p *Parser) U16At(off int) (uint16, error)

U16At reads a big-endian uint16 at the given offset (doesn't advance).

func (*Parser) U32

func (p *Parser) U32() (uint32, error)

U32 reads a big-endian uint32 and advances.

func (*Parser) U32At

func (p *Parser) U32At(off int) (uint32, error)

U32At reads a big-endian uint32 at the given offset (doesn't advance).

type Post

type Post struct {
	Version            uint32
	ItalicAngle        int32 // Fixed-point 16.16
	UnderlinePosition  int16
	UnderlineThickness int16
	IsFixedPitch       uint32
}

Post represents the post table.

func ParsePost

func ParsePost(data []byte) (*Post, error)

ParsePost parses the post table (minimal parsing for metrics).

func (*Post) ItalicAngleDegrees

func (p *Post) ItalicAngleDegrees() float64

ItalicAngleDegrees returns the italic angle in degrees.

type PrivateDict

type PrivateDict struct {
	BlueValues       []int
	OtherBlues       []int
	FamilyBlues      []int
	FamilyOtherBlues []int
	StdHW            int
	StdVW            int
	Subrs            int // Offset to Local Subrs (relative to Private DICT)
	DefaultWidthX    int
	NominalWidthX    int
	BlueScale        float64
	BlueShift        int
	BlueFuzz         int
}

PrivateDict contains private dictionary data.

type ReverseChainSingleSubst

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

ReverseChainSingleSubst represents a Reverse Chaining Context Single Substitution subtable (GSUB Type 8). It is designed to be applied in reverse (from end to beginning of buffer). Unlike ChainContextSubst, it only performs single glyph substitution (no nested lookups).

func (*ReverseChainSingleSubst) Apply

func (r *ReverseChainSingleSubst) Apply(ctx *GSUBContext) int

Apply applies the reverse chaining context single substitution. This lookup is intended to be applied in reverse (from end to beginning of buffer). It replaces the current glyph if it matches the coverage and context.

type Shaper

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

Shaper holds font data and performs text shaping.

func NewShaper

func NewShaper(font *Font) (*Shaper, error)

NewShaper creates a shaper from a parsed font.

func (*Shaper) Font

func (s *Shaper) Font() *Font

Font returns the font associated with this shaper.

func (*Shaper) GDEF

func (s *Shaper) GDEF() *GDEF

GDEF returns the GDEF table (may be nil).

func (*Shaper) GetDefaultFeatures

func (s *Shaper) GetDefaultFeatures() []Feature

DefaultFeatures returns the current default features.

func (*Shaper) HasGDEF

func (s *Shaper) HasGDEF() bool

HasGDEF returns true if the shaper has GDEF data.

func (*Shaper) HasGPOS

func (s *Shaper) HasGPOS() bool

HasGPOS returns true if the shaper has GPOS data.

func (*Shaper) HasGSUB

func (s *Shaper) HasGSUB() bool

HasGSUB returns true if the shaper has GSUB data.

func (*Shaper) HasHmtx

func (s *Shaper) HasHmtx() bool

HasHmtx returns true if the shaper has hmtx data.

func (*Shaper) SetDefaultFeatures

func (s *Shaper) SetDefaultFeatures(features []Feature)

SetDefaultFeatures sets the default features to apply when Shape is called with nil.

func (*Shaper) Shape

func (s *Shaper) Shape(buf *Buffer, features []Feature)

Shape shapes the text in the buffer using the specified features. If features is nil, default features are used. This is the main shaping entry point, similar to HarfBuzz's hb_shape().

func (*Shaper) ShapeString

func (s *Shaper) ShapeString(text string) ([]GlyphID, []GlyphPos)

ShapeString is a convenience function that shapes a string and returns the glyph IDs and positions.

type SinglePos

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

SinglePos represents a Single Positioning subtable.

func (*SinglePos) Apply

func (sp *SinglePos) Apply(ctx *GPOSContext) bool

Apply applies single positioning.

func (*SinglePos) Coverage

func (sp *SinglePos) Coverage() *Coverage

Coverage returns the coverage table for this subtable.

func (*SinglePos) Format

func (sp *SinglePos) Format() uint16

Format returns the subtable format (1 or 2).

func (*SinglePos) ValueFormat

func (sp *SinglePos) ValueFormat() uint16

ValueFormat returns the value format flags.

func (*SinglePos) ValueRecord

func (sp *SinglePos) ValueRecord() ValueRecord

ValueRecord returns the value record (format 1 only).

func (*SinglePos) ValueRecords

func (sp *SinglePos) ValueRecords() []ValueRecord

ValueRecords returns the per-glyph value records (format 2 only).

type SingleSubst

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

SingleSubst represents a Single Substitution subtable.

func (*SingleSubst) Apply

func (s *SingleSubst) Apply(ctx *GSUBContext) int

Apply applies the single substitution.

func (*SingleSubst) Mapping

func (s *SingleSubst) Mapping() map[GlyphID]GlyphID

Mapping returns all input->output glyph mappings for this substitution.

type Tag

type Tag uint32

Tag is a 4-byte OpenType tag.

func MakeTag

func MakeTag(a, b, c, d byte) Tag

MakeTag creates a Tag from 4 bytes.

func (Tag) String

func (t Tag) String() string

String returns the tag as a 4-character string.

type TopDict

type TopDict struct {
	Version     int // SID
	Notice      int // SID
	FullName    int // SID
	FamilyName  int // SID
	Weight      int // SID
	FontBBox    [4]int
	CharStrings int    // Offset to CharStrings INDEX
	Private     [2]int // [size, offset]
	Charset     int    // Offset to Charset
	Encoding    int    // Offset to Encoding

	// CID fonts
	ROS      [3]int // Registry, Ordering, Supplement (SIDs)
	FDArray  int
	FDSelect int
	IsCID    bool
}

TopDict contains top-level font dictionary data.

type ValueRecord

type ValueRecord struct {
	XPlacement int16 // Horizontal adjustment for placement
	YPlacement int16 // Vertical adjustment for placement
	XAdvance   int16 // Horizontal adjustment for advance
	YAdvance   int16 // Vertical adjustment for advance
}

ValueRecord holds positioning values.

func (*ValueRecord) IsZero

func (vr *ValueRecord) IsZero() bool

IsZero returns true if all values are zero.

Jump to

Keyboard shortcuts

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