Documentation ¶
Overview ¶
Package gtab reads and writes "GSUB" and "GPOS" tables. The main entry point is the Info type, which represents a parsed GSUB or GPOS table.
Index ¶
- Constants
- Variables
- type ChainedClassSeqRule
- type ChainedSeqContext1
- type ChainedSeqContext2
- type ChainedSeqContext3
- type ChainedSeqRule
- type ClassSeqRule
- type EntryExitRecord
- type Feature
- type FeatureIndex
- type FeatureListInfo
- type Features
- type Gpos1_1
- type Gpos1_2
- type Gpos2_1
- type Gpos2_2
- type Gpos3_1
- type Gpos4_1
- type Gpos6_1
- type GposValueRecord
- type Gsub1_1
- type Gsub1_2
- type Gsub2_1
- type Gsub3_1
- type Gsub4_1
- type Gsub8_1
- type Info
- type Ligature
- type LookupFlags
- type LookupIndex
- type LookupList
- type LookupMetaInfo
- type LookupTable
- type Match
- type PairAdjust
- type ScriptListInfo
- type SeqContext1
- type SeqContext2
- type SeqContext3
- type SeqLookup
- type SeqLookups
- type SeqRule
- type Subtable
- type Subtables
Constants ¶
const ( GposExtensionLookupType uint16 = 9 GsubExtensionLookupType uint16 = 7 )
Lookup types for extension lookup records. This can be used as an argument for the Info.Encode method.
Variables ¶
var ( // GsubDefaultFeatures can be used as an argument for the Info.FindLookups() // method. GsubDefaultFeatures = map[string]bool{ "calt": true, "ccmp": true, "clig": true, "liga": true, "locl": true, } // GposDefaultFeatures can be used as an argument for the Info.FindLookups() // method. GposDefaultFeatures = map[string]bool{ "kern": true, "mark": true, "mkmk": true, } )
Functions ¶
This section is empty.
Types ¶
type ChainedClassSeqRule ¶
type ChainedClassSeqRule struct { Backtrack []uint16 Input []uint16 // excludes the first input glyph, since this is in Cov Lookahead []uint16 Actions SeqLookups }
ChainedClassSeqRule is used to represent the rules in a ChainedSeqContext2. It describes a sequence of nested lookups together with the context where they apply. The Backtrack, Input and Lookahead sequences are given as lists of glyph classes, as defined by the corresponding class definition tables in the ChainedSeqContext2 structure.
type ChainedSeqContext1 ¶
type ChainedSeqContext1 struct { Cov coverage.Table Rules [][]*ChainedSeqRule // indexed by coverage index }
ChainedSeqContext1 is used for GSUB type 6 format 1 and GPOS type 8 format 1 subtables. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-1-simple-glyph-contexts
func (*ChainedSeqContext1) Apply ¶
func (l *ChainedSeqContext1) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*ChainedSeqContext1) Encode ¶
func (l *ChainedSeqContext1) Encode() []byte
Encode implements the Subtable interface.
func (*ChainedSeqContext1) EncodeLen ¶
func (l *ChainedSeqContext1) EncodeLen() int
EncodeLen implements the Subtable interface.
type ChainedSeqContext2 ¶
type ChainedSeqContext2 struct { Cov coverage.Table Backtrack classdef.Table Input classdef.Table Lookahead classdef.Table Rules [][]*ChainedClassSeqRule // indexed by input glyph class }
ChainedSeqContext2 is used for GSUB type 6 format 2 and GPOS type 8 format 2 subtables. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-2-class-based-glyph-contexts
func (*ChainedSeqContext2) Apply ¶
func (l *ChainedSeqContext2) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*ChainedSeqContext2) Encode ¶
func (l *ChainedSeqContext2) Encode() []byte
Encode implements the Subtable interface.
func (*ChainedSeqContext2) EncodeLen ¶
func (l *ChainedSeqContext2) EncodeLen() int
EncodeLen implements the Subtable interface.
type ChainedSeqContext3 ¶
type ChainedSeqContext3 struct { Backtrack []coverage.Set Input []coverage.Set Lookahead []coverage.Set Actions SeqLookups }
ChainedSeqContext3 is used for GSUB type 6 and GPOS type 8 format 3 subtables https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-3-coverage-based-glyph-contexts
func (*ChainedSeqContext3) Apply ¶
func (l *ChainedSeqContext3) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*ChainedSeqContext3) Encode ¶
func (l *ChainedSeqContext3) Encode() []byte
Encode implements the Subtable interface.
func (*ChainedSeqContext3) EncodeLen ¶
func (l *ChainedSeqContext3) EncodeLen() int
EncodeLen implements the Subtable interface.
type ChainedSeqRule ¶
type ChainedSeqRule struct { Backtrack []glyph.ID Input []glyph.ID // excludes the first input glyph, since this is in Cov Lookahead []glyph.ID Actions SeqLookups }
ChainedSeqRule describes the rules in a ChainedSeqContext1.
type ClassSeqRule ¶
type ClassSeqRule struct { Input []uint16 // excludes the first input glyph Actions SeqLookups }
ClassSeqRule describes a sequence of glyph classes and the actions to be performed
type EntryExitRecord ¶
EntryExitRecord is an OpenType EntryExitRecord table. The Exit anchor point of a glyph is aligned with the Entry anchor point of the following glyph.
type Feature ¶
type Feature struct { // Tag describes the function of this feature. // https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags Tag string // Lookups is a list of lookup indices that are used by this feature. Lookups []LookupIndex }
Feature describes an OpenType feature, used either in a "GPOS" or "GSUB" table.
type FeatureIndex ¶
type FeatureIndex uint16
FeatureIndex enumerates features. It is used as an index into the FeatureListInfo. Valid values are in the range from 0 to 0xFFFE. The special value 0xFFFF is used to indicate the absence of required features in the `Features` struct.
type FeatureListInfo ¶
type FeatureListInfo []*Feature
FeatureListInfo contains the contents of an OpenType "Feature List" table.
type Features ¶
type Features struct { Required FeatureIndex // 0xFFFF, if no required feature Optional []FeatureIndex }
Features describes the mandatory and optional features for a script/language.
type Gpos1_1 ¶
type Gpos1_1 struct { Cov coverage.Table Adjust *GposValueRecord }
Gpos1_1 is a Single Adjustment Positioning Subtable (GPOS type 1, format 1). If specifies a single adjustment to be applied to all glyphs in the coverage table. https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#single-adjustment-positioning-format-1-single-positioning-value
type Gpos1_2 ¶
type Gpos1_2 struct { Cov coverage.Table Adjust []*GposValueRecord // indexed by coverage index }
Gpos1_2 is a Single Adjustment Positioning Subtable (GPOS type 1, format 2) https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#single-adjustment-positioning-format-2-array-of-positioning-values
type Gpos2_1 ¶
type Gpos2_1 map[glyph.Pair]*PairAdjust
Gpos2_1 is a Pair Adjustment Positioning Subtable (format 1) https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#pair-adjustment-positioning-format-1-adjustments-for-glyph-pairs
func (Gpos2_1) CovAndAdjust ¶ added in v0.3.5
type Gpos2_2 ¶
type Gpos2_2 struct { Cov coverage.Set Class1, Class2 classdef.Table Adjust [][]*PairAdjust // indexed by class1 index, then class2 index }
Gpos2_2 is a Pair Adjustment Positioning Subtable (format 2) https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#pair-adjustment-positioning-format-2-class-pair-adjustment
type Gpos3_1 ¶
type Gpos3_1 struct { Cov coverage.Table Records []EntryExitRecord // indexed by coverage index }
Gpos3_1 is a Cursive Attachment Positioning subtable (format 1). https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#cursive-attachment-positioning-format1-cursive-attachment
type Gpos4_1 ¶
type Gpos4_1 struct { MarkCov coverage.Table BaseCov coverage.Table MarkArray []markarray.Record // indexed by mark coverage index BaseArray [][]anchor.Table // indexed by base coverage index, then by mark class }
Gpos4_1 is a Mark-to-Base Attachment Positioning Subtable (format 1) https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-base-attachment-positioning-format-1-mark-to-base-attachment-point
type Gpos6_1 ¶
type Gpos6_1 struct { Mark1Cov coverage.Table Mark2Cov coverage.Table Mark1Array []markarray.Record // indexed by mark1 coverage index Mark2Array [][]anchor.Table // indexed by mark2 coverage index, then by mark class }
Gpos6_1 is a Mark-to-Mark Attachment Positioning Subtable (format 1) https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-6-mark-to-mark-attachment-positioning-subtable
type GposValueRecord ¶
type GposValueRecord struct { XPlacement funit.Int16 // Horizontal adjustment for placement YPlacement funit.Int16 // Vertical adjustment for placement XAdvance funit.Int16 // Horizontal adjustment for advance YAdvance funit.Int16 // Vertical adjustment for advance XPlacementDevOffs uint16 // Offset to Device table/VariationIndex table for horizontal placement YPlacementDevOffs uint16 // Offset to Device table/VariationIndex table for vertical placement XAdvanceDevOffs uint16 // Offset to Device table/VariationIndex table for horizontal advance YAdvanceDevOffs uint16 // Offset to Device table/VariationIndex table for vertical advance }
GposValueRecord describes an adjustment to the position of a glyph or set of glyphs. https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record
func (*GposValueRecord) Apply ¶
func (vr *GposValueRecord) Apply(glyph *glyph.Info)
Apply adjusts the position of a glyph according to the value record.
func (*GposValueRecord) String ¶
func (vr *GposValueRecord) String() string
type Gsub1_1 ¶
Gsub1_1 is a Single Substitution subtable (GSUB type 1, format 1). Lookups of this type allow to replace a single glyph with another glyph. The original glyph must be contained in the coverage table. The new glyph is determined by adding `delta` to the original glyph's GID. https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#11-single-substitution-format-1
type Gsub1_2 ¶
type Gsub1_2 struct { Cov coverage.Table SubstituteGlyphIDs []glyph.ID // indexed by coverage index }
Gsub1_2 is a Single Substitution GSUB subtable (type 1, format 2). Lookups of this type allow to replace a single glyph with another glyph. The original glyph must be contained in the coverage table. The new glyph is found by looking up the replacement GID in the SubstituteGlyphIDs table (indexed by the coverage index of the original GID). https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#12-single-substitution-format-2
type Gsub2_1 ¶
Gsub2_1 is a Multiple Substitution GSUB subtable (type 2, format 1). Lookups of this type allow to replace a single glyph with multiple glyphs. The original glyph must be contained in the coverage table. The new glyphs are found by looking up the replacement GIDs in the `Repl` table (indexed by the coverage index of the original GID). Replacement sequences must have at least one glyph. https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#21-multiple-substitution-format-1
type Gsub3_1 ¶
Gsub3_1 is an Alternate Substitution GSUB subtable (type 3, format 1). https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#31-alternate-substitution-format-1
type Gsub4_1 ¶
Gsub4_1 is a Ligature Substitution GSUB subtable (type 4, format 1). Lookups of this type replace a sequence of glyphs with a single glyph. https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#41-ligature-substitution-format-1
type Gsub8_1 ¶
type Gsub8_1 struct { Input coverage.Table Backtrack []coverage.Table Lookahead []coverage.Table SubstituteGlyphIDs []glyph.ID // indexed by input coverage index }
Gsub8_1 is a Reverse Chaining Contextual Single Substitution GSUB subtable (type 8, format 1). https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#81-reverse-chaining-contextual-single-substitution-format-1-coverage-based-glyph-contexts
type Info ¶
type Info struct { ScriptList ScriptListInfo FeatureList FeatureListInfo LookupList LookupList }
Info contains the information from a "GSUB" or "GPOS" table.
func ReadGPOS ¶
func ReadGPOS(r parser.ReadSeekSizer) (*Info, error)
ReadGPOS reads and decodes an OpenType "GPOS" table from r. https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#gpos-header
func ReadGSUB ¶
func ReadGSUB(r parser.ReadSeekSizer) (*Info, error)
ReadGSUB reads and decodes an OpenType "GSUB" table from r. https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#gsub-header
func (*Info) FindLookups ¶
FindLookups returns the lookups required to implement the given features in the specified language.
type Ligature ¶
type Ligature struct { // In is the sequence of input glyphs that is replaced by Out, excluding // the first glyph in the sequence (since this is in Cov). // // The order in the Ligature offset array defines the preference for using // the ligatures, for example "ffl" is only applied if it comes before "ff". In []glyph.ID Out glyph.ID }
Ligature represents a substitution of a sequence of glyphs into a single glyph in a Gsub4_1 subtable.
type LookupFlags ¶
type LookupFlags uint16
LookupFlags contains bits which modify application of a lookup to a glyph string. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookupFlags
const ( LookupRightToLeft LookupFlags = 0x0001 LookupIgnoreBaseGlyphs LookupFlags = 0x0002 LookupIgnoreLigatures LookupFlags = 0x0004 LookupIgnoreMarks LookupFlags = 0x0008 LookupUseMarkFilteringSet LookupFlags = 0x0010 LookupMarkAttachTypeMask LookupFlags = 0xFF00 )
Bit values for LookupFlag.
type LookupIndex ¶
type LookupIndex uint16
LookupIndex enumerates lookups. It is used as an index into a LookupList.
type LookupList ¶
type LookupList []*LookupTable
LookupList contains the information from a Lookup List Table. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-list-table
func (LookupList) ApplyLookup ¶
func (ll LookupList) ApplyLookup(seq []glyph.Info, lookupIndex LookupIndex, gdef *gdef.Table) []glyph.Info
ApplyLookup applies a single lookup to the given glyphs.
type LookupMetaInfo ¶
type LookupMetaInfo struct { LookupType uint16 LookupFlag LookupFlags MarkFilteringSet uint16 }
LookupMetaInfo contains information associated with a lookup but not specific to a subtable.
type LookupTable ¶
type LookupTable struct { Meta *LookupMetaInfo // Subtables contains subtables to try for this lookup. The subtables // are tried in order, until one of them can be applied. // // The type of the subtables must match Meta.LookupType, but the // subtables may use any format within that type. Subtables Subtables }
LookupTable represents a lookup table inside a "GSUB" or "GPOS" table of a font. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-table
type Match ¶
type Match struct { InputPos []int // in increasing order Replace []glyph.Info Actions SeqLookups Next int }
Match describes the effect of applying a Lookup to a glyph sequence.
type PairAdjust ¶
type PairAdjust struct {
First, Second *GposValueRecord
}
PairAdjust represents information from a PairValueRecord table.
type ScriptListInfo ¶
ScriptListInfo contains the information of a ScriptList table. It maps BCP 47 tags to OpenType font features.
type SeqContext1 ¶
SeqContext1 is used for GSUB type 5 format 1 subtables and GPOS type 7 format 1 subtables. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-1-simple-glyph-contexts
func (*SeqContext1) Apply ¶
func (l *SeqContext1) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*SeqContext1) Encode ¶
func (l *SeqContext1) Encode() []byte
Encode implements the Subtable interface.
func (*SeqContext1) EncodeLen ¶
func (l *SeqContext1) EncodeLen() int
EncodeLen implements the Subtable interface.
type SeqContext2 ¶
type SeqContext2 struct { Cov coverage.Table Input classdef.Table Rules [][]*ClassSeqRule // indexed by class index of the first glyph }
SeqContext2 is used for GSUB type 5 format 2 subtables and GPOS type 7 format 2 subtables. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-2-class-based-glyph-contexts
func (*SeqContext2) Apply ¶
func (l *SeqContext2) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*SeqContext2) Encode ¶
func (l *SeqContext2) Encode() []byte
Encode implements the Subtable interface.
func (*SeqContext2) EncodeLen ¶
func (l *SeqContext2) EncodeLen() int
EncodeLen implements the Subtable interface.
type SeqContext3 ¶
type SeqContext3 struct { Input []coverage.Table Actions SeqLookups }
SeqContext3 is used for GSUB type 5 format 3 and GPOS type 7 format 3 subtables. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-3-coverage-based-glyph-contexts
func (*SeqContext3) Apply ¶
func (l *SeqContext3) Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match
Apply implements the Subtable interface.
func (*SeqContext3) Encode ¶
func (l *SeqContext3) Encode() []byte
Encode implements the Subtable interface.
func (*SeqContext3) EncodeLen ¶
func (l *SeqContext3) EncodeLen() int
EncodeLen implements the Subtable interface.
type SeqLookup ¶
type SeqLookup struct { SequenceIndex uint16 LookupListIndex LookupIndex }
SeqLookup describes the actions for contextual and chained contextual lookups.
type SeqRule ¶
type SeqRule struct { Input []glyph.ID // excludes the first input glyph, since this is in Cov Actions SeqLookups }
SeqRule describes a rule in a SeqContext1 subtable.
type Subtable ¶
type Subtable interface { // Apply attempts to apply the subtable at the given position. // If returns the new glyphs and the new position. If the subtable // cannot be applied, the unchanged glyphs and a negative position // are returned // // This checks whether the Subtable can be applied to seq[a:b-1]. // The function keep represents the lookup flags, glyphs for which // keep(seq[i].Gid) is false must be ignored. The caller already // checks the glyph at location a, so only subsequent glyphs need to // be tested by the Subtable implementation. Apply(keep keepGlyphFn, seq []glyph.Info, a, b int) *Match EncodeLen() int Encode() []byte }
Subtable represents a subtable of a "GSUB" or "GPOS" lookup table.