-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfont.go
114 lines (88 loc) · 3.11 KB
/
font.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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.
package truetype
import (
"errors"
"github.com/benoitkugler/textlayout/fonts"
type1c "github.com/benoitkugler/textlayout/fonts/type1C"
)
var _ fonts.Face = (*Font)(nil)
type fixed struct {
Major int16
Minor uint16
}
type longdatetime struct {
SecondsSince1904 uint64
}
var (
// errUnsupportedFormat is returned from Parse if parsing failed
errUnsupportedFormat = errors.New("unsupported font format")
// errMissingTable is returned from *Table if the table does not exist in the font.
errMissingTable = errors.New("missing table")
errUnsupportedTableOffsetLength = errors.New("unsupported table offset or length")
errInvalidDfont = errors.New("invalid dfont")
)
type gid = uint16
// 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)
type Font struct {
cmap Cmap
cmapVar unicodeVariations
cmapEncoding fonts.CmapEncoding
Names TableName
hhea, vhea *TableHVhea
vorg *tableVorg // optional
cff *type1c.Font
post TablePost // optional
svg tableSVG // optional
// Optionnal, only present in variable fonts
varCoords []float32 // coordinates in usage, may be nil
hvar, vvar *tableHVvar // optional
avar tableAvar
mvar TableMvar
gvar tableGvar
fvar TableFvar
Glyf TableGlyf
vmtx, Hmtx TableHVmtx
bitmap bitmapTable // CBDT or EBLC or BLOC
sbix tableSbix
OS2 *TableOS2 // optional
// graphite font, optionnal
Graphite *GraphiteTables
// Advanced layout tables.
layoutTables LayoutTables
fontSummary fontSummary
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
upem uint16 // cached value
// HasHint is true if the font has a prep table.
HasHint bool
}
// LayoutTables exposes advanced layout tables.
// All the fields are optionnals.
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 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 *Font) LayoutTables() LayoutTables { return font.layoutTables }