gtab

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 16 Imported by: 3

Documentation

Overview

Package gtab reads and writes OpenType "GSUB" and "GPOS" tables.

There are two main entry points:

  • The Info type represents a parsed OpenType "GSUB" or "GPOS" table.
  • The Context type allows to apply a "GSUB" or "GPOS" table to a sequence of glyphs.

Index

Constants

View Source
const (
	// TypeGsub is an OpenType "GSUB" table.
	TypeGsub = iota + 1

	// TypeGpos is an OpenType "GPOS" table.
	TypeGpos
)

These are the allowed types for use in the Read function.

Variables

View Source
var (
	// GsubDefaultFeatures lists a set of default features for "GSUB" tables.
	GsubDefaultFeatures = map[string]bool{
		"calt": true,
		"ccmp": true,
		"clig": true,
		"liga": true,
		"locl": true,
	}

	// GposDefaultFeatures lists a set of default features for "GPOS" tables.
	GposDefaultFeatures = map[string]bool{
		"kern": true,
		"mark": true,
		"mkmk": true,
	}
)

Default features for use with the Info.FindLookups method.

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   []SeqLookup
}

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.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chseqctxt2

type ChainedSeqContext1

type ChainedSeqContext1 struct {
	Cov   coverage.Table
	Rules [][]*ChainedSeqRule // indexed by coverage index
}

ChainedSeqContext1 is used for GSUB type 6 format 1 and for GPOS type 8 format 1 subtables.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chseqctxt1

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 for GPOS type 8 format 2 subtables.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chseqctxt2

type ChainedSeqContext3

type ChainedSeqContext3 struct {
	Backtrack []coverage.Set
	Input     []coverage.Set
	Lookahead []coverage.Set
	Actions   []SeqLookup
}

ChainedSeqContext3 is used for GSUB type 6 and for 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

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   []SeqLookup
}

ChainedSeqRule describes the rules in a ChainedSeqContext1.

type ClassSeqRule

type ClassSeqRule struct {
	Input   []uint16 // excludes the first input glyph
	Actions []SeqLookup
}

ClassSeqRule describes a sequence of glyph classes and the actions to be performed

type Context added in v0.4.5

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

Context holds all information required to apply a lookup to a glyph sequence.

func NewContext added in v0.4.5

func NewContext(ll LookupList, gdef *gdef.Table, lookups []LookupIndex) *Context

NewContext creates a new context, which can be used to apply the given lookups in the given order. The gdef parameter, if non-nil, is used to resolve glyph classes.

func (*Context) Apply added in v0.4.5

func (ctx *Context) Apply(seq []glyph.Info) []glyph.Info

Apply applies the lookups to the given sequence of glyphs.

This is the main entry-point for external users of GSUB and GPOS tables.

type EntryExitRecord

type EntryExitRecord struct {
	Entry anchor.Table
	Exit  anchor.Table
}

EntryExitRecord is an OpenType EntryExitRecord table, for use in Gpos3_1 subtables. 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 implement this feature.
	Lookups []LookupIndex
}

Feature describes an OpenType font feature.

func (Feature) String

func (f Feature) String() string

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

func (l Gpos2_1) CovAndAdjust() (coverage.Table, []map[glyph.ID]*PairAdjust)

CovAndAdjust is a convenience function which returns the coverage table and the adjustments.

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 Gpos5_1 added in v0.4.5

type Gpos5_1 struct {
	MarkCov   coverage.Table
	LigCov    coverage.Table
	MarkArray []markarray.Record // indexed by mark coverage index
	LigArray  [][][]anchor.Table // indexed by (ligature coverage index, ligature component, mark class)
}

Gpos5_1 is a Mark-to-Ligature Attachment Positioning Subtable (format 1).

https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-5-mark-to-ligature-attachment-positioning-subtable

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

type Gsub1_1 struct {
	Cov   coverage.Set
	Delta glyph.ID
}

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

type Gsub2_1 struct {
	Cov  coverage.Table
	Repl [][]glyph.ID // indexed by coverage index
}

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

type Gsub3_1 struct {
	Cov        coverage.Table
	Alternates [][]glyph.ID
}

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

type Gsub4_1 struct {
	Cov  coverage.Table
	Repl [][]Ligature // indexed by coverage index
}

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.

The order of entries in Repl defines the preference for using the ligatures, for example "ffl" is only applied if it comes before "ff".

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 {
	// The ScriptList lists the font features available for each natural
	// language.  Features are given as indices into the FeatureList.
	ScriptList ScriptListInfo

	// The FeatureList enumerates all font features available in the font.
	// Features are implemented by lookups from the LookupList.
	FeatureList FeatureListInfo

	// The LookupList enumerates all the OpenType lookups used to implement
	// the font features.
	LookupList LookupList
}

