pdfjs-dist 2.6.347 → 2.7.570
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +3 -3
- package/bower.json +1 -1
- package/build/pdf.js +2050 -1087
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +18219 -10436
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.d.ts +1 -0
- package/es5/build/pdf.js +6623 -6654
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +1 -1
- package/es5/build/pdf.worker.js +20815 -13888
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +1 -1
- package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
- package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
- package/es5/web/pdf_viewer.css +18 -15
- package/es5/web/pdf_viewer.js +1094 -514
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +774 -168
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +556 -108
- package/lib/core/cff_parser.js +7 -1
- package/lib/core/charsets.js +1 -1
- package/lib/core/cmap.js +20 -1
- package/lib/core/core_utils.js +162 -3
- package/lib/core/crypto.js +1 -1
- package/lib/core/default_appearance.js +132 -0
- package/lib/core/document.js +115 -9
- package/lib/core/encodings.js +1 -1
- package/lib/core/evaluator.js +168 -74
- package/lib/core/fonts.js +97 -11
- package/lib/core/function.js +5 -10
- package/lib/core/glyphlist.js +11 -4529
- package/lib/core/image_utils.js +30 -1
- package/lib/core/jpg.js +1 -1
- package/lib/core/jpx.js +5 -5
- package/lib/core/murmurhash3.js +1 -1
- package/lib/core/obj.js +123 -39
- package/lib/core/pattern.js +4 -4
- package/lib/core/primitives.js +24 -5
- package/lib/core/standard_fonts.js +1 -1
- package/lib/core/stream.js +5 -1
- package/lib/core/unicode.js +15 -1387
- package/lib/core/worker.js +58 -17
- package/lib/core/writer.js +68 -4
- package/lib/display/annotation_layer.js +712 -119
- package/lib/display/annotation_storage.js +21 -4
- package/lib/display/api.js +88 -18
- package/lib/display/canvas.js +414 -375
- package/lib/display/display_utils.js +11 -4
- package/lib/display/fetch_stream.js +3 -3
- package/lib/display/font_loader.js +2 -3
- package/lib/display/metadata.js +54 -20
- package/lib/display/node_stream.js +1 -1
- package/lib/display/optional_content_config.js +1 -1
- package/lib/display/pattern_helper.js +109 -113
- package/lib/display/svg.js +5 -5
- package/lib/display/text_layer.js +54 -54
- package/lib/display/transport_stream.js +4 -4
- package/lib/display/webgl.js +65 -68
- package/lib/examples/node/domstubs.js +9 -4
- package/lib/pdf.js +2 -2
- package/lib/pdf.sandbox.js +311 -0
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/scripting_utils.js +84 -0
- package/lib/shared/util.js +129 -14
- package/lib/{display → shared}/xml_parser.js +112 -4
- package/lib/test/unit/annotation_spec.js +831 -109
- package/lib/test/unit/annotation_storage_spec.js +28 -10
- package/lib/test/unit/api_spec.js +190 -160
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +73 -73
- package/lib/test/unit/clitests_helper.js +2 -0
- package/lib/test/unit/cmap_spec.js +48 -74
- package/lib/test/unit/core_utils_spec.js +34 -0
- package/lib/test/unit/crypto_spec.js +162 -199
- package/lib/test/unit/custom_spec.js +7 -18
- package/lib/test/unit/default_appearance_spec.js +54 -0
- package/lib/test/unit/display_svg_spec.js +24 -19
- package/lib/test/unit/display_utils_spec.js +1 -1
- package/lib/test/unit/document_spec.js +187 -20
- package/lib/test/unit/evaluator_spec.js +30 -30
- package/lib/test/unit/function_spec.js +165 -165
- package/lib/test/unit/jasmine-boot.js +52 -53
- package/lib/test/unit/metadata_spec.js +2 -2
- package/lib/test/unit/murmurhash3_spec.js +29 -16
- package/lib/test/unit/network_spec.js +21 -21
- package/lib/test/unit/pdf_find_controller_spec.js +131 -69
- package/lib/test/unit/pdf_find_utils_spec.js +10 -10
- package/lib/test/unit/scripting_spec.js +1104 -0
- package/lib/test/unit/stream_spec.js +8 -8
- package/lib/test/unit/test_utils.js +16 -19
- package/lib/test/unit/testreporter.js +11 -4
- package/lib/test/unit/type1_parser_spec.js +23 -23
- package/lib/test/unit/ui_utils_spec.js +78 -35
- package/lib/test/unit/unicode_spec.js +7 -7
- package/lib/test/unit/util_spec.js +26 -3
- package/lib/test/unit/writer_spec.js +16 -1
- package/lib/test/unit/xml_spec.js +117 -0
- package/lib/web/annotation_layer_builder.js +18 -6
- package/lib/web/app.js +579 -161
- package/lib/web/app_options.js +14 -0
- package/lib/web/base_tree_viewer.js +50 -0
- package/lib/web/base_viewer.js +350 -14
- package/lib/web/chromecom.js +9 -1
- package/lib/web/debugger.js +1 -2
- package/lib/web/download_manager.js +0 -15
- package/lib/web/firefox_print_service.js +6 -4
- package/lib/web/firefoxcom.js +84 -69
- package/lib/web/generic_scripting.js +55 -0
- package/lib/web/genericcom.js +9 -1
- package/lib/web/grab_to_pan.js +1 -1
- package/lib/web/interfaces.js +9 -3
- package/lib/web/pdf_attachment_viewer.js +1 -3
- package/lib/web/pdf_cursor_tools.js +20 -13
- package/lib/web/pdf_document_properties.js +48 -61
- package/lib/web/pdf_find_bar.js +1 -3
- package/lib/web/pdf_find_controller.js +58 -12
- package/lib/web/pdf_history.js +43 -21
- package/lib/web/pdf_layer_viewer.js +1 -9
- package/lib/web/pdf_link_service.js +108 -78
- package/lib/web/pdf_outline_viewer.js +166 -10
- package/lib/web/pdf_page_view.js +14 -14
- package/lib/web/pdf_presentation_mode.js +21 -31
- package/lib/web/pdf_rendering_queue.js +8 -1
- package/lib/web/pdf_sidebar.js +62 -107
- package/lib/web/pdf_sidebar_resizer.js +11 -21
- package/lib/web/pdf_single_page_viewer.js +8 -0
- package/lib/web/pdf_thumbnail_view.js +26 -26
- package/lib/web/pdf_thumbnail_viewer.js +13 -2
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/pdf_viewer.js +3 -1
- package/lib/web/preferences.js +33 -44
- package/lib/web/text_layer_builder.js +2 -9
- package/lib/web/ui_utils.js +78 -46
- package/lib/web/viewer_compatibility.js +1 -2
- package/package.json +4 -1
- package/types/display/annotation_layer.d.ts +18 -3
- package/types/display/api.d.ts +110 -54
- package/types/display/canvas.d.ts +1 -1
- package/types/display/display_utils.d.ts +96 -95
- package/types/display/fetch_stream.d.ts +2 -2
- package/types/display/metadata.d.ts +4 -0
- package/types/display/pattern_helper.d.ts +1 -1
- package/types/display/text_layer.d.ts +7 -7
- package/types/display/transport_stream.d.ts +1 -1
- package/types/shared/scripting_utils.d.ts +12 -0
- package/types/shared/util.d.ts +281 -250
- package/types/shared/xml_parser.d.ts +64 -0
- package/web/pdf_viewer.css +18 -15
- package/web/pdf_viewer.js +809 -408
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -1
- package/types/display/xml_parser.d.ts +0 -35
package/lib/core/evaluator.js
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PartialEvaluator = void 0;
|
27
|
+
exports.PartialEvaluator = exports.EvaluatorPreprocessor = void 0;
|
28
28
|
|
29
29
|
var _util = require("../shared/util.js");
|
30
30
|
|
@@ -226,12 +226,16 @@ class PartialEvaluator {
|
|
226
226
|
return newEvaluator;
|
227
227
|
}
|
228
228
|
|
229
|
-
hasBlendModes(resources) {
|
229
|
+
hasBlendModes(resources, nonBlendModesSet) {
|
230
230
|
if (!(resources instanceof _primitives.Dict)) {
|
231
231
|
return false;
|
232
232
|
}
|
233
233
|
|
234
|
-
|
234
|
+
if (resources.objId && nonBlendModesSet.has(resources.objId)) {
|
235
|
+
return false;
|
236
|
+
}
|
237
|
+
|
238
|
+
const processed = new _primitives.RefSet(nonBlendModesSet);
|
235
239
|
|
236
240
|
if (resources.objId) {
|
237
241
|
processed.put(resources.objId);
|
@@ -343,6 +347,9 @@ class PartialEvaluator {
|
|
343
347
|
}
|
344
348
|
}
|
345
349
|
|
350
|
+
processed.forEach(ref => {
|
351
|
+
nonBlendModesSet.put(ref);
|
352
|
+
});
|
346
353
|
return false;
|
347
354
|
}
|
348
355
|
|
@@ -680,7 +687,7 @@ class PartialEvaluator {
|
|
680
687
|
return transferMaps;
|
681
688
|
}
|
682
689
|
|
683
|
-
handleTilingType(fn,
|
690
|
+
handleTilingType(fn, color, resources, pattern, patternDict, operatorList, task, cacheKey, localTilingPatternCache) {
|
684
691
|
const tilingOpList = new _operator_list.OperatorList();
|
685
692
|
|
686
693
|
const patternResources = _primitives.Dict.merge({
|
@@ -694,14 +701,18 @@ class PartialEvaluator {
|
|
694
701
|
resources: patternResources,
|
695
702
|
operatorList: tilingOpList
|
696
703
|
}).then(function () {
|
697
|
-
|
698
|
-
|
699
|
-
argsArray: tilingOpList.argsArray
|
700
|
-
}, patternDict, args);
|
701
|
-
}).then(function (tilingPatternIR) {
|
704
|
+
const operatorListIR = tilingOpList.getIR();
|
705
|
+
const tilingPatternIR = (0, _pattern.getTilingPatternIR)(operatorListIR, patternDict, color);
|
702
706
|
operatorList.addDependencies(tilingOpList.dependencies);
|
703
707
|
operatorList.addOp(fn, tilingPatternIR);
|
704
|
-
|
708
|
+
|
709
|
+
if (cacheKey) {
|
710
|
+
localTilingPatternCache.set(cacheKey, patternDict.objId, {
|
711
|
+
operatorListIR,
|
712
|
+
dict: patternDict
|
713
|
+
});
|
714
|
+
}
|
715
|
+
}).catch(reason => {
|
705
716
|
if (reason instanceof _util.AbortException) {
|
706
717
|
return;
|
707
718
|
}
|
@@ -718,17 +729,15 @@ class PartialEvaluator {
|
|
718
729
|
});
|
719
730
|
}
|
720
731
|
|
721
|
-
handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
|
722
|
-
var fontName
|
723
|
-
fontSize = 0;
|
732
|
+
handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null) {
|
733
|
+
var fontName;
|
724
734
|
|
725
735
|
if (fontArgs) {
|
726
736
|
fontArgs = fontArgs.slice();
|
727
737
|
fontName = fontArgs[0].name;
|
728
|
-
fontSize = fontArgs[1];
|
729
738
|
}
|
730
739
|
|
731
|
-
return this.loadFont(fontName, fontRef, resources).then(translated => {
|
740
|
+
return this.loadFont(fontName, fontRef, resources, fallbackFontDict).then(translated => {
|
732
741
|
if (!translated.font.isType3Font) {
|
733
742
|
return translated;
|
734
743
|
}
|
@@ -749,8 +758,6 @@ class PartialEvaluator {
|
|
749
758
|
});
|
750
759
|
}).then(translated => {
|
751
760
|
state.font = translated.font;
|
752
|
-
state.fontSize = fontSize;
|
753
|
-
state.fontName = fontName;
|
754
761
|
translated.send(this.handler);
|
755
762
|
return translated.loadedName;
|
756
763
|
});
|
@@ -895,14 +902,14 @@ class PartialEvaluator {
|
|
895
902
|
});
|
896
903
|
}
|
897
904
|
|
898
|
-
loadFont(fontName, font, resources) {
|
899
|
-
const errorFont = () => {
|
900
|
-
return
|
905
|
+
loadFont(fontName, font, resources, fallbackFontDict = null) {
|
906
|
+
const errorFont = async () => {
|
907
|
+
return new TranslatedFont({
|
901
908
|
loadedName: "g_font_error",
|
902
909
|
font: new _fonts.ErrorFont(`Font "${fontName}" is not available.`),
|
903
910
|
dict: font,
|
904
911
|
extraProperties: this.options.fontExtraProperties
|
905
|
-
})
|
912
|
+
});
|
906
913
|
};
|
907
914
|
|
908
915
|
var fontRef,
|
@@ -934,7 +941,12 @@ class PartialEvaluator {
|
|
934
941
|
featureId: _util.UNSUPPORTED_FEATURES.errorFontMissing
|
935
942
|
});
|
936
943
|
(0, _util.warn)(`${partialMsg} -- attempting to fallback to a default font.`);
|
937
|
-
|
944
|
+
|
945
|
+
if (fallbackFontDict) {
|
946
|
+
fontRef = fallbackFontDict;
|
947
|
+
} else {
|
948
|
+
fontRef = PartialEvaluator.fallbackFontDict;
|
949
|
+
}
|
938
950
|
}
|
939
951
|
|
940
952
|
if (this.fontCache.has(fontRef)) {
|
@@ -947,12 +959,20 @@ class PartialEvaluator {
|
|
947
959
|
return errorFont();
|
948
960
|
}
|
949
961
|
|
950
|
-
if (font.
|
951
|
-
return font.
|
962
|
+
if (font.cacheKey && this.fontCache.has(font.cacheKey)) {
|
963
|
+
return this.fontCache.get(font.cacheKey);
|
952
964
|
}
|
953
965
|
|
954
966
|
var fontCapability = (0, _util.createPromiseCapability)();
|
955
|
-
|
967
|
+
let preEvaluatedFont;
|
968
|
+
|
969
|
+
try {
|
970
|
+
preEvaluatedFont = this.preEvaluateFont(font);
|
971
|
+
} catch (reason) {
|
972
|
+
(0, _util.warn)(`loadFont - ignoring preEvaluateFont errors: "${reason}".`);
|
973
|
+
return errorFont();
|
974
|
+
}
|
975
|
+
|
956
976
|
const {
|
957
977
|
descriptor,
|
958
978
|
hash
|
@@ -998,21 +1018,13 @@ class PartialEvaluator {
|
|
998
1018
|
fontID = this.idFactory.createFontId();
|
999
1019
|
}
|
1000
1020
|
|
1001
|
-
|
1021
|
+
font.cacheKey = `cacheKey_${fontID}`;
|
1022
|
+
this.fontCache.put(font.cacheKey, fontCapability.promise);
|
1002
1023
|
}
|
1003
1024
|
|
1004
1025
|
(0, _util.assert)(fontID && fontID.startsWith("f"), 'The "fontID" must be (correctly) defined.');
|
1005
1026
|
font.loadedName = `${this.idFactory.getDocId()}_${fontID}`;
|
1006
|
-
|
1007
|
-
var translatedPromise;
|
1008
|
-
|
1009
|
-
try {
|
1010
|
-
translatedPromise = this.translateFont(preEvaluatedFont);
|
1011
|
-
} catch (e) {
|
1012
|
-
translatedPromise = Promise.reject(e);
|
1013
|
-
}
|
1014
|
-
|
1015
|
-
translatedPromise.then(translatedFont => {
|
1027
|
+
this.translateFont(preEvaluatedFont).then(translatedFont => {
|
1016
1028
|
if (translatedFont.fontType !== undefined) {
|
1017
1029
|
var xrefFontStats = xref.stats.fontTypes;
|
1018
1030
|
xrefFontStats[translatedFont.fontType] = true;
|
@@ -1100,26 +1112,45 @@ class PartialEvaluator {
|
|
1100
1112
|
});
|
1101
1113
|
}
|
1102
1114
|
|
1103
|
-
|
1104
|
-
|
1105
|
-
var pattern;
|
1115
|
+
handleColorN(operatorList, fn, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache) {
|
1116
|
+
const patternName = args.pop();
|
1106
1117
|
|
1107
|
-
if (
|
1108
|
-
|
1109
|
-
|
1118
|
+
if (patternName instanceof _primitives.Name) {
|
1119
|
+
const name = patternName.name;
|
1120
|
+
const localTilingPattern = localTilingPatternCache.getByName(name);
|
1110
1121
|
|
1111
|
-
if (
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1122
|
+
if (localTilingPattern) {
|
1123
|
+
try {
|
1124
|
+
const color = cs.base ? cs.base.getRgb(args, 0) : null;
|
1125
|
+
const tilingPatternIR = (0, _pattern.getTilingPatternIR)(localTilingPattern.operatorListIR, localTilingPattern.dict, color);
|
1126
|
+
operatorList.addOp(fn, tilingPatternIR);
|
1127
|
+
return undefined;
|
1128
|
+
} catch (ex) {
|
1129
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
1130
|
+
throw ex;
|
1131
|
+
}
|
1132
|
+
}
|
1120
1133
|
}
|
1121
1134
|
|
1122
|
-
|
1135
|
+
let pattern = patterns.get(name);
|
1136
|
+
|
1137
|
+
if (pattern) {
|
1138
|
+
var dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern;
|
1139
|
+
var typeNum = dict.get("PatternType");
|
1140
|
+
|
1141
|
+
if (typeNum === PatternType.TILING) {
|
1142
|
+
const color = cs.base ? cs.base.getRgb(args, 0) : null;
|
1143
|
+
return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, name, localTilingPatternCache);
|
1144
|
+
} else if (typeNum === PatternType.SHADING) {
|
1145
|
+
var shading = dict.get("Shading");
|
1146
|
+
var matrix = dict.getArray("Matrix");
|
1147
|
+
pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this._pdfFunctionFactory, localColorSpaceCache);
|
1148
|
+
operatorList.addOp(fn, pattern.getIR());
|
1149
|
+
return undefined;
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
throw new _util.FormatError(`Unknown PatternType: ${typeNum}`);
|
1153
|
+
}
|
1123
1154
|
}
|
1124
1155
|
|
1125
1156
|
throw new _util.FormatError(`Unknown PatternName: ${patternName}`);
|
@@ -1186,7 +1217,8 @@ class PartialEvaluator {
|
|
1186
1217
|
task,
|
1187
1218
|
resources,
|
1188
1219
|
operatorList,
|
1189
|
-
initialState = null
|
1220
|
+
initialState = null,
|
1221
|
+
fallbackFontDict = null
|
1190
1222
|
}) {
|
1191
1223
|
resources = resources || _primitives.Dict.empty;
|
1192
1224
|
initialState = initialState || new EvalState();
|
@@ -1201,6 +1233,7 @@ class PartialEvaluator {
|
|
1201
1233
|
const localImageCache = new _image_utils.LocalImageCache();
|
1202
1234
|
const localColorSpaceCache = new _image_utils.LocalColorSpaceCache();
|
1203
1235
|
const localGStateCache = new _image_utils.LocalGStateCache();
|
1236
|
+
const localTilingPatternCache = new _image_utils.LocalTilingPatternCache();
|
1204
1237
|
|
1205
1238
|
var xobjs = resources.get("XObject") || _primitives.Dict.empty;
|
1206
1239
|
|
@@ -1341,7 +1374,7 @@ class PartialEvaluator {
|
|
1341
1374
|
|
1342
1375
|
case _util.OPS.setFont:
|
1343
1376
|
var fontSize = args[1];
|
1344
|
-
next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
|
1377
|
+
next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state, fallbackFontDict).then(function (loadedName) {
|
1345
1378
|
operatorList.addDependency(loadedName);
|
1346
1379
|
operatorList.addOp(_util.OPS.setFont, [loadedName, fontSize]);
|
1347
1380
|
}));
|
@@ -1533,7 +1566,7 @@ class PartialEvaluator {
|
|
1533
1566
|
cs = stateManager.state.fillColorSpace;
|
1534
1567
|
|
1535
1568
|
if (cs.name === "Pattern") {
|
1536
|
-
next(self.handleColorN(operatorList, _util.OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache));
|
1569
|
+
next(self.handleColorN(operatorList, _util.OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache));
|
1537
1570
|
return;
|
1538
1571
|
}
|
1539
1572
|
|
@@ -1545,7 +1578,7 @@ class PartialEvaluator {
|
|
1545
1578
|
cs = stateManager.state.strokeColorSpace;
|
1546
1579
|
|
1547
1580
|
if (cs.name === "Pattern") {
|
1548
|
-
next(self.handleColorN(operatorList, _util.OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache));
|
1581
|
+
next(self.handleColorN(operatorList, _util.OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache));
|
1549
1582
|
return;
|
1550
1583
|
}
|
1551
1584
|
|
@@ -2875,6 +2908,11 @@ class PartialEvaluator {
|
|
2875
2908
|
}
|
2876
2909
|
|
2877
2910
|
dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
|
2911
|
+
|
2912
|
+
if (!(dict instanceof _primitives.Dict)) {
|
2913
|
+
throw new _util.FormatError("Descendant font is not a dictionary.");
|
2914
|
+
}
|
2915
|
+
|
2878
2916
|
type = dict.get("Subtype");
|
2879
2917
|
|
2880
2918
|
if (!(0, _primitives.isName)(type)) {
|
@@ -2950,7 +2988,7 @@ class PartialEvaluator {
|
|
2950
2988
|
};
|
2951
2989
|
}
|
2952
2990
|
|
2953
|
-
translateFont(preEvaluatedFont) {
|
2991
|
+
async translateFont(preEvaluatedFont) {
|
2954
2992
|
var baseDict = preEvaluatedFont.baseDict;
|
2955
2993
|
var dict = preEvaluatedFont.dict;
|
2956
2994
|
var composite = preEvaluatedFont.composite;
|
@@ -3022,7 +3060,7 @@ class PartialEvaluator {
|
|
3022
3060
|
var baseFontStr = baseFont && baseFont.name;
|
3023
3061
|
|
3024
3062
|
if (fontNameStr !== baseFontStr) {
|
3025
|
-
(0, _util.info)(`The FontDescriptor
|
3063
|
+
(0, _util.info)(`The FontDescriptor's FontName is "${fontNameStr}" but ` + `should be the same as the Font's BaseFont "${baseFontStr}".`);
|
3026
3064
|
|
3027
3065
|
if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) {
|
3028
3066
|
fontName = baseFont;
|
@@ -3075,30 +3113,24 @@ class PartialEvaluator {
|
|
3075
3113
|
italicAngle: descriptor.get("ItalicAngle"),
|
3076
3114
|
isType3Font: false
|
3077
3115
|
};
|
3078
|
-
var cMapPromise;
|
3079
3116
|
|
3080
3117
|
if (composite) {
|
3081
|
-
|
3118
|
+
const cidEncoding = baseDict.get("Encoding");
|
3082
3119
|
|
3083
3120
|
if ((0, _primitives.isName)(cidEncoding)) {
|
3084
3121
|
properties.cidEncoding = cidEncoding.name;
|
3085
3122
|
}
|
3086
3123
|
|
3087
|
-
|
3124
|
+
const cMap = await _cmap.CMapFactory.create({
|
3088
3125
|
encoding: cidEncoding,
|
3089
3126
|
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
|
3090
3127
|
useCMap: null
|
3091
|
-
}).then(function (cMap) {
|
3092
|
-
properties.cMap = cMap;
|
3093
|
-
properties.vertical = properties.cMap.vertical;
|
3094
3128
|
});
|
3095
|
-
|
3096
|
-
|
3129
|
+
properties.cMap = cMap;
|
3130
|
+
properties.vertical = properties.cMap.vertical;
|
3097
3131
|
}
|
3098
3132
|
|
3099
|
-
return
|
3100
|
-
return this.extractDataStructures(dict, baseDict, properties);
|
3101
|
-
}).then(newProperties => {
|
3133
|
+
return this.extractDataStructures(dict, baseDict, properties).then(newProperties => {
|
3102
3134
|
this.extractWidths(dict, descriptor, newProperties);
|
3103
3135
|
|
3104
3136
|
if (type === "Type3") {
|
@@ -3197,7 +3229,7 @@ class TranslatedFont {
|
|
3197
3229
|
var charProcOperatorList = Object.create(null);
|
3198
3230
|
|
3199
3231
|
for (const key of charProcs.getKeys()) {
|
3200
|
-
loadCharProcsPromise = loadCharProcsPromise.then(
|
3232
|
+
loadCharProcsPromise = loadCharProcsPromise.then(() => {
|
3201
3233
|
var glyphStream = charProcs.get(key);
|
3202
3234
|
var operatorList = new _operator_list.OperatorList();
|
3203
3235
|
return type3Evaluator.getOperatorList({
|
@@ -3205,7 +3237,11 @@ class TranslatedFont {
|
|
3205
3237
|
task,
|
3206
3238
|
resources: fontResources,
|
3207
3239
|
operatorList
|
3208
|
-
}).then(
|
3240
|
+
}).then(() => {
|
3241
|
+
if (operatorList.fnArray[0] === _util.OPS.setCharWidthAndBounds) {
|
3242
|
+
this._removeType3ColorOperators(operatorList);
|
3243
|
+
}
|
3244
|
+
|
3209
3245
|
charProcOperatorList[key] = operatorList.getIR();
|
3210
3246
|
|
3211
3247
|
for (const dependency of operatorList.dependencies) {
|
@@ -3225,10 +3261,66 @@ class TranslatedFont {
|
|
3225
3261
|
return this.type3Loaded;
|
3226
3262
|
}
|
3227
3263
|
|
3264
|
+
_removeType3ColorOperators(operatorList) {
|
3265
|
+
let i = 1,
|
3266
|
+
ii = operatorList.length;
|
3267
|
+
|
3268
|
+
while (i < ii) {
|
3269
|
+
switch (operatorList.fnArray[i]) {
|
3270
|
+
case _util.OPS.setStrokeColorSpace:
|
3271
|
+
case _util.OPS.setFillColorSpace:
|
3272
|
+
case _util.OPS.setStrokeColor:
|
3273
|
+
case _util.OPS.setStrokeColorN:
|
3274
|
+
case _util.OPS.setFillColor:
|
3275
|
+
case _util.OPS.setFillColorN:
|
3276
|
+
case _util.OPS.setStrokeGray:
|
3277
|
+
case _util.OPS.setFillGray:
|
3278
|
+
case _util.OPS.setStrokeRGBColor:
|
3279
|
+
case _util.OPS.setFillRGBColor:
|
3280
|
+
case _util.OPS.setStrokeCMYKColor:
|
3281
|
+
case _util.OPS.setFillCMYKColor:
|
3282
|
+
case _util.OPS.shadingFill:
|
3283
|
+
case _util.OPS.setRenderingIntent:
|
3284
|
+
operatorList.fnArray.splice(i, 1);
|
3285
|
+
operatorList.argsArray.splice(i, 1);
|
3286
|
+
ii--;
|
3287
|
+
continue;
|
3288
|
+
|
3289
|
+
case _util.OPS.setGState:
|
3290
|
+
const [gStateObj] = operatorList.argsArray[i];
|
3291
|
+
let j = 0,
|
3292
|
+
jj = gStateObj.length;
|
3293
|
+
|
3294
|
+
while (j < jj) {
|
3295
|
+
const [gStateKey] = gStateObj[j];
|
3296
|
+
|
3297
|
+
switch (gStateKey) {
|
3298
|
+
case "TR":
|
3299
|
+
case "TR2":
|
3300
|
+
case "HT":
|
3301
|
+
case "BG":
|
3302
|
+
case "BG2":
|
3303
|
+
case "UCR":
|
3304
|
+
case "UCR2":
|
3305
|
+
gStateObj.splice(j, 1);
|
3306
|
+
jj--;
|
3307
|
+
continue;
|
3308
|
+
}
|
3309
|
+
|
3310
|
+
j++;
|
3311
|
+
}
|
3312
|
+
|
3313
|
+
break;
|
3314
|
+
}
|
3315
|
+
|
3316
|
+
i++;
|
3317
|
+
}
|
3318
|
+
}
|
3319
|
+
|
3228
3320
|
}
|
3229
3321
|
|
3230
3322
|
class StateManager {
|
3231
|
-
constructor(initialState) {
|
3323
|
+
constructor(initialState = new EvalState()) {
|
3232
3324
|
this.state = initialState;
|
3233
3325
|
this.stateStack = [];
|
3234
3326
|
}
|
@@ -3761,7 +3853,7 @@ class EvaluatorPreprocessor {
|
|
3761
3853
|
return (0, _util.shadow)(this, "MAX_INVALID_PATH_OPS", 20);
|
3762
3854
|
}
|
3763
3855
|
|
3764
|
-
constructor(stream, xref, stateManager) {
|
3856
|
+
constructor(stream, xref, stateManager = new StateManager()) {
|
3765
3857
|
this.parser = new _parser.Parser({
|
3766
3858
|
lexer: new _parser.Lexer(stream, EvaluatorPreprocessor.opMap),
|
3767
3859
|
xref
|
@@ -3872,4 +3964,6 @@ class EvaluatorPreprocessor {
|
|
3872
3964
|
}
|
3873
3965
|
}
|
3874
3966
|
|
3875
|
-
}
|
3967
|
+
}
|
3968
|
+
|
3969
|
+
exports.EvaluatorPreprocessor = EvaluatorPreprocessor;
|
package/lib/core/fonts.js
CHANGED
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
25
25
|
value: true
|
26
26
|
});
|
27
27
|
exports.getFontType = getFontType;
|
28
|
-
exports.
|
28
|
+
exports.ToUnicodeMap = exports.SEAC_ANALYSIS_ENABLED = exports.IdentityToUnicodeMap = exports.FontFlags = exports.Font = exports.ErrorFont = void 0;
|
29
29
|
|
30
30
|
var _util = require("../shared/util.js");
|
31
31
|
|
@@ -435,6 +435,7 @@ var Font = function FontClosure() {
|
|
435
435
|
this.defaultWidth = properties.defaultWidth;
|
436
436
|
this.composite = properties.composite;
|
437
437
|
this.cMap = properties.cMap;
|
438
|
+
this.capHeight = properties.capHeight / PDF_GLYPH_SPACE_UNITS;
|
438
439
|
this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
|
439
440
|
this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
|
440
441
|
this.fontMatrix = properties.fontMatrix;
|
@@ -466,7 +467,7 @@ var Font = function FontClosure() {
|
|
466
467
|
(0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ")");
|
467
468
|
}
|
468
469
|
|
469
|
-
this.fallbackToSystemFont();
|
470
|
+
this.fallbackToSystemFont(properties);
|
470
471
|
return;
|
471
472
|
}
|
472
473
|
|
@@ -509,7 +510,7 @@ var Font = function FontClosure() {
|
|
509
510
|
}
|
510
511
|
} catch (e) {
|
511
512
|
(0, _util.warn)(e);
|
512
|
-
this.fallbackToSystemFont();
|
513
|
+
this.fallbackToSystemFont(properties);
|
513
514
|
return;
|
514
515
|
}
|
515
516
|
|
@@ -1020,7 +1021,7 @@ var Font = function FontClosure() {
|
|
1020
1021
|
return data;
|
1021
1022
|
},
|
1022
1023
|
|
1023
|
-
fallbackToSystemFont
|
1024
|
+
fallbackToSystemFont(properties) {
|
1024
1025
|
this.missingFile = true;
|
1025
1026
|
var name = this.name;
|
1026
1027
|
var type = this.type;
|
@@ -1028,15 +1029,18 @@ var Font = function FontClosure() {
|
|
1028
1029
|
let fontName = name.replace(/[,_]/g, "-").replace(/\s/g, "");
|
1029
1030
|
var stdFontMap = (0, _standard_fonts.getStdFontMap)(),
|
1030
1031
|
nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();
|
1031
|
-
|
1032
|
+
const isStandardFont = !!stdFontMap[fontName];
|
1033
|
+
const isMappedToStandardFont = !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
|
1032
1034
|
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
|
1033
1035
|
this.bold = fontName.search(/bold/gi) !== -1;
|
1034
1036
|
this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
|
1035
1037
|
this.black = name.search(/Black/g) !== -1;
|
1036
|
-
|
1038
|
+
const isNarrow = name.search(/Narrow/g) !== -1;
|
1039
|
+
this.remeasure = (!isStandardFont || isNarrow) && Object.keys(this.widths).length > 0;
|
1037
1040
|
|
1038
|
-
if (isStandardFont && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
|
1039
|
-
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)()
|
1041
|
+
if ((isStandardFont || isMappedToStandardFont) && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
|
1042
|
+
const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)(),
|
1043
|
+
cidToGidMap = properties.cidToGidMap;
|
1040
1044
|
const map = [];
|
1041
1045
|
|
1042
1046
|
for (const charCode in GlyphMapForStandardFonts) {
|
@@ -1057,6 +1061,16 @@ var Font = function FontClosure() {
|
|
1057
1061
|
}
|
1058
1062
|
}
|
1059
1063
|
|
1064
|
+
if (cidToGidMap) {
|
1065
|
+
for (const charCode in map) {
|
1066
|
+
const cid = map[charCode];
|
1067
|
+
|
1068
|
+
if (cidToGidMap[cid] !== undefined) {
|
1069
|
+
map[+charCode] = cidToGidMap[cid];
|
1070
|
+
}
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
|
1060
1074
|
var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
|
1061
1075
|
|
1062
1076
|
if (!isIdentityUnicode) {
|
@@ -1109,6 +1123,7 @@ var Font = function FontClosure() {
|
|
1109
1123
|
this.loadedName = fontName.split("-")[0];
|
1110
1124
|
this.fontType = getFontType(type, subtype);
|
1111
1125
|
},
|
1126
|
+
|
1112
1127
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
1113
1128
|
const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
|
1114
1129
|
|
@@ -2641,7 +2656,7 @@ var Font = function FontClosure() {
|
|
2641
2656
|
return (0, _util.shadow)(this, "spaceWidth", width);
|
2642
2657
|
},
|
2643
2658
|
|
2644
|
-
|
2659
|
+
_charToGlyph(charcode, isSpace = false) {
|
2645
2660
|
var fontCharCode, width, operatorListId;
|
2646
2661
|
var widthCode = charcode;
|
2647
2662
|
|
@@ -2706,6 +2721,7 @@ var Font = function FontClosure() {
|
|
2706
2721
|
|
2707
2722
|
return glyph;
|
2708
2723
|
},
|
2724
|
+
|
2709
2725
|
charsToGlyphs: function Font_charsToGlyphs(chars) {
|
2710
2726
|
var charsCache = this.charsCache;
|
2711
2727
|
var glyphs, glyph, charcode;
|
@@ -2736,13 +2752,13 @@ var Font = function FontClosure() {
|
|
2736
2752
|
var length = c.length;
|
2737
2753
|
i += length;
|
2738
2754
|
var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
|
2739
|
-
glyph = this.
|
2755
|
+
glyph = this._charToGlyph(charcode, isSpace);
|
2740
2756
|
glyphs.push(glyph);
|
2741
2757
|
}
|
2742
2758
|
} else {
|
2743
2759
|
for (i = 0, ii = chars.length; i < ii; ++i) {
|
2744
2760
|
charcode = chars.charCodeAt(i);
|
2745
|
-
glyph = this.
|
2761
|
+
glyph = this._charToGlyph(charcode, charcode === 0x20);
|
2746
2762
|
glyphs.push(glyph);
|
2747
2763
|
}
|
2748
2764
|
}
|
@@ -2750,8 +2766,75 @@ var Font = function FontClosure() {
|
|
2750
2766
|
return charsCache[charsCacheKey] = glyphs;
|
2751
2767
|
},
|
2752
2768
|
|
2769
|
+
getCharPositions(chars) {
|
2770
|
+
const positions = [];
|
2771
|
+
|
2772
|
+
if (this.cMap) {
|
2773
|
+
const c = Object.create(null);
|
2774
|
+
let i = 0;
|
2775
|
+
|
2776
|
+
while (i < chars.length) {
|
2777
|
+
this.cMap.readCharCode(chars, i, c);
|
2778
|
+
const length = c.length;
|
2779
|
+
positions.push([i, i + length]);
|
2780
|
+
i += length;
|
2781
|
+
}
|
2782
|
+
} else {
|
2783
|
+
for (let i = 0, ii = chars.length; i < ii; ++i) {
|
2784
|
+
positions.push([i, i + 1]);
|
2785
|
+
}
|
2786
|
+
}
|
2787
|
+
|
2788
|
+
return positions;
|
2789
|
+
},
|
2790
|
+
|
2753
2791
|
get glyphCacheValues() {
|
2754
2792
|
return Object.values(this.glyphCache);
|
2793
|
+
},
|
2794
|
+
|
2795
|
+
encodeString(str) {
|
2796
|
+
const buffers = [];
|
2797
|
+
const currentBuf = [];
|
2798
|
+
|
2799
|
+
const hasCurrentBufErrors = () => buffers.length % 2 === 1;
|
2800
|
+
|
2801
|
+
for (let i = 0, ii = str.length; i < ii; i++) {
|
2802
|
+
const unicode = str.codePointAt(i);
|
2803
|
+
|
2804
|
+
if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
|
2805
|
+
i++;
|
2806
|
+
}
|
2807
|
+
|
2808
|
+
if (this.toUnicode) {
|
2809
|
+
const char = String.fromCodePoint(unicode);
|
2810
|
+
const charCode = this.toUnicode.charCodeOf(char);
|
2811
|
+
|
2812
|
+
if (charCode !== -1) {
|
2813
|
+
if (hasCurrentBufErrors()) {
|
2814
|
+
buffers.push(currentBuf.join(""));
|
2815
|
+
currentBuf.length = 0;
|
2816
|
+
}
|
2817
|
+
|
2818
|
+
const charCodeLength = this.cMap ? this.cMap.getCharCodeLength(charCode) : 1;
|
2819
|
+
|
2820
|
+
for (let j = charCodeLength - 1; j >= 0; j--) {
|
2821
|
+
currentBuf.push(String.fromCharCode(charCode >> 8 * j & 0xff));
|
2822
|
+
}
|
2823
|
+
|
2824
|
+
continue;
|
2825
|
+
}
|
2826
|
+
}
|
2827
|
+
|
2828
|
+
if (!hasCurrentBufErrors()) {
|
2829
|
+
buffers.push(currentBuf.join(""));
|
2830
|
+
currentBuf.length = 0;
|
2831
|
+
}
|
2832
|
+
|
2833
|
+
currentBuf.push(String.fromCodePoint(unicode));
|
2834
|
+
}
|
2835
|
+
|
2836
|
+
buffers.push(currentBuf.join(""));
|
2837
|
+
return buffers;
|
2755
2838
|
}
|
2756
2839
|
|
2757
2840
|
};
|
@@ -2771,6 +2854,9 @@ var ErrorFont = function ErrorFontClosure() {
|
|
2771
2854
|
charsToGlyphs: function ErrorFont_charsToGlyphs() {
|
2772
2855
|
return [];
|
2773
2856
|
},
|
2857
|
+
encodeString: function ErrorFont_encodeString(chars) {
|
2858
|
+
return [chars];
|
2859
|
+
},
|
2774
2860
|
|
2775
2861
|
exportData(extraProperties = false) {
|
2776
2862
|
return {
|