Documentation
¶
Overview ¶
Package font defines host-supplied font inputs and parsed font sets.
Index ¶
- type Assembly
- type AssemblyPart
- type Bounds
- type FaceInfo
- type FaceRef
- type Feature
- type FontFace
- type FontOption
- type FontSet
- func (f *FontSet) Config() FontSetConfig
- func (f *FontSet) Face(ref FaceRef) (FaceInfo, bool)
- func (f *FontSet) FaceCount() int
- func (f *FontSet) Features(ref FaceRef) ([]string, bool)
- func (f *FontSet) GlyphAdvance(g Glyph) (int32, bool)
- func (f *FontSet) GlyphMetrics(g Glyph) (GlyphMetrics, bool)
- func (f *FontSet) HasFeature(ref FaceRef, tag string) bool
- func (f *FontSet) IsExtendedShape(g Glyph) (bool, bool)
- func (f *FontSet) ItalicCorrection(g Glyph) (int32, bool)
- func (f *FontSet) Key() uint64
- func (f *FontSet) KeySHA256() [32]byte
- func (f *FontSet) MapRune(ref FaceRef, r rune) (Glyph, bool)
- func (f *FontSet) MapVariation(ref FaceRef, r, selector rune) (Glyph, bool)
- func (f *FontSet) MathConstant(ref FaceRef, c MathConstant) (int32, bool)
- func (f *FontSet) MathConstruction(g Glyph, axis MathAxis) (MathConstruction, bool)
- func (f *FontSet) MathKern(g Glyph, corner MathKernCorner, correctionHeight int32) int32
- func (f *FontSet) MathKernCurve(g Glyph, corner MathKernCorner) (KernCurve, bool)
- func (f *FontSet) Outline(g Glyph) (Outline, bool)
- func (f *FontSet) Shape(ref FaceRef, glyphs []GlyphID, features ...Feature) ([]GlyphID, bool)
- func (f *FontSet) ShapeMath(ref FaceRef, glyphs []GlyphID, style MathScriptStyle, flatten bool) ([]GlyphID, bool)
- func (f *FontSet) TopAccentAttachment(g Glyph) (int32, bool)
- func (f *FontSet) VerticalMetrics(ref FaceRef) (VerticalMetrics, bool)
- type FontSetConfig
- type Glyph
- type GlyphID
- type GlyphMetrics
- type KernCurve
- type MathAxis
- type MathConstant
- type MathConstruction
- type MathKernCorner
- type MathScriptStyle
- type Outline
- type Point
- type Segment
- type SizeVariant
- type VerticalMetrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assembly ¶
type Assembly struct {
ItalicCorrection int32
MinConnectorOverlap int32
Parts []AssemblyPart
}
Assembly is the complete recipe for constructing a stretchy glyph. Parts retain OpenType order, and the first and last parts are the endpoint glyphs.
type AssemblyPart ¶
type AssemblyPart struct {
Glyph GlyphID
StartConnector int32
EndConnector int32
FullAdvance int32
Extender bool
}
AssemblyPart is one component of a stretchy-glyph assembly.
type Bounds ¶
Bounds is a design-unit control bounding box in the same y-down coordinate space as Outline. It includes Bezier control points, matching OpenType MATH/font tooling bounds. YMin is the top edge and YMax is the bottom edge.
type FaceInfo ¶
type FaceInfo struct {
ID string
Index int
PostScriptName string
UnitsPerEm uint16
GlyphCount int
HasMath bool
}
FaceInfo is immutable metadata for one loaded face.
type FaceRef ¶
type FaceRef uint8
FaceRef identifies a face in a loaded FontSet. Fallback faces are numbered from fallbackFaceBase in their input order.
func FallbackFace ¶
FallbackFace returns the FaceRef for fallback index i.
type Feature ¶
Feature is one GSUB feature request. Value follows OpenType alternate-feature numbering: ssty=1 selects the first alternate and ssty=2 the second.
type FontFace ¶
FontFace is one face from a host-provided SFNT or TTC file.
ID is optional when the face is passed to LoadFontSet, LoadMathFont, or another high-level source helper. Empty IDs are derived deterministically.
type FontOption ¶
type FontOption func(*FontFace)
FontOption configures one face passed to LoadMathFont.
func WithFontID ¶
func WithFontID(id string) FontOption
WithFontID sets an explicit stable face ID. A blank ID is treated like an omitted ID and is derived by LoadMathFont.
func WithFontIndex ¶
func WithFontIndex(index int) FontOption
WithFontIndex selects a face in a TrueType/OpenType collection.
type FontSet ¶
type FontSet struct {
// contains filtered or unexported fields
}
FontSet is an immutable parsed font collection with a concurrency-safe glyph outline cache.
func LoadFontSet ¶
func LoadFontSet(config FontSetConfig) (*FontSet, error)
LoadFontSet validates and prepares host fonts. It accepts SFNT and TTC data. Empty face IDs are derived deterministically. Explicit IDs must be nonblank and unique. All font bytes are copied before parsing.
func LoadMathFont ¶
func LoadMathFont(data []byte, opts ...FontOption) (*FontSet, error)
LoadMathFont prepares one math face. The face ID is derived when opts do not provide one. The face must contain OpenType MATH constants.
func (*FontSet) Config ¶
func (f *FontSet) Config() FontSetConfig
Config returns an independent copy of the input font configuration.
func (*FontSet) GlyphAdvance ¶
GlyphAdvance returns the design-unit advance width of one glyph.
func (*FontSet) GlyphMetrics ¶
func (f *FontSet) GlyphMetrics(g Glyph) (GlyphMetrics, bool)
GlyphMetrics returns design-unit metrics for one glyph.
func (*FontSet) HasFeature ¶
HasFeature reports whether ref has a supported ssty or dtls rule.
func (*FontSet) IsExtendedShape ¶
IsExtendedShape reports whether a glyph is in MATH ExtendedShapeCoverage.
func (*FontSet) ItalicCorrection ¶
ItalicCorrection returns the MATH italic correction in design units.
func (*FontSet) Key ¶
Key returns a stable 64-bit cache key. Use KeySHA256 when collision-resistant identity is required.
func (*FontSet) MapVariation ¶
MapVariation maps a base rune and Unicode variation selector.
func (*FontSet) MathConstant ¶
func (f *FontSet) MathConstant(ref FaceRef, c MathConstant) (int32, bool)
MathConstant returns one design-unit MATH constant. Percentage constants are returned as literal percentages.
func (*FontSet) MathConstruction ¶
func (f *FontSet) MathConstruction(g Glyph, axis MathAxis) (MathConstruction, bool)
MathConstruction returns size variants and an optional assembly recipe.
func (*FontSet) MathKern ¶
func (f *FontSet) MathKern(g Glyph, corner MathKernCorner, correctionHeight int32) int32
MathKern evaluates a glyph's MATH cut-in kern at correctionHeight design units.
func (*FontSet) MathKernCurve ¶
func (f *FontSet) MathKernCurve(g Glyph, corner MathKernCorner) (KernCurve, bool)
MathKernCurve returns a defensive copy of a glyph's MATH cut-in kern curve.
func (*FontSet) Shape ¶
Shape applies one-to-one math GSUB features in request order and returns a new glyph slice. Tags must be exact, case-sensitive four-byte OpenType tags. Disabled (zero-valued) and unsupported features are ignored.
func (*FontSet) ShapeMath ¶
func (f *FontSet) ShapeMath(ref FaceRef, glyphs []GlyphID, style MathScriptStyle, flatten bool) ([]GlyphID, bool)
ShapeMath applies the standard math substitutions in Typst's canonical order: optional dtls first, then the style-appropriate ssty alternate.
func (*FontSet) TopAccentAttachment ¶
TopAccentAttachment returns the MATH top-accent attachment point in design units from the glyph origin.
func (*FontSet) VerticalMetrics ¶
func (f *FontSet) VerticalMetrics(ref FaceRef) (VerticalMetrics, bool)
VerticalMetrics returns design-unit vertical metrics for ref.
type FontSetConfig ¶
FontSetConfig configures a validated font collection. Math must contain OpenType MATH constants. Fallback order is deterministic.
type GlyphMetrics ¶
GlyphMetrics contains unhinted design-unit metrics for one glyph.
type KernCurve ¶
KernCurve is a MATH cut-in kerning step function. Heights contains n values in ascending order and Kerns contains n+1 values.
type MathConstant ¶
type MathConstant uint8
MathConstant identifies a value from the OpenType MATH constants table. Lengths are returned in design units. The three percentage constants are returned as their literal percentage value.
const ( ScriptPercentScaleDown MathConstant = iota ScriptScriptPercentScaleDown DelimitedSubFormulaMinHeight DisplayOperatorMinHeight MathLeading AxisHeight AccentBaseHeight FlattenedAccentBaseHeight SubscriptShiftDown SubscriptTopMax SubscriptBaselineDropMin SuperscriptShiftUp SuperscriptShiftUpCramped SuperscriptBottomMin SuperscriptBaselineDropMax SubSuperscriptGapMin SuperscriptBottomMaxWithSubscript SpaceAfterScript UpperLimitGapMin UpperLimitBaselineRiseMin LowerLimitGapMin LowerLimitBaselineDropMin StackTopShiftUp StackTopDisplayStyleShiftUp StackBottomShiftDown StackBottomDisplayStyleShiftDown StackGapMin StackDisplayStyleGapMin StretchStackTopShiftUp StretchStackBottomShiftDown StretchStackGapAboveMin StretchStackGapBelowMin FractionNumeratorShiftUp FractionNumeratorDisplayStyleShiftUp FractionDenominatorShiftDown FractionDenominatorDisplayStyleShiftDown FractionNumeratorGapMin FractionNumDisplayStyleGapMin FractionRuleThickness FractionDenominatorGapMin FractionDenomDisplayStyleGapMin SkewedFractionHorizontalGap SkewedFractionVerticalGap OverbarVerticalGap OverbarRuleThickness OverbarExtraAscender UnderbarVerticalGap UnderbarRuleThickness UnderbarExtraDescender RadicalVerticalGap RadicalDisplayStyleVerticalGap RadicalRuleThickness RadicalExtraAscender RadicalKernBeforeDegree RadicalKernAfterDegree RadicalDegreeBottomRaisePercent // MathConstantCount is the number of MATH constants, not a constant. MathConstantCount )
func (MathConstant) String ¶
func (c MathConstant) String() string
String returns the OpenType name for c.
type MathConstruction ¶
type MathConstruction struct {
Variants []SizeVariant
Assembly *Assembly
}
MathConstruction contains the pre-drawn variants and optional assembly for a glyph along one axis.
type MathKernCorner ¶
type MathKernCorner uint8
MathKernCorner identifies one of the four corners in a MATH cut-in kerning record.
const ( MathKernTopRight MathKernCorner = iota MathKernTopLeft MathKernBottomRight MathKernBottomLeft )
type MathScriptStyle ¶
type MathScriptStyle uint8
MathScriptStyle selects the ssty alternate used by ShapeMath.
const ( NoScriptVariant MathScriptStyle = iota ScriptVariant ScriptScriptVariant )
type Outline ¶
Outline is an immutable snapshot of a glyph's unhinted outline. Coordinates are whole design units; sub-design-unit CFF precision is not represented by this API. The returned value owns its Segments slice, so mutation cannot affect the font cache.
type Point ¶
Point is a whole design-unit outline coordinate. Fractional CFF coordinates are truncated toward zero once when the font is loaded, matching the pinned Typst/ttf-parser oracle.
type Segment ¶
Segment is one command in a glyph outline. Coordinates are font design units in y-down orientation with the baseline at y=0. MoveTo and LineTo use Points[0], QuadTo uses Points[0:2], CubeTo uses all three points, and Close uses none.
type SizeVariant ¶
SizeVariant is one pre-drawn size of a stretchy glyph.