truetype

package
v0.0.0-...-b7ff752 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT, MIT Imports: 23 Imported by: 3

Documentation

Overview

Package truetype provides support for OpenType and TrueType font formats, used in PDF.

It is largely influenced by github.com/ConradIrwin/font, golang.org/x/image/font/sfnt, and FreeType2.

Package truetype provides support for OpenType and TrueType font formats, used in PDF.

It is largely influenced by github.com/ConradIrwin/font and golang.org/x/image/font/sfnt, and FreeType2.

Index

Constants

View Source
const (
	Kerx1Push        = 0x8000 // If set, push this glyph on the kerning stack.
	Kerx1DontAdvance = 0x4000 // If set, don't advance to the next glyph before going to the new state.
	Kerx1Reset       = 0x2000 // If set, reset the kerning data (clear the stack)
	Kern1Offset      = 0x3FFF // Byte offset from beginning of subtable to the  value table for the glyphs on the kerning stack.
)

Kernx1 state entry flags

View Source
const (
	/* If set, make the current glyph the first
	* glyph to be rearranged. */
	MRMarkFirst = 0x8000
	/* If set, don't advance to the next glyph
	* before going to the new state. This means
	* that the glyph index doesn't change, even
	* if the glyph at that index has changed. */
	MRDontAdvance = 0x4000
	/* If set, make the current glyph the last
	* glyph to be rearranged. */
	MRMarkLast = 0x2000
	/* These bits are reserved and should be set to 0. */
	MRReserved = 0x1FF0
	/* The type of rearrangement specified. */
	MRVerb = 0x000F
)

MorxRearrangement flags

View Source
const (
	MCSetMark = 0x8000 /* If set, make the current glyph the marked glyph. */
	/* If set, don't advance to the next glyph before
	* going to the new state. */
	MCDontAdvance = 0x4000
	MCReserved    = 0x3FFF /* These bits are reserved and should be set to 0. */
)

MorxContextualSubtable flags

View Source
const (
	/* Push this glyph onto the component stack for
	* eventual processing. */
	MLSetComponent = 0x8000
	/* Leave the glyph pointer at this glyph for the
	next iteration. */
	MLDontAdvance   = 0x4000
	MLPerformAction = 0x2000 // Use the ligActionIndex to process a ligature group.
	/* Byte offset from beginning of subtable to the
	 * ligature action list. This value must be a
	 * multiple of 4. */
	MLOffset = 0x3FFF

	/* This is the last action in the list. This also
	* implies storage. */
	MLActionLast = 1 << 31
	/* Store the ligature at the current cumulated index
	* in the ligature table in place of the marked
	* (i.e. currently-popped) glyph. */
	MLActionStore = 1 << 30
	/* A 30-bit value which is sign-extended to 32-bits
	* and added to the glyph ID, resulting in an index
	* into the component table. */
	MLActionOffset = 0x3FFFFFFF
)

MorxLigatureSubtable flags

View Source
const (
	// If set, mark the current glyph.
	MISetMark = 0x8000
	// If set, don't advance to the next glyph before
	// going to the new state.  This does not mean
	// that the glyph pointed to is the same one as
	// before. If you've made insertions immediately
	// downstream of the current glyph, the next glyph
	// processed would in fact be the first one
	// inserted.
	MIDontAdvance = 0x4000
	// If set, and the currentInsertList is nonzero,
	// then the specified glyph list will be inserted
	// as a kashida-like insertion, either before or
	// after the current glyph (depending on the state
	// of the currentInsertBefore flag). If clear, and
	// the currentInsertList is nonzero, then the
	// specified glyph list will be inserted as a
	// split-vowel-like insertion, either before or
	// after the current glyph (depending on the state
	// of the currentInsertBefore flag).
	MICurrentIsKashidaLike = 0x2000
	// If set, and the markedInsertList is nonzero,
	// then the specified glyph list will be inserted
	// as a kashida-like insertion, either before or
	// after the marked glyph (depending on the state
	// of the markedInsertBefore flag). If clear, and
	// the markedInsertList is nonzero, then the
	// specified glyph list will be inserted as a
	// split-vowel-like insertion, either before or
	// after the marked glyph (depending on the state
	// of the markedInsertBefore flag).
	MIMarkedIsKashidaLike = 0x1000
	// If set, specifies that insertions are to be made
	// to the left of the current glyph. If clear,
	// they're made to the right of the current glyph.
	MICurrentInsertBefore = 0x0800
	// If set, specifies that insertions are to be
	// made to the left of the marked glyph. If clear,
	// they're made to the right of the marked glyph.
	MIMarkedInsertBefore = 0x0400
	// This 5-bit field is treated as a count of the
	// number of glyphs to insert at the current
	// position. Since zero means no insertions, the
	// largest number of insertions at any given
	// current location is 31 glyphs.
	MICurrentInsertCount = 0x3E0
	// This 5-bit field is treated as a count of the
	// number of glyphs to insert at the marked
	// position. Since zero means no insertions, the
	// largest number of insertions at any given
	// marked location is 31 glyphs.
	MIMarkedInsertCount = 0x001F
)

MorxInsertionSubtable flags

View Source
const (
	PEUnicodeDefault     = PlatformEncodingID(0)
	PEUnicodeBMP         = PlatformEncodingID(3)
	PEUnicodeFull        = PlatformEncodingID(4)
	PEUnicodeFull13      = PlatformEncodingID(6)
	PEMacRoman           = PEUnicodeDefault
	PEMicrosoftSymbolCs  = PlatformEncodingID(0)
	PEMicrosoftUnicodeCs = PlatformEncodingID(1)
	PEMicrosoftUcs4      = PlatformEncodingID(10)
)
View Source
const (
	PLMacEnglish       = PlatformLanguageID(0)
	PLUnicodeDefault   = PlatformLanguageID(0)
	PLMicrosoftEnglish = PlatformLanguageID(0x0409)
)

Variables

View Source
var (
	// TagPNG identifies bitmap glyph with png format
	TagPNG = MustNewTag("png ")
	// TagTIFF identifies bitmap glyph with tiff format
	TagTIFF = MustNewTag("tiff")
	// TagJPG identifies bitmap glyph with jpg format
	TagJPG = MustNewTag("jpg ")
)
View Source
var (

	// TagGpos represents the 'GPOS' table, which contains Glyph Positioning features
	TagGpos = MustNewTag("GPOS")
	// TagGsub represents the 'GSUB' table, which contains Glyph Substitution features
	TagGsub = MustNewTag("GSUB")
	// TagGdef represents the 'GDEF' table, which contains various Glyph Definitions
	TagGdef = MustNewTag("GDEF")

	// TagSilf represents the main Graphite table
	TagSilf = MustNewTag("Silf")

	// TypeTrueType is the first four bytes of an OpenType file containing a TrueType font
	TypeTrueType = Tag(0x00010000)
	// TypeAppleTrueType is the first four bytes of an OpenType file containing a TrueType font
	// (specifically one designed for Apple products, it's recommended to use TypeTrueType instead)
	TypeAppleTrueType = MustNewTag("true")
	// TypePostScript1 is the first four bytes of an OpenType file containing a PostScript Type 1 font
	TypePostScript1 = MustNewTag("typ1")
	// TypeOpenType is the first four bytes of an OpenType file containing a PostScript Type 2 font
	// as specified by OpenType
	TypeOpenType = MustNewTag("OTTO")

	// SignatureWOFF is the magic number at the start of a WOFF file.
	SignatureWOFF = MustNewTag("wOFF")
)

Functions

func Float1616ToUint

func Float1616ToUint(f Float1616) uint32

func Load

func Load(file fonts.Resource) (fonts.Faces, error)

Load implements fonts.FontLoader. For collection font files (.ttc, .otc), multiple fonts may be returned.

func ScanFont

func ScanFont(file fonts.Resource) ([]fonts.FontDescriptor, error)

ScanFont lazily parse `file` to extract a summary of the font(s). Collections are supported.

func SetVariations