Info contains the information from an OpenType "GSUB" or "GPOS" table.

func Read added in v0.4.5

func Read(r parser.ReadSeekSizer, tp Type) (*Info, error)

Read reads and decodes an OpenType "GSUB" or "GPOS" table from r. The tp argument must be one of TypeGsub or TypeGpos.

The format of the data read is defined here:

func (*Info) Encode

func (info *Info) Encode() []byte

Encode returns the binary representation of a "GSUB" or "GPOS" table.

func (*Info) FindLookups

func (info *Info) FindLookups(lang language.Tag, includeFeature map[string]bool) []LookupIndex

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).
	In []glyph.ID

	// Out is the glyph that replaces the input sequence.
	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.

LookupFlags can specify glyphs to be ignored in a variety of ways:

  • all base glyphs
  • all ligature glyphs
  • all mark glyphs
  • a subset of mark glyphs, specified by a mark filtering set
  • a subset of mark glyphs, specified by a mark attachment type

When this is used, the lookup is applied as if the ignored glyphs were not present in the input sequence.

There is also a flag value to control the behaviour of GPOS lookup type 3 (cursive attachment).

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookupFlags

const (
	// RightToLeft indicates that for GPOS lookup type 3 (cursive
	// attachment), the last glyph in the sequence (rather than the first) will
	// be positioned on the baseline.
	RightToLeft LookupFlags = 0x0001

	// IgnoreBaseGlyphs indicates that the lookup ignores glyphs which
	// are classified as base glyphs in the GDEF table.
	IgnoreBaseGlyphs LookupFlags = 0x0002

	// IgnoreLigatures indicates that the lookup ignores glyphs which
	// are classified as ligatures in the GDEF table.
	IgnoreLigatures LookupFlags = 0x0004

	// IgnoreMarks indicates that the lookup ignores glyphs which are
	// classified as marks in the GDEF table.
	IgnoreMarks LookupFlags = 0x0008

	// UseMarkFilteringSet indicates that the lookup ignores all
	// glyphs classified as marks in the GDEF table, except for those
	// in the specified mark filtering set.
	UseMarkFilteringSet LookupFlags = 0x0010

	// MarkAttachTypeMask, if not zero, skips over all marks that are not
	// of the specified type.  Mark attachment classes must be defined in the
	// MarkAttachClass Table in the GDEF table.
	MarkAttachTypeMask 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 an OpenType "Lookup List Table".

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-list-table

type LookupMetaInfo

type LookupMetaInfo struct {
	// LookupType identifies the type of the lookups inside a lookup table.
	// Different numbering schemes are used for GSUB and GPOS tables.
	LookupType uint16

	// LookupFlags contains flags which modify application of the lookup to a
	// glyph string.
	LookupFlags LookupFlags

	// An index into the MarkGlyphSets slice in the corresponding GDEF struct.
	// This is only used, if the MarkFilteringSet flag is set.  In this case,
	// all marks not present in the specified mark glyph set are skipped.
	MarkFilteringSet uint16
}

LookupMetaInfo contains information associated with a LookupTable. Only information which is not specific to a particular subtable is included here.

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 []Subtable
}

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 PairAdjust

type PairAdjust struct {
	First, Second *GposValueRecord
}

PairAdjust represents information from a PairValueRecord table.

This is used in Gpos2_1 and Gpos2_2 subtables.

type ScriptListInfo

type ScriptListInfo map[language.Tag]*Features

ScriptListInfo contains the information of an OpenType "ScriptList table". It maps BCP 47 tags to OpenType font features.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#scriptList

type SeqContext1

type SeqContext1 struct {
	Cov   coverage.Table
	Rules [][]*SeqRule // indexed by coverage index
}

SeqContext1 is used for GSUB type 5 format 1 subtables and for GPOS type 7 format 1 subtables.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-1-simple-glyph-contexts

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 for GPOS type 7 format 2 subtables.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-2-class-based-glyph-contexts

type SeqContext3

type SeqContext3 struct {
	Input   []coverage.Set
	Actions []SeqLookup
}

SeqContext3 is used for GSUB type 5 format 3 and for GPOS type 7 format 3 subtables.

https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-3-coverage-based-glyph-contexts

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 []SeqLookup
}

SeqRule describes a rule in a SeqContext1 subtable.

type Subtable

type Subtable interface {
	// contains filtered or unexported methods
}

Subtable represents a subtable of a "GSUB" or "GPOS" lookup table.

The following types are GSUB subtables:

The following types are GPOS subtables:

The following types can be used both in GSUB and GPOS tables:

type Type added in v0.4.5

type Type byte

Type chooses between "GSUB" and "GPOS" tables. The possible values are TypeGsub and TypeGpos.

func (Type) String added in v0.4.5

func (tp Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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