-
Notifications
You must be signed in to change notification settings - Fork 480
/
font.mjs
695 lines (635 loc) · 24.5 KB
/
font.mjs
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// The Font object
import Path from './path.mjs';
import sfnt from './tables/sfnt.mjs';
import { DefaultEncoding } from './encoding.mjs';
import glyphset from './glyphset.mjs';
import Position from './position.mjs';
import Substitution from './substitution.mjs';
import { PaletteManager } from './palettes.mjs';
import { LayerManager } from './layers.mjs';
import { SVGImageManager } from './svgimages.mjs';
import { VariationManager } from './variation.mjs';
import HintingTrueType from './hintingtt.mjs';
import Bidi from './bidi.mjs';
import { applyPaintType } from './tables/cff.mjs';
function createDefaultNamesInfo(options) {
return {
fontFamily: {en: options.familyName || ' '},
fontSubfamily: {en: options.styleName || ' '},
fullName: {en: options.fullName || options.familyName + ' ' + options.styleName},
// postScriptName may not contain any whitespace
postScriptName: {en: options.postScriptName || (options.familyName + options.styleName).replace(/\s/g, '')},
designer: {en: options.designer || ' '},
designerURL: {en: options.designerURL || ' '},
manufacturer: {en: options.manufacturer || ' '},
manufacturerURL: {en: options.manufacturerURL || ' '},
license: {en: options.license || ' '},
licenseURL: {en: options.licenseURL || ' '},
version: {en: options.version || 'Version 0.1'},
description: {en: options.description || ' '},
copyright: {en: options.copyright || ' '},
trademark: {en: options.trademark || ' '}
};
}
/**
* @typedef FontOptions
* @type Object
* @property {Boolean} empty - whether to create a new empty font
* @property {string} familyName
* @property {string} styleName
* @property {string=} fullName
* @property {string=} postScriptName
* @property {string=} designer
* @property {string=} designerURL
* @property {string=} manufacturer
* @property {string=} manufacturerURL
* @property {string=} license
* @property {string=} licenseURL
* @property {string=} version
* @property {string=} description
* @property {string=} copyright
* @property {string=} trademark
* @property {Number} unitsPerEm
* @property {Number} ascender
* @property {Number} descender
* @property {Number} createdTimestamp
* @property {Number} weightClass
* @property {Number} italicAngle
* @property {string=} widthClass
* @property {string=} fsSelection
*/
/**
* A Font represents a loaded OpenType font file.
* It contains a set of glyphs and methods to draw text on a drawing context,
* or to get a path representing the text.
* @exports opentype.Font
* @class
* @param {FontOptions}
* @constructor
*/
function Font(options) {
options = options || {};
options.tables = options.tables || {};
if (!options.empty) {
// Check that we've provided the minimum set of names.
if (!options.familyName) throw 'When creating a new Font object, familyName is required.';
if (!options.styleName) throw 'When creating a new Font object, styleName is required.';
if (!options.unitsPerEm) throw 'When creating a new Font object, unitsPerEm is required.';
if (!options.ascender) throw 'When creating a new Font object, ascender is required.';
if (options.descender > 0) throw 'When creating a new Font object, negative descender value is required.';
// OS X will complain if the names are empty, so we put a single space everywhere by default.
this.names = {};
this.names.unicode = createDefaultNamesInfo(options);
this.names.macintosh = createDefaultNamesInfo(options);
this.names.windows = createDefaultNamesInfo(options);
this.unitsPerEm = options.unitsPerEm || 1000;
this.ascender = options.ascender;
this.descender = options.descender;
this.createdTimestamp = options.createdTimestamp;
this.italicAngle = options.italicAngle || 0;
this.weightClass = options.weightClass || 0;
let selection = 0;
if (options.fsSelection) {
selection = options.fsSelection;
} else {
if (this.italicAngle < 0) {
selection |= this.fsSelectionValues.ITALIC;
} else if (this.italicAngle > 0) {
selection |= this.fsSelectionValues.OBLIQUE;
}
if (this.weightClass >= 600) {
selection |= this.fsSelectionValues.BOLD;
}
if (selection == 0) {
selection = this.fsSelectionValues.REGULAR;
}
}
if (!options.panose || !Array.isArray(options.panose)) {
options.panose = [0, 0, 0, 0, 0, 0, 0, 0, 0];
}
this.tables = Object.assign(options.tables, {
os2: Object.assign({
usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM,
usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM,
bFamilyType: options.panose[0] || 0,
bSerifStyle: options.panose[1] || 0,
bWeight: options.panose[2] || 0,
bProportion: options.panose[3] || 0,
bContrast: options.panose[4] || 0,
bStrokeVariation: options.panose[5] || 0,
bArmStyle: options.panose[6] || 0,
bLetterform: options.panose[7] || 0,
bMidline: options.panose[8] || 0,
bXHeight: options.panose[9] || 0,
fsSelection: selection,
}, options.tables.os2)
});
}
this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported.
this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []);
this.encoding = new DefaultEncoding(this);
this.position = new Position(this);
this.substitution = new Substitution(this);
this.tables = this.tables || {};
this.tables = new Proxy(this.tables, {
set: (tables, tableName, tableData) => {
tables[tableName] = tableData;
if (tables.fvar && (tables.gvar || tables.cff2) && !this.variation) {
this.variation = new VariationManager(this);
}
return true;
}
});
this.palettes = new PaletteManager(this);
this.layers = new LayerManager(this);
this.svgImages = new SVGImageManager(this);
// needed for low memory mode only.
this._push = null;
this._hmtxTableData = {};
Object.defineProperty(this, 'hinting', {
get: function() {
if (this._hinting) return this._hinting;
if (this.outlinesFormat === 'truetype') {
return (this._hinting = new HintingTrueType(this));
}
return null;
}
});
}
/**
* Check if the font has a glyph for the given character.
* @param {string}
* @return {Boolean}
*/
Font.prototype.hasChar = function(c) {
return this.encoding.charToGlyphIndex(c) > 0;
};
/**
* Convert the given character to a single glyph index.
* Note that this function assumes that there is a one-to-one mapping between
* the given character and a glyph; for complex scripts this might not be the case.
* @param {string}
* @return {Number}
*/
Font.prototype.charToGlyphIndex = function(s) {
return this.encoding.charToGlyphIndex(s);
};
/**
* Convert the given character to a single Glyph object.
* Note that this function assumes that there is a one-to-one mapping between
* the given character and a glyph; for complex scripts this might not be the case.
* @param {string}
* @return {opentype.Glyph}
*/
Font.prototype.charToGlyph = function(c) {
const glyphIndex = this.charToGlyphIndex(c);
let glyph = this.glyphs.get(glyphIndex);
if (!glyph) {
// .notdef
glyph = this.glyphs.get(0);
}
return glyph;
};
/**
* Update features
* @param {any} options features options
*/
Font.prototype.updateFeatures = function (options) {
// TODO: update all features options not only 'latn'.
return this.defaultRenderOptions.features.map(feature => {
if (feature.script === 'latn') {
return {
script: 'latn',
tags: feature.tags.filter(tag => options[tag])
};
} else {
return feature;
}
});
};
/**
* Convert the given text to a list of Glyph indexes.
* Note that there is no strict one-to-one mapping between characters and
* glyphs, so the list of returned glyph indexes can be larger or smaller than the
* length of the given string.
* @param {string}
* @param {GlyphRenderOptions} [options]
* @return {number[]}
*/
Font.prototype.stringToGlyphIndexes = function(s, options) {
const bidi = new Bidi();
// Create and register 'glyphIndex' state modifier
const charToGlyphIndexMod = token => this.charToGlyphIndex(token.char);
bidi.registerModifier('glyphIndex', null, charToGlyphIndexMod);
// roll-back to default features
let features = options ?
this.updateFeatures(options.features) :
this.defaultRenderOptions.features;
bidi.applyFeatures(this, features);
return bidi.getTextGlyphs(s);
};
/**
* Convert the given text to a list of Glyph objects.
* Note that there is no strict one-to-one mapping between characters and
* glyphs, so the list of returned glyphs can be larger or smaller than the
* length of the given string.
* @param {string}
* @param {GlyphRenderOptions} [options]
* @return {opentype.Glyph[]}
*/
Font.prototype.stringToGlyphs = function(s, options) {
const indexes = this.stringToGlyphIndexes(s, options);
let length = indexes.length;
// convert glyph indexes to glyph objects
const glyphs = new Array(length);
const notdef = this.glyphs.get(0);
for (let i = 0; i < length; i += 1) {
glyphs[i] = this.glyphs.get(indexes[i]) || notdef;
}
return glyphs;
};
/**
* @param {string}
* @return {Number}
*/
Font.prototype.nameToGlyphIndex = function(name) {
return this.glyphNames.nameToGlyphIndex(name);
};
/**
* @param {string}
* @return {opentype.Glyph}
*/
Font.prototype.nameToGlyph = function(name) {
const glyphIndex = this.nameToGlyphIndex(name);
let glyph = this.glyphs.get(glyphIndex);
if (!glyph) {
// .notdef
glyph = this.glyphs.get(0);
}
return glyph;
};
/**
* @param {Number}
* @return {String}
*/
Font.prototype.glyphIndexToName = function(gid) {
if (!this.glyphNames.glyphIndexToName) {
return '';
}
return this.glyphNames.glyphIndexToName(gid);
};
/**
* Retrieve the value of the kerning pair between the left glyph (or its index)
* and the right glyph (or its index). If no kerning pair is found, return 0.
* The kerning value gets added to the advance width when calculating the spacing
* between glyphs.
* For GPOS kerning, this method uses the default script and language, which covers
* most use cases. To have greater control, use font.position.getKerningValue .
* @param {opentype.Glyph} leftGlyph
* @param {opentype.Glyph} rightGlyph
* @return {Number}
*/
Font.prototype.getKerningValue = function(leftGlyph, rightGlyph) {
leftGlyph = leftGlyph.index || leftGlyph;
rightGlyph = rightGlyph.index || rightGlyph;
const gposKerning = this.position.defaultKerningTables;
if (gposKerning) {
return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph);
}
// "kern" table
return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0;
};
/**
* @typedef GlyphRenderOptions
* @type Object
* @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used.
* See https://www.microsoft.com/typography/otspec/scripttags.htm
* @property {string} [language='dflt'] - language system used to determine which features to apply.
* See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx
* @property {boolean} [kerning=true] - whether to include kerning values
* @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system.
* See https://www.microsoft.com/typography/otspec/featuretags.htm
* @property {boolean} [hinting=false] - whether to apply font hinting to the outlines
* @property {integer} [usePalette=0] For COLR/CPAL fonts, the zero-based index of the color palette to use. (Use `Font.palettes.get()` to get the available palettes)
* @property {boolean} [drawLayers=true] For COLR/CPAL fonts, this can be turned to false in order to draw the fallback glyphs instead
* @property {boolean} [drawSVG=true] For SVG fonts, this can be turned to false in order to draw the fallback glyphs instead
*/
Font.prototype.defaultRenderOptions = {
kerning: true,
features: [
/**
* these 4 features are required to render Arabic text properly
* and shouldn't be turned off when rendering arabic text.
*/
{ script: 'arab', tags: ['init', 'medi', 'fina', 'rlig'] },
{ script: 'latn', tags: ['liga', 'rlig'] },
{ script: 'thai', tags: ['liga', 'rlig', 'ccmp'] },
],
hinting: false,
usePalette: 0,
drawLayers: true,
drawSVG: true,
};
/**
* Helper function that invokes the given callback for each glyph in the given text.
* The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text
* @param {string} text - The text to apply.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
* @param {Function} callback
*/
Font.prototype.forEachGlyph = function(text, x, y, fontSize, options, callback) {
x = x !== undefined ? x : 0;
y = y !== undefined ? y : 0;
fontSize = fontSize !== undefined ? fontSize : 72;
options = Object.assign({}, this.defaultRenderOptions, options);
const fontScale = 1 / this.unitsPerEm * fontSize;
const glyphs = this.stringToGlyphs(text, options);
let kerningLookups;
if (options.kerning) {
const script = options.script || this.position.getDefaultScriptName();
kerningLookups = this.position.getKerningTables(script, options.language);
}
for (let i = 0; i < glyphs.length; i += 1) {
const glyph = glyphs[i];
callback.call(this, glyph, x, y, fontSize, options);
if (glyph.advanceWidth) {
x += glyph.advanceWidth * fontScale;
}
if (options.kerning && i < glyphs.length - 1) {
// We should apply position adjustment lookups in a more generic way.
// Here we only use the xAdvance value.
const kerningValue = kerningLookups ?
this.position.getKerningValue(kerningLookups, glyph.index, glyphs[i + 1].index) :
this.getKerningValue(glyph, glyphs[i + 1]);
x += kerningValue * fontScale;
}
if (options.letterSpacing) {
x += options.letterSpacing * fontSize;
} else if (options.tracking) {
x += (options.tracking / 1000) * fontSize;
}
}
return x;
};
/**
* Create a Path object that represents the given text.
* @param {string} text - The text to create.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
* @return {opentype.Path}
*/
Font.prototype.getPath = function(text, x, y, fontSize, options) {
options = Object.assign({}, this.defaultRenderOptions, options);
const fullPath = new Path();
fullPath._layers = [];
applyPaintType(this, fullPath, fontSize);
if (fullPath.stroke) {
const scale = 1 / (fullPath.unitsPerEm || 1000) * fontSize;
fullPath.strokeWidth *= scale;
}
this.forEachGlyph(text, x, y, fontSize, options, (glyph, gX, gY, gFontSize) => {
const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
if ( options.drawSVG || options.drawLayers ) {
const layers = glyphPath._layers;
if ( layers && layers.length ) {
for(let l = 0; l < layers.length; l++) {
const layer = layers[l];
fullPath._layers.push(layer);
}
return;
}
}
fullPath.extend(glyphPath);
});
return fullPath;
};
/**
* Create an array of Path objects that represent the glyphs of a given text.
* @param {string} text - The text to create.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
* @return {opentype.Path[]}
*/
Font.prototype.getPaths = function(text, x, y, fontSize, options) {
options = Object.assign({}, this.defaultRenderOptions, options);
const glyphPaths = [];
this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {
const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
glyphPaths.push(glyphPath);
});
return glyphPaths;
};
/**
* Returns the advance width of a text.
*
* This is something different than Path.getBoundingBox() as for example a
* suffixed whitespace increases the advanceWidth but not the bounding box
* or an overhanging letter like a calligraphic 'f' might have a quite larger
* bounding box than its advance width.
*
* This corresponds to canvas2dContext.measureText(text).width
*
* @param {string} text - The text to create.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
* @return advance width
*/
Font.prototype.getAdvanceWidth = function(text, fontSize, options) {
options = Object.assign({}, this.defaultRenderOptions, options);
return this.forEachGlyph(text, 0, 0, fontSize, options, function() {});
};
/**
* Draw the text on the given drawing context.
* @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
* @param {string} text - The text to create.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
*/
Font.prototype.draw = function(ctx, text, x, y, fontSize, options) {
const path = this.getPath(text, x, y, fontSize, options);
path.draw(ctx);
};
/**
* Draw the points of all glyphs in the text.
* On-curve points will be drawn in blue, off-curve points will be drawn in red.
* @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
* @param {string} text - The text to create.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
*/
Font.prototype.drawPoints = function(ctx, text, x, y, fontSize, options) {
options = Object.assign({}, this.defaultRenderOptions, options);
this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {
glyph.drawPoints(ctx, gX, gY, gFontSize, options, this);
});
};
/**
* Draw lines indicating important font measurements for all glyphs in the text.
* Black lines indicate the origin of the coordinate system (point 0,0).
* Blue lines indicate the glyph bounding box.
* Green line indicates the advance width of the glyph.
* @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.
* @param {string} text - The text to create.
* @param {number} [x=0] - Horizontal position of the beginning of the text.
* @param {number} [y=0] - Vertical position of the *baseline* of the text.
* @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.
* @param {GlyphRenderOptions=} options
*/
Font.prototype.drawMetrics = function(ctx, text, x, y, fontSize, options) {
options = Object.assign({}, this.defaultRenderOptions, options);
this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {
glyph.drawMetrics(ctx, gX, gY, gFontSize);
});
};
/**
* @param {string}
* @return {string}
*/
Font.prototype.getEnglishName = function(name) {
const translations = (this.names.unicode || this.names.macintosh || this.names.windows)[name];
if (translations) {
return translations.en;
}
};
/**
* Validate
*/
Font.prototype.validate = function() {
const warnings = [];
const _this = this;
function assert(predicate, message) {
if (!predicate) {
console.warn(`[opentype.js] ${message}`);
warnings.push(message);
}
}
function assertNamePresent(name) {
const englishName = _this.getEnglishName(name);
assert(englishName && englishName.trim().length > 0,
'No English ' + name + ' specified.');
}
// Identification information
assertNamePresent('fontFamily');
assertNamePresent('weightName');
assertNamePresent('manufacturer');
assertNamePresent('copyright');
assertNamePresent('version');
// Dimension information
assert(this.unitsPerEm > 0, 'No unitsPerEm specified.');
if (this.tables.colr) {
const baseGlyphs = this.tables.colr.baseGlyphRecords;
let previousID = -1;
for(let b = 0; b < baseGlyphs.length; b++) {
const currentGlyphID = baseGlyphs[b].glyphID;
assert(previousID < baseGlyphs[b].glyphID, `baseGlyphs must be sorted by GlyphID in ascending order, but glyphID ${currentGlyphID} comes after ${previousID}`);
if (previousID > baseGlyphs[b].glyphID) {
break;
}
previousID = currentGlyphID;
}
}
return warnings;
};
/**
* Convert the font object to a SFNT data structure.
* This structure contains all the necessary tables and metadata to create a binary OTF file.
* @return {opentype.Table}
*/
Font.prototype.toTables = function() {
return sfnt.fontToTable(this);
};
/**
* @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.
*/
Font.prototype.toBuffer = function() {
console.warn('Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.');
return this.toArrayBuffer();
};
/**
* Converts a `opentype.Font` into an `ArrayBuffer`
* @return {ArrayBuffer}
*/
Font.prototype.toArrayBuffer = function() {
const sfntTable = this.toTables();
const bytes = sfntTable.encode();
const buffer = new ArrayBuffer(bytes.length);
const intArray = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; i++) {
intArray[i] = bytes[i];
}
return buffer;
};
/**
* Initiate a download of the OpenType font.
* @deprecated
*/
Font.prototype.download = function() {
console.error('DEPRECATED: platform-specific actions are to be implemented on user-side');
};
/**
* @private
*/
Font.prototype.fsSelectionValues = {
ITALIC: 0x001, //1
UNDERSCORE: 0x002, //2
NEGATIVE: 0x004, //4
OUTLINED: 0x008, //8
STRIKEOUT: 0x010, //16
BOLD: 0x020, //32
REGULAR: 0x040, //64
USER_TYPO_METRICS: 0x080, //128
WWS: 0x100, //256
OBLIQUE: 0x200 //512
};
/**
* @private
*/
Font.prototype.macStyleValues = {
BOLD: 0x001, //1
ITALIC: 0x002, //2
UNDERLINE: 0x004, //4
OUTLINED: 0x008, //8
SHADOW: 0x010, //16
CONDENSED: 0x020, //32
EXTENDED: 0x040, //64
};
/**
* @private
*/
Font.prototype.usWidthClasses = {
ULTRA_CONDENSED: 1,
EXTRA_CONDENSED: 2,
CONDENSED: 3,
SEMI_CONDENSED: 4,
MEDIUM: 5,
SEMI_EXPANDED: 6,
EXPANDED: 7,
EXTRA_EXPANDED: 8,
ULTRA_EXPANDED: 9
};
/**
* @private
*/
Font.prototype.usWeightClasses = {
THIN: 100,
EXTRA_LIGHT: 200,
LIGHT: 300,
NORMAL: 400,
MEDIUM: 500,
SEMI_BOLD: 600,
BOLD: 700,
EXTRA_BOLD: 800,
BLACK: 900
};
export default Font;