func SetVariations(face FaceVariable, variations []Variation)

SetVariations applies a list of font-variation settings to a font, defaulting to the values given in the `fvar` table. Note that passing an empty slice will instead remove the coordinates.

Types

type AATAnchor

type AATAnchor struct {
	X, Y int16
}

AATAnchor is a point within the coordinate space of a given glyph independent of the control points used to render the glyph

type AATFeature

type AATFeature struct {
	Type, Setting uint16
	EnableFlags   uint32 // Flags for the settings that this feature and setting enables.
	DisableFlags  uint32 // Complement of flags for the settings that this feature and setting disable.
}

type AATFeatureName

type AATFeatureName struct {
	Settings  []AATSettingName
	Feature   uint16
	Flags     uint16
	NameIndex NameID
}

func (*AATFeatureName) GetSelectorInfos

func (feature *AATFeatureName) GetSelectorInfos() ([]AATFeatureSelector, uint16)

GetSelectorInfos fetches a list of the selectors available for the feature, and the default index. It the later equals 0xFFFF, then the feature type is non-exclusive. Otherwise, it is the index of the selector that is selected by default.

func (*AATFeatureName) IsExclusive

func (feature *AATFeatureName) IsExclusive() bool

IsExclusive returns true if the feature settings are mutually exclusive.

type AATFeatureSelector

type AATFeatureSelector struct {
	Name    NameID // selector's name identifier
	Enable  uint16 // value to turn the selector on
	Disable uint16 // value to turn the selector off
}

AATFeatureSelector represents a setting for an AAT feature type.

type AATSettingName

type AATSettingName struct {
	Setting uint16
	Name    NameID
}

type AATStateEntry

type AATStateEntry struct {
	NewState uint16
	Flags    uint16 // Table specific.
	// contains filtered or unexported fields
}

AATStateEntry is the shared type for entries in a state table. See the various AsXXX methods to exploit its content.

func (AATStateEntry) AsKernxIndex

func (e AATStateEntry) AsKernxIndex() uint16

AsKernxIndex reads the internal data for entries in 'kern/x' subtable format 1. An entry with no index returns 0xFFFF

func (AATStateEntry) AsMorxContextual

func (e AATStateEntry) AsMorxContextual() (markIndex, currentIndex uint16)

AsMorxContextual reads the internal data for entries in morx contextual subtable. The returned indexes use 0xFFFF as empty value.

func (AATStateEntry) AsMorxInsertion

func (e AATStateEntry) AsMorxInsertion() (currentIndex, markedIndex uint16)

AsMorxInsertion reads the internal data for entries in morx insertion subtable. The returned indexes use 0xFFFF as empty value.

func (AATStateEntry) AsMorxLigature

func (e AATStateEntry) AsMorxLigature() (ligActionIndex uint16)

AsMorxLigature reads the internal data for entries in morx ligature subtable.

type AATStateTable

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

AATStateTable is an extended state table.

func (*AATStateTable) GetClass

func (t *AATStateTable) GetClass(glyph GID) uint16

GetClass return the class for the given glyph, with the correct default value.

func (AATStateTable) GetEntry

func (t AATStateTable) GetEntry(state, class uint16) AATStateEntry

GetEntry return the entry for the given state and class, and handle invalid values (by returning an empty entry).

type CaretValue

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

CaretValue is either CaretValueFormat1, CaretValueFormat2 or CaretValueFormat3.

type CaretValueFormat1

type CaretValueFormat1 int16 // X or Y value, in design units

type CaretValueFormat2

type CaretValueFormat2 uint16

type CaretValueFormat3

type CaretValueFormat3 struct {
	Device     DeviceTable
	Coordinate int16 // X or Y value, in design units
}

type ChainedSequenceRule

type ChainedSequenceRule struct {
	SequenceRule
	Backtrack []uint16
	Lookahead []uint16
}

type Class

type Class interface {
	// ClassID returns the class ID for the provided glyph. Returns (0, false)
	// for glyphs not covered by this class.
	ClassID(GID) (uint32, bool)

	// GlyphSize returns the number of glyphs covered.
	GlyphSize() int

	// Extent returns the maximum class ID + 1. This is the length
	// required for an array to be indexed by the class values.
	Extent() int
}

Class group glyph indices. Conceptually it is a map[GID]uint32, but it may be implemented more efficiently.

type Cmap

type Cmap = fonts.Cmap

type CmapID

type CmapID struct {
	Platform PlatformID
	Encoding PlatformEncodingID
}

CmapID groups the platform and encoding of a Cmap subtable.

func (CmapID) IsSymbolic

func (c CmapID) IsSymbolic() bool

IsSymbolic returns `true` for the special case of a symbolic cmap, for which the codepoints are not interpreted as Unicode.

type CmapIter

type CmapIter = fonts.CmapIter

type CmapSubtable

type CmapSubtable struct {
	Cmap Cmap
	ID   CmapID
}

type ConditionFormat1

type ConditionFormat1 struct {
	Axis uint16 // Index (zero-based) for the variation axis within the 'fvar' table.
	// Minimum and maximum values of the font variation instances
	// that satisfy this condition.
	Min, Max float32
}

type Coverage

type Coverage interface {
	// Index returns the index of the provided glyph, or
	// `false` if the glyph is not covered by this lookup.
	// Note: this method is injective: two distincts, covered glyphs are mapped
	// to distincts tables.
	Index(GID) (int, bool)

	// Size return the number of glyphs covered. For non empty Coverages, it is also
	// 1 + (maximum index returned)
	Size() int
}

Coverage specifies all the glyphs affected by a substitution or positioning operation described in a subtable. Conceptually is it a []GlyphIndex, but it may be implemented for efficiently. See the concrete types `CoverageList` and `CoverageRanges`.

type CoverageList

type CoverageList []GID

CoverageList is a coverage with format 1. The glyphs are sorted in ascending order.

func (CoverageList) Index

func (cl CoverageList) Index(gi GID) (int, bool)

func (CoverageList) Size

func (cl CoverageList) Size() int

type CoverageRange

type CoverageRange struct {
	Start, End    GID
	StartCoverage int
}

CoverageRange store a range of indexes, starting from StartCoverage. For example, for the glyphs 12,13,14,15, and the indexes 7,8,9,10, the CoverageRange would be {12, 15, 7}.

type CoverageRanges

type CoverageRanges []CoverageRange

CoverageRanges is a coverage with format 2. Ranges are non-overlapping. The following GlyphIDs/index pairs are stored as follows:

	 glyphs: 130, 131, 132, 133, 134, 135, 137
	 indexes: 0, 1, 2, 3, 4, 5, 6
  ranges: {130, 135, 0}    {137, 137, 6}

StartCoverage is used to calculate the index without counting the length of the preceeding ranges

func (CoverageRanges) Index

func (cr CoverageRanges) Index(gi GID) (int, bool)

func (CoverageRanges) Size

func (cr CoverageRanges) Size() int

type DeviceHinting

type DeviceHinting struct {
	// with length endSize - startSize + 1
	Values []int8
	// correction range, in ppem
	StartSize, EndSize uint16
}

func (DeviceHinting) GetDelta

func (dev DeviceHinting) GetDelta(ppem uint16, scale int32) int32

GetDelta returns the hint for the given `ppem`, scaled by `scale`. It returns 0 for out of range `ppem` values.

type DeviceTable

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

DeviceTable is either an GPOSDeviceHinting for standard fonts, or a GPOSDeviceVariation for variable fonts.

type DeviceVariation

type DeviceVariation VariationStoreIndex

type FaceVariable

type FaceVariable interface {
	// Variations returns the variations for the font,
	// or an empty table for non-variable fonts.
	Variations() TableFvar

	// SetVarCoordinates apply the normalized coordinates values.
	// Use `NormalizeVariations` to convert from design space units.
	// See also `SetVariations`.
	SetVarCoordinates(coords []float32)

	// VarCoordinates returns the current variable coordinates,
	// in normalized units.
	VarCoordinates() []float32

	// NormalizeVariations should normalize the given design-space coordinates.
	// The minimum and maximum values for the axis are mapped to the interval
	// [-1,1], with the default axis value mapped to 0. This should be a no-op
	// for non-variable fonts.
	NormalizeVariations(coords []float32) []float32
}

