@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_font.js
DELETED
|
@@ -1,421 +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 {
|
|
17
|
-
CFF,
|
|
18
|
-
CFFCharset,
|
|
19
|
-
CFFCompiler,
|
|
20
|
-
CFFHeader,
|
|
21
|
-
CFFIndex,
|
|
22
|
-
CFFPrivateDict,
|
|
23
|
-
CFFStandardStrings,
|
|
24
|
-
CFFStrings,
|
|
25
|
-
CFFTopDict,
|
|
26
|
-
} from "./cff_parser.js";
|
|
27
|
-
import { SEAC_ANALYSIS_ENABLED, type1FontGlyphMapping } from "./fonts_utils.js";
|
|
28
|
-
import { isWhiteSpace } from "./core_utils.js";
|
|
29
|
-
import { Stream } from "./stream.js";
|
|
30
|
-
import { Type1Parser } from "./type1_parser.js";
|
|
31
|
-
import { warn } from "../shared/util.js";
|
|
32
|
-
|
|
33
|
-
function findBlock(streamBytes, signature, startIndex) {
|
|
34
|
-
const streamBytesLength = streamBytes.length;
|
|
35
|
-
const signatureLength = signature.length;
|
|
36
|
-
const scanLength = streamBytesLength - signatureLength;
|
|
37
|
-
|
|
38
|
-
let i = startIndex,
|
|
39
|
-
found = false;
|
|
40
|
-
while (i < scanLength) {
|
|
41
|
-
let j = 0;
|
|
42
|
-
while (j < signatureLength && streamBytes[i + j] === signature[j]) {
|
|
43
|
-
j++;
|
|
44
|
-
}
|
|
45
|
-
if (j >= signatureLength) {
|
|
46
|
-
// `signature` found, skip over whitespace.
|
|
47
|
-
i += j;
|
|
48
|
-
while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) {
|
|
49
|
-
i++;
|
|
50
|
-
}
|
|
51
|
-
found = true;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
i++;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
found,
|
|
58
|
-
length: i,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function getHeaderBlock(stream, suggestedLength) {
|
|
63
|
-
const EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
|
|
64
|
-
|
|
65
|
-
const streamStartPos = stream.pos; // Save the initial stream position.
|
|
66
|
-
let headerBytes, headerBytesLength, block;
|
|
67
|
-
try {
|
|
68
|
-
headerBytes = stream.getBytes(suggestedLength);
|
|
69
|
-
headerBytesLength = headerBytes.length;
|
|
70
|
-
} catch (ex) {
|
|
71
|
-
// Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
|
|
72
|
-
// cannot hold the result of `getBytes`, and fallback to simply checking
|
|
73
|
-
// the entire stream (fixes issue3928.pdf).
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (headerBytesLength === suggestedLength) {
|
|
77
|
-
// Most of the time `suggestedLength` is correct, so to speed things up we
|
|
78
|
-
// initially only check the last few bytes to see if the header was found.
|
|
79
|
-
// Otherwise we (potentially) check the entire stream to prevent errors in
|
|
80
|
-
// `Type1Parser` (fixes issue5686.pdf).
|
|
81
|
-
block = findBlock(
|
|
82
|
-
headerBytes,
|
|
83
|
-
EEXEC_SIGNATURE,
|
|
84
|
-
suggestedLength - 2 * EEXEC_SIGNATURE.length
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (block.found && block.length === suggestedLength) {
|
|
88
|
-
return {
|
|
89
|
-
stream: new Stream(headerBytes),
|
|
90
|
-
length: suggestedLength,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
warn('Invalid "Length1" property in Type1 font -- trying to recover.');
|
|
95
|
-
stream.pos = streamStartPos; // Reset the stream position.
|
|
96
|
-
|
|
97
|
-
const SCAN_BLOCK_LENGTH = 2048;
|
|
98
|
-
let actualLength;
|
|
99
|
-
while (true) {
|
|
100
|
-
const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
|
|
101
|
-
block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
|
|
102
|
-
|
|
103
|
-
if (block.length === 0) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
stream.pos += block.length; // Update the stream position.
|
|
107
|
-
|
|
108
|
-
if (block.found) {
|
|
109
|
-
actualLength = stream.pos - streamStartPos;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
stream.pos = streamStartPos; // Reset the stream position.
|
|
114
|
-
|
|
115
|
-
if (actualLength) {
|
|
116
|
-
return {
|
|
117
|
-
stream: new Stream(stream.getBytes(actualLength)),
|
|
118
|
-
length: actualLength,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
warn('Unable to recover "Length1" property in Type1 font -- using as is.');
|
|
122
|
-
return {
|
|
123
|
-
stream: new Stream(stream.getBytes(suggestedLength)),
|
|
124
|
-
length: suggestedLength,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function getEexecBlock(stream, suggestedLength) {
|
|
129
|
-
// We should ideally parse the eexec block to ensure that `suggestedLength`
|
|
130
|
-
// is correct, so we don't truncate the block data if it's too small.
|
|
131
|
-
// However, this would also require checking if the fixed-content portion
|
|
132
|
-
// exists (using the 'Length3' property), and ensuring that it's valid.
|
|
133
|
-
//
|
|
134
|
-
// Given that `suggestedLength` almost always is correct, all the validation
|
|
135
|
-
// would require a great deal of unnecessary parsing for most fonts.
|
|
136
|
-
// To save time, we always fetch the entire stream instead, which also avoid
|
|
137
|
-
// issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
|
|
138
|
-
//
|
|
139
|
-
// NOTE: This means that the function can include the fixed-content portion
|
|
140
|
-
// in the returned eexec block. In practice this does *not* seem to matter,
|
|
141
|
-
// since `Type1Parser_extractFontProgram` will skip over any non-commands.
|
|
142
|
-
const eexecBytes = stream.getBytes();
|
|
143
|
-
return {
|
|
144
|
-
stream: new Stream(eexecBytes),
|
|
145
|
-
length: eexecBytes.length,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Type1Font is also a CIDFontType0.
|
|
151
|
-
*/
|
|
152
|
-
class Type1Font {
|
|
153
|
-
constructor(name, file, properties) {
|
|
154
|
-
// Some bad generators embed pfb file as is, we have to strip 6-byte header.
|
|
155
|
-
// Also, length1 and length2 might be off by 6 bytes as well.
|
|
156
|
-
// http://www.math.ubc.ca/~cass/piscript/type1.pdf
|
|
157
|
-
const PFB_HEADER_SIZE = 6;
|
|
158
|
-
let headerBlockLength = properties.length1;
|
|
159
|
-
let eexecBlockLength = properties.length2;
|
|
160
|
-
let pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
|
|
161
|
-
const pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
|
|
162
|
-
if (pfbHeaderPresent) {
|
|
163
|
-
file.skip(PFB_HEADER_SIZE);
|
|
164
|
-
headerBlockLength =
|
|
165
|
-
(pfbHeader[5] << 24) |
|
|
166
|
-
(pfbHeader[4] << 16) |
|
|
167
|
-
(pfbHeader[3] << 8) |
|
|
168
|
-
pfbHeader[2];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Get the data block containing glyphs and subrs information
|
|
172
|
-
const headerBlock = getHeaderBlock(file, headerBlockLength);
|
|
173
|
-
const headerBlockParser = new Type1Parser(
|
|
174
|
-
headerBlock.stream,
|
|
175
|
-
false,
|
|
176
|
-
SEAC_ANALYSIS_ENABLED
|
|
177
|
-
);
|
|
178
|
-
headerBlockParser.extractFontHeader(properties);
|
|
179
|
-
|
|
180
|
-
if (pfbHeaderPresent) {
|
|
181
|
-
pfbHeader = file.getBytes(PFB_HEADER_SIZE);
|
|
182
|
-
eexecBlockLength =
|
|
183
|
-
(pfbHeader[5] << 24) |
|
|
184
|
-
(pfbHeader[4] << 16) |
|
|
185
|
-
(pfbHeader[3] << 8) |
|
|
186
|
-
pfbHeader[2];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Decrypt the data blocks and retrieve it's content
|
|
190
|
-
const eexecBlock = getEexecBlock(file, eexecBlockLength);
|
|
191
|
-
const eexecBlockParser = new Type1Parser(
|
|
192
|
-
eexecBlock.stream,
|
|
193
|
-
true,
|
|
194
|
-
SEAC_ANALYSIS_ENABLED
|
|
195
|
-
);
|
|
196
|
-
const data = eexecBlockParser.extractFontProgram(properties);
|
|
197
|
-
for (const key in data.properties) {
|
|
198
|
-
properties[key] = data.properties[key];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const charstrings = data.charstrings;
|
|
202
|
-
const type2Charstrings = this.getType2Charstrings(charstrings);
|
|
203
|
-
const subrs = this.getType2Subrs(data.subrs);
|
|
204
|
-
|
|
205
|
-
this.charstrings = charstrings;
|
|
206
|
-
this.data = this.wrap(
|
|
207
|
-
name,
|
|
208
|
-
type2Charstrings,
|
|
209
|
-
this.charstrings,
|
|
210
|
-
subrs,
|
|
211
|
-
properties
|
|
212
|
-
);
|
|
213
|
-
this.seacs = this.getSeacs(data.charstrings);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
get numGlyphs() {
|
|
217
|
-
return this.charstrings.length + 1;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
getCharset() {
|
|
221
|
-
const charset = [".notdef"];
|
|
222
|
-
const charstrings = this.charstrings;
|
|
223
|
-
for (let glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
|
224
|
-
charset.push(charstrings[glyphId].glyphName);
|
|
225
|
-
}
|
|
226
|
-
return charset;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
getGlyphMapping(properties) {
|
|
230
|
-
const charstrings = this.charstrings;
|
|
231
|
-
|
|
232
|
-
if (properties.composite) {
|
|
233
|
-
const charCodeToGlyphId = Object.create(null);
|
|
234
|
-
// Map CIDs directly to GIDs.
|
|
235
|
-
for (
|
|
236
|
-
let glyphId = 0, charstringsLen = charstrings.length;
|
|
237
|
-
glyphId < charstringsLen;
|
|
238
|
-
glyphId++
|
|
239
|
-
) {
|
|
240
|
-
const charCode = properties.cMap.charCodeOf(glyphId);
|
|
241
|
-
// Add 1 because glyph 0 is duplicated.
|
|
242
|
-
charCodeToGlyphId[charCode] = glyphId + 1;
|
|
243
|
-
}
|
|
244
|
-
return charCodeToGlyphId;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const glyphNames = [".notdef"];
|
|
248
|
-
let builtInEncoding, glyphId;
|
|
249
|
-
for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
|
|
250
|
-
glyphNames.push(charstrings[glyphId].glyphName);
|
|
251
|
-
}
|
|
252
|
-
const encoding = properties.builtInEncoding;
|
|
253
|
-
if (encoding) {
|
|
254
|
-
builtInEncoding = Object.create(null);
|
|
255
|
-
for (const charCode in encoding) {
|
|
256
|
-
glyphId = glyphNames.indexOf(encoding[charCode]);
|
|
257
|
-
if (glyphId >= 0) {
|
|
258
|
-
builtInEncoding[charCode] = glyphId;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
hasGlyphId(id) {
|
|
267
|
-
if (id < 0 || id >= this.numGlyphs) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
if (id === 0) {
|
|
271
|
-
// notdef is always defined.
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
const glyph = this.charstrings[id - 1];
|
|
275
|
-
return glyph.charstring.length > 0;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
getSeacs(charstrings) {
|
|
279
|
-
const seacMap = [];
|
|
280
|
-
for (let i = 0, ii = charstrings.length; i < ii; i++) {
|
|
281
|
-
const charstring = charstrings[i];
|
|
282
|
-
if (charstring.seac) {
|
|
283
|
-
// Offset by 1 for .notdef
|
|
284
|
-
seacMap[i + 1] = charstring.seac;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return seacMap;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
getType2Charstrings(type1Charstrings) {
|
|
291
|
-
const type2Charstrings = [];
|
|
292
|
-
for (let i = 0, ii = type1Charstrings.length; i < ii; i++) {
|
|
293
|
-
type2Charstrings.push(type1Charstrings[i].charstring);
|
|
294
|
-
}
|
|
295
|
-
return type2Charstrings;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
getType2Subrs(type1Subrs) {
|
|
299
|
-
let bias = 0;
|
|
300
|
-
const count = type1Subrs.length;
|
|
301
|
-
if (count < 1133) {
|
|
302
|
-
bias = 107;
|
|
303
|
-
} else if (count < 33769) {
|
|
304
|
-
bias = 1131;
|
|
305
|
-
} else {
|
|
306
|
-
bias = 32768;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Add a bunch of empty subrs to deal with the Type2 bias
|
|
310
|
-
const type2Subrs = [];
|
|
311
|
-
let i;
|
|
312
|
-
for (i = 0; i < bias; i++) {
|
|
313
|
-
type2Subrs.push([0x0b]);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
for (i = 0; i < count; i++) {
|
|
317
|
-
type2Subrs.push(type1Subrs[i]);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return type2Subrs;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
wrap(name, glyphs, charstrings, subrs, properties) {
|
|
324
|
-
const cff = new CFF();
|
|
325
|
-
cff.header = new CFFHeader(1, 0, 4, 4);
|
|
326
|
-
|
|
327
|
-
cff.names = [name];
|
|
328
|
-
|
|
329
|
-
const topDict = new CFFTopDict();
|
|
330
|
-
// CFF strings IDs 0...390 are predefined names, so refering
|
|
331
|
-
// to entries in our own String INDEX starts at SID 391.
|
|
332
|
-
topDict.setByName("version", 391);
|
|
333
|
-
topDict.setByName("Notice", 392);
|
|
334
|
-
topDict.setByName("FullName", 393);
|
|
335
|
-
topDict.setByName("FamilyName", 394);
|
|
336
|
-
topDict.setByName("Weight", 395);
|
|
337
|
-
topDict.setByName("Encoding", null); // placeholder
|
|
338
|
-
topDict.setByName("FontMatrix", properties.fontMatrix);
|
|
339
|
-
topDict.setByName("FontBBox", properties.bbox);
|
|
340
|
-
topDict.setByName("charset", null); // placeholder
|
|
341
|
-
topDict.setByName("CharStrings", null); // placeholder
|
|
342
|
-
topDict.setByName("Private", null); // placeholder
|
|
343
|
-
cff.topDict = topDict;
|
|
344
|
-
|
|
345
|
-
const strings = new CFFStrings();
|
|
346
|
-
strings.add("Version 0.11"); // Version
|
|
347
|
-
strings.add("See original notice"); // Notice
|
|
348
|
-
strings.add(name); // FullName
|
|
349
|
-
strings.add(name); // FamilyName
|
|
350
|
-
strings.add("Medium"); // Weight
|
|
351
|
-
cff.strings = strings;
|
|
352
|
-
|
|
353
|
-
cff.globalSubrIndex = new CFFIndex();
|
|
354
|
-
|
|
355
|
-
const count = glyphs.length;
|
|
356
|
-
const charsetArray = [".notdef"];
|
|
357
|
-
let i, ii;
|
|
358
|
-
for (i = 0; i < count; i++) {
|
|
359
|
-
const glyphName = charstrings[i].glyphName;
|
|
360
|
-
const index = CFFStandardStrings.indexOf(glyphName);
|
|
361
|
-
if (index === -1) {
|
|
362
|
-
strings.add(glyphName);
|
|
363
|
-
}
|
|
364
|
-
charsetArray.push(glyphName);
|
|
365
|
-
}
|
|
366
|
-
cff.charset = new CFFCharset(false, 0, charsetArray);
|
|
367
|
-
|
|
368
|
-
const charStringsIndex = new CFFIndex();
|
|
369
|
-
charStringsIndex.add([0x8b, 0x0e]); // .notdef
|
|
370
|
-
for (i = 0; i < count; i++) {
|
|
371
|
-
charStringsIndex.add(glyphs[i]);
|
|
372
|
-
}
|
|
373
|
-
cff.charStrings = charStringsIndex;
|
|
374
|
-
|
|
375
|
-
const privateDict = new CFFPrivateDict();
|
|
376
|
-
privateDict.setByName("Subrs", null); // placeholder
|
|
377
|
-
const fields = [
|
|
378
|
-
"BlueValues",
|
|
379
|
-
"OtherBlues",
|
|
380
|
-
"FamilyBlues",
|
|
381
|
-
"FamilyOtherBlues",
|
|
382
|
-
"StemSnapH",
|
|
383
|
-
"StemSnapV",
|
|
384
|
-
"BlueShift",
|
|
385
|
-
"BlueFuzz",
|
|
386
|
-
"BlueScale",
|
|
387
|
-
"LanguageGroup",
|
|
388
|
-
"ExpansionFactor",
|
|
389
|
-
"ForceBold",
|
|
390
|
-
"StdHW",
|
|
391
|
-
"StdVW",
|
|
392
|
-
];
|
|
393
|
-
for (i = 0, ii = fields.length; i < ii; i++) {
|
|
394
|
-
const field = fields[i];
|
|
395
|
-
if (!(field in properties.privateData)) {
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
const value = properties.privateData[field];
|
|
399
|
-
if (Array.isArray(value)) {
|
|
400
|
-
// All of the private dictionary array data in CFF must be stored as
|
|
401
|
-
// "delta-encoded" numbers.
|
|
402
|
-
for (let j = value.length - 1; j > 0; j--) {
|
|
403
|
-
value[j] -= value[j - 1]; // ... difference from previous value
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
privateDict.setByName(field, value);
|
|
407
|
-
}
|
|
408
|
-
cff.topDict.privateDict = privateDict;
|
|
409
|
-
|
|
410
|
-
const subrIndex = new CFFIndex();
|
|
411
|
-
for (i = 0, ii = subrs.length; i < ii; i++) {
|
|
412
|
-
subrIndex.add(subrs[i]);
|
|
413
|
-
}
|
|
414
|
-
privateDict.subrsIndex = subrIndex;
|
|
415
|
-
|
|
416
|
-
const compiler = new CFFCompiler(cff);
|
|
417
|
-
return compiler.compile();
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export { Type1Font };
|