pdfjs-dist 2.0.943 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,74 +19,94 @@
|
|
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.FontRendererFactory =
|
27
|
+
exports.FontRendererFactory = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _cff_parser = require("./cff_parser.js");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _glyphlist = require("./glyphlist.js");
|
34
34
|
|
35
|
-
var
|
35
|
+
var _encodings = require("./encodings.js");
|
36
36
|
|
37
|
-
var
|
38
|
-
|
39
|
-
var _stream = require('./stream');
|
40
|
-
|
41
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
42
|
-
|
43
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
44
|
-
|
45
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
37
|
+
var _stream = require("./stream.js");
|
46
38
|
|
47
39
|
var FontRendererFactory = function FontRendererFactoryClosure() {
|
48
40
|
function getLong(data, offset) {
|
49
41
|
return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
|
50
42
|
}
|
43
|
+
|
51
44
|
function getUshort(data, offset) {
|
52
45
|
return data[offset] << 8 | data[offset + 1];
|
53
46
|
}
|
47
|
+
|
48
|
+
function getSubroutineBias(subrs) {
|
49
|
+
const numSubrs = subrs.length;
|
50
|
+
let bias = 32768;
|
51
|
+
|
52
|
+
if (numSubrs < 1240) {
|
53
|
+
bias = 107;
|
54
|
+
} else if (numSubrs < 33900) {
|
55
|
+
bias = 1131;
|
56
|
+
}
|
57
|
+
|
58
|
+
return bias;
|
59
|
+
}
|
60
|
+
|
54
61
|
function parseCmap(data, start, end) {
|
55
62
|
var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
|
56
63
|
var format = getUshort(data, start + offset);
|
57
64
|
var ranges, p, i;
|
65
|
+
|
58
66
|
if (format === 4) {
|
59
67
|
getUshort(data, start + offset + 2);
|
60
68
|
var segCount = getUshort(data, start + offset + 6) >> 1;
|
61
69
|
p = start + offset + 14;
|
62
70
|
ranges = [];
|
71
|
+
|
63
72
|
for (i = 0; i < segCount; i++, p += 2) {
|
64
|
-
ranges[i] = {
|
73
|
+
ranges[i] = {
|
74
|
+
end: getUshort(data, p)
|
75
|
+
};
|
65
76
|
}
|
77
|
+
|
66
78
|
p += 2;
|
79
|
+
|
67
80
|
for (i = 0; i < segCount; i++, p += 2) {
|
68
81
|
ranges[i].start = getUshort(data, p);
|
69
82
|
}
|
83
|
+
|
70
84
|
for (i = 0; i < segCount; i++, p += 2) {
|
71
85
|
ranges[i].idDelta = getUshort(data, p);
|
72
86
|
}
|
87
|
+
|
73
88
|
for (i = 0; i < segCount; i++, p += 2) {
|
74
89
|
var idOffset = getUshort(data, p);
|
90
|
+
|
75
91
|
if (idOffset === 0) {
|
76
92
|
continue;
|
77
93
|
}
|
94
|
+
|
78
95
|
ranges[i].ids = [];
|
96
|
+
|
79
97
|
for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
|
80
98
|
ranges[i].ids[j] = getUshort(data, p + idOffset);
|
81
99
|
idOffset += 2;
|
82
100
|
}
|
83
101
|
}
|
102
|
+
|
84
103
|
return ranges;
|
85
104
|
} else if (format === 12) {
|
86
105
|
getLong(data, start + offset + 4);
|
87
106
|
var groups = getLong(data, start + offset + 12);
|
88
107
|
p = start + offset + 16;
|
89
108
|
ranges = [];
|
109
|
+
|
90
110
|
for (i = 0; i < groups; i++) {
|
91
111
|
ranges.push({
|
92
112
|
start: getLong(data, p),
|
@@ -95,10 +115,13 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
95
115
|
});
|
96
116
|
p += 12;
|
97
117
|
}
|
118
|
+
|
98
119
|
return ranges;
|
99
120
|
}
|
100
|
-
|
121
|
+
|
122
|
+
throw new _util.FormatError(`unsupported cmap: ${format}`);
|
101
123
|
}
|
124
|
+
|
102
125
|
function parseCff(data, start, end, seacAnalysisEnabled) {
|
103
126
|
var properties = {};
|
104
127
|
var parser = new _cff_parser.CFFParser(new _stream.Stream(data, start, end - start), properties, seacAnalysisEnabled);
|
@@ -112,80 +135,98 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
112
135
|
fdArray: cff.fdArray
|
113
136
|
};
|
114
137
|
}
|
138
|
+
|
115
139
|
function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
|
116
140
|
var itemSize, itemDecode;
|
141
|
+
|
117
142
|
if (isGlyphLocationsLong) {
|
118
143
|
itemSize = 4;
|
144
|
+
|
119
145
|
itemDecode = function fontItemDecodeLong(data, offset) {
|
120
146
|
return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
|
121
147
|
};
|
122
148
|
} else {
|
123
149
|
itemSize = 2;
|
150
|
+
|
124
151
|
itemDecode = function fontItemDecode(data, offset) {
|
125
152
|
return data[offset] << 9 | data[offset + 1] << 1;
|
126
153
|
};
|
127
154
|
}
|
155
|
+
|
128
156
|
var glyphs = [];
|
129
157
|
var startOffset = itemDecode(loca, 0);
|
158
|
+
|
130
159
|
for (var j = itemSize; j < loca.length; j += itemSize) {
|
131
160
|
var endOffset = itemDecode(loca, j);
|
132
161
|
glyphs.push(glyf.subarray(startOffset, endOffset));
|
133
162
|
startOffset = endOffset;
|
134
163
|
}
|
164
|
+
|
135
165
|
return glyphs;
|
136
166
|
}
|
167
|
+
|
137
168
|
function lookupCmap(ranges, unicode) {
|
138
169
|
var code = unicode.codePointAt(0),
|
139
170
|
gid = 0;
|
140
171
|
var l = 0,
|
141
172
|
r = ranges.length - 1;
|
173
|
+
|
142
174
|
while (l < r) {
|
143
175
|
var c = l + r + 1 >> 1;
|
176
|
+
|
144
177
|
if (code < ranges[c].start) {
|
145
178
|
r = c - 1;
|
146
179
|
} else {
|
147
180
|
l = c;
|
148
181
|
}
|
149
182
|
}
|
183
|
+
|
150
184
|
if (ranges[l].start <= code && code <= ranges[l].end) {
|
151
|
-
gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) &
|
185
|
+
gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xffff;
|
152
186
|
}
|
187
|
+
|
153
188
|
return {
|
154
189
|
charCode: code,
|
155
190
|
glyphId: gid
|
156
191
|
};
|
157
192
|
}
|
193
|
+
|
158
194
|
function compileGlyf(code, cmds, font) {
|
159
195
|
function moveTo(x, y) {
|
160
196
|
cmds.push({
|
161
|
-
cmd:
|
197
|
+
cmd: "moveTo",
|
162
198
|
args: [x, y]
|
163
199
|
});
|
164
200
|
}
|
201
|
+
|
165
202
|
function lineTo(x, y) {
|
166
203
|
cmds.push({
|
167
|
-
cmd:
|
204
|
+
cmd: "lineTo",
|
168
205
|
args: [x, y]
|
169
206
|
});
|
170
207
|
}
|
208
|
+
|
171
209
|
function quadraticCurveTo(xa, ya, x, y) {
|
172
210
|
cmds.push({
|
173
|
-
cmd:
|
211
|
+
cmd: "quadraticCurveTo",
|
174
212
|
args: [xa, ya, x, y]
|
175
213
|
});
|
176
214
|
}
|
215
|
+
|
177
216
|
var i = 0;
|
178
217
|
var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
|
179
218
|
var flags;
|
180
219
|
var x = 0,
|
181
220
|
y = 0;
|
182
221
|
i += 10;
|
222
|
+
|
183
223
|
if (numberOfContours < 0) {
|
184
224
|
do {
|
185
225
|
flags = code[i] << 8 | code[i + 1];
|
186
226
|
var glyphIndex = code[i + 2] << 8 | code[i + 3];
|
187
227
|
i += 4;
|
188
228
|
var arg1, arg2;
|
229
|
+
|
189
230
|
if (flags & 0x01) {
|
190
231
|
arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
|
191
232
|
arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
|
@@ -194,6 +235,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
194
235
|
arg1 = code[i++];
|
195
236
|
arg2 = code[i++];
|
196
237
|
}
|
238
|
+
|
197
239
|
if (flags & 0x02) {
|
198
240
|
x = arg1;
|
199
241
|
y = arg2;
|
@@ -201,10 +243,12 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
201
243
|
x = 0;
|
202
244
|
y = 0;
|
203
245
|
}
|
246
|
+
|
204
247
|
var scaleX = 1,
|
205
248
|
scaleY = 1,
|
206
249
|
scale01 = 0,
|
207
250
|
scale10 = 0;
|
251
|
+
|
208
252
|
if (flags & 0x08) {
|
209
253
|
scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
|
210
254
|
i += 2;
|
@@ -219,72 +263,96 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
219
263
|
scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
|
220
264
|
i += 8;
|
221
265
|
}
|
266
|
+
|
222
267
|
var subglyph = font.glyphs[glyphIndex];
|
268
|
+
|
223
269
|
if (subglyph) {
|
224
|
-
cmds.push({ cmd: 'save' });
|
225
270
|
cmds.push({
|
226
|
-
cmd:
|
271
|
+
cmd: "save"
|
272
|
+
});
|
273
|
+
cmds.push({
|
274
|
+
cmd: "transform",
|
227
275
|
args: [scaleX, scale01, scale10, scaleY, x, y]
|
228
276
|
});
|
229
277
|
compileGlyf(subglyph, cmds, font);
|
230
|
-
cmds.push({
|
278
|
+
cmds.push({
|
279
|
+
cmd: "restore"
|
280
|
+
});
|
231
281
|
}
|
232
282
|
} while (flags & 0x20);
|
233
283
|
} else {
|
234
284
|
var endPtsOfContours = [];
|
235
285
|
var j, jj;
|
286
|
+
|
236
287
|
for (j = 0; j < numberOfContours; j++) {
|
237
288
|
endPtsOfContours.push(code[i] << 8 | code[i + 1]);
|
238
289
|
i += 2;
|
239
290
|
}
|
291
|
+
|
240
292
|
var instructionLength = code[i] << 8 | code[i + 1];
|
241
293
|
i += 2 + instructionLength;
|
242
294
|
var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
|
243
295
|
var points = [];
|
296
|
+
|
244
297
|
while (points.length < numberOfPoints) {
|
245
298
|
flags = code[i++];
|
246
299
|
var repeat = 1;
|
300
|
+
|
247
301
|
if (flags & 0x08) {
|
248
302
|
repeat += code[i++];
|
249
303
|
}
|
304
|
+
|
250
305
|
while (repeat-- > 0) {
|
251
|
-
points.push({
|
306
|
+
points.push({
|
307
|
+
flags
|
308
|
+
});
|
252
309
|
}
|
253
310
|
}
|
311
|
+
|
254
312
|
for (j = 0; j < numberOfPoints; j++) {
|
255
313
|
switch (points[j].flags & 0x12) {
|
256
314
|
case 0x00:
|
257
315
|
x += (code[i] << 24 | code[i + 1] << 16) >> 16;
|
258
316
|
i += 2;
|
259
317
|
break;
|
318
|
+
|
260
319
|
case 0x02:
|
261
320
|
x -= code[i++];
|
262
321
|
break;
|
322
|
+
|
263
323
|
case 0x12:
|
264
324
|
x += code[i++];
|
265
325
|
break;
|
266
326
|
}
|
327
|
+
|
267
328
|
points[j].x = x;
|
268
329
|
}
|
330
|
+
|
269
331
|
for (j = 0; j < numberOfPoints; j++) {
|
270
332
|
switch (points[j].flags & 0x24) {
|
271
333
|
case 0x00:
|
272
334
|
y += (code[i] << 24 | code[i + 1] << 16) >> 16;
|
273
335
|
i += 2;
|
274
336
|
break;
|
337
|
+
|
275
338
|
case 0x04:
|
276
339
|
y -= code[i++];
|
277
340
|
break;
|
341
|
+
|
278
342
|
case 0x24:
|
279
343
|
y += code[i++];
|
280
344
|
break;
|
281
345
|
}
|
346
|
+
|
282
347
|
points[j].y = y;
|
283
348
|
}
|
349
|
+
|
284
350
|
var startPoint = 0;
|
351
|
+
|
285
352
|
for (i = 0; i < numberOfContours; i++) {
|
286
353
|
var endPoint = endPtsOfContours[i];
|
287
354
|
var contour = points.slice(startPoint, endPoint + 1);
|
355
|
+
|
288
356
|
if (contour[0].flags & 1) {
|
289
357
|
contour.push(contour[0]);
|
290
358
|
} else if (contour[contour.length - 1].flags & 1) {
|
@@ -298,7 +366,9 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
298
366
|
contour.unshift(p);
|
299
367
|
contour.push(p);
|
300
368
|
}
|
369
|
+
|
301
370
|
moveTo(contour[0].x, contour[0].y);
|
371
|
+
|
302
372
|
for (j = 1, jj = contour.length; j < jj; j++) {
|
303
373
|
if (contour[j].flags & 1) {
|
304
374
|
lineTo(contour[j].x, contour[j].y);
|
@@ -309,82 +379,103 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
309
379
|
quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
|
310
380
|
}
|
311
381
|
}
|
382
|
+
|
312
383
|
startPoint = endPoint + 1;
|
313
384
|
}
|
314
385
|
}
|
315
386
|
}
|
387
|
+
|
316
388
|
function compileCharString(code, cmds, font, glyphId) {
|
317
389
|
var stack = [];
|
318
390
|
var x = 0,
|
319
391
|
y = 0;
|
320
392
|
var stems = 0;
|
393
|
+
|
321
394
|
function moveTo(x, y) {
|
322
395
|
cmds.push({
|
323
|
-
cmd:
|
396
|
+
cmd: "moveTo",
|
324
397
|
args: [x, y]
|
325
398
|
});
|
326
399
|
}
|
400
|
+
|
327
401
|
function lineTo(x, y) {
|
328
402
|
cmds.push({
|
329
|
-
cmd:
|
403
|
+
cmd: "lineTo",
|
330
404
|
args: [x, y]
|
331
405
|
});
|
332
406
|
}
|
407
|
+
|
333
408
|
function bezierCurveTo(x1, y1, x2, y2, x, y) {
|
334
409
|
cmds.push({
|
335
|
-
cmd:
|
410
|
+
cmd: "bezierCurveTo",
|
336
411
|
args: [x1, y1, x2, y2, x, y]
|
337
412
|
});
|
338
413
|
}
|
414
|
+
|
339
415
|
function parse(code) {
|
340
416
|
var i = 0;
|
417
|
+
|
341
418
|
while (i < code.length) {
|
342
419
|
var stackClean = false;
|
343
420
|
var v = code[i++];
|
344
421
|
var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
|
422
|
+
|
345
423
|
switch (v) {
|
346
424
|
case 1:
|
347
425
|
stems += stack.length >> 1;
|
348
426
|
stackClean = true;
|
349
427
|
break;
|
428
|
+
|
350
429
|
case 3:
|
351
430
|
stems += stack.length >> 1;
|
352
431
|
stackClean = true;
|
353
432
|
break;
|
433
|
+
|
354
434
|
case 4:
|
355
435
|
y += stack.pop();
|
356
436
|
moveTo(x, y);
|
357
437
|
stackClean = true;
|
358
438
|
break;
|
439
|
+
|
359
440
|
case 5:
|
360
441
|
while (stack.length > 0) {
|
361
442
|
x += stack.shift();
|
362
443
|
y += stack.shift();
|
363
444
|
lineTo(x, y);
|
364
445
|
}
|
446
|
+
|
365
447
|
break;
|
448
|
+
|
366
449
|
case 6:
|
367
450
|
while (stack.length > 0) {
|
368
451
|
x += stack.shift();
|
369
452
|
lineTo(x, y);
|
453
|
+
|
370
454
|
if (stack.length === 0) {
|
371
455
|
break;
|
372
456
|
}
|
457
|
+
|
373
458
|
y += stack.shift();
|
374
459
|
lineTo(x, y);
|
375
460
|
}
|
461
|
+
|
376
462
|
break;
|
463
|
+
|
377
464
|
case 7:
|
378
465
|
while (stack.length > 0) {
|
379
466
|
y += stack.shift();
|
380
467
|
lineTo(x, y);
|
468
|
+
|
381
469
|
if (stack.length === 0) {
|
382
470
|
break;
|
383
471
|
}
|
472
|
+
|
384
473
|
x += stack.shift();
|
385
474
|
lineTo(x, y);
|
386
475
|
}
|
476
|
+
|
387
477
|
break;
|
478
|
+
|
388
479
|
case 8:
|
389
480
|
while (stack.length > 0) {
|
390
481
|
xa = x + stack.shift();
|
@@ -395,37 +486,47 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
395
486
|
y = yb + stack.shift();
|
396
487
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
397
488
|
}
|
489
|
+
|
398
490
|
break;
|
491
|
+
|
399
492
|
case 10:
|
400
493
|
n = stack.pop();
|
401
494
|
subrCode = null;
|
495
|
+
|
402
496
|
if (font.isCFFCIDFont) {
|
403
|
-
|
497
|
+
const fdIndex = font.fdSelect.getFDIndex(glyphId);
|
498
|
+
|
404
499
|
if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
|
405
|
-
|
406
|
-
|
500
|
+
const fontDict = font.fdArray[fdIndex];
|
501
|
+
let subrs;
|
502
|
+
|
407
503
|
if (fontDict.privateDict && fontDict.privateDict.subrsIndex) {
|
408
504
|
subrs = fontDict.privateDict.subrsIndex.objects;
|
409
505
|
}
|
506
|
+
|
410
507
|
if (subrs) {
|
411
|
-
|
412
|
-
n += numSubrs < 1240 ? 107 : numSubrs < 33900 ? 1131 : 32768;
|
508
|
+
n += getSubroutineBias(subrs);
|
413
509
|
subrCode = subrs[n];
|
414
510
|
}
|
415
511
|
} else {
|
416
|
-
(0, _util.warn)(
|
512
|
+
(0, _util.warn)("Invalid fd index for glyph index.");
|
417
513
|
}
|
418
514
|
} else {
|
419
515
|
subrCode = font.subrs[n + font.subrsBias];
|
420
516
|
}
|
517
|
+
|
421
518
|
if (subrCode) {
|
422
519
|
parse(subrCode);
|
423
520
|
}
|
521
|
+
|
424
522
|
break;
|
523
|
+
|
425
524
|
case 11:
|
426
525
|
return;
|
526
|
+
|
427
527
|
case 12:
|
428
528
|
v = code[i++];
|
529
|
+
|
429
530
|
switch (v) {
|
430
531
|
case 34:
|
431
532
|
xa = x + stack.shift();
|
@@ -438,6 +539,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
438
539
|
x = xb + stack.shift();
|
439
540
|
bezierCurveTo(xa, y1, xb, y, x, y);
|
440
541
|
break;
|
542
|
+
|
441
543
|
case 35:
|
442
544
|
xa = x + stack.shift();
|
443
545
|
ya = y + stack.shift();
|
@@ -455,6 +557,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
455
557
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
456
558
|
stack.pop();
|
457
559
|
break;
|
560
|
+
|
458
561
|
case 36:
|
459
562
|
xa = x + stack.shift();
|
460
563
|
y1 = y + stack.shift();
|
@@ -468,6 +571,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
468
571
|
x = xb + stack.shift();
|
469
572
|
bezierCurveTo(xa, y2, xb, y3, x, y);
|
470
573
|
break;
|
574
|
+
|
471
575
|
case 37:
|
472
576
|
var x0 = x,
|
473
577
|
y0 = y;
|
@@ -484,64 +588,81 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
484
588
|
yb = ya + stack.shift();
|
485
589
|
x = xb;
|
486
590
|
y = yb;
|
591
|
+
|
487
592
|
if (Math.abs(x - x0) > Math.abs(y - y0)) {
|
488
593
|
x += stack.shift();
|
489
594
|
} else {
|
490
595
|
y += stack.shift();
|
491
596
|
}
|
597
|
+
|
492
598
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
493
599
|
break;
|
600
|
+
|
494
601
|
default:
|
495
|
-
throw new _util.FormatError(
|
602
|
+
throw new _util.FormatError(`unknown operator: 12 ${v}`);
|
496
603
|
}
|
604
|
+
|
497
605
|
break;
|
606
|
+
|
498
607
|
case 14:
|
499
608
|
if (stack.length >= 4) {
|
500
609
|
var achar = stack.pop();
|
501
610
|
var bchar = stack.pop();
|
502
611
|
y = stack.pop();
|
503
612
|
x = stack.pop();
|
504
|
-
cmds.push({ cmd: 'save' });
|
505
613
|
cmds.push({
|
506
|
-
cmd:
|
614
|
+
cmd: "save"
|
615
|
+
});
|
616
|
+
cmds.push({
|
617
|
+
cmd: "translate",
|
507
618
|
args: [x, y]
|
508
619
|
});
|
509
620
|
var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[_encodings.StandardEncoding[achar]]));
|
510
621
|
compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
|
511
|
-
cmds.push({
|
622
|
+
cmds.push({
|
623
|
+
cmd: "restore"
|
624
|
+
});
|
512
625
|
cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[_encodings.StandardEncoding[bchar]]));
|
513
626
|
compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
|
514
627
|
}
|
628
|
+
|
515
629
|
return;
|
630
|
+
|
516
631
|
case 18:
|
517
632
|
stems += stack.length >> 1;
|
518
633
|
stackClean = true;
|
519
634
|
break;
|
635
|
+
|
520
636
|
case 19:
|
521
637
|
stems += stack.length >> 1;
|
522
638
|
i += stems + 7 >> 3;
|
523
639
|
stackClean = true;
|
524
640
|
break;
|
641
|
+
|
525
642
|
case 20:
|
526
643
|
stems += stack.length >> 1;
|
527
644
|
i += stems + 7 >> 3;
|
528
645
|
stackClean = true;
|
529
646
|
break;
|
647
|
+
|
530
648
|
case 21:
|
531
649
|
y += stack.pop();
|
532
650
|
x += stack.pop();
|
533
651
|
moveTo(x, y);
|
534
652
|
stackClean = true;
|
535
653
|
break;
|
654
|
+
|
536
655
|
case 22:
|
537
656
|
x += stack.pop();
|
538
657
|
moveTo(x, y);
|
539
658
|
stackClean = true;
|
540
659
|
break;
|
660
|
+
|
541
661
|
case 23:
|
542
662
|
stems += stack.length >> 1;
|
543
663
|
stackClean = true;
|
544
664
|
break;
|
665
|
+
|
545
666
|
case 24:
|
546
667
|
while (stack.length > 2) {
|
547
668
|
xa = x + stack.shift();
|
@@ -552,16 +673,19 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
552
673
|
y = yb + stack.shift();
|
553
674
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
554
675
|
}
|
676
|
+
|
555
677
|
x += stack.shift();
|
556
678
|
y += stack.shift();
|
557
679
|
lineTo(x, y);
|
558
680
|
break;
|
681
|
+
|
559
682
|
case 25:
|
560
683
|
while (stack.length > 6) {
|
561
684
|
x += stack.shift();
|
562
685
|
y += stack.shift();
|
563
686
|
lineTo(x, y);
|
564
687
|
}
|
688
|
+
|
565
689
|
xa = x + stack.shift();
|
566
690
|
ya = y + stack.shift();
|
567
691
|
xb = xa + stack.shift();
|
@@ -570,10 +694,12 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
570
694
|
y = yb + stack.shift();
|
571
695
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
572
696
|
break;
|
697
|
+
|
573
698
|
case 26:
|
574
699
|
if (stack.length % 2) {
|
575
700
|
x += stack.shift();
|
576
701
|
}
|
702
|
+
|
577
703
|
while (stack.length > 0) {
|
578
704
|
xa = x;
|
579
705
|
ya = y + stack.shift();
|
@@ -583,11 +709,14 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
583
709
|
y = yb + stack.shift();
|
584
710
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
585
711
|
}
|
712
|
+
|
586
713
|
break;
|
714
|
+
|
587
715
|
case 27:
|
588
716
|
if (stack.length % 2) {
|
589
717
|
y += stack.shift();
|
590
718
|
}
|
719
|
+
|
591
720
|
while (stack.length > 0) {
|
592
721
|
xa = x + stack.shift();
|
593
722
|
ya = y;
|
@@ -597,18 +726,24 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
597
726
|
y = yb;
|
598
727
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
599
728
|
}
|
729
|
+
|
600
730
|
break;
|
731
|
+
|
601
732
|
case 28:
|
602
733
|
stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
|
603
734
|
i += 2;
|
604
735
|
break;
|
736
|
+
|
605
737
|
case 29:
|
606
738
|
n = stack.pop() + font.gsubrsBias;
|
607
739
|
subrCode = font.gsubrs[n];
|
740
|
+
|
608
741
|
if (subrCode) {
|
609
742
|
parse(subrCode);
|
610
743
|
}
|
744
|
+
|
611
745
|
break;
|
746
|
+
|
612
747
|
case 30:
|
613
748
|
while (stack.length > 0) {
|
614
749
|
xa = x;
|
@@ -618,9 +753,11 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
618
753
|
x = xb + stack.shift();
|
619
754
|
y = yb + (stack.length === 1 ? stack.shift() : 0);
|
620
755
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
756
|
+
|
621
757
|
if (stack.length === 0) {
|
622
758
|
break;
|
623
759
|
}
|
760
|
+
|
624
761
|
xa = x + stack.shift();
|
625
762
|
ya = y;
|
626
763
|
xb = xa + stack.shift();
|
@@ -629,7 +766,9 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
629
766
|
x = xb + (stack.length === 1 ? stack.shift() : 0);
|
630
767
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
631
768
|
}
|
769
|
+
|
632
770
|
break;
|
771
|
+
|
633
772
|
case 31:
|
634
773
|
while (stack.length > 0) {
|
635
774
|
xa = x + stack.shift();
|
@@ -639,9 +778,11 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
639
778
|
y = yb + stack.shift();
|
640
779
|
x = xb + (stack.length === 1 ? stack.shift() : 0);
|
641
780
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
781
|
+
|
642
782
|
if (stack.length === 0) {
|
643
783
|
break;
|
644
784
|
}
|
785
|
+
|
645
786
|
xa = x;
|
646
787
|
ya = y + stack.shift();
|
647
788
|
xb = xa + stack.shift();
|
@@ -650,11 +791,14 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
650
791
|
y = yb + (stack.length === 1 ? stack.shift() : 0);
|
651
792
|
bezierCurveTo(xa, ya, xb, yb, x, y);
|
652
793
|
}
|
794
|
+
|
653
795
|
break;
|
796
|
+
|
654
797
|
default:
|
655
798
|
if (v < 32) {
|
656
|
-
throw new _util.FormatError(
|
799
|
+
throw new _util.FormatError(`unknown operator: ${v}`);
|
657
800
|
}
|
801
|
+
|
658
802
|
if (v < 247) {
|
659
803
|
stack.push(v - 139);
|
660
804
|
} else if (v < 251) {
|
@@ -665,177 +809,173 @@ var FontRendererFactory = function FontRendererFactoryClosure() {
|
|
665
809
|
stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
|
666
810
|
i += 4;
|
667
811
|
}
|
812
|
+
|
668
813
|
break;
|
669
814
|
}
|
815
|
+
|
670
816
|
if (stackClean) {
|
671
817
|
stack.length = 0;
|
672
818
|
}
|
673
819
|
}
|
674
820
|
}
|
821
|
+
|
675
822
|
parse(code);
|
676
823
|
}
|
677
|
-
var NOOP = [];
|
678
824
|
|
679
|
-
|
680
|
-
function CompiledFont(fontMatrix) {
|
681
|
-
_classCallCheck(this, CompiledFont);
|
825
|
+
const NOOP = [];
|
682
826
|
|
827
|
+
class CompiledFont {
|
828
|
+
constructor(fontMatrix) {
|
683
829
|
if (this.constructor === CompiledFont) {
|
684
|
-
(0, _util.unreachable)(
|
830
|
+
(0, _util.unreachable)("Cannot initialize CompiledFont.");
|
685
831
|
}
|
832
|
+
|
686
833
|
this.fontMatrix = fontMatrix;
|
687
834
|
this.compiledGlyphs = Object.create(null);
|
688
835
|
this.compiledCharCodeToGlyphId = Object.create(null);
|
689
836
|
}
|
690
837
|
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
this.compiledGlyphs[cmap.glyphId] = fn;
|
699
|
-
}
|
700
|
-
if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
|
701
|
-
this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
|
702
|
-
}
|
703
|
-
return fn;
|
838
|
+
getPathJs(unicode) {
|
839
|
+
const cmap = lookupCmap(this.cmap, unicode);
|
840
|
+
let fn = this.compiledGlyphs[cmap.glyphId];
|
841
|
+
|
842
|
+
if (!fn) {
|
843
|
+
fn = this.compileGlyph(this.glyphs[cmap.glyphId], cmap.glyphId);
|
844
|
+
this.compiledGlyphs[cmap.glyphId] = fn;
|
704
845
|
}
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
if (!code || code.length === 0 || code[0] === 14) {
|
709
|
-
return NOOP;
|
710
|
-
}
|
711
|
-
var fontMatrix = this.fontMatrix;
|
712
|
-
if (this.isCFFCIDFont) {
|
713
|
-
var fdIndex = this.fdSelect.getFDIndex(glyphId);
|
714
|
-
if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
|
715
|
-
var fontDict = this.fdArray[fdIndex];
|
716
|
-
fontMatrix = fontDict.getByName('FontMatrix') || _util.FONT_IDENTITY_MATRIX;
|
717
|
-
} else {
|
718
|
-
(0, _util.warn)('Invalid fd index for glyph index.');
|
719
|
-
}
|
720
|
-
}
|
721
|
-
var cmds = [];
|
722
|
-
cmds.push({ cmd: 'save' });
|
723
|
-
cmds.push({
|
724
|
-
cmd: 'transform',
|
725
|
-
args: fontMatrix.slice()
|
726
|
-
});
|
727
|
-
cmds.push({
|
728
|
-
cmd: 'scale',
|
729
|
-
args: ['size', '-size']
|
730
|
-
});
|
731
|
-
this.compileGlyphImpl(code, cmds, glyphId);
|
732
|
-
cmds.push({ cmd: 'restore' });
|
733
|
-
return cmds;
|
846
|
+
|
847
|
+
if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
|
848
|
+
this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
|
734
849
|
}
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
850
|
+
|
851
|
+
return fn;
|
852
|
+
}
|
853
|
+
|
854
|
+
compileGlyph(code, glyphId) {
|
855
|
+
if (!code || code.length === 0 || code[0] === 14) {
|
856
|
+
return NOOP;
|
739
857
|
}
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
858
|
+
|
859
|
+
let fontMatrix = this.fontMatrix;
|
860
|
+
|
861
|
+
if (this.isCFFCIDFont) {
|
862
|
+
const fdIndex = this.fdSelect.getFDIndex(glyphId);
|
863
|
+
|
864
|
+
if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
|
865
|
+
const fontDict = this.fdArray[fdIndex];
|
866
|
+
fontMatrix = fontDict.getByName("FontMatrix") || _util.FONT_IDENTITY_MATRIX;
|
867
|
+
} else {
|
868
|
+
(0, _util.warn)("Invalid fd index for glyph index.");
|
869
|
+
}
|
745
870
|
}
|
746
|
-
}]);
|
747
871
|
|
748
|
-
|
749
|
-
|
872
|
+
const cmds = [];
|
873
|
+
cmds.push({
|
874
|
+
cmd: "save"
|
875
|
+
});
|
876
|
+
cmds.push({
|
877
|
+
cmd: "transform",
|
878
|
+
args: fontMatrix.slice()
|
879
|
+
});
|
880
|
+
cmds.push({
|
881
|
+
cmd: "scale",
|
882
|
+
args: ["size", "-size"]
|
883
|
+
});
|
884
|
+
this.compileGlyphImpl(code, cmds, glyphId);
|
885
|
+
cmds.push({
|
886
|
+
cmd: "restore"
|
887
|
+
});
|
888
|
+
return cmds;
|
889
|
+
}
|
750
890
|
|
751
|
-
|
752
|
-
|
891
|
+
compileGlyphImpl() {
|
892
|
+
(0, _util.unreachable)("Children classes should implement this.");
|
893
|
+
}
|
753
894
|
|
754
|
-
|
755
|
-
|
895
|
+
hasBuiltPath(unicode) {
|
896
|
+
const cmap = lookupCmap(this.cmap, unicode);
|
897
|
+
return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
|
898
|
+
}
|
756
899
|
|
757
|
-
|
900
|
+
}
|
758
901
|
|
759
|
-
|
760
|
-
|
761
|
-
|
902
|
+
class TrueTypeCompiled extends CompiledFont {
|
903
|
+
constructor(glyphs, cmap, fontMatrix) {
|
904
|
+
super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
|
905
|
+
this.glyphs = glyphs;
|
906
|
+
this.cmap = cmap;
|
762
907
|
}
|
763
908
|
|
764
|
-
|
765
|
-
|
766
|
-
value: function compileGlyphImpl(code, cmds) {
|
767
|
-
compileGlyf(code, cmds, this);
|
768
|
-
}
|
769
|
-
}]);
|
770
|
-
|
771
|
-
return TrueTypeCompiled;
|
772
|
-
}(CompiledFont);
|
773
|
-
|
774
|
-
var Type2Compiled = function (_CompiledFont2) {
|
775
|
-
_inherits(Type2Compiled, _CompiledFont2);
|
776
|
-
|
777
|
-
function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
778
|
-
_classCallCheck(this, Type2Compiled);
|
779
|
-
|
780
|
-
var _this2 = _possibleConstructorReturn(this, (Type2Compiled.__proto__ || Object.getPrototypeOf(Type2Compiled)).call(this, fontMatrix || [0.001, 0, 0, 0.001, 0, 0]));
|
781
|
-
|
782
|
-
_this2.glyphs = cffInfo.glyphs;
|
783
|
-
_this2.gsubrs = cffInfo.gsubrs || [];
|
784
|
-
_this2.subrs = cffInfo.subrs || [];
|
785
|
-
_this2.cmap = cmap;
|
786
|
-
_this2.glyphNameMap = glyphNameMap || (0, _glyphlist.getGlyphsUnicode)();
|
787
|
-
_this2.gsubrsBias = _this2.gsubrs.length < 1240 ? 107 : _this2.gsubrs.length < 33900 ? 1131 : 32768;
|
788
|
-
_this2.subrsBias = _this2.subrs.length < 1240 ? 107 : _this2.subrs.length < 33900 ? 1131 : 32768;
|
789
|
-
_this2.isCFFCIDFont = cffInfo.isCFFCIDFont;
|
790
|
-
_this2.fdSelect = cffInfo.fdSelect;
|
791
|
-
_this2.fdArray = cffInfo.fdArray;
|
792
|
-
return _this2;
|
909
|
+
compileGlyphImpl(code, cmds) {
|
910
|
+
compileGlyf(code, cmds, this);
|
793
911
|
}
|
794
912
|
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
913
|
+
}
|
914
|
+
|
915
|
+
class Type2Compiled extends CompiledFont {
|
916
|
+
constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
917
|
+
super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
|
918
|
+
this.glyphs = cffInfo.glyphs;
|
919
|
+
this.gsubrs = cffInfo.gsubrs || [];
|
920
|
+
this.subrs = cffInfo.subrs || [];
|
921
|
+
this.cmap = cmap;
|
922
|
+
this.glyphNameMap = glyphNameMap || (0, _glyphlist.getGlyphsUnicode)();
|
923
|
+
this.gsubrsBias = getSubroutineBias(this.gsubrs);
|
924
|
+
this.subrsBias = getSubroutineBias(this.subrs);
|
925
|
+
this.isCFFCIDFont = cffInfo.isCFFCIDFont;
|
926
|
+
this.fdSelect = cffInfo.fdSelect;
|
927
|
+
this.fdArray = cffInfo.fdArray;
|
928
|
+
}
|
801
929
|
|
802
|
-
|
803
|
-
|
930
|
+
compileGlyphImpl(code, cmds, glyphId) {
|
931
|
+
compileCharString(code, cmds, this, glyphId);
|
932
|
+
}
|
933
|
+
|
934
|
+
}
|
804
935
|
|
805
936
|
return {
|
806
937
|
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
807
938
|
var data = new Uint8Array(font.data);
|
808
939
|
var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
809
940
|
var numTables = getUshort(data, 4);
|
941
|
+
|
810
942
|
for (var i = 0, p = 12; i < numTables; i++, p += 16) {
|
811
943
|
var tag = (0, _util.bytesToString)(data.subarray(p, p + 4));
|
812
944
|
var offset = getLong(data, p + 8);
|
813
945
|
var length = getLong(data, p + 12);
|
946
|
+
|
814
947
|
switch (tag) {
|
815
|
-
case
|
948
|
+
case "cmap":
|
816
949
|
cmap = parseCmap(data, offset, offset + length);
|
817
950
|
break;
|
818
|
-
|
951
|
+
|
952
|
+
case "glyf":
|
819
953
|
glyf = data.subarray(offset, offset + length);
|
820
954
|
break;
|
821
|
-
|
955
|
+
|
956
|
+
case "loca":
|
822
957
|
loca = data.subarray(offset, offset + length);
|
823
958
|
break;
|
824
|
-
|
959
|
+
|
960
|
+
case "head":
|
825
961
|
unitsPerEm = getUshort(data, offset + 18);
|
826
962
|
indexToLocFormat = getUshort(data, offset + 50);
|
827
963
|
break;
|
828
|
-
|
964
|
+
|
965
|
+
case "CFF ":
|
829
966
|
cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
|
830
967
|
break;
|
831
968
|
}
|
832
969
|
}
|
970
|
+
|
833
971
|
if (glyf) {
|
834
972
|
var fontMatrix = !unitsPerEm ? font.fontMatrix : [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
|
835
973
|
return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
|
836
974
|
}
|
975
|
+
|
837
976
|
return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
|
838
977
|
}
|
839
978
|
};
|
840
979
|
}();
|
980
|
+
|
841
981
|
exports.FontRendererFactory = FontRendererFactory;
|