FaceVariable is an extension interface supporting OpenType variable fonts. See the `Variations` method to check if a font is actually variable.

type Feature

type Feature struct {
	LookupIndices []uint16
	// contains filtered or unexported fields
}

Feature represents a glyph substitution or glyph positioning features.

type FeatureRecord

type FeatureRecord struct {
	Feature
	Tag Tag
}

FeatureRecord associate a tag with a feature

type FeatureSubstitution

type FeatureSubstitution struct {
	AlternateFeature Feature
	FeatureIndex     uint16 // The feature table index to match.
}

type FeatureVariation

type FeatureVariation struct {
	ConditionSet         []ConditionFormat1
	FeatureSubstitutions []FeatureSubstitution
}

type Float1616

type Float1616 = float32

Float1616 is a float32, represented in fixed 16.16 format in font files.

func Float1616FromUint

func Float1616FromUint(v uint32) Float1616

type Font

type Font struct {
	Names TableName

	Maxp TableMaxp

	Glyf TableGlyf
	Hmtx TableHVmtx

	OS2 *TableOS2 // optional

	// graphite font, optional
	Graphite *GraphiteTables

	Head TableHead

	// NumGlyphs exposes the number of glyph indexes present in the font,
	// as exposed in the 'maxp' table.
	NumGlyphs int // TODO: check usage

	// Type represents the kind of glyphs in this font.
	// It is one of TypeTrueType, TypeTrueTypeApple, TypePostScript1, TypeOpenType
	Type Tag

	// HasHint is true if the font has a prep table.
	HasHint bool

	// A six letter string for PDF inclusion. Empty until Subset() is called.
	SubsetID string
	// contains filtered or unexported fields
}

Font represents a SFNT font, which is the underlying representation found in .otf and .ttf files. SFNT is a container format, which contains a number of tables identified by tags. Depending on the type of glyphs embedded in the file which tables will exist. In particular, there's a big different between TrueType glyphs (usually .ttf) and CFF/PostScript Type 2 glyphs (usually .otf)

func Parse

func Parse(file fonts.Resource) (*Font, error)

Parse parses an OpenType or TrueType file and returns a Font. See Loader for support for collections, and FontParser for more control over table loading.

func (*Font) AscenderPDF

func (fnt *Font) AscenderPDF() int

AscenderPDF returns the /Ascent value for the PDF file

func (*Font) BoundingBoxPDF

func (fnt *Font) BoundingBoxPDF() string

BoundingBoxPDF returns the /FontBBox value for the PDF file

func (*Font) CMapPDF

func (fnt *Font) CMapPDF() string

CMapPDF returns a CMap string to be used in a PDF file

func (*Font) CapHeightPDF

func (fnt *Font) CapHeightPDF() int

CapHeightPDF returns the /CapHeight value for the PDF file

func (*Font) Cmap

func (font *Font) Cmap() (fonts.Cmap, fonts.CmapEncoding)

func (*Font) DescenderPDF

func (fnt *Font) DescenderPDF() int

DescenderPDF returns the /Descent value for the PDF file

func (*Font) FlagsPDF

func (fnt *Font) FlagsPDF() int

FlagsPDF returns the /Flags value for the PDF file

func (*Font) FontHExtents

func (f *Font) FontHExtents() (fonts.FontExtents, bool)

func (*Font) FontVExtents

func (f *Font) FontVExtents() (fonts.FontExtents, bool)

func (*Font) GetGlyphContourPoint

func (f *Font) GetGlyphContourPoint(glyph fonts.GID, pointIndex uint16) (x, y int32, ok bool)

func (*Font) GlyphData

func (f *Font) GlyphData(gid GID, xPpem, yPpem uint16) fonts.GlyphData

func (*Font) GlyphExtents

func (f *Font) GlyphExtents(glyph GID, xPpem, yPpem uint16) (fonts.GlyphExtents, bool)

func (*Font) GlyphHOrigin

func (f *Font) GlyphHOrigin(GID) (x, y int32, found bool)

func (*Font) GlyphName

func (f *Font) GlyphName(glyph GID) string

func (*Font) GlyphVOrigin

func (f *Font) GlyphVOrigin(glyph GID) (x, y int32, found bool)

func (*Font) HorizontalAdvance

func (f *Font) HorizontalAdvance(gid GID) float32

func (*Font) IsGraphite

func (font *Font) IsGraphite() (*Font, bool)

IsGraphite returns true if the font has Graphite capabilities, but does not check if the tables are actually valid.

func (*Font) ItalicAnglePDF

func (fnt *Font) ItalicAnglePDF() int

ItalicAnglePDF returns the /ItalicAngle value for the PDF file

func (*Font) LayoutTables

func (font *Font) LayoutTables() LayoutTables

LayoutTables returns the valid advanced layout tables. When parsing yields an error, it is ignored and an empty table is returned. See the individual methods for more control over error handling.

func (*Font) LineMetric

func (f *Font) LineMetric(metric fonts.LineMetric) (float32, bool)

func (*Font) LoadBitmaps

func (font *Font) LoadBitmaps() []fonts.BitmapSize

LoadBitmaps checks for the various bitmaps table and returns the first valid

func (*Font) LoadSummary

func (font *Font) LoadSummary() (fonts.FontSummary, error)

func (*Font) NamePDF

func (fnt *Font) NamePDF() string

NamePDF returns the PDF name of the font file

func (*Font) NominalGlyph

func (f *Font) NominalGlyph(ch rune) (GID, bool)

func (*Font) NormalizeVariations

func (f *Font) NormalizeVariations(coords []float32) []float32

NormalizeVariations normalizes the given design-space coordinates. The minimum and maximum values for the axis are mapped to the interval [-1,1], with the default axis value mapped to 0. Any additional scaling defined in the face's `avar` table is also applied, as described at https://docs.microsoft.com/en-us/typography/opentype/spec/avar

func (*Font) PostscriptInfo

func (font *Font) PostscriptInfo() (fonts.PSInfo, bool)

func (*Font) PostscriptName

func (font *Font) PostscriptName() string

PostscriptName returns the optional PostscriptName of the font

func (*Font) SetVarCoordinates

func (font *Font) SetVarCoordinates(coords []float32)

func (*Font) StemVPDF

func (fnt *Font) StemVPDF() int

StemVPDF returns the /StemV value for the PDF file

func (*Font) Subset

func (fnt *Font) Subset(codepoints []GID) error

Subset removes all data from the font except the one needed for the given code points.

func (*Font) Upem

func (f *Font) Upem() uint16

func (*Font) VarCoordinates

func (font *Font) VarCoordinates() []float32

func (*Font) VariationGlyph

func (f *Font) VariationGlyph(ch, varSelector rune) (GID, bool)

func (*Font) Variations

func (f *Font) Variations() TableFvar

func (*Font) VerticalAdvance

func (f *Font) VerticalAdvance(gid GID) float32

func (*Font) WidthsPDF

func (fnt *Font) WidthsPDF() string

WidthsPDF returns a width entry suitable for embedding in a PDF file.

func (*Font) WriteSubset

func (fnt *Font) WriteSubset(w io.Writer) error

WriteSubset writes a valid font to w that is suitable for including in PDF

func (*Font) XHeightPDF

func (fnt *Font) XHeightPDF() int

XHeightPDF returns the /XHeight value for the PDF file

type FontParser

type FontParser struct {
	Type Tag
	// contains filtered or unexported fields
}

FontParser serves as an intermediate when reading font files. Most of the time, the Parse and Loader.Load functions are enough, but `FontParser` may be used on its own when more control over table loading is needed.

func NewFontParser

func NewFontParser(file fonts.Resource) (*FontParser, error)

