@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 1.0.0
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.
- package/README.md +1 -1
- package/package.json +42 -26
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +98 -46
- package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
package/src/core/type1_parser.js
DELETED
|
@@ -1,776 +0,0 @@
|
|
|
1
|
-
/* Copyright 2012 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { getEncoding } from "./encodings.js";
|
|
17
|
-
import { isWhiteSpace } from "./core_utils.js";
|
|
18
|
-
import { Stream } from "./stream.js";
|
|
19
|
-
import { warn } from "../shared/util.js";
|
|
20
|
-
|
|
21
|
-
// Hinting is currently disabled due to unknown problems on windows
|
|
22
|
-
// in tracemonkey and various other pdfs with type1 fonts.
|
|
23
|
-
const HINTING_ENABLED = false;
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
* CharStrings are encoded following the the CharString Encoding sequence
|
|
27
|
-
* describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
|
|
28
|
-
* The value in a byte indicates a command, a number, or subsequent bytes
|
|
29
|
-
* that are to be interpreted in a special way.
|
|
30
|
-
*
|
|
31
|
-
* CharString Number Encoding:
|
|
32
|
-
* A CharString byte containing the values from 32 through 255 inclusive
|
|
33
|
-
* indicate an integer. These values are decoded in four ranges.
|
|
34
|
-
*
|
|
35
|
-
* 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
|
|
36
|
-
* indicate the integer v - 139. Thus, the integer values from -107 through
|
|
37
|
-
* 107 inclusive may be encoded in single byte.
|
|
38
|
-
*
|
|
39
|
-
* 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
|
|
40
|
-
* indicates an integer involving the next byte, w, according to the formula:
|
|
41
|
-
* [(v - 247) x 256] + w + 108
|
|
42
|
-
*
|
|
43
|
-
* 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
|
|
44
|
-
* indicates an integer involving the next byte, w, according to the formula:
|
|
45
|
-
* -[(v - 251) * 256] - w - 108
|
|
46
|
-
*
|
|
47
|
-
* 4. A CharString containing the value 255 indicates that the next 4 bytes
|
|
48
|
-
* are a two complement signed integer. The first of these bytes contains the
|
|
49
|
-
* highest order bits, the second byte contains the next higher order bits
|
|
50
|
-
* and the fourth byte contain the lowest order bits.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* CharString Command Encoding:
|
|
54
|
-
* CharStrings commands are encoded in 1 or 2 bytes.
|
|
55
|
-
*
|
|
56
|
-
* Single byte commands are encoded in 1 byte that contains a value between
|
|
57
|
-
* 0 and 31 inclusive.
|
|
58
|
-
* If a command byte contains the value 12, then the value in the next byte
|
|
59
|
-
* indicates a command. This "escape" mechanism allows many extra commands
|
|
60
|
-
* to be encoded and this encoding technique helps to minimize the length of
|
|
61
|
-
* the charStrings.
|
|
62
|
-
*/
|
|
63
|
-
const Type1CharString = (function Type1CharStringClosure() {
|
|
64
|
-
const COMMAND_MAP = {
|
|
65
|
-
hstem: [1],
|
|
66
|
-
vstem: [3],
|
|
67
|
-
vmoveto: [4],
|
|
68
|
-
rlineto: [5],
|
|
69
|
-
hlineto: [6],
|
|
70
|
-
vlineto: [7],
|
|
71
|
-
rrcurveto: [8],
|
|
72
|
-
callsubr: [10],
|
|
73
|
-
flex: [12, 35],
|
|
74
|
-
drop: [12, 18],
|
|
75
|
-
endchar: [14],
|
|
76
|
-
rmoveto: [21],
|
|
77
|
-
hmoveto: [22],
|
|
78
|
-
vhcurveto: [30],
|
|
79
|
-
hvcurveto: [31],
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// eslint-disable-next-line no-shadow
|
|
83
|
-
class Type1CharString {
|
|
84
|
-
constructor() {
|
|
85
|
-
this.width = 0;
|
|
86
|
-
this.lsb = 0;
|
|
87
|
-
this.flexing = false;
|
|
88
|
-
this.output = [];
|
|
89
|
-
this.stack = [];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
convert(encoded, subrs, seacAnalysisEnabled) {
|
|
93
|
-
const count = encoded.length;
|
|
94
|
-
let error = false;
|
|
95
|
-
let wx, sbx, subrNumber;
|
|
96
|
-
for (let i = 0; i < count; i++) {
|
|
97
|
-
let value = encoded[i];
|
|
98
|
-
if (value < 32) {
|
|
99
|
-
if (value === 12) {
|
|
100
|
-
value = (value << 8) + encoded[++i];
|
|
101
|
-
}
|
|
102
|
-
switch (value) {
|
|
103
|
-
case 1: // hstem
|
|
104
|
-
if (!HINTING_ENABLED) {
|
|
105
|
-
this.stack = [];
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
error = this.executeCommand(2, COMMAND_MAP.hstem);
|
|
109
|
-
break;
|
|
110
|
-
case 3: // vstem
|
|
111
|
-
if (!HINTING_ENABLED) {
|
|
112
|
-
this.stack = [];
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
error = this.executeCommand(2, COMMAND_MAP.vstem);
|
|
116
|
-
break;
|
|
117
|
-
case 4: // vmoveto
|
|
118
|
-
if (this.flexing) {
|
|
119
|
-
if (this.stack.length < 1) {
|
|
120
|
-
error = true;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
// Add the dx for flex and but also swap the values so they are
|
|
124
|
-
// the right order.
|
|
125
|
-
const dy = this.stack.pop();
|
|
126
|
-
this.stack.push(0, dy);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
error = this.executeCommand(1, COMMAND_MAP.vmoveto);
|
|
130
|
-
break;
|
|
131
|
-
case 5: // rlineto
|
|
132
|
-
error = this.executeCommand(2, COMMAND_MAP.rlineto);
|
|
133
|
-
break;
|
|
134
|
-
case 6: // hlineto
|
|
135
|
-
error = this.executeCommand(1, COMMAND_MAP.hlineto);
|
|
136
|
-
break;
|
|
137
|
-
case 7: // vlineto
|
|
138
|
-
error = this.executeCommand(1, COMMAND_MAP.vlineto);
|
|
139
|
-
break;
|
|
140
|
-
case 8: // rrcurveto
|
|
141
|
-
error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
|
|
142
|
-
break;
|
|
143
|
-
case 9: // closepath
|
|
144
|
-
// closepath is a Type1 command that does not take argument and is
|
|
145
|
-
// useless in Type2 and it can simply be ignored.
|
|
146
|
-
this.stack = [];
|
|
147
|
-
break;
|
|
148
|
-
case 10: // callsubr
|
|
149
|
-
if (this.stack.length < 1) {
|
|
150
|
-
error = true;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
subrNumber = this.stack.pop();
|
|
154
|
-
if (!subrs[subrNumber]) {
|
|
155
|
-
error = true;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
error = this.convert(
|
|
159
|
-
subrs[subrNumber],
|
|
160
|
-
subrs,
|
|
161
|
-
seacAnalysisEnabled
|
|
162
|
-
);
|
|
163
|
-
break;
|
|
164
|
-
case 11: // return
|
|
165
|
-
return error;
|
|
166
|
-
case 13: // hsbw
|
|
167
|
-
if (this.stack.length < 2) {
|
|
168
|
-
error = true;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
// To convert to type2 we have to move the width value to the
|
|
172
|
-
// first part of the charstring and then use hmoveto with lsb.
|
|
173
|
-
wx = this.stack.pop();
|
|
174
|
-
sbx = this.stack.pop();
|
|
175
|
-
this.lsb = sbx;
|
|
176
|
-
this.width = wx;
|
|
177
|
-
this.stack.push(wx, sbx);
|
|
178
|
-
error = this.executeCommand(2, COMMAND_MAP.hmoveto);
|
|
179
|
-
break;
|
|
180
|
-
case 14: // endchar
|
|
181
|
-
this.output.push(COMMAND_MAP.endchar[0]);
|
|
182
|
-
break;
|
|
183
|
-
case 21: // rmoveto
|
|
184
|
-
if (this.flexing) {
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
error = this.executeCommand(2, COMMAND_MAP.rmoveto);
|
|
188
|
-
break;
|
|
189
|
-
case 22: // hmoveto
|
|
190
|
-
if (this.flexing) {
|
|
191
|
-
// Add the dy for flex.
|
|
192
|
-
this.stack.push(0);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
error = this.executeCommand(1, COMMAND_MAP.hmoveto);
|
|
196
|
-
break;
|
|
197
|
-
case 30: // vhcurveto
|
|
198
|
-
error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
|
|
199
|
-
break;
|
|
200
|
-
case 31: // hvcurveto
|
|
201
|
-
error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
|
|
202
|
-
break;
|
|
203
|
-
case (12 << 8) + 0: // dotsection
|
|
204
|
-
// dotsection is a Type1 command to specify some hinting feature
|
|
205
|
-
// for dots that do not take a parameter and it can safely be
|
|
206
|
-
// ignored for Type2.
|
|
207
|
-
this.stack = [];
|
|
208
|
-
break;
|
|
209
|
-
case (12 << 8) + 1: // vstem3
|
|
210
|
-
if (!HINTING_ENABLED) {
|
|
211
|
-
this.stack = [];
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
// [vh]stem3 are Type1 only and Type2 supports [vh]stem with
|
|
215
|
-
// multiple parameters, so instead of returning [vh]stem3 take a
|
|
216
|
-
// shortcut and return [vhstem] instead.
|
|
217
|
-
error = this.executeCommand(2, COMMAND_MAP.vstem);
|
|
218
|
-
break;
|
|
219
|
-
case (12 << 8) + 2: // hstem3
|
|
220
|
-
if (!HINTING_ENABLED) {
|
|
221
|
-
this.stack = [];
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
// See vstem3.
|
|
225
|
-
error = this.executeCommand(2, COMMAND_MAP.hstem);
|
|
226
|
-
break;
|
|
227
|
-
case (12 << 8) + 6: // seac
|
|
228
|
-
// seac is like type 2's special endchar but it doesn't use the
|
|
229
|
-
// first argument asb, so remove it.
|
|
230
|
-
if (seacAnalysisEnabled) {
|
|
231
|
-
const asb = this.stack[this.stack.length - 5];
|
|
232
|
-
this.seac = this.stack.splice(-4, 4);
|
|
233
|
-
this.seac[0] += this.lsb - asb;
|
|
234
|
-
error = this.executeCommand(0, COMMAND_MAP.endchar);
|
|
235
|
-
} else {
|
|
236
|
-
error = this.executeCommand(4, COMMAND_MAP.endchar);
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
|
-
case (12 << 8) + 7: // sbw
|
|
240
|
-
if (this.stack.length < 4) {
|
|
241
|
-
error = true;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
// To convert to type2 we have to move the width value to the
|
|
245
|
-
// first part of the charstring and then use rmoveto with
|
|
246
|
-
// (dx, dy). The height argument will not be used for vmtx and
|
|
247
|
-
// vhea tables reconstruction -- ignoring it.
|
|
248
|
-
this.stack.pop(); // wy
|
|
249
|
-
wx = this.stack.pop();
|
|
250
|
-
const sby = this.stack.pop();
|
|
251
|
-
sbx = this.stack.pop();
|
|
252
|
-
this.lsb = sbx;
|
|
253
|
-
this.width = wx;
|
|
254
|
-
this.stack.push(wx, sbx, sby);
|
|
255
|
-
error = this.executeCommand(3, COMMAND_MAP.rmoveto);
|
|
256
|
-
break;
|
|
257
|
-
case (12 << 8) + 12: // div
|
|
258
|
-
if (this.stack.length < 2) {
|
|
259
|
-
error = true;
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
const num2 = this.stack.pop();
|
|
263
|
-
const num1 = this.stack.pop();
|
|
264
|
-
this.stack.push(num1 / num2);
|
|
265
|
-
break;
|
|
266
|
-
case (12 << 8) + 16: // callothersubr
|
|
267
|
-
if (this.stack.length < 2) {
|
|
268
|
-
error = true;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
subrNumber = this.stack.pop();
|
|
272
|
-
const numArgs = this.stack.pop();
|
|
273
|
-
if (subrNumber === 0 && numArgs === 3) {
|
|
274
|
-
const flexArgs = this.stack.splice(this.stack.length - 17, 17);
|
|
275
|
-
this.stack.push(
|
|
276
|
-
flexArgs[2] + flexArgs[0], // bcp1x + rpx
|
|
277
|
-
flexArgs[3] + flexArgs[1], // bcp1y + rpy
|
|
278
|
-
flexArgs[4], // bcp2x
|
|
279
|
-
flexArgs[5], // bcp2y
|
|
280
|
-
flexArgs[6], // p2x
|
|
281
|
-
flexArgs[7], // p2y
|
|
282
|
-
flexArgs[8], // bcp3x
|
|
283
|
-
flexArgs[9], // bcp3y
|
|
284
|
-
flexArgs[10], // bcp4x
|
|
285
|
-
flexArgs[11], // bcp4y
|
|
286
|
-
flexArgs[12], // p3x
|
|
287
|
-
flexArgs[13], // p3y
|
|
288
|
-
flexArgs[14] // flexDepth
|
|
289
|
-
// 15 = finalx unused by flex
|
|
290
|
-
// 16 = finaly unused by flex
|
|
291
|
-
);
|
|
292
|
-
error = this.executeCommand(13, COMMAND_MAP.flex, true);
|
|
293
|
-
this.flexing = false;
|
|
294
|
-
this.stack.push(flexArgs[15], flexArgs[16]);
|
|
295
|
-
} else if (subrNumber === 1 && numArgs === 0) {
|
|
296
|
-
this.flexing = true;
|
|
297
|
-
}
|
|
298
|
-
break;
|
|
299
|
-
case (12 << 8) + 17: // pop
|
|
300
|
-
// Ignore this since it is only used with othersubr.
|
|
301
|
-
break;
|
|
302
|
-
case (12 << 8) + 33: // setcurrentpoint
|
|
303
|
-
// Ignore for now.
|
|
304
|
-
this.stack = [];
|
|
305
|
-
break;
|
|
306
|
-
default:
|
|
307
|
-
warn('Unknown type 1 charstring command of "' + value + '"');
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
if (error) {
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
continue;
|
|
314
|
-
} else if (value <= 246) {
|
|
315
|
-
value -= 139;
|
|
316
|
-
} else if (value <= 250) {
|
|
317
|
-
value = (value - 247) * 256 + encoded[++i] + 108;
|
|
318
|
-
} else if (value <= 254) {
|
|
319
|
-
value = -((value - 251) * 256) - encoded[++i] - 108;
|
|
320
|
-
} else {
|
|
321
|
-
value =
|
|
322
|
-
((encoded[++i] & 0xff) << 24) |
|
|
323
|
-
((encoded[++i] & 0xff) << 16) |
|
|
324
|
-
((encoded[++i] & 0xff) << 8) |
|
|
325
|
-
((encoded[++i] & 0xff) << 0);
|
|
326
|
-
}
|
|
327
|
-
this.stack.push(value);
|
|
328
|
-
}
|
|
329
|
-
return error;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
executeCommand(howManyArgs, command, keepStack) {
|
|
333
|
-
const stackLength = this.stack.length;
|
|
334
|
-
if (howManyArgs > stackLength) {
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
const start = stackLength - howManyArgs;
|
|
338
|
-
for (let i = start; i < stackLength; i++) {
|
|
339
|
-
let value = this.stack[i];
|
|
340
|
-
if (Number.isInteger(value)) {
|
|
341
|
-
this.output.push(28, (value >> 8) & 0xff, value & 0xff);
|
|
342
|
-
} else {
|
|
343
|
-
// fixed point
|
|
344
|
-
value = (65536 * value) | 0;
|
|
345
|
-
this.output.push(
|
|
346
|
-
255,
|
|
347
|
-
(value >> 24) & 0xff,
|
|
348
|
-
(value >> 16) & 0xff,
|
|
349
|
-
(value >> 8) & 0xff,
|
|
350
|
-
value & 0xff
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
this.output.push.apply(this.output, command);
|
|
355
|
-
if (keepStack) {
|
|
356
|
-
this.stack.splice(start, howManyArgs);
|
|
357
|
-
} else {
|
|
358
|
-
this.stack.length = 0;
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return Type1CharString;
|
|
365
|
-
})();
|
|
366
|
-
|
|
367
|
-
/*
|
|
368
|
-
* Type1Parser encapsulate the needed code for parsing a Type1 font
|
|
369
|
-
* program. Some of its logic depends on the Type2 charstrings
|
|
370
|
-
* structure.
|
|
371
|
-
* Note: this doesn't really parse the font since that would require evaluation
|
|
372
|
-
* of PostScript, but it is possible in most cases to extract what we need
|
|
373
|
-
* without a full parse.
|
|
374
|
-
*/
|
|
375
|
-
const Type1Parser = (function Type1ParserClosure() {
|
|
376
|
-
/*
|
|
377
|
-
* Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
|
|
378
|
-
* of Plaintext Bytes. The function took a key as a parameter which can be
|
|
379
|
-
* for decrypting the eexec block of for decoding charStrings.
|
|
380
|
-
*/
|
|
381
|
-
const EEXEC_ENCRYPT_KEY = 55665;
|
|
382
|
-
const CHAR_STRS_ENCRYPT_KEY = 4330;
|
|
383
|
-
|
|
384
|
-
function isHexDigit(code) {
|
|
385
|
-
return (
|
|
386
|
-
(code >= 48 && code <= 57) || // '0'-'9'
|
|
387
|
-
(code >= 65 && code <= 70) || // 'A'-'F'
|
|
388
|
-
(code >= 97 && code <= 102) // 'a'-'f'
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function decrypt(data, key, discardNumber) {
|
|
393
|
-
if (discardNumber >= data.length) {
|
|
394
|
-
return new Uint8Array(0);
|
|
395
|
-
}
|
|
396
|
-
const c1 = 52845,
|
|
397
|
-
c2 = 22719;
|
|
398
|
-
let r = key | 0,
|
|
399
|
-
i,
|
|
400
|
-
j;
|
|
401
|
-
for (i = 0; i < discardNumber; i++) {
|
|
402
|
-
r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
|
|
403
|
-
}
|
|
404
|
-
const count = data.length - discardNumber;
|
|
405
|
-
const decrypted = new Uint8Array(count);
|
|
406
|
-
for (i = discardNumber, j = 0; j < count; i++, j++) {
|
|
407
|
-
const value = data[i];
|
|
408
|
-
decrypted[j] = value ^ (r >> 8);
|
|
409
|
-
r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
|
|
410
|
-
}
|
|
411
|
-
return decrypted;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function decryptAscii(data, key, discardNumber) {
|
|
415
|
-
const c1 = 52845,
|
|
416
|
-
c2 = 22719;
|
|
417
|
-
let r = key | 0;
|
|
418
|
-
const count = data.length,
|
|
419
|
-
maybeLength = count >>> 1;
|
|
420
|
-
const decrypted = new Uint8Array(maybeLength);
|
|
421
|
-
let i, j;
|
|
422
|
-
for (i = 0, j = 0; i < count; i++) {
|
|
423
|
-
const digit1 = data[i];
|
|
424
|
-
if (!isHexDigit(digit1)) {
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
i++;
|
|
428
|
-
let digit2;
|
|
429
|
-
while (i < count && !isHexDigit((digit2 = data[i]))) {
|
|
430
|
-
i++;
|
|
431
|
-
}
|
|
432
|
-
if (i < count) {
|
|
433
|
-
const value = parseInt(String.fromCharCode(digit1, digit2), 16);
|
|
434
|
-
decrypted[j++] = value ^ (r >> 8);
|
|
435
|
-
r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return decrypted.slice(discardNumber, j);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function isSpecial(c) {
|
|
442
|
-
return (
|
|
443
|
-
c === /* '/' = */ 0x2f ||
|
|
444
|
-
c === /* '[' = */ 0x5b ||
|
|
445
|
-
c === /* ']' = */ 0x5d ||
|
|
446
|
-
c === /* '{' = */ 0x7b ||
|
|
447
|
-
c === /* '}' = */ 0x7d ||
|
|
448
|
-
c === /* '(' = */ 0x28 ||
|
|
449
|
-
c === /* ')' = */ 0x29
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// eslint-disable-next-line no-shadow
|
|
454
|
-
class Type1Parser {
|
|
455
|
-
constructor(stream, encrypted, seacAnalysisEnabled) {
|
|
456
|
-
if (encrypted) {
|
|
457
|
-
const data = stream.getBytes();
|
|
458
|
-
const isBinary = !(
|
|
459
|
-
(isHexDigit(data[0]) || isWhiteSpace(data[0])) &&
|
|
460
|
-
isHexDigit(data[1]) &&
|
|
461
|
-
isHexDigit(data[2]) &&
|
|
462
|
-
isHexDigit(data[3]) &&
|
|
463
|
-
isHexDigit(data[4]) &&
|
|
464
|
-
isHexDigit(data[5]) &&
|
|
465
|
-
isHexDigit(data[6]) &&
|
|
466
|
-
isHexDigit(data[7])
|
|
467
|
-
);
|
|
468
|
-
stream = new Stream(
|
|
469
|
-
isBinary
|
|
470
|
-
? decrypt(data, EEXEC_ENCRYPT_KEY, 4)
|
|
471
|
-
: decryptAscii(data, EEXEC_ENCRYPT_KEY, 4)
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
this.seacAnalysisEnabled = !!seacAnalysisEnabled;
|
|
475
|
-
|
|
476
|
-
this.stream = stream;
|
|
477
|
-
this.nextChar();
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
readNumberArray() {
|
|
481
|
-
this.getToken(); // read '[' or '{' (arrays can start with either)
|
|
482
|
-
const array = [];
|
|
483
|
-
while (true) {
|
|
484
|
-
const token = this.getToken();
|
|
485
|
-
if (token === null || token === "]" || token === "}") {
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
array.push(parseFloat(token || 0));
|
|
489
|
-
}
|
|
490
|
-
return array;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
readNumber() {
|
|
494
|
-
const token = this.getToken();
|
|
495
|
-
return parseFloat(token || 0);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
readInt() {
|
|
499
|
-
// Use '| 0' to prevent setting a double into length such as the double
|
|
500
|
-
// does not flow into the loop variable.
|
|
501
|
-
const token = this.getToken();
|
|
502
|
-
return parseInt(token || 0, 10) | 0;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
readBoolean() {
|
|
506
|
-
const token = this.getToken();
|
|
507
|
-
// Use 1 and 0 since that's what type2 charstrings use.
|
|
508
|
-
return token === "true" ? 1 : 0;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
nextChar() {
|
|
512
|
-
return (this.currentChar = this.stream.getByte());
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
getToken() {
|
|
516
|
-
// Eat whitespace and comments.
|
|
517
|
-
let comment = false;
|
|
518
|
-
let ch = this.currentChar;
|
|
519
|
-
while (true) {
|
|
520
|
-
if (ch === -1) {
|
|
521
|
-
return null;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
if (comment) {
|
|
525
|
-
if (ch === 0x0a || ch === 0x0d) {
|
|
526
|
-
comment = false;
|
|
527
|
-
}
|
|
528
|
-
} else if (ch === /* '%' = */ 0x25) {
|
|
529
|
-
comment = true;
|
|
530
|
-
} else if (!isWhiteSpace(ch)) {
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
ch = this.nextChar();
|
|
534
|
-
}
|
|
535
|
-
if (isSpecial(ch)) {
|
|
536
|
-
this.nextChar();
|
|
537
|
-
return String.fromCharCode(ch);
|
|
538
|
-
}
|
|
539
|
-
let token = "";
|
|
540
|
-
do {
|
|
541
|
-
token += String.fromCharCode(ch);
|
|
542
|
-
ch = this.nextChar();
|
|
543
|
-
} while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch));
|
|
544
|
-
return token;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
readCharStrings(bytes, lenIV) {
|
|
548
|
-
if (lenIV === -1) {
|
|
549
|
-
// This isn't in the spec, but Adobe's tx program handles -1
|
|
550
|
-
// as plain text.
|
|
551
|
-
return bytes;
|
|
552
|
-
}
|
|
553
|
-
return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/*
|
|
557
|
-
* Returns an object containing a Subrs array and a CharStrings
|
|
558
|
-
* array extracted from and eexec encrypted block of data
|
|
559
|
-
*/
|
|
560
|
-
extractFontProgram(properties) {
|
|
561
|
-
const stream = this.stream;
|
|
562
|
-
|
|
563
|
-
const subrs = [],
|
|
564
|
-
charstrings = [];
|
|
565
|
-
const privateData = Object.create(null);
|
|
566
|
-
privateData.lenIV = 4;
|
|
567
|
-
const program = {
|
|
568
|
-
subrs: [],
|
|
569
|
-
charstrings: [],
|
|
570
|
-
properties: {
|
|
571
|
-
privateData,
|
|
572
|
-
},
|
|
573
|
-
};
|
|
574
|
-
let token, length, data, lenIV, encoded;
|
|
575
|
-
while ((token = this.getToken()) !== null) {
|
|
576
|
-
if (token !== "/") {
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
token = this.getToken();
|
|
580
|
-
switch (token) {
|
|
581
|
-
case "CharStrings":
|
|
582
|
-
// The number immediately following CharStrings must be greater or
|
|
583
|
-
// equal to the number of CharStrings.
|
|
584
|
-
this.getToken();
|
|
585
|
-
this.getToken(); // read in 'dict'
|
|
586
|
-
this.getToken(); // read in 'dup'
|
|
587
|
-
this.getToken(); // read in 'begin'
|
|
588
|
-
while (true) {
|
|
589
|
-
token = this.getToken();
|
|
590
|
-
if (token === null || token === "end") {
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
if (token !== "/") {
|
|
595
|
-
continue;
|
|
596
|
-
}
|
|
597
|
-
const glyph = this.getToken();
|
|
598
|
-
length = this.readInt();
|
|
599
|
-
this.getToken(); // read in 'RD' or '-|'
|
|
600
|
-
data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
|
|
601
|
-
lenIV = program.properties.privateData.lenIV;
|
|
602
|
-
encoded = this.readCharStrings(data, lenIV);
|
|
603
|
-
this.nextChar();
|
|
604
|
-
token = this.getToken(); // read in 'ND' or '|-'
|
|
605
|
-
if (token === "noaccess") {
|
|
606
|
-
this.getToken(); // read in 'def'
|
|
607
|
-
}
|
|
608
|
-
charstrings.push({
|
|
609
|
-
glyph,
|
|
610
|
-
encoded,
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
break;
|
|
614
|
-
case "Subrs":
|
|
615
|
-
this.readInt(); // num
|
|
616
|
-
this.getToken(); // read in 'array'
|
|
617
|
-
while (this.getToken() === "dup") {
|
|
618
|
-
const index = this.readInt();
|
|
619
|
-
length = this.readInt();
|
|
620
|
-
this.getToken(); // read in 'RD' or '-|'
|
|
621
|
-
data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
|
|
622
|
-
lenIV = program.properties.privateData.lenIV;
|
|
623
|
-
encoded = this.readCharStrings(data, lenIV);
|
|
624
|
-
this.nextChar();
|
|
625
|
-
token = this.getToken(); // read in 'NP' or '|'
|
|
626
|
-
if (token === "noaccess") {
|
|
627
|
-
this.getToken(); // read in 'put'
|
|
628
|
-
}
|
|
629
|
-
subrs[index] = encoded;
|
|
630
|
-
}
|
|
631
|
-
break;
|
|
632
|
-
case "BlueValues":
|
|
633
|
-
case "OtherBlues":
|
|
634
|
-
case "FamilyBlues":
|
|
635
|
-
case "FamilyOtherBlues":
|
|
636
|
-
const blueArray = this.readNumberArray();
|
|
637
|
-
// *Blue* values may contain invalid data: disables reading of
|
|
638
|
-
// those values when hinting is disabled.
|
|
639
|
-
if (
|
|
640
|
-
blueArray.length > 0 &&
|
|
641
|
-
blueArray.length % 2 === 0 &&
|
|
642
|
-
HINTING_ENABLED
|
|
643
|
-
) {
|
|
644
|
-
program.properties.privateData[token] = blueArray;
|
|
645
|
-
}
|
|
646
|
-
break;
|
|
647
|
-
case "StemSnapH":
|
|
648
|
-
case "StemSnapV":
|
|
649
|
-
program.properties.privateData[token] = this.readNumberArray();
|
|
650
|
-
break;
|
|
651
|
-
case "StdHW":
|
|
652
|
-
case "StdVW":
|
|
653
|
-
program.properties.privateData[token] = this.readNumberArray()[0];
|
|
654
|
-
break;
|
|
655
|
-
case "BlueShift":
|
|
656
|
-
case "lenIV":
|
|
657
|
-
case "BlueFuzz":
|
|
658
|
-
case "BlueScale":
|
|
659
|
-
case "LanguageGroup":
|
|
660
|
-
case "ExpansionFactor":
|
|
661
|
-
program.properties.privateData[token] = this.readNumber();
|
|
662
|
-
break;
|
|
663
|
-
case "ForceBold":
|
|
664
|
-
program.properties.privateData[token] = this.readBoolean();
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
for (let i = 0; i < charstrings.length; i++) {
|
|
670
|
-
const glyph = charstrings[i].glyph;
|
|
671
|
-
encoded = charstrings[i].encoded;
|
|
672
|
-
const charString = new Type1CharString();
|
|
673
|
-
const error = charString.convert(
|
|
674
|
-
encoded,
|
|
675
|
-
subrs,
|
|
676
|
-
this.seacAnalysisEnabled
|
|
677
|
-
);
|
|
678
|
-
let output = charString.output;
|
|
679
|
-
if (error) {
|
|
680
|
-
// It seems when FreeType encounters an error while evaluating a glyph
|
|
681
|
-
// that it completely ignores the glyph so we'll mimic that behaviour
|
|
682
|
-
// here and put an endchar to make the validator happy.
|
|
683
|
-
output = [14];
|
|
684
|
-
}
|
|
685
|
-
const charStringObject = {
|
|
686
|
-
glyphName: glyph,
|
|
687
|
-
charstring: output,
|
|
688
|
-
width: charString.width,
|
|
689
|
-
lsb: charString.lsb,
|
|
690
|
-
seac: charString.seac,
|
|
691
|
-
};
|
|
692
|
-
if (glyph === ".notdef") {
|
|
693
|
-
// Make sure .notdef is at index zero (issue #11477).
|
|
694
|
-
program.charstrings.unshift(charStringObject);
|
|
695
|
-
} else {
|
|
696
|
-
program.charstrings.push(charStringObject);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// Attempt to replace missing widths, from the font dictionary /Widths
|
|
700
|
-
// entry, with ones from the font data (fixes issue11150_reduced.pdf).
|
|
701
|
-
if (properties.builtInEncoding) {
|
|
702
|
-
const index = properties.builtInEncoding.indexOf(glyph);
|
|
703
|
-
if (
|
|
704
|
-
index > -1 &&
|
|
705
|
-
properties.widths[index] === undefined &&
|
|
706
|
-
index >= properties.firstChar &&
|
|
707
|
-
index <= properties.lastChar
|
|
708
|
-
) {
|
|
709
|
-
properties.widths[index] = charString.width;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
return program;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
extractFontHeader(properties) {
|
|
718
|
-
let token;
|
|
719
|
-
while ((token = this.getToken()) !== null) {
|
|
720
|
-
if (token !== "/") {
|
|
721
|
-
continue;
|
|
722
|
-
}
|
|
723
|
-
token = this.getToken();
|
|
724
|
-
switch (token) {
|
|
725
|
-
case "FontMatrix":
|
|
726
|
-
const matrix = this.readNumberArray();
|
|
727
|
-
properties.fontMatrix = matrix;
|
|
728
|
-
break;
|
|
729
|
-
case "Encoding":
|
|
730
|
-
const encodingArg = this.getToken();
|
|
731
|
-
let encoding;
|
|
732
|
-
if (!/^\d+$/.test(encodingArg)) {
|
|
733
|
-
// encoding name is specified
|
|
734
|
-
encoding = getEncoding(encodingArg);
|
|
735
|
-
} else {
|
|
736
|
-
encoding = [];
|
|
737
|
-
const size = parseInt(encodingArg, 10) | 0;
|
|
738
|
-
this.getToken(); // read in 'array'
|
|
739
|
-
|
|
740
|
-
for (let j = 0; j < size; j++) {
|
|
741
|
-
token = this.getToken();
|
|
742
|
-
// skipping till first dup or def (e.g. ignoring for statement)
|
|
743
|
-
while (token !== "dup" && token !== "def") {
|
|
744
|
-
token = this.getToken();
|
|
745
|
-
if (token === null) {
|
|
746
|
-
return; // invalid header
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
if (token === "def") {
|
|
750
|
-
break; // read all array data
|
|
751
|
-
}
|
|
752
|
-
const index = this.readInt();
|
|
753
|
-
this.getToken(); // read in '/'
|
|
754
|
-
const glyph = this.getToken();
|
|
755
|
-
encoding[index] = glyph;
|
|
756
|
-
this.getToken(); // read the in 'put'
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
properties.builtInEncoding = encoding;
|
|
760
|
-
break;
|
|
761
|
-
case "FontBBox":
|
|
762
|
-
const fontBBox = this.readNumberArray();
|
|
763
|
-
// adjusting ascent/descent
|
|
764
|
-
properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
|
|
765
|
-
properties.descent = Math.min(fontBBox[1], fontBBox[3]);
|
|
766
|
-
properties.ascentScaled = true;
|
|
767
|
-
break;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
return Type1Parser;
|
|
774
|
-
})();
|
|
775
|
-
|
|
776
|
-
export { Type1Parser };
|