Documentation
¶
Overview ¶
Package subset provides font subsetting functionality.
Index ¶
- Variables
- func Subset(font *ot.Font, codepoints []rune) ([]byte, error)
- func SubsetString(font *ot.Font, text string) ([]byte, error)
- type Flags
- type FontBuilder
- type Input
- func (i *Input) AddGlyph(gid ot.GlyphID)
- func (i *Input) AddGlyphs(gids ...ot.GlyphID)
- func (i *Input) AddString(s string)
- func (i *Input) AddUnicode(cp rune)
- func (i *Input) AddUnicodeRange(start, end rune)
- func (i *Input) AddUnicodes(cps ...rune)
- func (i *Input) DropTable(tag ot.Tag)
- func (i *Input) Glyphs() map[ot.GlyphID]bool
- func (i *Input) HasLayoutFeatures() bool
- func (i *Input) HasPinnedAxes() bool
- func (i *Input) IsFullyInstanced(font *ot.Font) bool
- func (i *Input) KeepFeature(tag ot.Tag)
- func (i *Input) PassThroughTable(tag ot.Tag)
- func (i *Input) PinAllAxesToDefault(font *ot.Font) bool
- func (i *Input) PinAxisLocation(axisTag ot.Tag, value float32)
- func (i *Input) PinAxisToDefault(font *ot.Font, axisTag ot.Tag) bool
- func (i *Input) PinnedAxes() map[ot.Tag]float32
- func (i *Input) ShouldDropTable(tag ot.Tag) bool
- func (i *Input) ShouldKeepFeature(tag ot.Tag) bool
- func (i *Input) ShouldPassThrough(tag ot.Tag) bool
- func (i *Input) Unicodes() map[rune]bool
- type Plan
- func (p *Plan) CFF() *ot.CFF
- func (p *Plan) Cmap() *ot.Cmap
- func (p *Plan) Execute() ([]byte, error)
- func (p *Plan) Fvar() *ot.Fvar
- func (p *Plan) GetGlyphDeltas(gid ot.GlyphID, numPoints int) (xDeltas, yDeltas []int16)
- func (p *Plan) GetGlyphDeltasWithCoords(gid ot.GlyphID, numPoints int, origPoints []ot.SimpleGlyphPoint) (xDeltas, yDeltas []int16)
- func (p *Plan) GetInstancedAdvance(oldGID ot.GlyphID) uint16
- func (p *Plan) Glyf() *ot.Glyf
- func (p *Plan) GlyphMap() map[ot.GlyphID]ot.GlyphID
- func (p *Plan) GlyphSet() map[ot.GlyphID]bool
- func (p *Plan) Hmtx() *ot.Hmtx
- func (p *Plan) Input() *Input
- func (p *Plan) IsInstanced() bool
- func (p *Plan) MapGlyph(oldGID ot.GlyphID) (ot.GlyphID, bool)
- func (p *Plan) NumOutputGlyphs() int
- func (p *Plan) OldGlyph(newGID ot.GlyphID) (ot.GlyphID, bool)
- func (p *Plan) Source() *ot.Font
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoTables is returned when building a font with no tables. ErrNoTables = errors.New("subset: no tables to build") // ErrMissingTable is returned when a required table is missing. ErrMissingTable = errors.New("subset: required table missing") // ErrInvalidGlyph is returned for invalid glyph references. ErrInvalidGlyph = errors.New("subset: invalid glyph reference") )
Functions ¶
Types ¶
type Flags ¶
type Flags uint32
Flags controls various subsetting options.
const ( // FlagNoHinting removes hinting instructions. FlagNoHinting Flags = 1 << iota // FlagRetainGIDs keeps original glyph IDs (pads with empty glyphs). FlagRetainGIDs // FlagGlyphNames retains PostScript glyph names. FlagGlyphNames // FlagNotdefOutline retains the .notdef glyph outline. FlagNotdefOutline // FlagNoLayoutClosure skips GSUB/GPOS glyph closure. FlagNoLayoutClosure // FlagPassUnrecognized keeps unrecognized tables. FlagPassUnrecognized // FlagDropLayoutTables excludes GSUB/GPOS/GDEF tables from output. // Use this for PDF embedding where shaping is already done. FlagDropLayoutTables )
type FontBuilder ¶
type FontBuilder struct {
// contains filtered or unexported fields
}
FontBuilder builds a new font from subset tables.
func (*FontBuilder) AddTable ¶
func (b *FontBuilder) AddTable(tag ot.Tag, data []byte)
AddTable adds or replaces a table in the font.
func (*FontBuilder) Build ¶
func (b *FontBuilder) Build() ([]byte, error)
Build produces the final font binary.
type Input ¶
type Input struct {
// Flags controls subsetting behavior.
Flags Flags
// contains filtered or unexported fields
}
Input configures which glyphs and tables to include in the subset.
func (*Input) AddUnicode ¶
AddUnicode adds a Unicode codepoint to retain.
func (*Input) AddUnicodeRange ¶
AddUnicodeRange adds a range of Unicode codepoints [start, end].
func (*Input) AddUnicodes ¶
AddUnicodes adds multiple Unicode codepoints.
func (*Input) HasLayoutFeatures ¶
HasLayoutFeatures returns true if specific features were requested.
func (*Input) HasPinnedAxes ¶ added in v0.0.3
HasPinnedAxes returns true if any axes have been pinned.
func (*Input) IsFullyInstanced ¶ added in v0.0.3
IsFullyInstanced returns true if all axes in the font have been pinned.
func (*Input) KeepFeature ¶
KeepFeature marks an OpenType feature to retain. If no features are specified, all features are retained.
func (*Input) PassThroughTable ¶
PassThroughTable marks a table to be copied unchanged.
func (*Input) PinAllAxesToDefault ¶ added in v0.0.3
PinAllAxesToDefault pins all variation axes to their default values. This creates a static font at the default instance. This is similar to HarfBuzz's hb_subset_input_pin_all_axes_to_default().
func (*Input) PinAxisLocation ¶ added in v0.0.3
PinAxisLocation pins a variation axis to a specific value. When all axes are pinned, the font is "instanced" to a static font. The value should be in design-space coordinates (e.g., 700 for Bold weight). This is similar to HarfBuzz's hb_subset_input_pin_axis_location().
func (*Input) PinAxisToDefault ¶ added in v0.0.3
PinAxisToDefault pins a variation axis to its default value. The font's fvar table is needed to determine the default. This is similar to HarfBuzz's hb_subset_input_pin_axis_to_default().
func (*Input) PinnedAxes ¶ added in v0.0.3
PinnedAxes returns the map of pinned axis tags to values.
func (*Input) ShouldDropTable ¶
ShouldDropTable returns true if the table should be excluded.
func (*Input) ShouldKeepFeature ¶
ShouldKeepFeature returns true if the feature should be retained.
func (*Input) ShouldPassThrough ¶
ShouldPassThrough returns true if the table should be copied unchanged.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan holds the computed glyph mapping and metadata for subsetting.
func CreatePlan ¶
CreatePlan creates a subset plan from a font and input configuration.
func (*Plan) GetGlyphDeltas ¶ added in v0.0.3
GetGlyphDeltas returns the gvar deltas for a glyph at the pinned coordinates. numPoints is the number of outline points in the glyph. This version doesn't support proper IUP interpolation.
func (*Plan) GetGlyphDeltasWithCoords ¶ added in v0.0.3
func (p *Plan) GetGlyphDeltasWithCoords(gid ot.GlyphID, numPoints int, origPoints []ot.SimpleGlyphPoint) (xDeltas, yDeltas []int16)
GetGlyphDeltasWithCoords returns the gvar deltas for a glyph at the pinned coordinates with proper IUP interpolation using the original point coordinates.
func (*Plan) GetInstancedAdvance ¶ added in v0.0.3
GetInstancedAdvance returns the instanced advance width for a glyph. If not instanced, returns the base advance from hmtx.
func (*Plan) IsInstanced ¶ added in v0.0.3
IsInstanced returns true if the plan will produce an instanced (static) font.
func (*Plan) MapGlyph ¶
MapGlyph maps an old glyph ID to a new glyph ID. Returns (0, false) if the glyph is not in the subset.
func (*Plan) NumOutputGlyphs ¶
NumOutputGlyphs returns the number of glyphs in the output font.