NewFontParser reads the `file` header and returns a parser. `file` will be used to parse tables, and should not be close.

func NewFontParsers

func NewFontParsers(file fonts.Resource) ([]*FontParser, error)

NewFontParsers is the same as `NewFontParser`, but supports collections.

func (*FontParser) AnkrTable

func (pr *FontParser) AnkrTable(numGlyphs int) (TableAnkr, error)

AnkrTable parse the AAT 'ankr' table.

func (*FontParser) CmapTable

func (pr *FontParser) CmapTable() (TableCmap, error)

func (*FontParser) FeatTable

func (pr *FontParser) FeatTable() (TableFeat, error)

FeatTable parse the AAT 'feat' table.

func (*FontParser) GDEFTable

func (pr *FontParser) GDEFTable(nbAxis int) (TableGDEF, error)

GDEFTable returns the Glyph Definition table identified with the 'GDEF' tag.

func (*FontParser) GPOSTable

func (pr *FontParser) GPOSTable() (TableGPOS, error)

GPOSTable returns the Glyph Positioning table identified with the 'GPOS' tag.

func (*FontParser) GSUBTable

func (pr *FontParser) GSUBTable() (TableGSUB, error)

GSUBTable returns the Glyph Substitution table identified with the 'GSUB' tag.

func (*FontParser) GetRawTable

func (pr *FontParser) GetRawTable(tag Tag) ([]byte, error)

GetRawTable returns the binary content of the given table, or an error if not found. Note that many tables are already interpreted by this package, see the various XXXTable().

func (*FontParser) GlyfTable

func (pr *FontParser) GlyfTable(numGlyphs int, locationIndexFormat int16) (TableGlyf, error)

GlyfTable parse the 'glyf' table. Note that glyphs may be defined in various format (like CFF or bitmaps), and stored in other tables. `locationIndexFormat` is found in the 'head' table.

func (*FontParser) HasTable

func (pr *FontParser) HasTable(tag Tag) bool

HasTable returns `true` is the font has the given table.

func (*FontParser) HheaTable

func (pr *FontParser) HheaTable() (*TableHVhea, error)

HheaTable returns the HHea table

func (*FontParser) HmtxTable

func (pr *FontParser) HmtxTable(numGlyphs int) (TableHVmtx, error)

HmtxTable returns the glyphs horizontal metrics (array of size numGlyphs), expressed in fonts units.

func (*FontParser) KernTable

func (pr *FontParser) KernTable(numGlyphs int) (TableKernx, error)

KernTable parses and returns the 'kern' table.

func (*FontParser) KerxTable

func (pr *FontParser) KerxTable(numGlyphs int) (TableKernx, error)

KerxTable parse the AAT 'kerx' table.

func (*FontParser) LoadGraphiteTables

func (pr *FontParser) LoadGraphiteTables() (gr GraphiteTables, err error)

LoadGraphiteTables returns the raw tables required for Graphite engine support. See the package graphite for how to interpret these tables.

func (*FontParser) MorxTable

func (pr *FontParser) MorxTable(numGlyphs int) (TableMorx, error)

MorxTable parse the AAT 'morx' table.

func (*FontParser) NumGlyphs

func (pr *FontParser) NumGlyphs() (int, error)

NumGlyphs parses the 'maxp' table to find the number of glyphs in the font.

func (*FontParser) OS2Table

func (pr *FontParser) OS2Table() (*TableOS2, error)

func (*FontParser) PostTable

func (pr *FontParser) PostTable(numGlyphs int) (TablePost, error)

PostTable returns the Post table names

func (*FontParser) TrakTable

func (pr *FontParser) TrakTable() (TableTrak, error)

TrakTable parse the AAT 'trak' table.

func (*FontParser) VheaTable

func (pr *FontParser) VheaTable() (*TableHVhea, error)

VheaTable returns the VHea table

func (*FontParser) VmtxTable

func (pr *FontParser) VmtxTable(numGlyphs int) (TableHVmtx, error)

VmtxTable returns the glyphs vertical metrics (array of size numGlyphs), expressed in fonts units.

type GID

type GID = fonts.GID

GID is a glyph ID

type GPOSAnchor

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

type GPOSAnchorFormat1

type GPOSAnchorFormat1 struct {
	X, Y int16 // in design units
}

type GPOSAnchorFormat2

type GPOSAnchorFormat2 struct {
	GPOSAnchorFormat1
	AnchorPoint uint16
}

type GPOSAnchorFormat3

type GPOSAnchorFormat3 struct {
	XDevice, YDevice DeviceTable // may be null
	GPOSAnchorFormat1
}

type GPOSChainedContext1

type GPOSChainedContext1 LookupChainedContext1

func (GPOSChainedContext1) Type

type GPOSChainedContext2

type GPOSChainedContext2 LookupChainedContext2

func (GPOSChainedContext2) Type

type GPOSChainedContext3

type GPOSChainedContext3 LookupChainedContext3

func (GPOSChainedContext3) Type

type GPOSContext1

type GPOSContext1 LookupContext1

func (GPOSContext1) Type

func (GPOSContext1) Type() GPOSType

type GPOSContext2

type GPOSContext2 LookupContext2

func (GPOSContext2) Type

func (GPOSContext2) Type() GPOSType

type GPOSContext3

type GPOSContext3 LookupContext3

func (GPOSContext3) Type

func (GPOSContext3) Type() GPOSType

type GPOSCursive1

type GPOSCursive1 [][2]GPOSAnchor // entry, exit (may be null)

GPOSCursive1 has, after successul parsing, the length of its associated coverage

func (GPOSCursive1) Type

func (GPOSCursive1) Type() GPOSType

type GPOSMark

type GPOSMark struct {
	Anchor     GPOSAnchor
	ClassValue uint16
}

type GPOSMarkToBase1

type GPOSMarkToBase1 struct {
	BaseCoverage Coverage
	// same length as the associated Coverage, marks can't be nil
	Marks []GPOSMark
	// one set for each index in `BaseCoverage`, each with same length
	// anchors may be nil
	Bases [][]GPOSAnchor
}

func (GPOSMarkToBase1) Type

func (GPOSMarkToBase1) Type() GPOSType

type GPOSMarkToLigature1

type GPOSMarkToLigature1 struct {
	LigatureCoverage Coverage
	Marks            []GPOSMark       // marks can't be nil
	Ligatures        [][][]GPOSAnchor // one set for each index in `LigatureCoverage`
}

func (GPOSMarkToLigature1) Type

type GPOSMarkToMark1

type GPOSMarkToMark1 struct {
	Mark2Coverage Coverage
	Marks1        []GPOSMark
	Marks2        [][]GPOSAnchor // one set for each index in `Mark2Coverage`, each with same length
}

func (GPOSMarkToMark1) Type

func (GPOSMarkToMark1) Type() GPOSType

type GPOSPair1

type GPOSPair1 struct {
	// After successul parsing, has one set for each glyph in the coverage
	Values  []GPOSPairSet
	Formats [2]GPOSValueFormat // first, second
}

func (GPOSPair1) Type

func (GPOSPair1) Type() GPOSType

type GPOSPair2

type GPOSPair2 struct {
	First, Second Class
	// Positionning for first and second glyphs.
	// After successful parsing, it has size First.Extent() x Second.Extent()
	Values  [][][2]GPOSValueRecord
	Formats [2]GPOSValueFormat // first, second
}

func (GPOSPair2) Type

func (GPOSPair2) Type() GPOSType

type GPOSPairSet

type GPOSPairSet []GPOSPairValueRecord

GPOSPairSet is sorted according to the `SecondGlyph` field

func (GPOSPairSet) FindGlyph

func (ps GPOSPairSet) FindGlyph(secondGlyph GID) *GPOSPairValueRecord

FindGlyph performs a binary search in the list, returning the record for `secondGlyph`, or `nil` if not found.

type GPOSPairValueRecord

type GPOSPairValueRecord struct {
	Pos         [2]GPOSValueRecord // Positioning data for first and second glyphs
	SecondGlyph GID                // Glyph ID of second glyph in the pair
}

