pdfjs-dist 2.3.200 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
package/lib/core/fonts.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -27,37 +27,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
27
27
|
exports.getFontType = getFontType;
|
28
28
|
exports.IdentityToUnicodeMap = exports.ToUnicodeMap = exports.FontFlags = exports.Font = exports.ErrorFont = exports.SEAC_ANALYSIS_ENABLED = void 0;
|
29
29
|
|
30
|
-
var _util = require("../shared/util");
|
30
|
+
var _util = require("../shared/util.js");
|
31
31
|
|
32
|
-
var _cff_parser = require("./cff_parser");
|
32
|
+
var _cff_parser = require("./cff_parser.js");
|
33
33
|
|
34
|
-
var _glyphlist = require("./glyphlist");
|
34
|
+
var _glyphlist = require("./glyphlist.js");
|
35
35
|
|
36
|
-
var _encodings = require("./encodings");
|
36
|
+
var _encodings = require("./encodings.js");
|
37
37
|
|
38
|
-
var _standard_fonts = require("./standard_fonts");
|
38
|
+
var _standard_fonts = require("./standard_fonts.js");
|
39
39
|
|
40
|
-
var _unicode = require("./unicode");
|
40
|
+
var _unicode = require("./unicode.js");
|
41
41
|
|
42
|
-
var
|
42
|
+
var _core_utils = require("./core_utils.js");
|
43
43
|
|
44
|
-
var
|
44
|
+
var _font_renderer = require("./font_renderer.js");
|
45
45
|
|
46
|
-
var
|
46
|
+
var _cmap = require("./cmap.js");
|
47
47
|
|
48
|
-
var _stream = require("./stream");
|
48
|
+
var _stream = require("./stream.js");
|
49
49
|
|
50
|
-
var _type1_parser = require("./type1_parser");
|
50
|
+
var _type1_parser = require("./type1_parser.js");
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
55
|
-
|
56
|
-
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
57
|
-
|
58
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
59
|
-
|
60
|
-
var PRIVATE_USE_AREAS = [[0xE000, 0xF8FF], [0x100000, 0x10FFFD]];
|
52
|
+
const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
|
61
53
|
var PDF_GLYPH_SPACE_UNITS = 1000;
|
62
54
|
var SEAC_ANALYSIS_ENABLED = true;
|
63
55
|
exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
|
@@ -73,7 +65,7 @@ var FontFlags = {
|
|
73
65
|
ForceBold: 262144
|
74
66
|
};
|
75
67
|
exports.FontFlags = FontFlags;
|
76
|
-
var MacStandardGlyphOrdering = [
|
68
|
+
var MacStandardGlyphOrdering = [".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", "guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"];
|
77
69
|
|
78
70
|
function adjustWidths(properties) {
|
79
71
|
if (!properties.fontMatrix) {
|
@@ -128,25 +120,25 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|
128
120
|
|
129
121
|
function getFontType(type, subtype) {
|
130
122
|
switch (type) {
|
131
|
-
case
|
132
|
-
return subtype ===
|
123
|
+
case "Type1":
|
124
|
+
return subtype === "Type1C" ? _util.FontType.TYPE1C : _util.FontType.TYPE1;
|
133
125
|
|
134
|
-
case
|
135
|
-
return subtype ===
|
126
|
+
case "CIDFontType0":
|
127
|
+
return subtype === "CIDFontType0C" ? _util.FontType.CIDFONTTYPE0C : _util.FontType.CIDFONTTYPE0;
|
136
128
|
|
137
|
-
case
|
129
|
+
case "OpenType":
|
138
130
|
return _util.FontType.OPENTYPE;
|
139
131
|
|
140
|
-
case
|
132
|
+
case "TrueType":
|
141
133
|
return _util.FontType.TRUETYPE;
|
142
134
|
|
143
|
-
case
|
135
|
+
case "CIDFontType2":
|
144
136
|
return _util.FontType.CIDFONTTYPE2;
|
145
137
|
|
146
|
-
case
|
138
|
+
case "MMType1":
|
147
139
|
return _util.FontType.MMTYPE1;
|
148
140
|
|
149
|
-
case
|
141
|
+
case "Type0":
|
150
142
|
return _util.FontType.TYPE0;
|
151
143
|
|
152
144
|
default:
|
@@ -169,7 +161,7 @@ function recoverGlyphName(name, glyphsUnicodeMap) {
|
|
169
161
|
}
|
170
162
|
}
|
171
163
|
|
172
|
-
(0, _util.info)(
|
164
|
+
(0, _util.info)("Unable to recover a standard glyph name for: " + name);
|
173
165
|
return name;
|
174
166
|
}
|
175
167
|
|
@@ -193,8 +185,7 @@ var Glyph = function GlyphClosure() {
|
|
193
185
|
}();
|
194
186
|
|
195
187
|
var ToUnicodeMap = function ToUnicodeMapClosure() {
|
196
|
-
function ToUnicodeMap() {
|
197
|
-
var cmap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
188
|
+
function ToUnicodeMap(cmap = []) {
|
198
189
|
this._map = cmap;
|
199
190
|
}
|
200
191
|
|
@@ -203,25 +194,28 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
203
194
|
return this._map.length;
|
204
195
|
},
|
205
196
|
|
206
|
-
forEach
|
197
|
+
forEach(callback) {
|
207
198
|
for (var charCode in this._map) {
|
208
199
|
callback(charCode, this._map[charCode].charCodeAt(0));
|
209
200
|
}
|
210
201
|
},
|
211
|
-
|
202
|
+
|
203
|
+
has(i) {
|
212
204
|
return this._map[i] !== undefined;
|
213
205
|
},
|
214
|
-
|
206
|
+
|
207
|
+
get(i) {
|
215
208
|
return this._map[i];
|
216
209
|
},
|
217
|
-
|
218
|
-
|
210
|
+
|
211
|
+
charCodeOf(value) {
|
212
|
+
const map = this._map;
|
219
213
|
|
220
214
|
if (map.length <= 0x10000) {
|
221
215
|
return map.indexOf(value);
|
222
216
|
}
|
223
217
|
|
224
|
-
for (
|
218
|
+
for (const charCode in map) {
|
225
219
|
if (map[charCode] === value) {
|
226
220
|
return charCode | 0;
|
227
221
|
}
|
@@ -229,11 +223,13 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
229
223
|
|
230
224
|
return -1;
|
231
225
|
},
|
232
|
-
|
226
|
+
|
227
|
+
amend(map) {
|
233
228
|
for (var charCode in map) {
|
234
229
|
this._map[charCode] = map[charCode];
|
235
230
|
}
|
236
231
|
}
|
232
|
+
|
237
233
|
};
|
238
234
|
return ToUnicodeMap;
|
239
235
|
}();
|
@@ -251,27 +247,32 @@ var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
|
251
247
|
return this.lastChar + 1 - this.firstChar;
|
252
248
|
},
|
253
249
|
|
254
|
-
forEach
|
250
|
+
forEach(callback) {
|
255
251
|
for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
|
256
252
|
callback(i, i);
|
257
253
|
}
|
258
254
|
},
|
259
|
-
|
255
|
+
|
256
|
+
has(i) {
|
260
257
|
return this.firstChar <= i && i <= this.lastChar;
|
261
258
|
},
|
262
|
-
|
259
|
+
|
260
|
+
get(i) {
|
263
261
|
if (this.firstChar <= i && i <= this.lastChar) {
|
264
262
|
return String.fromCharCode(i);
|
265
263
|
}
|
266
264
|
|
267
265
|
return undefined;
|
268
266
|
},
|
269
|
-
|
267
|
+
|
268
|
+
charCodeOf(v) {
|
270
269
|
return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
|
271
270
|
},
|
272
|
-
|
273
|
-
|
271
|
+
|
272
|
+
amend(map) {
|
273
|
+
(0, _util.unreachable)("Should not call amend()");
|
274
274
|
}
|
275
|
+
|
275
276
|
};
|
276
277
|
return IdentityToUnicodeMap;
|
277
278
|
}();
|
@@ -280,15 +281,15 @@ exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
|
|
280
281
|
|
281
282
|
var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
282
283
|
function writeInt16(dest, offset, num) {
|
283
|
-
dest[offset] = num >> 8 &
|
284
|
-
dest[offset + 1] = num &
|
284
|
+
dest[offset] = num >> 8 & 0xff;
|
285
|
+
dest[offset + 1] = num & 0xff;
|
285
286
|
}
|
286
287
|
|
287
288
|
function writeInt32(dest, offset, num) {
|
288
|
-
dest[offset] = num >> 24 &
|
289
|
-
dest[offset + 1] = num >> 16 &
|
290
|
-
dest[offset + 2] = num >> 8 &
|
291
|
-
dest[offset + 3] = num &
|
289
|
+
dest[offset] = num >> 24 & 0xff;
|
290
|
+
dest[offset + 1] = num >> 16 & 0xff;
|
291
|
+
dest[offset + 2] = num >> 8 & 0xff;
|
292
|
+
dest[offset + 3] = num & 0xff;
|
292
293
|
}
|
293
294
|
|
294
295
|
function writeData(dest, offset, data) {
|
@@ -296,13 +297,13 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
296
297
|
|
297
298
|
if (data instanceof Uint8Array) {
|
298
299
|
dest.set(data, offset);
|
299
|
-
} else if (typeof data ===
|
300
|
+
} else if (typeof data === "string") {
|
300
301
|
for (i = 0, ii = data.length; i < ii; i++) {
|
301
|
-
dest[offset++] = data.charCodeAt(i) &
|
302
|
+
dest[offset++] = data.charCodeAt(i) & 0xff;
|
302
303
|
}
|
303
304
|
} else {
|
304
305
|
for (i = 0, ii = data.length; i < ii; i++) {
|
305
|
-
dest[offset++] = data[i] &
|
306
|
+
dest[offset++] = data[i] & 0xff;
|
306
307
|
}
|
307
308
|
}
|
308
309
|
}
|
@@ -356,14 +357,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
356
357
|
writeData(file, tableOffsets[i], table);
|
357
358
|
}
|
358
359
|
|
359
|
-
if (sfnt ===
|
360
|
+
if (sfnt === "true") {
|
360
361
|
sfnt = (0, _util.string32)(0x00010000);
|
361
362
|
}
|
362
363
|
|
363
|
-
file[0] = sfnt.charCodeAt(0) &
|
364
|
-
file[1] = sfnt.charCodeAt(1) &
|
365
|
-
file[2] = sfnt.charCodeAt(2) &
|
366
|
-
file[3] = sfnt.charCodeAt(3) &
|
364
|
+
file[0] = sfnt.charCodeAt(0) & 0xff;
|
365
|
+
file[1] = sfnt.charCodeAt(1) & 0xff;
|
366
|
+
file[2] = sfnt.charCodeAt(2) & 0xff;
|
367
|
+
file[3] = sfnt.charCodeAt(3) & 0xff;
|
367
368
|
writeInt16(file, 4, numTables);
|
368
369
|
var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
|
369
370
|
writeInt16(file, 6, searchParams.range);
|
@@ -373,14 +374,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
373
374
|
|
374
375
|
for (i = 0; i < numTables; i++) {
|
375
376
|
tableName = tablesNames[i];
|
376
|
-
file[offset] = tableName.charCodeAt(0) &
|
377
|
-
file[offset + 1] = tableName.charCodeAt(1) &
|
378
|
-
file[offset + 2] = tableName.charCodeAt(2) &
|
379
|
-
file[offset + 3] = tableName.charCodeAt(3) &
|
377
|
+
file[offset] = tableName.charCodeAt(0) & 0xff;
|
378
|
+
file[offset + 1] = tableName.charCodeAt(1) & 0xff;
|
379
|
+
file[offset + 2] = tableName.charCodeAt(2) & 0xff;
|
380
|
+
file[offset + 3] = tableName.charCodeAt(3) & 0xff;
|
380
381
|
var checksum = 0;
|
381
382
|
|
382
383
|
for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
383
|
-
var quad = (0,
|
384
|
+
var quad = (0, _core_utils.readUint32)(file, j);
|
384
385
|
checksum = checksum + quad >>> 0;
|
385
386
|
}
|
386
387
|
|
@@ -394,7 +395,7 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
394
395
|
},
|
395
396
|
addTable: function OpenTypeFileBuilder_addTable(tag, data) {
|
396
397
|
if (tag in this.tables) {
|
397
|
-
throw new Error(
|
398
|
+
throw new Error("Table " + tag + " already exists");
|
398
399
|
}
|
399
400
|
|
400
401
|
this.tables[tag] = data;
|
@@ -419,7 +420,15 @@ var Font = function FontClosure() {
|
|
419
420
|
var subtype = properties.subtype;
|
420
421
|
this.type = type;
|
421
422
|
this.subtype = subtype;
|
422
|
-
|
423
|
+
let fallbackName = "sans-serif";
|
424
|
+
|
425
|
+
if (this.isMonospace) {
|
426
|
+
fallbackName = "monospace";
|
427
|
+
} else if (this.isSerifFont) {
|
428
|
+
fallbackName = "serif";
|
429
|
+
}
|
430
|
+
|
431
|
+
this.fallbackName = fallbackName;
|
423
432
|
this.differences = properties.differences;
|
424
433
|
this.widths = properties.widths;
|
425
434
|
this.defaultWidth = properties.defaultWidth;
|
@@ -435,7 +444,7 @@ var Font = function FontClosure() {
|
|
435
444
|
this.fallbackToUnicode = properties.fallbackToUnicode || new ToUnicodeMap();
|
436
445
|
this.toFontChar = [];
|
437
446
|
|
438
|
-
if (properties.type ===
|
447
|
+
if (properties.type === "Type3") {
|
439
448
|
for (charCode = 0; charCode < 256; charCode++) {
|
440
449
|
this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
|
441
450
|
}
|
@@ -454,54 +463,49 @@ var Font = function FontClosure() {
|
|
454
463
|
|
455
464
|
if (!file || file.isEmpty) {
|
456
465
|
if (file) {
|
457
|
-
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName +
|
466
|
+
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ")");
|
458
467
|
}
|
459
468
|
|
460
469
|
this.fallbackToSystemFont();
|
461
470
|
return;
|
462
471
|
}
|
463
472
|
|
464
|
-
|
465
|
-
|
466
|
-
var _getFontFileType2 = _slicedToArray(_getFontFileType, 2);
|
467
|
-
|
468
|
-
type = _getFontFileType2[0];
|
469
|
-
subtype = _getFontFileType2[1];
|
473
|
+
[type, subtype] = getFontFileType(file, properties);
|
470
474
|
|
471
475
|
if (type !== this.type || subtype !== this.subtype) {
|
472
|
-
(0, _util.info)(
|
476
|
+
(0, _util.info)("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`);
|
473
477
|
}
|
474
478
|
|
475
479
|
try {
|
476
480
|
var data;
|
477
481
|
|
478
482
|
switch (type) {
|
479
|
-
case
|
480
|
-
(0, _util.info)(
|
483
|
+
case "MMType1":
|
484
|
+
(0, _util.info)("MMType1 font (" + name + "), falling back to Type1.");
|
481
485
|
|
482
|
-
case
|
483
|
-
case
|
484
|
-
this.mimetype =
|
485
|
-
var cff = subtype ===
|
486
|
+
case "Type1":
|
487
|
+
case "CIDFontType0":
|
488
|
+
this.mimetype = "font/opentype";
|
489
|
+
var cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
|
486
490
|
adjustWidths(properties);
|
487
491
|
data = this.convert(name, cff, properties);
|
488
492
|
break;
|
489
493
|
|
490
|
-
case
|
491
|
-
case
|
492
|
-
case
|
493
|
-
this.mimetype =
|
494
|
+
case "OpenType":
|
495
|
+
case "TrueType":
|
496
|
+
case "CIDFontType2":
|
497
|
+
this.mimetype = "font/opentype";
|
494
498
|
data = this.checkAndRepair(name, file, properties);
|
495
499
|
|
496
500
|
if (this.isOpenType) {
|
497
501
|
adjustWidths(properties);
|
498
|
-
type =
|
502
|
+
type = "OpenType";
|
499
503
|
}
|
500
504
|
|
501
505
|
break;
|
502
506
|
|
503
507
|
default:
|
504
|
-
throw new _util.FormatError(
|
508
|
+
throw new _util.FormatError(`Font ${type} is not supported`);
|
505
509
|
}
|
506
510
|
} catch (e) {
|
507
511
|
(0, _util.warn)(e);
|
@@ -549,23 +553,28 @@ var Font = function FontClosure() {
|
|
549
553
|
}
|
550
554
|
|
551
555
|
function safeString16(value) {
|
552
|
-
|
556
|
+
if (value > 0x7fff) {
|
557
|
+
value = 0x7fff;
|
558
|
+
} else if (value < -0x8000) {
|
559
|
+
value = -0x8000;
|
560
|
+
}
|
561
|
+
|
553
562
|
return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
|
554
563
|
}
|
555
564
|
|
556
565
|
function isTrueTypeFile(file) {
|
557
566
|
var header = file.peekBytes(4);
|
558
|
-
return (0,
|
567
|
+
return (0, _core_utils.readUint32)(header, 0) === 0x00010000 || (0, _util.bytesToString)(header) === "true";
|
559
568
|
}
|
560
569
|
|
561
570
|
function isTrueTypeCollectionFile(file) {
|
562
|
-
|
563
|
-
return (0, _util.bytesToString)(header) ===
|
571
|
+
const header = file.peekBytes(4);
|
572
|
+
return (0, _util.bytesToString)(header) === "ttcf";
|
564
573
|
}
|
565
574
|
|
566
575
|
function isOpenTypeFile(file) {
|
567
576
|
var header = file.peekBytes(4);
|
568
|
-
return (0, _util.bytesToString)(header) ===
|
577
|
+
return (0, _util.bytesToString)(header) === "OTTO";
|
569
578
|
}
|
570
579
|
|
571
580
|
function isType1File(file) {
|
@@ -583,7 +592,7 @@ var Font = function FontClosure() {
|
|
583
592
|
}
|
584
593
|
|
585
594
|
function isCFFFile(file) {
|
586
|
-
|
595
|
+
const header = file.peekBytes(4);
|
587
596
|
|
588
597
|
if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
|
589
598
|
return true;
|
@@ -592,40 +601,41 @@ var Font = function FontClosure() {
|
|
592
601
|
return false;
|
593
602
|
}
|
594
603
|
|
595
|
-
function getFontFileType(file,
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
604
|
+
function getFontFileType(file, {
|
605
|
+
type,
|
606
|
+
subtype,
|
607
|
+
composite
|
608
|
+
}) {
|
609
|
+
let fileType, fileSubtype;
|
600
610
|
|
601
611
|
if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
|
602
612
|
if (composite) {
|
603
|
-
fileType =
|
613
|
+
fileType = "CIDFontType2";
|
604
614
|
} else {
|
605
|
-
fileType =
|
615
|
+
fileType = "TrueType";
|
606
616
|
}
|
607
617
|
} else if (isOpenTypeFile(file)) {
|
608
618
|
if (composite) {
|
609
|
-
fileType =
|
619
|
+
fileType = "CIDFontType2";
|
610
620
|
} else {
|
611
|
-
fileType =
|
621
|
+
fileType = "OpenType";
|
612
622
|
}
|
613
623
|
} else if (isType1File(file)) {
|
614
624
|
if (composite) {
|
615
|
-
fileType =
|
625
|
+
fileType = "CIDFontType0";
|
616
626
|
} else {
|
617
|
-
fileType = type ===
|
627
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
618
628
|
}
|
619
629
|
} else if (isCFFFile(file)) {
|
620
630
|
if (composite) {
|
621
|
-
fileType =
|
622
|
-
fileSubtype =
|
631
|
+
fileType = "CIDFontType0";
|
632
|
+
fileSubtype = "CIDFontType0C";
|
623
633
|
} else {
|
624
|
-
fileType = type ===
|
625
|
-
fileSubtype =
|
634
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
635
|
+
fileSubtype = "Type1C";
|
626
636
|
}
|
627
637
|
} else {
|
628
|
-
(0, _util.warn)(
|
638
|
+
(0, _util.warn)("getFontFileType: Unable to detect correct font file Type/Subtype.");
|
629
639
|
fileType = type;
|
630
640
|
fileSubtype = subtype;
|
631
641
|
}
|
@@ -675,7 +685,7 @@ var Font = function FontClosure() {
|
|
675
685
|
privateUseAreaIndex++;
|
676
686
|
|
677
687
|
if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
|
678
|
-
(0, _util.warn)(
|
688
|
+
(0, _util.warn)("Ran out of space in font private use area.");
|
679
689
|
break;
|
680
690
|
}
|
681
691
|
|
@@ -694,9 +704,9 @@ var Font = function FontClosure() {
|
|
694
704
|
}
|
695
705
|
|
696
706
|
return {
|
697
|
-
toFontChar
|
707
|
+
toFontChar,
|
698
708
|
charCodeToGlyphId: newMap,
|
699
|
-
nextAvailableFontCharCode
|
709
|
+
nextAvailableFontCharCode
|
700
710
|
};
|
701
711
|
}
|
702
712
|
|
@@ -738,7 +748,7 @@ var Font = function FontClosure() {
|
|
738
748
|
++end;
|
739
749
|
++n;
|
740
750
|
|
741
|
-
if (end ===
|
751
|
+
if (end === 0xffff) {
|
742
752
|
break;
|
743
753
|
}
|
744
754
|
}
|
@@ -751,30 +761,30 @@ var Font = function FontClosure() {
|
|
751
761
|
|
752
762
|
function createCmapTable(glyphs, numGlyphs) {
|
753
763
|
var ranges = getRanges(glyphs, numGlyphs);
|
754
|
-
var numTables = ranges[ranges.length - 1][1] >
|
755
|
-
var cmap =
|
764
|
+
var numTables = ranges[ranges.length - 1][1] > 0xffff ? 2 : 1;
|
765
|
+
var cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + (0, _util.string32)(4 + numTables * 8);
|
756
766
|
var i, ii, j, jj;
|
757
767
|
|
758
768
|
for (i = ranges.length - 1; i >= 0; --i) {
|
759
|
-
if (ranges[i][0] <=
|
769
|
+
if (ranges[i][0] <= 0xffff) {
|
760
770
|
break;
|
761
771
|
}
|
762
772
|
}
|
763
773
|
|
764
774
|
var bmpLength = i + 1;
|
765
775
|
|
766
|
-
if (ranges[i][0] <
|
767
|
-
ranges[i][1] =
|
776
|
+
if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
|
777
|
+
ranges[i][1] = 0xfffe;
|
768
778
|
}
|
769
779
|
|
770
|
-
var trailingRangesCount = ranges[i][1] <
|
780
|
+
var trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
|
771
781
|
var segCount = bmpLength + trailingRangesCount;
|
772
782
|
var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
|
773
|
-
var startCount =
|
774
|
-
var endCount =
|
775
|
-
var idDeltas =
|
776
|
-
var idRangeOffsets =
|
777
|
-
var glyphsIds =
|
783
|
+
var startCount = "";
|
784
|
+
var endCount = "";
|
785
|
+
var idDeltas = "";
|
786
|
+
var idRangeOffsets = "";
|
787
|
+
var glyphsIds = "";
|
778
788
|
var bias = 0;
|
779
789
|
var range, start, end, codes;
|
780
790
|
|
@@ -805,25 +815,25 @@ var Font = function FontClosure() {
|
|
805
815
|
}
|
806
816
|
} else {
|
807
817
|
var startCode = codes[0];
|
808
|
-
idDeltas += string16(startCode - start &
|
818
|
+
idDeltas += string16(startCode - start & 0xffff);
|
809
819
|
idRangeOffsets += string16(0);
|
810
820
|
}
|
811
821
|
}
|
812
822
|
|
813
823
|
if (trailingRangesCount > 0) {
|
814
|
-
endCount +=
|
815
|
-
startCount +=
|
816
|
-
idDeltas +=
|
817
|
-
idRangeOffsets +=
|
824
|
+
endCount += "\xFF\xFF";
|
825
|
+
startCount += "\xFF\xFF";
|
826
|
+
idDeltas += "\x00\x01";
|
827
|
+
idRangeOffsets += "\x00\x00";
|
818
828
|
}
|
819
829
|
|
820
|
-
var format314 =
|
821
|
-
var format31012 =
|
822
|
-
var header31012 =
|
830
|
+
var format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds;
|
831
|
+
var format31012 = "";
|
832
|
+
var header31012 = "";
|
823
833
|
|
824
834
|
if (numTables > 1) {
|
825
|
-
cmap +=
|
826
|
-
format31012 =
|
835
|
+
cmap += "\x00\x03" + "\x00\x0A" + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);
|
836
|
+
format31012 = "";
|
827
837
|
|
828
838
|
for (i = 0, ii = ranges.length; i < ii; i++) {
|
829
839
|
range = ranges[i];
|
@@ -843,10 +853,10 @@ var Font = function FontClosure() {
|
|
843
853
|
format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);
|
844
854
|
}
|
845
855
|
|
846
|
-
header31012 =
|
856
|
+
header31012 = "\x00\x0C" + "\x00\x00" + (0, _util.string32)(format31012.length + 16) + "\x00\x00\x00\x00" + (0, _util.string32)(format31012.length / 12);
|
847
857
|
}
|
848
858
|
|
849
|
-
return cmap +
|
859
|
+
return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
|
850
860
|
}
|
851
861
|
|
852
862
|
function validateOS2Table(os2) {
|
@@ -915,12 +925,12 @@ var Font = function FontClosure() {
|
|
915
925
|
} else if (position < 123) {
|
916
926
|
ulUnicodeRange4 |= 1 << position - 96;
|
917
927
|
} else {
|
918
|
-
throw new _util.FormatError(
|
928
|
+
throw new _util.FormatError("Unicode ranges Bits > 123 are reserved for internal usage");
|
919
929
|
}
|
920
930
|
}
|
921
931
|
|
922
|
-
if (lastCharIndex >
|
923
|
-
lastCharIndex =
|
932
|
+
if (lastCharIndex > 0xffff) {
|
933
|
+
lastCharIndex = 0xffff;
|
924
934
|
}
|
925
935
|
} else {
|
926
936
|
firstCharIndex = 0;
|
@@ -939,12 +949,12 @@ var Font = function FontClosure() {
|
|
939
949
|
|
940
950
|
var winAscent = override.yMax || typoAscent;
|
941
951
|
var winDescent = -override.yMin || -typoDescent;
|
942
|
-
return
|
952
|
+
return "\x00\x03" + "\x02\x24" + "\x01\xF4" + "\x00\x05" + "\x00\x00" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x00\x8C" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x01\xDF" + "\x00\x31" + "\x01\x02" + "\x00\x00" + "\x00\x00\x06" + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + "\x00\x00\x00\x00\x00\x00" + (0, _util.string32)(ulUnicodeRange1) + (0, _util.string32)(ulUnicodeRange2) + (0, _util.string32)(ulUnicodeRange3) + (0, _util.string32)(ulUnicodeRange4) + "\x2A\x32\x31\x2A" + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + "\x00\x64" + string16(winAscent) + string16(winDescent) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + "\x00\x03";
|
943
953
|
}
|
944
954
|
|
945
955
|
function createPostTable(properties) {
|
946
|
-
var angle = Math.floor(properties.italicAngle *
|
947
|
-
return
|
956
|
+
var angle = Math.floor(properties.italicAngle * 2 ** 16);
|
957
|
+
return "\x00\x03\x00\x00" + (0, _util.string32)(angle) + "\x00\x00" + "\x00\x00" + (0, _util.string32)(properties.fixedPitch) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00";
|
948
958
|
}
|
949
959
|
|
950
960
|
function createNameTable(name, proto) {
|
@@ -952,7 +962,7 @@ var Font = function FontClosure() {
|
|
952
962
|
proto = [[], []];
|
953
963
|
}
|
954
964
|
|
955
|
-
var strings = [proto[0][0] ||
|
965
|
+
var strings = [proto[0][0] || "Original licence", proto[0][1] || name, proto[0][2] || "Unknown", proto[0][3] || "uniqueID", proto[0][4] || name, proto[0][5] || "Version 0.11", proto[0][6] || "", proto[0][7] || "Unknown", proto[0][8] || "Unknown", proto[0][9] || "Unknown"];
|
956
966
|
var stringsUnicode = [];
|
957
967
|
var i, ii, j, jj, str;
|
958
968
|
|
@@ -964,15 +974,15 @@ var Font = function FontClosure() {
|
|
964
974
|
strBufUnicode.push(string16(str.charCodeAt(j)));
|
965
975
|
}
|
966
976
|
|
967
|
-
stringsUnicode.push(strBufUnicode.join(
|
977
|
+
stringsUnicode.push(strBufUnicode.join(""));
|
968
978
|
}
|
969
979
|
|
970
980
|
var names = [strings, stringsUnicode];
|
971
|
-
var platforms = [
|
972
|
-
var encodings = [
|
973
|
-
var languages = [
|
981
|
+
var platforms = ["\x00\x01", "\x00\x03"];
|
982
|
+
var encodings = ["\x00\x00", "\x00\x01"];
|
983
|
+
var languages = ["\x00\x00", "\x04\x09"];
|
974
984
|
var namesRecordCount = strings.length * platforms.length;
|
975
|
-
var nameTable =
|
985
|
+
var nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
|
976
986
|
var strOffset = 0;
|
977
987
|
|
978
988
|
for (i = 0, ii = platforms.length; i < ii; i++) {
|
@@ -986,7 +996,7 @@ var Font = function FontClosure() {
|
|
986
996
|
}
|
987
997
|
}
|
988
998
|
|
989
|
-
nameTable += strings.join(
|
999
|
+
nameTable += strings.join("") + stringsUnicode.join("");
|
990
1000
|
return nameTable;
|
991
1001
|
}
|
992
1002
|
|
@@ -1000,7 +1010,7 @@ var Font = function FontClosure() {
|
|
1000
1010
|
get renderer() {
|
1001
1011
|
var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
|
1002
1012
|
|
1003
|
-
return (0, _util.shadow)(this,
|
1013
|
+
return (0, _util.shadow)(this, "renderer", renderer);
|
1004
1014
|
},
|
1005
1015
|
|
1006
1016
|
exportData: function Font_exportData() {
|
@@ -1015,14 +1025,12 @@ var Font = function FontClosure() {
|
|
1015
1025
|
return data;
|
1016
1026
|
},
|
1017
1027
|
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
1018
|
-
var _this = this;
|
1019
|
-
|
1020
1028
|
this.missingFile = true;
|
1021
1029
|
var charCode, unicode;
|
1022
1030
|
var name = this.name;
|
1023
1031
|
var type = this.type;
|
1024
1032
|
var subtype = this.subtype;
|
1025
|
-
|
1033
|
+
let fontName = name.replace(/[,_]/g, "-").replace(/\s/g, "");
|
1026
1034
|
var stdFontMap = (0, _standard_fonts.getStdFontMap)(),
|
1027
1035
|
nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();
|
1028
1036
|
var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
|
@@ -1032,9 +1040,9 @@ var Font = function FontClosure() {
|
|
1032
1040
|
this.black = name.search(/Black/g) !== -1;
|
1033
1041
|
this.remeasure = Object.keys(this.widths).length > 0;
|
1034
1042
|
|
1035
|
-
if (isStandardFont && type ===
|
1036
|
-
|
1037
|
-
|
1043
|
+
if (isStandardFont && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
|
1044
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1045
|
+
const map = [];
|
1038
1046
|
|
1039
1047
|
for (charCode in GlyphMapForStandardFonts) {
|
1040
1048
|
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
@@ -1047,7 +1055,7 @@ var Font = function FontClosure() {
|
|
1047
1055
|
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
|
1048
1056
|
}
|
1049
1057
|
} else if (/Calibri/i.test(name)) {
|
1050
|
-
|
1058
|
+
const SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
|
1051
1059
|
|
1052
1060
|
for (charCode in SupplementalGlyphMapForCalibri) {
|
1053
1061
|
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
|
@@ -1068,17 +1076,18 @@ var Font = function FontClosure() {
|
|
1068
1076
|
this.toFontChar = buildToFontChar(_encodings.SymbolSetEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1069
1077
|
} else if (/Dingbats/i.test(fontName)) {
|
1070
1078
|
if (/Wingdings/i.test(name)) {
|
1071
|
-
(0, _util.warn)(
|
1079
|
+
(0, _util.warn)("Non-embedded Wingdings font, falling back to ZapfDingbats.");
|
1072
1080
|
}
|
1073
1081
|
|
1074
1082
|
this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);
|
1075
1083
|
} else if (isStandardFont) {
|
1076
1084
|
this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1077
1085
|
} else {
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1086
|
+
const glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
1087
|
+
const map = [];
|
1088
|
+
this.toUnicode.forEach((charCode, unicodeCharCode) => {
|
1089
|
+
if (!this.composite) {
|
1090
|
+
var glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
|
1082
1091
|
unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
1083
1092
|
|
1084
1093
|
if (unicode !== -1) {
|
@@ -1086,29 +1095,41 @@ var Font = function FontClosure() {
|
|
1086
1095
|
}
|
1087
1096
|
}
|
1088
1097
|
|
1089
|
-
|
1098
|
+
map[+charCode] = unicodeCharCode;
|
1090
1099
|
});
|
1100
|
+
|
1101
|
+
if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
|
1102
|
+
if (/Verdana/i.test(name)) {
|
1103
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1104
|
+
|
1105
|
+
for (charCode in GlyphMapForStandardFonts) {
|
1106
|
+
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
}
|
1110
|
+
|
1111
|
+
this.toFontChar = map;
|
1091
1112
|
}
|
1092
1113
|
|
1093
|
-
this.loadedName = fontName.split(
|
1114
|
+
this.loadedName = fontName.split("-")[0];
|
1094
1115
|
this.fontType = getFontType(type, subtype);
|
1095
1116
|
},
|
1096
1117
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
1097
|
-
|
1118
|
+
const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
|
1098
1119
|
|
1099
1120
|
function readTables(file, numTables) {
|
1100
|
-
|
1101
|
-
tables[
|
1102
|
-
tables[
|
1103
|
-
tables[
|
1104
|
-
tables[
|
1105
|
-
tables[
|
1106
|
-
tables[
|
1107
|
-
tables[
|
1108
|
-
tables[
|
1109
|
-
|
1110
|
-
for (
|
1111
|
-
|
1121
|
+
const tables = Object.create(null);
|
1122
|
+
tables["OS/2"] = null;
|
1123
|
+
tables["cmap"] = null;
|
1124
|
+
tables["head"] = null;
|
1125
|
+
tables["hhea"] = null;
|
1126
|
+
tables["hmtx"] = null;
|
1127
|
+
tables["maxp"] = null;
|
1128
|
+
tables["name"] = null;
|
1129
|
+
tables["post"] = null;
|
1130
|
+
|
1131
|
+
for (let i = 0; i < numTables; i++) {
|
1132
|
+
const table = readTableEntry(font);
|
1112
1133
|
|
1113
1134
|
if (!VALID_TABLES.includes(table.tag)) {
|
1114
1135
|
continue;
|
@@ -1135,17 +1156,17 @@ var Font = function FontClosure() {
|
|
1135
1156
|
var data = file.getBytes(length);
|
1136
1157
|
file.pos = previousPosition;
|
1137
1158
|
|
1138
|
-
if (tag ===
|
1159
|
+
if (tag === "head") {
|
1139
1160
|
data[8] = data[9] = data[10] = data[11] = 0;
|
1140
1161
|
data[17] |= 0x20;
|
1141
1162
|
}
|
1142
1163
|
|
1143
1164
|
return {
|
1144
|
-
tag
|
1145
|
-
checksum
|
1146
|
-
length
|
1147
|
-
offset
|
1148
|
-
data
|
1165
|
+
tag,
|
1166
|
+
checksum,
|
1167
|
+
length,
|
1168
|
+
offset,
|
1169
|
+
data
|
1149
1170
|
};
|
1150
1171
|
}
|
1151
1172
|
|
@@ -1160,23 +1181,23 @@ var Font = function FontClosure() {
|
|
1160
1181
|
}
|
1161
1182
|
|
1162
1183
|
function readTrueTypeCollectionHeader(ttc) {
|
1163
|
-
|
1164
|
-
(0, _util.assert)(ttcTag ===
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
for (
|
1184
|
+
const ttcTag = (0, _util.bytesToString)(ttc.getBytes(4));
|
1185
|
+
(0, _util.assert)(ttcTag === "ttcf", "Must be a TrueType Collection font.");
|
1186
|
+
const majorVersion = ttc.getUint16();
|
1187
|
+
const minorVersion = ttc.getUint16();
|
1188
|
+
const numFonts = ttc.getInt32() >>> 0;
|
1189
|
+
const offsetTable = [];
|
1190
|
+
|
1191
|
+
for (let i = 0; i < numFonts; i++) {
|
1171
1192
|
offsetTable.push(ttc.getInt32() >>> 0);
|
1172
1193
|
}
|
1173
1194
|
|
1174
|
-
|
1175
|
-
ttcTag
|
1176
|
-
majorVersion
|
1177
|
-
minorVersion
|
1178
|
-
numFonts
|
1179
|
-
offsetTable
|
1195
|
+
const header = {
|
1196
|
+
ttcTag,
|
1197
|
+
majorVersion,
|
1198
|
+
minorVersion,
|
1199
|
+
numFonts,
|
1200
|
+
offsetTable
|
1180
1201
|
};
|
1181
1202
|
|
1182
1203
|
switch (majorVersion) {
|
@@ -1190,30 +1211,31 @@ var Font = function FontClosure() {
|
|
1190
1211
|
return header;
|
1191
1212
|
}
|
1192
1213
|
|
1193
|
-
throw new _util.FormatError(
|
1214
|
+
throw new _util.FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
|
1194
1215
|
}
|
1195
1216
|
|
1196
1217
|
function readTrueTypeCollectionData(ttc, fontName) {
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1218
|
+
const {
|
1219
|
+
numFonts,
|
1220
|
+
offsetTable
|
1221
|
+
} = readTrueTypeCollectionHeader(ttc);
|
1200
1222
|
|
1201
|
-
for (
|
1223
|
+
for (let i = 0; i < numFonts; i++) {
|
1202
1224
|
ttc.pos = (ttc.start || 0) + offsetTable[i];
|
1203
|
-
|
1204
|
-
|
1225
|
+
const potentialHeader = readOpenTypeHeader(ttc);
|
1226
|
+
const potentialTables = readTables(ttc, potentialHeader.numTables);
|
1205
1227
|
|
1206
|
-
if (!potentialTables[
|
1228
|
+
if (!potentialTables["name"]) {
|
1207
1229
|
throw new _util.FormatError('TrueType Collection font must contain a "name" table.');
|
1208
1230
|
}
|
1209
1231
|
|
1210
|
-
|
1232
|
+
const nameTable = readNameTable(potentialTables["name"]);
|
1211
1233
|
|
1212
|
-
for (
|
1213
|
-
for (
|
1214
|
-
|
1234
|
+
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
1235
|
+
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
1236
|
+
const nameEntry = nameTable[j][k];
|
1215
1237
|
|
1216
|
-
if (nameEntry && nameEntry.replace(/\s/g,
|
1238
|
+
if (nameEntry && nameEntry.replace(/\s/g, "") === fontName) {
|
1217
1239
|
return {
|
1218
1240
|
header: potentialHeader,
|
1219
1241
|
tables: potentialTables
|
@@ -1223,12 +1245,12 @@ var Font = function FontClosure() {
|
|
1223
1245
|
}
|
1224
1246
|
}
|
1225
1247
|
|
1226
|
-
throw new _util.FormatError(
|
1248
|
+
throw new _util.FormatError(`TrueType Collection does not contain "${fontName}" font.`);
|
1227
1249
|
}
|
1228
1250
|
|
1229
1251
|
function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
|
1230
1252
|
if (!cmap) {
|
1231
|
-
(0, _util.warn)(
|
1253
|
+
(0, _util.warn)("No cmap table available.");
|
1232
1254
|
return {
|
1233
1255
|
platformId: -1,
|
1234
1256
|
encodingId: -1,
|
@@ -1272,9 +1294,9 @@ var Font = function FontClosure() {
|
|
1272
1294
|
|
1273
1295
|
if (useTable) {
|
1274
1296
|
potentialTable = {
|
1275
|
-
platformId
|
1276
|
-
encodingId
|
1277
|
-
offset
|
1297
|
+
platformId,
|
1298
|
+
encodingId,
|
1299
|
+
offset
|
1278
1300
|
};
|
1279
1301
|
}
|
1280
1302
|
|
@@ -1288,7 +1310,7 @@ var Font = function FontClosure() {
|
|
1288
1310
|
}
|
1289
1311
|
|
1290
1312
|
if (!potentialTable || font.peekByte() === -1) {
|
1291
|
-
(0, _util.warn)(
|
1313
|
+
(0, _util.warn)("Could not find a preferred cmap table.");
|
1292
1314
|
return {
|
1293
1315
|
platformId: -1,
|
1294
1316
|
encodingId: -1,
|
@@ -1371,15 +1393,15 @@ var Font = function FontClosure() {
|
|
1371
1393
|
offsetIndex = segment.offsetIndex;
|
1372
1394
|
|
1373
1395
|
for (j = start; j <= end; j++) {
|
1374
|
-
if (j ===
|
1396
|
+
if (j === 0xffff) {
|
1375
1397
|
continue;
|
1376
1398
|
}
|
1377
1399
|
|
1378
1400
|
glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
|
1379
|
-
glyphId = glyphId + delta &
|
1401
|
+
glyphId = glyphId + delta & 0xffff;
|
1380
1402
|
mappings.push({
|
1381
1403
|
charCode: j,
|
1382
|
-
glyphId
|
1404
|
+
glyphId
|
1383
1405
|
});
|
1384
1406
|
}
|
1385
1407
|
}
|
@@ -1391,12 +1413,12 @@ var Font = function FontClosure() {
|
|
1391
1413
|
glyphId = font.getUint16();
|
1392
1414
|
var charCode = firstCode + j;
|
1393
1415
|
mappings.push({
|
1394
|
-
charCode
|
1395
|
-
glyphId
|
1416
|
+
charCode,
|
1417
|
+
glyphId
|
1396
1418
|
});
|
1397
1419
|
}
|
1398
1420
|
} else {
|
1399
|
-
(0, _util.warn)(
|
1421
|
+
(0, _util.warn)("cmap table has unsupported format: " + format);
|
1400
1422
|
return {
|
1401
1423
|
platformId: -1,
|
1402
1424
|
encodingId: -1,
|
@@ -1419,8 +1441,8 @@ var Font = function FontClosure() {
|
|
1419
1441
|
return {
|
1420
1442
|
platformId: potentialTable.platformId,
|
1421
1443
|
encodingId: potentialTable.encodingId,
|
1422
|
-
mappings
|
1423
|
-
hasShortCmap
|
1444
|
+
mappings,
|
1445
|
+
hasShortCmap
|
1424
1446
|
};
|
1425
1447
|
}
|
1426
1448
|
|
@@ -1450,7 +1472,7 @@ var Font = function FontClosure() {
|
|
1450
1472
|
var numOfMetrics = font.getUint16();
|
1451
1473
|
|
1452
1474
|
if (numOfMetrics > numGlyphs) {
|
1453
|
-
(0, _util.info)(
|
1475
|
+
(0, _util.info)("The numOfMetrics (" + numOfMetrics + ") should not be " + "greater than the numGlyphs (" + numGlyphs + ")");
|
1454
1476
|
numOfMetrics = numGlyphs;
|
1455
1477
|
header.data[34] = (numOfMetrics & 0xff00) >> 8;
|
1456
1478
|
header.data[35] = numOfMetrics & 0x00ff;
|
@@ -1513,11 +1535,27 @@ var Font = function FontClosure() {
|
|
1513
1535
|
for (i = 0; i < flagsCount; i++) {
|
1514
1536
|
var flag = glyf[j++];
|
1515
1537
|
|
1516
|
-
if (flag &
|
1517
|
-
glyf[j - 1] = flag &
|
1538
|
+
if (flag & 0xc0) {
|
1539
|
+
glyf[j - 1] = flag & 0x3f;
|
1540
|
+
}
|
1541
|
+
|
1542
|
+
let xLength = 2;
|
1543
|
+
|
1544
|
+
if (flag & 2) {
|
1545
|
+
xLength = 1;
|
1546
|
+
} else if (flag & 16) {
|
1547
|
+
xLength = 0;
|
1518
1548
|
}
|
1519
1549
|
|
1520
|
-
|
1550
|
+
let yLength = 2;
|
1551
|
+
|
1552
|
+
if (flag & 4) {
|
1553
|
+
yLength = 1;
|
1554
|
+
} else if (flag & 32) {
|
1555
|
+
yLength = 0;
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
const xyLength = xLength + yLength;
|
1521
1559
|
coordinatesLength += xyLength;
|
1522
1560
|
|
1523
1561
|
if (flag & 8) {
|
@@ -1568,7 +1606,7 @@ var Font = function FontClosure() {
|
|
1568
1606
|
var version = int32(data[0], data[1], data[2], data[3]);
|
1569
1607
|
|
1570
1608
|
if (version >> 16 !== 1) {
|
1571
|
-
(0, _util.info)(
|
1609
|
+
(0, _util.info)("Attempting to fix invalid version in head table: " + version);
|
1572
1610
|
data[0] = 0;
|
1573
1611
|
data[1] = 1;
|
1574
1612
|
data[2] = 0;
|
@@ -1578,7 +1616,7 @@ var Font = function FontClosure() {
|
|
1578
1616
|
var indexToLocFormat = int16(data[50], data[51]);
|
1579
1617
|
|
1580
1618
|
if (indexToLocFormat < 0 || indexToLocFormat > 1) {
|
1581
|
-
(0, _util.info)(
|
1619
|
+
(0, _util.info)("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat);
|
1582
1620
|
var numGlyphsPlusOne = numGlyphs + 1;
|
1583
1621
|
|
1584
1622
|
if (locaLength === numGlyphsPlusOne << 1) {
|
@@ -1588,7 +1626,7 @@ var Font = function FontClosure() {
|
|
1588
1626
|
data[50] = 0;
|
1589
1627
|
data[51] = 1;
|
1590
1628
|
} else {
|
1591
|
-
throw new _util.FormatError(
|
1629
|
+
throw new _util.FormatError("Could not fix indexToLocFormat: " + indexToLocFormat);
|
1592
1630
|
}
|
1593
1631
|
}
|
1594
1632
|
}
|
@@ -1604,10 +1642,10 @@ var Font = function FontClosure() {
|
|
1604
1642
|
};
|
1605
1643
|
|
1606
1644
|
itemEncode = function fontItemEncodeLong(data, offset, value) {
|
1607
|
-
data[offset] = value >>> 24 &
|
1608
|
-
data[offset + 1] = value >> 16 &
|
1609
|
-
data[offset + 2] = value >> 8 &
|
1610
|
-
data[offset + 3] = value &
|
1645
|
+
data[offset] = value >>> 24 & 0xff;
|
1646
|
+
data[offset + 1] = value >> 16 & 0xff;
|
1647
|
+
data[offset + 2] = value >> 8 & 0xff;
|
1648
|
+
data[offset + 3] = value & 0xff;
|
1611
1649
|
};
|
1612
1650
|
} else {
|
1613
1651
|
itemSize = 2;
|
@@ -1617,15 +1655,14 @@ var Font = function FontClosure() {
|
|
1617
1655
|
};
|
1618
1656
|
|
1619
1657
|
itemEncode = function fontItemEncode(data, offset, value) {
|
1620
|
-
data[offset] = value >> 9 &
|
1621
|
-
data[offset + 1] = value >> 1 &
|
1658
|
+
data[offset] = value >> 9 & 0xff;
|
1659
|
+
data[offset + 1] = value >> 1 & 0xff;
|
1622
1660
|
};
|
1623
1661
|
}
|
1624
1662
|
|
1625
1663
|
var numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
|
1626
|
-
var locaData = loca.data;
|
1627
1664
|
var locaDataSize = itemSize * (1 + numGlyphsOut);
|
1628
|
-
locaData = new Uint8Array(locaDataSize);
|
1665
|
+
var locaData = new Uint8Array(locaDataSize);
|
1629
1666
|
locaData.set(loca.data.subarray(0, locaDataSize));
|
1630
1667
|
loca.data = locaData;
|
1631
1668
|
var oldGlyfData = glyf.data;
|
@@ -1693,8 +1730,8 @@ var Font = function FontClosure() {
|
|
1693
1730
|
}
|
1694
1731
|
|
1695
1732
|
return {
|
1696
|
-
missingGlyphs
|
1697
|
-
maxSizeOfInstructions
|
1733
|
+
missingGlyphs,
|
1734
|
+
maxSizeOfInstructions
|
1698
1735
|
};
|
1699
1736
|
}
|
1700
1737
|
|
@@ -1750,7 +1787,7 @@ var Font = function FontClosure() {
|
|
1750
1787
|
strBuf[i] = String.fromCharCode(font.getByte());
|
1751
1788
|
}
|
1752
1789
|
|
1753
|
-
customNames.push(strBuf.join(
|
1790
|
+
customNames.push(strBuf.join(""));
|
1754
1791
|
}
|
1755
1792
|
|
1756
1793
|
glyphNames = [];
|
@@ -1772,7 +1809,7 @@ var Font = function FontClosure() {
|
|
1772
1809
|
break;
|
1773
1810
|
|
1774
1811
|
default:
|
1775
|
-
(0, _util.warn)(
|
1812
|
+
(0, _util.warn)("Unknown/unsupported post table version " + version);
|
1776
1813
|
valid = false;
|
1777
1814
|
|
1778
1815
|
if (properties.defaultEncoding) {
|
@@ -1837,7 +1874,7 @@ var Font = function FontClosure() {
|
|
1837
1874
|
var nameIndex = record.name;
|
1838
1875
|
|
1839
1876
|
if (record.encoding) {
|
1840
|
-
var str =
|
1877
|
+
var str = "";
|
1841
1878
|
|
1842
1879
|
for (var j = 0, jj = record.length; j < jj; j += 2) {
|
1843
1880
|
str += String.fromCharCode(font.getUint16());
|
@@ -1896,8 +1933,8 @@ var Font = function FontClosure() {
|
|
1896
1933
|
stack.push(b << 8 | data[i++]);
|
1897
1934
|
}
|
1898
1935
|
}
|
1899
|
-
} else if ((op &
|
1900
|
-
n = op -
|
1936
|
+
} else if ((op & 0xf8) === 0xb0) {
|
1937
|
+
n = op - 0xb0 + 1;
|
1901
1938
|
|
1902
1939
|
if (inFDEF || inELSE) {
|
1903
1940
|
i += n;
|
@@ -1906,8 +1943,8 @@ var Font = function FontClosure() {
|
|
1906
1943
|
stack.push(data[i++]);
|
1907
1944
|
}
|
1908
1945
|
}
|
1909
|
-
} else if ((op &
|
1910
|
-
n = op -
|
1946
|
+
} else if ((op & 0xf8) === 0xb8) {
|
1947
|
+
n = op - 0xb8 + 1;
|
1911
1948
|
|
1912
1949
|
if (inFDEF || inELSE) {
|
1913
1950
|
i += n * 2;
|
@@ -1917,20 +1954,20 @@ var Font = function FontClosure() {
|
|
1917
1954
|
stack.push(b << 8 | data[i++]);
|
1918
1955
|
}
|
1919
1956
|
}
|
1920
|
-
} else if (op ===
|
1957
|
+
} else if (op === 0x2b && !tooComplexToFollowFunctions) {
|
1921
1958
|
if (!inFDEF && !inELSE) {
|
1922
1959
|
funcId = stack[stack.length - 1];
|
1923
1960
|
|
1924
1961
|
if (isNaN(funcId)) {
|
1925
|
-
(0, _util.info)(
|
1962
|
+
(0, _util.info)("TT: CALL empty stack (or invalid entry).");
|
1926
1963
|
} else {
|
1927
1964
|
ttContext.functionsUsed[funcId] = true;
|
1928
1965
|
|
1929
1966
|
if (funcId in ttContext.functionsStackDeltas) {
|
1930
|
-
|
1967
|
+
const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
|
1931
1968
|
|
1932
1969
|
if (newStackLength < 0) {
|
1933
|
-
(0, _util.warn)(
|
1970
|
+
(0, _util.warn)("TT: CALL invalid functions stack delta.");
|
1934
1971
|
ttContext.hintsValid = false;
|
1935
1972
|
return;
|
1936
1973
|
}
|
@@ -1938,15 +1975,15 @@ var Font = function FontClosure() {
|
|
1938
1975
|
stack.length = newStackLength;
|
1939
1976
|
} else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
|
1940
1977
|
callstack.push({
|
1941
|
-
data
|
1942
|
-
i
|
1978
|
+
data,
|
1979
|
+
i,
|
1943
1980
|
stackTop: stack.length - 1
|
1944
1981
|
});
|
1945
1982
|
functionsCalled.push(funcId);
|
1946
1983
|
pc = ttContext.functionsDefined[funcId];
|
1947
1984
|
|
1948
1985
|
if (!pc) {
|
1949
|
-
(0, _util.warn)(
|
1986
|
+
(0, _util.warn)("TT: CALL non-existent function");
|
1950
1987
|
ttContext.hintsValid = false;
|
1951
1988
|
return;
|
1952
1989
|
}
|
@@ -1956,9 +1993,9 @@ var Font = function FontClosure() {
|
|
1956
1993
|
}
|
1957
1994
|
}
|
1958
1995
|
}
|
1959
|
-
} else if (op ===
|
1996
|
+
} else if (op === 0x2c && !tooComplexToFollowFunctions) {
|
1960
1997
|
if (inFDEF || inELSE) {
|
1961
|
-
(0, _util.warn)(
|
1998
|
+
(0, _util.warn)("TT: nested FDEFs not allowed");
|
1962
1999
|
tooComplexToFollowFunctions = true;
|
1963
2000
|
}
|
1964
2001
|
|
@@ -1966,10 +2003,10 @@ var Font = function FontClosure() {
|
|
1966
2003
|
lastDeff = i;
|
1967
2004
|
funcId = stack.pop();
|
1968
2005
|
ttContext.functionsDefined[funcId] = {
|
1969
|
-
data
|
1970
|
-
i
|
2006
|
+
data,
|
2007
|
+
i
|
1971
2008
|
};
|
1972
|
-
} else if (op ===
|
2009
|
+
} else if (op === 0x2d) {
|
1973
2010
|
if (inFDEF) {
|
1974
2011
|
inFDEF = false;
|
1975
2012
|
lastEndf = i;
|
@@ -1977,7 +2014,7 @@ var Font = function FontClosure() {
|
|
1977
2014
|
pc = callstack.pop();
|
1978
2015
|
|
1979
2016
|
if (!pc) {
|
1980
|
-
(0, _util.warn)(
|
2017
|
+
(0, _util.warn)("TT: ENDF bad stack");
|
1981
2018
|
ttContext.hintsValid = false;
|
1982
2019
|
return;
|
1983
2020
|
}
|
@@ -1989,7 +2026,7 @@ var Font = function FontClosure() {
|
|
1989
2026
|
}
|
1990
2027
|
} else if (op === 0x89) {
|
1991
2028
|
if (inFDEF || inELSE) {
|
1992
|
-
(0, _util.warn)(
|
2029
|
+
(0, _util.warn)("TT: nested IDEFs not allowed");
|
1993
2030
|
tooComplexToFollowFunctions = true;
|
1994
2031
|
}
|
1995
2032
|
|
@@ -1997,7 +2034,7 @@ var Font = function FontClosure() {
|
|
1997
2034
|
lastDeff = i;
|
1998
2035
|
} else if (op === 0x58) {
|
1999
2036
|
++ifLevel;
|
2000
|
-
} else if (op ===
|
2037
|
+
} else if (op === 0x1b) {
|
2001
2038
|
inELSE = ifLevel;
|
2002
2039
|
} else if (op === 0x59) {
|
2003
2040
|
if (inELSE === ifLevel) {
|
@@ -2005,7 +2042,7 @@ var Font = function FontClosure() {
|
|
2005
2042
|
}
|
2006
2043
|
|
2007
2044
|
--ifLevel;
|
2008
|
-
} else if (op ===
|
2045
|
+
} else if (op === 0x1c) {
|
2009
2046
|
if (!inFDEF && !inELSE) {
|
2010
2047
|
var offset = stack[stack.length - 1];
|
2011
2048
|
|
@@ -2016,7 +2053,15 @@ var Font = function FontClosure() {
|
|
2016
2053
|
}
|
2017
2054
|
|
2018
2055
|
if (!inFDEF && !inELSE) {
|
2019
|
-
|
2056
|
+
let stackDelta = 0;
|
2057
|
+
|
2058
|
+
if (op <= 0x8e) {
|
2059
|
+
stackDelta = TTOpsStackDeltas[op];
|
2060
|
+
} else if (op >= 0xc0 && op <= 0xdf) {
|
2061
|
+
stackDelta = -1;
|
2062
|
+
} else if (op >= 0xe0) {
|
2063
|
+
stackDelta = -2;
|
2064
|
+
}
|
2020
2065
|
|
2021
2066
|
if (op >= 0x71 && op <= 0x75) {
|
2022
2067
|
n = stack.pop();
|
@@ -2046,8 +2091,8 @@ var Font = function FontClosure() {
|
|
2046
2091
|
}
|
2047
2092
|
|
2048
2093
|
if (lastDeff > lastEndf) {
|
2049
|
-
(0, _util.warn)(
|
2050
|
-
content.push(new Uint8Array([0x22,
|
2094
|
+
(0, _util.warn)("TT: complementing a missing function tail");
|
2095
|
+
content.push(new Uint8Array([0x22, 0x2d]));
|
2051
2096
|
}
|
2052
2097
|
|
2053
2098
|
foldTTTable(table, content);
|
@@ -2059,20 +2104,20 @@ var Font = function FontClosure() {
|
|
2059
2104
|
}
|
2060
2105
|
|
2061
2106
|
if (ttContext.functionsDefined.length > maxFunctionDefs) {
|
2062
|
-
(0, _util.warn)(
|
2107
|
+
(0, _util.warn)("TT: more functions defined than expected");
|
2063
2108
|
ttContext.hintsValid = false;
|
2064
2109
|
return;
|
2065
2110
|
}
|
2066
2111
|
|
2067
2112
|
for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
|
2068
2113
|
if (j > maxFunctionDefs) {
|
2069
|
-
(0, _util.warn)(
|
2114
|
+
(0, _util.warn)("TT: invalid function id: " + j);
|
2070
2115
|
ttContext.hintsValid = false;
|
2071
2116
|
return;
|
2072
2117
|
}
|
2073
2118
|
|
2074
2119
|
if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
|
2075
|
-
(0, _util.warn)(
|
2120
|
+
(0, _util.warn)("TT: undefined function: " + j);
|
2076
2121
|
ttContext.hintsValid = false;
|
2077
2122
|
return;
|
2078
2123
|
}
|
@@ -2133,10 +2178,10 @@ var Font = function FontClosure() {
|
|
2133
2178
|
}
|
2134
2179
|
|
2135
2180
|
font = new _stream.Stream(new Uint8Array(font.getBytes()));
|
2136
|
-
|
2181
|
+
let header, tables;
|
2137
2182
|
|
2138
2183
|
if (isTrueTypeCollectionFile(font)) {
|
2139
|
-
|
2184
|
+
const ttcData = readTrueTypeCollectionData(font, this.name);
|
2140
2185
|
header = ttcData.header;
|
2141
2186
|
tables = ttcData.tables;
|
2142
2187
|
} else {
|
@@ -2144,34 +2189,34 @@ var Font = function FontClosure() {
|
|
2144
2189
|
tables = readTables(font, header.numTables);
|
2145
2190
|
}
|
2146
2191
|
|
2147
|
-
|
2148
|
-
var isTrueType = !tables[
|
2192
|
+
let cff, cffFile;
|
2193
|
+
var isTrueType = !tables["CFF "];
|
2149
2194
|
|
2150
2195
|
if (!isTrueType) {
|
2151
|
-
|
2196
|
+
const isComposite = properties.composite && ((properties.cidToGidMap || []).length > 0 || !(properties.cMap instanceof _cmap.IdentityCMap));
|
2152
2197
|
|
2153
|
-
if (header.version ===
|
2154
|
-
cffFile = new _stream.Stream(tables[
|
2198
|
+
if (header.version === "OTTO" && !isComposite || !tables["head"] || !tables["hhea"] || !tables["maxp"] || !tables["post"]) {
|
2199
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2155
2200
|
cff = new CFFFont(cffFile, properties);
|
2156
2201
|
adjustWidths(properties);
|
2157
2202
|
return this.convert(name, cff, properties);
|
2158
2203
|
}
|
2159
2204
|
|
2160
|
-
delete tables[
|
2161
|
-
delete tables[
|
2162
|
-
delete tables[
|
2163
|
-
delete tables[
|
2164
|
-
delete tables[
|
2205
|
+
delete tables["glyf"];
|
2206
|
+
delete tables["loca"];
|
2207
|
+
delete tables["fpgm"];
|
2208
|
+
delete tables["prep"];
|
2209
|
+
delete tables["cvt "];
|
2165
2210
|
this.isOpenType = true;
|
2166
2211
|
} else {
|
2167
|
-
if (!tables[
|
2212
|
+
if (!tables["loca"]) {
|
2168
2213
|
throw new _util.FormatError('Required "loca" table is not found');
|
2169
2214
|
}
|
2170
2215
|
|
2171
|
-
if (!tables[
|
2216
|
+
if (!tables["glyf"]) {
|
2172
2217
|
(0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
|
2173
|
-
tables[
|
2174
|
-
tag:
|
2218
|
+
tables["glyf"] = {
|
2219
|
+
tag: "glyf",
|
2175
2220
|
data: new Uint8Array(0)
|
2176
2221
|
};
|
2177
2222
|
}
|
@@ -2179,32 +2224,32 @@ var Font = function FontClosure() {
|
|
2179
2224
|
this.isOpenType = false;
|
2180
2225
|
}
|
2181
2226
|
|
2182
|
-
if (!tables[
|
2227
|
+
if (!tables["maxp"]) {
|
2183
2228
|
throw new _util.FormatError('Required "maxp" table is not found');
|
2184
2229
|
}
|
2185
2230
|
|
2186
|
-
font.pos = (font.start || 0) + tables[
|
2231
|
+
font.pos = (font.start || 0) + tables["maxp"].offset;
|
2187
2232
|
var version = font.getInt32();
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2233
|
+
const numGlyphs = font.getUint16();
|
2234
|
+
let numGlyphsOut = numGlyphs + 1;
|
2235
|
+
let dupFirstEntry = true;
|
2191
2236
|
|
2192
|
-
if (numGlyphsOut >
|
2237
|
+
if (numGlyphsOut > 0xffff) {
|
2193
2238
|
dupFirstEntry = false;
|
2194
2239
|
numGlyphsOut = numGlyphs;
|
2195
|
-
(0, _util.warn)(
|
2240
|
+
(0, _util.warn)("Not enough space in glyfs to duplicate first glyph.");
|
2196
2241
|
}
|
2197
2242
|
|
2198
2243
|
var maxFunctionDefs = 0;
|
2199
2244
|
var maxSizeOfInstructions = 0;
|
2200
2245
|
|
2201
|
-
if (version >= 0x00010000 && tables[
|
2246
|
+
if (version >= 0x00010000 && tables["maxp"].length >= 22) {
|
2202
2247
|
font.pos += 8;
|
2203
2248
|
var maxZones = font.getUint16();
|
2204
2249
|
|
2205
2250
|
if (maxZones > 2) {
|
2206
|
-
tables[
|
2207
|
-
tables[
|
2251
|
+
tables["maxp"].data[14] = 0;
|
2252
|
+
tables["maxp"].data[15] = 2;
|
2208
2253
|
}
|
2209
2254
|
|
2210
2255
|
font.pos += 4;
|
@@ -2213,61 +2258,61 @@ var Font = function FontClosure() {
|
|
2213
2258
|
maxSizeOfInstructions = font.getUint16();
|
2214
2259
|
}
|
2215
2260
|
|
2216
|
-
tables[
|
2217
|
-
tables[
|
2218
|
-
var hintsValid = sanitizeTTPrograms(tables[
|
2261
|
+
tables["maxp"].data[4] = numGlyphsOut >> 8;
|
2262
|
+
tables["maxp"].data[5] = numGlyphsOut & 255;
|
2263
|
+
var hintsValid = sanitizeTTPrograms(tables["fpgm"], tables["prep"], tables["cvt "], maxFunctionDefs);
|
2219
2264
|
|
2220
2265
|
if (!hintsValid) {
|
2221
|
-
delete tables[
|
2222
|
-
delete tables[
|
2223
|
-
delete tables[
|
2266
|
+
delete tables["fpgm"];
|
2267
|
+
delete tables["prep"];
|
2268
|
+
delete tables["cvt "];
|
2224
2269
|
}
|
2225
2270
|
|
2226
|
-
sanitizeMetrics(font, tables[
|
2271
|
+
sanitizeMetrics(font, tables["hhea"], tables["hmtx"], numGlyphsOut, dupFirstEntry);
|
2227
2272
|
|
2228
|
-
if (!tables[
|
2273
|
+
if (!tables["head"]) {
|
2229
2274
|
throw new _util.FormatError('Required "head" table is not found');
|
2230
2275
|
}
|
2231
2276
|
|
2232
|
-
sanitizeHead(tables[
|
2277
|
+
sanitizeHead(tables["head"], numGlyphs, isTrueType ? tables["loca"].length : 0);
|
2233
2278
|
var missingGlyphs = Object.create(null);
|
2234
2279
|
|
2235
2280
|
if (isTrueType) {
|
2236
|
-
var isGlyphLocationsLong = int16(tables[
|
2237
|
-
var glyphsInfo = sanitizeGlyphLocations(tables[
|
2281
|
+
var isGlyphLocationsLong = int16(tables["head"].data[50], tables["head"].data[51]);
|
2282
|
+
var glyphsInfo = sanitizeGlyphLocations(tables["loca"], tables["glyf"], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
|
2238
2283
|
missingGlyphs = glyphsInfo.missingGlyphs;
|
2239
2284
|
|
2240
|
-
if (version >= 0x00010000 && tables[
|
2241
|
-
tables[
|
2242
|
-
tables[
|
2285
|
+
if (version >= 0x00010000 && tables["maxp"].length >= 22) {
|
2286
|
+
tables["maxp"].data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
|
2287
|
+
tables["maxp"].data[27] = glyphsInfo.maxSizeOfInstructions & 255;
|
2243
2288
|
}
|
2244
2289
|
}
|
2245
2290
|
|
2246
|
-
if (!tables[
|
2291
|
+
if (!tables["hhea"]) {
|
2247
2292
|
throw new _util.FormatError('Required "hhea" table is not found');
|
2248
2293
|
}
|
2249
2294
|
|
2250
|
-
if (tables[
|
2251
|
-
tables[
|
2252
|
-
tables[
|
2295
|
+
if (tables["hhea"].data[10] === 0 && tables["hhea"].data[11] === 0) {
|
2296
|
+
tables["hhea"].data[10] = 0xff;
|
2297
|
+
tables["hhea"].data[11] = 0xff;
|
2253
2298
|
}
|
2254
2299
|
|
2255
2300
|
var metricsOverride = {
|
2256
|
-
unitsPerEm: int16(tables[
|
2257
|
-
yMax: int16(tables[
|
2258
|
-
yMin: signedInt16(tables[
|
2259
|
-
ascent: int16(tables[
|
2260
|
-
descent: signedInt16(tables[
|
2301
|
+
unitsPerEm: int16(tables["head"].data[18], tables["head"].data[19]),
|
2302
|
+
yMax: int16(tables["head"].data[42], tables["head"].data[43]),
|
2303
|
+
yMin: signedInt16(tables["head"].data[38], tables["head"].data[39]),
|
2304
|
+
ascent: int16(tables["hhea"].data[4], tables["hhea"].data[5]),
|
2305
|
+
descent: signedInt16(tables["hhea"].data[6], tables["hhea"].data[7])
|
2261
2306
|
};
|
2262
2307
|
this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
|
2263
2308
|
this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
2264
2309
|
|
2265
|
-
if (tables[
|
2266
|
-
readPostScriptTable(tables[
|
2310
|
+
if (tables["post"]) {
|
2311
|
+
readPostScriptTable(tables["post"], properties, numGlyphs);
|
2267
2312
|
}
|
2268
2313
|
|
2269
|
-
tables[
|
2270
|
-
tag:
|
2314
|
+
tables["post"] = {
|
2315
|
+
tag: "post",
|
2271
2316
|
data: createPostTable(properties)
|
2272
2317
|
};
|
2273
2318
|
var charCodeToGlyphId = [],
|
@@ -2282,7 +2327,7 @@ var Font = function FontClosure() {
|
|
2282
2327
|
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
2283
2328
|
properties.cMap.forEach(function (charCode, cid) {
|
2284
2329
|
if (cid > 0xffff) {
|
2285
|
-
throw new _util.FormatError(
|
2330
|
+
throw new _util.FormatError("Max size of CID is 65,535");
|
2286
2331
|
}
|
2287
2332
|
|
2288
2333
|
var glyphId = -1;
|
@@ -2298,7 +2343,7 @@ var Font = function FontClosure() {
|
|
2298
2343
|
}
|
2299
2344
|
});
|
2300
2345
|
} else {
|
2301
|
-
var cmapTable = readCmapTable(tables[
|
2346
|
+
var cmapTable = readCmapTable(tables["cmap"], font, this.isSymbolicFont, properties.hasEncoding);
|
2302
2347
|
var cmapPlatformId = cmapTable.platformId;
|
2303
2348
|
var cmapEncodingId = cmapTable.encodingId;
|
2304
2349
|
var cmapMappings = cmapTable.mappings;
|
@@ -2307,7 +2352,7 @@ var Font = function FontClosure() {
|
|
2307
2352
|
if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && !!(0, _encodings.getEncoding)(properties.baseEncodingName)) {
|
2308
2353
|
var baseEncoding = [];
|
2309
2354
|
|
2310
|
-
if (properties.baseEncodingName ===
|
2355
|
+
if (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding") {
|
2311
2356
|
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
2312
2357
|
}
|
2313
2358
|
|
@@ -2318,7 +2363,7 @@ var Font = function FontClosure() {
|
|
2318
2363
|
|
2319
2364
|
if (this.differences && charCode in this.differences) {
|
2320
2365
|
glyphName = this.differences[charCode];
|
2321
|
-
} else if (charCode in baseEncoding && baseEncoding[charCode] !==
|
2366
|
+
} else if (charCode in baseEncoding && baseEncoding[charCode] !== "") {
|
2322
2367
|
glyphName = baseEncoding[charCode];
|
2323
2368
|
} else {
|
2324
2369
|
glyphName = _encodings.StandardEncoding[charCode];
|
@@ -2339,7 +2384,7 @@ var Font = function FontClosure() {
|
|
2339
2384
|
|
2340
2385
|
var found = false;
|
2341
2386
|
|
2342
|
-
for (
|
2387
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2343
2388
|
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
|
2344
2389
|
continue;
|
2345
2390
|
}
|
@@ -2362,18 +2407,18 @@ var Font = function FontClosure() {
|
|
2362
2407
|
}
|
2363
2408
|
}
|
2364
2409
|
} else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
|
2365
|
-
for (
|
2366
|
-
charCodeToGlyphId[cmapMappings[
|
2410
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2411
|
+
charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
|
2367
2412
|
}
|
2368
2413
|
} else {
|
2369
|
-
for (
|
2370
|
-
charCode = cmapMappings[
|
2414
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2415
|
+
charCode = cmapMappings[i].charCode;
|
2371
2416
|
|
2372
|
-
if (cmapPlatformId === 3 && charCode >=
|
2373
|
-
charCode &=
|
2417
|
+
if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
|
2418
|
+
charCode &= 0xff;
|
2374
2419
|
}
|
2375
2420
|
|
2376
|
-
charCodeToGlyphId[charCode] = cmapMappings[
|
2421
|
+
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
2377
2422
|
}
|
2378
2423
|
}
|
2379
2424
|
}
|
@@ -2382,7 +2427,7 @@ var Font = function FontClosure() {
|
|
2382
2427
|
charCodeToGlyphId[0] = 0;
|
2383
2428
|
}
|
2384
2429
|
|
2385
|
-
|
2430
|
+
let glyphZeroId = numGlyphsOut - 1;
|
2386
2431
|
|
2387
2432
|
if (!dupFirstEntry) {
|
2388
2433
|
glyphZeroId = 0;
|
@@ -2390,39 +2435,39 @@ var Font = function FontClosure() {
|
|
2390
2435
|
|
2391
2436
|
var newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId);
|
2392
2437
|
this.toFontChar = newMapping.toFontChar;
|
2393
|
-
tables[
|
2394
|
-
tag:
|
2438
|
+
tables["cmap"] = {
|
2439
|
+
tag: "cmap",
|
2395
2440
|
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut)
|
2396
2441
|
};
|
2397
2442
|
|
2398
|
-
if (!tables[
|
2399
|
-
tables[
|
2400
|
-
tag:
|
2443
|
+
if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"])) {
|
2444
|
+
tables["OS/2"] = {
|
2445
|
+
tag: "OS/2",
|
2401
2446
|
data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
|
2402
2447
|
};
|
2403
2448
|
}
|
2404
2449
|
|
2405
2450
|
if (!isTrueType) {
|
2406
2451
|
try {
|
2407
|
-
cffFile = new _stream.Stream(tables[
|
2452
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2408
2453
|
var parser = new _cff_parser.CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
|
2409
2454
|
cff = parser.parse();
|
2410
2455
|
cff.duplicateFirstGlyph();
|
2411
2456
|
var compiler = new _cff_parser.CFFCompiler(cff);
|
2412
|
-
tables[
|
2457
|
+
tables["CFF "].data = compiler.compile();
|
2413
2458
|
} catch (e) {
|
2414
|
-
(0, _util.warn)(
|
2459
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
2415
2460
|
}
|
2416
2461
|
}
|
2417
2462
|
|
2418
|
-
if (!tables[
|
2419
|
-
tables[
|
2420
|
-
tag:
|
2463
|
+
if (!tables["name"]) {
|
2464
|
+
tables["name"] = {
|
2465
|
+
tag: "name",
|
2421
2466
|
data: createNameTable(this.name)
|
2422
2467
|
};
|
2423
2468
|
} else {
|
2424
|
-
var namePrototype = readNameTable(tables[
|
2425
|
-
tables[
|
2469
|
+
var namePrototype = readNameTable(tables["name"]);
|
2470
|
+
tables["name"].data = createNameTable(name, namePrototype);
|
2426
2471
|
}
|
2427
2472
|
|
2428
2473
|
var builder = new OpenTypeFileBuilder(header.version);
|
@@ -2440,7 +2485,7 @@ var Font = function FontClosure() {
|
|
2440
2485
|
adjustToUnicode(properties, properties.builtInEncoding);
|
2441
2486
|
}
|
2442
2487
|
|
2443
|
-
|
2488
|
+
let glyphZeroId = 1;
|
2444
2489
|
|
2445
2490
|
if (font instanceof CFFFont) {
|
2446
2491
|
glyphZeroId = font.numGlyphs - 1;
|
@@ -2513,9 +2558,9 @@ var Font = function FontClosure() {
|
|
2513
2558
|
var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
|
2514
2559
|
var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
|
2515
2560
|
seacMap[charCode] = {
|
2516
|
-
baseFontCharCode
|
2517
|
-
accentFontCharCode
|
2518
|
-
accentOffset
|
2561
|
+
baseFontCharCode,
|
2562
|
+
accentFontCharCode,
|
2563
|
+
accentOffset
|
2519
2564
|
};
|
2520
2565
|
}
|
2521
2566
|
}
|
@@ -2524,23 +2569,23 @@ var Font = function FontClosure() {
|
|
2524
2569
|
}
|
2525
2570
|
|
2526
2571
|
var unitsPerEm = 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
|
2527
|
-
var builder = new OpenTypeFileBuilder(
|
2528
|
-
builder.addTable(
|
2529
|
-
builder.addTable(
|
2530
|
-
builder.addTable(
|
2531
|
-
builder.addTable(
|
2532
|
-
builder.addTable(
|
2533
|
-
builder.addTable(
|
2572
|
+
var builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
|
2573
|
+
builder.addTable("CFF ", font.data);
|
2574
|
+
builder.addTable("OS/2", createOS2Table(properties, newMapping.charCodeToGlyphId));
|
2575
|
+
builder.addTable("cmap", createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
|
2576
|
+
builder.addTable("head", "\x00\x01\x00\x00" + "\x00\x00\x10\x00" + "\x00\x00\x00\x00" + "\x5F\x0F\x3C\xF5" + "\x00\x00" + safeString16(unitsPerEm) + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00" + safeString16(properties.descent) + "\x0F\xFF" + safeString16(properties.ascent) + string16(properties.italicAngle ? 2 : 0) + "\x00\x11" + "\x00\x00" + "\x00\x00" + "\x00\x00");
|
2577
|
+
builder.addTable("hhea", "\x00\x01\x00\x00" + safeString16(properties.ascent) + safeString16(properties.descent) + "\x00\x00" + "\xFF\xFF" + "\x00\x00" + "\x00\x00" + "\x00\x00" + safeString16(properties.capHeight) + safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + string16(numGlyphs));
|
2578
|
+
builder.addTable("hmtx", function fontFieldsHmtx() {
|
2534
2579
|
var charstrings = font.charstrings;
|
2535
2580
|
var cffWidths = font.cff ? font.cff.widths : null;
|
2536
|
-
var hmtx =
|
2581
|
+
var hmtx = "\x00\x00\x00\x00";
|
2537
2582
|
|
2538
2583
|
for (var i = 1, ii = numGlyphs; i < ii; i++) {
|
2539
2584
|
var width = 0;
|
2540
2585
|
|
2541
2586
|
if (charstrings) {
|
2542
2587
|
var charstring = charstrings[i - 1];
|
2543
|
-
width =
|
2588
|
+
width = "width" in charstring ? charstring.width : 0;
|
2544
2589
|
} else if (cffWidths) {
|
2545
2590
|
width = Math.ceil(cffWidths[i] || 0);
|
2546
2591
|
}
|
@@ -2550,18 +2595,18 @@ var Font = function FontClosure() {
|
|
2550
2595
|
|
2551
2596
|
return hmtx;
|
2552
2597
|
}());
|
2553
|
-
builder.addTable(
|
2554
|
-
builder.addTable(
|
2555
|
-
builder.addTable(
|
2598
|
+
builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs));
|
2599
|
+
builder.addTable("name", createNameTable(fontName));
|
2600
|
+
builder.addTable("post", createPostTable(properties));
|
2556
2601
|
return builder.toArray();
|
2557
2602
|
},
|
2558
2603
|
|
2559
2604
|
get spaceWidth() {
|
2560
|
-
if (
|
2605
|
+
if ("_shadowWidth" in this) {
|
2561
2606
|
return this._shadowWidth;
|
2562
2607
|
}
|
2563
2608
|
|
2564
|
-
var possibleSpaceReplacements = [
|
2609
|
+
var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
2565
2610
|
var width;
|
2566
2611
|
|
2567
2612
|
for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
|
@@ -2613,9 +2658,9 @@ var Font = function FontClosure() {
|
|
2613
2658
|
width = this.widths[widthCode];
|
2614
2659
|
width = (0, _util.isNum)(width) ? width : this.defaultWidth;
|
2615
2660
|
var vmetric = this.vmetrics && this.vmetrics[widthCode];
|
2616
|
-
|
2661
|
+
let unicode = this.toUnicode.get(charcode) || this.fallbackToUnicode.get(charcode) || charcode;
|
2617
2662
|
|
2618
|
-
if (typeof unicode ===
|
2663
|
+
if (typeof unicode === "number") {
|
2619
2664
|
unicode = String.fromCharCode(unicode);
|
2620
2665
|
}
|
2621
2666
|
|
@@ -2623,6 +2668,12 @@ var Font = function FontClosure() {
|
|
2623
2668
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
2624
2669
|
|
2625
2670
|
if (this.missingFile) {
|
2671
|
+
const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
|
2672
|
+
|
2673
|
+
if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
|
2674
|
+
fontCharCode = 0x20;
|
2675
|
+
}
|
2676
|
+
|
2626
2677
|
fontCharCode = (0, _unicode.mapSpecialUnicodeValues)(fontCharCode);
|
2627
2678
|
}
|
2628
2679
|
|
@@ -2642,7 +2693,7 @@ var Font = function FontClosure() {
|
|
2642
2693
|
};
|
2643
2694
|
}
|
2644
2695
|
|
2645
|
-
var fontChar = typeof fontCharCode ===
|
2696
|
+
var fontChar = typeof fontCharCode === "number" ? String.fromCodePoint(fontCharCode) : "";
|
2646
2697
|
var glyph = this.glyphCache[charcode];
|
2647
2698
|
|
2648
2699
|
if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
|
@@ -2709,7 +2760,7 @@ exports.Font = Font;
|
|
2709
2760
|
var ErrorFont = function ErrorFontClosure() {
|
2710
2761
|
function ErrorFont(error) {
|
2711
2762
|
this.error = error;
|
2712
|
-
this.loadedName =
|
2763
|
+
this.loadedName = "g_font_error";
|
2713
2764
|
this.missingFile = true;
|
2714
2765
|
}
|
2715
2766
|
|
@@ -2813,7 +2864,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2813
2864
|
if (j >= signatureLength) {
|
2814
2865
|
i += j;
|
2815
2866
|
|
2816
|
-
while (i < streamBytesLength && (0,
|
2867
|
+
while (i < streamBytesLength && (0, _core_utils.isWhiteSpace)(streamBytes[i])) {
|
2817
2868
|
i++;
|
2818
2869
|
}
|
2819
2870
|
|
@@ -2825,7 +2876,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2825
2876
|
}
|
2826
2877
|
|
2827
2878
|
return {
|
2828
|
-
found
|
2879
|
+
found,
|
2829
2880
|
length: i
|
2830
2881
|
};
|
2831
2882
|
}
|
@@ -2943,7 +2994,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2943
2994
|
},
|
2944
2995
|
|
2945
2996
|
getCharset: function Type1Font_getCharset() {
|
2946
|
-
var charset = [
|
2997
|
+
var charset = [".notdef"];
|
2947
2998
|
var charstrings = this.charstrings;
|
2948
2999
|
|
2949
3000
|
for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -2954,7 +3005,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2954
3005
|
},
|
2955
3006
|
getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
|
2956
3007
|
var charstrings = this.charstrings;
|
2957
|
-
var glyphNames = [
|
3008
|
+
var glyphNames = [".notdef"],
|
2958
3009
|
glyphId;
|
2959
3010
|
|
2960
3011
|
for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -3028,7 +3079,7 @@ var Type1Font = function Type1FontClosure() {
|
|
3028
3079
|
var i;
|
3029
3080
|
|
3030
3081
|
for (i = 0; i < bias; i++) {
|
3031
|
-
type2Subrs.push([
|
3082
|
+
type2Subrs.push([0x0b]);
|
3032
3083
|
}
|
3033
3084
|
|
3034
3085
|
for (i = 0; i < count; i++) {
|
@@ -3042,34 +3093,34 @@ var Type1Font = function Type1FontClosure() {
|
|
3042
3093
|
cff.header = new _cff_parser.CFFHeader(1, 0, 4, 4);
|
3043
3094
|
cff.names = [name];
|
3044
3095
|
var topDict = new _cff_parser.CFFTopDict();
|
3045
|
-
topDict.setByName(
|
3046
|
-
topDict.setByName(
|
3047
|
-
topDict.setByName(
|
3048
|
-
topDict.setByName(
|
3049
|
-
topDict.setByName(
|
3050
|
-
topDict.setByName(
|
3051
|
-
topDict.setByName(
|
3052
|
-
topDict.setByName(
|
3053
|
-
topDict.setByName(
|
3054
|
-
topDict.setByName(
|
3055
|
-
topDict.setByName(
|
3096
|
+
topDict.setByName("version", 391);
|
3097
|
+
topDict.setByName("Notice", 392);
|
3098
|
+
topDict.setByName("FullName", 393);
|
3099
|
+
topDict.setByName("FamilyName", 394);
|
3100
|
+
topDict.setByName("Weight", 395);
|
3101
|
+
topDict.setByName("Encoding", null);
|
3102
|
+
topDict.setByName("FontMatrix", properties.fontMatrix);
|
3103
|
+
topDict.setByName("FontBBox", properties.bbox);
|
3104
|
+
topDict.setByName("charset", null);
|
3105
|
+
topDict.setByName("CharStrings", null);
|
3106
|
+
topDict.setByName("Private", null);
|
3056
3107
|
cff.topDict = topDict;
|
3057
3108
|
var strings = new _cff_parser.CFFStrings();
|
3058
|
-
strings.add(
|
3059
|
-
strings.add(
|
3109
|
+
strings.add("Version 0.11");
|
3110
|
+
strings.add("See original notice");
|
3060
3111
|
strings.add(name);
|
3061
3112
|
strings.add(name);
|
3062
|
-
strings.add(
|
3113
|
+
strings.add("Medium");
|
3063
3114
|
cff.strings = strings;
|
3064
3115
|
cff.globalSubrIndex = new _cff_parser.CFFIndex();
|
3065
3116
|
var count = glyphs.length;
|
3066
|
-
var charsetArray = [
|
3117
|
+
var charsetArray = [".notdef"];
|
3067
3118
|
var i, ii;
|
3068
3119
|
|
3069
3120
|
for (i = 0; i < count; i++) {
|
3070
|
-
|
3121
|
+
const glyphName = charstrings[i].glyphName;
|
3071
3122
|
|
3072
|
-
|
3123
|
+
const index = _cff_parser.CFFStandardStrings.indexOf(glyphName);
|
3073
3124
|
|
3074
3125
|
if (index === -1) {
|
3075
3126
|
strings.add(glyphName);
|
@@ -3080,7 +3131,7 @@ var Type1Font = function Type1FontClosure() {
|
|
3080
3131
|
|
3081
3132
|
cff.charset = new _cff_parser.CFFCharset(false, 0, charsetArray);
|
3082
3133
|
var charStringsIndex = new _cff_parser.CFFIndex();
|
3083
|
-
charStringsIndex.add([
|
3134
|
+
charStringsIndex.add([0x8b, 0x0e]);
|
3084
3135
|
|
3085
3136
|
for (i = 0; i < count; i++) {
|
3086
3137
|
charStringsIndex.add(glyphs[i]);
|
@@ -3088,8 +3139,8 @@ var Type1Font = function Type1FontClosure() {
|
|
3088
3139
|
|
3089
3140
|
cff.charStrings = charStringsIndex;
|
3090
3141
|
var privateDict = new _cff_parser.CFFPrivateDict();
|
3091
|
-
privateDict.setByName(
|
3092
|
-
var fields = [
|
3142
|
+
privateDict.setByName("Subrs", null);
|
3143
|
+
var fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"];
|
3093
3144
|
|
3094
3145
|
for (i = 0, ii = fields.length; i < ii; i++) {
|
3095
3146
|
var field = fields[i];
|
@@ -3136,7 +3187,7 @@ var CFFFont = function CFFFontClosure() {
|
|
3136
3187
|
try {
|
3137
3188
|
this.data = compiler.compile();
|
3138
3189
|
} catch (e) {
|
3139
|
-
(0, _util.warn)(
|
3190
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
3140
3191
|
this.data = file;
|
3141
3192
|
}
|
3142
3193
|
}
|
@@ -3158,7 +3209,7 @@ var CFFFont = function CFFFontClosure() {
|
|
3158
3209
|
|
3159
3210
|
if (properties.composite) {
|
3160
3211
|
charCodeToGlyphId = Object.create(null);
|
3161
|
-
|
3212
|
+
let charCode;
|
3162
3213
|
|
3163
3214
|
if (cff.isCIDFont) {
|
3164
3215
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|