fonts

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeClosureGSUB

func ComputeClosureGSUB(fontData []byte, initialGIDs map[int]bool) (map[int]bool, error)

ComputeClosureGSUB computes the transitive closure of glyphs reachable via GSUB substitutions.

func ExtractTable

func ExtractTable(data []byte, table OpenTypeTable) ([]byte, error)

ExtractTable returns the raw data of a specific table.

func LoadOpenType

func LoadOpenType(name string, data []byte) (*semantic.Font, error)

LoadOpenType parses an OpenType font (CFF or TrueType outlines). If it contains CFF outlines, it extracts the CFF table and embeds it as FontFile3.

func LoadTrueType

func LoadTrueType(name string, data []byte) (*semantic.Font, error)

LoadTrueType parses a TrueType/OpenType font, extracts basic metrics, and returns a semantic.Font configured for Type0 Identity-H usage with a FontFile2 stream. The full font is embedded (no subsetting).

func ParseOpenTypeTableDirectory

func ParseOpenTypeTableDirectory(data []byte) (map[string]OpenTypeTable, error)

ParseOpenTypeTableDirectory parses the header and table directory of an OpenType/TrueType font.

func ParseType1

func ParseType1(name string, pfbData []byte) (*semantic.Font, error)

ParseType1 parses PFB (font data) and returns a semantic.Font. It extracts metrics from the ASCII segment of the PFB.

func SubsetTrueType

func SubsetTrueType(data []byte, usedGIDs map[int]bool) ([]byte, error)

SubsetTrueType subsets a TrueType font file, keeping only the specified GIDs. It performs a sparse subsetting: GIDs are preserved (Identity-H compatible), but unused glyph data is removed from the 'glyf' table.

Types

type Analyzer

type Analyzer struct {
	// Map of font -> set of used CIDs/codes
	UsedGlyphs map[*semantic.Font]map[int]bool
	// TextRuns records per-font script-aware runs derived from ToUnicode mappings.
	TextRuns map[*semantic.Font][]TextRun
}

Analyzer identifies used glyphs in a document.

func NewAnalyzer

func NewAnalyzer() *Analyzer

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(doc *semantic.Document)

type CFF

type CFF struct {
	Header   CFFHeader
	Names    []string
	TopDicts []map[int][]Operand // Key is operator, value is operands
	Strings  []string
}

CFF represents a parsed Compact Font Format structure.

func ParseCFF

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

ParseCFF parses the CFF data.

type CFFHeader

type CFFHeader struct {
	Major   uint8
	Minor   uint8
	HdrSize uint8
	OffSize uint8
}

type OpenTypeTable

type OpenTypeTable struct {
	Tag      string
	CheckSum uint32
	Offset   uint32
	Length   uint32
}

OpenTypeTable represents an entry in the OpenType table directory.

type Operand

type Operand struct {
	Int   int
	Float float64
	IsInt bool
}

type Planner

type Planner struct {
	Subsets map[*semantic.Font]*Subset
}

func NewPlanner

func NewPlanner() *Planner

func (*Planner) Plan

func (p *Planner) Plan(analyzer *Analyzer)

type ShapedGlyph

type ShapedGlyph struct {
	ID       int
	XAdvance float64 // In PDF text units (1/1000 em)
	YAdvance float64
	XOffset  float64
	YOffset  float64
}

ShapedGlyph represents a single shaped glyph with positioning information.

func ShapeText

func ShapeText(text string, font *semantic.Font) ([]ShapedGlyph, error)

ShapeText shapes the given text using the provided font and returns the glyphs and positioning.

type Subset

type Subset struct {
	OriginalToSubset map[int]int // Map original CID -> new CID (identity for now)
	SubsetToOriginal map[int]int // Map new CID -> original CID
	UsedCIDs         []int       // List of used CIDs
	GlyphSet         map[int]bool
}

type Subsetter

type Subsetter struct{}

Subsetter applies the subsetting plan to the fonts.

func NewSubsetter

func NewSubsetter() *Subsetter

func (*Subsetter) Apply

func (s *Subsetter) Apply(doc *semantic.Document, planner *Planner)

type TextRun

type TextRun struct {
	Runes  []rune
	Script language.Script
}

TextRun stores a contiguous set of runes that share the same script.

Jump to

Keyboard shortcuts

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