type GPOSSingle1

type GPOSSingle1 struct {
	Value  GPOSValueRecord
	Format GPOSValueFormat
}

func (GPOSSingle1) Type

func (GPOSSingle1) Type() GPOSType

type GPOSSingle2

type GPOSSingle2 struct {
	// After successful parsing, has same length as associated coverage.
	Values []GPOSValueRecord
	Format GPOSValueFormat
}

func (GPOSSingle2) Type

func (GPOSSingle2) Type() GPOSType

type GPOSSubtable

type GPOSSubtable struct {
	// For GPOSChained - Format 3, its the coverage of the first input.
	Coverage Coverage
	Data     interface{ Type() GPOSType }
}

GPOSSubtable is one of the subtables of a GPOS lookup.

type GPOSType

type GPOSType uint16

GPOSType identifies the kind of lookup format, for GPOS tables.

const (
	GPOSSingle         GPOSType = 1 + iota // Adjust position of a single glyph
	GPOSPair                               // Adjust position of a pair of glyphs
	GPOSCursive                            // Attach cursive glyphs
	GPOSMarkToBase                         // Attach a combining mark to a base glyph
	GPOSMarkToLigature                     // Attach a combining mark to a ligature
	GPOSMarkToMark                         // Attach a combining mark to another mark
	GPOSContext                            // Position one or more glyphs in context
	GPOSChained                            // Position one or more glyphs in chained context

)

type GPOSValueFormat

type GPOSValueFormat uint16

GPOSValueFormat is a mask indicating which field are set in a GPOSValueRecord. It is often shared between many records.

const (
	XPlacement GPOSValueFormat = 1 << iota /* Includes horizontal adjustment for placement */
	YPlacement                             /* Includes vertical adjustment for placement */
	XAdvance                               /* Includes horizontal adjustment for advance */
	YAdvance                               /* Includes vertical adjustment for advance */
	XPlaDevice                             /* Includes horizontal Device table for placement */
	YPlaDevice                             /* Includes vertical Device table for placement */
	XAdvDevice                             /* Includes horizontal Device table for advance */
	YAdvDevice                             /* Includes vertical Device table for advance */

	//  Mask for having any Device table
	Devices = XPlaDevice | YPlaDevice | XAdvDevice | YAdvDevice
)

type GPOSValueRecord

type GPOSValueRecord struct {
	XPlaDevice DeviceTable // Device table for horizontal placement (may be nil)
	YPlaDevice DeviceTable // Device table for vertical placement (may be nil)
	XAdvDevice DeviceTable // Device table for horizontal advance (may be nil)
	YAdvDevice DeviceTable // Device table for vertical advance (may be nil)
	// format     gposValueFormat
	XPlacement int16 // Horizontal adjustment for placement--in design units
	YPlacement int16 // Vertical adjustment for placement--in design units
	XAdvance   int16 // Horizontal adjustment for advance--in design units (only used for horizontal writing)
	YAdvance   int16 // Vertical adjustment for advance--in design units (only used for vertical writing)
}

type GSUBAlternate1

type GSUBAlternate1 [][]GID

func (GSUBAlternate1) Type

func (GSUBAlternate1) Type() GSUBType

type GSUBChainedContext1

type GSUBChainedContext1 LookupChainedContext1

func (GSUBChainedContext1) Type

type GSUBChainedContext2

type GSUBChainedContext2 LookupChainedContext2

func (GSUBChainedContext2) Type

type GSUBChainedContext3

type GSUBChainedContext3 LookupChainedContext3

func (GSUBChainedContext3) Type

type GSUBContext1

type GSUBContext1 LookupContext1

func (GSUBContext1) Type

func (GSUBContext1) Type() GSUBType

type GSUBContext2

type GSUBContext2 LookupContext2

func (GSUBContext2) Type

func (GSUBContext2) Type() GSUBType

type GSUBContext3

type GSUBContext3 LookupContext3

func (GSUBContext3) Type

func (GSUBContext3) Type() GSUBType

type GSUBLigature1

type GSUBLigature1 [][]LigatureGlyph

GSUBLigature1 stores one ligature set per glyph in the coverage.

func (GSUBLigature1) Type

func (GSUBLigature1) Type() GSUBType

type GSUBMultiple1

type GSUBMultiple1 [][]GID

func (GSUBMultiple1) Type

func (GSUBMultiple1) Type() GSUBType

type GSUBReverseChainedContext1

type GSUBReverseChainedContext1 struct {
	Backtrack   []Coverage
	Lookahead   []Coverage
	Substitutes []GID
}

func (GSUBReverseChainedContext1) Type

type GSUBSingle1

type GSUBSingle1 int16

GSUBSingle1 is a Single Substitution Format 1, expressed as a delta from the coverage.

func (GSUBSingle1) Type

func (GSUBSingle1) Type() GSUBType

type GSUBSingle2

type GSUBSingle2 []GID

GSUBSingle2 is a Single Substitution Format 2, expressed as substitutes

func (GSUBSingle2) Type

func (GSUBSingle2) Type() GSUBType

type GSUBSubtable

type GSUBSubtable struct {
	// For SubChaining - Format 3, its the coverage of the first input.
	Coverage Coverage
	Data     interface{ Type() GSUBType }
}

GSUBSubtable is one of the subtables of a GSUB lookup.

type GSUBType

type GSUBType uint16

GSUBType identifies the kind of lookup format, for GSUB tables.

const (
	GSUBSingle    GSUBType = 1 + iota // Single (format 1.1 1.2)	Replace one glyph with one glyph
	GSUBMultiple                      // Multiple (format 2.1)	Replace one glyph with more than one glyph
	GSUBAlternate                     // Alternate (format 3.1)	Replace one glyph with one of many glyphs
	GSUBLigature                      // Ligature (format 4.1)	Replace multiple glyphs with one glyph
	GSUBContext                       // Context (format 5.1 5.2 5.3)	Replace one or more glyphs in context
	GSUBChaining                      // Chaining Context (format 6.1 6.2 6.3)	Replace one or more glyphs in chained context

	GSUBReverse // Reverse chaining context single (format 8.1)
)

type GlyphData

type GlyphData struct {
	Xmin, Ymin, Xmax, Ymax int16
	// contains filtered or unexported fields
}

type GlyphNames

type GlyphNames interface {
	// GlyphName return the postscript name of a
	// glyph, or an empty string if it not found
	GlyphName(x GID) string
}

GlyphNames stores the names of a 'post' table.

type GlyphProps

type GlyphProps = uint16

GlyphProps is a 16-bit integer where the lower 8-bit have bits representing glyph class, and high 8-bit the mark attachment type (if any).

const (
	BaseGlyph GlyphProps = 1 << (iota + 1)
	Ligature
	Mark
)

type GraphiteTables

type GraphiteTables struct {
	Sill, Feat, Gloc, Glat, Silf []byte
}

GraphiteTables contains the data for the graphite tables

type ItemVariationData

type ItemVariationData struct {
	RegionIndexes []uint16  // Array of indices into the variation region list for the regions referenced by this item variation data table.
	Deltas        [][]int16 // Each row as the same length as `RegionIndexes`
}

type Kern0

type Kern0 []KerningPair

func (Kern0) KernPair

func (k Kern0) KernPair(left, right GID) int16

type Kern1

type Kern1 struct {
	Values  []int16 // After successful parsing, may be safely indexed by AATStateEntry.AsKernxIndex() from `Machine`
	Machine AATStateTable
}

type Kern2

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

func (Kern2) KernPair

func (k Kern2) KernPair(left, right GID) int16

type Kern3

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

Kern3 is the Apple kerning subtable format 3

func (Kern3) KernPair

func (ks Kern3) KernPair(left, right GID) int16

type KernSubtable

type KernSubtable struct {
	Data interface {
		// contains filtered or unexported methods
	}

	IsExtended bool // `true` for AAT `kerx` subtables
	TupleCount int  // 0 for scalar values
	// contains filtered or unexported fields
}

