pdfjs-dist 2.2.228 → 2.6.347
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- 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 +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -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/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- 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 +1144 -927
- 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 +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- 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 +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- 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 +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- 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 +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -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 +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- 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 +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
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,40 +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 _stream = require("./stream");
|
48
|
+
var _stream = require("./stream.js");
|
49
49
|
|
50
|
-
var _type1_parser = require("./type1_parser");
|
50
|
+
var _type1_parser = require("./type1_parser.js");
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
55
|
-
|
56
|
-
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
57
|
-
|
58
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
59
|
-
|
60
|
-
var PRIVATE_USE_AREAS = [[0xE000, 0xF8FF], [0x100000, 0x10FFFD]];
|
52
|
+
const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
|
61
53
|
var PDF_GLYPH_SPACE_UNITS = 1000;
|
62
54
|
var SEAC_ANALYSIS_ENABLED = true;
|
63
55
|
exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
|
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"];
|
64
58
|
var FontFlags = {
|
65
59
|
FixedPitch: 1,
|
66
60
|
Serif: 2,
|
@@ -73,7 +67,7 @@ var FontFlags = {
|
|
73
67
|
ForceBold: 262144
|
74
68
|
};
|
75
69
|
exports.FontFlags = FontFlags;
|
76
|
-
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"];
|
77
71
|
|
78
72
|
function adjustWidths(properties) {
|
79
73
|
if (!properties.fontMatrix) {
|
@@ -128,25 +122,25 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|
128
122
|
|
129
123
|
function getFontType(type, subtype) {
|
130
124
|
switch (type) {
|
131
|
-
case
|
132
|
-
return subtype ===
|
125
|
+
case "Type1":
|
126
|
+
return subtype === "Type1C" ? _util.FontType.TYPE1C : _util.FontType.TYPE1;
|
133
127
|
|
134
|
-
case
|
135
|
-
return subtype ===
|
128
|
+
case "CIDFontType0":
|
129
|
+
return subtype === "CIDFontType0C" ? _util.FontType.CIDFONTTYPE0C : _util.FontType.CIDFONTTYPE0;
|
136
130
|
|
137
|
-
case
|
131
|
+
case "OpenType":
|
138
132
|
return _util.FontType.OPENTYPE;
|
139
133
|
|
140
|
-
case
|
134
|
+
case "TrueType":
|
141
135
|
return _util.FontType.TRUETYPE;
|
142
136
|
|
143
|
-
case
|
137
|
+
case "CIDFontType2":
|
144
138
|
return _util.FontType.CIDFONTTYPE2;
|
145
139
|
|
146
|
-
case
|
140
|
+
case "MMType1":
|
147
141
|
return _util.FontType.MMTYPE1;
|
148
142
|
|
149
|
-
case
|
143
|
+
case "Type0":
|
150
144
|
return _util.FontType.TYPE0;
|
151
145
|
|
152
146
|
default:
|
@@ -169,7 +163,7 @@ function recoverGlyphName(name, glyphsUnicodeMap) {
|
|
169
163
|
}
|
170
164
|
}
|
171
165
|
|
172
|
-
(0, _util.info)(
|
166
|
+
(0, _util.info)("Unable to recover a standard glyph name for: " + name);
|
173
167
|
return name;
|
174
168
|
}
|
175
169
|
|
@@ -193,8 +187,7 @@ var Glyph = function GlyphClosure() {
|
|
193
187
|
}();
|
194
188
|
|
195
189
|
var ToUnicodeMap = function ToUnicodeMapClosure() {
|
196
|
-
function ToUnicodeMap() {
|
197
|
-
var cmap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
190
|
+
function ToUnicodeMap(cmap = []) {
|
198
191
|
this._map = cmap;
|
199
192
|
}
|
200
193
|
|
@@ -203,25 +196,28 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
203
196
|
return this._map.length;
|
204
197
|
},
|
205
198
|
|
206
|
-
forEach
|
199
|
+
forEach(callback) {
|
207
200
|
for (var charCode in this._map) {
|
208
201
|
callback(charCode, this._map[charCode].charCodeAt(0));
|
209
202
|
}
|
210
203
|
},
|
211
|
-
|
204
|
+
|
205
|
+
has(i) {
|
212
206
|
return this._map[i] !== undefined;
|
213
207
|
},
|
214
|
-
|
208
|
+
|
209
|
+
get(i) {
|
215
210
|
return this._map[i];
|
216
211
|
},
|
217
|
-
|
218
|
-
|
212
|
+
|
213
|
+
charCodeOf(value) {
|
214
|
+
const map = this._map;
|
219
215
|
|
220
216
|
if (map.length <= 0x10000) {
|
221
217
|
return map.indexOf(value);
|
222
218
|
}
|
223
219
|
|
224
|
-
for (
|
220
|
+
for (const charCode in map) {
|
225
221
|
if (map[charCode] === value) {
|
226
222
|
return charCode | 0;
|
227
223
|
}
|
@@ -229,11 +225,13 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
229
225
|
|
230
226
|
return -1;
|
231
227
|
},
|
232
|
-
|
228
|
+
|
229
|
+
amend(map) {
|
233
230
|
for (var charCode in map) {
|
234
231
|
this._map[charCode] = map[charCode];
|
235
232
|
}
|
236
233
|
}
|
234
|
+
|
237
235
|
};
|
238
236
|
return ToUnicodeMap;
|
239
237
|
}();
|
@@ -251,27 +249,32 @@ var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
|
251
249
|
return this.lastChar + 1 - this.firstChar;
|
252
250
|
},
|
253
251
|
|
254
|
-
forEach
|
252
|
+
forEach(callback) {
|
255
253
|
for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
|
256
254
|
callback(i, i);
|
257
255
|
}
|
258
256
|
},
|
259
|
-
|
257
|
+
|
258
|
+
has(i) {
|
260
259
|
return this.firstChar <= i && i <= this.lastChar;
|
261
260
|
},
|
262
|
-
|
261
|
+
|
262
|
+
get(i) {
|
263
263
|
if (this.firstChar <= i && i <= this.lastChar) {
|
264
264
|
return String.fromCharCode(i);
|
265
265
|
}
|
266
266
|
|
267
267
|
return undefined;
|
268
268
|
},
|
269
|
-
|
269
|
+
|
270
|
+
charCodeOf(v) {
|
270
271
|
return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
|
271
272
|
},
|
272
|
-
|
273
|
-
|
273
|
+
|
274
|
+
amend(map) {
|
275
|
+
(0, _util.unreachable)("Should not call amend()");
|
274
276
|
}
|
277
|
+
|
275
278
|
};
|
276
279
|
return IdentityToUnicodeMap;
|
277
280
|
}();
|
@@ -280,15 +283,15 @@ exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
|
|
280
283
|
|
281
284
|
var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
282
285
|
function writeInt16(dest, offset, num) {
|
283
|
-
dest[offset] = num >> 8 &
|
284
|
-
dest[offset + 1] = num &
|
286
|
+
dest[offset] = num >> 8 & 0xff;
|
287
|
+
dest[offset + 1] = num & 0xff;
|
285
288
|
}
|
286
289
|
|
287
290
|
function writeInt32(dest, offset, num) {
|
288
|
-
dest[offset] = num >> 24 &
|
289
|
-
dest[offset + 1] = num >> 16 &
|
290
|
-
dest[offset + 2] = num >> 8 &
|
291
|
-
dest[offset + 3] = num &
|
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;
|
292
295
|
}
|
293
296
|
|
294
297
|
function writeData(dest, offset, data) {
|
@@ -296,13 +299,13 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
296
299
|
|
297
300
|
if (data instanceof Uint8Array) {
|
298
301
|
dest.set(data, offset);
|
299
|
-
} else if (typeof data ===
|
302
|
+
} else if (typeof data === "string") {
|
300
303
|
for (i = 0, ii = data.length; i < ii; i++) {
|
301
|
-
dest[offset++] = data.charCodeAt(i) &
|
304
|
+
dest[offset++] = data.charCodeAt(i) & 0xff;
|
302
305
|
}
|
303
306
|
} else {
|
304
307
|
for (i = 0, ii = data.length; i < ii; i++) {
|
305
|
-
dest[offset++] = data[i] &
|
308
|
+
dest[offset++] = data[i] & 0xff;
|
306
309
|
}
|
307
310
|
}
|
308
311
|
}
|
@@ -356,14 +359,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
356
359
|
writeData(file, tableOffsets[i], table);
|
357
360
|
}
|
358
361
|
|
359
|
-
if (sfnt ===
|
362
|
+
if (sfnt === "true") {
|
360
363
|
sfnt = (0, _util.string32)(0x00010000);
|
361
364
|
}
|
362
365
|
|
363
|
-
file[0] = sfnt.charCodeAt(0) &
|
364
|
-
file[1] = sfnt.charCodeAt(1) &
|
365
|
-
file[2] = sfnt.charCodeAt(2) &
|
366
|
-
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;
|
367
370
|
writeInt16(file, 4, numTables);
|
368
371
|
var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
|
369
372
|
writeInt16(file, 6, searchParams.range);
|
@@ -373,14 +376,14 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
373
376
|
|
374
377
|
for (i = 0; i < numTables; i++) {
|
375
378
|
tableName = tablesNames[i];
|
376
|
-
file[offset] = tableName.charCodeAt(0) &
|
377
|
-
file[offset + 1] = tableName.charCodeAt(1) &
|
378
|
-
file[offset + 2] = tableName.charCodeAt(2) &
|
379
|
-
file[offset + 3] = tableName.charCodeAt(3) &
|
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;
|
380
383
|
var checksum = 0;
|
381
384
|
|
382
385
|
for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
383
|
-
var quad = (0,
|
386
|
+
var quad = (0, _core_utils.readUint32)(file, j);
|
384
387
|
checksum = checksum + quad >>> 0;
|
385
388
|
}
|
386
389
|
|
@@ -394,7 +397,7 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
394
397
|
},
|
395
398
|
addTable: function OpenTypeFileBuilder_addTable(tag, data) {
|
396
399
|
if (tag in this.tables) {
|
397
|
-
throw new Error(
|
400
|
+
throw new Error("Table " + tag + " already exists");
|
398
401
|
}
|
399
402
|
|
400
403
|
this.tables[tag] = data;
|
@@ -409,7 +412,6 @@ var Font = function FontClosure() {
|
|
409
412
|
this.name = name;
|
410
413
|
this.loadedName = properties.loadedName;
|
411
414
|
this.isType3Font = properties.isType3Font;
|
412
|
-
this.sizes = [];
|
413
415
|
this.missingFile = false;
|
414
416
|
this.glyphCache = Object.create(null);
|
415
417
|
this.isSerifFont = !!(properties.flags & FontFlags.Serif);
|
@@ -419,12 +421,19 @@ var Font = function FontClosure() {
|
|
419
421
|
var subtype = properties.subtype;
|
420
422
|
this.type = type;
|
421
423
|
this.subtype = subtype;
|
422
|
-
|
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;
|
423
433
|
this.differences = properties.differences;
|
424
434
|
this.widths = properties.widths;
|
425
435
|
this.defaultWidth = properties.defaultWidth;
|
426
436
|
this.composite = properties.composite;
|
427
|
-
this.wideChars = properties.wideChars;
|
428
437
|
this.cMap = properties.cMap;
|
429
438
|
this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
|
430
439
|
this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
|
@@ -435,7 +444,7 @@ var Font = function FontClosure() {
|
|
435
444
|
this.fallbackToUnicode = properties.fallbackToUnicode || new ToUnicodeMap();
|
436
445
|
this.toFontChar = [];
|
437
446
|
|
438
|
-
if (properties.type ===
|
447
|
+
if (properties.type === "Type3") {
|
439
448
|
for (charCode = 0; charCode < 256; charCode++) {
|
440
449
|
this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
|
441
450
|
}
|
@@ -445,7 +454,7 @@ var Font = function FontClosure() {
|
|
445
454
|
}
|
446
455
|
|
447
456
|
this.cidEncoding = properties.cidEncoding;
|
448
|
-
this.vertical = properties.vertical;
|
457
|
+
this.vertical = !!properties.vertical;
|
449
458
|
|
450
459
|
if (this.vertical) {
|
451
460
|
this.vmetrics = properties.vmetrics;
|
@@ -454,54 +463,49 @@ var Font = function FontClosure() {
|
|
454
463
|
|
455
464
|
if (!file || file.isEmpty) {
|
456
465
|
if (file) {
|
457
|
-
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName +
|
466
|
+
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ")");
|
458
467
|
}
|
459
468
|
|
460
469
|
this.fallbackToSystemFont();
|
461
470
|
return;
|
462
471
|
}
|
463
472
|
|
464
|
-
|
465
|
-
|
466
|
-
var _getFontFileType2 = _slicedToArray(_getFontFileType, 2);
|
467
|
-
|
468
|
-
type = _getFontFileType2[0];
|
469
|
-
subtype = _getFontFileType2[1];
|
473
|
+
[type, subtype] = getFontFileType(file, properties);
|
470
474
|
|
471
475
|
if (type !== this.type || subtype !== this.subtype) {
|
472
|
-
(0, _util.info)(
|
476
|
+
(0, _util.info)("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`);
|
473
477
|
}
|
474
478
|
|
475
479
|
try {
|
476
480
|
var data;
|
477
481
|
|
478
482
|
switch (type) {
|
479
|
-
case
|
480
|
-
(0, _util.info)(
|
483
|
+
case "MMType1":
|
484
|
+
(0, _util.info)("MMType1 font (" + name + "), falling back to Type1.");
|
481
485
|
|
482
|
-
case
|
483
|
-
case
|
484
|
-
this.mimetype =
|
485
|
-
var cff = subtype ===
|
486
|
+
case "Type1":
|
487
|
+
case "CIDFontType0":
|
488
|
+
this.mimetype = "font/opentype";
|
489
|
+
var cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
|
486
490
|
adjustWidths(properties);
|
487
491
|
data = this.convert(name, cff, properties);
|
488
492
|
break;
|
489
493
|
|
490
|
-
case
|
491
|
-
case
|
492
|
-
case
|
493
|
-
this.mimetype =
|
494
|
+
case "OpenType":
|
495
|
+
case "TrueType":
|
496
|
+
case "CIDFontType2":
|
497
|
+
this.mimetype = "font/opentype";
|
494
498
|
data = this.checkAndRepair(name, file, properties);
|
495
499
|
|
496
500
|
if (this.isOpenType) {
|
497
501
|
adjustWidths(properties);
|
498
|
-
type =
|
502
|
+
type = "OpenType";
|
499
503
|
}
|
500
504
|
|
501
505
|
break;
|
502
506
|
|
503
507
|
default:
|
504
|
-
throw new _util.FormatError(
|
508
|
+
throw new _util.FormatError(`Font ${type} is not supported`);
|
505
509
|
}
|
506
510
|
} catch (e) {
|
507
511
|
(0, _util.warn)(e);
|
@@ -515,17 +519,9 @@ var Font = function FontClosure() {
|
|
515
519
|
this.widths = properties.widths;
|
516
520
|
this.defaultWidth = properties.defaultWidth;
|
517
521
|
this.toUnicode = properties.toUnicode;
|
518
|
-
this.encoding = properties.baseEncoding;
|
519
522
|
this.seacMap = properties.seacMap;
|
520
523
|
}
|
521
524
|
|
522
|
-
Font.getFontID = function () {
|
523
|
-
var ID = 1;
|
524
|
-
return function Font_getFontID() {
|
525
|
-
return String(ID++);
|
526
|
-
};
|
527
|
-
}();
|
528
|
-
|
529
525
|
function int16(b0, b1) {
|
530
526
|
return (b0 << 8) + b1;
|
531
527
|
}
|
@@ -549,23 +545,28 @@ var Font = function FontClosure() {
|
|
549
545
|
}
|
550
546
|
|
551
547
|
function safeString16(value) {
|
552
|
-
|
548
|
+
if (value > 0x7fff) {
|
549
|
+
value = 0x7fff;
|
550
|
+
} else if (value < -0x8000) {
|
551
|
+
value = -0x8000;
|
552
|
+
}
|
553
|
+
|
553
554
|
return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
|
554
555
|
}
|
555
556
|
|
556
557
|
function isTrueTypeFile(file) {
|
557
558
|
var header = file.peekBytes(4);
|
558
|
-
return (0,
|
559
|
+
return (0, _core_utils.readUint32)(header, 0) === 0x00010000 || (0, _util.bytesToString)(header) === "true";
|
559
560
|
}
|
560
561
|
|
561
562
|
function isTrueTypeCollectionFile(file) {
|
562
|
-
|
563
|
-
return (0, _util.bytesToString)(header) ===
|
563
|
+
const header = file.peekBytes(4);
|
564
|
+
return (0, _util.bytesToString)(header) === "ttcf";
|
564
565
|
}
|
565
566
|
|
566
567
|
function isOpenTypeFile(file) {
|
567
568
|
var header = file.peekBytes(4);
|
568
|
-
return (0, _util.bytesToString)(header) ===
|
569
|
+
return (0, _util.bytesToString)(header) === "OTTO";
|
569
570
|
}
|
570
571
|
|
571
572
|
function isType1File(file) {
|
@@ -583,7 +584,7 @@ var Font = function FontClosure() {
|
|
583
584
|
}
|
584
585
|
|
585
586
|
function isCFFFile(file) {
|
586
|
-
|
587
|
+
const header = file.peekBytes(4);
|
587
588
|
|
588
589
|
if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
|
589
590
|
return true;
|
@@ -592,40 +593,41 @@ var Font = function FontClosure() {
|
|
592
593
|
return false;
|
593
594
|
}
|
594
595
|
|
595
|
-
function getFontFileType(file,
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
596
|
+
function getFontFileType(file, {
|
597
|
+
type,
|
598
|
+
subtype,
|
599
|
+
composite
|
600
|
+
}) {
|
601
|
+
let fileType, fileSubtype;
|
600
602
|
|
601
603
|
if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
|
602
604
|
if (composite) {
|
603
|
-
fileType =
|
605
|
+
fileType = "CIDFontType2";
|
604
606
|
} else {
|
605
|
-
fileType =
|
607
|
+
fileType = "TrueType";
|
606
608
|
}
|
607
609
|
} else if (isOpenTypeFile(file)) {
|
608
610
|
if (composite) {
|
609
|
-
fileType =
|
611
|
+
fileType = "CIDFontType2";
|
610
612
|
} else {
|
611
|
-
fileType =
|
613
|
+
fileType = "OpenType";
|
612
614
|
}
|
613
615
|
} else if (isType1File(file)) {
|
614
616
|
if (composite) {
|
615
|
-
fileType =
|
617
|
+
fileType = "CIDFontType0";
|
616
618
|
} else {
|
617
|
-
fileType = type ===
|
619
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
618
620
|
}
|
619
621
|
} else if (isCFFFile(file)) {
|
620
622
|
if (composite) {
|
621
|
-
fileType =
|
622
|
-
fileSubtype =
|
623
|
+
fileType = "CIDFontType0";
|
624
|
+
fileSubtype = "CIDFontType0C";
|
623
625
|
} else {
|
624
|
-
fileType = type ===
|
625
|
-
fileSubtype =
|
626
|
+
fileType = type === "MMType1" ? "MMType1" : "Type1";
|
627
|
+
fileSubtype = "Type1C";
|
626
628
|
}
|
627
629
|
} else {
|
628
|
-
(0, _util.warn)(
|
630
|
+
(0, _util.warn)("getFontFileType: Unable to detect correct font file Type/Subtype.");
|
629
631
|
fileType = type;
|
630
632
|
fileSubtype = subtype;
|
631
633
|
}
|
@@ -675,7 +677,7 @@ var Font = function FontClosure() {
|
|
675
677
|
privateUseAreaIndex++;
|
676
678
|
|
677
679
|
if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
|
678
|
-
(0, _util.warn)(
|
680
|
+
(0, _util.warn)("Ran out of space in font private use area.");
|
679
681
|
break;
|
680
682
|
}
|
681
683
|
|
@@ -694,9 +696,9 @@ var Font = function FontClosure() {
|
|
694
696
|
}
|
695
697
|
|
696
698
|
return {
|
697
|
-
toFontChar
|
699
|
+
toFontChar,
|
698
700
|
charCodeToGlyphId: newMap,
|
699
|
-
nextAvailableFontCharCode
|
701
|
+
nextAvailableFontCharCode
|
700
702
|
};
|
701
703
|
}
|
702
704
|
|
@@ -738,7 +740,7 @@ var Font = function FontClosure() {
|
|
738
740
|
++end;
|
739
741
|
++n;
|
740
742
|
|
741
|
-
if (end ===
|
743
|
+
if (end === 0xffff) {
|
742
744
|
break;
|
743
745
|
}
|
744
746
|
}
|
@@ -751,30 +753,30 @@ var Font = function FontClosure() {
|
|
751
753
|
|
752
754
|
function createCmapTable(glyphs, numGlyphs) {
|
753
755
|
var ranges = getRanges(glyphs, numGlyphs);
|
754
|
-
var numTables = ranges[ranges.length - 1][1] >
|
755
|
-
var cmap =
|
756
|
+
var numTables = ranges[ranges.length - 1][1] > 0xffff ? 2 : 1;
|
757
|
+
var cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + (0, _util.string32)(4 + numTables * 8);
|
756
758
|
var i, ii, j, jj;
|
757
759
|
|
758
760
|
for (i = ranges.length - 1; i >= 0; --i) {
|
759
|
-
if (ranges[i][0] <=
|
761
|
+
if (ranges[i][0] <= 0xffff) {
|
760
762
|
break;
|
761
763
|
}
|
762
764
|
}
|
763
765
|
|
764
766
|
var bmpLength = i + 1;
|
765
767
|
|
766
|
-
if (ranges[i][0] <
|
767
|
-
ranges[i][1] =
|
768
|
+
if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
|
769
|
+
ranges[i][1] = 0xfffe;
|
768
770
|
}
|
769
771
|
|
770
|
-
var trailingRangesCount = ranges[i][1] <
|
772
|
+
var trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
|
771
773
|
var segCount = bmpLength + trailingRangesCount;
|
772
774
|
var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
|
773
|
-
var startCount =
|
774
|
-
var endCount =
|
775
|
-
var idDeltas =
|
776
|
-
var idRangeOffsets =
|
777
|
-
var glyphsIds =
|
775
|
+
var startCount = "";
|
776
|
+
var endCount = "";
|
777
|
+
var idDeltas = "";
|
778
|
+
var idRangeOffsets = "";
|
779
|
+
var glyphsIds = "";
|
778
780
|
var bias = 0;
|
779
781
|
var range, start, end, codes;
|
780
782
|
|
@@ -805,25 +807,25 @@ var Font = function FontClosure() {
|
|
805
807
|
}
|
806
808
|
} else {
|
807
809
|
var startCode = codes[0];
|
808
|
-
idDeltas += string16(startCode - start &
|
810
|
+
idDeltas += string16(startCode - start & 0xffff);
|
809
811
|
idRangeOffsets += string16(0);
|
810
812
|
}
|
811
813
|
}
|
812
814
|
|
813
815
|
if (trailingRangesCount > 0) {
|
814
|
-
endCount +=
|
815
|
-
startCount +=
|
816
|
-
idDeltas +=
|
817
|
-
idRangeOffsets +=
|
816
|
+
endCount += "\xFF\xFF";
|
817
|
+
startCount += "\xFF\xFF";
|
818
|
+
idDeltas += "\x00\x01";
|
819
|
+
idRangeOffsets += "\x00\x00";
|
818
820
|
}
|
819
821
|
|
820
|
-
var format314 =
|
821
|
-
var format31012 =
|
822
|
-
var header31012 =
|
822
|
+
var format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds;
|
823
|
+
var format31012 = "";
|
824
|
+
var header31012 = "";
|
823
825
|
|
824
826
|
if (numTables > 1) {
|
825
|
-
cmap +=
|
826
|
-
format31012 =
|
827
|
+
cmap += "\x00\x03" + "\x00\x0A" + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);
|
828
|
+
format31012 = "";
|
827
829
|
|
828
830
|
for (i = 0, ii = ranges.length; i < ii; i++) {
|
829
831
|
range = ranges[i];
|
@@ -843,31 +845,31 @@ var Font = function FontClosure() {
|
|
843
845
|
format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);
|
844
846
|
}
|
845
847
|
|
846
|
-
header31012 =
|
848
|
+
header31012 = "\x00\x0C" + "\x00\x00" + (0, _util.string32)(format31012.length + 16) + "\x00\x00\x00\x00" + (0, _util.string32)(format31012.length / 12);
|
847
849
|
}
|
848
850
|
|
849
|
-
return cmap +
|
851
|
+
return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
|
850
852
|
}
|
851
853
|
|
852
|
-
function validateOS2Table(os2) {
|
853
|
-
|
854
|
-
var version =
|
855
|
-
|
856
|
-
var selection =
|
854
|
+
function validateOS2Table(os2, file) {
|
855
|
+
file.pos = (file.start || 0) + os2.offset;
|
856
|
+
var version = file.getUint16();
|
857
|
+
file.skip(60);
|
858
|
+
var selection = file.getUint16();
|
857
859
|
|
858
860
|
if (version < 4 && selection & 0x0300) {
|
859
861
|
return false;
|
860
862
|
}
|
861
863
|
|
862
|
-
var firstChar =
|
863
|
-
var lastChar =
|
864
|
+
var firstChar = file.getUint16();
|
865
|
+
var lastChar = file.getUint16();
|
864
866
|
|
865
867
|
if (firstChar > lastChar) {
|
866
868
|
return false;
|
867
869
|
}
|
868
870
|
|
869
|
-
|
870
|
-
var usWinAscent =
|
871
|
+
file.skip(6);
|
872
|
+
var usWinAscent = file.getUint16();
|
871
873
|
|
872
874
|
if (usWinAscent === 0) {
|
873
875
|
return false;
|
@@ -915,12 +917,12 @@ var Font = function FontClosure() {
|
|
915
917
|
} else if (position < 123) {
|
916
918
|
ulUnicodeRange4 |= 1 << position - 96;
|
917
919
|
} else {
|
918
|
-
throw new _util.FormatError(
|
920
|
+
throw new _util.FormatError("Unicode ranges Bits > 123 are reserved for internal usage");
|
919
921
|
}
|
920
922
|
}
|
921
923
|
|
922
|
-
if (lastCharIndex >
|
923
|
-
lastCharIndex =
|
924
|
+
if (lastCharIndex > 0xffff) {
|
925
|
+
lastCharIndex = 0xffff;
|
924
926
|
}
|
925
927
|
} else {
|
926
928
|
firstCharIndex = 0;
|
@@ -939,12 +941,12 @@ var Font = function FontClosure() {
|
|
939
941
|
|
940
942
|
var winAscent = override.yMax || typoAscent;
|
941
943
|
var winDescent = -override.yMin || -typoDescent;
|
942
|
-
return
|
944
|
+
return "\x00\x03" + "\x02\x24" + "\x01\xF4" + "\x00\x05" + "\x00\x00" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x00\x8C" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x01\xDF" + "\x00\x31" + "\x01\x02" + "\x00\x00" + "\x00\x00\x06" + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + "\x00\x00\x00\x00\x00\x00" + (0, _util.string32)(ulUnicodeRange1) + (0, _util.string32)(ulUnicodeRange2) + (0, _util.string32)(ulUnicodeRange3) + (0, _util.string32)(ulUnicodeRange4) + "\x2A\x32\x31\x2A" + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + "\x00\x64" + string16(winAscent) + string16(winDescent) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + "\x00\x03";
|
943
945
|
}
|
944
946
|
|
945
947
|
function createPostTable(properties) {
|
946
|
-
var angle = Math.floor(properties.italicAngle *
|
947
|
-
return
|
948
|
+
var angle = Math.floor(properties.italicAngle * 2 ** 16);
|
949
|
+
return "\x00\x03\x00\x00" + (0, _util.string32)(angle) + "\x00\x00" + "\x00\x00" + (0, _util.string32)(properties.fixedPitch) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00";
|
948
950
|
}
|
949
951
|
|
950
952
|
function createNameTable(name, proto) {
|
@@ -952,7 +954,7 @@ var Font = function FontClosure() {
|
|
952
954
|
proto = [[], []];
|
953
955
|
}
|
954
956
|
|
955
|
-
var strings = [proto[0][0] ||
|
957
|
+
var strings = [proto[0][0] || "Original licence", proto[0][1] || name, proto[0][2] || "Unknown", proto[0][3] || "uniqueID", proto[0][4] || name, proto[0][5] || "Version 0.11", proto[0][6] || "", proto[0][7] || "Unknown", proto[0][8] || "Unknown", proto[0][9] || "Unknown"];
|
956
958
|
var stringsUnicode = [];
|
957
959
|
var i, ii, j, jj, str;
|
958
960
|
|
@@ -964,15 +966,15 @@ var Font = function FontClosure() {
|
|
964
966
|
strBufUnicode.push(string16(str.charCodeAt(j)));
|
965
967
|
}
|
966
968
|
|
967
|
-
stringsUnicode.push(strBufUnicode.join(
|
969
|
+
stringsUnicode.push(strBufUnicode.join(""));
|
968
970
|
}
|
969
971
|
|
970
972
|
var names = [strings, stringsUnicode];
|
971
|
-
var platforms = [
|
972
|
-
var encodings = [
|
973
|
-
var languages = [
|
973
|
+
var platforms = ["\x00\x01", "\x00\x03"];
|
974
|
+
var encodings = ["\x00\x00", "\x00\x01"];
|
975
|
+
var languages = ["\x00\x00", "\x04\x09"];
|
974
976
|
var namesRecordCount = strings.length * platforms.length;
|
975
|
-
var nameTable =
|
977
|
+
var nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
|
976
978
|
var strOffset = 0;
|
977
979
|
|
978
980
|
for (i = 0, ii = platforms.length; i < ii; i++) {
|
@@ -986,7 +988,7 @@ var Font = function FontClosure() {
|
|
986
988
|
}
|
987
989
|
}
|
988
990
|
|
989
|
-
nameTable += strings.join(
|
991
|
+
nameTable += strings.join("") + stringsUnicode.join("");
|
990
992
|
return nameTable;
|
991
993
|
}
|
992
994
|
|
@@ -994,35 +996,36 @@ var Font = function FontClosure() {
|
|
994
996
|
name: null,
|
995
997
|
font: null,
|
996
998
|
mimetype: null,
|
997
|
-
encoding: null,
|
998
999
|
disableFontFace: false,
|
999
1000
|
|
1000
1001
|
get renderer() {
|
1001
1002
|
var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
|
1002
1003
|
|
1003
|
-
return (0, _util.shadow)(this,
|
1004
|
+
return (0, _util.shadow)(this, "renderer", renderer);
|
1004
1005
|
},
|
1005
1006
|
|
1006
|
-
exportData
|
1007
|
-
|
1007
|
+
exportData(extraProperties = false) {
|
1008
|
+
const exportDataProperties = extraProperties ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] : EXPORT_DATA_PROPERTIES;
|
1009
|
+
const data = Object.create(null);
|
1010
|
+
let property, value;
|
1011
|
+
|
1012
|
+
for (property of exportDataProperties) {
|
1013
|
+
value = this[property];
|
1008
1014
|
|
1009
|
-
|
1010
|
-
|
1011
|
-
data[i] = this[i];
|
1015
|
+
if (value !== undefined) {
|
1016
|
+
data[property] = value;
|
1012
1017
|
}
|
1013
1018
|
}
|
1014
1019
|
|
1015
1020
|
return data;
|
1016
1021
|
},
|
1017
|
-
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
1018
|
-
var _this = this;
|
1019
1022
|
|
1023
|
+
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
1020
1024
|
this.missingFile = true;
|
1021
|
-
var charCode, unicode;
|
1022
1025
|
var name = this.name;
|
1023
1026
|
var type = this.type;
|
1024
1027
|
var subtype = this.subtype;
|
1025
|
-
|
1028
|
+
let fontName = name.replace(/[,_]/g, "-").replace(/\s/g, "");
|
1026
1029
|
var stdFontMap = (0, _standard_fonts.getStdFontMap)(),
|
1027
1030
|
nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();
|
1028
1031
|
var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
|
@@ -1032,24 +1035,24 @@ var Font = function FontClosure() {
|
|
1032
1035
|
this.black = name.search(/Black/g) !== -1;
|
1033
1036
|
this.remeasure = Object.keys(this.widths).length > 0;
|
1034
1037
|
|
1035
|
-
if (isStandardFont && type ===
|
1036
|
-
|
1037
|
-
|
1038
|
+
if (isStandardFont && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
|
1039
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1040
|
+
const map = [];
|
1038
1041
|
|
1039
|
-
for (charCode in GlyphMapForStandardFonts) {
|
1042
|
+
for (const charCode in GlyphMapForStandardFonts) {
|
1040
1043
|
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
1041
1044
|
}
|
1042
1045
|
|
1043
1046
|
if (/Arial-?Black/i.test(name)) {
|
1044
1047
|
var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();
|
1045
1048
|
|
1046
|
-
for (charCode in SupplementalGlyphMapForArialBlack) {
|
1049
|
+
for (const charCode in SupplementalGlyphMapForArialBlack) {
|
1047
1050
|
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
|
1048
1051
|
}
|
1049
1052
|
} else if (/Calibri/i.test(name)) {
|
1050
|
-
|
1053
|
+
const SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
|
1051
1054
|
|
1052
|
-
for (charCode in SupplementalGlyphMapForCalibri) {
|
1055
|
+
for (const charCode in SupplementalGlyphMapForCalibri) {
|
1053
1056
|
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
|
1054
1057
|
}
|
1055
1058
|
}
|
@@ -1068,47 +1071,60 @@ var Font = function FontClosure() {
|
|
1068
1071
|
this.toFontChar = buildToFontChar(_encodings.SymbolSetEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1069
1072
|
} else if (/Dingbats/i.test(fontName)) {
|
1070
1073
|
if (/Wingdings/i.test(name)) {
|
1071
|
-
(0, _util.warn)(
|
1074
|
+
(0, _util.warn)("Non-embedded Wingdings font, falling back to ZapfDingbats.");
|
1072
1075
|
}
|
1073
1076
|
|
1074
1077
|
this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);
|
1075
1078
|
} else if (isStandardFont) {
|
1076
1079
|
this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
1077
1080
|
} else {
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1081
|
+
const glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
1082
|
+
const map = [];
|
1083
|
+
this.toUnicode.forEach((charCode, unicodeCharCode) => {
|
1084
|
+
if (!this.composite) {
|
1085
|
+
var glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
|
1086
|
+
const unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
1083
1087
|
|
1084
1088
|
if (unicode !== -1) {
|
1085
1089
|
unicodeCharCode = unicode;
|
1086
1090
|
}
|
1087
1091
|
}
|
1088
1092
|
|
1089
|
-
|
1093
|
+
map[+charCode] = unicodeCharCode;
|
1090
1094
|
});
|
1095
|
+
|
1096
|
+
if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
|
1097
|
+
if (/Verdana/i.test(name)) {
|
1098
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
1099
|
+
|
1100
|
+
for (const charCode in GlyphMapForStandardFonts) {
|
1101
|
+
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
1102
|
+
}
|
1103
|
+
}
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
this.toFontChar = map;
|
1091
1107
|
}
|
1092
1108
|
|
1093
|
-
this.loadedName = fontName.split(
|
1109
|
+
this.loadedName = fontName.split("-")[0];
|
1094
1110
|
this.fontType = getFontType(type, subtype);
|
1095
1111
|
},
|
1096
1112
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
1097
|
-
|
1113
|
+
const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
|
1098
1114
|
|
1099
1115
|
function readTables(file, numTables) {
|
1100
|
-
|
1101
|
-
tables[
|
1102
|
-
tables
|
1103
|
-
tables
|
1104
|
-
tables
|
1105
|
-
tables
|
1106
|
-
tables
|
1107
|
-
tables
|
1108
|
-
tables
|
1109
|
-
|
1110
|
-
for (
|
1111
|
-
|
1116
|
+
const tables = Object.create(null);
|
1117
|
+
tables["OS/2"] = null;
|
1118
|
+
tables.cmap = null;
|
1119
|
+
tables.head = null;
|
1120
|
+
tables.hhea = null;
|
1121
|
+
tables.hmtx = null;
|
1122
|
+
tables.maxp = null;
|
1123
|
+
tables.name = null;
|
1124
|
+
tables.post = null;
|
1125
|
+
|
1126
|
+
for (let i = 0; i < numTables; i++) {
|
1127
|
+
const table = readTableEntry(file);
|
1112
1128
|
|
1113
1129
|
if (!VALID_TABLES.includes(table.tag)) {
|
1114
1130
|
continue;
|
@@ -1135,17 +1151,17 @@ var Font = function FontClosure() {
|
|
1135
1151
|
var data = file.getBytes(length);
|
1136
1152
|
file.pos = previousPosition;
|
1137
1153
|
|
1138
|
-
if (tag ===
|
1154
|
+
if (tag === "head") {
|
1139
1155
|
data[8] = data[9] = data[10] = data[11] = 0;
|
1140
1156
|
data[17] |= 0x20;
|
1141
1157
|
}
|
1142
1158
|
|
1143
1159
|
return {
|
1144
|
-
tag
|
1145
|
-
checksum
|
1146
|
-
length
|
1147
|
-
offset
|
1148
|
-
data
|
1160
|
+
tag,
|
1161
|
+
checksum,
|
1162
|
+
length,
|
1163
|
+
offset,
|
1164
|
+
data
|
1149
1165
|
};
|
1150
1166
|
}
|
1151
1167
|
|
@@ -1160,23 +1176,23 @@ var Font = function FontClosure() {
|
|
1160
1176
|
}
|
1161
1177
|
|
1162
1178
|
function readTrueTypeCollectionHeader(ttc) {
|
1163
|
-
|
1164
|
-
(0, _util.assert)(ttcTag ===
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
for (
|
1179
|
+
const ttcTag = (0, _util.bytesToString)(ttc.getBytes(4));
|
1180
|
+
(0, _util.assert)(ttcTag === "ttcf", "Must be a TrueType Collection font.");
|
1181
|
+
const majorVersion = ttc.getUint16();
|
1182
|
+
const minorVersion = ttc.getUint16();
|
1183
|
+
const numFonts = ttc.getInt32() >>> 0;
|
1184
|
+
const offsetTable = [];
|
1185
|
+
|
1186
|
+
for (let i = 0; i < numFonts; i++) {
|
1171
1187
|
offsetTable.push(ttc.getInt32() >>> 0);
|
1172
1188
|
}
|
1173
1189
|
|
1174
|
-
|
1175
|
-
ttcTag
|
1176
|
-
majorVersion
|
1177
|
-
minorVersion
|
1178
|
-
numFonts
|
1179
|
-
offsetTable
|
1190
|
+
const header = {
|
1191
|
+
ttcTag,
|
1192
|
+
majorVersion,
|
1193
|
+
minorVersion,
|
1194
|
+
numFonts,
|
1195
|
+
offsetTable
|
1180
1196
|
};
|
1181
1197
|
|
1182
1198
|
switch (majorVersion) {
|
@@ -1190,30 +1206,31 @@ var Font = function FontClosure() {
|
|
1190
1206
|
return header;
|
1191
1207
|
}
|
1192
1208
|
|
1193
|
-
throw new _util.FormatError(
|
1209
|
+
throw new _util.FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
|
1194
1210
|
}
|
1195
1211
|
|
1196
1212
|
function readTrueTypeCollectionData(ttc, fontName) {
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1213
|
+
const {
|
1214
|
+
numFonts,
|
1215
|
+
offsetTable
|
1216
|
+
} = readTrueTypeCollectionHeader(ttc);
|
1200
1217
|
|
1201
|
-
for (
|
1218
|
+
for (let i = 0; i < numFonts; i++) {
|
1202
1219
|
ttc.pos = (ttc.start || 0) + offsetTable[i];
|
1203
|
-
|
1204
|
-
|
1220
|
+
const potentialHeader = readOpenTypeHeader(ttc);
|
1221
|
+
const potentialTables = readTables(ttc, potentialHeader.numTables);
|
1205
1222
|
|
1206
|
-
if (!potentialTables
|
1223
|
+
if (!potentialTables.name) {
|
1207
1224
|
throw new _util.FormatError('TrueType Collection font must contain a "name" table.');
|
1208
1225
|
}
|
1209
1226
|
|
1210
|
-
|
1227
|
+
const nameTable = readNameTable(potentialTables.name);
|
1211
1228
|
|
1212
|
-
for (
|
1213
|
-
for (
|
1214
|
-
|
1229
|
+
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
1230
|
+
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
1231
|
+
const nameEntry = nameTable[j][k];
|
1215
1232
|
|
1216
|
-
if (nameEntry && nameEntry.replace(/\s/g,
|
1233
|
+
if (nameEntry && nameEntry.replace(/\s/g, "") === fontName) {
|
1217
1234
|
return {
|
1218
1235
|
header: potentialHeader,
|
1219
1236
|
tables: potentialTables
|
@@ -1223,12 +1240,12 @@ var Font = function FontClosure() {
|
|
1223
1240
|
}
|
1224
1241
|
}
|
1225
1242
|
|
1226
|
-
throw new _util.FormatError(
|
1243
|
+
throw new _util.FormatError(`TrueType Collection does not contain "${fontName}" font.`);
|
1227
1244
|
}
|
1228
1245
|
|
1229
|
-
function readCmapTable(cmap,
|
1246
|
+
function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
|
1230
1247
|
if (!cmap) {
|
1231
|
-
(0, _util.warn)(
|
1248
|
+
(0, _util.warn)("No cmap table available.");
|
1232
1249
|
return {
|
1233
1250
|
platformId: -1,
|
1234
1251
|
encodingId: -1,
|
@@ -1238,24 +1255,24 @@ var Font = function FontClosure() {
|
|
1238
1255
|
}
|
1239
1256
|
|
1240
1257
|
var segment;
|
1241
|
-
var start = (
|
1242
|
-
|
1243
|
-
|
1244
|
-
var numTables =
|
1258
|
+
var start = (file.start ? file.start : 0) + cmap.offset;
|
1259
|
+
file.pos = start;
|
1260
|
+
file.skip(2);
|
1261
|
+
var numTables = file.getUint16();
|
1245
1262
|
var potentialTable;
|
1246
1263
|
var canBreak = false;
|
1247
1264
|
|
1248
1265
|
for (var i = 0; i < numTables; i++) {
|
1249
|
-
var platformId =
|
1250
|
-
var encodingId =
|
1251
|
-
var offset =
|
1266
|
+
var platformId = file.getUint16();
|
1267
|
+
var encodingId = file.getUint16();
|
1268
|
+
var offset = file.getInt32() >>> 0;
|
1252
1269
|
var useTable = false;
|
1253
1270
|
|
1254
1271
|
if (potentialTable && potentialTable.platformId === platformId && potentialTable.encodingId === encodingId) {
|
1255
1272
|
continue;
|
1256
1273
|
}
|
1257
1274
|
|
1258
|
-
if (platformId === 0 && encodingId === 0) {
|
1275
|
+
if (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 3)) {
|
1259
1276
|
useTable = true;
|
1260
1277
|
} else if (platformId === 1 && encodingId === 0) {
|
1261
1278
|
useTable = true;
|
@@ -1272,9 +1289,9 @@ var Font = function FontClosure() {
|
|
1272
1289
|
|
1273
1290
|
if (useTable) {
|
1274
1291
|
potentialTable = {
|
1275
|
-
platformId
|
1276
|
-
encodingId
|
1277
|
-
offset
|
1292
|
+
platformId,
|
1293
|
+
encodingId,
|
1294
|
+
offset
|
1278
1295
|
};
|
1279
1296
|
}
|
1280
1297
|
|
@@ -1284,11 +1301,11 @@ var Font = function FontClosure() {
|
|
1284
1301
|
}
|
1285
1302
|
|
1286
1303
|
if (potentialTable) {
|
1287
|
-
|
1304
|
+
file.pos = start + potentialTable.offset;
|
1288
1305
|
}
|
1289
1306
|
|
1290
|
-
if (!potentialTable ||
|
1291
|
-
(0, _util.warn)(
|
1307
|
+
if (!potentialTable || file.peekByte() === -1) {
|
1308
|
+
(0, _util.warn)("Could not find a preferred cmap table.");
|
1292
1309
|
return {
|
1293
1310
|
platformId: -1,
|
1294
1311
|
encodingId: -1,
|
@@ -1297,16 +1314,15 @@ var Font = function FontClosure() {
|
|
1297
1314
|
};
|
1298
1315
|
}
|
1299
1316
|
|
1300
|
-
var format =
|
1301
|
-
|
1302
|
-
font.getUint16();
|
1317
|
+
var format = file.getUint16();
|
1318
|
+
file.skip(2 + 2);
|
1303
1319
|
var hasShortCmap = false;
|
1304
1320
|
var mappings = [];
|
1305
1321
|
var j, glyphId;
|
1306
1322
|
|
1307
1323
|
if (format === 0) {
|
1308
1324
|
for (j = 0; j < 256; j++) {
|
1309
|
-
var index =
|
1325
|
+
var index = file.getByte();
|
1310
1326
|
|
1311
1327
|
if (!index) {
|
1312
1328
|
continue;
|
@@ -1320,32 +1336,32 @@ var Font = function FontClosure() {
|
|
1320
1336
|
|
1321
1337
|
hasShortCmap = true;
|
1322
1338
|
} else if (format === 4) {
|
1323
|
-
var segCount =
|
1324
|
-
|
1339
|
+
var segCount = file.getUint16() >> 1;
|
1340
|
+
file.skip(6);
|
1325
1341
|
var segIndex,
|
1326
1342
|
segments = [];
|
1327
1343
|
|
1328
1344
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1329
1345
|
segments.push({
|
1330
|
-
end:
|
1346
|
+
end: file.getUint16()
|
1331
1347
|
});
|
1332
1348
|
}
|
1333
1349
|
|
1334
|
-
|
1350
|
+
file.skip(2);
|
1335
1351
|
|
1336
1352
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1337
|
-
segments[segIndex].start =
|
1353
|
+
segments[segIndex].start = file.getUint16();
|
1338
1354
|
}
|
1339
1355
|
|
1340
1356
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1341
|
-
segments[segIndex].delta =
|
1357
|
+
segments[segIndex].delta = file.getUint16();
|
1342
1358
|
}
|
1343
1359
|
|
1344
1360
|
var offsetsCount = 0;
|
1345
1361
|
|
1346
1362
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1347
1363
|
segment = segments[segIndex];
|
1348
|
-
var rangeOffset =
|
1364
|
+
var rangeOffset = file.getUint16();
|
1349
1365
|
|
1350
1366
|
if (!rangeOffset) {
|
1351
1367
|
segment.offsetIndex = -1;
|
@@ -1360,7 +1376,7 @@ var Font = function FontClosure() {
|
|
1360
1376
|
var offsets = [];
|
1361
1377
|
|
1362
1378
|
for (j = 0; j < offsetsCount; j++) {
|
1363
|
-
offsets.push(
|
1379
|
+
offsets.push(file.getUint16());
|
1364
1380
|
}
|
1365
1381
|
|
1366
1382
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
@@ -1371,32 +1387,32 @@ var Font = function FontClosure() {
|
|
1371
1387
|
offsetIndex = segment.offsetIndex;
|
1372
1388
|
|
1373
1389
|
for (j = start; j <= end; j++) {
|
1374
|
-
if (j ===
|
1390
|
+
if (j === 0xffff) {
|
1375
1391
|
continue;
|
1376
1392
|
}
|
1377
1393
|
|
1378
1394
|
glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
|
1379
|
-
glyphId = glyphId + delta &
|
1395
|
+
glyphId = glyphId + delta & 0xffff;
|
1380
1396
|
mappings.push({
|
1381
1397
|
charCode: j,
|
1382
|
-
glyphId
|
1398
|
+
glyphId
|
1383
1399
|
});
|
1384
1400
|
}
|
1385
1401
|
}
|
1386
1402
|
} else if (format === 6) {
|
1387
|
-
var firstCode =
|
1388
|
-
var entryCount =
|
1403
|
+
var firstCode = file.getUint16();
|
1404
|
+
var entryCount = file.getUint16();
|
1389
1405
|
|
1390
1406
|
for (j = 0; j < entryCount; j++) {
|
1391
|
-
glyphId =
|
1407
|
+
glyphId = file.getUint16();
|
1392
1408
|
var charCode = firstCode + j;
|
1393
1409
|
mappings.push({
|
1394
|
-
charCode
|
1395
|
-
glyphId
|
1410
|
+
charCode,
|
1411
|
+
glyphId
|
1396
1412
|
});
|
1397
1413
|
}
|
1398
1414
|
} else {
|
1399
|
-
(0, _util.warn)(
|
1415
|
+
(0, _util.warn)("cmap table has unsupported format: " + format);
|
1400
1416
|
return {
|
1401
1417
|
platformId: -1,
|
1402
1418
|
encodingId: -1,
|
@@ -1419,12 +1435,12 @@ var Font = function FontClosure() {
|
|
1419
1435
|
return {
|
1420
1436
|
platformId: potentialTable.platformId,
|
1421
1437
|
encodingId: potentialTable.encodingId,
|
1422
|
-
mappings
|
1423
|
-
hasShortCmap
|
1438
|
+
mappings,
|
1439
|
+
hasShortCmap
|
1424
1440
|
};
|
1425
1441
|
}
|
1426
1442
|
|
1427
|
-
function sanitizeMetrics(
|
1443
|
+
function sanitizeMetrics(file, header, metrics, numGlyphs, dupFirstEntry) {
|
1428
1444
|
if (!header) {
|
1429
1445
|
if (metrics) {
|
1430
1446
|
metrics.data = null;
|
@@ -1433,24 +1449,24 @@ var Font = function FontClosure() {
|
|
1433
1449
|
return;
|
1434
1450
|
}
|
1435
1451
|
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
var numOfMetrics =
|
1452
|
+
file.pos = (file.start ? file.start : 0) + header.offset;
|
1453
|
+
file.pos += 4;
|
1454
|
+
file.pos += 2;
|
1455
|
+
file.pos += 2;
|
1456
|
+
file.pos += 2;
|
1457
|
+
file.pos += 2;
|
1458
|
+
file.pos += 2;
|
1459
|
+
file.pos += 2;
|
1460
|
+
file.pos += 2;
|
1461
|
+
file.pos += 2;
|
1462
|
+
file.pos += 2;
|
1463
|
+
file.pos += 2;
|
1464
|
+
file.pos += 8;
|
1465
|
+
file.pos += 2;
|
1466
|
+
var numOfMetrics = file.getUint16();
|
1451
1467
|
|
1452
1468
|
if (numOfMetrics > numGlyphs) {
|
1453
|
-
(0, _util.info)(
|
1469
|
+
(0, _util.info)("The numOfMetrics (" + numOfMetrics + ") should not be " + "greater than the numGlyphs (" + numGlyphs + ")");
|
1454
1470
|
numOfMetrics = numGlyphs;
|
1455
1471
|
header.data[34] = (numOfMetrics & 0xff00) >> 8;
|
1456
1472
|
header.data[35] = numOfMetrics & 0x00ff;
|
@@ -1513,11 +1529,27 @@ var Font = function FontClosure() {
|
|
1513
1529
|
for (i = 0; i < flagsCount; i++) {
|
1514
1530
|
var flag = glyf[j++];
|
1515
1531
|
|
1516
|
-
if (flag &
|
1517
|
-
glyf[j - 1] = flag &
|
1532
|
+
if (flag & 0xc0) {
|
1533
|
+
glyf[j - 1] = flag & 0x3f;
|
1518
1534
|
}
|
1519
1535
|
|
1520
|
-
|
1536
|
+
let xLength = 2;
|
1537
|
+
|
1538
|
+
if (flag & 2) {
|
1539
|
+
xLength = 1;
|
1540
|
+
} else if (flag & 16) {
|
1541
|
+
xLength = 0;
|
1542
|
+
}
|
1543
|
+
|
1544
|
+
let yLength = 2;
|
1545
|
+
|
1546
|
+
if (flag & 4) {
|
1547
|
+
yLength = 1;
|
1548
|
+
} else if (flag & 32) {
|
1549
|
+
yLength = 0;
|
1550
|
+
}
|
1551
|
+
|
1552
|
+
const xyLength = xLength + yLength;
|
1521
1553
|
coordinatesLength += xyLength;
|
1522
1554
|
|
1523
1555
|
if (flag & 8) {
|
@@ -1568,7 +1600,7 @@ var Font = function FontClosure() {
|
|
1568
1600
|
var version = int32(data[0], data[1], data[2], data[3]);
|
1569
1601
|
|
1570
1602
|
if (version >> 16 !== 1) {
|
1571
|
-
(0, _util.info)(
|
1603
|
+
(0, _util.info)("Attempting to fix invalid version in head table: " + version);
|
1572
1604
|
data[0] = 0;
|
1573
1605
|
data[1] = 1;
|
1574
1606
|
data[2] = 0;
|
@@ -1578,7 +1610,7 @@ var Font = function FontClosure() {
|
|
1578
1610
|
var indexToLocFormat = int16(data[50], data[51]);
|
1579
1611
|
|
1580
1612
|
if (indexToLocFormat < 0 || indexToLocFormat > 1) {
|
1581
|
-
(0, _util.info)(
|
1613
|
+
(0, _util.info)("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat);
|
1582
1614
|
var numGlyphsPlusOne = numGlyphs + 1;
|
1583
1615
|
|
1584
1616
|
if (locaLength === numGlyphsPlusOne << 1) {
|
@@ -1588,7 +1620,7 @@ var Font = function FontClosure() {
|
|
1588
1620
|
data[50] = 0;
|
1589
1621
|
data[51] = 1;
|
1590
1622
|
} else {
|
1591
|
-
throw new _util.FormatError(
|
1623
|
+
throw new _util.FormatError("Could not fix indexToLocFormat: " + indexToLocFormat);
|
1592
1624
|
}
|
1593
1625
|
}
|
1594
1626
|
}
|
@@ -1604,10 +1636,10 @@ var Font = function FontClosure() {
|
|
1604
1636
|
};
|
1605
1637
|
|
1606
1638
|
itemEncode = function fontItemEncodeLong(data, offset, value) {
|
1607
|
-
data[offset] = value >>> 24 &
|
1608
|
-
data[offset + 1] = value >> 16 &
|
1609
|
-
data[offset + 2] = value >> 8 &
|
1610
|
-
data[offset + 3] = value &
|
1639
|
+
data[offset] = value >>> 24 & 0xff;
|
1640
|
+
data[offset + 1] = value >> 16 & 0xff;
|
1641
|
+
data[offset + 2] = value >> 8 & 0xff;
|
1642
|
+
data[offset + 3] = value & 0xff;
|
1611
1643
|
};
|
1612
1644
|
} else {
|
1613
1645
|
itemSize = 2;
|
@@ -1617,42 +1649,53 @@ var Font = function FontClosure() {
|
|
1617
1649
|
};
|
1618
1650
|
|
1619
1651
|
itemEncode = function fontItemEncode(data, offset, value) {
|
1620
|
-
data[offset] = value >> 9 &
|
1621
|
-
data[offset + 1] = value >> 1 &
|
1652
|
+
data[offset] = value >> 9 & 0xff;
|
1653
|
+
data[offset + 1] = value >> 1 & 0xff;
|
1622
1654
|
};
|
1623
1655
|
}
|
1624
1656
|
|
1625
1657
|
var numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
|
1626
|
-
var locaData = loca.data;
|
1627
1658
|
var locaDataSize = itemSize * (1 + numGlyphsOut);
|
1628
|
-
locaData = new Uint8Array(locaDataSize);
|
1659
|
+
var locaData = new Uint8Array(locaDataSize);
|
1629
1660
|
locaData.set(loca.data.subarray(0, locaDataSize));
|
1630
1661
|
loca.data = locaData;
|
1631
1662
|
var oldGlyfData = glyf.data;
|
1632
1663
|
var oldGlyfDataLength = oldGlyfData.length;
|
1633
1664
|
var newGlyfData = new Uint8Array(oldGlyfDataLength);
|
1634
|
-
var startOffset = itemDecode(locaData, 0);
|
1635
|
-
var writeOffset = 0;
|
1636
|
-
var missingGlyphs = Object.create(null);
|
1637
|
-
itemEncode(locaData, 0, writeOffset);
|
1638
1665
|
var i, j;
|
1666
|
+
const locaEntries = [];
|
1639
1667
|
|
1640
|
-
for (i = 0, j =
|
1641
|
-
|
1668
|
+
for (i = 0, j = 0; i < numGlyphs + 1; i++, j += itemSize) {
|
1669
|
+
let offset = itemDecode(locaData, j);
|
1642
1670
|
|
1643
|
-
if (
|
1644
|
-
|
1671
|
+
if (offset > oldGlyfDataLength) {
|
1672
|
+
offset = oldGlyfDataLength;
|
1645
1673
|
}
|
1646
1674
|
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1675
|
+
locaEntries.push({
|
1676
|
+
index: i,
|
1677
|
+
offset,
|
1678
|
+
endOffset: 0
|
1679
|
+
});
|
1680
|
+
}
|
1650
1681
|
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1682
|
+
locaEntries.sort((a, b) => {
|
1683
|
+
return a.offset - b.offset;
|
1684
|
+
});
|
1685
|
+
|
1686
|
+
for (i = 0; i < numGlyphs; i++) {
|
1687
|
+
locaEntries[i].endOffset = locaEntries[i + 1].offset;
|
1688
|
+
}
|
1654
1689
|
|
1655
|
-
|
1690
|
+
locaEntries.sort((a, b) => {
|
1691
|
+
return a.index - b.index;
|
1692
|
+
});
|
1693
|
+
var missingGlyphs = Object.create(null);
|
1694
|
+
var writeOffset = 0;
|
1695
|
+
itemEncode(locaData, 0, writeOffset);
|
1696
|
+
|
1697
|
+
for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
|
1698
|
+
var glyphProfile = sanitizeGlyph(oldGlyfData, locaEntries[i].offset, locaEntries[i].endOffset, newGlyfData, writeOffset, hintsValid);
|
1656
1699
|
var newLength = glyphProfile.length;
|
1657
1700
|
|
1658
1701
|
if (newLength === 0) {
|
@@ -1665,7 +1708,6 @@ var Font = function FontClosure() {
|
|
1665
1708
|
|
1666
1709
|
writeOffset += newLength;
|
1667
1710
|
itemEncode(locaData, j, writeOffset);
|
1668
|
-
startOffset = endOffset;
|
1669
1711
|
}
|
1670
1712
|
|
1671
1713
|
if (writeOffset === 0) {
|
@@ -1693,18 +1735,18 @@ var Font = function FontClosure() {
|
|
1693
1735
|
}
|
1694
1736
|
|
1695
1737
|
return {
|
1696
|
-
missingGlyphs
|
1697
|
-
maxSizeOfInstructions
|
1738
|
+
missingGlyphs,
|
1739
|
+
maxSizeOfInstructions
|
1698
1740
|
};
|
1699
1741
|
}
|
1700
1742
|
|
1701
|
-
function readPostScriptTable(post,
|
1743
|
+
function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
|
1702
1744
|
var start = (font.start ? font.start : 0) + post.offset;
|
1703
1745
|
font.pos = start;
|
1704
1746
|
var length = post.length,
|
1705
1747
|
end = start + length;
|
1706
1748
|
var version = font.getInt32();
|
1707
|
-
font.
|
1749
|
+
font.skip(28);
|
1708
1750
|
var glyphNames;
|
1709
1751
|
var valid = true;
|
1710
1752
|
var i;
|
@@ -1750,7 +1792,7 @@ var Font = function FontClosure() {
|
|
1750
1792
|
strBuf[i] = String.fromCharCode(font.getByte());
|
1751
1793
|
}
|
1752
1794
|
|
1753
|
-
customNames.push(strBuf.join(
|
1795
|
+
customNames.push(strBuf.join(""));
|
1754
1796
|
}
|
1755
1797
|
|
1756
1798
|
glyphNames = [];
|
@@ -1772,17 +1814,17 @@ var Font = function FontClosure() {
|
|
1772
1814
|
break;
|
1773
1815
|
|
1774
1816
|
default:
|
1775
|
-
(0, _util.warn)(
|
1817
|
+
(0, _util.warn)("Unknown/unsupported post table version " + version);
|
1776
1818
|
valid = false;
|
1777
1819
|
|
1778
|
-
if (
|
1779
|
-
glyphNames =
|
1820
|
+
if (propertiesObj.defaultEncoding) {
|
1821
|
+
glyphNames = propertiesObj.defaultEncoding;
|
1780
1822
|
}
|
1781
1823
|
|
1782
1824
|
break;
|
1783
1825
|
}
|
1784
1826
|
|
1785
|
-
|
1827
|
+
propertiesObj.glyphNames = glyphNames;
|
1786
1828
|
return valid;
|
1787
1829
|
}
|
1788
1830
|
|
@@ -1837,7 +1879,7 @@ var Font = function FontClosure() {
|
|
1837
1879
|
var nameIndex = record.name;
|
1838
1880
|
|
1839
1881
|
if (record.encoding) {
|
1840
|
-
var str =
|
1882
|
+
var str = "";
|
1841
1883
|
|
1842
1884
|
for (var j = 0, jj = record.length; j < jj; j += 2) {
|
1843
1885
|
str += String.fromCharCode(font.getUint16());
|
@@ -1896,8 +1938,8 @@ var Font = function FontClosure() {
|
|
1896
1938
|
stack.push(b << 8 | data[i++]);
|
1897
1939
|
}
|
1898
1940
|
}
|
1899
|
-
} else if ((op &
|
1900
|
-
n = op -
|
1941
|
+
} else if ((op & 0xf8) === 0xb0) {
|
1942
|
+
n = op - 0xb0 + 1;
|
1901
1943
|
|
1902
1944
|
if (inFDEF || inELSE) {
|
1903
1945
|
i += n;
|
@@ -1906,8 +1948,8 @@ var Font = function FontClosure() {
|
|
1906
1948
|
stack.push(data[i++]);
|
1907
1949
|
}
|
1908
1950
|
}
|
1909
|
-
} else if ((op &
|
1910
|
-
n = op -
|
1951
|
+
} else if ((op & 0xf8) === 0xb8) {
|
1952
|
+
n = op - 0xb8 + 1;
|
1911
1953
|
|
1912
1954
|
if (inFDEF || inELSE) {
|
1913
1955
|
i += n * 2;
|
@@ -1917,20 +1959,20 @@ var Font = function FontClosure() {
|
|
1917
1959
|
stack.push(b << 8 | data[i++]);
|
1918
1960
|
}
|
1919
1961
|
}
|
1920
|
-
} else if (op ===
|
1962
|
+
} else if (op === 0x2b && !tooComplexToFollowFunctions) {
|
1921
1963
|
if (!inFDEF && !inELSE) {
|
1922
1964
|
funcId = stack[stack.length - 1];
|
1923
1965
|
|
1924
1966
|
if (isNaN(funcId)) {
|
1925
|
-
(0, _util.info)(
|
1967
|
+
(0, _util.info)("TT: CALL empty stack (or invalid entry).");
|
1926
1968
|
} else {
|
1927
1969
|
ttContext.functionsUsed[funcId] = true;
|
1928
1970
|
|
1929
1971
|
if (funcId in ttContext.functionsStackDeltas) {
|
1930
|
-
|
1972
|
+
const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
|
1931
1973
|
|
1932
1974
|
if (newStackLength < 0) {
|
1933
|
-
(0, _util.warn)(
|
1975
|
+
(0, _util.warn)("TT: CALL invalid functions stack delta.");
|
1934
1976
|
ttContext.hintsValid = false;
|
1935
1977
|
return;
|
1936
1978
|
}
|
@@ -1938,15 +1980,15 @@ var Font = function FontClosure() {
|
|
1938
1980
|
stack.length = newStackLength;
|
1939
1981
|
} else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
|
1940
1982
|
callstack.push({
|
1941
|
-
data
|
1942
|
-
i
|
1983
|
+
data,
|
1984
|
+
i,
|
1943
1985
|
stackTop: stack.length - 1
|
1944
1986
|
});
|
1945
1987
|
functionsCalled.push(funcId);
|
1946
1988
|
pc = ttContext.functionsDefined[funcId];
|
1947
1989
|
|
1948
1990
|
if (!pc) {
|
1949
|
-
(0, _util.warn)(
|
1991
|
+
(0, _util.warn)("TT: CALL non-existent function");
|
1950
1992
|
ttContext.hintsValid = false;
|
1951
1993
|
return;
|
1952
1994
|
}
|
@@ -1956,9 +1998,9 @@ var Font = function FontClosure() {
|
|
1956
1998
|
}
|
1957
1999
|
}
|
1958
2000
|
}
|
1959
|
-
} else if (op ===
|
2001
|
+
} else if (op === 0x2c && !tooComplexToFollowFunctions) {
|
1960
2002
|
if (inFDEF || inELSE) {
|
1961
|
-
(0, _util.warn)(
|
2003
|
+
(0, _util.warn)("TT: nested FDEFs not allowed");
|
1962
2004
|
tooComplexToFollowFunctions = true;
|
1963
2005
|
}
|
1964
2006
|
|
@@ -1966,10 +2008,10 @@ var Font = function FontClosure() {
|
|
1966
2008
|
lastDeff = i;
|
1967
2009
|
funcId = stack.pop();
|
1968
2010
|
ttContext.functionsDefined[funcId] = {
|
1969
|
-
data
|
1970
|
-
i
|
2011
|
+
data,
|
2012
|
+
i
|
1971
2013
|
};
|
1972
|
-
} else if (op ===
|
2014
|
+
} else if (op === 0x2d) {
|
1973
2015
|
if (inFDEF) {
|
1974
2016
|
inFDEF = false;
|
1975
2017
|
lastEndf = i;
|
@@ -1977,7 +2019,7 @@ var Font = function FontClosure() {
|
|
1977
2019
|
pc = callstack.pop();
|
1978
2020
|
|
1979
2021
|
if (!pc) {
|
1980
|
-
(0, _util.warn)(
|
2022
|
+
(0, _util.warn)("TT: ENDF bad stack");
|
1981
2023
|
ttContext.hintsValid = false;
|
1982
2024
|
return;
|
1983
2025
|
}
|
@@ -1989,7 +2031,7 @@ var Font = function FontClosure() {
|
|
1989
2031
|
}
|
1990
2032
|
} else if (op === 0x89) {
|
1991
2033
|
if (inFDEF || inELSE) {
|
1992
|
-
(0, _util.warn)(
|
2034
|
+
(0, _util.warn)("TT: nested IDEFs not allowed");
|
1993
2035
|
tooComplexToFollowFunctions = true;
|
1994
2036
|
}
|
1995
2037
|
|
@@ -1997,7 +2039,7 @@ var Font = function FontClosure() {
|
|
1997
2039
|
lastDeff = i;
|
1998
2040
|
} else if (op === 0x58) {
|
1999
2041
|
++ifLevel;
|
2000
|
-
} else if (op ===
|
2042
|
+
} else if (op === 0x1b) {
|
2001
2043
|
inELSE = ifLevel;
|
2002
2044
|
} else if (op === 0x59) {
|
2003
2045
|
if (inELSE === ifLevel) {
|
@@ -2005,7 +2047,7 @@ var Font = function FontClosure() {
|
|
2005
2047
|
}
|
2006
2048
|
|
2007
2049
|
--ifLevel;
|
2008
|
-
} else if (op ===
|
2050
|
+
} else if (op === 0x1c) {
|
2009
2051
|
if (!inFDEF && !inELSE) {
|
2010
2052
|
var offset = stack[stack.length - 1];
|
2011
2053
|
|
@@ -2016,7 +2058,15 @@ var Font = function FontClosure() {
|
|
2016
2058
|
}
|
2017
2059
|
|
2018
2060
|
if (!inFDEF && !inELSE) {
|
2019
|
-
|
2061
|
+
let stackDelta = 0;
|
2062
|
+
|
2063
|
+
if (op <= 0x8e) {
|
2064
|
+
stackDelta = TTOpsStackDeltas[op];
|
2065
|
+
} else if (op >= 0xc0 && op <= 0xdf) {
|
2066
|
+
stackDelta = -1;
|
2067
|
+
} else if (op >= 0xe0) {
|
2068
|
+
stackDelta = -2;
|
2069
|
+
}
|
2020
2070
|
|
2021
2071
|
if (op >= 0x71 && op <= 0x75) {
|
2022
2072
|
n = stack.pop();
|
@@ -2046,8 +2096,8 @@ var Font = function FontClosure() {
|
|
2046
2096
|
}
|
2047
2097
|
|
2048
2098
|
if (lastDeff > lastEndf) {
|
2049
|
-
(0, _util.warn)(
|
2050
|
-
content.push(new Uint8Array([0x22,
|
2099
|
+
(0, _util.warn)("TT: complementing a missing function tail");
|
2100
|
+
content.push(new Uint8Array([0x22, 0x2d]));
|
2051
2101
|
}
|
2052
2102
|
|
2053
2103
|
foldTTTable(table, content);
|
@@ -2059,20 +2109,20 @@ var Font = function FontClosure() {
|
|
2059
2109
|
}
|
2060
2110
|
|
2061
2111
|
if (ttContext.functionsDefined.length > maxFunctionDefs) {
|
2062
|
-
(0, _util.warn)(
|
2112
|
+
(0, _util.warn)("TT: more functions defined than expected");
|
2063
2113
|
ttContext.hintsValid = false;
|
2064
2114
|
return;
|
2065
2115
|
}
|
2066
2116
|
|
2067
2117
|
for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
|
2068
2118
|
if (j > maxFunctionDefs) {
|
2069
|
-
(0, _util.warn)(
|
2119
|
+
(0, _util.warn)("TT: invalid function id: " + j);
|
2070
2120
|
ttContext.hintsValid = false;
|
2071
2121
|
return;
|
2072
2122
|
}
|
2073
2123
|
|
2074
2124
|
if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
|
2075
|
-
(0, _util.warn)(
|
2125
|
+
(0, _util.warn)("TT: undefined function: " + j);
|
2076
2126
|
ttContext.hintsValid = false;
|
2077
2127
|
return;
|
2078
2128
|
}
|
@@ -2133,10 +2183,10 @@ var Font = function FontClosure() {
|
|
2133
2183
|
}
|
2134
2184
|
|
2135
2185
|
font = new _stream.Stream(new Uint8Array(font.getBytes()));
|
2136
|
-
|
2186
|
+
let header, tables;
|
2137
2187
|
|
2138
2188
|
if (isTrueTypeCollectionFile(font)) {
|
2139
|
-
|
2189
|
+
const ttcData = readTrueTypeCollectionData(font, this.name);
|
2140
2190
|
header = ttcData.header;
|
2141
2191
|
tables = ttcData.tables;
|
2142
2192
|
} else {
|
@@ -2144,34 +2194,34 @@ var Font = function FontClosure() {
|
|
2144
2194
|
tables = readTables(font, header.numTables);
|
2145
2195
|
}
|
2146
2196
|
|
2147
|
-
|
2148
|
-
var isTrueType = !tables[
|
2197
|
+
let cff, cffFile;
|
2198
|
+
var isTrueType = !tables["CFF "];
|
2149
2199
|
|
2150
2200
|
if (!isTrueType) {
|
2151
|
-
|
2201
|
+
const isComposite = properties.composite && ((properties.cidToGidMap || []).length > 0 || !(properties.cMap instanceof _cmap.IdentityCMap));
|
2152
2202
|
|
2153
|
-
if (header.version ===
|
2154
|
-
cffFile = new _stream.Stream(tables[
|
2203
|
+
if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
|
2204
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2155
2205
|
cff = new CFFFont(cffFile, properties);
|
2156
2206
|
adjustWidths(properties);
|
2157
2207
|
return this.convert(name, cff, properties);
|
2158
2208
|
}
|
2159
2209
|
|
2160
|
-
delete tables
|
2161
|
-
delete tables
|
2162
|
-
delete tables
|
2163
|
-
delete tables
|
2164
|
-
delete tables[
|
2210
|
+
delete tables.glyf;
|
2211
|
+
delete tables.loca;
|
2212
|
+
delete tables.fpgm;
|
2213
|
+
delete tables.prep;
|
2214
|
+
delete tables["cvt "];
|
2165
2215
|
this.isOpenType = true;
|
2166
2216
|
} else {
|
2167
|
-
if (!tables
|
2217
|
+
if (!tables.loca) {
|
2168
2218
|
throw new _util.FormatError('Required "loca" table is not found');
|
2169
2219
|
}
|
2170
2220
|
|
2171
|
-
if (!tables
|
2221
|
+
if (!tables.glyf) {
|
2172
2222
|
(0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
|
2173
|
-
tables
|
2174
|
-
tag:
|
2223
|
+
tables.glyf = {
|
2224
|
+
tag: "glyf",
|
2175
2225
|
data: new Uint8Array(0)
|
2176
2226
|
};
|
2177
2227
|
}
|
@@ -2179,32 +2229,32 @@ var Font = function FontClosure() {
|
|
2179
2229
|
this.isOpenType = false;
|
2180
2230
|
}
|
2181
2231
|
|
2182
|
-
if (!tables
|
2232
|
+
if (!tables.maxp) {
|
2183
2233
|
throw new _util.FormatError('Required "maxp" table is not found');
|
2184
2234
|
}
|
2185
2235
|
|
2186
|
-
font.pos = (font.start || 0) + tables
|
2236
|
+
font.pos = (font.start || 0) + tables.maxp.offset;
|
2187
2237
|
var version = font.getInt32();
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2238
|
+
const numGlyphs = font.getUint16();
|
2239
|
+
let numGlyphsOut = numGlyphs + 1;
|
2240
|
+
let dupFirstEntry = true;
|
2191
2241
|
|
2192
|
-
if (numGlyphsOut >
|
2242
|
+
if (numGlyphsOut > 0xffff) {
|
2193
2243
|
dupFirstEntry = false;
|
2194
2244
|
numGlyphsOut = numGlyphs;
|
2195
|
-
(0, _util.warn)(
|
2245
|
+
(0, _util.warn)("Not enough space in glyfs to duplicate first glyph.");
|
2196
2246
|
}
|
2197
2247
|
|
2198
2248
|
var maxFunctionDefs = 0;
|
2199
2249
|
var maxSizeOfInstructions = 0;
|
2200
2250
|
|
2201
|
-
if (version >= 0x00010000 && tables
|
2251
|
+
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
2202
2252
|
font.pos += 8;
|
2203
2253
|
var maxZones = font.getUint16();
|
2204
2254
|
|
2205
2255
|
if (maxZones > 2) {
|
2206
|
-
tables
|
2207
|
-
tables
|
2256
|
+
tables.maxp.data[14] = 0;
|
2257
|
+
tables.maxp.data[15] = 2;
|
2208
2258
|
}
|
2209
2259
|
|
2210
2260
|
font.pos += 4;
|
@@ -2213,65 +2263,64 @@ var Font = function FontClosure() {
|
|
2213
2263
|
maxSizeOfInstructions = font.getUint16();
|
2214
2264
|
}
|
2215
2265
|
|
2216
|
-
tables
|
2217
|
-
tables
|
2218
|
-
var hintsValid = sanitizeTTPrograms(tables
|
2266
|
+
tables.maxp.data[4] = numGlyphsOut >> 8;
|
2267
|
+
tables.maxp.data[5] = numGlyphsOut & 255;
|
2268
|
+
var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs);
|
2219
2269
|
|
2220
2270
|
if (!hintsValid) {
|
2221
|
-
delete tables
|
2222
|
-
delete tables
|
2223
|
-
delete tables[
|
2271
|
+
delete tables.fpgm;
|
2272
|
+
delete tables.prep;
|
2273
|
+
delete tables["cvt "];
|
2224
2274
|
}
|
2225
2275
|
|
2226
|
-
sanitizeMetrics(font, tables
|
2276
|
+
sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphsOut, dupFirstEntry);
|
2227
2277
|
|
2228
|
-
if (!tables
|
2278
|
+
if (!tables.head) {
|
2229
2279
|
throw new _util.FormatError('Required "head" table is not found');
|
2230
2280
|
}
|
2231
2281
|
|
2232
|
-
sanitizeHead(tables
|
2282
|
+
sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
|
2233
2283
|
var missingGlyphs = Object.create(null);
|
2234
2284
|
|
2235
2285
|
if (isTrueType) {
|
2236
|
-
var isGlyphLocationsLong = int16(tables
|
2237
|
-
var glyphsInfo = sanitizeGlyphLocations(tables
|
2286
|
+
var isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
|
2287
|
+
var glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
|
2238
2288
|
missingGlyphs = glyphsInfo.missingGlyphs;
|
2239
2289
|
|
2240
|
-
if (version >= 0x00010000 && tables
|
2241
|
-
tables
|
2242
|
-
tables
|
2290
|
+
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
2291
|
+
tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
|
2292
|
+
tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
|
2243
2293
|
}
|
2244
2294
|
}
|
2245
2295
|
|
2246
|
-
if (!tables
|
2296
|
+
if (!tables.hhea) {
|
2247
2297
|
throw new _util.FormatError('Required "hhea" table is not found');
|
2248
2298
|
}
|
2249
2299
|
|
2250
|
-
if (tables
|
2251
|
-
tables
|
2252
|
-
tables
|
2300
|
+
if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
|
2301
|
+
tables.hhea.data[10] = 0xff;
|
2302
|
+
tables.hhea.data[11] = 0xff;
|
2253
2303
|
}
|
2254
2304
|
|
2255
2305
|
var metricsOverride = {
|
2256
|
-
unitsPerEm: int16(tables
|
2257
|
-
yMax: int16(tables
|
2258
|
-
yMin: signedInt16(tables
|
2259
|
-
ascent: int16(tables
|
2260
|
-
descent: signedInt16(tables
|
2306
|
+
unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
|
2307
|
+
yMax: int16(tables.head.data[42], tables.head.data[43]),
|
2308
|
+
yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
|
2309
|
+
ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
|
2310
|
+
descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7])
|
2261
2311
|
};
|
2262
2312
|
this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
|
2263
2313
|
this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
2264
2314
|
|
2265
|
-
if (tables
|
2266
|
-
readPostScriptTable(tables
|
2315
|
+
if (tables.post) {
|
2316
|
+
readPostScriptTable(tables.post, properties, numGlyphs);
|
2267
2317
|
}
|
2268
2318
|
|
2269
|
-
tables
|
2270
|
-
tag:
|
2319
|
+
tables.post = {
|
2320
|
+
tag: "post",
|
2271
2321
|
data: createPostTable(properties)
|
2272
2322
|
};
|
2273
|
-
|
2274
|
-
charCode;
|
2323
|
+
const charCodeToGlyphId = [];
|
2275
2324
|
|
2276
2325
|
function hasGlyph(glyphId) {
|
2277
2326
|
return !missingGlyphs[glyphId];
|
@@ -2282,7 +2331,7 @@ var Font = function FontClosure() {
|
|
2282
2331
|
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
2283
2332
|
properties.cMap.forEach(function (charCode, cid) {
|
2284
2333
|
if (cid > 0xffff) {
|
2285
|
-
throw new _util.FormatError(
|
2334
|
+
throw new _util.FormatError("Max size of CID is 65,535");
|
2286
2335
|
}
|
2287
2336
|
|
2288
2337
|
var glyphId = -1;
|
@@ -2298,27 +2347,26 @@ var Font = function FontClosure() {
|
|
2298
2347
|
}
|
2299
2348
|
});
|
2300
2349
|
} else {
|
2301
|
-
var cmapTable = readCmapTable(tables
|
2350
|
+
var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding);
|
2302
2351
|
var cmapPlatformId = cmapTable.platformId;
|
2303
2352
|
var cmapEncodingId = cmapTable.encodingId;
|
2304
2353
|
var cmapMappings = cmapTable.mappings;
|
2305
2354
|
var cmapMappingsLength = cmapMappings.length;
|
2355
|
+
let baseEncoding = [];
|
2306
2356
|
|
2307
|
-
if (properties.hasEncoding && (
|
2308
|
-
|
2309
|
-
|
2310
|
-
if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
|
2311
|
-
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
2312
|
-
}
|
2357
|
+
if (properties.hasEncoding && (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding")) {
|
2358
|
+
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
2359
|
+
}
|
2313
2360
|
|
2361
|
+
if (properties.hasEncoding && !this.isSymbolicFont && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0)) {
|
2314
2362
|
var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2315
2363
|
|
2316
|
-
for (charCode = 0; charCode < 256; charCode++) {
|
2364
|
+
for (let charCode = 0; charCode < 256; charCode++) {
|
2317
2365
|
var glyphName, standardGlyphName;
|
2318
2366
|
|
2319
2367
|
if (this.differences && charCode in this.differences) {
|
2320
2368
|
glyphName = this.differences[charCode];
|
2321
|
-
} else if (charCode in baseEncoding && baseEncoding[charCode] !==
|
2369
|
+
} else if (charCode in baseEncoding && baseEncoding[charCode] !== "") {
|
2322
2370
|
glyphName = baseEncoding[charCode];
|
2323
2371
|
} else {
|
2324
2372
|
glyphName = _encodings.StandardEncoding[charCode];
|
@@ -2337,43 +2385,41 @@ var Font = function FontClosure() {
|
|
2337
2385
|
unicodeOrCharCode = _encodings.MacRomanEncoding.indexOf(standardGlyphName);
|
2338
2386
|
}
|
2339
2387
|
|
2340
|
-
|
2341
|
-
|
2342
|
-
for (var i = 0; i < cmapMappingsLength; ++i) {
|
2388
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2343
2389
|
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
|
2344
2390
|
continue;
|
2345
2391
|
}
|
2346
2392
|
|
2347
2393
|
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
2348
|
-
found = true;
|
2349
2394
|
break;
|
2350
2395
|
}
|
2351
|
-
|
2352
|
-
if (!found && properties.glyphNames) {
|
2353
|
-
var glyphId = properties.glyphNames.indexOf(glyphName);
|
2354
|
-
|
2355
|
-
if (glyphId === -1 && standardGlyphName !== glyphName) {
|
2356
|
-
glyphId = properties.glyphNames.indexOf(standardGlyphName);
|
2357
|
-
}
|
2358
|
-
|
2359
|
-
if (glyphId > 0 && hasGlyph(glyphId)) {
|
2360
|
-
charCodeToGlyphId[charCode] = glyphId;
|
2361
|
-
}
|
2362
|
-
}
|
2363
2396
|
}
|
2364
|
-
} else if (cmapPlatformId === 0
|
2365
|
-
for (
|
2366
|
-
charCodeToGlyphId[cmapMappings[
|
2397
|
+
} else if (cmapPlatformId === 0) {
|
2398
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2399
|
+
charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
|
2367
2400
|
}
|
2368
2401
|
} else {
|
2369
|
-
for (
|
2370
|
-
charCode = cmapMappings[
|
2402
|
+
for (let i = 0; i < cmapMappingsLength; ++i) {
|
2403
|
+
let charCode = cmapMappings[i].charCode;
|
2371
2404
|
|
2372
|
-
if (cmapPlatformId === 3 && charCode >=
|
2373
|
-
charCode &=
|
2405
|
+
if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
|
2406
|
+
charCode &= 0xff;
|
2374
2407
|
}
|
2375
2408
|
|
2376
|
-
charCodeToGlyphId[charCode] = cmapMappings[
|
2409
|
+
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
2410
|
+
}
|
2411
|
+
}
|
2412
|
+
|
2413
|
+
if (properties.glyphNames && baseEncoding.length) {
|
2414
|
+
for (let i = 0; i < 256; ++i) {
|
2415
|
+
if (charCodeToGlyphId[i] === undefined && baseEncoding[i]) {
|
2416
|
+
glyphName = baseEncoding[i];
|
2417
|
+
const glyphId = properties.glyphNames.indexOf(glyphName);
|
2418
|
+
|
2419
|
+
if (glyphId > 0 && hasGlyph(glyphId)) {
|
2420
|
+
charCodeToGlyphId[i] = glyphId;
|
2421
|
+
}
|
2422
|
+
}
|
2377
2423
|
}
|
2378
2424
|
}
|
2379
2425
|
}
|
@@ -2382,7 +2428,7 @@ var Font = function FontClosure() {
|
|
2382
2428
|
charCodeToGlyphId[0] = 0;
|
2383
2429
|
}
|
2384
2430
|
|
2385
|
-
|
2431
|
+
let glyphZeroId = numGlyphsOut - 1;
|
2386
2432
|
|
2387
2433
|
if (!dupFirstEntry) {
|
2388
2434
|
glyphZeroId = 0;
|
@@ -2390,39 +2436,39 @@ var Font = function FontClosure() {
|
|
2390
2436
|
|
2391
2437
|
var newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId);
|
2392
2438
|
this.toFontChar = newMapping.toFontChar;
|
2393
|
-
tables
|
2394
|
-
tag:
|
2439
|
+
tables.cmap = {
|
2440
|
+
tag: "cmap",
|
2395
2441
|
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut)
|
2396
2442
|
};
|
2397
2443
|
|
2398
|
-
if (!tables[
|
2399
|
-
tables[
|
2400
|
-
tag:
|
2444
|
+
if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
|
2445
|
+
tables["OS/2"] = {
|
2446
|
+
tag: "OS/2",
|
2401
2447
|
data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
|
2402
2448
|
};
|
2403
2449
|
}
|
2404
2450
|
|
2405
2451
|
if (!isTrueType) {
|
2406
2452
|
try {
|
2407
|
-
cffFile = new _stream.Stream(tables[
|
2453
|
+
cffFile = new _stream.Stream(tables["CFF "].data);
|
2408
2454
|
var parser = new _cff_parser.CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
|
2409
2455
|
cff = parser.parse();
|
2410
2456
|
cff.duplicateFirstGlyph();
|
2411
2457
|
var compiler = new _cff_parser.CFFCompiler(cff);
|
2412
|
-
tables[
|
2458
|
+
tables["CFF "].data = compiler.compile();
|
2413
2459
|
} catch (e) {
|
2414
|
-
(0, _util.warn)(
|
2460
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
2415
2461
|
}
|
2416
2462
|
}
|
2417
2463
|
|
2418
|
-
if (!tables
|
2419
|
-
tables
|
2420
|
-
tag:
|
2464
|
+
if (!tables.name) {
|
2465
|
+
tables.name = {
|
2466
|
+
tag: "name",
|
2421
2467
|
data: createNameTable(this.name)
|
2422
2468
|
};
|
2423
2469
|
} else {
|
2424
|
-
var namePrototype = readNameTable(tables
|
2425
|
-
tables
|
2470
|
+
var namePrototype = readNameTable(tables.name);
|
2471
|
+
tables.name.data = createNameTable(name, namePrototype);
|
2426
2472
|
}
|
2427
2473
|
|
2428
2474
|
var builder = new OpenTypeFileBuilder(header.version);
|
@@ -2440,7 +2486,7 @@ var Font = function FontClosure() {
|
|
2440
2486
|
adjustToUnicode(properties, properties.builtInEncoding);
|
2441
2487
|
}
|
2442
2488
|
|
2443
|
-
|
2489
|
+
let glyphZeroId = 1;
|
2444
2490
|
|
2445
2491
|
if (font instanceof CFFFont) {
|
2446
2492
|
glyphZeroId = font.numGlyphs - 1;
|
@@ -2507,15 +2553,15 @@ var Font = function FontClosure() {
|
|
2507
2553
|
continue;
|
2508
2554
|
}
|
2509
2555
|
|
2510
|
-
for (
|
2556
|
+
for (let i = 0, ii = charCodes.length; i < ii; i++) {
|
2511
2557
|
var charCode = charCodes[i];
|
2512
2558
|
var charCodeToGlyphId = newMapping.charCodeToGlyphId;
|
2513
2559
|
var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
|
2514
2560
|
var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
|
2515
2561
|
seacMap[charCode] = {
|
2516
|
-
baseFontCharCode
|
2517
|
-
accentFontCharCode
|
2518
|
-
accentOffset
|
2562
|
+
baseFontCharCode,
|
2563
|
+
accentFontCharCode,
|
2564
|
+
accentOffset
|
2519
2565
|
};
|
2520
2566
|
}
|
2521
2567
|
}
|
@@ -2524,23 +2570,23 @@ var Font = function FontClosure() {
|
|
2524
2570
|
}
|
2525
2571
|
|
2526
2572
|
var unitsPerEm = 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
|
2527
|
-
var builder = new OpenTypeFileBuilder(
|
2528
|
-
builder.addTable(
|
2529
|
-
builder.addTable(
|
2530
|
-
builder.addTable(
|
2531
|
-
builder.addTable(
|
2532
|
-
builder.addTable(
|
2533
|
-
builder.addTable(
|
2573
|
+
var builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
|
2574
|
+
builder.addTable("CFF ", font.data);
|
2575
|
+
builder.addTable("OS/2", createOS2Table(properties, newMapping.charCodeToGlyphId));
|
2576
|
+
builder.addTable("cmap", createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
|
2577
|
+
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");
|
2578
|
+
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));
|
2579
|
+
builder.addTable("hmtx", function fontFieldsHmtx() {
|
2534
2580
|
var charstrings = font.charstrings;
|
2535
2581
|
var cffWidths = font.cff ? font.cff.widths : null;
|
2536
|
-
var hmtx =
|
2582
|
+
var hmtx = "\x00\x00\x00\x00";
|
2537
2583
|
|
2538
|
-
for (
|
2584
|
+
for (let i = 1, ii = numGlyphs; i < ii; i++) {
|
2539
2585
|
var width = 0;
|
2540
2586
|
|
2541
2587
|
if (charstrings) {
|
2542
2588
|
var charstring = charstrings[i - 1];
|
2543
|
-
width =
|
2589
|
+
width = "width" in charstring ? charstring.width : 0;
|
2544
2590
|
} else if (cffWidths) {
|
2545
2591
|
width = Math.ceil(cffWidths[i] || 0);
|
2546
2592
|
}
|
@@ -2550,18 +2596,14 @@ var Font = function FontClosure() {
|
|
2550
2596
|
|
2551
2597
|
return hmtx;
|
2552
2598
|
}());
|
2553
|
-
builder.addTable(
|
2554
|
-
builder.addTable(
|
2555
|
-
builder.addTable(
|
2599
|
+
builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs));
|
2600
|
+
builder.addTable("name", createNameTable(fontName));
|
2601
|
+
builder.addTable("post", createPostTable(properties));
|
2556
2602
|
return builder.toArray();
|
2557
2603
|
},
|
2558
2604
|
|
2559
2605
|
get spaceWidth() {
|
2560
|
-
|
2561
|
-
return this._shadowWidth;
|
2562
|
-
}
|
2563
|
-
|
2564
|
-
var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
|
2606
|
+
var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
2565
2607
|
var width;
|
2566
2608
|
|
2567
2609
|
for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
|
@@ -2576,10 +2618,8 @@ var Font = function FontClosure() {
|
|
2576
2618
|
var glyphUnicode = glyphsUnicodeMap[glyphName];
|
2577
2619
|
var charcode = 0;
|
2578
2620
|
|
2579
|
-
if (this.composite) {
|
2580
|
-
|
2581
|
-
charcode = this.cMap.lookup(glyphUnicode);
|
2582
|
-
}
|
2621
|
+
if (this.composite && this.cMap.contains(glyphUnicode)) {
|
2622
|
+
charcode = this.cMap.lookup(glyphUnicode);
|
2583
2623
|
}
|
2584
2624
|
|
2585
2625
|
if (!charcode && this.toUnicode) {
|
@@ -2598,8 +2638,7 @@ var Font = function FontClosure() {
|
|
2598
2638
|
}
|
2599
2639
|
|
2600
2640
|
width = width || this.defaultWidth;
|
2601
|
-
this
|
2602
|
-
return width;
|
2641
|
+
return (0, _util.shadow)(this, "spaceWidth", width);
|
2603
2642
|
},
|
2604
2643
|
|
2605
2644
|
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
|
@@ -2613,16 +2652,22 @@ var Font = function FontClosure() {
|
|
2613
2652
|
width = this.widths[widthCode];
|
2614
2653
|
width = (0, _util.isNum)(width) ? width : this.defaultWidth;
|
2615
2654
|
var vmetric = this.vmetrics && this.vmetrics[widthCode];
|
2616
|
-
|
2655
|
+
let unicode = this.toUnicode.get(charcode) || this.fallbackToUnicode.get(charcode) || charcode;
|
2617
2656
|
|
2618
|
-
if (typeof unicode ===
|
2657
|
+
if (typeof unicode === "number") {
|
2619
2658
|
unicode = String.fromCharCode(unicode);
|
2620
2659
|
}
|
2621
2660
|
|
2622
|
-
var isInFont = charcode in this.toFontChar;
|
2661
|
+
var isInFont = (charcode in this.toFontChar);
|
2623
2662
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
2624
2663
|
|
2625
2664
|
if (this.missingFile) {
|
2665
|
+
const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
|
2666
|
+
|
2667
|
+
if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
|
2668
|
+
fontCharCode = 0x20;
|
2669
|
+
}
|
2670
|
+
|
2626
2671
|
fontCharCode = (0, _unicode.mapSpecialUnicodeValues)(fontCharCode);
|
2627
2672
|
}
|
2628
2673
|
|
@@ -2642,7 +2687,16 @@ var Font = function FontClosure() {
|
|
2642
2687
|
};
|
2643
2688
|
}
|
2644
2689
|
|
2645
|
-
|
2690
|
+
let fontChar = "";
|
2691
|
+
|
2692
|
+
if (typeof fontCharCode === "number") {
|
2693
|
+
if (fontCharCode <= 0x10ffff) {
|
2694
|
+
fontChar = String.fromCodePoint(fontCharCode);
|
2695
|
+
} else {
|
2696
|
+
(0, _util.warn)(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
|
2697
|
+
}
|
2698
|
+
}
|
2699
|
+
|
2646
2700
|
var glyph = this.glyphCache[charcode];
|
2647
2701
|
|
2648
2702
|
if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
|
@@ -2709,7 +2763,7 @@ exports.Font = Font;
|
|
2709
2763
|
var ErrorFont = function ErrorFontClosure() {
|
2710
2764
|
function ErrorFont(error) {
|
2711
2765
|
this.error = error;
|
2712
|
-
this.loadedName =
|
2766
|
+
this.loadedName = "g_font_error";
|
2713
2767
|
this.missingFile = true;
|
2714
2768
|
}
|
2715
2769
|
|
@@ -2717,11 +2771,13 @@ var ErrorFont = function ErrorFontClosure() {
|
|
2717
2771
|
charsToGlyphs: function ErrorFont_charsToGlyphs() {
|
2718
2772
|
return [];
|
2719
2773
|
},
|
2720
|
-
|
2774
|
+
|
2775
|
+
exportData(extraProperties = false) {
|
2721
2776
|
return {
|
2722
2777
|
error: this.error
|
2723
2778
|
};
|
2724
2779
|
}
|
2780
|
+
|
2725
2781
|
};
|
2726
2782
|
return ErrorFont;
|
2727
2783
|
}();
|
@@ -2813,7 +2869,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2813
2869
|
if (j >= signatureLength) {
|
2814
2870
|
i += j;
|
2815
2871
|
|
2816
|
-
while (i < streamBytesLength && (0,
|
2872
|
+
while (i < streamBytesLength && (0, _core_utils.isWhiteSpace)(streamBytes[i])) {
|
2817
2873
|
i++;
|
2818
2874
|
}
|
2819
2875
|
|
@@ -2825,7 +2881,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2825
2881
|
}
|
2826
2882
|
|
2827
2883
|
return {
|
2828
|
-
found
|
2884
|
+
found,
|
2829
2885
|
length: i
|
2830
2886
|
};
|
2831
2887
|
}
|
@@ -2923,10 +2979,10 @@ var Type1Font = function Type1FontClosure() {
|
|
2923
2979
|
|
2924
2980
|
var eexecBlock = getEexecBlock(file, eexecBlockLength);
|
2925
2981
|
var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
|
2926
|
-
var data = eexecBlockParser.extractFontProgram();
|
2982
|
+
var data = eexecBlockParser.extractFontProgram(properties);
|
2927
2983
|
|
2928
|
-
for (
|
2929
|
-
properties[
|
2984
|
+
for (const key in data.properties) {
|
2985
|
+
properties[key] = data.properties[key];
|
2930
2986
|
}
|
2931
2987
|
|
2932
2988
|
var charstrings = data.charstrings;
|
@@ -2943,7 +2999,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2943
2999
|
},
|
2944
3000
|
|
2945
3001
|
getCharset: function Type1Font_getCharset() {
|
2946
|
-
var charset = [
|
3002
|
+
var charset = [".notdef"];
|
2947
3003
|
var charstrings = this.charstrings;
|
2948
3004
|
|
2949
3005
|
for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -2954,7 +3010,19 @@ var Type1Font = function Type1FontClosure() {
|
|
2954
3010
|
},
|
2955
3011
|
getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
|
2956
3012
|
var charstrings = this.charstrings;
|
2957
|
-
|
3013
|
+
|
3014
|
+
if (properties.composite) {
|
3015
|
+
const charCodeToGlyphId = Object.create(null);
|
3016
|
+
|
3017
|
+
for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) {
|
3018
|
+
const charCode = properties.cMap.charCodeOf(glyphId);
|
3019
|
+
charCodeToGlyphId[charCode] = glyphId + 1;
|
3020
|
+
}
|
3021
|
+
|
3022
|
+
return charCodeToGlyphId;
|
3023
|
+
}
|
3024
|
+
|
3025
|
+
var glyphNames = [".notdef"],
|
2958
3026
|
glyphId;
|
2959
3027
|
|
2960
3028
|
for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
@@ -3028,7 +3096,7 @@ var Type1Font = function Type1FontClosure() {
|
|
3028
3096
|
var i;
|
3029
3097
|
|
3030
3098
|
for (i = 0; i < bias; i++) {
|
3031
|
-
type2Subrs.push([
|
3099
|
+
type2Subrs.push([0x0b]);
|
3032
3100
|
}
|
3033
3101
|
|
3034
3102
|
for (i = 0; i < count; i++) {
|
@@ -3042,34 +3110,34 @@ var Type1Font = function Type1FontClosure() {
|
|
3042
3110
|
cff.header = new _cff_parser.CFFHeader(1, 0, 4, 4);
|
3043
3111
|
cff.names = [name];
|
3044
3112
|
var topDict = new _cff_parser.CFFTopDict();
|
3045
|
-
topDict.setByName(
|
3046
|
-
topDict.setByName(
|
3047
|
-
topDict.setByName(
|
3048
|
-
topDict.setByName(
|
3049
|
-
topDict.setByName(
|
3050
|
-
topDict.setByName(
|
3051
|
-
topDict.setByName(
|
3052
|
-
topDict.setByName(
|
3053
|
-
topDict.setByName(
|
3054
|
-
topDict.setByName(
|
3055
|
-
topDict.setByName(
|
3113
|
+
topDict.setByName("version", 391);
|
3114
|
+
topDict.setByName("Notice", 392);
|
3115
|
+
topDict.setByName("FullName", 393);
|
3116
|
+
topDict.setByName("FamilyName", 394);
|
3117
|
+
topDict.setByName("Weight", 395);
|
3118
|
+
topDict.setByName("Encoding", null);
|
3119
|
+
topDict.setByName("FontMatrix", properties.fontMatrix);
|
3120
|
+
topDict.setByName("FontBBox", properties.bbox);
|
3121
|
+
topDict.setByName("charset", null);
|
3122
|
+
topDict.setByName("CharStrings", null);
|
3123
|
+
topDict.setByName("Private", null);
|
3056
3124
|
cff.topDict = topDict;
|
3057
3125
|
var strings = new _cff_parser.CFFStrings();
|
3058
|
-
strings.add(
|
3059
|
-
strings.add(
|
3126
|
+
strings.add("Version 0.11");
|
3127
|
+
strings.add("See original notice");
|
3060
3128
|
strings.add(name);
|
3061
3129
|
strings.add(name);
|
3062
|
-
strings.add(
|
3130
|
+
strings.add("Medium");
|
3063
3131
|
cff.strings = strings;
|
3064
3132
|
cff.globalSubrIndex = new _cff_parser.CFFIndex();
|
3065
3133
|
var count = glyphs.length;
|
3066
|
-
var charsetArray = [
|
3134
|
+
var charsetArray = [".notdef"];
|
3067
3135
|
var i, ii;
|
3068
3136
|
|
3069
3137
|
for (i = 0; i < count; i++) {
|
3070
|
-
|
3138
|
+
const glyphName = charstrings[i].glyphName;
|
3071
3139
|
|
3072
|
-
|
3140
|
+
const index = _cff_parser.CFFStandardStrings.indexOf(glyphName);
|
3073
3141
|
|
3074
3142
|
if (index === -1) {
|
3075
3143
|
strings.add(glyphName);
|
@@ -3080,7 +3148,7 @@ var Type1Font = function Type1FontClosure() {
|
|
3080
3148
|
|
3081
3149
|
cff.charset = new _cff_parser.CFFCharset(false, 0, charsetArray);
|
3082
3150
|
var charStringsIndex = new _cff_parser.CFFIndex();
|
3083
|
-
charStringsIndex.add([
|
3151
|
+
charStringsIndex.add([0x8b, 0x0e]);
|
3084
3152
|
|
3085
3153
|
for (i = 0; i < count; i++) {
|
3086
3154
|
charStringsIndex.add(glyphs[i]);
|
@@ -3088,8 +3156,8 @@ var Type1Font = function Type1FontClosure() {
|
|
3088
3156
|
|
3089
3157
|
cff.charStrings = charStringsIndex;
|
3090
3158
|
var privateDict = new _cff_parser.CFFPrivateDict();
|
3091
|
-
privateDict.setByName(
|
3092
|
-
var fields = [
|
3159
|
+
privateDict.setByName("Subrs", null);
|
3160
|
+
var fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"];
|
3093
3161
|
|
3094
3162
|
for (i = 0, ii = fields.length; i < ii; i++) {
|
3095
3163
|
var field = fields[i];
|
@@ -3136,7 +3204,7 @@ var CFFFont = function CFFFontClosure() {
|
|
3136
3204
|
try {
|
3137
3205
|
this.data = compiler.compile();
|
3138
3206
|
} catch (e) {
|
3139
|
-
(0, _util.warn)(
|
3207
|
+
(0, _util.warn)("Failed to compile font " + properties.loadedName);
|
3140
3208
|
this.data = file;
|
3141
3209
|
}
|
3142
3210
|
}
|
@@ -3158,7 +3226,7 @@ var CFFFont = function CFFFontClosure() {
|
|
3158
3226
|
|
3159
3227
|
if (properties.composite) {
|
3160
3228
|
charCodeToGlyphId = Object.create(null);
|
3161
|
-
|
3229
|
+
let charCode;
|
3162
3230
|
|
3163
3231
|
if (cff.isCIDFont) {
|
3164
3232
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|