@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4

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.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
@@ -1,882 +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
- bytesToString,
18
- FONT_IDENTITY_MATRIX,
19
- FormatError,
20
- unreachable,
21
- warn,
22
- } from "../shared/util.js";
23
- import { CFFParser } from "./cff_parser.js";
24
- import { getGlyphsUnicode } from "./glyphlist.js";
25
- import { StandardEncoding } from "./encodings.js";
26
- import { Stream } from "./stream.js";
27
-
28
- function getLong(data, offset) {
29
- return (
30
- (data[offset] << 24) |
31
- (data[offset + 1] << 16) |
32
- (data[offset + 2] << 8) |
33
- data[offset + 3]
34
- );
35
- }
36
-
37
- function getUshort(data, offset) {
38
- return (data[offset] << 8) | data[offset + 1];
39
- }
40
-
41
- function getSubroutineBias(subrs) {
42
- const numSubrs = subrs.length;
43
- let bias = 32768;
44
- if (numSubrs < 1240) {
45
- bias = 107;
46
- } else if (numSubrs < 33900) {
47
- bias = 1131;
48
- }
49
- return bias;
50
- }
51
-
52
- function parseCmap(data, start, end) {
53
- const offset =
54
- getUshort(data, start + 2) === 1
55
- ? getLong(data, start + 8)
56
- : getLong(data, start + 16);
57
- const format = getUshort(data, start + offset);
58
- let ranges, p, i;
59
- if (format === 4) {
60
- getUshort(data, start + offset + 2); // length
61
- const segCount = getUshort(data, start + offset + 6) >> 1;
62
- p = start + offset + 14;
63
- ranges = [];
64
- for (i = 0; i < segCount; i++, p += 2) {
65
- ranges[i] = { end: getUshort(data, p) };
66
- }
67
- p += 2;
68
- for (i = 0; i < segCount; i++, p += 2) {
69
- ranges[i].start = getUshort(data, p);
70
- }
71
- for (i = 0; i < segCount; i++, p += 2) {
72
- ranges[i].idDelta = getUshort(data, p);
73
- }
74
- for (i = 0; i < segCount; i++, p += 2) {
75
- let idOffset = getUshort(data, p);
76
- if (idOffset === 0) {
77
- continue;
78
- }
79
- ranges[i].ids = [];
80
- for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
81
- ranges[i].ids[j] = getUshort(data, p + idOffset);
82
- idOffset += 2;
83
- }
84
- }
85
- return ranges;
86
- } else if (format === 12) {
87
- getLong(data, start + offset + 4); // length
88
- const groups = getLong(data, start + offset + 12);
89
- p = start + offset + 16;
90
- ranges = [];
91
- for (i = 0; i < groups; i++) {
92
- ranges.push({
93
- start: getLong(data, p),
94
- end: getLong(data, p + 4),
95
- idDelta: getLong(data, p + 8) - getLong(data, p),
96
- });
97
- p += 12;
98
- }
99
- return ranges;
100
- }
101
- throw new FormatError(`unsupported cmap: ${format}`);
102
- }
103
-
104
- function parseCff(data, start, end, seacAnalysisEnabled) {
105
- const properties = {};
106
- const parser = new CFFParser(
107
- new Stream(data, start, end - start),
108
- properties,
109
- seacAnalysisEnabled
110
- );
111
- const cff = parser.parse();
112
- return {
113
- glyphs: cff.charStrings.objects,
114
- subrs:
115
- cff.topDict.privateDict &&
116
- cff.topDict.privateDict.subrsIndex &&
117
- cff.topDict.privateDict.subrsIndex.objects,
118
- gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects,
119
- isCFFCIDFont: cff.isCIDFont,
120
- fdSelect: cff.fdSelect,
121
- fdArray: cff.fdArray,
122
- };
123
- }
124
-
125
- function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
126
- let itemSize, itemDecode;
127
- if (isGlyphLocationsLong) {
128
- itemSize = 4;
129
- itemDecode = function fontItemDecodeLong(data, offset) {
130
- return (
131
- (data[offset] << 24) |
132
- (data[offset + 1] << 16) |
133
- (data[offset + 2] << 8) |
134
- data[offset + 3]
135
- );
136
- };
137
- } else {
138
- itemSize = 2;
139
- itemDecode = function fontItemDecode(data, offset) {
140
- return (data[offset] << 9) | (data[offset + 1] << 1);
141
- };
142
- }
143
- const glyphs = [];
144
- let startOffset = itemDecode(loca, 0);
145
- for (let j = itemSize; j < loca.length; j += itemSize) {
146
- const endOffset = itemDecode(loca, j);
147
- glyphs.push(glyf.subarray(startOffset, endOffset));
148
- startOffset = endOffset;
149
- }
150
- return glyphs;
151
- }
152
-
153
- function lookupCmap(ranges, unicode) {
154
- const code = unicode.codePointAt(0);
155
- let gid = 0,
156
- l = 0,
157
- r = ranges.length - 1;
158
- while (l < r) {
159
- const c = (l + r + 1) >> 1;
160
- if (code < ranges[c].start) {
161
- r = c - 1;
162
- } else {
163
- l = c;
164
- }
165
- }
166
- if (ranges[l].start <= code && code <= ranges[l].end) {
167
- gid =
168
- (ranges[l].idDelta +
169
- (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code)) &
170
- 0xffff;
171
- }
172
- return {
173
- charCode: code,
174
- glyphId: gid,
175
- };
176
- }
177
-
178
- function compileGlyf(code, cmds, font) {
179
- function moveTo(x, y) {
180
- cmds.push({ cmd: "moveTo", args: [x, y] });
181
- }
182
- function lineTo(x, y) {
183
- cmds.push({ cmd: "lineTo", args: [x, y] });
184
- }
185
- function quadraticCurveTo(xa, ya, x, y) {
186
- cmds.push({ cmd: "quadraticCurveTo", args: [xa, ya, x, y] });
187
- }
188
-
189
- let i = 0;
190
- const numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
191
- let flags;
192
- let x = 0,
193
- y = 0;
194
- i += 10;
195
- if (numberOfContours < 0) {
196
- // composite glyph
197
- do {
198
- flags = (code[i] << 8) | code[i + 1];
199
- const glyphIndex = (code[i + 2] << 8) | code[i + 3];
200
- i += 4;
201
- let arg1, arg2;
202
- if (flags & 0x01) {
203
- arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
204
- arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
205
- i += 4;
206
- } else {
207
- arg1 = code[i++];
208
- arg2 = code[i++];
209
- }
210
- if (flags & 0x02) {
211
- x = arg1;
212
- y = arg2;
213
- } else {
214
- x = 0;
215
- y = 0; // TODO "they are points" ?
216
- }
217
- let scaleX = 1,
218
- scaleY = 1,
219
- scale01 = 0,
220
- scale10 = 0;
221
- if (flags & 0x08) {
222
- scaleX = scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
223
- i += 2;
224
- } else if (flags & 0x40) {
225
- scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
226
- scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
227
- i += 4;
228
- } else if (flags & 0x80) {
229
- scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
230
- scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
231
- scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
232
- scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
233
- i += 8;
234
- }
235
- const subglyph = font.glyphs[glyphIndex];
236
- if (subglyph) {
237
- cmds.push(
238
- { cmd: "save" },
239
- {
240
- cmd: "transform",
241
- args: [scaleX, scale01, scale10, scaleY, x, y],
242
- }
243
- );
244
- compileGlyf(subglyph, cmds, font);
245
- cmds.push({ cmd: "restore" });
246
- }
247
- } while (flags & 0x20);
248
- } else {
249
- // simple glyph
250
- const endPtsOfContours = [];
251
- let j, jj;
252
- for (j = 0; j < numberOfContours; j++) {
253
- endPtsOfContours.push((code[i] << 8) | code[i + 1]);
254
- i += 2;
255
- }
256
- const instructionLength = (code[i] << 8) | code[i + 1];
257
- i += 2 + instructionLength; // skipping the instructions
258
- const numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
259
- const points = [];
260
- while (points.length < numberOfPoints) {
261
- flags = code[i++];
262
- let repeat = 1;
263
- if (flags & 0x08) {
264
- repeat += code[i++];
265
- }
266
- while (repeat-- > 0) {
267
- points.push({ flags });
268
- }
269
- }
270
- for (j = 0; j < numberOfPoints; j++) {
271
- switch (points[j].flags & 0x12) {
272
- case 0x00:
273
- x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
274
- i += 2;
275
- break;
276
- case 0x02:
277
- x -= code[i++];
278
- break;
279
- case 0x12:
280
- x += code[i++];
281
- break;
282
- }
283
- points[j].x = x;
284
- }
285
- for (j = 0; j < numberOfPoints; j++) {
286
- switch (points[j].flags & 0x24) {
287
- case 0x00:
288
- y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
289
- i += 2;
290
- break;
291
- case 0x04:
292
- y -= code[i++];
293
- break;
294
- case 0x24:
295
- y += code[i++];
296
- break;
297
- }
298
- points[j].y = y;
299
- }
300
-
301
- let startPoint = 0;
302
- for (i = 0; i < numberOfContours; i++) {
303
- const endPoint = endPtsOfContours[i];
304
- // contours might have implicit points, which is located in the middle
305
- // between two neighboring off-curve points
306
- const contour = points.slice(startPoint, endPoint + 1);
307
- if (contour[0].flags & 1) {
308
- contour.push(contour[0]); // using start point at the contour end
309
- } else if (contour[contour.length - 1].flags & 1) {
310
- // first is off-curve point, trying to use one from the end
311
- contour.unshift(contour[contour.length - 1]);
312
- } else {
313
- // start and end are off-curve points, creating implicit one
314
- const p = {
315
- flags: 1,
316
- x: (contour[0].x + contour[contour.length - 1].x) / 2,
317
- y: (contour[0].y + contour[contour.length - 1].y) / 2,
318
- };
319
- contour.unshift(p);
320
- contour.push(p);
321
- }
322
- moveTo(contour[0].x, contour[0].y);
323
- for (j = 1, jj = contour.length; j < jj; j++) {
324
- if (contour[j].flags & 1) {
325
- lineTo(contour[j].x, contour[j].y);
326
- } else if (contour[j + 1].flags & 1) {
327
- quadraticCurveTo(
328
- contour[j].x,
329
- contour[j].y,
330
- contour[j + 1].x,
331
- contour[j + 1].y
332
- );
333
- j++;
334
- } else {
335
- quadraticCurveTo(
336
- contour[j].x,
337
- contour[j].y,
338
- (contour[j].x + contour[j + 1].x) / 2,
339
- (contour[j].y + contour[j + 1].y) / 2
340
- );
341
- }
342
- }
343
- startPoint = endPoint + 1;
344
- }
345
- }
346
- }
347
-
348
- function compileCharString(charStringCode, cmds, font, glyphId) {
349
- function moveTo(x, y) {
350
- cmds.push({ cmd: "moveTo", args: [x, y] });
351
- }
352
- function lineTo(x, y) {
353
- cmds.push({ cmd: "lineTo", args: [x, y] });
354
- }
355
- function bezierCurveTo(x1, y1, x2, y2, x, y) {
356
- cmds.push({ cmd: "bezierCurveTo", args: [x1, y1, x2, y2, x, y] });
357
- }
358
-
359
- const stack = [];
360
- let x = 0,
361
- y = 0;
362
- let stems = 0;
363
-
364
- function parse(code) {
365
- let i = 0;
366
- while (i < code.length) {
367
- let stackClean = false;
368
- let v = code[i++];
369
- let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
370
- switch (v) {
371
- case 1: // hstem
372
- stems += stack.length >> 1;
373
- stackClean = true;
374
- break;
375
- case 3: // vstem
376
- stems += stack.length >> 1;
377
- stackClean = true;
378
- break;
379
- case 4: // vmoveto
380
- y += stack.pop();
381
- moveTo(x, y);
382
- stackClean = true;
383
- break;
384
- case 5: // rlineto
385
- while (stack.length > 0) {
386
- x += stack.shift();
387
- y += stack.shift();
388
- lineTo(x, y);
389
- }
390
- break;
391
- case 6: // hlineto
392
- while (stack.length > 0) {
393
- x += stack.shift();
394
- lineTo(x, y);
395
- if (stack.length === 0) {
396
- break;
397
- }
398
- y += stack.shift();
399
- lineTo(x, y);
400
- }
401
- break;
402
- case 7: // vlineto
403
- while (stack.length > 0) {
404
- y += stack.shift();
405
- lineTo(x, y);
406
- if (stack.length === 0) {
407
- break;
408
- }
409
- x += stack.shift();
410
- lineTo(x, y);
411
- }
412
- break;
413
- case 8: // rrcurveto
414
- while (stack.length > 0) {
415
- xa = x + stack.shift();
416
- ya = y + stack.shift();
417
- xb = xa + stack.shift();
418
- yb = ya + stack.shift();
419
- x = xb + stack.shift();
420
- y = yb + stack.shift();
421
- bezierCurveTo(xa, ya, xb, yb, x, y);
422
- }
423
- break;
424
- case 10: // callsubr
425
- n = stack.pop();
426
- subrCode = null;
427
- if (font.isCFFCIDFont) {
428
- const fdIndex = font.fdSelect.getFDIndex(glyphId);
429
- if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
430
- const fontDict = font.fdArray[fdIndex];
431
- let subrs;
432
- if (fontDict.privateDict && fontDict.privateDict.subrsIndex) {
433
- subrs = fontDict.privateDict.subrsIndex.objects;
434
- }
435
- if (subrs) {
436
- // Add subroutine bias.
437
- n += getSubroutineBias(subrs);
438
- subrCode = subrs[n];
439
- }
440
- } else {
441
- warn("Invalid fd index for glyph index.");
442
- }
443
- } else {
444
- subrCode = font.subrs[n + font.subrsBias];
445
- }
446
- if (subrCode) {
447
- parse(subrCode);
448
- }
449
- break;
450
- case 11: // return
451
- return;
452
- case 12:
453
- v = code[i++];
454
- switch (v) {
455
- case 34: // flex
456
- xa = x + stack.shift();
457
- xb = xa + stack.shift();
458
- y1 = y + stack.shift();
459
- x = xb + stack.shift();
460
- bezierCurveTo(xa, y, xb, y1, x, y1);
461
- xa = x + stack.shift();
462
- xb = xa + stack.shift();
463
- x = xb + stack.shift();
464
- bezierCurveTo(xa, y1, xb, y, x, y);
465
- break;
466
- case 35: // flex
467
- xa = x + stack.shift();
468
- ya = y + stack.shift();
469
- xb = xa + stack.shift();
470
- yb = ya + stack.shift();
471
- x = xb + stack.shift();
472
- y = yb + stack.shift();
473
- bezierCurveTo(xa, ya, xb, yb, x, y);
474
- xa = x + stack.shift();
475
- ya = y + stack.shift();
476
- xb = xa + stack.shift();
477
- yb = ya + stack.shift();
478
- x = xb + stack.shift();
479
- y = yb + stack.shift();
480
- bezierCurveTo(xa, ya, xb, yb, x, y);
481
- stack.pop(); // fd
482
- break;
483
- case 36: // hflex1
484
- xa = x + stack.shift();
485
- y1 = y + stack.shift();
486
- xb = xa + stack.shift();
487
- y2 = y1 + stack.shift();
488
- x = xb + stack.shift();
489
- bezierCurveTo(xa, y1, xb, y2, x, y2);
490
- xa = x + stack.shift();
491
- xb = xa + stack.shift();
492
- y3 = y2 + stack.shift();
493
- x = xb + stack.shift();
494
- bezierCurveTo(xa, y2, xb, y3, x, y);
495
- break;
496
- case 37: // flex1
497
- const x0 = x,
498
- y0 = y;
499
- xa = x + stack.shift();
500
- ya = y + stack.shift();
501
- xb = xa + stack.shift();
502
- yb = ya + stack.shift();
503
- x = xb + stack.shift();
504
- y = yb + stack.shift();
505
- bezierCurveTo(xa, ya, xb, yb, x, y);
506
- xa = x + stack.shift();
507
- ya = y + stack.shift();
508
- xb = xa + stack.shift();
509
- yb = ya + stack.shift();
510
- x = xb;
511
- y = yb;
512
- if (Math.abs(x - x0) > Math.abs(y - y0)) {
513
- x += stack.shift();
514
- } else {
515
- y += stack.shift();
516
- }
517
- bezierCurveTo(xa, ya, xb, yb, x, y);
518
- break;
519
- default:
520
- throw new FormatError(`unknown operator: 12 ${v}`);
521
- }
522
- break;
523
- case 14: // endchar
524
- if (stack.length >= 4) {
525
- const achar = stack.pop();
526
- const bchar = stack.pop();
527
- y = stack.pop();
528
- x = stack.pop();
529
- cmds.push({ cmd: "save" }, { cmd: "translate", args: [x, y] });
530
- let cmap = lookupCmap(
531
- font.cmap,
532
- String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]])
533
- );
534
- compileCharString(
535
- font.glyphs[cmap.glyphId],
536
- cmds,
537
- font,
538
- cmap.glyphId
539
- );
540
- cmds.push({ cmd: "restore" });
541
-
542
- cmap = lookupCmap(
543
- font.cmap,
544
- String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]])
545
- );
546
- compileCharString(
547
- font.glyphs[cmap.glyphId],
548
- cmds,
549
- font,
550
- cmap.glyphId
551
- );
552
- }
553
- return;
554
- case 18: // hstemhm
555
- stems += stack.length >> 1;
556
- stackClean = true;
557
- break;
558
- case 19: // hintmask
559
- stems += stack.length >> 1;
560
- i += (stems + 7) >> 3;
561
- stackClean = true;
562
- break;
563
- case 20: // cntrmask
564
- stems += stack.length >> 1;
565
- i += (stems + 7) >> 3;
566
- stackClean = true;
567
- break;
568
- case 21: // rmoveto
569
- y += stack.pop();
570
- x += stack.pop();
571
- moveTo(x, y);
572
- stackClean = true;
573
- break;
574
- case 22: // hmoveto
575
- x += stack.pop();
576
- moveTo(x, y);
577
- stackClean = true;
578
- break;
579
- case 23: // vstemhm
580
- stems += stack.length >> 1;
581
- stackClean = true;
582
- break;
583
- case 24: // rcurveline
584
- while (stack.length > 2) {
585
- xa = x + stack.shift();
586
- ya = y + stack.shift();
587
- xb = xa + stack.shift();
588
- yb = ya + stack.shift();
589
- x = xb + stack.shift();
590
- y = yb + stack.shift();
591
- bezierCurveTo(xa, ya, xb, yb, x, y);
592
- }
593
- x += stack.shift();
594
- y += stack.shift();
595
- lineTo(x, y);
596
- break;
597
- case 25: // rlinecurve
598
- while (stack.length > 6) {
599
- x += stack.shift();
600
- y += stack.shift();
601
- lineTo(x, y);
602
- }
603
- xa = x + stack.shift();
604
- ya = y + stack.shift();
605
- xb = xa + stack.shift();
606
- yb = ya + stack.shift();
607
- x = xb + stack.shift();
608
- y = yb + stack.shift();
609
- bezierCurveTo(xa, ya, xb, yb, x, y);
610
- break;
611
- case 26: // vvcurveto
612
- if (stack.length % 2) {
613
- x += stack.shift();
614
- }
615
- while (stack.length > 0) {
616
- xa = x;
617
- ya = y + stack.shift();
618
- xb = xa + stack.shift();
619
- yb = ya + stack.shift();
620
- x = xb;
621
- y = yb + stack.shift();
622
- bezierCurveTo(xa, ya, xb, yb, x, y);
623
- }
624
- break;
625
- case 27: // hhcurveto
626
- if (stack.length % 2) {
627
- y += stack.shift();
628
- }
629
- while (stack.length > 0) {
630
- xa = x + stack.shift();
631
- ya = y;
632
- xb = xa + stack.shift();
633
- yb = ya + stack.shift();
634
- x = xb + stack.shift();
635
- y = yb;
636
- bezierCurveTo(xa, ya, xb, yb, x, y);
637
- }
638
- break;
639
- case 28:
640
- stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
641
- i += 2;
642
- break;
643
- case 29: // callgsubr
644
- n = stack.pop() + font.gsubrsBias;
645
- subrCode = font.gsubrs[n];
646
- if (subrCode) {
647
- parse(subrCode);
648
- }
649
- break;
650
- case 30: // vhcurveto
651
- while (stack.length > 0) {
652
- xa = x;
653
- ya = y + stack.shift();
654
- xb = xa + stack.shift();
655
- yb = ya + stack.shift();
656
- x = xb + stack.shift();
657
- y = yb + (stack.length === 1 ? stack.shift() : 0);
658
- bezierCurveTo(xa, ya, xb, yb, x, y);
659
- if (stack.length === 0) {
660
- break;
661
- }
662
-
663
- xa = x + stack.shift();
664
- ya = y;
665
- xb = xa + stack.shift();
666
- yb = ya + stack.shift();
667
- y = yb + stack.shift();
668
- x = xb + (stack.length === 1 ? stack.shift() : 0);
669
- bezierCurveTo(xa, ya, xb, yb, x, y);
670
- }
671
- break;
672
- case 31: // hvcurveto
673
- while (stack.length > 0) {
674
- xa = x + stack.shift();
675
- ya = y;
676
- xb = xa + stack.shift();
677
- yb = ya + stack.shift();
678
- y = yb + stack.shift();
679
- x = xb + (stack.length === 1 ? stack.shift() : 0);
680
- bezierCurveTo(xa, ya, xb, yb, x, y);
681
- if (stack.length === 0) {
682
- break;
683
- }
684
-
685
- xa = x;
686
- ya = y + stack.shift();
687
- xb = xa + stack.shift();
688
- yb = ya + stack.shift();
689
- x = xb + stack.shift();
690
- y = yb + (stack.length === 1 ? stack.shift() : 0);
691
- bezierCurveTo(xa, ya, xb, yb, x, y);
692
- }
693
- break;
694
- default:
695
- if (v < 32) {
696
- throw new FormatError(`unknown operator: ${v}`);
697
- }
698
- if (v < 247) {
699
- stack.push(v - 139);
700
- } else if (v < 251) {
701
- stack.push((v - 247) * 256 + code[i++] + 108);
702
- } else if (v < 255) {
703
- stack.push(-(v - 251) * 256 - code[i++] - 108);
704
- } else {
705
- stack.push(
706
- ((code[i] << 24) |
707
- (code[i + 1] << 16) |
708
- (code[i + 2] << 8) |
709
- code[i + 3]) /
710
- 65536
711
- );
712
- i += 4;
713
- }
714
- break;
715
- }
716
- if (stackClean) {
717
- stack.length = 0;
718
- }
719
- }
720
- }
721
- parse(charStringCode);
722
- }
723
-
724
- const NOOP = [];
725
-
726
- class CompiledFont {
727
- constructor(fontMatrix) {
728
- if (this.constructor === CompiledFont) {
729
- unreachable("Cannot initialize CompiledFont.");
730
- }
731
- this.fontMatrix = fontMatrix;
732
-
733
- this.compiledGlyphs = Object.create(null);
734
- this.compiledCharCodeToGlyphId = Object.create(null);
735
- }
736
-
737
- getPathJs(unicode) {
738
- const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
739
- let fn = this.compiledGlyphs[glyphId];
740
- if (!fn) {
741
- try {
742
- fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
743
- this.compiledGlyphs[glyphId] = fn;
744
- } catch (ex) {
745
- // Avoid attempting to re-compile a corrupt glyph.
746
- this.compiledGlyphs[glyphId] = NOOP;
747
-
748
- if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
749
- this.compiledCharCodeToGlyphId[charCode] = glyphId;
750
- }
751
- throw ex;
752
- }
753
- }
754
- if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
755
- this.compiledCharCodeToGlyphId[charCode] = glyphId;
756
- }
757
- return fn;
758
- }
759
-
760
- compileGlyph(code, glyphId) {
761
- if (!code || code.length === 0 || code[0] === 14) {
762
- return NOOP;
763
- }
764
-
765
- let fontMatrix = this.fontMatrix;
766
- if (this.isCFFCIDFont) {
767
- // Top DICT's FontMatrix can be ignored because CFFCompiler always
768
- // removes it and copies to FDArray DICTs.
769
- const fdIndex = this.fdSelect.getFDIndex(glyphId);
770
- if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
771
- const fontDict = this.fdArray[fdIndex];
772
- fontMatrix = fontDict.getByName("FontMatrix") || FONT_IDENTITY_MATRIX;
773
- } else {
774
- warn("Invalid fd index for glyph index.");
775
- }
776
- }
777
-
778
- const cmds = [
779
- { cmd: "save" },
780
- { cmd: "transform", args: fontMatrix.slice() },
781
- { cmd: "scale", args: ["size", "-size"] },
782
- ];
783
- this.compileGlyphImpl(code, cmds, glyphId);
784
-
785
- cmds.push({ cmd: "restore" });
786
-
787
- return cmds;
788
- }
789
-
790
- compileGlyphImpl() {
791
- unreachable("Children classes should implement this.");
792
- }
793
-
794
- hasBuiltPath(unicode) {
795
- const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
796
- return (
797
- this.compiledGlyphs[glyphId] !== undefined &&
798
- this.compiledCharCodeToGlyphId[charCode] !== undefined
799
- );
800
- }
801
- }
802
-
803
- class TrueTypeCompiled extends CompiledFont {
804
- constructor(glyphs, cmap, fontMatrix) {
805
- super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
806
-
807
- this.glyphs = glyphs;
808
- this.cmap = cmap;
809
- }
810
-
811
- compileGlyphImpl(code, cmds) {
812
- compileGlyf(code, cmds, this);
813
- }
814
- }
815
-
816
- class Type2Compiled extends CompiledFont {
817
- constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
818
- super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
819
-
820
- this.glyphs = cffInfo.glyphs;
821
- this.gsubrs = cffInfo.gsubrs || [];
822
- this.subrs = cffInfo.subrs || [];
823
- this.cmap = cmap;
824
- this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
825
-
826
- this.gsubrsBias = getSubroutineBias(this.gsubrs);
827
- this.subrsBias = getSubroutineBias(this.subrs);
828
-
829
- this.isCFFCIDFont = cffInfo.isCFFCIDFont;
830
- this.fdSelect = cffInfo.fdSelect;
831
- this.fdArray = cffInfo.fdArray;
832
- }
833
-
834
- compileGlyphImpl(code, cmds, glyphId) {
835
- compileCharString(code, cmds, this, glyphId);
836
- }
837
- }
838
-
839
- class FontRendererFactory {
840
- static create(font, seacAnalysisEnabled) {
841
- const data = new Uint8Array(font.data);
842
- let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
843
- const numTables = getUshort(data, 4);
844
- for (let i = 0, p = 12; i < numTables; i++, p += 16) {
845
- const tag = bytesToString(data.subarray(p, p + 4));
846
- const offset = getLong(data, p + 8);
847
- const length = getLong(data, p + 12);
848
- switch (tag) {
849
- case "cmap":
850
- cmap = parseCmap(data, offset, offset + length);
851
- break;
852
- case "glyf":
853
- glyf = data.subarray(offset, offset + length);
854
- break;
855
- case "loca":
856
- loca = data.subarray(offset, offset + length);
857
- break;
858
- case "head":
859
- unitsPerEm = getUshort(data, offset + 18);
860
- indexToLocFormat = getUshort(data, offset + 50);
861
- break;
862
- case "CFF ":
863
- cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
864
- break;
865
- }
866
- }
867
-
868
- if (glyf) {
869
- const fontMatrix = !unitsPerEm
870
- ? font.fontMatrix
871
- : [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
872
- return new TrueTypeCompiled(
873
- parseGlyfTable(glyf, loca, indexToLocFormat),
874
- cmap,
875
- fontMatrix
876
- );
877
- }
878
- return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
879
- }
880
- }
881
-
882
- export { FontRendererFactory };