KernSubtable contains kerning information. Some formats provides an easy lookup method: see SimpleKerns. Others require a state machine to interpret it.

func (KernSubtable) IsBackwards

func (k KernSubtable) IsBackwards() bool

IsBackwards returns true if state-table based should process the glyphs backwards.

func (KernSubtable) IsCrossStream

func (k KernSubtable) IsCrossStream() bool

IsCrossStream returns true if the subtable has cross-stream kerning values.

func (KernSubtable) IsHorizontal

func (k KernSubtable) IsHorizontal() bool

IsHorizontal returns true if the subtable has horizontal kerning values.

func (KernSubtable) IsVariation

func (k KernSubtable) IsVariation() bool

IsVariation returns true if the subtable has variation kerning values.

type KerningPair

type KerningPair struct {
	Left, Right GID
	// Note: For 'kerx' table version 4 with tuples, this is
	// the first element of the kerning tuple.
	Value int16
}

type Kerx4

type Kerx4 struct {
	Anchors []KerxAnchor
	Machine AATStateTable
	// contains filtered or unexported fields
}

func (Kerx4) ActionType

func (k Kerx4) ActionType() uint8

ActionType returns 0, 1 or 2 .

type Kerx6

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

func (Kerx6) KernPair

func (k Kerx6) KernPair(left, right GID) int16

type KerxAnchor

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

type KerxAnchorAnchor

type KerxAnchorAnchor struct {
	Mark, Current uint16
}

type KerxAnchorControl

type KerxAnchorControl struct {
	Mark, Current uint16
}

type KerxAnchorCoordinates

type KerxAnchorCoordinates struct {
	MarkX, MarkY, CurrentX, CurrentY int16
}

type LangSys

type LangSys struct {
	// Features contains the index of the features for this language,
	// relative to the Features slice of the table
	Features []uint16
	// Index of a feature required for this language system.
	// If no required features, default to 0xFFFF
	RequiredFeatureIndex uint16
	Tag                  Tag
}

LangSys represents the language system for a script.

type LayoutTables

type LayoutTables struct {
	GDEF TableGDEF // An absent table has a nil Class
	Trak TableTrak
	Ankr TableAnkr
	Feat TableFeat
	Morx TableMorx
	Kern TableKernx
	Kerx TableKernx
	GSUB TableGSUB // An absent table has a nil slice of lookups
	GPOS TableGPOS // An absent table has a nil slice of lookups
}

LayoutTables exposes advanced layout tables. All fields are optional.

type LigatureCaretList

type LigatureCaretList struct {
	Coverage  Coverage
	LigCarets [][]CaretValue // once successfully parsed, has same length as Coverage.Size()
}

type LigatureGlyph

type LigatureGlyph struct {
	// Glyphs composing the ligature, starting after the
	// implicit first glyph, given in the coverage of the
	// SubstitutionLigature table
	Components []uint16
	// Output ligature glyph
	Glyph GID
}

func (LigatureGlyph) Matches

func (l LigatureGlyph) Matches(glyphsFromSecond []GID) bool

Matches tests if the ligature should be applied on `glyphsFromSecond`, which starts from the second glyph.

type LookupChainedContext1

type LookupChainedContext1 [][]ChainedSequenceRule

type LookupChainedContext2

type LookupChainedContext2 struct {
	BacktrackClass Class
	InputClass     Class
	LookaheadClass Class
	SequenceSets   [][]ChainedSequenceRule
}

type LookupChainedContext3

type LookupChainedContext3 struct {
	Backtrack       []Coverage
	Input           []Coverage
	Lookahead       []Coverage
	SequenceLookups []SequenceLookup
}

type LookupContext1

type LookupContext1 [][]SequenceRule

type LookupContext2

type LookupContext2 struct {
	Class        Class
	SequenceSets [][]SequenceRule
}

type LookupContext3

type LookupContext3 struct {
	Coverages       []Coverage
	SequenceLookups []SequenceLookup
}

type LookupFlag

type LookupFlag = uint16
const (
	// This bit relates only to the correct processing of
	// the cursive attachment lookup type (GPOS lookup type 3).
	// When this bit is set, the last glyph in a given sequence to
	// which the cursive attachment lookup is applied, will be positioned on the baseline.
	RightToLeft      LookupFlag = 1 << iota
	IgnoreBaseGlyphs            // If set, skips over base glyphs
	IgnoreLigatures             // If set, skips over ligatures
	IgnoreMarks                 // If set, skips over all combining marks
	// If set, indicates that the lookup table structure
	// is followed by a MarkFilteringSet field.
	// The layout engine skips over all mark glyphs not in the mark filtering set indicated.
	UseMarkFilteringSet
	Reserved LookupFlag = 0x00E0 // For future use (Set to zero)
	// If not zero, skips over all marks of attachment
	// type different from specified.
	MarkAttachmentType LookupFlag = 0xFF00
)

type LookupGPOS

type LookupGPOS struct {
	// After successful parsing, it is a non empty array
	// with all subtables of the same `GPOSType`.
	Subtables []GPOSSubtable
	Type      GPOSType
	LookupOptions
}

LookupGPOS is a lookup for GPOS tables.

type LookupGSUB

type LookupGSUB struct {
	// After successful parsing, all subtables have the `GSUBType`.
	Subtables []GSUBSubtable
	LookupOptions
	Type GSUBType
}

LookupGSUB is a lookup for GSUB tables.

type LookupOptions

type LookupOptions struct {
	Flag LookupFlag // Lookup qualifiers.
	// Index (base 0) into GDEF mark glyph sets structure,
	// meaningfull only if UseMarkFilteringSet is set.
	MarkFilteringSet uint16 // TODO: sanitize with gdef
}

func (LookupOptions) Props

func (l LookupOptions) Props() uint32

Props returns a 32-bit integer where the lower 16-bit is `Flag` and the higher 16-bit is `MarkFilteringSet` if the lookup uses one.

type Metric

type Metric struct {
	Advance, SideBearing int16
}

Metric contains the advance and side bearing of each glyph.

type MortxSubtable

type MortxSubtable struct {
	Data     interface{ Type() MorxSubtableType }
	Coverage uint8  // high byte of the coverage flag
	Flags    uint32 // Mask identifying which subtable this is.
}

type MorxChain

type MorxChain struct {
	Features     []AATFeature
	Subtables    []MortxSubtable
	DefaultFlags uint32
}

type MorxContextualSubtable

type MorxContextualSubtable struct {
	Substitutions []Class
	Machine       AATStateTable
}

func (MorxContextualSubtable) Type

type MorxInsertionSubtable

type MorxInsertionSubtable struct {
	// After successul parsing, this array may be safely
	// indexed by the indexes and counts from Machine entries.
	Insertions []GID
	Machine    AATStateTable
}

func (MorxInsertionSubtable) Type

type MorxLigatureSubtable

type MorxLigatureSubtable struct {
	LigatureAction []uint32
	Component      []uint16
	Ligatures      []GID
	Machine        AATStateTable
}

func (MorxLigatureSubtable) Type

type MorxNonContextualSubtable

type MorxNonContextualSubtable struct {
	Class // the lookup value is interpreted as a GlyphIndex
}

func (MorxNonContextualSubtable) Type

type MorxRearrangementSubtable

type MorxRearrangementSubtable AATStateTable

MorxRearrangementSubtable is a 'morx' subtable format 0.

func (MorxRearrangementSubtable) Type

type MorxSubtableType

type MorxSubtableType uint8

MorxSubtableType indicates the kind of 'morx' subtable. See the constants.

const (
	MorxRearrangement MorxSubtableType = iota
	MorxContextual
	MorxLigature

	MorxNonContextual
	MorxInsertion
)

type NameEntry

type NameEntry struct {
	Value      []byte // raw value of the name
	PlatformID PlatformID
	EncodingID PlatformEncodingID
	LanguageID PlatformLanguageID
	NameID     NameID
}

func (*NameEntry) Label

