Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultFontDirs() []string
- func DefaultGenericFonts() map[string][]string
- func Extension(b []byte) string
- func FromGoFreetype(font *truetype.Font) []byte
- func FromGoSFNT(font *sfnt.Font) []byte
- func MediaType(b []byte) (string, error)
- func NewSFNTReader(r io.Reader) (*bytes.Reader, error)
- func ParseEOT(b []byte) ([]byte, error)
- func ParseWOFF(b []byte) ([]byte, error)
- func ParseWOFF2(b []byte) ([]byte, error)
- func ToSFNT(b []byte) ([]byte, error)
- func Uint8ToFlags(v uint8) (flags [8]bool)
- func Uint16ToFlags(v uint16) (flags [16]bool)
- type AFM
- func (afm *AFM) FindGlyphName(name string) uint16
- func (afm *AFM) GlyphAdvance(glyphID uint16) uint16
- func (afm *AFM) GlyphBounds(glyphID uint16) (int16, int16, int16, int16)
- func (afm *AFM) GlyphIndex(r rune) uint16
- func (afm *AFM) GlyphName(glyphID uint16) string
- func (afm *AFM) Kerning(left, right uint16) int16
- func (afm *AFM) NumGlyphs() uint16
- type AFMCharMetrics
- type EncodingID
- type FeatureTag
- type FontMetadata
- type Hinting
- type LanguageTag
- type MergeOptions
- type NameID
- type Pather
- type PlatformID
- type SFNT
- func (sfnt *SFNT) FindGlyphName(name string) uint16
- func (sfnt *SFNT) GlyphAdvance(glyphID uint16) uint16
- func (sfnt *SFNT) GlyphBounds(glyphID uint16) (int16, int16, int16, int16)
- func (sfnt *SFNT) GlyphIndex(r rune) uint16
- func (sfnt *SFNT) GlyphName(glyphID uint16) string
- func (sfnt *SFNT) GlyphPath(p Pather, glyphID, ppem uint16, x, y, scale float64, hinting Hinting) error
- func (sfnt *SFNT) GlyphToUnicode(glyphID uint16) []rune
- func (sfnt *SFNT) GlyphVerticalAdvance(glyphID uint16) uint16
- func (sfnt *SFNT) Kerning(left, right uint16) int16
- func (sfnt *SFNT) Merge(sfnt2 *SFNT, options MergeOptions) error
- func (sfnt *SFNT) NumGlyphs() uint16
- func (sfnt *SFNT) SetGlyphNames(names []string) error
- func (sfnt *SFNT) Subset(glyphIDs []uint16, options SubsetOptions) (*SFNT, error)
- func (sfnt *SFNT) UnitsPerEm() uint16
- func (sfnt *SFNT) VerticalMetrics() (uint16, uint16, uint16)
- func (sfnt *SFNT) Write() []byte
- func (sfnt *SFNT) WriteWOFF2() ([]byte, error)
- type ScriptTag
- type Style
- type SubsetOptions
- type SystemFonts
- type ValueRecord
Constants ¶
const ( PlatformUnicode = PlatformID(0) PlatformMacintosh = PlatformID(1) PlatformWindows = PlatformID(3) PlatformCustom = PlatformID(4) )
see PlatformID
const ( EncodingUnicode2BMP = EncodingID(3) EncodingUnicode2FullRepertoir = EncodingID(4) EncodingUnicodeVariationSequences = EncodingID(5) EncodingUnicodeFullRepertoire = EncodingID(6) EncodingMacintoshRoman = EncodingID(0) EncodingMacintoshJapanese = EncodingID(1) EncodingMacintoshChineseTraditional = EncodingID(2) EncodingMacintoshKorean = EncodingID(3) EncodingMacintoshArabic = EncodingID(4) EncodingMacintoshHebrew = EncodingID(5) EncodingMacintoshGreek = EncodingID(6) EncodingMacintoshRussian = EncodingID(7) EncodingMacintoshRSymbol = EncodingID(8) EncodingMacintoshDevanagari = EncodingID(9) EncodingMacintoshGurmukhi = EncodingID(10) EncodingMacintoshGujarati = EncodingID(11) EncodingMacintoshOriya = EncodingID(12) EncodingMacintoshBengali = EncodingID(13) EncodingMacintoshTamil = EncodingID(14) EncodingMacintoshTelugu = EncodingID(15) EncodingMacintoshKannada = EncodingID(16) EncodingMacintoshMalayalam = EncodingID(17) EncodingMacintoshSinhalese = EncodingID(18) EncodingMacintoshBurmese = EncodingID(19) EncodingMacintoshKhmer = EncodingID(20) EncodingMacintoshThai = EncodingID(21) EncodingMacintoshLaotian = EncodingID(22) EncodingMacintoshGeorgian = EncodingID(23) EncodingMacintoshArmenian = EncodingID(24) EncodingMacintoshChineseSimplified = EncodingID(25) EncodingMacintoshTibetan = EncodingID(26) EncodingMacintoshMongolian = EncodingID(27) EncodingMacintoshGeez = EncodingID(28) EncodingMacintoshSlavic = EncodingID(29) EncodingMacintoshVietnamese = EncodingID(30) EncodingMacintoshSindhi = EncodingID(31) EncodingMacintoshUninterpreted = EncodingID(32) EncodingWindowsSymbol = EncodingID(0) EncodingWindowsUnicodeBMP = EncodingID(1) EncodingWindowsShiftJIS = EncodingID(2) EncodingWindowsPRC = EncodingID(3) EncodingWindowsBig5 = EncodingID(4) EncodingWindowsWansung = EncodingID(5) EncodingWindowsJohab = EncodingID(6) EncodingWindowsUnicodeFullRepertoir = EncodingID(10) )
see EncodingID
const ( NameCopyrightNotice = NameID(0) NameFontFamily = NameID(1) NameFontSubfamily = NameID(2) NameUniqueIdentifier = NameID(3) NameFull = NameID(4) NameVersion = NameID(5) NamePostScript = NameID(6) NameTrademark = NameID(7) NameManufacturer = NameID(8) NameDesigner = NameID(9) NameDescription = NameID(10) NameVendorURL = NameID(11) NameDesignerURL = NameID(12) NameLicense = NameID(13) NameLicenseURL = NameID(14) NamePreferredFamily = NameID(16) NamePreferredSubfamily = NameID(17) NameCompatibleFull = NameID(18) NameSampleText = NameID(19) NamePostScriptCID = NameID(20) NameWWSFamily = NameID(21) NameWWSSubfamily = NameID(22) NameLightBackgroundPalette = NameID(23) NameDarkBackgroundPalette = NameID(24) NameVariationsPostScriptPrefix = NameID(25) )
see NameID
const ( UnknownScript = ScriptTag("") DefaultScript = ScriptTag("DFLT") )
const ( UnknownLanguage = LanguageTag("") DefaultLanguage = LanguageTag("DFLT") // permanently reserved and not used in font )
const MaxCmapSegments = 20000
MaxCmapSegments is the maximum number of cmap segments that will be accepted.
const (
UnknownFeature = FeatureTag("")
)
Variables ¶
var ( KeepAllTables = []string{"all"} KeepMinTables = []string{"min"} KeepPDFTables = []string{"pdf"} )
var ErrBadNumOperands = fmt.Errorf("bad number of operands for operator")
var ErrExceedsMemory = fmt.Errorf("memory limit exceded")
ErrExceedsMemory is returned if the font is malformed.
var ErrInvalidFontData = fmt.Errorf("invalid font data")
ErrInvalidFontData is returned if the font is malformed.
var MaxMemory uint32 = 30 * 1024 * 1024
MaxMemory is the maximum memory that can be allocated by a font.
Functions ¶
func DefaultFontDirs ¶
func DefaultFontDirs() []string
func DefaultGenericFonts ¶
func Extension ¶
Extension returns the file extension for a given font. An empty string is returned when the font is not recognized.
func FromGoFreetype ¶
FromGoFreetype parses a structure from truetype.Font to a valid SFNT byte slice.
func FromGoSFNT ¶
FromGoSFNT parses a structure from sfnt.Font to a valid SFNT byte slice.
func NewSFNTReader ¶
NewSFNTReader takes an io.Reader and transforms it into an SFNT reader. That is, given TTF/OTF/WOFF/WOFF2/EOT input, it will return TTF/OTF output.
func ParseEOT ¶
ParseEOT parses the EOT font format and returns its contained SFNT font format (TTF or OTF). See https://www.w3.org/Submission/EOT/
func ParseWOFF ¶
ParseWOFF parses the WOFF font format and returns its contained SFNT font format (TTF or OTF). See https://www.w3.org/TR/WOFF/
func ParseWOFF2 ¶
ParseWOFF2 parses the WOFF2 font format and returns its contained SFNT font format (TTF or OTF). See https://www.w3.org/TR/WOFF2/
func ToSFNT ¶
ToSFNT takes a byte slice and transforms it into an SFNT byte slice. That is, given TTF/OTF/WOFF/WOFF2/EOT input, it will return TTF/OTF output.
func Uint8ToFlags ¶
Uint8ToFlags converts a uint8 in 8 booleans from least to most significant.
func Uint16ToFlags ¶
Uint16ToFlags converts a uint16 in 16 booleans from least to most significant.
Types ¶
type AFM ¶
type AFM struct {
FontName string
FullName string
FamilyName string
Weight string
FontBBox [4]int16
CapHeight uint16
XHeight uint16
Ascender uint16
Descender uint16
UnderlinePosition uint16
UnderlineThickness uint16
ItalicAngle float64
CharWidth [2]uint16
IsFixedPitch bool
CharMetrics []AFMCharMetrics
Ligatures map[[2]uint16]uint16
KernPairs map[[2]uint16]int16
// contains filtered or unexported fields
}
func (*AFM) FindGlyphName ¶
FindGlyphName returns the glyphID for a given glyph name. When the name is not defined it returns 0.
func (*AFM) GlyphAdvance ¶
GlyphAdvance returns the (horizontal) advance width of the glyph.
func (*AFM) GlyphBounds ¶
GlyphBounds returns the bounding rectangle (xmin,ymin,xmax,ymax) of the glyph.
func (*AFM) GlyphIndex ¶
GlyphIndex returns the glyphID for a given rune. When the rune is not defined it returns 0.
func (*AFM) GlyphName ¶
GlyphName returns the name of the glyph. It returns an empty string when no name exists.
type AFMCharMetrics ¶
type FeatureTag ¶
type FeatureTag string
type FontMetadata ¶
func (FontMetadata) String ¶
func (metadata FontMetadata) String() string
type LanguageTag ¶
type LanguageTag string
type MergeOptions ¶
type MergeOptions struct {
RearrangeCmap bool // Rearrange glyph unicode mapping, assigning a sequential codepoint for each glyph in order starting at 33 (exclamation). May be useful when embedding into a PDF with a custom unicode mapping.
}
type Pather ¶
type Pather interface {
MoveTo(float64, float64)
LineTo(float64, float64)
QuadTo(float64, float64, float64, float64)
CubeTo(float64, float64, float64, float64, float64, float64)
Close()
}
Pather is an interface to append a glyph's path to canvas.Path.
type SFNT ¶
type SFNT struct {
Length uint32
Version string
IsCFF, IsTrueType bool // only one can be true
Tables map[string][]byte
// required
Cmap *cmapTable
Head *headTable
Hhea *hheaTable
Hmtx *hmtxTable
Maxp *maxpTable
Name *nameTable
OS2 *os2Table
Post *postTable
// TrueType
Glyf *glyfTable
Loca *locaTable
// CFF
CFF *cffTable
// optional
Kern *kernTable
Vhea *vheaTable
Vmtx *vmtxTable
// TODO: SFNT tables
//Hdmx *hdmxTable
Gpos *gposgsubTable
Gsub *gposgsubTable
Jsft *jsftTable
}
SFNT is a parsed OpenType font.
func ParseEmbeddedSFNT ¶
ParseEmbeddedSFNT is like ParseSFNT but for embedded font files in PDFs. It allows font files with fewer required tables.
func ParseFont ¶
ParseFont parses a byte slice and of a TTF, OTF, WOFF, WOFF2, or EOT font format. It will return the parsed font and its mimetype. DEPRECATED: use ParseSFNT
func ParseSFNT ¶
ParseSFNT parses an OpenType file format (TTF, OTF, TTC). The index is used for font collections to select a single font.
func (*SFNT) FindGlyphName ¶
FindGlyphName returns the glyphID for a given glyph name. When the name is not defined it returns 0.
func (*SFNT) GlyphAdvance ¶
GlyphAdvance returns the (horizontal) advance width of the glyph.
func (*SFNT) GlyphBounds ¶
GlyphBounds returns the bounding rectangle (xmin,ymin,xmax,ymax) of the glyph.
func (*SFNT) GlyphIndex ¶
GlyphIndex returns the glyph ID for the corresponding rune. It looks for each character map subtable in the order in which they appear and returns the first match, or 0 when no match is found.
func (*SFNT) GlyphName ¶
GlyphName returns the name of the glyph. It returns an empty string when no name exists.
func (*SFNT) GlyphPath ¶
func (sfnt *SFNT) GlyphPath(p Pather, glyphID, ppem uint16, x, y, scale float64, hinting Hinting) error
GlyphPath draws the glyph's contour as a path to the pather interface. It will use the specified ppem (pixels-per-EM) for hinting purposes. The path is draws to the (x,y) coordinate and scaled using the given scale factor.
func (*SFNT) GlyphToUnicode ¶
GlyphToUnicode returns the runes for the corresponding glyph ID. It looks for each character map subtable in the order in which they appear and returns the runes which reference the glyph ID, or nil when no match is found. This is the inverse mapping of the character map table and is cached after the first call. Each glyph may be mapped from multiple runes.
func (*SFNT) GlyphVerticalAdvance ¶
GlyphVerticalAdvance returns the vertical advance width of the glyph.
func (*SFNT) Kerning ¶
Kerning returns the kerning between two glyphs, i.e. the advance correction for glyph pairs.
func (*SFNT) Merge ¶
func (sfnt *SFNT) Merge(sfnt2 *SFNT, options MergeOptions) error
Merge merges the glyphs of another font into the current one in-place by merging the glyf, loca, kern tables (or CFF table for CFF fonts), as well as the hmtx, cmap, and post tables. Also updates the maxp, head, and OS/2 tables. The other font remains untouched.
func (*SFNT) SetGlyphNames ¶
func (*SFNT) Subset ¶
func (sfnt *SFNT) Subset(glyphIDs []uint16, options SubsetOptions) (*SFNT, error)
Subset trims an SFNT font to contain only the passed glyphIDs, thereby resulting in a significant size reduction. The glyphIDs will apear in the specified order in the file and their dependencies are added to the end.
func (*SFNT) UnitsPerEm ¶
UnitsPerEm returns the number of units per em
func (*SFNT) VerticalMetrics ¶
VerticalMetrics returns the ascender, descender, and line gap values. It returns the "win" values, or the "typo" values if OS/2.FsSelection.USE_TYPO_METRICS is set. If those are zero or not set, default to the "hhea" values.
func (*SFNT) WriteWOFF2 ¶
type Style ¶
type Style int
Style defines the font style to be used for the font. It specifies a boldness with optionally italic, e.g. Black | Italic will specify a black boldness (a font-weight of 800 in CSS) and italic.
const ( UnknownStyle Style = -1 Thin Style = iota ExtraLight Light Regular Medium SemiBold Bold ExtraBold Black Italic Style = 1 << 8 )
see Style
func ParseStyle ¶
func ParseStyleCSS ¶
type SubsetOptions ¶
type SubsetOptions struct {
Tables []string // names of tables to include, special values are KeepAllTables, KeepMinTables, or KeepPDFTables
}
type SystemFonts ¶
type SystemFonts struct {
Generics map[string][]string
Fonts map[string]map[Style]FontMetadata
}
func FindSystemFonts ¶
func FindSystemFonts(dirs []string) (*SystemFonts, error)
func LoadSystemFonts ¶
func LoadSystemFonts(filename string) (*SystemFonts, error)
func (*SystemFonts) Add ¶
func (s *SystemFonts) Add(metadata FontMetadata)
func (*SystemFonts) Match ¶
func (s *SystemFonts) Match(name string, style Style) (FontMetadata, bool)
func (*SystemFonts) Save ¶
func (s *SystemFonts) Save(filename string) error
func (*SystemFonts) String ¶
func (s *SystemFonts) String() string
