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 Uint16ToFlags(v uint16) (flags [16]bool)
- func Uint8ToFlags(v uint8) (flags [8]bool)
- type BinaryReader
- func (r *BinaryReader) EOF() bool
- func (r *BinaryReader) Len() uint32
- func (r *BinaryReader) Pos() uint32
- func (r *BinaryReader) ReadByte() byte
- func (r *BinaryReader) ReadBytes(n uint32) []byte
- func (r *BinaryReader) ReadInt16() int16
- func (r *BinaryReader) ReadInt16LE() int16
- func (r *BinaryReader) ReadInt32() int32
- func (r *BinaryReader) ReadInt64() int64
- func (r *BinaryReader) ReadInt8() int8
- func (r *BinaryReader) ReadString(n uint32) string
- func (r *BinaryReader) ReadUint16() uint16
- func (r *BinaryReader) ReadUint16LE() uint16
- func (r *BinaryReader) ReadUint32() uint32
- func (r *BinaryReader) ReadUint32LE() uint32
- func (r *BinaryReader) ReadUint64() uint64
- func (r *BinaryReader) ReadUint8() uint8
- func (r *BinaryReader) Seek(pos uint32)
- type BinaryWriter
- func (w *BinaryWriter) Bytes() []byte
- func (w *BinaryWriter) Len() uint32
- func (w *BinaryWriter) WriteByte(v byte)
- func (w *BinaryWriter) WriteBytes(v []byte)
- func (w *BinaryWriter) WriteInt16(v int16)
- func (w *BinaryWriter) WriteInt32(v int32)
- func (w *BinaryWriter) WriteInt64(v int64)
- func (w *BinaryWriter) WriteInt8(v int8)
- func (w *BinaryWriter) WriteString(v string)
- func (w *BinaryWriter) WriteUint16(v uint16)
- func (w *BinaryWriter) WriteUint32(v uint32)
- func (w *BinaryWriter) WriteUint64(v uint64)
- func (w *BinaryWriter) WriteUint8(v uint8)
- type BitmapReader
- type EncodingID
- type FeatureTag
- type FontMetadata
- type Hinting
- type LanguageTag
- type NameID
- type Pather
- type PlatformID
- type SFNT
- func (sfnt *SFNT) GlyphAdvance(glyphID uint16) uint16
- func (sfnt *SFNT) GlyphBounds(glyphID uint16) (int16, int16, int16, int16, error)
- 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) GlyphVerticalAdvance(glyphID uint16) uint16
- func (sfnt *SFNT) Kerning(left, right uint16) int16
- func (sfnt *SFNT) NumGlyphs() uint16
- func (sfnt *SFNT) Subset(glyphIDs []uint16, writeTables WriteTables) ([]byte, []uint16)
- func (sfnt *SFNT) VerticalMetrics() (uint16, uint16, uint16)
- func (sfnt *SFNT) Write() []byte
- type ScriptTag
- type Style
- type SystemFonts
- type ValueRecord
- type WriteTables
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 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 Uint16ToFlags ¶
Uint16ToFlags converts a uint16 in 16 booleans from least to most significant.
func Uint8ToFlags ¶
Uint8ToFlags converts a uint8 in 8 booleans from least to most significant.
Types ¶
type BinaryReader ¶
type BinaryReader struct {
// contains filtered or unexported fields
}
BinaryReader is a binary big endian file format reader.
func NewBinaryReader ¶
func NewBinaryReader(buf []byte) *BinaryReader
NewBinaryReader returns a big endian binary file format reader.
func (*BinaryReader) EOF ¶
func (r *BinaryReader) EOF() bool
EOF returns true if we reached the end-of-file.
func (*BinaryReader) Len ¶
func (r *BinaryReader) Len() uint32
Len returns the remaining length of the buffer.
func (*BinaryReader) ReadByte ¶
func (r *BinaryReader) ReadByte() byte
ReadByte reads a single byte.
func (*BinaryReader) ReadBytes ¶
func (r *BinaryReader) ReadBytes(n uint32) []byte
ReadBytes reads n bytes.
func (*BinaryReader) ReadInt16LE ¶
func (r *BinaryReader) ReadInt16LE() int16
ReadInt16LE reads a int16 little endian.
func (*BinaryReader) ReadString ¶
func (r *BinaryReader) ReadString(n uint32) string
ReadString reads a string of length n.
func (*BinaryReader) ReadUint16 ¶
func (r *BinaryReader) ReadUint16() uint16
ReadUint16 reads a uint16.
func (*BinaryReader) ReadUint16LE ¶
func (r *BinaryReader) ReadUint16LE() uint16
ReadUint16LE reads a uint16 little endian.
func (*BinaryReader) ReadUint32 ¶
func (r *BinaryReader) ReadUint32() uint32
ReadUint32 reads a uint32.
func (*BinaryReader) ReadUint32LE ¶
func (r *BinaryReader) ReadUint32LE() uint32
ReadUint32LE reads a uint32 little endian.
func (*BinaryReader) ReadUint64 ¶
func (r *BinaryReader) ReadUint64() uint64
ReadUint64 reads a uint64.
func (*BinaryReader) Seek ¶
func (r *BinaryReader) Seek(pos uint32)
Seek set the reader position in the buffer.
type BinaryWriter ¶
type BinaryWriter struct {
// contains filtered or unexported fields
}
BinaryWriter is a big endian binary file format writer.
func NewBinaryWriter ¶
func NewBinaryWriter(buf []byte) *BinaryWriter
NewBinaryWriter returns a big endian binary file format writer.
func (*BinaryWriter) Bytes ¶
func (w *BinaryWriter) Bytes() []byte
Bytes returns the buffer's bytes.
func (*BinaryWriter) Len ¶
func (w *BinaryWriter) Len() uint32
Len returns the buffer's length in bytes.
func (*BinaryWriter) WriteByte ¶
func (w *BinaryWriter) WriteByte(v byte)
WriteByte writes the given byte to the buffer.
func (*BinaryWriter) WriteBytes ¶
func (w *BinaryWriter) WriteBytes(v []byte)
WriteBytes writes the given bytes to the buffer.
func (*BinaryWriter) WriteInt16 ¶
func (w *BinaryWriter) WriteInt16(v int16)
WriteInt16 writes the given int16 to the buffer.
func (*BinaryWriter) WriteInt32 ¶
func (w *BinaryWriter) WriteInt32(v int32)
WriteInt32 writes the given int32 to the buffer.
func (*BinaryWriter) WriteInt64 ¶
func (w *BinaryWriter) WriteInt64(v int64)
WriteInt64 writes the given int64 to the buffer.
func (*BinaryWriter) WriteInt8 ¶
func (w *BinaryWriter) WriteInt8(v int8)
WriteInt8 writes the given int8 to the buffer.
func (*BinaryWriter) WriteString ¶
func (w *BinaryWriter) WriteString(v string)
WriteString writes the given string to the buffer.
func (*BinaryWriter) WriteUint16 ¶
func (w *BinaryWriter) WriteUint16(v uint16)
WriteUint16 writes the given uint16 to the buffer.
func (*BinaryWriter) WriteUint32 ¶
func (w *BinaryWriter) WriteUint32(v uint32)
WriteUint32 writes the given uint32 to the buffer.
func (*BinaryWriter) WriteUint64 ¶
func (w *BinaryWriter) WriteUint64(v uint64)
WriteUint64 writes the given uint64 to the buffer.
func (*BinaryWriter) WriteUint8 ¶
func (w *BinaryWriter) WriteUint8(v uint8)
WriteUint8 writes the given uint8 to the buffer.
type BitmapReader ¶
type BitmapReader struct {
// contains filtered or unexported fields
}
BitmapReader is a binary bitmap reader.
func NewBitmapReader ¶
func NewBitmapReader(buf []byte) *BitmapReader
NewBitmapReader returns a binary bitmap reader.
func (*BitmapReader) EOF ¶
func (r *BitmapReader) EOF() bool
EOF returns if we reached the buffer's end-of-file.
func (*BitmapReader) Pos ¶
func (r *BitmapReader) Pos() uint32
Pos returns the current bit position.
type FeatureTag ¶
type FeatureTag string
type FontMetadata ¶
func (FontMetadata) String ¶
func (metadata FontMetadata) String() string
type LanguageTag ¶
type LanguageTag string
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 { Data []byte 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 //Hdmx *hdmxTable // TODO Vmtx *vmtxTable 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.
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) 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 glyphID for a given rune. When the rune is not defined it returns 0.
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) 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) Subset ¶
func (sfnt *SFNT) Subset(glyphIDs []uint16, writeTables WriteTables) ([]byte, []uint16)
Subset regenerates a font file containing 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. It returns the compressed font file and the glyphIDs in the order in which they appear.
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.
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 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
type ValueRecord ¶
type WriteTables ¶
type WriteTables int
const ( WriteAllTables WriteTables = iota WriteMinTables WritePDFTables )