func (n *NameEntry) Label() string

func (*NameEntry) Platform

func (n *NameEntry) Platform() string

func (*NameEntry) String

func (n *NameEntry) String() string

String is a best-effort attempt to get an UTF-8 encoded version of Value. Only MicrosoftUnicode (3,1 ,X), MacRomain (1,0,X) and Unicode platform strings are supported.

type NameID

type NameID uint16

NameID is the ID for entries in the font table.

const (
	NameCopyrightNotice NameID = iota
	NameFontFamily
	NameFontSubfamily
	NameUniqueIdentifier
	NameFull
	NameVersion
	NamePostscript
	NameTrademark
	NameManufacturer
	NameDesigner
	NameDescription
	NameVendorURL
	NameDesignerURL
	NameLicenseDescription

	NameLicenseURL
	NamePreferredFamily    // or Typographic Family
	NamePreferredSubfamily // or Typographic Subfamily
	NameCompatibleFull
	NameSampleText
	NamePostscriptCID
	NameWWSFamily
	NameWWSSubfamily
	NameLightBackgroundPalette
	NameDarkBackgroundPalette
)

func (NameID) String

func (nameId NameID) String() string

String returns an identifying

type PlatformEncodingID

type PlatformEncodingID uint16

PlatformEncodingID represents the platform specific id for entries in the name table. The most common values are provided as constants.

type PlatformID

type PlatformID uint16

PlatformID represents the platform id for entries in the name table.

const (
	PlatformUnicode PlatformID = iota
	PlatformMac
	PlatformIso /* deprecated */
	PlatformMicrosoft
	PlatformCustom

	PlatformAdobe /* artificial */
)

func (PlatformID) String

func (p PlatformID) String() string

String returns an idenfying string for each platform or "Platform X" for unknown values.

type PlatformLanguageID

type PlatformLanguageID uint16

PlatformLanguageID represents the language used by an entry in the name table, the three most common values are provided as constants.

type Script

type Script struct {
	DefaultLanguage *LangSys
	Languages       []LangSys
	Tag             Tag
}

Script represents a single script (i.e "latn" (Latin), "cyrl" (Cyrillic), etc).

func (Script) FindLanguage

func (t Script) FindLanguage(language Tag) int

FindLanguage looks for `language` and return its index into the Languages slice, or -1 if the tag is not found.

func (Script) GetLangSys

func (t Script) GetLangSys(index uint16) LangSys

GetLangSys return the language at `index`. It `index` is out of range (for example with 0xFFFF), it returns `DefaultLanguage` (which may be empty)

type SequenceLookup

type SequenceLookup struct {
	InputIndex  uint16 // Index (zero-based) into the input glyph sequence
	LookupIndex uint16 // Index (zero-based) into the LookupList
}

SequenceLookup is used to specify an action (a nested lookup) to be applied to a glyph at a particular sequence position within the input sequence.

type SequenceRule

type SequenceRule struct {
	// Starts with the second glyph
	// For format1, it is interpreted as GlyphIndex, for format 2, as ClassID
	Input   []uint16
	Lookups []SequenceLookup
}

SequenceRule is used in Context format 1 and 2

type SimpleKerns

type SimpleKerns interface {
	// KernPair return the kern value for the given pair, or zero.
	// The value is expressed in glyph units and
	// is negative when glyphs should be closer.
	KernPair(left, right GID) int16
}

SimpleKerns store a compact form of the kerning values. It is not implemented by complex AAT kerning subtables.

type TableAnkr

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

TableAnkr represents the ankr table

func (TableAnkr) GetAnchor

func (t TableAnkr) GetAnchor(glyph GID, index int) (anchor AATAnchor)

GetAnchor return the i-th anchor for `glyph`, or {0,0} if not found.

type TableCmap

type TableCmap struct {
	Cmaps []CmapSubtable
	// contains filtered or unexported fields
}

TableCmap defines the mapping of character codes to the glyph index values used in the font. It may contain more than one subtable, in order to support more than one character encoding scheme.

func (TableCmap) BestEncoding

func (t TableCmap) BestEncoding() (Cmap, fonts.CmapEncoding)

BestEncoding returns the widest encoding supported. For valid fonts, the returned cmap won't be nil.

func (*TableCmap) FindSubtable

func (t *TableCmap) FindSubtable(id CmapID) Cmap

FindSubtable returns the cmap for the given platform and encoding, or nil if not found.

type TableFeat

type TableFeat []AATFeatureName

func (TableFeat) GetFeature

func (t TableFeat) GetFeature(feature uint16) *AATFeatureName

GetFeature performs a binary search into the names, using `Feature` as key, returning `nil` if not found.

type TableFvar

type TableFvar struct {
	Axis      []VarAxis
	Instances []VarInstance // contains the default instance
}

func (*TableFvar) GetDesignCoords

func (fvar *TableFvar) GetDesignCoords(variations []Variation, designCoords []float32)

GetDesignCoords updates the design coordinates, with the given pairs of axis/value. It will panic if `designCoords` has not the length expected by the table, that is the number of axis.

func (*TableFvar) GetDesignCoordsDefault

func (fvar *TableFvar) GetDesignCoordsDefault(variations []Variation) []float32

GetDesignCoordsDefault returns the design coordinates corresponding to the given pairs of axis/value. The default value of the axis is used when not specified in the variations.

func (TableFvar) IsDefaultInstance

func (fvar TableFvar) IsDefaultInstance(it VarInstance) bool

IsDefaultInstance returns `true` is `instance` has the same coordinates as the default instance.

type TableGDEF

type TableGDEF struct {
	// Identify the class of the glyph:
	//	1:	Base glyph, single character, spacing glyph
	//	2:	Ligature glyph (multiple character, spacing glyph)
	//	3:	Mark glyph (non-spacing combining glyph)
	//	4:	Component glyph (part of single character, spacing glyph)
	// May be nil
	Class Class
	// Class to which a mark glyph may belong (may be nil)
	MarkAttach        Class
	MarkGlyphSet      []Coverage        // used in GSUB and GPOS lookups to filter which marks in a string are considered or ignored
	VariationStore    VariationStore    // for variable fonts, may be empty
	LigatureCaretList LigatureCaretList // optional
}

func (*TableGDEF) GetGlyphProps

func (t *TableGDEF) GetGlyphProps(glyph GID) GlyphProps

GetGlyphProps return a summary of the glyph properties.

type TableGPOS

type TableGPOS struct {
	Lookups []LookupGPOS
	TableLayout
}

TableGPOS provides precise control over glyph placement for sophisticated text layout and rendering in each script and language system that a font supports.

type TableGSUB

type TableGSUB struct {
	Lookups []LookupGSUB
	TableLayout
}

TableGSUB is the Glyph Substitution (GSUB) table. It provides data for substition of glyphs for appropriate rendering of scripts, such as cursively-connecting forms in Arabic script, or for advanced typographic effects, such as ligatures.

type TableGlyf

type TableGlyf []GlyphData // length numGlyphs

type TableHVhea

type TableHVhea struct {
	Ascent               int16 // typoAscent in version 1.1
	Descent              int16 // typoDescent in version 1.1
	LineGap              int16 // typoLineGap in version 1.1
	AdvanceMax           uint16
	MinFirstSideBearing  int16 // left/top
	MinSecondSideBearing int16 // right/bottom
	MaxExtent            int16
	CaretSlopeRise       int16
	CaretSlopeRun        int16
	CaretOffset          int16

	MetricDataFormat int16
	NumberOfHMetrics uint16
	// contains filtered or unexported fields
}

TableHVhea exposes global metrics for horizontal or vertical writing.

type TableHVmtx

type TableHVmtx []Metric // with length numGlyphs

TableHVmtx contains advance width and side bearings for each glyph.

type TableHead

type TableHead struct {
	Created      longdatetime
	Updated      longdatetime
	FontRevision uint32

	UnitsPerEm    uint16
	Flags         uint16
	XMin          int16
	YMin          int16
	XMax          int16
	YMax          int16
	MacStyle      uint16
	LowestRecPPEM uint16
	FontDirection int16
	// contains filtered or unexported fields
}

