pdfjs-dist 2.0.943 → 2.1.266
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/bower.json +1 -1
- package/build/pdf.js +15329 -11095
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +12497 -4184
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +3438 -1209
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +335 -109
- package/lib/core/arithmetic_decoder.js +274 -244
- package/lib/core/bidi.js +64 -5
- package/lib/core/ccitt.js +172 -17
- package/lib/core/ccitt_stream.js +14 -5
- package/lib/core/cff_parser.js +304 -28
- package/lib/core/charsets.js +4 -3
- package/lib/core/chunked_stream.js +379 -149
- package/lib/core/cmap.js +210 -40
- package/lib/core/colorspace.js +332 -187
- package/lib/core/crypto.js +289 -44
- package/lib/core/document.js +508 -249
- package/lib/core/encodings.js +18 -9
- package/lib/core/evaluator.js +657 -119
- package/lib/core/font_renderer.js +217 -34
- package/lib/core/fonts.js +632 -41
- package/lib/core/function.js +252 -26
- package/lib/core/glyphlist.js +2 -1
- package/lib/core/image.js +124 -27
- package/lib/core/jbig2.js +425 -65
- package/lib/core/jbig2_stream.js +18 -7
- package/lib/core/jpeg_stream.js +24 -8
- package/lib/core/jpg.js +208 -16
- package/lib/core/jpx.js +395 -5
- package/lib/core/jpx_stream.js +17 -5
- package/lib/core/metrics.js +3 -3
- package/lib/core/murmurhash3.js +23 -5
- package/lib/core/obj.js +625 -132
- package/lib/core/operator_list.js +104 -3
- package/lib/core/parser.js +262 -25
- package/lib/core/pattern.js +144 -12
- package/lib/core/pdf_manager.js +104 -70
- package/lib/core/primitives.js +74 -21
- package/lib/core/ps_parser.js +133 -44
- package/lib/core/standard_fonts.js +9 -9
- package/lib/core/stream.js +283 -31
- package/lib/core/type1_parser.js +138 -6
- package/lib/core/unicode.js +28 -1
- package/lib/core/worker.js +192 -57
- package/lib/display/annotation_layer.js +303 -123
- package/lib/display/api.js +1073 -574
- package/lib/display/api_compatibility.js +4 -1
- package/lib/display/canvas.js +314 -18
- package/lib/display/content_disposition.js +70 -23
- package/lib/display/dom_utils.js +112 -59
- package/lib/display/fetch_stream.js +95 -50
- package/lib/display/font_loader.js +250 -132
- package/lib/display/metadata.js +37 -15
- package/lib/display/network.js +123 -34
- package/lib/display/network_utils.js +23 -10
- package/lib/display/node_stream.js +162 -65
- package/lib/display/pattern_helper.js +57 -6
- package/lib/display/svg.js +194 -18
- package/lib/display/text_layer.js +128 -14
- package/lib/display/transport_stream.js +83 -27
- package/lib/display/webgl.js +63 -17
- package/lib/display/worker_options.js +4 -3
- package/lib/display/xml_parser.js +162 -52
- package/lib/examples/node/domstubs.js +56 -3
- package/lib/pdf.js +15 -2
- package/lib/pdf.worker.js +4 -2
- package/lib/shared/compatibility.js +129 -26
- package/lib/shared/global_scope.js +1 -1
- package/lib/shared/is_node.js +3 -3
- package/lib/shared/message_handler.js +103 -45
- package/lib/shared/streams_polyfill.js +20 -16
- package/lib/shared/url_polyfill.js +8 -2
- package/lib/shared/util.js +246 -84
- package/lib/test/unit/annotation_spec.js +99 -73
- package/lib/test/unit/api_spec.js +347 -113
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +17 -5
- package/lib/test/unit/clitests_helper.js +7 -8
- package/lib/test/unit/cmap_spec.js +79 -25
- package/lib/test/unit/colorspace_spec.js +65 -18
- package/lib/test/unit/crypto_spec.js +16 -4
- package/lib/test/unit/custom_spec.js +40 -52
- package/lib/test/unit/display_svg_spec.js +32 -16
- package/lib/test/unit/document_spec.js +2 -2
- package/lib/test/unit/dom_utils_spec.js +8 -8
- package/lib/test/unit/encodings_spec.js +24 -44
- package/lib/test/unit/evaluator_spec.js +15 -8
- package/lib/test/unit/function_spec.js +16 -4
- package/lib/test/unit/jasmine-boot.js +29 -16
- package/lib/test/unit/message_handler_spec.js +19 -6
- package/lib/test/unit/metadata_spec.js +64 -11
- package/lib/test/unit/murmurhash3_spec.js +2 -2
- package/lib/test/unit/network_spec.js +19 -4
- package/lib/test/unit/network_utils_spec.js +6 -4
- package/lib/test/unit/node_stream_spec.js +50 -26
- package/lib/test/unit/parser_spec.js +13 -29
- package/lib/test/unit/pdf_find_controller_spec.js +144 -32
- package/lib/test/unit/pdf_find_utils_spec.js +10 -9
- package/lib/test/unit/pdf_history_spec.js +20 -8
- package/lib/test/unit/primitives_spec.js +23 -3
- package/lib/test/unit/stream_spec.js +8 -3
- package/lib/test/unit/test_utils.js +89 -26
- package/lib/test/unit/testreporter.js +19 -1
- package/lib/test/unit/type1_parser_spec.js +7 -5
- package/lib/test/unit/ui_utils_spec.js +162 -38
- package/lib/test/unit/unicode_spec.js +13 -10
- package/lib/test/unit/util_spec.js +89 -9
- package/lib/web/annotation_layer_builder.js +38 -21
- package/lib/web/app.js +610 -245
- package/lib/web/app_options.js +54 -34
- package/lib/web/base_viewer.js +359 -162
- package/lib/web/chromecom.js +159 -80
- package/lib/web/debugger.js +161 -17
- package/lib/web/download_manager.js +29 -11
- package/lib/web/firefox_print_service.js +16 -8
- package/lib/web/firefoxcom.js +127 -91
- package/lib/web/genericcom.js +50 -31
- package/lib/web/genericl10n.js +46 -34
- package/lib/web/grab_to_pan.js +25 -3
- package/lib/web/interfaces.js +108 -61
- package/lib/web/overlay_manager.js +67 -45
- package/lib/web/password_prompt.js +20 -12
- package/lib/web/pdf_attachment_viewer.js +37 -17
- package/lib/web/pdf_cursor_tools.js +38 -15
- package/lib/web/pdf_document_properties.js +65 -24
- package/lib/web/pdf_find_bar.js +48 -20
- package/lib/web/pdf_find_controller.js +290 -89
- package/lib/web/pdf_find_utils.js +19 -3
- package/lib/web/pdf_history.js +186 -49
- package/lib/web/pdf_link_service.js +127 -52
- package/lib/web/pdf_outline_viewer.js +71 -21
- package/lib/web/pdf_page_view.js +188 -63
- package/lib/web/pdf_presentation_mode.js +98 -33
- package/lib/web/pdf_print_service.js +54 -10
- package/lib/web/pdf_rendering_queue.js +26 -4
- package/lib/web/pdf_sidebar.js +116 -62
- package/lib/web/pdf_sidebar_resizer.js +41 -15
- package/lib/web/pdf_single_page_viewer.js +65 -68
- package/lib/web/pdf_thumbnail_view.js +102 -31
- package/lib/web/pdf_thumbnail_viewer.js +62 -22
- package/lib/web/pdf_viewer.component.js +111 -31
- package/lib/web/pdf_viewer.js +80 -60
- package/lib/web/preferences.js +61 -39
- package/lib/web/secondary_toolbar.js +101 -82
- package/lib/web/text_layer_builder.js +124 -69
- package/lib/web/toolbar.js +67 -27
- package/lib/web/ui_utils.js +284 -128
- package/lib/web/view_history.js +75 -51
- package/lib/web/viewer_compatibility.js +2 -1
- package/package.json +1 -1
- package/web/pdf_viewer.css +1 -1
- package/web/pdf_viewer.js +2200 -973
- package/web/pdf_viewer.js.map +1 -1
- package/lib/web/dom_events.js +0 -140
package/lib/core/fonts.js
CHANGED
@@ -19,38 +19,46 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.getFontType =
|
27
|
+
exports.getFontType = getFontType;
|
28
|
+
exports.IdentityToUnicodeMap = exports.ToUnicodeMap = exports.FontFlags = exports.Font = exports.ErrorFont = exports.SEAC_ANALYSIS_ENABLED = void 0;
|
28
29
|
|
29
|
-
var
|
30
|
+
var _util = require("../shared/util");
|
30
31
|
|
31
|
-
var
|
32
|
+
var _cff_parser = require("./cff_parser");
|
32
33
|
|
33
|
-
var
|
34
|
+
var _glyphlist = require("./glyphlist");
|
34
35
|
|
35
|
-
var
|
36
|
+
var _encodings = require("./encodings");
|
36
37
|
|
37
|
-
var
|
38
|
+
var _standard_fonts = require("./standard_fonts");
|
38
39
|
|
39
|
-
var
|
40
|
+
var _unicode = require("./unicode");
|
40
41
|
|
41
|
-
var
|
42
|
+
var _font_renderer = require("./font_renderer");
|
42
43
|
|
43
|
-
var
|
44
|
+
var _cmap = require("./cmap");
|
44
45
|
|
45
|
-
var
|
46
|
+
var _stream = require("./stream");
|
46
47
|
|
47
|
-
var
|
48
|
+
var _type1_parser = require("./type1_parser");
|
48
49
|
|
49
|
-
|
50
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
51
|
+
|
52
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
53
|
+
|
54
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
55
|
+
|
56
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
50
57
|
|
51
58
|
var PRIVATE_USE_AREAS = [[0xE000, 0xF8FF], [0x100000, 0x10FFFD]];
|
52
59
|
var PDF_GLYPH_SPACE_UNITS = 1000;
|
53
60
|
var SEAC_ANALYSIS_ENABLED = true;
|
61
|
+
exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
|
54
62
|
var FontFlags = {
|
55
63
|
FixedPitch: 1,
|
56
64
|
Serif: 2,
|
@@ -62,70 +70,95 @@ var FontFlags = {
|
|
62
70
|
SmallCap: 131072,
|
63
71
|
ForceBold: 262144
|
64
72
|
};
|
73
|
+
exports.FontFlags = FontFlags;
|
65
74
|
var MacStandardGlyphOrdering = ['.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis', 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis', 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar', 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply', 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter', 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla', 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
|
75
|
+
|
66
76
|
function adjustWidths(properties) {
|
67
77
|
if (!properties.fontMatrix) {
|
68
78
|
return;
|
69
79
|
}
|
80
|
+
|
70
81
|
if (properties.fontMatrix[0] === _util.FONT_IDENTITY_MATRIX[0]) {
|
71
82
|
return;
|
72
83
|
}
|
84
|
+
|
73
85
|
var scale = 0.001 / properties.fontMatrix[0];
|
74
86
|
var glyphsWidths = properties.widths;
|
87
|
+
|
75
88
|
for (var glyph in glyphsWidths) {
|
76
89
|
glyphsWidths[glyph] *= scale;
|
77
90
|
}
|
91
|
+
|
78
92
|
properties.defaultWidth *= scale;
|
79
93
|
}
|
94
|
+
|
80
95
|
function adjustToUnicode(properties, builtInEncoding) {
|
81
96
|
if (properties.hasIncludedToUnicodeMap) {
|
82
97
|
return;
|
83
98
|
}
|
99
|
+
|
84
100
|
if (properties.hasEncoding) {
|
85
101
|
return;
|
86
102
|
}
|
103
|
+
|
87
104
|
if (builtInEncoding === properties.defaultEncoding) {
|
88
105
|
return;
|
89
106
|
}
|
107
|
+
|
90
108
|
if (properties.toUnicode instanceof IdentityToUnicodeMap) {
|
91
109
|
return;
|
92
110
|
}
|
111
|
+
|
93
112
|
var toUnicode = [],
|
94
113
|
glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
114
|
+
|
95
115
|
for (var charCode in builtInEncoding) {
|
96
116
|
var glyphName = builtInEncoding[charCode];
|
97
117
|
var unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
118
|
+
|
98
119
|
if (unicode !== -1) {
|
99
120
|
toUnicode[charCode] = String.fromCharCode(unicode);
|
100
121
|
}
|
101
122
|
}
|
123
|
+
|
102
124
|
properties.toUnicode.amend(toUnicode);
|
103
125
|
}
|
126
|
+
|
104
127
|
function getFontType(type, subtype) {
|
105
128
|
switch (type) {
|
106
129
|
case 'Type1':
|
107
130
|
return subtype === 'Type1C' ? _util.FontType.TYPE1C : _util.FontType.TYPE1;
|
131
|
+
|
108
132
|
case 'CIDFontType0':
|
109
133
|
return subtype === 'CIDFontType0C' ? _util.FontType.CIDFONTTYPE0C : _util.FontType.CIDFONTTYPE0;
|
134
|
+
|
110
135
|
case 'OpenType':
|
111
136
|
return _util.FontType.OPENTYPE;
|
137
|
+
|
112
138
|
case 'TrueType':
|
113
139
|
return _util.FontType.TRUETYPE;
|
140
|
+
|
114
141
|
case 'CIDFontType2':
|
115
142
|
return _util.FontType.CIDFONTTYPE2;
|
143
|
+
|
116
144
|
case 'MMType1':
|
117
145
|
return _util.FontType.MMTYPE1;
|
146
|
+
|
118
147
|
case 'Type0':
|
119
148
|
return _util.FontType.TYPE0;
|
149
|
+
|
120
150
|
default:
|
121
151
|
return _util.FontType.UNKNOWN;
|
122
152
|
}
|
123
153
|
}
|
154
|
+
|
124
155
|
function recoverGlyphName(name, glyphsUnicodeMap) {
|
125
156
|
if (glyphsUnicodeMap[name] !== undefined) {
|
126
157
|
return name;
|
127
158
|
}
|
159
|
+
|
128
160
|
var unicode = (0, _unicode.getUnicodeForGlyph)(name, glyphsUnicodeMap);
|
161
|
+
|
129
162
|
if (unicode !== -1) {
|
130
163
|
for (var key in glyphsUnicodeMap) {
|
131
164
|
if (glyphsUnicodeMap[key] === unicode) {
|
@@ -133,9 +166,11 @@ function recoverGlyphName(name, glyphsUnicodeMap) {
|
|
133
166
|
}
|
134
167
|
}
|
135
168
|
}
|
169
|
+
|
136
170
|
(0, _util.info)('Unable to recover a standard glyph name for: ' + name);
|
137
171
|
return name;
|
138
172
|
}
|
173
|
+
|
139
174
|
var Glyph = function GlyphClosure() {
|
140
175
|
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
|
141
176
|
this.fontChar = fontChar;
|
@@ -147,21 +182,25 @@ var Glyph = function GlyphClosure() {
|
|
147
182
|
this.isSpace = isSpace;
|
148
183
|
this.isInFont = isInFont;
|
149
184
|
}
|
185
|
+
|
150
186
|
Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
|
151
187
|
return this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && this.width === width && this.vmetric === vmetric && this.operatorListId === operatorListId && this.isSpace === isSpace && this.isInFont === isInFont;
|
152
188
|
};
|
189
|
+
|
153
190
|
return Glyph;
|
154
191
|
}();
|
192
|
+
|
155
193
|
var ToUnicodeMap = function ToUnicodeMapClosure() {
|
156
194
|
function ToUnicodeMap() {
|
157
195
|
var cmap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
158
|
-
|
159
196
|
this._map = cmap;
|
160
197
|
}
|
198
|
+
|
161
199
|
ToUnicodeMap.prototype = {
|
162
200
|
get length() {
|
163
201
|
return this._map.length;
|
164
202
|
},
|
203
|
+
|
165
204
|
forEach: function forEach(callback) {
|
166
205
|
for (var charCode in this._map) {
|
167
206
|
callback(charCode, this._map[charCode].charCodeAt(0));
|
@@ -175,14 +214,17 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
175
214
|
},
|
176
215
|
charCodeOf: function charCodeOf(value) {
|
177
216
|
var map = this._map;
|
217
|
+
|
178
218
|
if (map.length <= 0x10000) {
|
179
219
|
return map.indexOf(value);
|
180
220
|
}
|
221
|
+
|
181
222
|
for (var charCode in map) {
|
182
223
|
if (map[charCode] === value) {
|
183
224
|
return charCode | 0;
|
184
225
|
}
|
185
226
|
}
|
227
|
+
|
186
228
|
return -1;
|
187
229
|
},
|
188
230
|
amend: function amend(map) {
|
@@ -193,15 +235,20 @@ var ToUnicodeMap = function ToUnicodeMapClosure() {
|
|
193
235
|
};
|
194
236
|
return ToUnicodeMap;
|
195
237
|
}();
|
238
|
+
|
239
|
+
exports.ToUnicodeMap = ToUnicodeMap;
|
240
|
+
|
196
241
|
var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
197
242
|
function IdentityToUnicodeMap(firstChar, lastChar) {
|
198
243
|
this.firstChar = firstChar;
|
199
244
|
this.lastChar = lastChar;
|
200
245
|
}
|
246
|
+
|
201
247
|
IdentityToUnicodeMap.prototype = {
|
202
248
|
get length() {
|
203
249
|
return this.lastChar + 1 - this.firstChar;
|
204
250
|
},
|
251
|
+
|
205
252
|
forEach: function forEach(callback) {
|
206
253
|
for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
|
207
254
|
callback(i, i);
|
@@ -214,6 +261,7 @@ var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
|
214
261
|
if (this.firstChar <= i && i <= this.lastChar) {
|
215
262
|
return String.fromCharCode(i);
|
216
263
|
}
|
264
|
+
|
217
265
|
return undefined;
|
218
266
|
},
|
219
267
|
charCodeOf: function charCodeOf(v) {
|
@@ -225,19 +273,25 @@ var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
|
|
225
273
|
};
|
226
274
|
return IdentityToUnicodeMap;
|
227
275
|
}();
|
276
|
+
|
277
|
+
exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
|
278
|
+
|
228
279
|
var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
229
280
|
function writeInt16(dest, offset, num) {
|
230
281
|
dest[offset] = num >> 8 & 0xFF;
|
231
282
|
dest[offset + 1] = num & 0xFF;
|
232
283
|
}
|
284
|
+
|
233
285
|
function writeInt32(dest, offset, num) {
|
234
286
|
dest[offset] = num >> 24 & 0xFF;
|
235
287
|
dest[offset + 1] = num >> 16 & 0xFF;
|
236
288
|
dest[offset + 2] = num >> 8 & 0xFF;
|
237
289
|
dest[offset + 3] = num & 0xFF;
|
238
290
|
}
|
291
|
+
|
239
292
|
function writeData(dest, offset, data) {
|
240
293
|
var i, ii;
|
294
|
+
|
241
295
|
if (data instanceof Uint8Array) {
|
242
296
|
dest.set(data, offset);
|
243
297
|
} else if (typeof data === 'string') {
|
@@ -250,17 +304,21 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
250
304
|
}
|
251
305
|
}
|
252
306
|
}
|
307
|
+
|
253
308
|
function OpenTypeFileBuilder(sfnt) {
|
254
309
|
this.sfnt = sfnt;
|
255
310
|
this.tables = Object.create(null);
|
256
311
|
}
|
312
|
+
|
257
313
|
OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
|
258
314
|
var maxPower2 = 1,
|
259
315
|
log2 = 0;
|
316
|
+
|
260
317
|
while ((maxPower2 ^ entriesCount) > maxPower2) {
|
261
318
|
maxPower2 <<= 1;
|
262
319
|
log2++;
|
263
320
|
}
|
321
|
+
|
264
322
|
var searchRange = maxPower2 * entrySize;
|
265
323
|
return {
|
266
324
|
range: searchRange,
|
@@ -268,6 +326,7 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
268
326
|
rangeShift: entrySize * entriesCount - searchRange
|
269
327
|
};
|
270
328
|
};
|
329
|
+
|
271
330
|
var OTF_HEADER_SIZE = 12;
|
272
331
|
var OTF_TABLE_ENTRY_SIZE = 16;
|
273
332
|
OpenTypeFileBuilder.prototype = {
|
@@ -280,20 +339,25 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
280
339
|
var i, j, jj, table, tableName;
|
281
340
|
var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
|
282
341
|
var tableOffsets = [offset];
|
342
|
+
|
283
343
|
for (i = 0; i < numTables; i++) {
|
284
344
|
table = tables[tablesNames[i]];
|
285
345
|
var paddedLength = (table.length + 3 & ~3) >>> 0;
|
286
346
|
offset += paddedLength;
|
287
347
|
tableOffsets.push(offset);
|
288
348
|
}
|
349
|
+
|
289
350
|
var file = new Uint8Array(offset);
|
351
|
+
|
290
352
|
for (i = 0; i < numTables; i++) {
|
291
353
|
table = tables[tablesNames[i]];
|
292
354
|
writeData(file, tableOffsets[i], table);
|
293
355
|
}
|
356
|
+
|
294
357
|
if (sfnt === 'true') {
|
295
358
|
sfnt = (0, _util.string32)(0x00010000);
|
296
359
|
}
|
360
|
+
|
297
361
|
file[0] = sfnt.charCodeAt(0) & 0xFF;
|
298
362
|
file[1] = sfnt.charCodeAt(1) & 0xFF;
|
299
363
|
file[2] = sfnt.charCodeAt(2) & 0xFF;
|
@@ -304,6 +368,7 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
304
368
|
writeInt16(file, 8, searchParams.entry);
|
305
369
|
writeInt16(file, 10, searchParams.rangeShift);
|
306
370
|
offset = OTF_HEADER_SIZE;
|
371
|
+
|
307
372
|
for (i = 0; i < numTables; i++) {
|
308
373
|
tableName = tablesNames[i];
|
309
374
|
file[offset] = tableName.charCodeAt(0) & 0xFF;
|
@@ -311,26 +376,31 @@ var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
|
|
311
376
|
file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
|
312
377
|
file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
|
313
378
|
var checksum = 0;
|
379
|
+
|
314
380
|
for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
315
381
|
var quad = (0, _util.readUint32)(file, j);
|
316
382
|
checksum = checksum + quad >>> 0;
|
317
383
|
}
|
384
|
+
|
318
385
|
writeInt32(file, offset + 4, checksum);
|
319
386
|
writeInt32(file, offset + 8, tableOffsets[i]);
|
320
387
|
writeInt32(file, offset + 12, tables[tableName].length);
|
321
388
|
offset += OTF_TABLE_ENTRY_SIZE;
|
322
389
|
}
|
390
|
+
|
323
391
|
return file;
|
324
392
|
},
|
325
393
|
addTable: function OpenTypeFileBuilder_addTable(tag, data) {
|
326
394
|
if (tag in this.tables) {
|
327
395
|
throw new Error('Table ' + tag + ' already exists');
|
328
396
|
}
|
397
|
+
|
329
398
|
this.tables[tag] = data;
|
330
399
|
}
|
331
400
|
};
|
332
401
|
return OpenTypeFileBuilder;
|
333
402
|
}();
|
403
|
+
|
334
404
|
var Font = function FontClosure() {
|
335
405
|
function Font(name, file, properties) {
|
336
406
|
var charCode;
|
@@ -362,23 +432,29 @@ var Font = function FontClosure() {
|
|
362
432
|
this.toUnicode = properties.toUnicode;
|
363
433
|
this.fallbackToUnicode = properties.fallbackToUnicode || new ToUnicodeMap();
|
364
434
|
this.toFontChar = [];
|
435
|
+
|
365
436
|
if (properties.type === 'Type3') {
|
366
437
|
for (charCode = 0; charCode < 256; charCode++) {
|
367
438
|
this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
|
368
439
|
}
|
440
|
+
|
369
441
|
this.fontType = _util.FontType.TYPE3;
|
370
442
|
return;
|
371
443
|
}
|
444
|
+
|
372
445
|
this.cidEncoding = properties.cidEncoding;
|
373
446
|
this.vertical = properties.vertical;
|
447
|
+
|
374
448
|
if (this.vertical) {
|
375
449
|
this.vmetrics = properties.vmetrics;
|
376
450
|
this.defaultVMetrics = properties.defaultVMetrics;
|
377
451
|
}
|
452
|
+
|
378
453
|
if (!file || file.isEmpty) {
|
379
454
|
if (file) {
|
380
455
|
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ')');
|
381
456
|
}
|
457
|
+
|
382
458
|
this.fallbackToSystemFont();
|
383
459
|
return;
|
384
460
|
}
|
@@ -391,13 +467,16 @@ var Font = function FontClosure() {
|
|
391
467
|
subtype = _getFontFileType2[1];
|
392
468
|
|
393
469
|
if (type !== this.type || subtype !== this.subtype) {
|
394
|
-
(0, _util.info)('Inconsistent font file Type/SubType, expected: ' + (this.type
|
470
|
+
(0, _util.info)('Inconsistent font file Type/SubType, expected: ' + "".concat(this.type, "/").concat(this.subtype, " but found: ").concat(type, "/").concat(subtype, "."));
|
395
471
|
}
|
472
|
+
|
396
473
|
try {
|
397
474
|
var data;
|
475
|
+
|
398
476
|
switch (type) {
|
399
477
|
case 'MMType1':
|
400
478
|
(0, _util.info)('MMType1 font (' + name + '), falling back to Type1.');
|
479
|
+
|
401
480
|
case 'Type1':
|
402
481
|
case 'CIDFontType0':
|
403
482
|
this.mimetype = 'font/opentype';
|
@@ -405,24 +484,29 @@ var Font = function FontClosure() {
|
|
405
484
|
adjustWidths(properties);
|
406
485
|
data = this.convert(name, cff, properties);
|
407
486
|
break;
|
487
|
+
|
408
488
|
case 'OpenType':
|
409
489
|
case 'TrueType':
|
410
490
|
case 'CIDFontType2':
|
411
491
|
this.mimetype = 'font/opentype';
|
412
492
|
data = this.checkAndRepair(name, file, properties);
|
493
|
+
|
413
494
|
if (this.isOpenType) {
|
414
495
|
adjustWidths(properties);
|
415
496
|
type = 'OpenType';
|
416
497
|
}
|
498
|
+
|
417
499
|
break;
|
500
|
+
|
418
501
|
default:
|
419
|
-
throw new _util.FormatError(
|
502
|
+
throw new _util.FormatError("Font ".concat(type, " is not supported"));
|
420
503
|
}
|
421
504
|
} catch (e) {
|
422
505
|
(0, _util.warn)(e);
|
423
506
|
this.fallbackToSystemFont();
|
424
507
|
return;
|
425
508
|
}
|
509
|
+
|
426
510
|
this.data = data;
|
427
511
|
this.fontType = getFontType(type, subtype);
|
428
512
|
this.fontMatrix = properties.fontMatrix;
|
@@ -432,69 +516,86 @@ var Font = function FontClosure() {
|
|
432
516
|
this.encoding = properties.baseEncoding;
|
433
517
|
this.seacMap = properties.seacMap;
|
434
518
|
}
|
519
|
+
|
435
520
|
Font.getFontID = function () {
|
436
521
|
var ID = 1;
|
437
522
|
return function Font_getFontID() {
|
438
523
|
return String(ID++);
|
439
524
|
};
|
440
525
|
}();
|
526
|
+
|
441
527
|
function int16(b0, b1) {
|
442
528
|
return (b0 << 8) + b1;
|
443
529
|
}
|
530
|
+
|
444
531
|
function writeSignedInt16(bytes, index, value) {
|
445
532
|
bytes[index + 1] = value;
|
446
533
|
bytes[index] = value >>> 8;
|
447
534
|
}
|
535
|
+
|
448
536
|
function signedInt16(b0, b1) {
|
449
537
|
var value = (b0 << 8) + b1;
|
450
538
|
return value & 1 << 15 ? value - 0x10000 : value;
|
451
539
|
}
|
540
|
+
|
452
541
|
function int32(b0, b1, b2, b3) {
|
453
542
|
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
|
454
543
|
}
|
544
|
+
|
455
545
|
function string16(value) {
|
456
546
|
return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
|
457
547
|
}
|
548
|
+
|
458
549
|
function safeString16(value) {
|
459
550
|
value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
|
460
551
|
return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
|
461
552
|
}
|
553
|
+
|
462
554
|
function isTrueTypeFile(file) {
|
463
555
|
var header = file.peekBytes(4);
|
464
556
|
return (0, _util.readUint32)(header, 0) === 0x00010000 || (0, _util.bytesToString)(header) === 'true';
|
465
557
|
}
|
558
|
+
|
466
559
|
function isTrueTypeCollectionFile(file) {
|
467
560
|
var header = file.peekBytes(4);
|
468
561
|
return (0, _util.bytesToString)(header) === 'ttcf';
|
469
562
|
}
|
563
|
+
|
470
564
|
function isOpenTypeFile(file) {
|
471
565
|
var header = file.peekBytes(4);
|
472
566
|
return (0, _util.bytesToString)(header) === 'OTTO';
|
473
567
|
}
|
568
|
+
|
474
569
|
function isType1File(file) {
|
475
570
|
var header = file.peekBytes(2);
|
571
|
+
|
476
572
|
if (header[0] === 0x25 && header[1] === 0x21) {
|
477
573
|
return true;
|
478
574
|
}
|
575
|
+
|
479
576
|
if (header[0] === 0x80 && header[1] === 0x01) {
|
480
577
|
return true;
|
481
578
|
}
|
579
|
+
|
482
580
|
return false;
|
483
581
|
}
|
582
|
+
|
484
583
|
function isCFFFile(file) {
|
485
584
|
var header = file.peekBytes(4);
|
585
|
+
|
486
586
|
if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
|
487
587
|
return true;
|
488
588
|
}
|
589
|
+
|
489
590
|
return false;
|
490
591
|
}
|
592
|
+
|
491
593
|
function getFontFileType(file, _ref) {
|
492
594
|
var type = _ref.type,
|
493
595
|
subtype = _ref.subtype,
|
494
596
|
composite = _ref.composite;
|
597
|
+
var fileType, fileSubtype;
|
495
598
|
|
496
|
-
var fileType = void 0,
|
497
|
-
fileSubtype = void 0;
|
498
599
|
if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
|
499
600
|
if (composite) {
|
500
601
|
fileType = 'CIDFontType2';
|
@@ -526,112 +627,144 @@ var Font = function FontClosure() {
|
|
526
627
|
fileType = type;
|
527
628
|
fileSubtype = subtype;
|
528
629
|
}
|
630
|
+
|
529
631
|
return [fileType, fileSubtype];
|
530
632
|
}
|
633
|
+
|
531
634
|
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
532
635
|
var toFontChar = [],
|
533
636
|
unicode;
|
637
|
+
|
534
638
|
for (var i = 0, ii = encoding.length; i < ii; i++) {
|
535
639
|
unicode = (0, _unicode.getUnicodeForGlyph)(encoding[i], glyphsUnicodeMap);
|
640
|
+
|
536
641
|
if (unicode !== -1) {
|
537
642
|
toFontChar[i] = unicode;
|
538
643
|
}
|
539
644
|
}
|
645
|
+
|
540
646
|
for (var charCode in differences) {
|
541
647
|
unicode = (0, _unicode.getUnicodeForGlyph)(differences[charCode], glyphsUnicodeMap);
|
648
|
+
|
542
649
|
if (unicode !== -1) {
|
543
650
|
toFontChar[+charCode] = unicode;
|
544
651
|
}
|
545
652
|
}
|
653
|
+
|
546
654
|
return toFontChar;
|
547
655
|
}
|
656
|
+
|
548
657
|
function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId) {
|
549
658
|
var newMap = Object.create(null);
|
550
659
|
var toFontChar = [];
|
551
660
|
var privateUseAreaIndex = 0;
|
552
661
|
var nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
|
553
662
|
var privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
|
663
|
+
|
554
664
|
for (var originalCharCode in charCodeToGlyphId) {
|
555
665
|
originalCharCode |= 0;
|
556
666
|
var glyphId = charCodeToGlyphId[originalCharCode];
|
667
|
+
|
557
668
|
if (!hasGlyph(glyphId)) {
|
558
669
|
continue;
|
559
670
|
}
|
671
|
+
|
560
672
|
if (nextAvailableFontCharCode > privateUseOffetEnd) {
|
561
673
|
privateUseAreaIndex++;
|
674
|
+
|
562
675
|
if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
|
563
676
|
(0, _util.warn)('Ran out of space in font private use area.');
|
564
677
|
break;
|
565
678
|
}
|
679
|
+
|
566
680
|
nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
|
567
681
|
privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
|
568
682
|
}
|
683
|
+
|
569
684
|
var fontCharCode = nextAvailableFontCharCode++;
|
685
|
+
|
570
686
|
if (glyphId === 0) {
|
571
687
|
glyphId = newGlyphZeroId;
|
572
688
|
}
|
689
|
+
|
573
690
|
newMap[fontCharCode] = glyphId;
|
574
691
|
toFontChar[originalCharCode] = fontCharCode;
|
575
692
|
}
|
693
|
+
|
576
694
|
return {
|
577
695
|
toFontChar: toFontChar,
|
578
696
|
charCodeToGlyphId: newMap,
|
579
697
|
nextAvailableFontCharCode: nextAvailableFontCharCode
|
580
698
|
};
|
581
699
|
}
|
700
|
+
|
582
701
|
function getRanges(glyphs, numGlyphs) {
|
583
702
|
var codes = [];
|
703
|
+
|
584
704
|
for (var charCode in glyphs) {
|
585
705
|
if (glyphs[charCode] >= numGlyphs) {
|
586
706
|
continue;
|
587
707
|
}
|
708
|
+
|
588
709
|
codes.push({
|
589
710
|
fontCharCode: charCode | 0,
|
590
711
|
glyphId: glyphs[charCode]
|
591
712
|
});
|
592
713
|
}
|
714
|
+
|
593
715
|
if (codes.length === 0) {
|
594
716
|
codes.push({
|
595
717
|
fontCharCode: 0,
|
596
718
|
glyphId: 0
|
597
719
|
});
|
598
720
|
}
|
721
|
+
|
599
722
|
codes.sort(function fontGetRangesSort(a, b) {
|
600
723
|
return a.fontCharCode - b.fontCharCode;
|
601
724
|
});
|
602
725
|
var ranges = [];
|
603
726
|
var length = codes.length;
|
727
|
+
|
604
728
|
for (var n = 0; n < length;) {
|
605
729
|
var start = codes[n].fontCharCode;
|
606
730
|
var codeIndices = [codes[n].glyphId];
|
607
731
|
++n;
|
608
732
|
var end = start;
|
733
|
+
|
609
734
|
while (n < length && end + 1 === codes[n].fontCharCode) {
|
610
735
|
codeIndices.push(codes[n].glyphId);
|
611
736
|
++end;
|
612
737
|
++n;
|
738
|
+
|
613
739
|
if (end === 0xFFFF) {
|
614
740
|
break;
|
615
741
|
}
|
616
742
|
}
|
743
|
+
|
617
744
|
ranges.push([start, end, codeIndices]);
|
618
745
|
}
|
746
|
+
|
619
747
|
return ranges;
|
620
748
|
}
|
749
|
+
|
621
750
|
function createCmapTable(glyphs, numGlyphs) {
|
622
751
|
var ranges = getRanges(glyphs, numGlyphs);
|
623
752
|
var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
|
624
753
|
var cmap = '\x00\x00' + string16(numTables) + '\x00\x03' + '\x00\x01' + (0, _util.string32)(4 + numTables * 8);
|
625
754
|
var i, ii, j, jj;
|
755
|
+
|
626
756
|
for (i = ranges.length - 1; i >= 0; --i) {
|
627
757
|
if (ranges[i][0] <= 0xFFFF) {
|
628
758
|
break;
|
629
759
|
}
|
630
760
|
}
|
761
|
+
|
631
762
|
var bmpLength = i + 1;
|
763
|
+
|
632
764
|
if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
|
633
765
|
ranges[i][1] = 0xFFFE;
|
634
766
|
}
|
767
|
+
|
635
768
|
var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
|
636
769
|
var segCount = bmpLength + trailingRangesCount;
|
637
770
|
var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
|
@@ -642,6 +775,7 @@ var Font = function FontClosure() {
|
|
642
775
|
var glyphsIds = '';
|
643
776
|
var bias = 0;
|
644
777
|
var range, start, end, codes;
|
778
|
+
|
645
779
|
for (i = 0, ii = bmpLength; i < ii; i++) {
|
646
780
|
range = ranges[i];
|
647
781
|
start = range[0];
|
@@ -650,17 +784,20 @@ var Font = function FontClosure() {
|
|
650
784
|
endCount += string16(end);
|
651
785
|
codes = range[2];
|
652
786
|
var contiguous = true;
|
787
|
+
|
653
788
|
for (j = 1, jj = codes.length; j < jj; ++j) {
|
654
789
|
if (codes[j] !== codes[j - 1] + 1) {
|
655
790
|
contiguous = false;
|
656
791
|
break;
|
657
792
|
}
|
658
793
|
}
|
794
|
+
|
659
795
|
if (!contiguous) {
|
660
796
|
var offset = (segCount - i) * 2 + bias * 2;
|
661
797
|
bias += end - start + 1;
|
662
798
|
idDeltas += string16(0);
|
663
799
|
idRangeOffsets += string16(offset);
|
800
|
+
|
664
801
|
for (j = 0, jj = codes.length; j < jj; ++j) {
|
665
802
|
glyphsIds += string16(codes[j]);
|
666
803
|
}
|
@@ -670,23 +807,28 @@ var Font = function FontClosure() {
|
|
670
807
|
idRangeOffsets += string16(0);
|
671
808
|
}
|
672
809
|
}
|
810
|
+
|
673
811
|
if (trailingRangesCount > 0) {
|
674
812
|
endCount += '\xFF\xFF';
|
675
813
|
startCount += '\xFF\xFF';
|
676
814
|
idDeltas += '\x00\x01';
|
677
815
|
idRangeOffsets += '\x00\x00';
|
678
816
|
}
|
817
|
+
|
679
818
|
var format314 = '\x00\x00' + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
|
680
819
|
var format31012 = '';
|
681
820
|
var header31012 = '';
|
821
|
+
|
682
822
|
if (numTables > 1) {
|
683
823
|
cmap += '\x00\x03' + '\x00\x0A' + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);
|
684
824
|
format31012 = '';
|
825
|
+
|
685
826
|
for (i = 0, ii = ranges.length; i < ii; i++) {
|
686
827
|
range = ranges[i];
|
687
828
|
start = range[0];
|
688
829
|
codes = range[2];
|
689
830
|
var code = codes[0];
|
831
|
+
|
690
832
|
for (j = 1, jj = codes.length; j < jj; ++j) {
|
691
833
|
if (codes[j] !== codes[j - 1] + 1) {
|
692
834
|
end = range[0] + j - 1;
|
@@ -695,33 +837,44 @@ var Font = function FontClosure() {
|
|
695
837
|
code = codes[j];
|
696
838
|
}
|
697
839
|
}
|
840
|
+
|
698
841
|
format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);
|
699
842
|
}
|
843
|
+
|
700
844
|
header31012 = '\x00\x0C' + '\x00\x00' + (0, _util.string32)(format31012.length + 16) + '\x00\x00\x00\x00' + (0, _util.string32)(format31012.length / 12);
|
701
845
|
}
|
846
|
+
|
702
847
|
return cmap + '\x00\x04' + string16(format314.length + 4) + format314 + header31012 + format31012;
|
703
848
|
}
|
849
|
+
|
704
850
|
function validateOS2Table(os2) {
|
705
851
|
var stream = new _stream.Stream(os2.data);
|
706
852
|
var version = stream.getUint16();
|
707
853
|
stream.getBytes(60);
|
708
854
|
var selection = stream.getUint16();
|
855
|
+
|
709
856
|
if (version < 4 && selection & 0x0300) {
|
710
857
|
return false;
|
711
858
|
}
|
859
|
+
|
712
860
|
var firstChar = stream.getUint16();
|
713
861
|
var lastChar = stream.getUint16();
|
862
|
+
|
714
863
|
if (firstChar > lastChar) {
|
715
864
|
return false;
|
716
865
|
}
|
866
|
+
|
717
867
|
stream.getBytes(6);
|
718
868
|
var usWinAscent = stream.getUint16();
|
869
|
+
|
719
870
|
if (usWinAscent === 0) {
|
720
871
|
return false;
|
721
872
|
}
|
873
|
+
|
722
874
|
os2.data[8] = os2.data[9] = 0;
|
723
875
|
return true;
|
724
876
|
}
|
877
|
+
|
725
878
|
function createOS2Table(properties, charstrings, override) {
|
726
879
|
override = override || {
|
727
880
|
unitsPerEm: 0,
|
@@ -736,16 +889,21 @@ var Font = function FontClosure() {
|
|
736
889
|
var ulUnicodeRange4 = 0;
|
737
890
|
var firstCharIndex = null;
|
738
891
|
var lastCharIndex = 0;
|
892
|
+
|
739
893
|
if (charstrings) {
|
740
894
|
for (var code in charstrings) {
|
741
895
|
code |= 0;
|
896
|
+
|
742
897
|
if (firstCharIndex > code || !firstCharIndex) {
|
743
898
|
firstCharIndex = code;
|
744
899
|
}
|
900
|
+
|
745
901
|
if (lastCharIndex < code) {
|
746
902
|
lastCharIndex = code;
|
747
903
|
}
|
904
|
+
|
748
905
|
var position = (0, _unicode.getUnicodeRangeFor)(code);
|
906
|
+
|
749
907
|
if (position < 32) {
|
750
908
|
ulUnicodeRange1 |= 1 << position;
|
751
909
|
} else if (position < 64) {
|
@@ -758,6 +916,7 @@ var Font = function FontClosure() {
|
|
758
916
|
throw new _util.FormatError('Unicode ranges Bits > 123 are reserved for internal usage');
|
759
917
|
}
|
760
918
|
}
|
919
|
+
|
761
920
|
if (lastCharIndex > 0xFFFF) {
|
762
921
|
lastCharIndex = 0xFFFF;
|
763
922
|
}
|
@@ -765,37 +924,47 @@ var Font = function FontClosure() {
|
|
765
924
|
firstCharIndex = 0;
|
766
925
|
lastCharIndex = 255;
|
767
926
|
}
|
927
|
+
|
768
928
|
var bbox = properties.bbox || [0, 0, 0, 0];
|
769
929
|
var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
|
770
930
|
var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
|
771
931
|
var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
|
772
932
|
var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
|
933
|
+
|
773
934
|
if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
|
774
935
|
typoDescent = -typoDescent;
|
775
936
|
}
|
937
|
+
|
776
938
|
var winAscent = override.yMax || typoAscent;
|
777
939
|
var winDescent = -override.yMin || -typoDescent;
|
778
940
|
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';
|
779
941
|
}
|
942
|
+
|
780
943
|
function createPostTable(properties) {
|
781
944
|
var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
|
782
945
|
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';
|
783
946
|
}
|
947
|
+
|
784
948
|
function createNameTable(name, proto) {
|
785
949
|
if (!proto) {
|
786
950
|
proto = [[], []];
|
787
951
|
}
|
952
|
+
|
788
953
|
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'];
|
789
954
|
var stringsUnicode = [];
|
790
955
|
var i, ii, j, jj, str;
|
956
|
+
|
791
957
|
for (i = 0, ii = strings.length; i < ii; i++) {
|
792
958
|
str = proto[1][i] || strings[i];
|
793
959
|
var strBufUnicode = [];
|
960
|
+
|
794
961
|
for (j = 0, jj = str.length; j < jj; j++) {
|
795
962
|
strBufUnicode.push(string16(str.charCodeAt(j)));
|
796
963
|
}
|
964
|
+
|
797
965
|
stringsUnicode.push(strBufUnicode.join(''));
|
798
966
|
}
|
967
|
+
|
799
968
|
var names = [strings, stringsUnicode];
|
800
969
|
var platforms = ['\x00\x01', '\x00\x03'];
|
801
970
|
var encodings = ['\x00\x00', '\x00\x01'];
|
@@ -803,8 +972,10 @@ var Font = function FontClosure() {
|
|
803
972
|
var namesRecordCount = strings.length * platforms.length;
|
804
973
|
var nameTable = '\x00\x00' + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
|
805
974
|
var strOffset = 0;
|
975
|
+
|
806
976
|
for (i = 0, ii = platforms.length; i < ii; i++) {
|
807
977
|
var strs = names[i];
|
978
|
+
|
808
979
|
for (j = 0, jj = strs.length; j < jj; j++) {
|
809
980
|
str = strs[j];
|
810
981
|
var nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset);
|
@@ -812,25 +983,33 @@ var Font = function FontClosure() {
|
|
812
983
|
strOffset += str.length;
|
813
984
|
}
|
814
985
|
}
|
986
|
+
|
815
987
|
nameTable += strings.join('') + stringsUnicode.join('');
|
816
988
|
return nameTable;
|
817
989
|
}
|
990
|
+
|
818
991
|
Font.prototype = {
|
819
992
|
name: null,
|
820
993
|
font: null,
|
821
994
|
mimetype: null,
|
822
995
|
encoding: null,
|
996
|
+
disableFontFace: false,
|
997
|
+
|
823
998
|
get renderer() {
|
824
999
|
var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
|
1000
|
+
|
825
1001
|
return (0, _util.shadow)(this, 'renderer', renderer);
|
826
1002
|
},
|
1003
|
+
|
827
1004
|
exportData: function Font_exportData() {
|
828
1005
|
var data = {};
|
1006
|
+
|
829
1007
|
for (var i in this) {
|
830
1008
|
if (this.hasOwnProperty(i)) {
|
831
1009
|
data[i] = this[i];
|
832
1010
|
}
|
833
1011
|
}
|
1012
|
+
|
834
1013
|
return data;
|
835
1014
|
},
|
836
1015
|
fallbackToSystemFont: function Font_fallbackToSystemFont() {
|
@@ -850,29 +1029,37 @@ var Font = function FontClosure() {
|
|
850
1029
|
this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
|
851
1030
|
this.black = name.search(/Black/g) !== -1;
|
852
1031
|
this.remeasure = Object.keys(this.widths).length > 0;
|
853
|
-
|
1032
|
+
|
1033
|
+
if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.startsWith('Identity-')) {
|
854
1034
|
var GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
|
855
1035
|
var map = [];
|
1036
|
+
|
856
1037
|
for (charCode in GlyphMapForStandardFonts) {
|
857
1038
|
map[+charCode] = GlyphMapForStandardFonts[charCode];
|
858
1039
|
}
|
1040
|
+
|
859
1041
|
if (/Arial-?Black/i.test(name)) {
|
860
1042
|
var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();
|
1043
|
+
|
861
1044
|
for (charCode in SupplementalGlyphMapForArialBlack) {
|
862
1045
|
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
|
863
1046
|
}
|
864
1047
|
} else if (/Calibri/i.test(name)) {
|
865
1048
|
var SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
|
1049
|
+
|
866
1050
|
for (charCode in SupplementalGlyphMapForCalibri) {
|
867
1051
|
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
|
868
1052
|
}
|
869
1053
|
}
|
1054
|
+
|
870
1055
|
var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
|
1056
|
+
|
871
1057
|
if (!isIdentityUnicode) {
|
872
1058
|
this.toUnicode.forEach(function (charCode, unicodeCharCode) {
|
873
1059
|
map[+charCode] = unicodeCharCode;
|
874
1060
|
});
|
875
1061
|
}
|
1062
|
+
|
876
1063
|
this.toFontChar = map;
|
877
1064
|
this.toUnicode = new ToUnicodeMap(map);
|
878
1065
|
} else if (/Symbol/i.test(fontName)) {
|
@@ -881,6 +1068,7 @@ var Font = function FontClosure() {
|
|
881
1068
|
if (/Wingdings/i.test(name)) {
|
882
1069
|
(0, _util.warn)('Non-embedded Wingdings font, falling back to ZapfDingbats.');
|
883
1070
|
}
|
1071
|
+
|
884
1072
|
this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);
|
885
1073
|
} else if (isStandardFont) {
|
886
1074
|
this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
|
@@ -890,18 +1078,22 @@ var Font = function FontClosure() {
|
|
890
1078
|
if (!_this.composite) {
|
891
1079
|
var glyphName = _this.differences[charCode] || _this.defaultEncoding[charCode];
|
892
1080
|
unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
1081
|
+
|
893
1082
|
if (unicode !== -1) {
|
894
1083
|
unicodeCharCode = unicode;
|
895
1084
|
}
|
896
1085
|
}
|
1086
|
+
|
897
1087
|
_this.toFontChar[charCode] = unicodeCharCode;
|
898
1088
|
});
|
899
1089
|
}
|
1090
|
+
|
900
1091
|
this.loadedName = fontName.split('-')[0];
|
901
1092
|
this.fontType = getFontType(type, subtype);
|
902
1093
|
},
|
903
1094
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
904
1095
|
var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
|
1096
|
+
|
905
1097
|
function readTables(file, numTables) {
|
906
1098
|
var tables = Object.create(null);
|
907
1099
|
tables['OS/2'] = null;
|
@@ -912,18 +1104,24 @@ var Font = function FontClosure() {
|
|
912
1104
|
tables['maxp'] = null;
|
913
1105
|
tables['name'] = null;
|
914
1106
|
tables['post'] = null;
|
1107
|
+
|
915
1108
|
for (var i = 0; i < numTables; i++) {
|
916
1109
|
var table = readTableEntry(font);
|
1110
|
+
|
917
1111
|
if (!VALID_TABLES.includes(table.tag)) {
|
918
1112
|
continue;
|
919
1113
|
}
|
1114
|
+
|
920
1115
|
if (table.length === 0) {
|
921
1116
|
continue;
|
922
1117
|
}
|
1118
|
+
|
923
1119
|
tables[table.tag] = table;
|
924
1120
|
}
|
1121
|
+
|
925
1122
|
return tables;
|
926
1123
|
}
|
1124
|
+
|
927
1125
|
function readTableEntry(file) {
|
928
1126
|
var tag = (0, _util.bytesToString)(file.getBytes(4));
|
929
1127
|
var checksum = file.getInt32() >>> 0;
|
@@ -934,10 +1132,12 @@ var Font = function FontClosure() {
|
|
934
1132
|
file.skip(offset);
|
935
1133
|
var data = file.getBytes(length);
|
936
1134
|
file.pos = previousPosition;
|
1135
|
+
|
937
1136
|
if (tag === 'head') {
|
938
1137
|
data[8] = data[9] = data[10] = data[11] = 0;
|
939
1138
|
data[17] |= 0x20;
|
940
1139
|
}
|
1140
|
+
|
941
1141
|
return {
|
942
1142
|
tag: tag,
|
943
1143
|
checksum: checksum,
|
@@ -946,6 +1146,7 @@ var Font = function FontClosure() {
|
|
946
1146
|
data: data
|
947
1147
|
};
|
948
1148
|
}
|
1149
|
+
|
949
1150
|
function readOpenTypeHeader(ttf) {
|
950
1151
|
return {
|
951
1152
|
version: (0, _util.bytesToString)(ttf.getBytes(4)),
|
@@ -955,6 +1156,7 @@ var Font = function FontClosure() {
|
|
955
1156
|
rangeShift: ttf.getUint16()
|
956
1157
|
};
|
957
1158
|
}
|
1159
|
+
|
958
1160
|
function readTrueTypeCollectionHeader(ttc) {
|
959
1161
|
var ttcTag = (0, _util.bytesToString)(ttc.getBytes(4));
|
960
1162
|
(0, _util.assert)(ttcTag === 'ttcf', 'Must be a TrueType Collection font.');
|
@@ -962,9 +1164,11 @@ var Font = function FontClosure() {
|
|
962
1164
|
var minorVersion = ttc.getUint16();
|
963
1165
|
var numFonts = ttc.getInt32() >>> 0;
|
964
1166
|
var offsetTable = [];
|
1167
|
+
|
965
1168
|
for (var i = 0; i < numFonts; i++) {
|
966
1169
|
offsetTable.push(ttc.getInt32() >>> 0);
|
967
1170
|
}
|
1171
|
+
|
968
1172
|
var header = {
|
969
1173
|
ttcTag: ttcTag,
|
970
1174
|
majorVersion: majorVersion,
|
@@ -972,17 +1176,21 @@ var Font = function FontClosure() {
|
|
972
1176
|
numFonts: numFonts,
|
973
1177
|
offsetTable: offsetTable
|
974
1178
|
};
|
1179
|
+
|
975
1180
|
switch (majorVersion) {
|
976
1181
|
case 1:
|
977
1182
|
return header;
|
1183
|
+
|
978
1184
|
case 2:
|
979
1185
|
header.dsigTag = ttc.getInt32() >>> 0;
|
980
1186
|
header.dsigLength = ttc.getInt32() >>> 0;
|
981
1187
|
header.dsigOffset = ttc.getInt32() >>> 0;
|
982
1188
|
return header;
|
983
1189
|
}
|
984
|
-
|
1190
|
+
|
1191
|
+
throw new _util.FormatError("Invalid TrueType Collection majorVersion: ".concat(majorVersion, "."));
|
985
1192
|
}
|
1193
|
+
|
986
1194
|
function readTrueTypeCollectionData(ttc, fontName) {
|
987
1195
|
var _readTrueTypeCollecti = readTrueTypeCollectionHeader(ttc),
|
988
1196
|
numFonts = _readTrueTypeCollecti.numFonts,
|
@@ -992,13 +1200,17 @@ var Font = function FontClosure() {
|
|
992
1200
|
ttc.pos = (ttc.start || 0) + offsetTable[i];
|
993
1201
|
var potentialHeader = readOpenTypeHeader(ttc);
|
994
1202
|
var potentialTables = readTables(ttc, potentialHeader.numTables);
|
1203
|
+
|
995
1204
|
if (!potentialTables['name']) {
|
996
1205
|
throw new _util.FormatError('TrueType Collection font must contain a "name" table.');
|
997
1206
|
}
|
1207
|
+
|
998
1208
|
var nameTable = readNameTable(potentialTables['name']);
|
1209
|
+
|
999
1210
|
for (var j = 0, jj = nameTable.length; j < jj; j++) {
|
1000
1211
|
for (var k = 0, kk = nameTable[j].length; k < kk; k++) {
|
1001
1212
|
var nameEntry = nameTable[j][k];
|
1213
|
+
|
1002
1214
|
if (nameEntry && nameEntry.replace(/\s/g, '') === fontName) {
|
1003
1215
|
return {
|
1004
1216
|
header: potentialHeader,
|
@@ -1008,8 +1220,10 @@ var Font = function FontClosure() {
|
|
1008
1220
|
}
|
1009
1221
|
}
|
1010
1222
|
}
|
1011
|
-
|
1223
|
+
|
1224
|
+
throw new _util.FormatError("TrueType Collection does not contain \"".concat(fontName, "\" font."));
|
1012
1225
|
}
|
1226
|
+
|
1013
1227
|
function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
|
1014
1228
|
if (!cmap) {
|
1015
1229
|
(0, _util.warn)('No cmap table available.');
|
@@ -1020,6 +1234,7 @@ var Font = function FontClosure() {
|
|
1020
1234
|
hasShortCmap: false
|
1021
1235
|
};
|
1022
1236
|
}
|
1237
|
+
|
1023
1238
|
var segment;
|
1024
1239
|
var start = (font.start ? font.start : 0) + cmap.offset;
|
1025
1240
|
font.pos = start;
|
@@ -1027,20 +1242,24 @@ var Font = function FontClosure() {
|
|
1027
1242
|
var numTables = font.getUint16();
|
1028
1243
|
var potentialTable;
|
1029
1244
|
var canBreak = false;
|
1245
|
+
|
1030
1246
|
for (var i = 0; i < numTables; i++) {
|
1031
1247
|
var platformId = font.getUint16();
|
1032
1248
|
var encodingId = font.getUint16();
|
1033
1249
|
var offset = font.getInt32() >>> 0;
|
1034
1250
|
var useTable = false;
|
1251
|
+
|
1035
1252
|
if (potentialTable && potentialTable.platformId === platformId && potentialTable.encodingId === encodingId) {
|
1036
1253
|
continue;
|
1037
1254
|
}
|
1255
|
+
|
1038
1256
|
if (platformId === 0 && encodingId === 0) {
|
1039
1257
|
useTable = true;
|
1040
1258
|
} else if (platformId === 1 && encodingId === 0) {
|
1041
1259
|
useTable = true;
|
1042
1260
|
} else if (platformId === 3 && encodingId === 1 && (hasEncoding || !potentialTable)) {
|
1043
1261
|
useTable = true;
|
1262
|
+
|
1044
1263
|
if (!isSymbolicFont) {
|
1045
1264
|
canBreak = true;
|
1046
1265
|
}
|
@@ -1048,6 +1267,7 @@ var Font = function FontClosure() {
|
|
1048
1267
|
useTable = true;
|
1049
1268
|
canBreak = true;
|
1050
1269
|
}
|
1270
|
+
|
1051
1271
|
if (useTable) {
|
1052
1272
|
potentialTable = {
|
1053
1273
|
platformId: platformId,
|
@@ -1055,13 +1275,16 @@ var Font = function FontClosure() {
|
|
1055
1275
|
offset: offset
|
1056
1276
|
};
|
1057
1277
|
}
|
1278
|
+
|
1058
1279
|
if (canBreak) {
|
1059
1280
|
break;
|
1060
1281
|
}
|
1061
1282
|
}
|
1283
|
+
|
1062
1284
|
if (potentialTable) {
|
1063
1285
|
font.pos = start + potentialTable.offset;
|
1064
1286
|
}
|
1287
|
+
|
1065
1288
|
if (!potentialTable || font.peekByte() === -1) {
|
1066
1289
|
(0, _util.warn)('Could not find a preferred cmap table.');
|
1067
1290
|
return {
|
@@ -1071,65 +1294,85 @@ var Font = function FontClosure() {
|
|
1071
1294
|
hasShortCmap: false
|
1072
1295
|
};
|
1073
1296
|
}
|
1297
|
+
|
1074
1298
|
var format = font.getUint16();
|
1075
1299
|
font.getUint16();
|
1076
1300
|
font.getUint16();
|
1077
1301
|
var hasShortCmap = false;
|
1078
1302
|
var mappings = [];
|
1079
1303
|
var j, glyphId;
|
1304
|
+
|
1080
1305
|
if (format === 0) {
|
1081
1306
|
for (j = 0; j < 256; j++) {
|
1082
1307
|
var index = font.getByte();
|
1308
|
+
|
1083
1309
|
if (!index) {
|
1084
1310
|
continue;
|
1085
1311
|
}
|
1312
|
+
|
1086
1313
|
mappings.push({
|
1087
1314
|
charCode: j,
|
1088
1315
|
glyphId: index
|
1089
1316
|
});
|
1090
1317
|
}
|
1318
|
+
|
1091
1319
|
hasShortCmap = true;
|
1092
1320
|
} else if (format === 4) {
|
1093
1321
|
var segCount = font.getUint16() >> 1;
|
1094
1322
|
font.getBytes(6);
|
1095
1323
|
var segIndex,
|
1096
1324
|
segments = [];
|
1325
|
+
|
1097
1326
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1098
|
-
segments.push({
|
1327
|
+
segments.push({
|
1328
|
+
end: font.getUint16()
|
1329
|
+
});
|
1099
1330
|
}
|
1331
|
+
|
1100
1332
|
font.getUint16();
|
1333
|
+
|
1101
1334
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1102
1335
|
segments[segIndex].start = font.getUint16();
|
1103
1336
|
}
|
1337
|
+
|
1104
1338
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1105
1339
|
segments[segIndex].delta = font.getUint16();
|
1106
1340
|
}
|
1341
|
+
|
1107
1342
|
var offsetsCount = 0;
|
1343
|
+
|
1108
1344
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1109
1345
|
segment = segments[segIndex];
|
1110
1346
|
var rangeOffset = font.getUint16();
|
1347
|
+
|
1111
1348
|
if (!rangeOffset) {
|
1112
1349
|
segment.offsetIndex = -1;
|
1113
1350
|
continue;
|
1114
1351
|
}
|
1352
|
+
|
1115
1353
|
var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
|
1116
1354
|
segment.offsetIndex = offsetIndex;
|
1117
1355
|
offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
|
1118
1356
|
}
|
1357
|
+
|
1119
1358
|
var offsets = [];
|
1359
|
+
|
1120
1360
|
for (j = 0; j < offsetsCount; j++) {
|
1121
1361
|
offsets.push(font.getUint16());
|
1122
1362
|
}
|
1363
|
+
|
1123
1364
|
for (segIndex = 0; segIndex < segCount; segIndex++) {
|
1124
1365
|
segment = segments[segIndex];
|
1125
1366
|
start = segment.start;
|
1126
1367
|
var end = segment.end;
|
1127
1368
|
var delta = segment.delta;
|
1128
1369
|
offsetIndex = segment.offsetIndex;
|
1370
|
+
|
1129
1371
|
for (j = start; j <= end; j++) {
|
1130
1372
|
if (j === 0xFFFF) {
|
1131
1373
|
continue;
|
1132
1374
|
}
|
1375
|
+
|
1133
1376
|
glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
|
1134
1377
|
glyphId = glyphId + delta & 0xFFFF;
|
1135
1378
|
mappings.push({
|
@@ -1141,6 +1384,7 @@ var Font = function FontClosure() {
|
|
1141
1384
|
} else if (format === 6) {
|
1142
1385
|
var firstCode = font.getUint16();
|
1143
1386
|
var entryCount = font.getUint16();
|
1387
|
+
|
1144
1388
|
for (j = 0; j < entryCount; j++) {
|
1145
1389
|
glyphId = font.getUint16();
|
1146
1390
|
var charCode = firstCode + j;
|
@@ -1158,15 +1402,18 @@ var Font = function FontClosure() {
|
|
1158
1402
|
hasShortCmap: false
|
1159
1403
|
};
|
1160
1404
|
}
|
1405
|
+
|
1161
1406
|
mappings.sort(function (a, b) {
|
1162
1407
|
return a.charCode - b.charCode;
|
1163
1408
|
});
|
1409
|
+
|
1164
1410
|
for (i = 1; i < mappings.length; i++) {
|
1165
1411
|
if (mappings[i - 1].charCode === mappings[i].charCode) {
|
1166
1412
|
mappings.splice(i, 1);
|
1167
1413
|
i--;
|
1168
1414
|
}
|
1169
1415
|
}
|
1416
|
+
|
1170
1417
|
return {
|
1171
1418
|
platformId: potentialTable.platformId,
|
1172
1419
|
encodingId: potentialTable.encodingId,
|
@@ -1174,40 +1421,62 @@ var Font = function FontClosure() {
|
|
1174
1421
|
hasShortCmap: hasShortCmap
|
1175
1422
|
};
|
1176
1423
|
}
|
1424
|
+
|
1177
1425
|
function sanitizeMetrics(font, header, metrics, numGlyphs) {
|
1178
1426
|
if (!header) {
|
1179
1427
|
if (metrics) {
|
1180
1428
|
metrics.data = null;
|
1181
1429
|
}
|
1430
|
+
|
1182
1431
|
return;
|
1183
1432
|
}
|
1433
|
+
|
1184
1434
|
font.pos = (font.start ? font.start : 0) + header.offset;
|
1185
|
-
font.pos +=
|
1435
|
+
font.pos += 4;
|
1436
|
+
font.pos += 2;
|
1437
|
+
font.pos += 2;
|
1438
|
+
font.pos += 2;
|
1439
|
+
font.pos += 2;
|
1440
|
+
font.pos += 2;
|
1441
|
+
font.pos += 2;
|
1442
|
+
font.pos += 2;
|
1443
|
+
font.pos += 2;
|
1444
|
+
font.pos += 2;
|
1445
|
+
font.pos += 2;
|
1446
|
+
font.pos += 8;
|
1447
|
+
font.pos += 2;
|
1186
1448
|
var numOfMetrics = font.getUint16();
|
1449
|
+
|
1187
1450
|
if (numOfMetrics > numGlyphs) {
|
1188
1451
|
(0, _util.info)('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
|
1189
1452
|
numOfMetrics = numGlyphs;
|
1190
1453
|
header.data[34] = (numOfMetrics & 0xff00) >> 8;
|
1191
1454
|
header.data[35] = numOfMetrics & 0x00ff;
|
1192
1455
|
}
|
1456
|
+
|
1193
1457
|
var numOfSidebearings = numGlyphs - numOfMetrics;
|
1194
1458
|
var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
|
1459
|
+
|
1195
1460
|
if (numMissing > 0) {
|
1196
1461
|
var entries = new Uint8Array(metrics.length + numMissing * 2);
|
1197
1462
|
entries.set(metrics.data);
|
1198
1463
|
metrics.data = entries;
|
1199
1464
|
}
|
1200
1465
|
}
|
1466
|
+
|
1201
1467
|
function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
|
1202
1468
|
var glyphProfile = {
|
1203
1469
|
length: 0,
|
1204
1470
|
sizeOfInstructions: 0
|
1205
1471
|
};
|
1472
|
+
|
1206
1473
|
if (sourceEnd - sourceStart <= 12) {
|
1207
1474
|
return glyphProfile;
|
1208
1475
|
}
|
1476
|
+
|
1209
1477
|
var glyf = source.subarray(sourceStart, sourceEnd);
|
1210
1478
|
var contoursCount = signedInt16(glyf[0], glyf[1]);
|
1479
|
+
|
1211
1480
|
if (contoursCount < 0) {
|
1212
1481
|
contoursCount = -1;
|
1213
1482
|
writeSignedInt16(glyf, 0, contoursCount);
|
@@ -1215,64 +1484,81 @@ var Font = function FontClosure() {
|
|
1215
1484
|
glyphProfile.length = glyf.length;
|
1216
1485
|
return glyphProfile;
|
1217
1486
|
}
|
1487
|
+
|
1218
1488
|
var i,
|
1219
1489
|
j = 10,
|
1220
1490
|
flagsCount = 0;
|
1491
|
+
|
1221
1492
|
for (i = 0; i < contoursCount; i++) {
|
1222
1493
|
var endPoint = glyf[j] << 8 | glyf[j + 1];
|
1223
1494
|
flagsCount = endPoint + 1;
|
1224
1495
|
j += 2;
|
1225
1496
|
}
|
1497
|
+
|
1226
1498
|
var instructionsStart = j;
|
1227
1499
|
var instructionsLength = glyf[j] << 8 | glyf[j + 1];
|
1228
1500
|
glyphProfile.sizeOfInstructions = instructionsLength;
|
1229
1501
|
j += 2 + instructionsLength;
|
1230
1502
|
var instructionsEnd = j;
|
1231
1503
|
var coordinatesLength = 0;
|
1504
|
+
|
1232
1505
|
for (i = 0; i < flagsCount; i++) {
|
1233
1506
|
var flag = glyf[j++];
|
1507
|
+
|
1234
1508
|
if (flag & 0xC0) {
|
1235
1509
|
glyf[j - 1] = flag & 0x3F;
|
1236
1510
|
}
|
1511
|
+
|
1237
1512
|
var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
|
1238
1513
|
coordinatesLength += xyLength;
|
1514
|
+
|
1239
1515
|
if (flag & 8) {
|
1240
1516
|
var repeat = glyf[j++];
|
1241
1517
|
i += repeat;
|
1242
1518
|
coordinatesLength += repeat * xyLength;
|
1243
1519
|
}
|
1244
1520
|
}
|
1521
|
+
|
1245
1522
|
if (coordinatesLength === 0) {
|
1246
1523
|
return glyphProfile;
|
1247
1524
|
}
|
1525
|
+
|
1248
1526
|
var glyphDataLength = j + coordinatesLength;
|
1527
|
+
|
1249
1528
|
if (glyphDataLength > glyf.length) {
|
1250
1529
|
return glyphProfile;
|
1251
1530
|
}
|
1531
|
+
|
1252
1532
|
if (!hintsValid && instructionsLength > 0) {
|
1253
1533
|
dest.set(glyf.subarray(0, instructionsStart), destStart);
|
1254
1534
|
dest.set([0, 0], destStart + instructionsStart);
|
1255
1535
|
dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
|
1256
1536
|
glyphDataLength -= instructionsLength;
|
1537
|
+
|
1257
1538
|
if (glyf.length - glyphDataLength > 3) {
|
1258
1539
|
glyphDataLength = glyphDataLength + 3 & ~3;
|
1259
1540
|
}
|
1541
|
+
|
1260
1542
|
glyphProfile.length = glyphDataLength;
|
1261
1543
|
return glyphProfile;
|
1262
1544
|
}
|
1545
|
+
|
1263
1546
|
if (glyf.length - glyphDataLength > 3) {
|
1264
1547
|
glyphDataLength = glyphDataLength + 3 & ~3;
|
1265
1548
|
dest.set(glyf.subarray(0, glyphDataLength), destStart);
|
1266
1549
|
glyphProfile.length = glyphDataLength;
|
1267
1550
|
return glyphProfile;
|
1268
1551
|
}
|
1552
|
+
|
1269
1553
|
dest.set(glyf, destStart);
|
1270
1554
|
glyphProfile.length = glyf.length;
|
1271
1555
|
return glyphProfile;
|
1272
1556
|
}
|
1557
|
+
|
1273
1558
|
function sanitizeHead(head, numGlyphs, locaLength) {
|
1274
1559
|
var data = head.data;
|
1275
1560
|
var version = int32(data[0], data[1], data[2], data[3]);
|
1561
|
+
|
1276
1562
|
if (version >> 16 !== 1) {
|
1277
1563
|
(0, _util.info)('Attempting to fix invalid version in head table: ' + version);
|
1278
1564
|
data[0] = 0;
|
@@ -1280,10 +1566,13 @@ var Font = function FontClosure() {
|
|
1280
1566
|
data[2] = 0;
|
1281
1567
|
data[3] = 0;
|
1282
1568
|
}
|
1569
|
+
|
1283
1570
|
var indexToLocFormat = int16(data[50], data[51]);
|
1571
|
+
|
1284
1572
|
if (indexToLocFormat < 0 || indexToLocFormat > 1) {
|
1285
1573
|
(0, _util.info)('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
|
1286
1574
|
var numGlyphsPlusOne = numGlyphs + 1;
|
1575
|
+
|
1287
1576
|
if (locaLength === numGlyphsPlusOne << 1) {
|
1288
1577
|
data[50] = 0;
|
1289
1578
|
data[51] = 0;
|
@@ -1295,13 +1584,17 @@ var Font = function FontClosure() {
|
|
1295
1584
|
}
|
1296
1585
|
}
|
1297
1586
|
}
|
1587
|
+
|
1298
1588
|
function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) {
|
1299
1589
|
var itemSize, itemDecode, itemEncode;
|
1590
|
+
|
1300
1591
|
if (isGlyphLocationsLong) {
|
1301
1592
|
itemSize = 4;
|
1593
|
+
|
1302
1594
|
itemDecode = function fontItemDecodeLong(data, offset) {
|
1303
1595
|
return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
|
1304
1596
|
};
|
1597
|
+
|
1305
1598
|
itemEncode = function fontItemEncodeLong(data, offset, value) {
|
1306
1599
|
data[offset] = value >>> 24 & 0xFF;
|
1307
1600
|
data[offset + 1] = value >> 16 & 0xFF;
|
@@ -1310,14 +1603,17 @@ var Font = function FontClosure() {
|
|
1310
1603
|
};
|
1311
1604
|
} else {
|
1312
1605
|
itemSize = 2;
|
1606
|
+
|
1313
1607
|
itemDecode = function fontItemDecode(data, offset) {
|
1314
1608
|
return data[offset] << 9 | data[offset + 1] << 1;
|
1315
1609
|
};
|
1610
|
+
|
1316
1611
|
itemEncode = function fontItemEncode(data, offset, value) {
|
1317
1612
|
data[offset] = value >> 9 & 0xFF;
|
1318
1613
|
data[offset + 1] = value >> 1 & 0xFF;
|
1319
1614
|
};
|
1320
1615
|
}
|
1616
|
+
|
1321
1617
|
var numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
|
1322
1618
|
var locaData = loca.data;
|
1323
1619
|
var locaDataSize = itemSize * (1 + numGlyphsOut);
|
@@ -1332,53 +1628,68 @@ var Font = function FontClosure() {
|
|
1332
1628
|
var missingGlyphs = Object.create(null);
|
1333
1629
|
itemEncode(locaData, 0, writeOffset);
|
1334
1630
|
var i, j;
|
1631
|
+
|
1335
1632
|
for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
|
1336
1633
|
var endOffset = itemDecode(locaData, j);
|
1634
|
+
|
1337
1635
|
if (endOffset === 0) {
|
1338
1636
|
endOffset = startOffset;
|
1339
1637
|
}
|
1638
|
+
|
1340
1639
|
if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
|
1341
1640
|
endOffset = oldGlyfDataLength;
|
1342
1641
|
}
|
1642
|
+
|
1343
1643
|
if (endOffset > oldGlyfDataLength) {
|
1344
1644
|
startOffset = endOffset;
|
1345
1645
|
}
|
1646
|
+
|
1346
1647
|
var glyphProfile = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
|
1347
1648
|
var newLength = glyphProfile.length;
|
1649
|
+
|
1348
1650
|
if (newLength === 0) {
|
1349
1651
|
missingGlyphs[i] = true;
|
1350
1652
|
}
|
1653
|
+
|
1351
1654
|
if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {
|
1352
1655
|
maxSizeOfInstructions = glyphProfile.sizeOfInstructions;
|
1353
1656
|
}
|
1657
|
+
|
1354
1658
|
writeOffset += newLength;
|
1355
1659
|
itemEncode(locaData, j, writeOffset);
|
1356
1660
|
startOffset = endOffset;
|
1357
1661
|
}
|
1662
|
+
|
1358
1663
|
if (writeOffset === 0) {
|
1359
1664
|
var simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
|
1665
|
+
|
1360
1666
|
for (i = 0, j = itemSize; i < numGlyphsOut; i++, j += itemSize) {
|
1361
1667
|
itemEncode(locaData, j, simpleGlyph.length);
|
1362
1668
|
}
|
1669
|
+
|
1363
1670
|
glyf.data = simpleGlyph;
|
1364
1671
|
} else if (dupFirstEntry) {
|
1365
1672
|
var firstEntryLength = itemDecode(locaData, itemSize);
|
1673
|
+
|
1366
1674
|
if (newGlyfData.length > firstEntryLength + writeOffset) {
|
1367
1675
|
glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
|
1368
1676
|
} else {
|
1369
1677
|
glyf.data = new Uint8Array(firstEntryLength + writeOffset);
|
1370
1678
|
glyf.data.set(newGlyfData.subarray(0, writeOffset));
|
1371
1679
|
}
|
1680
|
+
|
1372
1681
|
glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
|
1373
1682
|
itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
|
1374
1683
|
} else {
|
1375
1684
|
glyf.data = newGlyfData.subarray(0, writeOffset);
|
1376
1685
|
}
|
1686
|
+
|
1377
1687
|
return {
|
1378
1688
|
missingGlyphs: missingGlyphs,
|
1379
1689
|
maxSizeOfInstructions: maxSizeOfInstructions
|
1380
1690
|
};
|
1381
1691
|
}
|
1692
|
+
|
1382
1693
|
function readPostScriptTable(post, properties, maxpNumGlyphs) {
|
1383
1694
|
var start = (font.start ? font.start : 0) + post.offset;
|
1384
1695
|
font.pos = start;
|
@@ -1389,61 +1700,84 @@ var Font = function FontClosure() {
|
|
1389
1700
|
var glyphNames;
|
1390
1701
|
var valid = true;
|
1391
1702
|
var i;
|
1703
|
+
|
1392
1704
|
switch (version) {
|
1393
1705
|
case 0x00010000:
|
1394
1706
|
glyphNames = MacStandardGlyphOrdering;
|
1395
1707
|
break;
|
1708
|
+
|
1396
1709
|
case 0x00020000:
|
1397
1710
|
var numGlyphs = font.getUint16();
|
1711
|
+
|
1398
1712
|
if (numGlyphs !== maxpNumGlyphs) {
|
1399
1713
|
valid = false;
|
1400
1714
|
break;
|
1401
1715
|
}
|
1716
|
+
|
1402
1717
|
var glyphNameIndexes = [];
|
1718
|
+
|
1403
1719
|
for (i = 0; i < numGlyphs; ++i) {
|
1404
1720
|
var index = font.getUint16();
|
1721
|
+
|
1405
1722
|
if (index >= 32768) {
|
1406
1723
|
valid = false;
|
1407
1724
|
break;
|
1408
1725
|
}
|
1726
|
+
|
1409
1727
|
glyphNameIndexes.push(index);
|
1410
1728
|
}
|
1729
|
+
|
1411
1730
|
if (!valid) {
|
1412
1731
|
break;
|
1413
1732
|
}
|
1733
|
+
|
1414
1734
|
var customNames = [];
|
1415
1735
|
var strBuf = [];
|
1736
|
+
|
1416
1737
|
while (font.pos < end) {
|
1417
1738
|
var stringLength = font.getByte();
|
1418
1739
|
strBuf.length = stringLength;
|
1740
|
+
|
1419
1741
|
for (i = 0; i < stringLength; ++i) {
|
1420
1742
|
strBuf[i] = String.fromCharCode(font.getByte());
|
1421
1743
|
}
|
1744
|
+
|
1422
1745
|
customNames.push(strBuf.join(''));
|
1423
1746
|
}
|
1747
|
+
|
1424
1748
|
glyphNames = [];
|
1749
|
+
|
1425
1750
|
for (i = 0; i < numGlyphs; ++i) {
|
1426
1751
|
var j = glyphNameIndexes[i];
|
1752
|
+
|
1427
1753
|
if (j < 258) {
|
1428
1754
|
glyphNames.push(MacStandardGlyphOrdering[j]);
|
1429
1755
|
continue;
|
1430
1756
|
}
|
1757
|
+
|
1431
1758
|
glyphNames.push(customNames[j - 258]);
|
1432
1759
|
}
|
1760
|
+
|
1433
1761
|
break;
|
1762
|
+
|
1434
1763
|
case 0x00030000:
|
1435
1764
|
break;
|
1765
|
+
|
1436
1766
|
default:
|
1437
1767
|
(0, _util.warn)('Unknown/unsupported post table version ' + version);
|
1438
1768
|
valid = false;
|
1769
|
+
|
1439
1770
|
if (properties.defaultEncoding) {
|
1440
1771
|
glyphNames = properties.defaultEncoding;
|
1441
1772
|
}
|
1773
|
+
|
1442
1774
|
break;
|
1443
1775
|
}
|
1776
|
+
|
1444
1777
|
properties.glyphNames = glyphNames;
|
1445
1778
|
return valid;
|
1446
1779
|
}
|
1780
|
+
|
1447
1781
|
function readNameTable(nameTable) {
|
1448
1782
|
var start = (font.start ? font.start : 0) + nameTable.offset;
|
1449
1783
|
font.pos = start;
|
@@ -1452,14 +1786,17 @@ var Font = function FontClosure() {
|
|
1452
1786
|
end = start + length;
|
1453
1787
|
var format = font.getUint16();
|
1454
1788
|
var FORMAT_0_HEADER_LENGTH = 6;
|
1789
|
+
|
1455
1790
|
if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
|
1456
1791
|
return names;
|
1457
1792
|
}
|
1793
|
+
|
1458
1794
|
var numRecords = font.getUint16();
|
1459
1795
|
var stringsStart = font.getUint16();
|
1460
1796
|
var records = [];
|
1461
1797
|
var NAME_RECORD_LENGTH = 12;
|
1462
1798
|
var i, ii;
|
1799
|
+
|
1463
1800
|
for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
|
1464
1801
|
var r = {
|
1465
1802
|
platform: font.getUint16(),
|
@@ -1469,34 +1806,46 @@ var Font = function FontClosure() {
|
|
1469
1806
|
length: font.getUint16(),
|
1470
1807
|
offset: font.getUint16()
|
1471
1808
|
};
|
1809
|
+
|
1472
1810
|
if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
|
1473
1811
|
records.push(r);
|
1474
1812
|
}
|
1475
1813
|
}
|
1814
|
+
|
1476
1815
|
for (i = 0, ii = records.length; i < ii; i++) {
|
1477
1816
|
var record = records[i];
|
1817
|
+
|
1478
1818
|
if (record.length <= 0) {
|
1479
1819
|
continue;
|
1480
1820
|
}
|
1821
|
+
|
1481
1822
|
var pos = start + stringsStart + record.offset;
|
1823
|
+
|
1482
1824
|
if (pos + record.length > end) {
|
1483
1825
|
continue;
|
1484
1826
|
}
|
1827
|
+
|
1485
1828
|
font.pos = pos;
|
1486
1829
|
var nameIndex = record.name;
|
1830
|
+
|
1487
1831
|
if (record.encoding) {
|
1488
1832
|
var str = '';
|
1833
|
+
|
1489
1834
|
for (var j = 0, jj = record.length; j < jj; j += 2) {
|
1490
1835
|
str += String.fromCharCode(font.getUint16());
|
1491
1836
|
}
|
1837
|
+
|
1492
1838
|
names[1][nameIndex] = str;
|
1493
1839
|
} else {
|
1494
1840
|
names[0][nameIndex] = (0, _util.bytesToString)(font.getBytes(record.length));
|
1495
1841
|
}
|
1496
1842
|
}
|
1843
|
+
|
1497
1844
|
return names;
|
1498
1845
|
}
|
1846
|
+
|
1499
1847
|
var TTOpsStackDeltas = [0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1, 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2, 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1, -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
|
1848
|
+
|
1500
1849
|
function sanitizeTTProgram(table, ttContext) {
|
1501
1850
|
var data = table.data;
|
1502
1851
|
var i = 0,
|
@@ -1514,10 +1863,13 @@ var Font = function FontClosure() {
|
|
1514
1863
|
var inFDEF = false,
|
1515
1864
|
ifLevel = 0,
|
1516
1865
|
inELSE = 0;
|
1866
|
+
|
1517
1867
|
for (var ii = data.length; i < ii;) {
|
1518
1868
|
var op = data[i++];
|
1869
|
+
|
1519
1870
|
if (op === 0x40) {
|
1520
1871
|
n = data[i++];
|
1872
|
+
|
1521
1873
|
if (inFDEF || inELSE) {
|
1522
1874
|
i += n;
|
1523
1875
|
} else {
|
@@ -1527,6 +1879,7 @@ var Font = function FontClosure() {
|
|
1527
1879
|
}
|
1528
1880
|
} else if (op === 0x41) {
|
1529
1881
|
n = data[i++];
|
1882
|
+
|
1530
1883
|
if (inFDEF || inELSE) {
|
1531
1884
|
i += n * 2;
|
1532
1885
|
} else {
|
@@ -1537,6 +1890,7 @@ var Font = function FontClosure() {
|
|
1537
1890
|
}
|
1538
1891
|
} else if ((op & 0xF8) === 0xB0) {
|
1539
1892
|
n = op - 0xB0 + 1;
|
1893
|
+
|
1540
1894
|
if (inFDEF || inELSE) {
|
1541
1895
|
i += n;
|
1542
1896
|
} else {
|
@@ -1546,6 +1900,7 @@ var Font = function FontClosure() {
|
|
1546
1900
|
}
|
1547
1901
|
} else if ((op & 0xF8) === 0xB8) {
|
1548
1902
|
n = op - 0xB8 + 1;
|
1903
|
+
|
1549
1904
|
if (inFDEF || inELSE) {
|
1550
1905
|
i += n * 2;
|
1551
1906
|
} else {
|
@@ -1557,17 +1912,21 @@ var Font = function FontClosure() {
|
|
1557
1912
|
} else if (op === 0x2B && !tooComplexToFollowFunctions) {
|
1558
1913
|
if (!inFDEF && !inELSE) {
|
1559
1914
|
funcId = stack[stack.length - 1];
|
1915
|
+
|
1560
1916
|
if (isNaN(funcId)) {
|
1561
1917
|
(0, _util.info)('TT: CALL empty stack (or invalid entry).');
|
1562
1918
|
} else {
|
1563
1919
|
ttContext.functionsUsed[funcId] = true;
|
1920
|
+
|
1564
1921
|
if (funcId in ttContext.functionsStackDeltas) {
|
1565
1922
|
var newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
|
1923
|
+
|
1566
1924
|
if (newStackLength < 0) {
|
1567
1925
|
(0, _util.warn)('TT: CALL invalid functions stack delta.');
|
1568
1926
|
ttContext.hintsValid = false;
|
1569
1927
|
return;
|
1570
1928
|
}
|
1929
|
+
|
1571
1930
|
stack.length = newStackLength;
|
1572
1931
|
} else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
|
1573
1932
|
callstack.push({
|
@@ -1577,11 +1936,13 @@ var Font = function FontClosure() {
|
|
1577
1936
|
});
|
1578
1937
|
functionsCalled.push(funcId);
|
1579
1938
|
pc = ttContext.functionsDefined[funcId];
|
1939
|
+
|
1580
1940
|
if (!pc) {
|
1581
1941
|
(0, _util.warn)('TT: CALL non-existent function');
|
1582
1942
|
ttContext.hintsValid = false;
|
1583
1943
|
return;
|
1584
1944
|
}
|
1945
|
+
|
1585
1946
|
data = pc.data;
|
1586
1947
|
i = pc.i;
|
1587
1948
|
}
|
@@ -1592,6 +1953,7 @@ var Font = function FontClosure() {
|
|
1592
1953
|
(0, _util.warn)('TT: nested FDEFs not allowed');
|
1593
1954
|
tooComplexToFollowFunctions = true;
|
1594
1955
|
}
|
1956
|
+
|
1595
1957
|
inFDEF = true;
|
1596
1958
|
lastDeff = i;
|
1597
1959
|
funcId = stack.pop();
|
@@ -1605,11 +1967,13 @@ var Font = function FontClosure() {
|
|
1605
1967
|
lastEndf = i;
|
1606
1968
|
} else {
|
1607
1969
|
pc = callstack.pop();
|
1970
|
+
|
1608
1971
|
if (!pc) {
|
1609
1972
|
(0, _util.warn)('TT: ENDF bad stack');
|
1610
1973
|
ttContext.hintsValid = false;
|
1611
1974
|
return;
|
1612
1975
|
}
|
1976
|
+
|
1613
1977
|
funcId = functionsCalled.pop();
|
1614
1978
|
data = pc.data;
|
1615
1979
|
i = pc.i;
|
@@ -1620,6 +1984,7 @@ var Font = function FontClosure() {
|
|
1620
1984
|
(0, _util.warn)('TT: nested IDEFs not allowed');
|
1621
1985
|
tooComplexToFollowFunctions = true;
|
1622
1986
|
}
|
1987
|
+
|
1623
1988
|
inFDEF = true;
|
1624
1989
|
lastDeff = i;
|
1625
1990
|
} else if (op === 0x58) {
|
@@ -1630,59 +1995,74 @@ var Font = function FontClosure() {
|
|
1630
1995
|
if (inELSE === ifLevel) {
|
1631
1996
|
inELSE = 0;
|
1632
1997
|
}
|
1998
|
+
|
1633
1999
|
--ifLevel;
|
1634
2000
|
} else if (op === 0x1C) {
|
1635
2001
|
if (!inFDEF && !inELSE) {
|
1636
2002
|
var offset = stack[stack.length - 1];
|
2003
|
+
|
1637
2004
|
if (offset > 0) {
|
1638
2005
|
i += offset - 1;
|
1639
2006
|
}
|
1640
2007
|
}
|
1641
2008
|
}
|
2009
|
+
|
1642
2010
|
if (!inFDEF && !inELSE) {
|
1643
2011
|
var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
|
2012
|
+
|
1644
2013
|
if (op >= 0x71 && op <= 0x75) {
|
1645
2014
|
n = stack.pop();
|
2015
|
+
|
1646
2016
|
if (!isNaN(n)) {
|
1647
2017
|
stackDelta = -n * 2;
|
1648
2018
|
}
|
1649
2019
|
}
|
2020
|
+
|
1650
2021
|
while (stackDelta < 0 && stack.length > 0) {
|
1651
2022
|
stack.pop();
|
1652
2023
|
stackDelta++;
|
1653
2024
|
}
|
2025
|
+
|
1654
2026
|
while (stackDelta > 0) {
|
1655
2027
|
stack.push(NaN);
|
1656
2028
|
stackDelta--;
|
1657
2029
|
}
|
1658
2030
|
}
|
1659
2031
|
}
|
2032
|
+
|
1660
2033
|
ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
|
1661
2034
|
var content = [data];
|
2035
|
+
|
1662
2036
|
if (i > data.length) {
|
1663
2037
|
content.push(new Uint8Array(i - data.length));
|
1664
2038
|
}
|
2039
|
+
|
1665
2040
|
if (lastDeff > lastEndf) {
|
1666
2041
|
(0, _util.warn)('TT: complementing a missing function tail');
|
1667
2042
|
content.push(new Uint8Array([0x22, 0x2D]));
|
1668
2043
|
}
|
2044
|
+
|
1669
2045
|
foldTTTable(table, content);
|
1670
2046
|
}
|
2047
|
+
|
1671
2048
|
function checkInvalidFunctions(ttContext, maxFunctionDefs) {
|
1672
2049
|
if (ttContext.tooComplexToFollowFunctions) {
|
1673
2050
|
return;
|
1674
2051
|
}
|
2052
|
+
|
1675
2053
|
if (ttContext.functionsDefined.length > maxFunctionDefs) {
|
1676
2054
|
(0, _util.warn)('TT: more functions defined than expected');
|
1677
2055
|
ttContext.hintsValid = false;
|
1678
2056
|
return;
|
1679
2057
|
}
|
2058
|
+
|
1680
2059
|
for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
|
1681
2060
|
if (j > maxFunctionDefs) {
|
1682
2061
|
(0, _util.warn)('TT: invalid function id: ' + j);
|
1683
2062
|
ttContext.hintsValid = false;
|
1684
2063
|
return;
|
1685
2064
|
}
|
2065
|
+
|
1686
2066
|
if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
|
1687
2067
|
(0, _util.warn)('TT: undefined function: ' + j);
|
1688
2068
|
ttContext.hintsValid = false;
|
@@ -1690,24 +2070,30 @@ var Font = function FontClosure() {
|
|
1690
2070
|
}
|
1691
2071
|
}
|
1692
2072
|
}
|
2073
|
+
|
1693
2074
|
function foldTTTable(table, content) {
|
1694
2075
|
if (content.length > 1) {
|
1695
2076
|
var newLength = 0;
|
1696
2077
|
var j, jj;
|
2078
|
+
|
1697
2079
|
for (j = 0, jj = content.length; j < jj; j++) {
|
1698
2080
|
newLength += content[j].length;
|
1699
2081
|
}
|
2082
|
+
|
1700
2083
|
newLength = newLength + 3 & ~3;
|
1701
2084
|
var result = new Uint8Array(newLength);
|
1702
2085
|
var pos = 0;
|
2086
|
+
|
1703
2087
|
for (j = 0, jj = content.length; j < jj; j++) {
|
1704
2088
|
result.set(content[j], pos);
|
1705
2089
|
pos += content[j].length;
|
1706
2090
|
}
|
2091
|
+
|
1707
2092
|
table.data = result;
|
1708
2093
|
table.length = newLength;
|
1709
2094
|
}
|
1710
2095
|
}
|
2096
|
+
|
1711
2097
|
function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
|
1712
2098
|
var ttContext = {
|
1713
2099
|
functionsDefined: [],
|
@@ -1716,25 +2102,31 @@ var Font = function FontClosure() {
|
|
1716
2102
|
tooComplexToFollowFunctions: false,
|
1717
2103
|
hintsValid: true
|
1718
2104
|
};
|
2105
|
+
|
1719
2106
|
if (fpgm) {
|
1720
2107
|
sanitizeTTProgram(fpgm, ttContext);
|
1721
2108
|
}
|
2109
|
+
|
1722
2110
|
if (prep) {
|
1723
2111
|
sanitizeTTProgram(prep, ttContext);
|
1724
2112
|
}
|
2113
|
+
|
1725
2114
|
if (fpgm) {
|
1726
2115
|
checkInvalidFunctions(ttContext, maxFunctionDefs);
|
1727
2116
|
}
|
2117
|
+
|
1728
2118
|
if (cvt && cvt.length & 1) {
|
1729
2119
|
var cvtData = new Uint8Array(cvt.length + 1);
|
1730
2120
|
cvtData.set(cvt.data);
|
1731
2121
|
cvt.data = cvtData;
|
1732
2122
|
}
|
2123
|
+
|
1733
2124
|
return ttContext.hintsValid;
|
1734
2125
|
}
|
2126
|
+
|
1735
2127
|
font = new _stream.Stream(new Uint8Array(font.getBytes()));
|
1736
|
-
var header
|
1737
|
-
|
2128
|
+
var header, tables;
|
2129
|
+
|
1738
2130
|
if (isTrueTypeCollectionFile(font)) {
|
1739
2131
|
var ttcData = readTrueTypeCollectionData(font, this.name);
|
1740
2132
|
header = ttcData.header;
|
@@ -1743,17 +2135,20 @@ var Font = function FontClosure() {
|
|
1743
2135
|
header = readOpenTypeHeader(font);
|
1744
2136
|
tables = readTables(font, header.numTables);
|
1745
2137
|
}
|
1746
|
-
|
1747
|
-
|
2138
|
+
|
2139
|
+
var cff, cffFile;
|
1748
2140
|
var isTrueType = !tables['CFF '];
|
2141
|
+
|
1749
2142
|
if (!isTrueType) {
|
1750
2143
|
var isComposite = properties.composite && ((properties.cidToGidMap || []).length > 0 || !(properties.cMap instanceof _cmap.IdentityCMap));
|
2144
|
+
|
1751
2145
|
if (header.version === 'OTTO' && !isComposite || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
|
1752
2146
|
cffFile = new _stream.Stream(tables['CFF '].data);
|
1753
2147
|
cff = new CFFFont(cffFile, properties);
|
1754
2148
|
adjustWidths(properties);
|
1755
2149
|
return this.convert(name, cff, properties);
|
1756
2150
|
}
|
2151
|
+
|
1757
2152
|
delete tables['glyf'];
|
1758
2153
|
delete tables['loca'];
|
1759
2154
|
delete tables['fpgm'];
|
@@ -1764,6 +2159,7 @@ var Font = function FontClosure() {
|
|
1764
2159
|
if (!tables['loca']) {
|
1765
2160
|
throw new _util.FormatError('Required "loca" table is not found');
|
1766
2161
|
}
|
2162
|
+
|
1767
2163
|
if (!tables['glyf']) {
|
1768
2164
|
(0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
|
1769
2165
|
tables['glyf'] = {
|
@@ -1771,65 +2167,83 @@ var Font = function FontClosure() {
|
|
1771
2167
|
data: new Uint8Array(0)
|
1772
2168
|
};
|
1773
2169
|
}
|
2170
|
+
|
1774
2171
|
this.isOpenType = false;
|
1775
2172
|
}
|
2173
|
+
|
1776
2174
|
if (!tables['maxp']) {
|
1777
2175
|
throw new _util.FormatError('Required "maxp" table is not found');
|
1778
2176
|
}
|
2177
|
+
|
1779
2178
|
font.pos = (font.start || 0) + tables['maxp'].offset;
|
1780
2179
|
var version = font.getInt32();
|
1781
2180
|
var numGlyphs = font.getUint16();
|
1782
2181
|
var numGlyphsOut = numGlyphs + 1;
|
1783
2182
|
var dupFirstEntry = true;
|
2183
|
+
|
1784
2184
|
if (numGlyphsOut > 0xFFFF) {
|
1785
2185
|
dupFirstEntry = false;
|
1786
2186
|
numGlyphsOut = numGlyphs;
|
1787
2187
|
(0, _util.warn)('Not enough space in glyfs to duplicate first glyph.');
|
1788
2188
|
}
|
2189
|
+
|
1789
2190
|
var maxFunctionDefs = 0;
|
1790
2191
|
var maxSizeOfInstructions = 0;
|
2192
|
+
|
1791
2193
|
if (version >= 0x00010000 && tables['maxp'].length >= 22) {
|
1792
2194
|
font.pos += 8;
|
1793
2195
|
var maxZones = font.getUint16();
|
2196
|
+
|
1794
2197
|
if (maxZones > 2) {
|
1795
2198
|
tables['maxp'].data[14] = 0;
|
1796
2199
|
tables['maxp'].data[15] = 2;
|
1797
2200
|
}
|
2201
|
+
|
1798
2202
|
font.pos += 4;
|
1799
2203
|
maxFunctionDefs = font.getUint16();
|
1800
2204
|
font.pos += 4;
|
1801
2205
|
maxSizeOfInstructions = font.getUint16();
|
1802
2206
|
}
|
2207
|
+
|
1803
2208
|
tables['maxp'].data[4] = numGlyphsOut >> 8;
|
1804
2209
|
tables['maxp'].data[5] = numGlyphsOut & 255;
|
1805
2210
|
var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
|
2211
|
+
|
1806
2212
|
if (!hintsValid) {
|
1807
2213
|
delete tables['fpgm'];
|
1808
2214
|
delete tables['prep'];
|
1809
2215
|
delete tables['cvt '];
|
1810
2216
|
}
|
2217
|
+
|
1811
2218
|
sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphsOut);
|
2219
|
+
|
1812
2220
|
if (!tables['head']) {
|
1813
2221
|
throw new _util.FormatError('Required "head" table is not found');
|
1814
2222
|
}
|
2223
|
+
|
1815
2224
|
sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
|
1816
2225
|
var missingGlyphs = Object.create(null);
|
2226
|
+
|
1817
2227
|
if (isTrueType) {
|
1818
2228
|
var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
|
1819
2229
|
var glyphsInfo = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
|
1820
2230
|
missingGlyphs = glyphsInfo.missingGlyphs;
|
2231
|
+
|
1821
2232
|
if (version >= 0x00010000 && tables['maxp'].length >= 22) {
|
1822
2233
|
tables['maxp'].data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
|
1823
2234
|
tables['maxp'].data[27] = glyphsInfo.maxSizeOfInstructions & 255;
|
1824
2235
|
}
|
1825
2236
|
}
|
2237
|
+
|
1826
2238
|
if (!tables['hhea']) {
|
1827
2239
|
throw new _util.FormatError('Required "hhea" table is not found');
|
1828
2240
|
}
|
2241
|
+
|
1829
2242
|
if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
|
1830
2243
|
tables['hhea'].data[10] = 0xFF;
|
1831
2244
|
tables['hhea'].data[11] = 0xFF;
|
1832
2245
|
}
|
2246
|
+
|
1833
2247
|
var metricsOverride = {
|
1834
2248
|
unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
|
1835
2249
|
yMax: int16(tables['head'].data[42], tables['head'].data[43]),
|
@@ -1839,18 +2253,22 @@ var Font = function FontClosure() {
|
|
1839
2253
|
};
|
1840
2254
|
this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
|
1841
2255
|
this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
2256
|
+
|
1842
2257
|
if (tables['post']) {
|
1843
2258
|
readPostScriptTable(tables['post'], properties, numGlyphs);
|
1844
2259
|
}
|
2260
|
+
|
1845
2261
|
tables['post'] = {
|
1846
2262
|
tag: 'post',
|
1847
2263
|
data: createPostTable(properties)
|
1848
2264
|
};
|
1849
2265
|
var charCodeToGlyphId = [],
|
1850
2266
|
charCode;
|
2267
|
+
|
1851
2268
|
function hasGlyph(glyphId) {
|
1852
2269
|
return !missingGlyphs[glyphId];
|
1853
2270
|
}
|
2271
|
+
|
1854
2272
|
if (properties.composite) {
|
1855
2273
|
var cidToGidMap = properties.cidToGidMap || [];
|
1856
2274
|
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
@@ -1858,12 +2276,15 @@ var Font = function FontClosure() {
|
|
1858
2276
|
if (cid > 0xffff) {
|
1859
2277
|
throw new _util.FormatError('Max size of CID is 65,535');
|
1860
2278
|
}
|
2279
|
+
|
1861
2280
|
var glyphId = -1;
|
2281
|
+
|
1862
2282
|
if (isCidToGidMapEmpty) {
|
1863
2283
|
glyphId = cid;
|
1864
2284
|
} else if (cidToGidMap[cid] !== undefined) {
|
1865
2285
|
glyphId = cidToGidMap[cid];
|
1866
2286
|
}
|
2287
|
+
|
1867
2288
|
if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {
|
1868
2289
|
charCodeToGlyphId[charCode] = glyphId;
|
1869
2290
|
}
|
@@ -1874,14 +2295,19 @@ var Font = function FontClosure() {
|
|
1874
2295
|
var cmapEncodingId = cmapTable.encodingId;
|
1875
2296
|
var cmapMappings = cmapTable.mappings;
|
1876
2297
|
var cmapMappingsLength = cmapMappings.length;
|
2298
|
+
|
1877
2299
|
if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && !!(0, _encodings.getEncoding)(properties.baseEncodingName)) {
|
1878
2300
|
var baseEncoding = [];
|
2301
|
+
|
1879
2302
|
if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
|
1880
2303
|
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
1881
2304
|
}
|
2305
|
+
|
1882
2306
|
var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2307
|
+
|
1883
2308
|
for (charCode = 0; charCode < 256; charCode++) {
|
1884
2309
|
var glyphName, standardGlyphName;
|
2310
|
+
|
1885
2311
|
if (this.differences && charCode in this.differences) {
|
1886
2312
|
glyphName = this.differences[charCode];
|
1887
2313
|
} else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
|
@@ -1889,68 +2315,85 @@ var Font = function FontClosure() {
|
|
1889
2315
|
} else {
|
1890
2316
|
glyphName = _encodings.StandardEncoding[charCode];
|
1891
2317
|
}
|
2318
|
+
|
1892
2319
|
if (!glyphName) {
|
1893
2320
|
continue;
|
1894
2321
|
}
|
2322
|
+
|
1895
2323
|
standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
|
1896
2324
|
var unicodeOrCharCode;
|
2325
|
+
|
1897
2326
|
if (cmapPlatformId === 3 && cmapEncodingId === 1) {
|
1898
2327
|
unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
|
1899
2328
|
} else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
|
1900
2329
|
unicodeOrCharCode = _encodings.MacRomanEncoding.indexOf(standardGlyphName);
|
1901
2330
|
}
|
2331
|
+
|
1902
2332
|
var found = false;
|
2333
|
+
|
1903
2334
|
for (var i = 0; i < cmapMappingsLength; ++i) {
|
1904
2335
|
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
|
1905
2336
|
continue;
|
1906
2337
|
}
|
2338
|
+
|
1907
2339
|
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
1908
2340
|
found = true;
|
1909
2341
|
break;
|
1910
2342
|
}
|
2343
|
+
|
1911
2344
|
if (!found && properties.glyphNames) {
|
1912
2345
|
var glyphId = properties.glyphNames.indexOf(glyphName);
|
2346
|
+
|
1913
2347
|
if (glyphId === -1 && standardGlyphName !== glyphName) {
|
1914
2348
|
glyphId = properties.glyphNames.indexOf(standardGlyphName);
|
1915
2349
|
}
|
2350
|
+
|
1916
2351
|
if (glyphId > 0 && hasGlyph(glyphId)) {
|
1917
2352
|
charCodeToGlyphId[charCode] = glyphId;
|
1918
2353
|
}
|
1919
2354
|
}
|
1920
2355
|
}
|
1921
2356
|
} else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
|
1922
|
-
for (var
|
1923
|
-
charCodeToGlyphId[cmapMappings[
|
2357
|
+
for (var _i2 = 0; _i2 < cmapMappingsLength; ++_i2) {
|
2358
|
+
charCodeToGlyphId[cmapMappings[_i2].charCode] = cmapMappings[_i2].glyphId;
|
1924
2359
|
}
|
1925
2360
|
} else {
|
1926
|
-
for (var
|
1927
|
-
charCode = cmapMappings[
|
2361
|
+
for (var _i3 = 0; _i3 < cmapMappingsLength; ++_i3) {
|
2362
|
+
charCode = cmapMappings[_i3].charCode;
|
2363
|
+
|
1928
2364
|
if (cmapPlatformId === 3 && charCode >= 0xF000 && charCode <= 0xF0FF) {
|
1929
2365
|
charCode &= 0xFF;
|
1930
2366
|
}
|
1931
|
-
|
2367
|
+
|
2368
|
+
charCodeToGlyphId[charCode] = cmapMappings[_i3].glyphId;
|
1932
2369
|
}
|
1933
2370
|
}
|
1934
2371
|
}
|
2372
|
+
|
1935
2373
|
if (charCodeToGlyphId.length === 0) {
|
1936
2374
|
charCodeToGlyphId[0] = 0;
|
1937
2375
|
}
|
2376
|
+
|
1938
2377
|
var glyphZeroId = numGlyphsOut - 1;
|
2378
|
+
|
1939
2379
|
if (!dupFirstEntry) {
|
1940
2380
|
glyphZeroId = 0;
|
1941
2381
|
}
|
2382
|
+
|
1942
2383
|
var newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId);
|
1943
2384
|
this.toFontChar = newMapping.toFontChar;
|
1944
2385
|
tables['cmap'] = {
|
1945
2386
|
tag: 'cmap',
|
1946
2387
|
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut)
|
1947
2388
|
};
|
2389
|
+
|
1948
2390
|
if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
|
1949
2391
|
tables['OS/2'] = {
|
1950
2392
|
tag: 'OS/2',
|
1951
2393
|
data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
|
1952
2394
|
};
|
1953
2395
|
}
|
2396
|
+
|
1954
2397
|
if (!isTrueType) {
|
1955
2398
|
try {
|
1956
2399
|
cffFile = new _stream.Stream(tables['CFF '].data);
|
@@ -1963,6 +2406,7 @@ var Font = function FontClosure() {
|
|
1963
2406
|
(0, _util.warn)('Failed to compile font ' + properties.loadedName);
|
1964
2407
|
}
|
1965
2408
|
}
|
2409
|
+
|
1966
2410
|
if (!tables['name']) {
|
1967
2411
|
tables['name'] = {
|
1968
2412
|
tag: 'name',
|
@@ -1972,51 +2416,67 @@ var Font = function FontClosure() {
|
|
1972
2416
|
var namePrototype = readNameTable(tables['name']);
|
1973
2417
|
tables['name'].data = createNameTable(name, namePrototype);
|
1974
2418
|
}
|
2419
|
+
|
1975
2420
|
var builder = new OpenTypeFileBuilder(header.version);
|
2421
|
+
|
1976
2422
|
for (var tableTag in tables) {
|
1977
2423
|
builder.addTable(tableTag, tables[tableTag].data);
|
1978
2424
|
}
|
2425
|
+
|
1979
2426
|
return builder.toArray();
|
1980
2427
|
},
|
1981
2428
|
convert: function Font_convert(fontName, font, properties) {
|
1982
2429
|
properties.fixedPitch = false;
|
2430
|
+
|
1983
2431
|
if (properties.builtInEncoding) {
|
1984
2432
|
adjustToUnicode(properties, properties.builtInEncoding);
|
1985
2433
|
}
|
2434
|
+
|
1986
2435
|
var glyphZeroId = 1;
|
2436
|
+
|
1987
2437
|
if (font instanceof CFFFont) {
|
1988
2438
|
glyphZeroId = font.numGlyphs - 1;
|
1989
2439
|
}
|
2440
|
+
|
1990
2441
|
var mapping = font.getGlyphMapping(properties);
|
1991
2442
|
var newMapping = adjustMapping(mapping, font.hasGlyphId.bind(font), glyphZeroId);
|
1992
2443
|
this.toFontChar = newMapping.toFontChar;
|
1993
2444
|
var numGlyphs = font.numGlyphs;
|
2445
|
+
|
1994
2446
|
function getCharCodes(charCodeToGlyphId, glyphId) {
|
1995
2447
|
var charCodes = null;
|
2448
|
+
|
1996
2449
|
for (var charCode in charCodeToGlyphId) {
|
1997
2450
|
if (glyphId === charCodeToGlyphId[charCode]) {
|
1998
2451
|
if (!charCodes) {
|
1999
2452
|
charCodes = [];
|
2000
2453
|
}
|
2454
|
+
|
2001
2455
|
charCodes.push(charCode | 0);
|
2002
2456
|
}
|
2003
2457
|
}
|
2458
|
+
|
2004
2459
|
return charCodes;
|
2005
2460
|
}
|
2461
|
+
|
2006
2462
|
function createCharCode(charCodeToGlyphId, glyphId) {
|
2007
2463
|
for (var charCode in charCodeToGlyphId) {
|
2008
2464
|
if (glyphId === charCodeToGlyphId[charCode]) {
|
2009
2465
|
return charCode | 0;
|
2010
2466
|
}
|
2011
2467
|
}
|
2468
|
+
|
2012
2469
|
newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
|
2013
2470
|
return newMapping.nextAvailableFontCharCode++;
|
2014
2471
|
}
|
2472
|
+
|
2015
2473
|
var seacs = font.seacs;
|
2474
|
+
|
2016
2475
|
if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
|
2017
2476
|
var matrix = properties.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
2018
2477
|
var charset = font.getCharset();
|
2019
2478
|
var seacMap = Object.create(null);
|
2479
|
+
|
2020
2480
|
for (var glyphId in seacs) {
|
2021
2481
|
glyphId |= 0;
|
2022
2482
|
var seac = seacs[glyphId];
|
@@ -2024,17 +2484,21 @@ var Font = function FontClosure() {
|
|
2024
2484
|
var accentGlyphName = _encodings.StandardEncoding[seac[3]];
|
2025
2485
|
var baseGlyphId = charset.indexOf(baseGlyphName);
|
2026
2486
|
var accentGlyphId = charset.indexOf(accentGlyphName);
|
2487
|
+
|
2027
2488
|
if (baseGlyphId < 0 || accentGlyphId < 0) {
|
2028
2489
|
continue;
|
2029
2490
|
}
|
2491
|
+
|
2030
2492
|
var accentOffset = {
|
2031
2493
|
x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
|
2032
2494
|
y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
|
2033
2495
|
};
|
2034
2496
|
var charCodes = getCharCodes(mapping, glyphId);
|
2497
|
+
|
2035
2498
|
if (!charCodes) {
|
2036
2499
|
continue;
|
2037
2500
|
}
|
2501
|
+
|
2038
2502
|
for (var i = 0, ii = charCodes.length; i < ii; i++) {
|
2039
2503
|
var charCode = charCodes[i];
|
2040
2504
|
var charCodeToGlyphId = newMapping.charCodeToGlyphId;
|
@@ -2047,8 +2511,10 @@ var Font = function FontClosure() {
|
|
2047
2511
|
};
|
2048
2512
|
}
|
2049
2513
|
}
|
2514
|
+
|
2050
2515
|
properties.seacMap = seacMap;
|
2051
2516
|
}
|
2517
|
+
|
2052
2518
|
var unitsPerEm = 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
|
2053
2519
|
var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
|
2054
2520
|
builder.addTable('CFF ', font.data);
|
@@ -2060,16 +2526,20 @@ var Font = function FontClosure() {
|
|
2060
2526
|
var charstrings = font.charstrings;
|
2061
2527
|
var cffWidths = font.cff ? font.cff.widths : null;
|
2062
2528
|
var hmtx = '\x00\x00\x00\x00';
|
2529
|
+
|
2063
2530
|
for (var i = 1, ii = numGlyphs; i < ii; i++) {
|
2064
2531
|
var width = 0;
|
2532
|
+
|
2065
2533
|
if (charstrings) {
|
2066
2534
|
var charstring = charstrings[i - 1];
|
2067
2535
|
width = 'width' in charstring ? charstring.width : 0;
|
2068
2536
|
} else if (cffWidths) {
|
2069
2537
|
width = Math.ceil(cffWidths[i] || 0);
|
2070
2538
|
}
|
2539
|
+
|
2071
2540
|
hmtx += string16(width) + string16(0);
|
2072
2541
|
}
|
2542
|
+
|
2073
2543
|
return hmtx;
|
2074
2544
|
}());
|
2075
2545
|
builder.addTable('maxp', '\x00\x00\x50\x00' + string16(numGlyphs));
|
@@ -2077,63 +2547,83 @@ var Font = function FontClosure() {
|
|
2077
2547
|
builder.addTable('post', createPostTable(properties));
|
2078
2548
|
return builder.toArray();
|
2079
2549
|
},
|
2550
|
+
|
2080
2551
|
get spaceWidth() {
|
2081
2552
|
if ('_shadowWidth' in this) {
|
2082
2553
|
return this._shadowWidth;
|
2083
2554
|
}
|
2555
|
+
|
2084
2556
|
var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
|
2085
2557
|
var width;
|
2558
|
+
|
2086
2559
|
for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
|
2087
2560
|
var glyphName = possibleSpaceReplacements[i];
|
2561
|
+
|
2088
2562
|
if (glyphName in this.widths) {
|
2089
2563
|
width = this.widths[glyphName];
|
2090
2564
|
break;
|
2091
2565
|
}
|
2566
|
+
|
2092
2567
|
var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2093
2568
|
var glyphUnicode = glyphsUnicodeMap[glyphName];
|
2094
2569
|
var charcode = 0;
|
2570
|
+
|
2095
2571
|
if (this.composite) {
|
2096
2572
|
if (this.cMap.contains(glyphUnicode)) {
|
2097
2573
|
charcode = this.cMap.lookup(glyphUnicode);
|
2098
2574
|
}
|
2099
2575
|
}
|
2576
|
+
|
2100
2577
|
if (!charcode && this.toUnicode) {
|
2101
2578
|
charcode = this.toUnicode.charCodeOf(glyphUnicode);
|
2102
2579
|
}
|
2580
|
+
|
2103
2581
|
if (charcode <= 0) {
|
2104
2582
|
charcode = glyphUnicode;
|
2105
2583
|
}
|
2584
|
+
|
2106
2585
|
width = this.widths[charcode];
|
2586
|
+
|
2107
2587
|
if (width) {
|
2108
2588
|
break;
|
2109
2589
|
}
|
2110
2590
|
}
|
2591
|
+
|
2111
2592
|
width = width || this.defaultWidth;
|
2112
2593
|
this._shadowWidth = width;
|
2113
2594
|
return width;
|
2114
2595
|
},
|
2596
|
+
|
2115
2597
|
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
|
2116
2598
|
var fontCharCode, width, operatorListId;
|
2117
2599
|
var widthCode = charcode;
|
2600
|
+
|
2118
2601
|
if (this.cMap && this.cMap.contains(charcode)) {
|
2119
2602
|
widthCode = this.cMap.lookup(charcode);
|
2120
2603
|
}
|
2604
|
+
|
2121
2605
|
width = this.widths[widthCode];
|
2122
2606
|
width = (0, _util.isNum)(width) ? width : this.defaultWidth;
|
2123
2607
|
var vmetric = this.vmetrics && this.vmetrics[widthCode];
|
2124
2608
|
var unicode = this.toUnicode.get(charcode) || this.fallbackToUnicode.get(charcode) || charcode;
|
2609
|
+
|
2125
2610
|
if (typeof unicode === 'number') {
|
2126
2611
|
unicode = String.fromCharCode(unicode);
|
2127
2612
|
}
|
2613
|
+
|
2128
2614
|
var isInFont = charcode in this.toFontChar;
|
2129
2615
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
2616
|
+
|
2130
2617
|
if (this.missingFile) {
|
2131
2618
|
fontCharCode = (0, _unicode.mapSpecialUnicodeValues)(fontCharCode);
|
2132
2619
|
}
|
2620
|
+
|
2133
2621
|
if (this.isType3Font) {
|
2134
2622
|
operatorListId = fontCharCode;
|
2135
2623
|
}
|
2624
|
+
|
2136
2625
|
var accent = null;
|
2626
|
+
|
2137
2627
|
if (this.seacMap && this.seacMap[charcode]) {
|
2138
2628
|
isInFont = true;
|
2139
2629
|
var seac = this.seacMap[charcode];
|
@@ -2143,32 +2633,41 @@ var Font = function FontClosure() {
|
|
2143
2633
|
offset: seac.accentOffset
|
2144
2634
|
};
|
2145
2635
|
}
|
2636
|
+
|
2146
2637
|
var fontChar = typeof fontCharCode === 'number' ? String.fromCodePoint(fontCharCode) : '';
|
2147
2638
|
var glyph = this.glyphCache[charcode];
|
2639
|
+
|
2148
2640
|
if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
|
2149
2641
|
glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
|
2150
2642
|
this.glyphCache[charcode] = glyph;
|
2151
2643
|
}
|
2644
|
+
|
2152
2645
|
return glyph;
|
2153
2646
|
},
|
2154
2647
|
charsToGlyphs: function Font_charsToGlyphs(chars) {
|
2155
2648
|
var charsCache = this.charsCache;
|
2156
2649
|
var glyphs, glyph, charcode;
|
2650
|
+
|
2157
2651
|
if (charsCache) {
|
2158
2652
|
glyphs = charsCache[chars];
|
2653
|
+
|
2159
2654
|
if (glyphs) {
|
2160
2655
|
return glyphs;
|
2161
2656
|
}
|
2162
2657
|
}
|
2658
|
+
|
2163
2659
|
if (!charsCache) {
|
2164
2660
|
charsCache = this.charsCache = Object.create(null);
|
2165
2661
|
}
|
2662
|
+
|
2166
2663
|
glyphs = [];
|
2167
2664
|
var charsCacheKey = chars;
|
2168
2665
|
var i = 0,
|
2169
2666
|
ii;
|
2667
|
+
|
2170
2668
|
if (this.cMap) {
|
2171
2669
|
var c = Object.create(null);
|
2670
|
+
|
2172
2671
|
while (i < chars.length) {
|
2173
2672
|
this.cMap.readCharCode(chars, i, c);
|
2174
2673
|
charcode = c.charcode;
|
@@ -2185,35 +2684,53 @@ var Font = function FontClosure() {
|
|
2185
2684
|
glyphs.push(glyph);
|
2186
2685
|
}
|
2187
2686
|
}
|
2687
|
+
|
2188
2688
|
return charsCache[charsCacheKey] = glyphs;
|
2689
|
+
},
|
2690
|
+
|
2691
|
+
get glyphCacheValues() {
|
2692
|
+
return Object.values(this.glyphCache);
|
2189
2693
|
}
|
2694
|
+
|
2190
2695
|
};
|
2191
2696
|
return Font;
|
2192
2697
|
}();
|
2698
|
+
|
2699
|
+
exports.Font = Font;
|
2700
|
+
|
2193
2701
|
var ErrorFont = function ErrorFontClosure() {
|
2194
2702
|
function ErrorFont(error) {
|
2195
2703
|
this.error = error;
|
2196
2704
|
this.loadedName = 'g_font_error';
|
2197
2705
|
this.missingFile = true;
|
2198
2706
|
}
|
2707
|
+
|
2199
2708
|
ErrorFont.prototype = {
|
2200
2709
|
charsToGlyphs: function ErrorFont_charsToGlyphs() {
|
2201
2710
|
return [];
|
2202
2711
|
},
|
2203
2712
|
exportData: function ErrorFont_exportData() {
|
2204
|
-
return {
|
2713
|
+
return {
|
2714
|
+
error: this.error
|
2715
|
+
};
|
2205
2716
|
}
|
2206
2717
|
};
|
2207
2718
|
return ErrorFont;
|
2208
2719
|
}();
|
2720
|
+
|
2721
|
+
exports.ErrorFont = ErrorFont;
|
2722
|
+
|
2209
2723
|
function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
2210
2724
|
var charCodeToGlyphId = Object.create(null);
|
2211
2725
|
var glyphId, charCode, baseEncoding;
|
2212
2726
|
var isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
|
2727
|
+
|
2213
2728
|
if (properties.baseEncodingName) {
|
2214
2729
|
baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
|
2730
|
+
|
2215
2731
|
for (charCode = 0; charCode < baseEncoding.length; charCode++) {
|
2216
2732
|
glyphId = glyphNames.indexOf(baseEncoding[charCode]);
|
2733
|
+
|
2217
2734
|
if (glyphId >= 0) {
|
2218
2735
|
charCodeToGlyphId[charCode] = glyphId;
|
2219
2736
|
} else {
|
@@ -2226,8 +2743,10 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
|
2226
2743
|
}
|
2227
2744
|
} else {
|
2228
2745
|
baseEncoding = _encodings.StandardEncoding;
|
2746
|
+
|
2229
2747
|
for (charCode = 0; charCode < baseEncoding.length; charCode++) {
|
2230
2748
|
glyphId = glyphNames.indexOf(baseEncoding[charCode]);
|
2749
|
+
|
2231
2750
|
if (glyphId >= 0) {
|
2232
2751
|
charCodeToGlyphId[charCode] = glyphId;
|
2233
2752
|
} else {
|
@@ -2235,21 +2754,27 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
|
2235
2754
|
}
|
2236
2755
|
}
|
2237
2756
|
}
|
2757
|
+
|
2238
2758
|
var differences = properties.differences,
|
2239
2759
|
glyphsUnicodeMap;
|
2760
|
+
|
2240
2761
|
if (differences) {
|
2241
2762
|
for (charCode in differences) {
|
2242
2763
|
var glyphName = differences[charCode];
|
2243
2764
|
glyphId = glyphNames.indexOf(glyphName);
|
2765
|
+
|
2244
2766
|
if (glyphId === -1) {
|
2245
2767
|
if (!glyphsUnicodeMap) {
|
2246
2768
|
glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2247
2769
|
}
|
2770
|
+
|
2248
2771
|
var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
|
2772
|
+
|
2249
2773
|
if (standardGlyphName !== glyphName) {
|
2250
2774
|
glyphId = glyphNames.indexOf(standardGlyphName);
|
2251
2775
|
}
|
2252
2776
|
}
|
2777
|
+
|
2253
2778
|
if (glyphId >= 0) {
|
2254
2779
|
charCodeToGlyphId[charCode] = glyphId;
|
2255
2780
|
} else {
|
@@ -2257,8 +2782,10 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
|
2257
2782
|
}
|
2258
2783
|
}
|
2259
2784
|
}
|
2785
|
+
|
2260
2786
|
return charCodeToGlyphId;
|
2261
2787
|
}
|
2788
|
+
|
2262
2789
|
var Type1Font = function Type1FontClosure() {
|
2263
2790
|
function findBlock(streamBytes, signature, startIndex) {
|
2264
2791
|
var streamBytesLength = streamBytes.length;
|
@@ -2267,30 +2794,39 @@ var Type1Font = function Type1FontClosure() {
|
|
2267
2794
|
var i = startIndex,
|
2268
2795
|
j,
|
2269
2796
|
found = false;
|
2797
|
+
|
2270
2798
|
while (i < scanLength) {
|
2271
2799
|
j = 0;
|
2800
|
+
|
2272
2801
|
while (j < signatureLength && streamBytes[i + j] === signature[j]) {
|
2273
2802
|
j++;
|
2274
2803
|
}
|
2804
|
+
|
2275
2805
|
if (j >= signatureLength) {
|
2276
2806
|
i += j;
|
2807
|
+
|
2277
2808
|
while (i < streamBytesLength && (0, _util.isSpace)(streamBytes[i])) {
|
2278
2809
|
i++;
|
2279
2810
|
}
|
2811
|
+
|
2280
2812
|
found = true;
|
2281
2813
|
break;
|
2282
2814
|
}
|
2815
|
+
|
2283
2816
|
i++;
|
2284
2817
|
}
|
2818
|
+
|
2285
2819
|
return {
|
2286
2820
|
found: found,
|
2287
2821
|
length: i
|
2288
2822
|
};
|
2289
2823
|
}
|
2824
|
+
|
2290
2825
|
function getHeaderBlock(stream, suggestedLength) {
|
2291
2826
|
var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
|
2292
2827
|
var streamStartPos = stream.pos;
|
2293
2828
|
var headerBytes, headerBytesLength, block;
|
2829
|
+
|
2294
2830
|
try {
|
2295
2831
|
headerBytes = stream.getBytes(suggestedLength);
|
2296
2832
|
headerBytesLength = headerBytes.length;
|
@@ -2299,8 +2835,10 @@ var Type1Font = function Type1FontClosure() {
|
|
2299
2835
|
throw ex;
|
2300
2836
|
}
|
2301
2837
|
}
|
2838
|
+
|
2302
2839
|
if (headerBytesLength === suggestedLength) {
|
2303
2840
|
block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
|
2841
|
+
|
2304
2842
|
if (block.found && block.length === suggestedLength) {
|
2305
2843
|
return {
|
2306
2844
|
stream: new _stream.Stream(headerBytes),
|
@@ -2308,35 +2846,44 @@ var Type1Font = function Type1FontClosure() {
|
|
2308
2846
|
};
|
2309
2847
|
}
|
2310
2848
|
}
|
2849
|
+
|
2311
2850
|
(0, _util.warn)('Invalid "Length1" property in Type1 font -- trying to recover.');
|
2312
2851
|
stream.pos = streamStartPos;
|
2313
2852
|
var SCAN_BLOCK_LENGTH = 2048;
|
2314
2853
|
var actualLength;
|
2854
|
+
|
2315
2855
|
while (true) {
|
2316
2856
|
var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
|
2317
2857
|
block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
|
2858
|
+
|
2318
2859
|
if (block.length === 0) {
|
2319
2860
|
break;
|
2320
2861
|
}
|
2862
|
+
|
2321
2863
|
stream.pos += block.length;
|
2864
|
+
|
2322
2865
|
if (block.found) {
|
2323
2866
|
actualLength = stream.pos - streamStartPos;
|
2324
2867
|
break;
|
2325
2868
|
}
|
2326
2869
|
}
|
2870
|
+
|
2327
2871
|
stream.pos = streamStartPos;
|
2872
|
+
|
2328
2873
|
if (actualLength) {
|
2329
2874
|
return {
|
2330
2875
|
stream: new _stream.Stream(stream.getBytes(actualLength)),
|
2331
2876
|
length: actualLength
|
2332
2877
|
};
|
2333
2878
|
}
|
2879
|
+
|
2334
2880
|
(0, _util.warn)('Unable to recover "Length1" property in Type1 font -- using as is.');
|
2335
2881
|
return {
|
2336
2882
|
stream: new _stream.Stream(stream.getBytes(suggestedLength)),
|
2337
2883
|
length: suggestedLength
|
2338
2884
|
};
|
2339
2885
|
}
|
2886
|
+
|
2340
2887
|
function getEexecBlock(stream, suggestedLength) {
|
2341
2888
|
var eexecBytes = stream.getBytes();
|
2342
2889
|
return {
|
@@ -2344,29 +2891,36 @@ var Type1Font = function Type1FontClosure() {
|
|
2344
2891
|
length: eexecBytes.length
|
2345
2892
|
};
|
2346
2893
|
}
|
2894
|
+
|
2347
2895
|
function Type1Font(name, file, properties) {
|
2348
2896
|
var PFB_HEADER_SIZE = 6;
|
2349
2897
|
var headerBlockLength = properties.length1;
|
2350
2898
|
var eexecBlockLength = properties.length2;
|
2351
2899
|
var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
|
2352
2900
|
var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
|
2901
|
+
|
2353
2902
|
if (pfbHeaderPresent) {
|
2354
2903
|
file.skip(PFB_HEADER_SIZE);
|
2355
2904
|
headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
|
2356
2905
|
}
|
2906
|
+
|
2357
2907
|
var headerBlock = getHeaderBlock(file, headerBlockLength);
|
2358
2908
|
var headerBlockParser = new _type1_parser.Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
|
2359
2909
|
headerBlockParser.extractFontHeader(properties);
|
2910
|
+
|
2360
2911
|
if (pfbHeaderPresent) {
|
2361
2912
|
pfbHeader = file.getBytes(PFB_HEADER_SIZE);
|
2362
2913
|
eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
|
2363
2914
|
}
|
2915
|
+
|
2364
2916
|
var eexecBlock = getEexecBlock(file, eexecBlockLength);
|
2365
2917
|
var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
|
2366
2918
|
var data = eexecBlockParser.extractFontProgram();
|
2919
|
+
|
2367
2920
|
for (var info in data.properties) {
|
2368
2921
|
properties[info] = data.properties[info];
|
2369
2922
|
}
|
2923
|
+
|
2370
2924
|
var charstrings = data.charstrings;
|
2371
2925
|
var type2Charstrings = this.getType2Charstrings(charstrings);
|
2372
2926
|
var subrs = this.getType2Subrs(data.subrs);
|
@@ -2374,68 +2928,86 @@ var Type1Font = function Type1FontClosure() {
|
|
2374
2928
|
this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
|
2375
2929
|
this.seacs = this.getSeacs(data.charstrings);
|
2376
2930
|
}
|
2931
|
+
|
2377
2932
|
Type1Font.prototype = {
|
2378
2933
|
get numGlyphs() {
|
2379
2934
|
return this.charstrings.length + 1;
|
2380
2935
|
},
|
2936
|
+
|
2381
2937
|
getCharset: function Type1Font_getCharset() {
|
2382
2938
|
var charset = ['.notdef'];
|
2383
2939
|
var charstrings = this.charstrings;
|
2940
|
+
|
2384
2941
|
for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
2385
2942
|
charset.push(charstrings[glyphId].glyphName);
|
2386
2943
|
}
|
2944
|
+
|
2387
2945
|
return charset;
|
2388
2946
|
},
|
2389
2947
|
getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
|
2390
2948
|
var charstrings = this.charstrings;
|
2391
2949
|
var glyphNames = ['.notdef'],
|
2392
2950
|
glyphId;
|
2951
|
+
|
2393
2952
|
for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
2394
2953
|
glyphNames.push(charstrings[glyphId].glyphName);
|
2395
2954
|
}
|
2955
|
+
|
2396
2956
|
var encoding = properties.builtInEncoding;
|
2957
|
+
|
2397
2958
|
if (encoding) {
|
2398
2959
|
var builtInEncoding = Object.create(null);
|
2960
|
+
|
2399
2961
|
for (var charCode in encoding) {
|
2400
2962
|
glyphId = glyphNames.indexOf(encoding[charCode]);
|
2963
|
+
|
2401
2964
|
if (glyphId >= 0) {
|
2402
2965
|
builtInEncoding[charCode] = glyphId;
|
2403
2966
|
}
|
2404
2967
|
}
|
2405
2968
|
}
|
2969
|
+
|
2406
2970
|
return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
|
2407
2971
|
},
|
2408
2972
|
hasGlyphId: function Type1Font_hasGlyphID(id) {
|
2409
2973
|
if (id < 0 || id >= this.numGlyphs) {
|
2410
2974
|
return false;
|
2411
2975
|
}
|
2976
|
+
|
2412
2977
|
if (id === 0) {
|
2413
2978
|
return true;
|
2414
2979
|
}
|
2980
|
+
|
2415
2981
|
var glyph = this.charstrings[id - 1];
|
2416
2982
|
return glyph.charstring.length > 0;
|
2417
2983
|
},
|
2418
2984
|
getSeacs: function Type1Font_getSeacs(charstrings) {
|
2419
2985
|
var i, ii;
|
2420
2986
|
var seacMap = [];
|
2987
|
+
|
2421
2988
|
for (i = 0, ii = charstrings.length; i < ii; i++) {
|
2422
2989
|
var charstring = charstrings[i];
|
2990
|
+
|
2423
2991
|
if (charstring.seac) {
|
2424
2992
|
seacMap[i + 1] = charstring.seac;
|
2425
2993
|
}
|
2426
2994
|
}
|
2995
|
+
|
2427
2996
|
return seacMap;
|
2428
2997
|
},
|
2429
2998
|
getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
|
2430
2999
|
var type2Charstrings = [];
|
3000
|
+
|
2431
3001
|
for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
|
2432
3002
|
type2Charstrings.push(type1Charstrings[i].charstring);
|
2433
3003
|
}
|
3004
|
+
|
2434
3005
|
return type2Charstrings;
|
2435
3006
|
},
|
2436
3007
|
getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
|
2437
3008
|
var bias = 0;
|
2438
3009
|
var count = type1Subrs.length;
|
3010
|
+
|
2439
3011
|
if (count < 1133) {
|
2440
3012
|
bias = 107;
|
2441
3013
|
} else if (count < 33769) {
|
@@ -2443,14 +3015,18 @@ var Type1Font = function Type1FontClosure() {
|
|
2443
3015
|
} else {
|
2444
3016
|
bias = 32768;
|
2445
3017
|
}
|
3018
|
+
|
2446
3019
|
var type2Subrs = [];
|
2447
3020
|
var i;
|
3021
|
+
|
2448
3022
|
for (i = 0; i < bias; i++) {
|
2449
3023
|
type2Subrs.push([0x0B]);
|
2450
3024
|
}
|
3025
|
+
|
2451
3026
|
for (i = 0; i < count; i++) {
|
2452
3027
|
type2Subrs.push(type1Subrs[i]);
|
2453
3028
|
}
|
3029
|
+
|
2454
3030
|
return type2Subrs;
|
2455
3031
|
},
|
2456
3032
|
wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
|
@@ -2481,41 +3057,55 @@ var Type1Font = function Type1FontClosure() {
|
|
2481
3057
|
var count = glyphs.length;
|
2482
3058
|
var charsetArray = [0];
|
2483
3059
|
var i, ii;
|
3060
|
+
|
2484
3061
|
for (i = 0; i < count; i++) {
|
2485
3062
|
var index = _cff_parser.CFFStandardStrings.indexOf(charstrings[i].glyphName);
|
3063
|
+
|
2486
3064
|
if (index === -1) {
|
2487
3065
|
index = 0;
|
2488
3066
|
}
|
3067
|
+
|
2489
3068
|
charsetArray.push(index >> 8 & 0xff, index & 0xff);
|
2490
3069
|
}
|
3070
|
+
|
2491
3071
|
cff.charset = new _cff_parser.CFFCharset(false, 0, [], charsetArray);
|
2492
3072
|
var charStringsIndex = new _cff_parser.CFFIndex();
|
2493
3073
|
charStringsIndex.add([0x8B, 0x0E]);
|
3074
|
+
|
2494
3075
|
for (i = 0; i < count; i++) {
|
2495
3076
|
charStringsIndex.add(glyphs[i]);
|
2496
3077
|
}
|
3078
|
+
|
2497
3079
|
cff.charStrings = charStringsIndex;
|
2498
3080
|
var privateDict = new _cff_parser.CFFPrivateDict();
|
2499
3081
|
privateDict.setByName('Subrs', null);
|
2500
3082
|
var fields = ['BlueValues', 'OtherBlues', 'FamilyBlues', 'FamilyOtherBlues', 'StemSnapH', 'StemSnapV', 'BlueShift', 'BlueFuzz', 'BlueScale', 'LanguageGroup', 'ExpansionFactor', 'ForceBold', 'StdHW', 'StdVW'];
|
3083
|
+
|
2501
3084
|
for (i = 0, ii = fields.length; i < ii; i++) {
|
2502
3085
|
var field = fields[i];
|
3086
|
+
|
2503
3087
|
if (!(field in properties.privateData)) {
|
2504
3088
|
continue;
|
2505
3089
|
}
|
3090
|
+
|
2506
3091
|
var value = properties.privateData[field];
|
3092
|
+
|
2507
3093
|
if (Array.isArray(value)) {
|
2508
3094
|
for (var j = value.length - 1; j > 0; j--) {
|
2509
3095
|
value[j] -= value[j - 1];
|
2510
3096
|
}
|
2511
3097
|
}
|
3098
|
+
|
2512
3099
|
privateDict.setByName(field, value);
|
2513
3100
|
}
|
3101
|
+
|
2514
3102
|
cff.topDict.privateDict = privateDict;
|
2515
3103
|
var subrIndex = new _cff_parser.CFFIndex();
|
3104
|
+
|
2516
3105
|
for (i = 0, ii = subrs.length; i < ii; i++) {
|
2517
3106
|
subrIndex.add(subrs[i]);
|
2518
3107
|
}
|
3108
|
+
|
2519
3109
|
privateDict.subrsIndex = subrIndex;
|
2520
3110
|
var compiler = new _cff_parser.CFFCompiler(cff);
|
2521
3111
|
return compiler.compile();
|
@@ -2523,6 +3113,7 @@ var Type1Font = function Type1FontClosure() {
|
|
2523
3113
|
};
|
2524
3114
|
return Type1Font;
|
2525
3115
|
}();
|
3116
|
+
|
2526
3117
|
var CFFFont = function CFFFontClosure() {
|
2527
3118
|
function CFFFont(file, properties) {
|
2528
3119
|
this.properties = properties;
|
@@ -2531,6 +3122,7 @@ var CFFFont = function CFFFontClosure() {
|
|
2531
3122
|
this.cff.duplicateFirstGlyph();
|
2532
3123
|
var compiler = new _cff_parser.CFFCompiler(this.cff);
|
2533
3124
|
this.seacs = this.cff.seacs;
|
3125
|
+
|
2534
3126
|
try {
|
2535
3127
|
this.data = compiler.compile();
|
2536
3128
|
} catch (e) {
|
@@ -2538,10 +3130,12 @@ var CFFFont = function CFFFontClosure() {
|
|
2538
3130
|
this.data = file;
|
2539
3131
|
}
|
2540
3132
|
}
|
3133
|
+
|
2541
3134
|
CFFFont.prototype = {
|
2542
3135
|
get numGlyphs() {
|
2543
3136
|
return this.cff.charStrings.count;
|
2544
3137
|
},
|
3138
|
+
|
2545
3139
|
getCharset: function CFFFont_getCharset() {
|
2546
3140
|
return this.cff.charset.charset;
|
2547
3141
|
},
|
@@ -2551,8 +3145,10 @@ var CFFFont = function CFFFontClosure() {
|
|
2551
3145
|
var charsets = cff.charset.charset;
|
2552
3146
|
var charCodeToGlyphId;
|
2553
3147
|
var glyphId;
|
3148
|
+
|
2554
3149
|
if (properties.composite) {
|
2555
3150
|
charCodeToGlyphId = Object.create(null);
|
3151
|
+
|
2556
3152
|
if (cff.isCIDFont) {
|
2557
3153
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
2558
3154
|
var cid = charsets[glyphId];
|
@@ -2564,8 +3160,10 @@ var CFFFont = function CFFFontClosure() {
|
|
2564
3160
|
charCodeToGlyphId[glyphId] = glyphId;
|
2565
3161
|
}
|
2566
3162
|
}
|
3163
|
+
|
2567
3164
|
return charCodeToGlyphId;
|
2568
3165
|
}
|
3166
|
+
|
2569
3167
|
var encoding = cff.encoding ? cff.encoding.encoding : null;
|
2570
3168
|
charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
|
2571
3169
|
return charCodeToGlyphId;
|
@@ -2575,11 +3173,4 @@ var CFFFont = function CFFFontClosure() {
|
|
2575
3173
|
}
|
2576
3174
|
};
|
2577
3175
|
return CFFFont;
|
2578
|
-
}();
|
2579
|
-
exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
|
2580
|
-
exports.ErrorFont = ErrorFont;
|
2581
|
-
exports.Font = Font;
|
2582
|
-
exports.FontFlags = FontFlags;
|
2583
|
-
exports.ToUnicodeMap = ToUnicodeMap;
|
2584
|
-
exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
|
2585
|
-
exports.getFontType = getFontType;
|
3176
|
+
}();
|