pdfjs-dist 2.1.266 → 2.5.207
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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- 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 +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- 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 +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- 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 +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- 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 +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- 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 +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
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,38 +27,34 @@ 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
|
48
|
+
var _stream = require("./stream.js");
|
49
49
|
|
50
|
-
|
50
|
+
var _type1_parser = require("./type1_parser.js");
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
function _iterableToArrayLimit(arr, i) { 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; }
|
55
|
-
|
56
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
57
|
-
|
58
|
-
var PRIVATE_USE_AREAS = [[0xE000, 0xF8FF], [0x100000, 0x10FFFD]];
|
52
|
+
const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
|
59
53
|
var PDF_GLYPH_SPACE_UNITS = 1000;
|
60
54
|
var SEAC_ANALYSIS_ENABLED = true;
|
61
55
|
exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
|
56
|
+
const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "fontType", "isMonospace", "isSerifFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "type", "vertical"];
|
57
|
+
const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"];
|
62
58
|
var FontFlags = {
|
63
59
|
FixedPitch: 1,
|
64
60
|
Serif: 2,
|
@@ -71,7 +67,7 @@ var FontFlags = {
|
|
71
67
|
ForceBold: 262144
|
72
68
|
};
|
73
69
|
exports.FontFlags = FontFlags;
|
74
|
-
var MacStandardGlyphOrdering = [
|
70
|
+
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"];
|
75
71
|
|
76
72
|
function adjustWidths(properties) {
|
77
73
|
if (!properties.fontMatrix) {
|
@@ -126,25 +122,25 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|
126
122
|
|
127
123
|
function getFontType(type, subtype) {
|
128
124
|
switch (type) {
|
129
|
-
case
|
130
|
-
return subtype ===
|
125
|
+
case "Type1":
|
126
|
+
return subtype === "Type1C" ? _util.FontType.TYPE1C : _util.FontType.TYPE1;
|
131
127
|
|
132
|
-
case
|
133
|
-
return subtype ===
|
128
|
+
case "CIDFontType0":
|
129
|
+
return subtype === "CIDFontType0C" ? _util.FontType.CIDFONTTYPE0C : _util.FontType.CIDFONTTYPE0;
|
134
130
|
|
135
|
-
case
|
131
|
+
case "OpenType":
|
136
132
|
return _util.FontType.OPENTYPE;
|
137
133
|
|
138
|
-
case
|
134
|
+
case "TrueType":
|
139
135
|
return _util.FontType.TRUETYPE;
|
140
136
|
|
141
|
-
case
|
137
|
+
case "CIDFontType2":
|
142
138
|
return _util.FontType.CIDFONTTYPE2;
|
143
139
|
|
144
|
-
case
|
140
|
+
case "MMType1":
|
145
141
|
return _util.FontType.MMTYPE1;
|
146
142
|
|
147
|
-
case
|
143
|
+
case "Type0":
|
148
144
|
return _util.FontType.TYPE0;
|
149
145
|
|
150
146
|
default:
|
@@ -167,7 +163,7 @@ function recoverGlyphName(name, glyphsUnicodeMap) {
|
|
167
163
|
}
|
168
164
|
}
|
169
165
|
|
170
|
-
(0, _util.info)(
|
166
|
+
(0, _util.info)("Unable to recover a standard glyph name for: " + name);
|
171
167
|
return name;
|
172
168
|
}
|
173
169
|
|
@@ -191,8 +187,7 @@ var Glyph = function GlyphClosure() {
|
|
191
187
|
}();
|
192
188
|
|
193
189
|
var ToUnicodeMap = function ToUnicodeMapClosure() {
|
194
|
-
function ToUnicodeMap() {
|
195
|
-
var cmap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
190
|
+
function ToUnicodeMap(cmap = []) {
|
196
191
|
this._map = cmap;
|
197
192
|
}
|
198
193
|
|
@@ -201,25 +196,28 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
201
196
|
return this._map.length;
|
202
197
|
},
|
203
198
|
|
204
|
-
forEach
|
199
|
+
forEach(callback) {
|
205
200
|
for (var charCode in this._map) {
|
206
201
|
callback(charCode, this._map[charCode].charCodeAt(0));
|
207
202
|
}
|
208
203
|
},
|
209
|
-
|
204
|
+
|
205
|
+
has(i) {
|
210
206
|
return this._map[i] !== undefined;
|
211
207
|
},
|
212
|
-
|
208
|
+
|
209
|
+
get(i) {
|
213
210
|
return this._map[i];
|
214
211
|
},
|
215
|
-
|
216
|
-
|
212
|
+
|
213
|
+
charCodeOf(value) {
|
214
|
+
const map = this._map;
|
217
215
|
|
218
216
|
if (map.length <= 0x10000) {
|
219
217
|
return map.indexOf(value);
|
220
218
|
}
|
221
219
|
|
222
|
-
for (
|
220
|
+
for (const charCode in map) {
|
223
221
|
if (map[charCode] === value) {
|
224
222
|
return charCode | 0;
|
225
223
|
}
|
@@ -227,11 +225,13 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
227
225
|
|
228
226
|
return -1;
|
229
227
|
},
|
230
|
-
|
228
|
+
|
229
|
+
amend(map) {
|
231
230
|
for (var charCode in map) {
|
232
231
|
this._map[charCode] = map[charCode];
|
233
232
|
}
|
234
233
|
}
|
234
|
+
|
235
235
|
};
|
236
236
|
return ToUnicodeMap;
|
237
237
|
}();
|
@@ -249,27 +249,32 @@ var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
|
249
249
|
return this.lastChar + 1 - this.firstChar;
|
250
250
|
},
|
251
251
|
|
252
|
-
forEach
|
252
|
+
forEach(callback) {
|
253
253
|
for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
|
254
254
|
callback(i, i);
|
255
255
|
}
|
256
256
|
},
|
257
|
-
|
257
|
+
|
258
|
+
has(i) {
|
258
259
|
return this.firstChar <= i && i <= this.lastChar;
|
259
260
|
},
|
260
|
-
|
261
|
+
|
262
|
+
get(i) {
|
261
263
|
if (this.firstChar <= i && i <= this.lastChar) {
|
262
264
|
return String.fromCharCode(i);
|
263
265
|
}
|
264
266
|
|
265
267
|
return undefined;
|
266
268
|
},
|
267
|
-
|
269
|
+
|
270
|
+
charCodeOf(v) {
|
268
271
|
return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
|
269
272
|
},
|
270
|
-
|
271
|
-
|
273
|
+
|
274
|
+
amend(map) {
|
275
|
+
(0, _util.unreachable)("Should not call amend()");
|
272
276
|
}
|
277
|
+
|
273
278
|
};
|
274
279
|
return IdentityToUnicodeMap;
|
275
280
|
}();
|
@@ -278,15 +283,15 @@ exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
|
|
278
283
|
|
279
284
|
var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
280
285
|
function writeInt16(dest, offset, num) {
|
281
|
-
dest[offset] = num >> 8 &
|
282
|
-
dest[offset + 1] = num &
|
286
|
+
dest[offset] = num >> 8 & 0xff;
|
287
|
+
dest[offset + 1] = num & 0xff;
|
283
288
|
}
|
284
289
|
|
285
290
|
function writeInt32(dest, offset, num) {
|
286
|
-
dest[offset] = num >> 24 &
|
287
|
-
dest[offset + 1] = num >> 16 &
|
288
|
-
dest[offset + 2] = num >> 8 &
|
289
|
-
dest[offset + 3] = num &
|
291
|
+
dest[offset] = num >> 24 & 0xff;
|
292
|
+
dest[offset + 1] = num >> 16 & 0xff;
|
293
|
+
dest[offset + 2] = num >> 8 & 0xff;
|
294
|
+
dest[offset + 3] = num & 0xff;
|
290
295
|
}
|
291
296
|
|
292
297
|
function writeData(dest, offset, data) {
|
@@ -294,13 +299,13 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
294
299
|
|
295
300
|
if (data instanceof Uint8Array) {
|
296
301
|
dest.set(data, offset);
|
297
|
-
} else if (typeof data ===
|
302
|
+
} else if (typeof data === "string") {
|
298
303
|
for (i = 0, ii = data.length; i < ii; i++) {
|
299
|
-
dest[offset++] = data.charCodeAt(i) &
|
304
|
+
dest[offset++] = data.charCodeAt(i) & 0xff;
|
300
305
|
}
|
301
306
|
} else {
|
302
307
|
for (i = 0, ii = data.length; i < ii; i++) {
|
303
|
-
dest[offset++] = data[i] &
|
308
|
+
dest[offset++] = data[i] & 0xff;
|
304
309
|
}
|
305
310
|
}
|
306
311
|
}
|
@@ -354,14 +359,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
354
359
|
writeData(file, tableOffsets[i], table);
|
355
360
|
}
|
356
361
|
|
357
|
-
if (sfnt ===
|
362
|
+
if (sfnt === "true") {
|
358
363
|
sfnt = (0, _util.string32)(0x00010000);
|
359
364
|
}
|
360
365
|
|
361
|
-
file[0] = sfnt.charCodeAt(0) &
|
362
|
-
file[1] = sfnt.charCodeAt(1) &
|
363
|
-
file[2] = sfnt.charCodeAt(2) &
|
364
|
-
file[3] = sfnt.charCodeAt(3) &
|
366
|
+
file[0] = sfnt.charCodeAt(0) & 0xff;
|
367
|
+
file[1] = sfnt.charCodeAt(1) & 0xff;
|
368
|
+
file[2] = sfnt.charCodeAt(2) & 0xff;
|
369
|
+
file[3] = sfnt.charCodeAt(3) & 0xff;
|
365
370
|
writeInt16(file, 4, numTables);
|
366
371
|
var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
|
367
372
|
writeInt16(file, 6, searchParams.range);
|
@@ -371,14 +376,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
371
376
|
|
372
377
|
for (i = 0; i < numTables; i++) {
|
373
378
|
tableName = tablesNames[i];
|
374
|
-
file[offset] = tableName.charCodeAt(0) &
|
375
|
-
file[offset + 1] = tableName.charCodeAt(1) &
|
376
|
-
file[offset + 2] = tableName.charCodeAt(2) &
|
377
|
-
file[offset + 3] = tableName.charCodeAt(3) &
|
379
|
+
file[offset] = tableName.charCodeAt(0) & 0xff;
|
380
|
+
file[offset + 1] = tableName.charCodeAt(1) & 0xff;
|
381
|
+
file[offset + 2] = tableName.charCodeAt(2) & 0xff;
|
382
|
+
file[offset + 3] = tableName.charCodeAt(3) & 0xff;
|
378
383
|
var checksum = 0;
|
379
384
|
|
380
385
|
for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
381
|
-
var quad = (0,
|
386
|
+
var quad = (0, _core_utils.readUint32)(file, j);
|
382
387
|
checksum = checksum + quad >>> 0;
|
383
388
|
}
|
384
389
|
|
@@ -392,7 +397,7 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
392
397
|
},
|
393
398
|
addTable: function OpenTypeFileBuilder_addTable(tag, data) {
|
394
399
|
if (tag in this.tables) {
|
395
|
-
throw new Error(
|
400
|
+
throw new Error("Table " + tag + " already exists");
|
396
401
|
}
|
397
402
|
|
398
403
|
this.tables[tag] = data;
|
@@ -407,7 +412,6 @@ var Font = function FontClosure() {
|
|
407
412
|
this.name = name;
|
408
413
|
this.loadedName = properties.loadedName;
|
409
414
|
this.isType3Font = properties.isType3Font;
|
410
|
-
this.sizes = [];
|
411
415
|
this.missingFile = false;
|
412
416
|
this.glyphCache = Object.create(null);
|
413
417
|
this.isSerifFont = !!(properties.flags & FontFlags.Serif);
|
@@ -417,12 +421,19 @@ var Font = function FontClosure() {
|
|
417
421
|
var subtype = properties.subtype;
|
418
422
|
this.type = type;
|
419
423
|
this.subtype = subtype;
|
420
|
-
|
424
|
+
let fallbackName = "sans-serif";
|
425
|
+
|
426
|
+
if (this.isMonospace) {
|
427
|
+
fallbackName = "monospace";
|
428
|
+
} else if (this.isSerifFont) {
|
429
|
+
fallbackName = "serif";
|
430
|
+
}
|
431
|
+
|
432
|
+
this.fallbackName = fallbackName;
|
421
433
|
this.differences = properties.differences;
|
422
434
|
this.widths = properties.widths;
|
423
435
|
this.defaultWidth = properties.defaultWidth;
|
424
436
|
this.composite = properties.composite;
|
425
|
-
this.wideChars = properties.wideChars;
|
426
437
|
this.cMap = properties.cMap;
|
427
438
|
this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
|
428
439
|
this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
|
@@ -433,7 +444,7 @@ var Font = function FontClosure() {
|
|
433
444
|
this.fallbackToUnicode = properties.fallbackToUnicode || new ToUnicodeMap();
|
434
445
|
this.toFontChar = [];
|
435
446
|
|
436
|
-
if (properties.type ===
|
447
|
+
if (properties.type === "Type3") {
|
437
448
|
for (charCode = 0; charCode < 256; charCode++) {
|
438
449
|
this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
|
439
450
|
}
|
@@ -443,7 +454,7 @@ var Font = function FontClosure() {
|
|
443
454
|
}
|
444
455
|
|
445
456
|
this.cidEncoding = properties.cidEncoding;
|
446
|
-
this.vertical = properties.vertical;
|
457
|
+
this.vertical = !!properties.vertical;
|
447
458
|
|
448
459
|
if (this.vertical) {
|
449
460
|
this.vmetrics = properties.vmetrics;
|
@@ -452,54 +463,49 @@ var Font = function FontClosure() {
|
|
452
463
|
|
453
464
|
if (!file || file.isEmpty) {
|
454
465
|
if (file) {
|
455
|
-
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName +
|
466
|
+
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ")");
|
456
467
|
}
|
457
468
|
|
458
469
|
this.fallbackToSystemFont();
|
459
470
|
return;
|
460
471
|
}
|
461
472
|
|
462
|
-
|
463
|
-
|
464
|
-
var _getFontFileType2 = _slicedToArray(_getFontFileType, 2);
|
465
|
-
|
466
|
-
type = _getFontFileType2[0];
|
467
|
-
subtype = _getFontFileType2[1];
|
473
|
+
[type, subtype] = getFontFileType(file, properties);
|
468
474
|
|
469
475
|
if (type !== this.type || subtype !== this.subtype) {
|
470
|
-
(0, _util.info)(
|
476
|
+
(0, _util.info)("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`);
|
471
477
|
}
|
472
478
|
|
473
479
|
try {
|
474
480
|
var data;
|
475
481
|
|
476
482
|
switch (type) {
|
477
|
-
case
|
478
|
-
(0, _util.info)(
|
483
|
+
case "MMType1":
|
484
|
+
(0, _util.info)("MMType1 font (" + name + "), falling back to Type1.");
|
479
485
|
|
480
|
-
case
|
481
|
-
case
|
482
|
-
this.mimetype =
|
483
|
-
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);
|
484
490
|
adjustWidths(properties);
|
485
491
|
data = this.convert(name, cff, properties);
|
486
492
|
break;
|
487
493
|
|
488
|
-
case
|
489
|
-
case
|
490
|
-
case
|
491
|
-
this.mimetype =
|
494
|
+
case "OpenType":
|
495
|
+
case "TrueType":
|
496
|
+
case "CIDFontType2":
|
497
|
+
this.mimetype = "font/opentype";
|
492
498
|
data = this.checkAndRepair(name, file, properties);
|
493
499
|
|
494
500
|
if (this.isOpenType) {
|
495
501
|
adjustWidths(properties);
|
496
|
-
type =
|
502
|
+
type = "OpenType";
|
497
503
|
}
|
498
504
|
|
499
505
|
break;
|
500
506
|
|
501
507
|
default:
|
502
|
-
throw new _util.FormatError(
|
508
|
+
throw new _util.FormatError(`Font ${type} is not supported`);
|
503
509
|
}
|
504
510
|
} catch (e) {
|
505
511
|
(0, _util.warn)(e);
|
@@ -513,7 +519,6 @@ var Font = function FontClosure() {
|
|
513
519
|
this.widths = properties.widths;
|
514
520
|
this.defaultWidth = properties.defaultWidth;
|
515
521
|
this.toUnicode = properties.toUnicode;
|
516
|
-
this.encoding = properties.baseEncoding;
|
517
522
|
this.seacMap = properties.seacMap;
|
518
523
|
}
|
519
524
|
|
@@ -547,23 +552,28 @@ var Font = function FontClosure() {
|
|
547
552
|
}
|
548
553
|
|
549
554
|
function safeString16(value) {
|
550
|
-
|
555
|
+
if (value > 0x7fff) {
|
556
|
+
value = 0x7fff;
|
557
|
+
} else if (value < -0x8000) {
|
558
|
+
value = -0x8000;
|
559
|
+
}
|
560
|
+
|
551
561
|
return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
|
552
562
|
}
|
553
563
|
|
554
564
|
function isTrueTypeFile(file) {
|
555
565
|
var header = file.peekBytes(4);
|
556
|
-
return (0,
|
566
|
+
return (0, _core_utils.readUint32)(header, 0) === 0x00010000 || (0, _util.bytesToString)(header) === "true";
|
557
567
|
}
|
558
568
|
|
559
569
|
function isTrueTypeCollectionFile(file) {
|
560
|
-
|
561
|
-
return (0, _util.bytesToString)(header) ===
|
570
|
+
const header = file.peekBytes(4);
|
571
|
+
return (0, _util.bytesToString)(header) === "ttcf";
|
562
572
|
}
|
563
573
|
|
564
574
|
function isOpenTypeFile(file) {
|
565
575
|
var header = file.peekBytes(4);
|
566
|
-
return (0, _util.bytesToString)(header) ===
|
576
|
+
return (0, _util.bytesToString)(header) === "OTTO";
|
567
577
|
}
|
568
578
|
|
569
579
|
function isType1File(file) {
|
@@ -581,7 +591,7 @@ var Font = function FontClosure() {
|
|
581
591
|
}
|
582
592
|
|
583
593
|
function isCFFFile(file) {
|
584
|
-
|
594
|
+
const header = file.peekBytes(4);
|
585
595
|
|
586
596
|
if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
|
587
597
|
return true;
|
@@ -590,40 +600,41 @@ var Font = function FontClosure() {
|
|
590
600
|
return false;
|
591
601
|
}
|
592
602
|
|
593
|
-
function getFontFileType(file,
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
603
|
+
function getFontFileType(file, {
|
604
|
+
type,
|
605
|
+
subtype,
|
606
|
+
composite
|
607
|
+
}) {
|
608
|
+
let fileType, fileSubtype;
|
598
609
|
|
599
610
|
if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
|
600
611
|
if (composite) {
|
601
|
-
fileType =
|
612
|
+
fileType = "CIDFontType2";
|
602
613
|
} else {
|
603
|
-
fileType =
|
614
|
+
fileType = "TrueType";
|
604
615
|
}
|
605
616
|
} else if (isOpenTypeFile(file)) {
|
606
617
|
if (composite) {
|
607
|
-
fileType =
|
618
|
+
fileType = "CIDFontType2";
|
608
619
|
} else {
|
609
|
-
fileType =
|
620
|
+
fileType = "OpenType";
|
610
621
|
}
|
611
622
|
} else if (isType1File(file)) {
|
612
623
|
if (composite) {
|
613
|
-
fileType =
|
624
|
+
fileType = "CIDFontType0";
|
614
625
|
} else {
|
615
|
-
fileType = type ===
|
626
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
616
627
|
}
|
617
628
|
} else if (isCFFFile(file)) {
|
618
629
|
if (composite) {
|
619
|
-
fileType =
|
620
|
-
fileSubtype =
|
630
|
+
fileType = "CIDFontType0";
|
631
|
+
fileSubtype = "CIDFontType0C";
|
621
632
|
} else {
|
622
|
-
fileType = type ===
|
623
|
-
fileSubtype =
|
633
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
634
|
+
fileSubtype = "Type1C";
|
624
635
|
}
|
625
636
|
} else {
|
626
|
-
(0, _util.warn)(
|
637
|
+
(0, _util.warn)("getFontFileType: Unable to detect correct font file Type/Subtype.");
|
627
638
|
fileType = type;
|
628
639
|
fileSubtype = subtype;
|
629
640
|
}
|
@@ -673,7 +684,7 @@ var Font = function FontClosure() {
|
|
673
684
|
privateUseAreaIndex++;
|
674
685
|
|
675
686
|
if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
|
676
|
-
(0, _util.warn)(
|
687
|
+
(0, _util.warn)("Ran out of space in font private use area.");
|
677
688
|
break;
|
678
689
|
}
|
679
690
|
|
@@ -692,9 +703,9 @@ var Font = function FontClosure() {
|
|
692
703
|
}
|
693
704
|
|
694
705
|
return {
|
695
|
-
toFontChar
|
706
|
+
toFontChar,
|
696
707
|
charCodeToGlyphId: newMap,
|
697
|
-
nextAvailableFontCharCode
|
708
|
+
nextAvailableFontCharCode
|
698
709
|
};
|
699
710
|
}
|
700
711
|
|
@@ -736,7 +747,7 @@ var Font = function FontClosure() {
|
|
736
747
|
++end;
|
737
748
|
++n;
|
738
749
|
|
739
|
-
if (end ===
|
750
|
+
if (end === 0xffff) {
|
740
751
|
break;
|
741
752
|
}
|
742
753
|
}
|
@@ -749,30 +760,30 @@ var Font = function FontClosure() {
|
|
749
760
|
|
750
761
|
function createCmapTable(glyphs, numGlyphs) {
|
751
762
|
var ranges = getRanges(glyphs, numGlyphs);
|
752
|
-
var numTables = ranges[ranges.length - 1][1] >
|
753
|
-
var cmap =
|
763
|
+
var numTables = ranges[ranges.length - 1][1] > 0xffff ? 2 : 1;
|
764
|
+
var cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + (0, _util.string32)(4 + numTables * 8);
|
754
765
|
var i, ii, j, jj;
|
755
766
|
|
756
767
|
for (i = ranges.length - 1; i >= 0; --i) {
|
757
|
-
if (ranges[i][0] <=
|
768
|
+
if (ranges[i][0] <= 0xffff) {
|
758
769
|
break;
|
759
770
|
}
|
760
771
|
}
|
761
772
|
|
762
773
|
var bmpLength = i + 1;
|
763
774
|
|
764
|
-
if (ranges[i][0] <
|
765
|
-
ranges[i][1] =
|
775
|
+
if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
|
776
|
+
ranges[i][1] = 0xfffe;
|
766
777
|
}
|
767
778
|
|
768
|
-
var trailingRangesCount = ranges[i][1] <
|
779
|
+
var trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
|
769
780
|
var segCount = bmpLength + trailingRangesCount;
|
770
781
|
var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
|
771
|
-
var startCount =
|
772
|
-
var endCount =
|
773
|
-
var idDeltas =
|
774
|
-
var idRangeOffsets =
|
775
|
-
var glyphsIds =
|
782
|
+
var startCount = "";
|
783
|
+
var endCount = "";
|
784
|
+
var idDeltas = "";
|
785
|
+
var idRangeOffsets = "";
|
786
|
+
var glyphsIds = "";
|
776
787
|
var bias = 0;
|
777
788
|
var range, start, end, codes;
|
778
789
|
|
@@ -803,25 +814,25 @@ var Font = function FontClosure() {
|
|
803
814
|
}
|
804
815
|
} else {
|
805
816
|
var startCode = codes[0];
|
806
|
-
idDeltas += string16(startCode - start &
|
817
|
+
idDeltas += string16(startCode - start & 0xffff);
|
807
818
|
idRangeOffsets += string16(0);
|
808
819
|
}
|
809
820
|
}
|
810
821
|
|
811
822
|
if (trailingRangesCount > 0) {
|
812
|
-
endCount +=
|
813
|
-
startCount +=
|
814
|
-
idDeltas +=
|
815
|
-
idRangeOffsets +=
|
823
|
+
endCount += "\xFF\xFF";
|
824
|
+
startCount += "\xFF\xFF";
|
825
|
+
idDeltas += "\x00\x01";
|
826
|
+
idRangeOffsets += "\x00\x00";
|
816
827
|
}
|
817
828
|
|
818
|
-
var format314 =
|
819
|
-
var format31012 =
|
820
|
-
var header31012 =
|
829
|
+
var format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds;
|
830
|
+
var format31012 = "";
|
831
|
+
var header31012 = "";
|
821
832
|
|
822
833
|
if (numTables > 1) {
|
823
|
-
cmap +=
|
824
|
-
format31012 =
|
834
|
+
cmap += "\x00\x03" + "\x00\x0A" + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);
|
835
|
+
format31012 = "";
|
825
836
|
|
826
837
|
for (i = 0, ii = ranges.length; i < ii; i++) {
|
827
838
|
range = ranges[i];
|
@@ -841,31 +852,31 @@ var Font = function FontClosure() {
|
|
841
852
|
format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);
|
842
853
|
}
|
843
854
|
|
844
|
-
header31012 =
|
855
|
+
header31012 = "\x00\x0C" + "\x00\x00" + (0, _util.string32)(format31012.length + 16) + "\x00\x00\x00\x00" + (0, _util.string32)(format31012.length / 12);
|
845
856
|
}
|
846
857
|
|
847
|
-
return cmap +
|
858
|
+
return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
|
848
859
|
}
|
849
860
|
|
850
|
-
function validateOS2Table(os2) {
|
851
|
-
|
852
|
-
var version =
|
853
|
-
|
854
|
-
var selection =
|
861
|
+
function validateOS2Table(os2, file) {
|
862
|
+
file.pos = (file.start || 0) + os2.offset;
|
863
|
+
var version = file.getUint16();
|
864
|
+
file.skip(60);
|
865
|
+
var selection = file.getUint16();
|
855
866
|
|
856
867
|
if (version < 4 && selection & 0x0300) {
|
857
868
|
return false;
|
858
869
|
}
|
859
870
|
|
860
|
-
var firstChar =
|
861
|
-
var lastChar =
|
871
|
+
var firstChar = file.getUint16();
|
872
|
+
var lastChar = file.getUint16();
|
862
873
|
|
863
874
|
if (firstChar > lastChar) {
|
864
875
|
return false;
|
865
876
|
}
|
866
877
|
|
867
|
-
|
868
|
-
var usWinAscent =
|
878
|
+
file.skip(6);
|
879
|
+
var usWinAscent = file.getUint16();
|
869
880
|
|
870
881
|
if (usWinAscent === 0) {
|
871
882
|
return false;
|
@@ -913,12 +924,12 @@ var Font = function FontClosure() {
|
|
913
924
|
} else if (position < 123) {
|
914
925
|
ulUnicodeRange4 |= 1 << position - 96;
|
915
926
|
} else {
|
916
|
-
throw new _util.FormatError(
|
927
|
+
throw new _util.FormatError("Unicode ranges Bits > 123 are reserved for internal usage");
|
917
928
|
}
|
918
929
|
}
|
919
930
|
|
920
|
-
if (lastCharIndex >
|
921
|
-
lastCharIndex =
|
931
|
+
if (lastCharIndex > 0xffff) {
|
932
|
+
lastCharIndex = 0xffff;
|
922
933
|
}
|
923
934
|
} else {
|
924
935
|
firstCharIndex = 0;
|
@@ -937,12 +948,12 @@ var Font = function FontClosure() {
|
|
937
948
|
|
938
949
|
var winAscent = override.yMax || typoAscent;
|
939
950
|
var winDescent = -override.yMin || -typoDescent;
|
940
|
-
return
|
951
|
+
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";
|
941
952
|
}
|
942
953
|
|
943
954
|
function createPostTable(properties) {
|
944
|
-
var angle = Math.floor(properties.italicAngle *
|
945
|
-
return
|
955
|
+
var angle = Math.floor(properties.italicAngle * 2 ** 16);
|
956
|
+
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";
|
946
957
|
}
|
947
958
|
|
948
959
|
function createNameTable(name, proto) {
|
@@ -950,7 +961,7 @@ var Font = function FontClosure() {
|
|
950
961
|
proto = [[], []];
|
951
962
|
}
|
952
963
|
|
953
|
-
var strings = [proto[0][0] ||
|
964
|
+
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"];
|
954
965
|
var stringsUnicode = [];
|
955
966
|
var i, ii, j, jj, str;
|
956
967
|
|
@@ -962,15 +973,15 @@ var Font = function FontClosure() {
|
|
962
973
|
strBufUnicode.push(string16(str.charCodeAt(j)));
|
963
974
|
}
|
964
975
|
|
965
|
-
stringsUnicode.push(strBufUnicode.join(
|
976
|
+
stringsUnicode.push(strBufUnicode.join(""));
|
966
977
|
}
|
967
978
|
|
968
979
|
var names = [strings, stringsUnicode];
|
969
|
-
var platforms = [
|
970
|
-
var encodings = [
|
971
|
-
var languages = [
|
980
|
+
var platforms = ["\x00\x01", "\x00\x03"];
|
981
|
+
var encodings = ["\x00\x00", "\x00\x01"];
|
982
|
+
var languages = ["\x00\x00", "\x04\x09"];
|
972
983
|
var namesRecordCount = strings.length * platforms.length;
|
973
|
-
var nameTable =
|
984
|
+
var nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
|
974
985
|
var strOffset = 0;
|
975
986
|
|
976
987
|
for (i = 0, ii = platforms.length; i < ii; i++) {
|
@@ -984,7 +995,7 @@ var Font = function FontClosure() {
|
|
984
995
|
}
|
985
996
|
}
|
986
997
|
|
987
|
-
nameTable += strings.join(
|
998
|
+
nameTable += strings.join("") + stringsUnicode.join("");
|
988
999
|
return nameTable;
|
989
1000
|
}
|
990
1001
|
|
@@ -992,35 +1003,36 @@ var Font = function FontClosure() {
|
|
992
1003
|
name: null,
|
993
1004
|
font: null,
|
994
1005
|
mimetype: null,
|
995
|
-
encoding: null,
|
996
1006
|
disableFontFace: false,
|
997
1007
|
|
998
1008
|
get renderer() {
|
999
1009
|
var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
|
1000
1010
|
|
1001
|
-
return (0, _util.shadow)(this,
|
1011
|
+
return (0, _util.shadow)(this, "renderer", renderer);
|
1002
1012
|
},
|
1003
1013
|
|
1004
|
-
exportData
|
1005
|
-
|
1014
|
+
exportData(extraProperties = false) {
|
1015
|
+
const exportDataProperties = extraProperties ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] : EXPORT_DATA_PROPERTIES;
|
1016
|
+
const data = Object.create(null);
|
1017
|
+
let property, value;
|
1018
|
+
|
1019
|
+
for (property of exportDataProperties) {
|
1020
|
+
value = this[property];
|
1006
1021
|
|
1007
|
-
|
1008
|
-
|
1009
|
-
data[i] = this[i];
|
1022
|
+
if (value !== undefined) {
|
1023
|
+
data[property] = value;
|
1010
1024
|
}
|
1011
1025
|
}
|
1012
1026
|
|
1013
1027
|
return data;
|
1014
1028
|
},
|
1015
|
-
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
1016
|
-
var _this = this;
|
1017
1029
|
|
1030
|
+
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
1018
1031
|
this.missingFile = true;
|
1019
|
-
var charCode, unicode;
|
1020
1032
|
var name = this.name;
|
1021
1033
|
var type = this.type;
|
1022
1034
|
var subtype = this.subtype;
|
1023
|
-
|
1035
|
+
let fontName = name.replace(/[,_]/g, "-").replace(/\s/g, "");
|
1024
1036
|
var stdFontMap = (0, _standard_fonts.getStdFontMap)(),
|
1025
1037
|
nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();
|
1026
1038
|
var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
|
@@ -1030,24 +1042,24 @@ var Font = function FontClosure() {
|
|
1030
1042
|
this.black = name.search(/Black/g) !== -1;
|
1031
1043
|
this.remeasure = Object.keys(this.widths).length > 0;
|
1032
1044
|
|
1033
|
-
if (isStandardFont && type ===
|
1034
|
-
|
1035
|
-
|
1045
|
+
if (isStandardFont && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
|
1046
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1047
|
+
const map = [];
|
1036
1048
|
|
1037
|
-
for (charCode in GlyphMapForStandardFonts) {
|
1049
|
+
for (const charCode in GlyphMapForStandardFonts) {
|
1038
1050
|
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
1039
1051
|
}
|
1040
1052
|
|
1041
1053
|
if (/Arial-?Black/i.test(name)) {
|
1042
1054
|
var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();
|
1043
1055
|
|
1044
|
-
for (charCode in SupplementalGlyphMapForArialBlack) {
|
1056
|
+
for (const charCode in SupplementalGlyphMapForArialBlack) {
|
1045
1057
|
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
|
1046
1058
|
}
|
1047
1059
|
} else if (/Calibri/i.test(name)) {
|
1048
|
-
|
1060
|
+
const SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
|
1049
1061
|
|
1050
|
-
for (charCode in SupplementalGlyphMapForCalibri) {
|
1062
|
+
for (const charCode in SupplementalGlyphMapForCalibri) {
|
1051
1063
|
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
|
1052
1064
|
}
|
1053
1065
|
}
|
@@ -1066,47 +1078,60 @@ var Font = function FontClosure() {
|
|
1066
1078
|
this.toFontChar = buildToFontChar(_encodings.SymbolSetEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1067
1079
|
} else if (/Dingbats/i.test(fontName)) {
|
1068
1080
|
if (/Wingdings/i.test(name)) {
|
1069
|
-
(0, _util.warn)(
|
1081
|
+
(0, _util.warn)("Non-embedded Wingdings font, falling back to ZapfDingbats.");
|
1070
1082
|
}
|
1071
1083
|
|
1072
1084
|
this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);
|
1073
1085
|
} else if (isStandardFont) {
|
1074
1086
|
this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1075
1087
|
} else {
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1088
|
+
const glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
1089
|
+
const map = [];
|
1090
|
+
this.toUnicode.forEach((charCode, unicodeCharCode) => {
|
1091
|
+
if (!this.composite) {
|
1092
|
+
var glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
|
1093
|
+
const unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
1081
1094
|
|
1082
1095
|
if (unicode !== -1) {
|
1083
1096
|
unicodeCharCode = unicode;
|
1084
1097
|
}
|
1085
1098
|
}
|
1086
1099
|
|
1087
|
-
|
1100
|
+
map[+charCode] = unicodeCharCode;
|
1088
1101
|
});
|
1102
|
+
|
1103
|
+
if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
|
1104
|
+
if (/Verdana/i.test(name)) {
|
1105
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1106
|
+
|
1107
|
+
for (const charCode in GlyphMapForStandardFonts) {
|
1108
|
+
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
|
1113
|
+
this.toFontChar = map;
|
1089
1114
|
}
|
1090
1115
|
|
1091
|
-
this.loadedName = fontName.split(
|
1116
|
+
this.loadedName = fontName.split("-")[0];
|
1092
1117
|
this.fontType = getFontType(type, subtype);
|
1093
1118
|
},
|
1094
1119
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
1095
|
-
|
1120
|
+
const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
|
1096
1121
|
|
1097
1122
|
function readTables(file, numTables) {
|
1098
|
-
|
1099
|
-
tables[
|
1100
|
-
tables
|
1101
|
-
tables
|
1102
|
-
tables
|
1103
|
-
tables
|
1104
|
-
tables
|
1105
|
-
tables
|
1106
|
-
tables
|
1107
|
-
|
1108
|
-
for (
|
1109
|
-
|
1123
|
+
const tables = Object.create(null);
|
1124
|
+
tables["OS/2"] = null;
|
1125
|
+
tables.cmap = null;
|
1126
|
+
tables.head = null;
|
1127
|
+
tables.hhea = null;
|
1128
|
+
tables.hmtx = null;
|
1129
|
+
tables.maxp = null;
|
1130
|
+
tables.name = null;
|
1131
|
+
tables.post = null;
|
1132
|
+
|
1133
|
+
for (let i = 0; i < numTables; i++) {
|
1134
|
+
const table = readTableEntry(file);
|
1110
1135
|
|
1111
1136
|
if (!VALID_TABLES.includes(table.tag)) {
|
1112
1137
|
continue;
|
@@ -1133,17 +1158,17 @@ var Font = function FontClosure() {
|
|
1133
1158
|
var data = file.getBytes(length);
|
1134
1159
|
file.pos = previousPosition;
|
1135
1160
|
|
1136
|
-
if (tag ===
|
1161
|
+
if (tag === "head") {
|
1137
1162
|
data[8] = data[9] = data[10] = data[11] = 0;
|
1138
1163
|
data[17] |= 0x20;
|
1139
1164
|
}
|
1140
1165
|
|
1141
1166
|
return {
|
1142
|
-
tag
|
1143
|
-
checksum
|
1144
|
-
length
|
1145
|
-
offset
|
1146
|
-
data
|
1167
|
+
tag,
|
1168
|
+
checksum,
|
1169
|
+
length,
|
1170
|
+
offset,
|
1171
|
+
data
|
1147
1172
|
};
|
1148
1173
|
}
|
1149
1174
|
|
@@ -1158,23 +1183,23 @@ var Font = function FontClosure() {
|
|
1158
1183
|
}
|
1159
1184
|
|
1160
1185
|
function readTrueTypeCollectionHeader(ttc) {
|
1161
|
-
|
1162
|
-
(0, _util.assert)(ttcTag ===
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
for (
|
1186
|
+
const ttcTag = (0, _util.bytesToString)(ttc.getBytes(4));
|
1187
|
+
(0, _util.assert)(ttcTag === "ttcf", "Must be a TrueType Collection font.");
|
1188
|
+
const majorVersion = ttc.getUint16();
|
1189
|
+
const minorVersion = ttc.getUint16();
|
1190
|
+
const numFonts = ttc.getInt32() >>> 0;
|
1191
|
+
const offsetTable = [];
|
1192
|
+
|
1193
|
+
for (let i = 0; i < numFonts; i++) {
|
1169
1194
|
offsetTable.push(ttc.getInt32() >>> 0);
|
1170
1195
|
}
|
1171
1196
|
|
1172
|
-
|
1173
|
-
ttcTag
|
1174
|
-
majorVersion
|
1175
|
-
minorVersion
|
1176
|
-
numFonts
|
1177
|
-
offsetTable
|
1197
|
+
const header = {
|
1198
|
+
ttcTag,
|
1199
|
+
majorVersion,
|
1200
|
+
minorVersion,
|
1201
|
+
numFonts,
|
1202
|
+
offsetTable
|
1178
1203
|
};
|
1179
1204
|
|
1180
1205
|
switch (majorVersion) {
|
@@ -1188,30 +1213,31 @@ var Font = function FontClosure() {
|
|
1188
1213
|
return header;
|
1189
1214
|
}
|
1190
1215
|
|
1191
|
-
throw new _util.FormatError(
|
1216
|
+
throw new _util.FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
|
1192
1217
|
}
|
1193
1218
|
|
1194
1219
|
function readTrueTypeCollectionData(ttc, fontName) {
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1220
|
+
const {
|
1221
|
+
numFonts,
|
1222
|
+
offsetTable
|
1223
|
+
} = readTrueTypeCollectionHeader(ttc);
|
1198
1224
|
|
1199
|
-
for (
|
1225
|
+
for (let i = 0; i < numFonts; i++) {
|
1200
1226
|
ttc.pos = (ttc.start || 0) + offsetTable[i];
|
1201
|
-
|
1202
|
-
|
1227
|
+
const potentialHeader = readOpenTypeHeader(ttc);
|
1228
|
+
const potentialTables = readTables(ttc, potentialHeader.numTables);
|
1203
1229
|
|
1204
|
-
if (!potentialTables
|
1230
|
+
if (!potentialTables.name) {
|
1205
1231
|
throw new _util.FormatError('TrueType Collection font must contain a "name" table.');
|
1206
1232
|
}
|
1207
1233
|
|
1208
|
-
|
1234
|
+
const nameTable = readNameTable(potentialTables.name);
|
1209
1235
|
|
1210
|
-
for (
|
1211
|
-
for (
|
1212
|
-
|
1236
|
+
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
1237
|
+
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
1238
|
+
const nameEntry = nameTable[j][k];
|
1213
1239
|
|
1214
|
-
if (nameEntry && nameEntry.replace(/\s/g,
|
1240
|
+
if (nameEntry && nameEntry.replace(/\s/g, "") === fontName) {
|
1215
1241
|
return {
|
1216
1242
|
header: potentialHeader,
|
1217
1243
|
tables: potentialTables
|
@@ -1221,12 +1247,12 @@ var Font = function FontClosure() {
|
|
1221
1247
|
}
|
1222
1248
|
}
|
1223
1249
|
|
1224
|
-
throw new _util.FormatError(
|
1250
|
+
throw new _util.FormatError(`TrueType Collection does not contain "${fontName}" font.`);
|
1225
1251
|
}
|
1226
1252
|
|
1227
|
-
function readCmapTable(cmap,
|
1253
|
+
function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
|
1228
1254
|
if (!cmap) {
|
1229
|
-
(0, _util.warn)(
|
1255
|
+
(0, _util.warn)("No cmap table available.");
|
1230
1256
|
return {
|
1231
1257
|
platformId: -1,
|
1232
1258
|
encodingId: -1,
|
@@ -1236,17 +1262,17 @@ var Font = function FontClosure() {
|
|
1236
1262
|
}
|
1237
1263
|
|
1238
1264
|
var segment;
|
1239
|
-
var start = (
|
1240
|
-
|
1241
|
-
|
1242
|
-
var numTables =
|
1265
|
+
var start = (file.start ? file.start : 0) + cmap.offset;
|
1266
|
+
file.pos = start;
|
1267
|
+
file.skip(2);
|
1268
|
+
var numTables = file.getUint16();
|
1243
1269
|
var potentialTable;
|
1244
1270
|
var canBreak = false;
|
1245
1271
|
|
1246
1272
|
for (var i = 0; i < numTables; i++) {
|
1247
|
-
var platformId =
|
1248
|
-
var encodingId =
|
1249
|
-
var offset =
|
1273
|
+
var platformId = file.getUint16();
|
1274
|
+
var encodingId = file.getUint16();
|
1275
|
+
var offset = file.getInt32() >>> 0;
|
1250
1276
|
var useTable = false;
|
1251
1277
|
|
1252
1278
|
if (potentialTable && potentialTable.platformId === platformId && potentialTable.encodingId === encodingId) {
|
@@ -1270,9 +1296,9 @@ var Font = function FontClosure() {
|
|
1270
1296
|
|
1271
1297
|
if (useTable) {
|
1272
1298
|
potentialTable = {
|
1273
|
-
platformId
|
1274
|
-
encodingId
|
1275
|
-
offset
|
1299
|
+
platformId,
|
1300
|
+
encodingId,
|
1301
|
+
offset
|
1276
1302
|
};
|
1277
1303
|
}
|
1278
1304
|
|
@@ -1282,11 +1308,11 @@ var Font = function FontClosure() {
|
|
1282
1308
|
}
|
1283
1309
|
|
1284
1310
|
if (potentialTable) {
|
1285
|
-
|
1311
|
+
file.pos = start + potentialTable.offset;
|
1286
1312
|
}
|
1287
1313
|
|
1288
|
-
if (!potentialTable ||
|
1289
|
-
(0, _util.warn)(
|
1314
|
+
if (!potentialTable || file.peekByte() === -1) {
|
1315
|
+
(0, _util.warn)("Could not find a preferred cmap table.");
|
1290
1316
|
return {
|
1291
1317
|
platformId: -1,
|
1292
1318
|
encodingId: -1,
|
@@ -1295,16 +1321,15 @@ var Font = function FontClosure() {
|
|
1295
1321
|
};
|
1296
1322
|
}
|
1297
1323
|
|
1298
|
-
var format =
|
1299
|
-
|
1300
|
-
font.getUint16();
|
1324
|
+
var format = file.getUint16();
|
1325
|
+
file.skip(2 + 2);
|
1301
1326
|
var hasShortCmap = false;
|
1302
1327
|
var mappings = [];
|
1303
1328
|
var j, glyphId;
|
1304
1329
|
|
1305
1330
|
if (format === 0) {
|
1306
1331
|
for (j = 0; j < 256; j++) {
|
1307
|
-
var index =
|
1332
|
+
var index = file.getByte();
|
1308
1333
|
|
1309
1334
|
if (!index) {
|
1310
1335
|
continue;
|
@@ -1318,32 +1343,32 @@ var Font = function FontClosure() {
|
|
1318
1343
|
|
1319
1344
|
hasShortCmap = true;
|
1320
1345
|
} else if (format === 4) {
|
1321
|
-
var segCount =
|
1322
|
-
|
1346
|
+
var segCount = file.getUint16() >> 1;
|
1347
|
+
file.skip(6);
|
1323
1348
|
var segIndex,
|
1324
1349
|
segments = [];
|
1325
1350
|
|
1326
1351
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1327
1352
|
segments.push({
|
1328
|
-
end:
|
1353
|
+
end: file.getUint16()
|
1329
1354
|
});
|
1330
1355
|
}
|
1331
1356
|
|
1332
|
-
|
1357
|
+
file.skip(2);
|
1333
1358
|
|
1334
1359
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1335
|
-
segments[segIndex].start =
|
1360
|
+
segments[segIndex].start = file.getUint16();
|
1336
1361
|
}
|
1337
1362
|
|
1338
1363
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1339
|
-
segments[segIndex].delta =
|
1364
|
+
segments[segIndex].delta = file.getUint16();
|
1340
1365
|
}
|
1341
1366
|
|
1342
1367
|
var offsetsCount = 0;
|
1343
1368
|
|
1344
1369
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1345
1370
|
segment = segments[segIndex];
|
1346
|
-
var rangeOffset =
|
1371
|
+
var rangeOffset = file.getUint16();
|
1347
1372
|
|
1348
1373
|
if (!rangeOffset) {
|
1349
1374
|
segment.offsetIndex = -1;
|
@@ -1358,7 +1383,7 @@ var Font = function FontClosure() {
|
|
1358
1383
|
var offsets = [];
|
1359
1384
|
|
1360
1385
|
for (j = 0; j < offsetsCount; j++) {
|
1361
|
-
offsets.push(
|
1386
|
+
offsets.push(file.getUint16());
|
1362
1387
|
}
|
1363
1388
|
|
1364
1389
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
@@ -1369,32 +1394,32 @@ var Font = function FontClosure() {
|
|
1369
1394
|
offsetIndex = segment.offsetIndex;
|
1370
1395
|
|
1371
1396
|
for (j = start; j <= end; j++) {
|
1372
|
-
if (j ===
|
1397
|
+
if (j === 0xffff) {
|
1373
1398
|
continue;
|
1374
1399
|
}
|
1375
1400
|
|
1376
1401
|
glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
|
1377
|
-
glyphId = glyphId + delta &
|
1402
|
+
glyphId = glyphId + delta & 0xffff;
|
1378
1403
|
mappings.push({
|
1379
1404
|
charCode: j,
|
1380
|
-
glyphId
|
1405
|
+
glyphId
|
1381
1406
|
});
|
1382
1407
|
}
|
1383
1408
|
}
|
1384
1409
|
} else if (format === 6) {
|
1385
|
-
var firstCode =
|
1386
|
-
var entryCount =
|
1410
|
+
var firstCode = file.getUint16();
|
1411
|
+
var entryCount = file.getUint16();
|
1387
1412
|
|
1388
1413
|
for (j = 0; j < entryCount; j++) {
|
1389
|
-
glyphId =
|
1414
|
+
glyphId = file.getUint16();
|
1390
1415
|
var charCode = firstCode + j;
|
1391
1416
|
mappings.push({
|
1392
|
-
charCode
|
1393
|
-
glyphId
|
1417
|
+
charCode,
|
1418
|
+
glyphId
|
1394
1419
|
});
|
1395
1420
|
}
|
1396
1421
|
} else {
|
1397
|
-
(0, _util.warn)(
|
1422
|
+
(0, _util.warn)("cmap table has unsupported format: " + format);
|
1398
1423
|
return {
|
1399
1424
|
platformId: -1,
|
1400
1425
|
encodingId: -1,
|
@@ -1417,12 +1442,12 @@ var Font = function FontClosure() {
|
|
1417
1442
|
return {
|
1418
1443
|
platformId: potentialTable.platformId,
|
1419
1444
|
encodingId: potentialTable.encodingId,
|
1420
|
-
mappings
|
1421
|
-
hasShortCmap
|
1445
|
+
mappings,
|
1446
|
+
hasShortCmap
|
1422
1447
|
};
|
1423
1448
|
}
|
1424
1449
|
|
1425
|
-
function sanitizeMetrics(
|
1450
|
+
function sanitizeMetrics(file, header, metrics, numGlyphs, dupFirstEntry) {
|
1426
1451
|
if (!header) {
|
1427
1452
|
if (metrics) {
|
1428
1453
|
metrics.data = null;
|
@@ -1431,24 +1456,24 @@ var Font = function FontClosure() {
|
|
1431
1456
|
return;
|
1432
1457
|
}
|
1433
1458
|
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
var numOfMetrics =
|
1459
|
+
file.pos = (file.start ? file.start : 0) + header.offset;
|
1460
|
+
file.pos += 4;
|
1461
|
+
file.pos += 2;
|
1462
|
+
file.pos += 2;
|
1463
|
+
file.pos += 2;
|
1464
|
+
file.pos += 2;
|
1465
|
+
file.pos += 2;
|
1466
|
+
file.pos += 2;
|
1467
|
+
file.pos += 2;
|
1468
|
+
file.pos += 2;
|
1469
|
+
file.pos += 2;
|
1470
|
+
file.pos += 2;
|
1471
|
+
file.pos += 8;
|
1472
|
+
file.pos += 2;
|
1473
|
+
var numOfMetrics = file.getUint16();
|
1449
1474
|
|
1450
1475
|
if (numOfMetrics > numGlyphs) {
|
1451
|
-
(0, _util.info)(
|
1476
|
+
(0, _util.info)("The numOfMetrics (" + numOfMetrics + ") should not be " + "greater than the numGlyphs (" + numGlyphs + ")");
|
1452
1477
|
numOfMetrics = numGlyphs;
|
1453
1478
|
header.data[34] = (numOfMetrics & 0xff00) >> 8;
|
1454
1479
|
header.data[35] = numOfMetrics & 0x00ff;
|
@@ -1460,6 +1485,12 @@ var Font = function FontClosure() {
|
|
1460
1485
|
if (numMissing > 0) {
|
1461
1486
|
var entries = new Uint8Array(metrics.length + numMissing * 2);
|
1462
1487
|
entries.set(metrics.data);
|
1488
|
+
|
1489
|
+
if (dupFirstEntry) {
|
1490
|
+
entries[metrics.length] = metrics.data[2];
|
1491
|
+
entries[metrics.length + 1] = metrics.data[3];
|
1492
|
+
}
|
1493
|
+
|
1463
1494
|
metrics.data = entries;
|
1464
1495
|
}
|
1465
1496
|
}
|
@@ -1505,11 +1536,27 @@ var Font = function FontClosure() {
|
|
1505
1536
|
for (i = 0; i < flagsCount; i++) {
|
1506
1537
|
var flag = glyf[j++];
|
1507
1538
|
|
1508
|
-
if (flag &
|
1509
|
-
glyf[j - 1] = flag &
|
1539
|
+
if (flag & 0xc0) {
|
1540
|
+
glyf[j - 1] = flag & 0x3f;
|
1541
|
+
}
|
1542
|
+
|
1543
|
+
let xLength = 2;
|
1544
|
+
|
1545
|
+
if (flag & 2) {
|
1546
|
+
xLength = 1;
|
1547
|
+
} else if (flag & 16) {
|
1548
|
+
xLength = 0;
|
1510
1549
|
}
|
1511
1550
|
|
1512
|
-
|
1551
|
+
let yLength = 2;
|
1552
|
+
|
1553
|
+
if (flag & 4) {
|
1554
|
+
yLength = 1;
|
1555
|
+
} else if (flag & 32) {
|
1556
|
+
yLength = 0;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
const xyLength = xLength + yLength;
|
1513
1560
|
coordinatesLength += xyLength;
|
1514
1561
|
|
1515
1562
|
if (flag & 8) {
|
@@ -1560,7 +1607,7 @@ var Font = function FontClosure() {
|
|
1560
1607
|
var version = int32(data[0], data[1], data[2], data[3]);
|
1561
1608
|
|
1562
1609
|
if (version >> 16 !== 1) {
|
1563
|
-
(0, _util.info)(
|
1610
|
+
(0, _util.info)("Attempting to fix invalid version in head table: " + version);
|
1564
1611
|
data[0] = 0;
|
1565
1612
|
data[1] = 1;
|
1566
1613
|
data[2] = 0;
|
@@ -1570,7 +1617,7 @@ var Font = function FontClosure() {
|
|
1570
1617
|
var indexToLocFormat = int16(data[50], data[51]);
|
1571
1618
|
|
1572
1619
|
if (indexToLocFormat < 0 || indexToLocFormat > 1) {
|
1573
|
-
(0, _util.info)(
|
1620
|
+
(0, _util.info)("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat);
|
1574
1621
|
var numGlyphsPlusOne = numGlyphs + 1;
|
1575
1622
|
|
1576
1623
|
if (locaLength === numGlyphsPlusOne << 1) {
|
@@ -1580,7 +1627,7 @@ var Font = function FontClosure() {
|
|
1580
1627
|
data[50] = 0;
|
1581
1628
|
data[51] = 1;
|
1582
1629
|
} else {
|
1583
|
-
throw new _util.FormatError(
|
1630
|
+
throw new _util.FormatError("Could not fix indexToLocFormat: " + indexToLocFormat);
|
1584
1631
|
}
|
1585
1632
|
}
|
1586
1633
|
}
|
@@ -1596,10 +1643,10 @@ var Font = function FontClosure() {
|
|
1596
1643
|
};
|
1597
1644
|
|
1598
1645
|
itemEncode = function fontItemEncodeLong(data, offset, value) {
|
1599
|
-
data[offset] = value >>> 24 &
|
1600
|
-
data[offset + 1] = value >> 16 &
|
1601
|
-
data[offset + 2] = value >> 8 &
|
1602
|
-
data[offset + 3] = value &
|
1646
|
+
data[offset] = value >>> 24 & 0xff;
|
1647
|
+
data[offset + 1] = value >> 16 & 0xff;
|
1648
|
+
data[offset + 2] = value >> 8 & 0xff;
|
1649
|
+
data[offset + 3] = value & 0xff;
|
1603
1650
|
};
|
1604
1651
|
} else {
|
1605
1652
|
itemSize = 2;
|
@@ -1609,15 +1656,14 @@ var Font = function FontClosure() {
|
|
1609
1656
|
};
|
1610
1657
|
|
1611
1658
|
itemEncode = function fontItemEncode(data, offset, value) {
|
1612
|
-
data[offset] = value >> 9 &
|
1613
|
-
data[offset + 1] = value >> 1 &
|
1659
|
+
data[offset] = value >> 9 & 0xff;
|
1660
|
+
data[offset + 1] = value >> 1 & 0xff;
|
1614
1661
|
};
|
1615
1662
|
}
|
1616
1663
|
|
1617
1664
|
var numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
|
1618
|
-
var locaData = loca.data;
|
1619
1665
|
var locaDataSize = itemSize * (1 + numGlyphsOut);
|
1620
|
-
locaData = new Uint8Array(locaDataSize);
|
1666
|
+
var locaData = new Uint8Array(locaDataSize);
|
1621
1667
|
locaData.set(loca.data.subarray(0, locaDataSize));
|
1622
1668
|
loca.data = locaData;
|
1623
1669
|
var oldGlyfData = glyf.data;
|
@@ -1685,18 +1731,18 @@ var Font = function FontClosure() {
|
|
1685
1731
|
}
|
1686
1732
|
|
1687
1733
|
return {
|
1688
|
-
missingGlyphs
|
1689
|
-
maxSizeOfInstructions
|
1734
|
+
missingGlyphs,
|
1735
|
+
maxSizeOfInstructions
|
1690
1736
|
};
|
1691
1737
|
}
|
1692
1738
|
|
1693
|
-
function readPostScriptTable(post,
|
1739
|
+
function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
|
1694
1740
|
var start = (font.start ? font.start : 0) + post.offset;
|
1695
1741
|
font.pos = start;
|
1696
1742
|
var length = post.length,
|
1697
1743
|
end = start + length;
|
1698
1744
|
var version = font.getInt32();
|
1699
|
-
font.
|
1745
|
+
font.skip(28);
|
1700
1746
|
var glyphNames;
|
1701
1747
|
var valid = true;
|
1702
1748
|
var i;
|
@@ -1742,7 +1788,7 @@ var Font = function FontClosure() {
|
|
1742
1788
|
strBuf[i] = String.fromCharCode(font.getByte());
|
1743
1789
|
}
|
1744
1790
|
|
1745
|
-
customNames.push(strBuf.join(
|
1791
|
+
customNames.push(strBuf.join(""));
|
1746
1792
|
}
|
1747
1793
|
|
1748
1794
|
glyphNames = [];
|
@@ -1764,17 +1810,17 @@ var Font = function FontClosure() {
|
|
1764
1810
|
break;
|
1765
1811
|
|
1766
1812
|
default:
|
1767
|
-
(0, _util.warn)(
|
1813
|
+
(0, _util.warn)("Unknown/unsupported post table version " + version);
|
1768
1814
|
valid = false;
|
1769
1815
|
|
1770
|
-
if (
|
1771
|
-
glyphNames =
|
1816
|
+
if (propertiesObj.defaultEncoding) {
|
1817
|
+
glyphNames = propertiesObj.defaultEncoding;
|
1772
1818
|
}
|
1773
1819
|
|
1774
1820
|
break;
|
1775
1821
|
}
|
1776
1822
|
|
1777
|
-
|
1823
|
+
propertiesObj.glyphNames = glyphNames;
|
1778
1824
|
return valid;
|
1779
1825
|
}
|
1780
1826
|
|
@@ -1829,7 +1875,7 @@ var Font = function FontClosure() {
|
|
1829
1875
|
var nameIndex = record.name;
|
1830
1876
|
|
1831
1877
|
if (record.encoding) {
|
1832
|
-
var str =
|
1878
|
+
var str = "";
|
1833
1879
|
|
1834
1880
|
for (var j = 0, jj = record.length; j < jj; j += 2) {
|
1835
1881
|
str += String.fromCharCode(font.getUint16());
|
@@ -1888,8 +1934,8 @@ var Font = function FontClosure() {
|
|
1888
1934
|
stack.push(b << 8 | data[i++]);
|
1889
1935
|
}
|
1890
1936
|
}
|
1891
|
-
} else if ((op &
|
1892
|
-
n = op -
|
1937
|
+
} else if ((op & 0xf8) === 0xb0) {
|
1938
|
+
n = op - 0xb0 + 1;
|
1893
1939
|
|
1894
1940
|
if (inFDEF || inELSE) {
|
1895
1941
|
i += n;
|
@@ -1898,8 +1944,8 @@ var Font = function FontClosure() {
|
|
1898
1944
|
stack.push(data[i++]);
|
1899
1945
|
}
|
1900
1946
|
}
|
1901
|
-
} else if ((op &
|
1902
|
-
n = op -
|
1947
|
+
} else if ((op & 0xf8) === 0xb8) {
|
1948
|
+
n = op - 0xb8 + 1;
|
1903
1949
|
|
1904
1950
|
if (inFDEF || inELSE) {
|
1905
1951
|
i += n * 2;
|
@@ -1909,20 +1955,20 @@ var Font = function FontClosure() {
|
|
1909
1955
|
stack.push(b << 8 | data[i++]);
|
1910
1956
|
}
|
1911
1957
|
}
|
1912
|
-
} else if (op ===
|
1958
|
+
} else if (op === 0x2b && !tooComplexToFollowFunctions) {
|
1913
1959
|
if (!inFDEF && !inELSE) {
|
1914
1960
|
funcId = stack[stack.length - 1];
|
1915
1961
|
|
1916
1962
|
if (isNaN(funcId)) {
|
1917
|
-
(0, _util.info)(
|
1963
|
+
(0, _util.info)("TT: CALL empty stack (or invalid entry).");
|
1918
1964
|
} else {
|
1919
1965
|
ttContext.functionsUsed[funcId] = true;
|
1920
1966
|
|
1921
1967
|
if (funcId in ttContext.functionsStackDeltas) {
|
1922
|
-
|
1968
|
+
const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
|
1923
1969
|
|
1924
1970
|
if (newStackLength < 0) {
|
1925
|
-
(0, _util.warn)(
|
1971
|
+
(0, _util.warn)("TT: CALL invalid functions stack delta.");
|
1926
1972
|
ttContext.hintsValid = false;
|
1927
1973
|
return;
|
1928
1974
|
}
|
@@ -1930,15 +1976,15 @@ var Font = function FontClosure() {
|
|
1930
1976
|
stack.length = newStackLength;
|
1931
1977
|
} else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
|
1932
1978
|
callstack.push({
|
1933
|
-
data
|
1934
|
-
i
|
1979
|
+
data,
|
1980
|
+
i,
|
1935
1981
|
stackTop: stack.length - 1
|
1936
1982
|
});
|
1937
1983
|
functionsCalled.push(funcId);
|
1938
1984
|
pc = ttContext.functionsDefined[funcId];
|
1939
1985
|
|
1940
1986
|
if (!pc) {
|
1941
|
-
(0, _util.warn)(
|
1987
|
+
(0, _util.warn)("TT: CALL non-existent function");
|
1942
1988
|
ttContext.hintsValid = false;
|
1943
1989
|
return;
|
1944
1990
|
}
|
@@ -1948,9 +1994,9 @@ var Font = function FontClosure() {
|
|
1948
1994
|
}
|
1949
1995
|
}
|
1950
1996
|
}
|
1951
|
-
} else if (op ===
|
1997
|
+
} else if (op === 0x2c && !tooComplexToFollowFunctions) {
|
1952
1998
|
if (inFDEF || inELSE) {
|
1953
|
-
(0, _util.warn)(
|
1999
|
+
(0, _util.warn)("TT: nested FDEFs not allowed");
|
1954
2000
|
tooComplexToFollowFunctions = true;
|
1955
2001
|
}
|
1956
2002
|
|
@@ -1958,10 +2004,10 @@ var Font = function FontClosure() {
|
|
1958
2004
|
lastDeff = i;
|
1959
2005
|
funcId = stack.pop();
|
1960
2006
|
ttContext.functionsDefined[funcId] = {
|
1961
|
-
data
|
1962
|
-
i
|
2007
|
+
data,
|
2008
|
+
i
|
1963
2009
|
};
|
1964
|
-
} else if (op ===
|
2010
|
+
} else if (op === 0x2d) {
|
1965
2011
|
if (inFDEF) {
|
1966
2012
|
inFDEF = false;
|
1967
2013
|
lastEndf = i;
|
@@ -1969,7 +2015,7 @@ var Font = function FontClosure() {
|
|
1969
2015
|
pc = callstack.pop();
|
1970
2016
|
|
1971
2017
|
if (!pc) {
|
1972
|
-
(0, _util.warn)(
|
2018
|
+
(0, _util.warn)("TT: ENDF bad stack");
|
1973
2019
|
ttContext.hintsValid = false;
|
1974
2020
|
return;
|
1975
2021
|
}
|
@@ -1981,7 +2027,7 @@ var Font = function FontClosure() {
|
|
1981
2027
|
}
|
1982
2028
|
} else if (op === 0x89) {
|
1983
2029
|
if (inFDEF || inELSE) {
|
1984
|
-
(0, _util.warn)(
|
2030
|
+
(0, _util.warn)("TT: nested IDEFs not allowed");
|
1985
2031
|
tooComplexToFollowFunctions = true;
|
1986
2032
|
}
|
1987
2033
|
|
@@ -1989,7 +2035,7 @@ var Font = function FontClosure() {
|
|
1989
2035
|
lastDeff = i;
|
1990
2036
|
} else if (op === 0x58) {
|
1991
2037
|
++ifLevel;
|
1992
|
-
} else if (op ===
|
2038
|
+
} else if (op === 0x1b) {
|
1993
2039
|
inELSE = ifLevel;
|
1994
2040
|
} else if (op === 0x59) {
|
1995
2041
|
if (inELSE === ifLevel) {
|
@@ -1997,7 +2043,7 @@ var Font = function FontClosure() {
|
|
1997
2043
|
}
|
1998
2044
|
|
1999
2045
|
--ifLevel;
|
2000
|
-
} else if (op ===
|
2046
|
+
} else if (op === 0x1c) {
|
2001
2047
|
if (!inFDEF && !inELSE) {
|
2002
2048
|
var offset = stack[stack.length - 1];
|
2003
2049
|
|
@@ -2008,7 +2054,15 @@ var Font = function FontClosure() {
|
|
2008
2054
|
}
|
2009
2055
|
|
2010
2056
|
if (!inFDEF && !inELSE) {
|
2011
|
-
|
2057
|
+
let stackDelta = 0;
|
2058
|
+
|
2059
|
+
if (op <= 0x8e) {
|
2060
|
+
stackDelta = TTOpsStackDeltas[op];
|
2061
|
+
} else if (op >= 0xc0 && op <= 0xdf) {
|
2062
|
+
stackDelta = -1;
|
2063
|
+
} else if (op >= 0xe0) {
|
2064
|
+
stackDelta = -2;
|
2065
|
+
}
|
2012
2066
|
|
2013
2067
|
if (op >= 0x71 && op <= 0x75) {
|
2014
2068
|
n = stack.pop();
|
@@ -2038,8 +2092,8 @@ var Font = function FontClosure() {
|
|
2038
2092
|
}
|
2039
2093
|
|
2040
2094
|
if (lastDeff > lastEndf) {
|
2041
|
-
(0, _util.warn)(
|
2042
|
-
content.push(new Uint8Array([0x22,
|
2095
|
+
(0, _util.warn)("TT: complementing a missing function tail");
|
2096
|
+
content.push(new Uint8Array([0x22, 0x2d]));
|
2043
2097
|
}
|
2044
2098
|
|
2045
2099
|
foldTTTable(table, content);
|
@@ -2051,20 +2105,20 @@ var Font = function FontClosure() {
|
|
2051
2105
|
}
|
2052
2106
|
|
2053
2107
|
if (ttContext.functionsDefined.length > maxFunctionDefs) {
|
2054
|
-
(0, _util.warn)(
|
2108
|
+
(0, _util.warn)("TT: more functions defined than expected");
|
2055
2109
|
ttContext.hintsValid = false;
|
2056
2110
|
return;
|
2057
2111
|
}
|
2058
2112
|
|
2059
2113
|
for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
|
2060
2114
|
if (j > maxFunctionDefs) {
|
2061
|
-
(0, _util.warn)(
|
2115
|
+
(0, _util.warn)("TT: invalid function id: " + j);
|
2062
2116
|
ttContext.hintsValid = false;
|
2063
2117
|
return;
|
2064
2118
|
}
|
2065
2119
|
|
2066
2120
|
if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
|
2067
|
-
(0, _util.warn)(
|
2121
|
+
(0, _util.warn)("TT: undefined function: " + j);
|
2068
2122
|
ttContext.hintsValid = false;
|
2069
2123
|
return;
|
2070
2124
|
}
|
@@ -2125,10 +2179,10 @@ var Font = function FontClosure() {
|
|
2125
2179
|
}
|
2126
2180
|
|
2127
2181
|
font = new _stream.Stream(new Uint8Array(font.getBytes()));
|
2128
|
-
|
2182
|
+
let header, tables;
|
2129
2183
|
|
2130
2184
|
if (isTrueTypeCollectionFile(font)) {
|
2131
|
-
|
2185
|
+
const ttcData = readTrueTypeCollectionData(font, this.name);
|
2132
2186
|
header = ttcData.header;
|
2133
2187
|
tables = ttcData.tables;
|
2134
2188
|
} else {
|
@@ -2136,34 +2190,34 @@ var Font = function FontClosure() {
|
|
2136
2190
|
tables = readTables(font, header.numTables);
|
2137
2191
|
}
|
2138
2192
|
|
2139
|
-
|
2140
|
-
var isTrueType = !tables[
|
2193
|
+
let cff, cffFile;
|
2194
|
+
var isTrueType = !tables["CFF "];
|
2141
2195
|
|
2142
2196
|
if (!isTrueType) {
|
2143
|
-
|
2197
|
+
const isComposite = properties.composite && ((properties.cidToGidMap || []).length > 0 || !(properties.cMap instanceof _cmap.IdentityCMap));
|
2144
2198
|
|
2145
|
-
if (header.version ===
|
2146
|
-
cffFile = new _stream.Stream(tables[
|
2199
|
+
if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
|
2200
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2147
2201
|
cff = new CFFFont(cffFile, properties);
|
2148
2202
|
adjustWidths(properties);
|
2149
2203
|
return this.convert(name, cff, properties);
|
2150
2204
|
}
|
2151
2205
|
|
2152
|
-
delete tables
|
2153
|
-
delete tables
|
2154
|
-
delete tables
|
2155
|
-
delete tables
|
2156
|
-
delete tables[
|
2206
|
+
delete tables.glyf;
|
2207
|
+
delete tables.loca;
|
2208
|
+
delete tables.fpgm;
|
2209
|
+
delete tables.prep;
|
2210
|
+
delete tables["cvt "];
|
2157
2211
|
this.isOpenType = true;
|
2158
2212
|
} else {
|
2159
|
-
if (!tables
|
2213
|
+
if (!tables.loca) {
|
2160
2214
|
throw new _util.FormatError('Required "loca" table is not found');
|
2161
2215
|
}
|
2162
2216
|
|
2163
|
-
if (!tables
|
2217
|
+
if (!tables.glyf) {
|
2164
2218
|
(0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
|
2165
|
-
tables
|
2166
|
-
tag:
|
2219
|
+
tables.glyf = {
|
2220
|
+
tag: "glyf",
|
2167
2221
|
data: new Uint8Array(0)
|
2168
2222
|
};
|
2169
2223
|
}
|
@@ -2171,32 +2225,32 @@ var Font = function FontClosure() {
|
|
2171
2225
|
this.isOpenType = false;
|
2172
2226
|
}
|
2173
2227
|
|
2174
|
-
if (!tables
|
2228
|
+
if (!tables.maxp) {
|
2175
2229
|
throw new _util.FormatError('Required "maxp" table is not found');
|
2176
2230
|
}
|
2177
2231
|
|
2178
|
-
font.pos = (font.start || 0) + tables
|
2232
|
+
font.pos = (font.start || 0) + tables.maxp.offset;
|
2179
2233
|
var version = font.getInt32();
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2234
|
+
const numGlyphs = font.getUint16();
|
2235
|
+
let numGlyphsOut = numGlyphs + 1;
|
2236
|
+
let dupFirstEntry = true;
|
2183
2237
|
|
2184
|
-
if (numGlyphsOut >
|
2238
|
+
if (numGlyphsOut > 0xffff) {
|
2185
2239
|
dupFirstEntry = false;
|
2186
2240
|
numGlyphsOut = numGlyphs;
|
2187
|
-
(0, _util.warn)(
|
2241
|
+
(0, _util.warn)("Not enough space in glyfs to duplicate first glyph.");
|
2188
2242
|
}
|
2189
2243
|
|
2190
2244
|
var maxFunctionDefs = 0;
|
2191
2245
|
var maxSizeOfInstructions = 0;
|
2192
2246
|
|
2193
|
-
if (version >= 0x00010000 && tables
|
2247
|
+
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
2194
2248
|
font.pos += 8;
|
2195
2249
|
var maxZones = font.getUint16();
|
2196
2250
|
|
2197
2251
|
if (maxZones > 2) {
|
2198
|
-
tables
|
2199
|
-
tables
|
2252
|
+
tables.maxp.data[14] = 0;
|
2253
|
+
tables.maxp.data[15] = 2;
|
2200
2254
|
}
|
2201
2255
|
|
2202
2256
|
font.pos += 4;
|
@@ -2205,65 +2259,64 @@ var Font = function FontClosure() {
|
|
2205
2259
|
maxSizeOfInstructions = font.getUint16();
|
2206
2260
|
}
|
2207
2261
|
|
2208
|
-
tables
|
2209
|
-
tables
|
2210
|
-
var hintsValid = sanitizeTTPrograms(tables
|
2262
|
+
tables.maxp.data[4] = numGlyphsOut >> 8;
|
2263
|
+
tables.maxp.data[5] = numGlyphsOut & 255;
|
2264
|
+
var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs);
|
2211
2265
|
|
2212
2266
|
if (!hintsValid) {
|
2213
|
-
delete tables
|
2214
|
-
delete tables
|
2215
|
-
delete tables[
|
2267
|
+
delete tables.fpgm;
|
2268
|
+
delete tables.prep;
|
2269
|
+
delete tables["cvt "];
|
2216
2270
|
}
|
2217
2271
|
|
2218
|
-
sanitizeMetrics(font, tables
|
2272
|
+
sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphsOut, dupFirstEntry);
|
2219
2273
|
|
2220
|
-
if (!tables
|
2274
|
+
if (!tables.head) {
|
2221
2275
|
throw new _util.FormatError('Required "head" table is not found');
|
2222
2276
|
}
|
2223
2277
|
|
2224
|
-
sanitizeHead(tables
|
2278
|
+
sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
|
2225
2279
|
var missingGlyphs = Object.create(null);
|
2226
2280
|
|
2227
2281
|
if (isTrueType) {
|
2228
|
-
var isGlyphLocationsLong = int16(tables
|
2229
|
-
var glyphsInfo = sanitizeGlyphLocations(tables
|
2282
|
+
var isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
|
2283
|
+
var glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
|
2230
2284
|
missingGlyphs = glyphsInfo.missingGlyphs;
|
2231
2285
|
|
2232
|
-
if (version >= 0x00010000 && tables
|
2233
|
-
tables
|
2234
|
-
tables
|
2286
|
+
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
2287
|
+
tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
|
2288
|
+
tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
|
2235
2289
|
}
|
2236
2290
|
}
|
2237
2291
|
|
2238
|
-
if (!tables
|
2292
|
+
if (!tables.hhea) {
|
2239
2293
|
throw new _util.FormatError('Required "hhea" table is not found');
|
2240
2294
|
}
|
2241
2295
|
|
2242
|
-
if (tables
|
2243
|
-
tables
|
2244
|
-
tables
|
2296
|
+
if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
|
2297
|
+
tables.hhea.data[10] = 0xff;
|
2298
|
+
tables.hhea.data[11] = 0xff;
|
2245
2299
|
}
|
2246
2300
|
|
2247
2301
|
var metricsOverride = {
|
2248
|
-
unitsPerEm: int16(tables
|
2249
|
-
yMax: int16(tables
|
2250
|
-
yMin: signedInt16(tables
|
2251
|
-
ascent: int16(tables
|
2252
|
-
descent: signedInt16(tables
|
2302
|
+
unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
|
2303
|
+
yMax: int16(tables.head.data[42], tables.head.data[43]),
|
2304
|
+
yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
|
2305
|
+
ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
|
2306
|
+
descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7])
|
2253
2307
|
};
|
2254
2308
|
this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
|
2255
2309
|
this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
2256
2310
|
|
2257
|
-
if (tables
|
2258
|
-
readPostScriptTable(tables
|
2311
|
+
if (tables.post) {
|
2312
|
+
readPostScriptTable(tables.post, properties, numGlyphs);
|
2259
2313
|
}
|
2260
2314
|
|
2261
|
-
tables
|
2262
|
-
tag:
|
2315
|
+
tables.post = {
|
2316
|
+
tag: "post",
|
2263
2317
|
data: createPostTable(properties)
|
2264
2318
|
};
|
2265
|
-
|
2266
|
-
charCode;
|
2319
|
+
const charCodeToGlyphId = [];
|
2267
2320
|
|
2268
2321
|
function hasGlyph(glyphId) {
|
2269
2322
|
return !missingGlyphs[glyphId];
|
@@ -2274,7 +2327,7 @@ var Font = function FontClosure() {
|
|
2274
2327
|
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
2275
2328
|
properties.cMap.forEach(function (charCode, cid) {
|
2276
2329
|
if (cid > 0xffff) {
|
2277
|
-
throw new _util.FormatError(
|
2330
|
+
throw new _util.FormatError("Max size of CID is 65,535");
|
2278
2331
|
}
|
2279
2332
|
|
2280
2333
|
var glyphId = -1;
|
@@ -2290,7 +2343,7 @@ var Font = function FontClosure() {
|
|
2290
2343
|
}
|
2291
2344
|
});
|
2292
2345
|
} else {
|
2293
|
-
var cmapTable = readCmapTable(tables
|
2346
|
+
var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding);
|
2294
2347
|
var cmapPlatformId = cmapTable.platformId;
|
2295
2348
|
var cmapEncodingId = cmapTable.encodingId;
|
2296
2349
|
var cmapMappings = cmapTable.mappings;
|
@@ -2299,18 +2352,18 @@ var Font = function FontClosure() {
|
|
2299
2352
|
if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && !!(0, _encodings.getEncoding)(properties.baseEncodingName)) {
|
2300
2353
|
var baseEncoding = [];
|
2301
2354
|
|
2302
|
-
if (properties.baseEncodingName ===
|
2355
|
+
if (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding") {
|
2303
2356
|
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
2304
2357
|
}
|
2305
2358
|
|
2306
2359
|
var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2307
2360
|
|
2308
|
-
for (charCode = 0; charCode < 256; charCode++) {
|
2361
|
+
for (let charCode = 0; charCode < 256; charCode++) {
|
2309
2362
|
var glyphName, standardGlyphName;
|
2310
2363
|
|
2311
2364
|
if (this.differences && charCode in this.differences) {
|
2312
2365
|
glyphName = this.differences[charCode];
|
2313
|
-
} else if (charCode in baseEncoding && baseEncoding[charCode] !==
|
2366
|
+
} else if (charCode in baseEncoding && baseEncoding[charCode] !== "") {
|
2314
2367
|
glyphName = baseEncoding[charCode];
|
2315
2368
|
} else {
|
2316
2369
|
glyphName = _encodings.StandardEncoding[charCode];
|
@@ -2331,7 +2384,7 @@ var Font = function FontClosure() {
|
|
2331
2384
|
|
2332
2385
|
var found = false;
|
2333
2386
|
|
2334
|
-
for (
|
2387
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2335
2388
|
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
|
2336
2389
|
continue;
|
2337
2390
|
}
|
@@ -2354,18 +2407,18 @@ var Font = function FontClosure() {
|
|
2354
2407
|
}
|
2355
2408
|
}
|
2356
2409
|
} else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
|
2357
|
-
for (
|
2358
|
-
charCodeToGlyphId[cmapMappings[
|
2410
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2411
|
+
charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
|
2359
2412
|
}
|
2360
2413
|
} else {
|
2361
|
-
for (
|
2362
|
-
charCode = cmapMappings[
|
2414
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2415
|
+
let charCode = cmapMappings[i].charCode;
|
2363
2416
|
|
2364
|
-
if (cmapPlatformId === 3 && charCode >=
|
2365
|
-
charCode &=
|
2417
|
+
if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
|
2418
|
+
charCode &= 0xff;
|
2366
2419
|
}
|
2367
2420
|
|
2368
|
-
charCodeToGlyphId[charCode] = cmapMappings[
|
2421
|
+
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
2369
2422
|
}
|
2370
2423
|
}
|
2371
2424
|
}
|
@@ -2374,7 +2427,7 @@ var Font = function FontClosure() {
|
|
2374
2427
|
charCodeToGlyphId[0] = 0;
|
2375
2428
|
}
|
2376
2429
|
|
2377
|
-
|
2430
|
+
let glyphZeroId = numGlyphsOut - 1;
|
2378
2431
|
|
2379
2432
|
if (!dupFirstEntry) {
|
2380
2433
|
glyphZeroId = 0;
|
@@ -2382,39 +2435,39 @@ var Font = function FontClosure() {
|
|
2382
2435
|
|
2383
2436
|
var newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId);
|
2384
2437
|
this.toFontChar = newMapping.toFontChar;
|
2385
|
-
tables
|
2386
|
-
tag:
|
2438
|
+
tables.cmap = {
|
2439
|
+
tag: "cmap",
|
2387
2440
|
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut)
|
2388
2441
|
};
|
2389
2442
|
|
2390
|
-
if (!tables[
|
2391
|
-
tables[
|
2392
|
-
tag:
|
2443
|
+
if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
|
2444
|
+
tables["OS/2"] = {
|
2445
|
+
tag: "OS/2",
|
2393
2446
|
data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
|
2394
2447
|
};
|
2395
2448
|
}
|
2396
2449
|
|
2397
2450
|
if (!isTrueType) {
|
2398
2451
|
try {
|
2399
|
-
cffFile = new _stream.Stream(tables[
|
2452
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2400
2453
|
var parser = new _cff_parser.CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
|
2401
2454
|
cff = parser.parse();
|
2402
2455
|
cff.duplicateFirstGlyph();
|
2403
2456
|
var compiler = new _cff_parser.CFFCompiler(cff);
|
2404
|
-
tables[
|
2457
|
+
tables["CFF "].data = compiler.compile();
|
2405
2458
|
} catch (e) {
|
2406
|
-
(0, _util.warn)(
|
2459
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
2407
2460
|
}
|
2408
2461
|
}
|
2409
2462
|
|
2410
|
-
if (!tables
|
2411
|
-
tables
|
2412
|
-
tag:
|
2463
|
+
if (!tables.name) {
|
2464
|
+
tables.name = {
|
2465
|
+
tag: "name",
|
2413
2466
|
data: createNameTable(this.name)
|
2414
2467
|
};
|
2415
2468
|
} else {
|
2416
|
-
var namePrototype = readNameTable(tables
|
2417
|
-
tables
|
2469
|
+
var namePrototype = readNameTable(tables.name);
|
2470
|
+
tables.name.data = createNameTable(name, namePrototype);
|
2418
2471
|
}
|
2419
2472
|
|
2420
2473
|
var builder = new OpenTypeFileBuilder(header.version);
|
@@ -2432,7 +2485,7 @@ var Font = function FontClosure() {
|
|
2432
2485
|
adjustToUnicode(properties, properties.builtInEncoding);
|
2433
2486
|
}
|
2434
2487
|
|
2435
|
-
|
2488
|
+
let glyphZeroId = 1;
|
2436
2489
|
|
2437
2490
|
if (font instanceof CFFFont) {
|
2438
2491
|
glyphZeroId = font.numGlyphs - 1;
|
@@ -2499,15 +2552,15 @@ var Font = function FontClosure() {
|
|
2499
2552
|
continue;
|
2500
2553
|
}
|
2501
2554
|
|
2502
|
-
for (
|
2555
|
+
for (let i = 0, ii = charCodes.length; i < ii; i++) {
|
2503
2556
|
var charCode = charCodes[i];
|
2504
2557
|
var charCodeToGlyphId = newMapping.charCodeToGlyphId;
|
2505
2558
|
var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
|
2506
2559
|
var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
|
2507
2560
|
seacMap[charCode] = {
|
2508
|
-
baseFontCharCode
|
2509
|
-
accentFontCharCode
|
2510
|
-
accentOffset
|
2561
|
+
baseFontCharCode,
|
2562
|
+
accentFontCharCode,
|
2563
|
+
accentOffset
|
2511
2564
|
};
|
2512
2565
|
}
|
2513
2566
|
}
|
@@ -2516,23 +2569,23 @@ var Font = function FontClosure() {
|
|
2516
2569
|
}
|
2517
2570
|
|
2518
2571
|
var unitsPerEm = 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
|
2519
|
-
var builder = new OpenTypeFileBuilder(
|
2520
|
-
builder.addTable(
|
2521
|
-
builder.addTable(
|
2522
|
-
builder.addTable(
|
2523
|
-
builder.addTable(
|
2524
|
-
builder.addTable(
|
2525
|
-
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() {
|
2526
2579
|
var charstrings = font.charstrings;
|
2527
2580
|
var cffWidths = font.cff ? font.cff.widths : null;
|
2528
|
-
var hmtx =
|
2581
|
+
var hmtx = "\x00\x00\x00\x00";
|
2529
2582
|
|
2530
|
-
for (
|
2583
|
+
for (let i = 1, ii = numGlyphs; i < ii; i++) {
|
2531
2584
|
var width = 0;
|
2532
2585
|
|
2533
2586
|
if (charstrings) {
|
2534
2587
|
var charstring = charstrings[i - 1];
|
2535
|
-
width =
|
2588
|
+
width = "width" in charstring ? charstring.width : 0;
|
2536
2589
|
} else if (cffWidths) {
|
2537
2590
|
width = Math.ceil(cffWidths[i] || 0);
|
2538
2591
|
}
|
@@ -2542,18 +2595,14 @@ var Font = function FontClosure() {
|
|
2542
2595
|
|
2543
2596
|
return hmtx;
|
2544
2597
|
}());
|
2545
|
-
builder.addTable(
|
2546
|
-
builder.addTable(
|
2547
|
-
builder.addTable(
|
2598
|
+
builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs));
|
2599
|
+
builder.addTable("name", createNameTable(fontName));
|
2600
|
+
builder.addTable("post", createPostTable(properties));
|
2548
2601
|
return builder.toArray();
|
2549
2602
|
},
|
2550
2603
|
|
2551
2604
|
get spaceWidth() {
|
2552
|
-
|
2553
|
-
return this._shadowWidth;
|
2554
|
-
}
|
2555
|
-
|
2556
|
-
var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
|
2605
|
+
var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
2557
2606
|
var width;
|
2558
2607
|
|
2559
2608
|
for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
|
@@ -2568,10 +2617,8 @@ var Font = function FontClosure() {
|
|
2568
2617
|
var glyphUnicode = glyphsUnicodeMap[glyphName];
|
2569
2618
|
var charcode = 0;
|
2570
2619
|
|
2571
|
-
if (this.composite) {
|
2572
|
-
|
2573
|
-
charcode = this.cMap.lookup(glyphUnicode);
|
2574
|
-
}
|
2620
|
+
if (this.composite && this.cMap.contains(glyphUnicode)) {
|
2621
|
+
charcode = this.cMap.lookup(glyphUnicode);
|
2575
2622
|
}
|
2576
2623
|
|
2577
2624
|
if (!charcode && this.toUnicode) {
|
@@ -2590,8 +2637,7 @@ var Font = function FontClosure() {
|
|
2590
2637
|
}
|
2591
2638
|
|
2592
2639
|
width = width || this.defaultWidth;
|
2593
|
-
this
|
2594
|
-
return width;
|
2640
|
+
return (0, _util.shadow)(this, "spaceWidth", width);
|
2595
2641
|
},
|
2596
2642
|
|
2597
2643
|
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
|
@@ -2605,16 +2651,22 @@ var Font = function FontClosure() {
|
|
2605
2651
|
width = this.widths[widthCode];
|
2606
2652
|
width = (0, _util.isNum)(width) ? width : this.defaultWidth;
|
2607
2653
|
var vmetric = this.vmetrics && this.vmetrics[widthCode];
|
2608
|
-
|
2654
|
+
let unicode = this.toUnicode.get(charcode) || this.fallbackToUnicode.get(charcode) || charcode;
|
2609
2655
|
|
2610
|
-
if (typeof unicode ===
|
2656
|
+
if (typeof unicode === "number") {
|
2611
2657
|
unicode = String.fromCharCode(unicode);
|
2612
2658
|
}
|
2613
2659
|
|
2614
|
-
var isInFont = charcode in this.toFontChar;
|
2660
|
+
var isInFont = (charcode in this.toFontChar);
|
2615
2661
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
2616
2662
|
|
2617
2663
|
if (this.missingFile) {
|
2664
|
+
const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
|
2665
|
+
|
2666
|
+
if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
|
2667
|
+
fontCharCode = 0x20;
|
2668
|
+
}
|
2669
|
+
|
2618
2670
|
fontCharCode = (0, _unicode.mapSpecialUnicodeValues)(fontCharCode);
|
2619
2671
|
}
|
2620
2672
|
|
@@ -2634,7 +2686,16 @@ var Font = function FontClosure() {
|
|
2634
2686
|
};
|
2635
2687
|
}
|
2636
2688
|
|
2637
|
-
|
2689
|
+
let fontChar = "";
|
2690
|
+
|
2691
|
+
if (typeof fontCharCode === "number") {
|
2692
|
+
if (fontCharCode <= 0x10ffff) {
|
2693
|
+
fontChar = String.fromCodePoint(fontCharCode);
|
2694
|
+
} else {
|
2695
|
+
(0, _util.warn)(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
|
2696
|
+
}
|
2697
|
+
}
|
2698
|
+
|
2638
2699
|
var glyph = this.glyphCache[charcode];
|
2639
2700
|
|
2640
2701
|
if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
|
@@ -2701,7 +2762,7 @@ exports.Font = Font;
|
|
2701
2762
|
var ErrorFont = function ErrorFontClosure() {
|
2702
2763
|
function ErrorFont(error) {
|
2703
2764
|
this.error = error;
|
2704
|
-
this.loadedName =
|
2765
|
+
this.loadedName = "g_font_error";
|
2705
2766
|
this.missingFile = true;
|
2706
2767
|
}
|
2707
2768
|
|
@@ -2709,11 +2770,13 @@ var ErrorFont = function ErrorFontClosure() {
|
|
2709
2770
|
charsToGlyphs: function ErrorFont_charsToGlyphs() {
|
2710
2771
|
return [];
|
2711
2772
|
},
|
2712
|
-
|
2773
|
+
|
2774
|
+
exportData(extraProperties = false) {
|
2713
2775
|
return {
|
2714
2776
|
error: this.error
|
2715
2777
|
};
|
2716
2778
|
}
|
2779
|
+
|
2717
2780
|
};
|
2718
2781
|
return ErrorFont;
|
2719
2782
|
}();
|
@@ -2805,7 +2868,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2805
2868
|
if (j >= signatureLength) {
|
2806
2869
|
i += j;
|
2807
2870
|
|
2808
|
-
while (i < streamBytesLength && (0,
|
2871
|
+
while (i < streamBytesLength && (0, _core_utils.isWhiteSpace)(streamBytes[i])) {
|
2809
2872
|
i++;
|
2810
2873
|
}
|
2811
2874
|
|
@@ -2817,7 +2880,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2817
2880
|
}
|
2818
2881
|
|
2819
2882
|
return {
|
2820
|
-
found
|
2883
|
+
found,
|
2821
2884
|
length: i
|
2822
2885
|
};
|
2823
2886
|
}
|
@@ -2831,7 +2894,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2831
2894
|
headerBytes = stream.getBytes(suggestedLength);
|
2832
2895
|
headerBytesLength = headerBytes.length;
|
2833
2896
|
} catch (ex) {
|
2834
|
-
if (ex instanceof
|
2897
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
2835
2898
|
throw ex;
|
2836
2899
|
}
|
2837
2900
|
}
|
@@ -2915,10 +2978,10 @@ var Type1Font = function Type1FontClosure() {
|
|
2915
2978
|
|
2916
2979
|
var eexecBlock = getEexecBlock(file, eexecBlockLength);
|
2917
2980
|
var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
|
2918
|
-
var data = eexecBlockParser.extractFontProgram();
|
2981
|
+
var data = eexecBlockParser.extractFontProgram(properties);
|
2919
2982
|
|
2920
|
-
for (
|
2921
|
-
properties[
|
2983
|
+
for (const key in data.properties) {
|
2984
|
+
properties[key] = data.properties[key];
|
2922
2985
|
}
|
2923
2986
|
|
2924
2987
|
var charstrings = data.charstrings;
|
@@ -2935,7 +2998,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2935
2998
|
},
|
2936
2999
|
|
2937
3000
|
getCharset: function Type1Font_getCharset() {
|
2938
|
-
var charset = [
|
3001
|
+
var charset = [".notdef"];
|
2939
3002
|
var charstrings = this.charstrings;
|
2940
3003
|
|
2941
3004
|
for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -2946,7 +3009,19 @@ var Type1Font = function Type1FontClosure() {
|
|
2946
3009
|
},
|
2947
3010
|
getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
|
2948
3011
|
var charstrings = this.charstrings;
|
2949
|
-
|
3012
|
+
|
3013
|
+
if (properties.composite) {
|
3014
|
+
const charCodeToGlyphId = Object.create(null);
|
3015
|
+
|
3016
|
+
for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) {
|
3017
|
+
const charCode = properties.cMap.charCodeOf(glyphId);
|
3018
|
+
charCodeToGlyphId[charCode] = glyphId + 1;
|
3019
|
+
}
|
3020
|
+
|
3021
|
+
return charCodeToGlyphId;
|
3022
|
+
}
|
3023
|
+
|
3024
|
+
var glyphNames = [".notdef"],
|
2950
3025
|
glyphId;
|
2951
3026
|
|
2952
3027
|
for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -3020,7 +3095,7 @@ var Type1Font = function Type1FontClosure() {
|
|
3020
3095
|
var i;
|
3021
3096
|
|
3022
3097
|
for (i = 0; i < bias; i++) {
|
3023
|
-
type2Subrs.push([
|
3098
|
+
type2Subrs.push([0x0b]);
|
3024
3099
|
}
|
3025
3100
|
|
3026
3101
|
for (i = 0; i < count; i++) {
|
@@ -3034,43 +3109,45 @@ var Type1Font = function Type1FontClosure() {
|
|
3034
3109
|
cff.header = new _cff_parser.CFFHeader(1, 0, 4, 4);
|
3035
3110
|
cff.names = [name];
|
3036
3111
|
var topDict = new _cff_parser.CFFTopDict();
|
3037
|
-
topDict.setByName(
|
3038
|
-
topDict.setByName(
|
3039
|
-
topDict.setByName(
|
3040
|
-
topDict.setByName(
|
3041
|
-
topDict.setByName(
|
3042
|
-
topDict.setByName(
|
3043
|
-
topDict.setByName(
|
3044
|
-
topDict.setByName(
|
3045
|
-
topDict.setByName(
|
3046
|
-
topDict.setByName(
|
3047
|
-
topDict.setByName(
|
3112
|
+
topDict.setByName("version", 391);
|
3113
|
+
topDict.setByName("Notice", 392);
|
3114
|
+
topDict.setByName("FullName", 393);
|
3115
|
+
topDict.setByName("FamilyName", 394);
|
3116
|
+
topDict.setByName("Weight", 395);
|
3117
|
+
topDict.setByName("Encoding", null);
|
3118
|
+
topDict.setByName("FontMatrix", properties.fontMatrix);
|
3119
|
+
topDict.setByName("FontBBox", properties.bbox);
|
3120
|
+
topDict.setByName("charset", null);
|
3121
|
+
topDict.setByName("CharStrings", null);
|
3122
|
+
topDict.setByName("Private", null);
|
3048
3123
|
cff.topDict = topDict;
|
3049
3124
|
var strings = new _cff_parser.CFFStrings();
|
3050
|
-
strings.add(
|
3051
|
-
strings.add(
|
3125
|
+
strings.add("Version 0.11");
|
3126
|
+
strings.add("See original notice");
|
3052
3127
|
strings.add(name);
|
3053
3128
|
strings.add(name);
|
3054
|
-
strings.add(
|
3129
|
+
strings.add("Medium");
|
3055
3130
|
cff.strings = strings;
|
3056
3131
|
cff.globalSubrIndex = new _cff_parser.CFFIndex();
|
3057
3132
|
var count = glyphs.length;
|
3058
|
-
var charsetArray = [
|
3133
|
+
var charsetArray = [".notdef"];
|
3059
3134
|
var i, ii;
|
3060
3135
|
|
3061
3136
|
for (i = 0; i < count; i++) {
|
3062
|
-
|
3137
|
+
const glyphName = charstrings[i].glyphName;
|
3138
|
+
|
3139
|
+
const index = _cff_parser.CFFStandardStrings.indexOf(glyphName);
|
3063
3140
|
|
3064
3141
|
if (index === -1) {
|
3065
|
-
|
3142
|
+
strings.add(glyphName);
|
3066
3143
|
}
|
3067
3144
|
|
3068
|
-
charsetArray.push(
|
3145
|
+
charsetArray.push(glyphName);
|
3069
3146
|
}
|
3070
3147
|
|
3071
|
-
cff.charset = new _cff_parser.CFFCharset(false, 0,
|
3148
|
+
cff.charset = new _cff_parser.CFFCharset(false, 0, charsetArray);
|
3072
3149
|
var charStringsIndex = new _cff_parser.CFFIndex();
|
3073
|
-
charStringsIndex.add([
|
3150
|
+
charStringsIndex.add([0x8b, 0x0e]);
|
3074
3151
|
|
3075
3152
|
for (i = 0; i < count; i++) {
|
3076
3153
|
charStringsIndex.add(glyphs[i]);
|
@@ -3078,8 +3155,8 @@ var Type1Font = function Type1FontClosure() {
|
|
3078
3155
|
|
3079
3156
|
cff.charStrings = charStringsIndex;
|
3080
3157
|
var privateDict = new _cff_parser.CFFPrivateDict();
|
3081
|
-
privateDict.setByName(
|
3082
|
-
var fields = [
|
3158
|
+
privateDict.setByName("Subrs", null);
|
3159
|
+
var fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"];
|
3083
3160
|
|
3084
3161
|
for (i = 0, ii = fields.length; i < ii; i++) {
|
3085
3162
|
var field = fields[i];
|
@@ -3126,7 +3203,7 @@ var CFFFont = function CFFFontClosure() {
|
|
3126
3203
|
try {
|
3127
3204
|
this.data = compiler.compile();
|
3128
3205
|
} catch (e) {
|
3129
|
-
(0, _util.warn)(
|
3206
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
3130
3207
|
this.data = file;
|
3131
3208
|
}
|
3132
3209
|
}
|
@@ -3148,16 +3225,18 @@ var CFFFont = function CFFFontClosure() {
|
|
3148
3225
|
|
3149
3226
|
if (properties.composite) {
|
3150
3227
|
charCodeToGlyphId = Object.create(null);
|
3228
|
+
let charCode;
|
3151
3229
|
|
3152
3230
|
if (cff.isCIDFont) {
|
3153
3231
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
3154
3232
|
var cid = charsets[glyphId];
|
3155
|
-
|
3233
|
+
charCode = properties.cMap.charCodeOf(cid);
|
3156
3234
|
charCodeToGlyphId[charCode] = glyphId;
|
3157
3235
|
}
|
3158
3236
|
} else {
|
3159
3237
|
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
3160
|
-
|
3238
|
+
charCode = properties.cMap.charCodeOf(glyphId);
|
3239
|
+
charCodeToGlyphId[charCode] = glyphId;
|
3161
3240
|
}
|
3162
3241
|
}
|
3163
3242
|
|