TableHead contains critical information about the rest of the font. https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6head.html https://docs.microsoft.com/fr-fr/typography/opentype/spec/head

func (*TableHead) ExpectedChecksum

func (table *TableHead) ExpectedChecksum() uint32

ExpectedChecksum is the checksum that the file should have had.

func (*TableHead) Upem

func (table *TableHead) Upem() uint16

Upem returns the units per em

type TableKernx

type TableKernx []KernSubtable

TableKernx represents a 'kern' or 'kerx' kerning table. It supports both Microsoft and Apple formats.

type TableLayout

type TableLayout struct {
	Scripts           []Script
	Features          []FeatureRecord
	FeatureVariations []FeatureVariation
	// contains filtered or unexported fields
}

TableLayout represents the common layout table used by GPOS and GSUB. The Features field contains all the features for this layout. However, the script and language determines which feature is used.

See https://www.microsoft.com/typography/otspec/chapter2.htm#organization See https://www.microsoft.com/typography/otspec/GPOS.htm See https://www.microsoft.com/typography/otspec/GSUB.htm

func (*TableLayout) FindFeatureIndex

func (t *TableLayout) FindFeatureIndex(featureTag Tag) (uint16, bool)

FindFeatureIndex fetches the index for a given feature tag in the specified face's GSUB table or GPOS table. Returns false if not found

func (*TableLayout) FindScript

func (t *TableLayout) FindScript(script Tag) int

FindScript looks for `script` and return its index into the Scripts slice, or -1 if the tag is not found.

func (*TableLayout) FindVariationIndex

func (t *TableLayout) FindVariationIndex(coords []float32) int

FindVariationIndex returns the first feature variation matching the specified variation coordinates, as an index in the `FeatureVariations` field. It returns `-1` if not found.

type TableMaxp

type TableMaxp struct {
	Version               uint32
	NumGlyphs             uint16
	MaxPoints             uint16
	MaxContours           uint16
	MaxCompositePoints    uint16
	MaxCompositeContours  uint16
	MaxZones              uint16
	MaxTwilightPoints     uint16
	MaxStorage            uint16
	MaxFunctionDefs       uint16
	MaxInstructionDefs    uint16
	MaxStackElements      uint16
	MaxSizeOfInstructions uint16
	MaxComponentElements  uint16
	MaxComponentDepth     uint16
}

TableMaxp table maxp

type TableMorx

type TableMorx []MorxChain

type TableMvar

type TableMvar struct {
	Values []VarValueRecord // sorted by tag
	Store  VariationStore
}

type TableName

type TableName []NameEntry

TableName represents the OpenType 'name' table. This contains human-readable meta-data about the font, for example the Author and Copyright. https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html

func (TableName) SelectEntry

func (names TableName) SelectEntry(name NameID) *NameEntry

SelectEntry return the entry for name or nil if not found.

type TableOS2

type TableOS2 struct {
	TableOS2Version4

	UsLowerPointSize uint16
	UsUpperPointSize uint16
}

type TableOS2Version0

type TableOS2Version0 struct {
	Version             uint16
	XAvgCharWidth       uint16
	USWeightClass       uint16
	USWidthClass        uint16
	FSType              uint16
	YSubscriptXSize     int16
	YSubscriptYSize     int16
	YSubscriptXOffset   int16
	YSubscriptYOffset   int16
	YSuperscriptXSize   int16
	YSuperscriptYSize   int16
	YSuperscriptXOffset int16
	YSuperscriptYOffset int16
	YStrikeoutSize      int16
	YStrikeoutPosition  int16
	SFamilyClass        int16
	Panose              [10]byte
	UlCharRange         [4]uint32
	AchVendID           Tag
	FsSelection         uint16
	USFirstCharIndex    uint16
	USLastCharIndex     uint16
	STypoAscender       int16
	STypoDescender      int16
	STypoLineGap        int16
	UsWinAscent         uint16
	UsWinDescent        uint16
}

type TableOS2Version1

type TableOS2Version1 struct {
	TableOS2Version0

	UlCodePageRange1 uint32
	UlCodePageRange2 uint32
}

type TableOS2Version4

type TableOS2Version4 struct {
	TableOS2Version1

	SxHeigh       int16
	SCapHeight    int16
	UsDefaultChar uint16
	UsBreakChar   uint16
	UsMaxContext  uint16
}

TableOS2Version4 is the OS2 format for versions 2,3 and 4

type TablePost

type TablePost struct {
	// Names stores the glyph names. It may be nil.
	Names GlyphNames
	// ItalicAngle in counter-clockwise degrees from the vertical. Zero for
	// upright text, negative for text that leans to the right (forward).
	ItalicAngle float64
	// Version of the version tag of the "post" table.
	Version uint32
	// UnderlinePosition is the suggested distance of the top of the
	// underline from the baseline (negative values indicate below baseline).
	UnderlinePosition int16
	// Suggested values for the underline thickness.
	UnderlineThickness int16
	// IsFixedPitch indicates that the font is not proportionally spaced
	// (i.e. monospaced).
	IsFixedPitch bool
}

TablePost represents an information stored in the PostScript font section.

type TableTrak

type TableTrak struct {
	Horizontal, Vertical TrakData // may be empty
}

func (TableTrak) IsEmpty

func (t TableTrak) IsEmpty() bool

IsEmpty return `true` it the table has no entries.

type Tag

type Tag uint32

Tag represents an open-type name. These are technically uint32's, but are usually displayed in ASCII as they are all acronyms. See https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#Overview

func MustNewTag

func MustNewTag(str string) Tag

MustNewTag gives you the Tag corresponding to the acronym. This function will panic if the string passed in is not 4 bytes long.

func NewTag

func NewTag(a, b, c, d byte) Tag

NewTag returns the tag for <abcd>.

func (Tag) String

func (tag Tag) String() string

String returns the ASCII representation of the tag.

type TrackEntry

type TrackEntry struct {
	PerSizeTracking []int16 // in font units, with length len(Sizes)
	Track           float32
	NameIndex       NameID
}

type TrakData

type TrakData struct {
	Entries []TrackEntry
	Sizes   []float32
}

func (TrakData) GetTracking

func (td TrakData) GetTracking(ptem float32, trackValue float32) float32

GetTracking select the tracking for the given `trackValue` and apply it for `ptem`. It returns 0 if not found.

type VarAxis

type VarAxis struct {
	Tag     Tag       // Tag identifying the design variation for the axis.
	Minimum Float1616 // minium value on the variation axis that the font covers
	Default Float1616 // default position on the axis
	Maximum Float1616 // maximum value on the variation axis that the font covers
	// contains filtered or unexported fields
}

type VarInstance

type VarInstance struct {
	Coords    []float32 // in design units; length: number of axis
	Subfamily NameID

	PSStringID NameID
}

type VarValueRecord

type VarValueRecord struct {
	Tag   Tag
	Index VariationStoreIndex
}

type Variation

type Variation struct {
	Tag   Tag     // variation-axis identifier tag
	Value float32 // in design units
}

Variation defines a value for a wanted variation axis.

type VariationRegion

type VariationRegion [3]float32

VariationRegion stores start, peek, end coordinates.

type VariationStore

type VariationStore struct {
	Regions [][]VariationRegion // for each region, for each axis
	Datas   []ItemVariationData
}

VariationStore store variation data. After successful parsing, every region indexes in `Datas` elements are valid, that is, can safely be used as index into `Regions`.

func (VariationStore) GetDelta

func (store VariationStore) GetDelta(index VariationStoreIndex, coords []float32) float32

GetDelta uses the variation store and the selected instance coordinates to compute the value at `index`.

type VariationStoreIndex

type VariationStoreIndex struct {
	DeltaSetOuter, DeltaSetInner uint16
}

VariationStoreIndex reference an item in the variation store

Jump to

Keyboard shortcuts

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