/
std_times.go
295 lines (277 loc) · 11.8 KB
/
std_times.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
/*
* The embedded character metrics specified in this file are distributed under the terms listed in
* ./testdata/afms/MustRead.html.
*/
package fonts
import "sync"
func init() {
// The aliases seen for the standard 14 font names.
// Most of these are from table 5.5.1 in
// https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf
RegisterStdFont(TimesRomanName, newFontTimesRoman, "TimesNewRoman", "Times")
RegisterStdFont(TimesBoldName, newFontTimesBold, "TimesNewRoman,Bold", "Times,Bold")
RegisterStdFont(TimesItalicName, newFontTimesItalic, "TimesNewRoman,Italic", "Times,Italic")
RegisterStdFont(TimesBoldItalicName, newFontTimesBoldItalic, "TimesNewRoman,BoldItalic", "Times,BoldItalic")
}
const (
// timesFamily is a PDF name of the Times font family.
timesFamily = "Times"
// TimesRomanName is a PDF name of the Times font.
TimesRomanName = StdFontName("Times-Roman")
// TimesBoldName is a PDF name of the Times (bold) font.
TimesBoldName = StdFontName("Times-Bold")
// TimesItalicName is a PDF name of the Times (italic) font.
TimesItalicName = StdFontName("Times-Italic")
// TimesBoldItalicName is a PDF name of the Times (bold, italic) font.
TimesBoldItalicName = StdFontName("Times-BoldItalic")
)
// newFontTimesRoman returns a new instance of the font with a default encoder set (WinAnsiEncoding).
func newFontTimesRoman() StdFont {
timesOnce.Do(initTimes)
desc := Descriptor{
Name: TimesRomanName,
Family: timesFamily,
Weight: FontWeightRoman,
Flags: 0x0020,
BBox: [4]float64{-168, -218, 1000, 898},
ItalicAngle: 0,
Ascent: 683,
Descent: -217,
CapHeight: 662,
XHeight: 450,
StemV: 84,
StemH: 28,
}
return NewStdFont(desc, timesRomanCharMetrics)
}
// newFontTimesBold returns a new instance of the font with a default encoder set (WinAnsiEncoding).
func newFontTimesBold() StdFont {
timesOnce.Do(initTimes)
desc := Descriptor{
Name: TimesBoldName,
Family: timesFamily,
Weight: FontWeightBold,
Flags: 0x0020,
BBox: [4]float64{-168, -218, 1000, 935},
ItalicAngle: 0,
Ascent: 683,
Descent: -217,
CapHeight: 676,
XHeight: 461,
StemV: 139,
StemH: 44,
}
return NewStdFont(desc, timesBoldCharMetrics)
}
// newFontTimesItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
func newFontTimesItalic() StdFont {
timesOnce.Do(initTimes)
desc := Descriptor{
Name: TimesItalicName,
Family: timesFamily,
Weight: FontWeightMedium,
Flags: 0x0060,
BBox: [4]float64{-169, -217, 1010, 883},
ItalicAngle: -15.5,
Ascent: 683,
Descent: -217,
CapHeight: 653,
XHeight: 441,
StemV: 76,
StemH: 32,
}
return NewStdFont(desc, timesItalicCharMetrics)
}
// newFontTimesBoldItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
func newFontTimesBoldItalic() StdFont {
timesOnce.Do(initTimes)
desc := Descriptor{
Name: TimesBoldItalicName,
Family: timesFamily,
Weight: FontWeightBold,
Flags: 0x0060,
BBox: [4]float64{-200, -218, 996, 921},
ItalicAngle: -15,
Ascent: 683,
Descent: -217,
CapHeight: 669,
XHeight: 462,
StemV: 121,
StemH: 42,
}
return NewStdFont(desc, timesBoldItalicCharMetrics)
}
var timesOnce sync.Once
func initTimes() {
// unpack font metrics
timesRomanCharMetrics = make(map[rune]CharMetrics, len(type1CommonRunes))
timesBoldCharMetrics = make(map[rune]CharMetrics, len(type1CommonRunes))
timesBoldItalicCharMetrics = make(map[rune]CharMetrics, len(type1CommonRunes))
timesItalicCharMetrics = make(map[rune]CharMetrics, len(type1CommonRunes))
for i, r := range type1CommonRunes {
timesRomanCharMetrics[r] = CharMetrics{Wx: float64(timesRomanWx[i])}
timesBoldCharMetrics[r] = CharMetrics{Wx: float64(timesBoldWx[i])}
timesBoldItalicCharMetrics[r] = CharMetrics{Wx: float64(timesBoldItalicWx[i])}
timesItalicCharMetrics[r] = CharMetrics{Wx: float64(timesItalicWx[i])}
}
}
// timesRomanCharMetrics are the font metrics loaded from afms/Times-Roman.afm.
// See afms/MustRead.html for license information.
var timesRomanCharMetrics map[rune]CharMetrics
// timesBoldCharMetrics are the font metrics loaded from afms/Times-Bold.afm.
// See afms/MustRead.html for license information.
var timesBoldCharMetrics map[rune]CharMetrics
// timesBoldItalicCharMetrics are the font metrics loaded from afms/Times-BoldItalic.afm.
// See afms/MustRead.html for license information.
var timesBoldItalicCharMetrics map[rune]CharMetrics
// timesItalicCharMetrics font metrics loaded from afms/Times-Italic.afm.
// See afms/MustRead.html for license information.
var timesItalicCharMetrics map[rune]CharMetrics
// timesRomanWx are the font metrics loaded from afms/Times-Roman.afm.
// See afms/MustRead.html for license information.
var timesRomanWx = []int16{
722, 889, 722, 722, 722, 722, 722, 722, 722, 722,
722, 667, 667, 667, 667, 667, 722, 722, 722, 612,
611, 611, 611, 611, 611, 611, 611, 611, 611, 722,
500, 556, 722, 722, 722, 722, 333, 333, 333, 333,
333, 333, 333, 333, 389, 722, 722, 611, 611, 611,
611, 611, 889, 722, 722, 722, 722, 722, 722, 889,
722, 722, 722, 722, 722, 722, 722, 722, 556, 722,
667, 667, 667, 667, 556, 556, 556, 556, 556, 611,
611, 611, 556, 722, 722, 722, 722, 722, 722, 722,
722, 722, 722, 944, 722, 722, 722, 722, 611, 611,
611, 611, 444, 444, 444, 444, 333, 444, 667, 444,
444, 778, 444, 444, 469, 541, 500, 921, 444, 500,
278, 200, 480, 480, 333, 333, 333, 200, 350, 444,
444, 333, 444, 444, 333, 500, 333, 278, 250, 250,
760, 500, 500, 500, 500, 588, 500, 400, 333, 564,
500, 333, 278, 444, 444, 444, 444, 444, 444, 444,
500, 1000, 444, 1000, 500, 444, 564, 500, 333, 333,
333, 556, 500, 556, 500, 500, 167, 500, 500, 500,
500, 333, 564, 549, 500, 500, 333, 333, 500, 333,
333, 278, 278, 278, 278, 278, 278, 278, 278, 500,
500, 278, 278, 344, 278, 564, 549, 564, 471, 278,
778, 333, 564, 500, 564, 500, 500, 500, 500, 500,
549, 500, 500, 500, 500, 500, 500, 722, 333, 500,
500, 500, 500, 750, 750, 300, 276, 310, 500, 500,
500, 453, 333, 333, 476, 833, 250, 250, 1000, 564,
564, 500, 444, 444, 408, 444, 444, 444, 333, 333,
333, 180, 333, 333, 453, 333, 333, 760, 333, 389,
389, 389, 389, 389, 500, 278, 500, 500, 278, 250,
500, 600, 278, 326, 278, 500, 500, 750, 300, 333,
980, 500, 300, 500, 500, 500, 500, 500, 500, 500,
500, 500, 500, 500, 722, 500, 500, 500, 500, 500,
444, 444, 444, 444, 500,
}
// timesBoldWx are the font metrics loaded from afms/Times-Bold.afm.
// See afms/MustRead.html for license information.
var timesBoldWx = []int16{
722, 1000, 722, 722, 722, 722, 722, 722, 722, 722,
722, 667, 722, 722, 722, 722, 722, 722, 722, 612,
667, 667, 667, 667, 667, 667, 667, 667, 667, 722,
500, 611, 778, 778, 778, 778, 389, 389, 389, 389,
389, 389, 389, 389, 500, 778, 778, 667, 667, 667,
667, 667, 944, 722, 722, 722, 722, 722, 778, 1000,
778, 778, 778, 778, 778, 778, 778, 778, 611, 778,
722, 722, 722, 722, 556, 556, 556, 556, 556, 667,
667, 667, 611, 722, 722, 722, 722, 722, 722, 722,
722, 722, 722, 1000, 722, 722, 722, 722, 667, 667,
667, 667, 500, 500, 500, 500, 333, 500, 722, 500,
500, 833, 500, 500, 581, 520, 500, 930, 500, 556,
278, 220, 394, 394, 333, 333, 333, 220, 350, 444,
444, 333, 444, 444, 333, 500, 333, 333, 250, 250,
747, 500, 556, 500, 500, 672, 556, 400, 333, 570,
500, 333, 278, 444, 444, 444, 444, 444, 444, 444,
500, 1000, 444, 1000, 500, 444, 570, 500, 333, 333,
333, 556, 500, 556, 500, 500, 167, 500, 500, 500,
556, 333, 570, 549, 500, 500, 333, 333, 556, 333,
333, 278, 278, 278, 278, 278, 278, 278, 333, 556,
556, 278, 278, 394, 278, 570, 549, 570, 494, 278,
833, 333, 570, 556, 570, 556, 556, 556, 556, 500,
549, 556, 500, 500, 500, 500, 500, 722, 333, 500,
500, 500, 500, 750, 750, 300, 300, 330, 500, 500,
556, 540, 333, 333, 494, 1000, 250, 250, 1000, 570,
570, 556, 500, 500, 555, 500, 500, 500, 333, 333,
333, 278, 444, 444, 549, 444, 444, 747, 333, 389,
389, 389, 389, 389, 500, 333, 500, 500, 278, 250,
500, 600, 333, 416, 333, 556, 500, 750, 300, 333,
1000, 500, 300, 556, 556, 556, 556, 556, 556, 556,
500, 556, 556, 500, 722, 500, 500, 500, 500, 500,
444, 444, 444, 444, 500,
}
// timesBoldItalicWx are the font metrics loaded from afms/Times-BoldItalic.afm.
// See afms/MustRead.html for license information.
var timesBoldItalicWx = []int16{
667, 944, 667, 667, 667, 667, 667, 667, 667, 667,
667, 667, 667, 667, 667, 667, 722, 722, 722, 612,
667, 667, 667, 667, 667, 667, 667, 667, 667, 722,
500, 667, 722, 722, 722, 778, 389, 389, 389, 389,
389, 389, 389, 389, 500, 667, 667, 611, 611, 611,
611, 611, 889, 722, 722, 722, 722, 722, 722, 944,
722, 722, 722, 722, 722, 722, 722, 722, 611, 722,
667, 667, 667, 667, 556, 556, 556, 556, 556, 611,
611, 611, 611, 722, 722, 722, 722, 722, 722, 722,
722, 722, 667, 889, 667, 611, 611, 611, 611, 611,
611, 611, 500, 500, 500, 500, 333, 500, 722, 500,
500, 778, 500, 500, 570, 570, 500, 832, 500, 500,
278, 220, 348, 348, 333, 333, 333, 220, 350, 444,
444, 333, 444, 444, 333, 500, 333, 333, 250, 250,
747, 500, 500, 500, 500, 608, 500, 400, 333, 570,
500, 333, 278, 444, 444, 444, 444, 444, 444, 444,
500, 1000, 444, 1000, 500, 444, 570, 500, 389, 389,
333, 556, 500, 556, 500, 500, 167, 500, 500, 500,
500, 333, 570, 549, 500, 500, 333, 333, 556, 333,
333, 278, 278, 278, 278, 278, 278, 278, 278, 500,
500, 278, 278, 382, 278, 570, 549, 606, 494, 278,
778, 333, 606, 576, 570, 556, 556, 556, 556, 500,
549, 556, 500, 500, 500, 500, 500, 722, 333, 500,
500, 500, 500, 750, 750, 300, 266, 300, 500, 500,
500, 500, 333, 333, 494, 833, 250, 250, 1000, 570,
570, 500, 500, 500, 555, 500, 500, 500, 333, 333,
333, 278, 389, 389, 549, 389, 389, 747, 333, 389,
389, 389, 389, 389, 500, 333, 500, 500, 278, 250,
500, 600, 278, 366, 278, 500, 500, 750, 300, 333,
1000, 500, 300, 556, 556, 556, 556, 556, 556, 556,
500, 556, 556, 444, 667, 500, 444, 444, 444, 500,
389, 389, 389, 389, 500,
}
// timesItalicWx font metrics loaded from afms/Times-Italic.afm.
// See afms/MustRead.html for license information.
var timesItalicWx = []int16{
611, 889, 611, 611, 611, 611, 611, 611, 611, 611,
611, 611, 667, 667, 667, 667, 722, 722, 722, 612,
611, 611, 611, 611, 611, 611, 611, 611, 611, 722,
500, 611, 722, 722, 722, 722, 333, 333, 333, 333,
333, 333, 333, 333, 444, 667, 667, 556, 556, 611,
556, 556, 833, 667, 667, 667, 667, 667, 722, 944,
722, 722, 722, 722, 722, 722, 722, 722, 611, 722,
611, 611, 611, 611, 500, 500, 500, 500, 500, 556,
556, 556, 611, 722, 722, 722, 722, 722, 722, 722,
722, 722, 611, 833, 611, 556, 556, 556, 556, 556,
556, 556, 500, 500, 500, 500, 333, 500, 667, 500,
500, 778, 500, 500, 422, 541, 500, 920, 500, 500,
278, 275, 400, 400, 389, 389, 333, 275, 350, 444,
444, 333, 444, 444, 333, 500, 333, 333, 250, 250,
760, 500, 500, 500, 500, 544, 500, 400, 333, 675,
500, 333, 278, 444, 444, 444, 444, 444, 444, 444,
500, 889, 444, 889, 500, 444, 675, 500, 333, 389,
278, 500, 500, 500, 500, 500, 167, 500, 500, 500,
500, 333, 675, 549, 500, 500, 333, 333, 500, 333,
333, 278, 278, 278, 278, 278, 278, 278, 278, 444,
444, 278, 278, 300, 278, 675, 549, 675, 471, 278,
722, 333, 675, 500, 675, 500, 500, 500, 500, 500,
549, 500, 500, 500, 500, 500, 500, 667, 333, 500,
500, 500, 500, 750, 750, 300, 276, 310, 500, 500,
500, 523, 333, 333, 476, 833, 250, 250, 1000, 675,
675, 500, 500, 500, 420, 556, 556, 556, 333, 333,
333, 214, 389, 389, 453, 389, 389, 760, 333, 389,
389, 389, 389, 389, 500, 333, 500, 500, 278, 250,
500, 600, 278, 300, 278, 500, 500, 750, 300, 333,
980, 500, 300, 500, 500, 500, 500, 500, 500, 500,
500, 500, 500, 444, 667, 444, 444, 444, 444, 500,
389, 389, 389, 389, 500,
}