pdfjs-dist 2.2.228 → 2.6.347
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 +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
package/lib/core/annotation.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -24,195 +24,194 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
+
exports.getQuadPoints = getQuadPoints;
|
27
28
|
exports.MarkupAnnotation = exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = void 0;
|
28
29
|
|
29
|
-
var _util = require("../shared/util");
|
30
|
+
var _util = require("../shared/util.js");
|
30
31
|
|
31
|
-
var _obj = require("./obj");
|
32
|
+
var _obj = require("./obj.js");
|
32
33
|
|
33
|
-
var _primitives = require("./primitives");
|
34
|
+
var _primitives = require("./primitives.js");
|
34
35
|
|
35
|
-
var _colorspace = require("./colorspace");
|
36
|
+
var _colorspace = require("./colorspace.js");
|
36
37
|
|
37
|
-
var _core_utils = require("./core_utils");
|
38
|
+
var _core_utils = require("./core_utils.js");
|
38
39
|
|
39
|
-
var _operator_list = require("./operator_list");
|
40
|
+
var _operator_list = require("./operator_list.js");
|
40
41
|
|
41
|
-
var _stream = require("./stream");
|
42
|
+
var _stream = require("./stream.js");
|
42
43
|
|
43
|
-
|
44
|
+
var _writer = require("./writer.js");
|
44
45
|
|
45
|
-
|
46
|
+
class AnnotationFactory {
|
47
|
+
static create(xref, ref, pdfManager, idFactory) {
|
48
|
+
return pdfManager.ensureCatalog("acroForm").then(acroForm => {
|
49
|
+
return pdfManager.ensure(this, "_create", [xref, ref, pdfManager, idFactory, acroForm]);
|
50
|
+
});
|
51
|
+
}
|
46
52
|
|
47
|
-
|
53
|
+
static _create(xref, ref, pdfManager, idFactory, acroForm) {
|
54
|
+
const dict = xref.fetchIfRef(ref);
|
48
55
|
|
49
|
-
|
56
|
+
if (!(0, _primitives.isDict)(dict)) {
|
57
|
+
return undefined;
|
58
|
+
}
|
50
59
|
|
51
|
-
|
60
|
+
const id = (0, _primitives.isRef)(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
|
61
|
+
let subtype = dict.get("Subtype");
|
62
|
+
subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
|
63
|
+
const parameters = {
|
64
|
+
xref,
|
65
|
+
ref,
|
66
|
+
dict,
|
67
|
+
subtype,
|
68
|
+
id,
|
69
|
+
pdfManager,
|
70
|
+
acroForm: acroForm instanceof _primitives.Dict ? acroForm : _primitives.Dict.empty
|
71
|
+
};
|
52
72
|
|
53
|
-
|
73
|
+
switch (subtype) {
|
74
|
+
case "Link":
|
75
|
+
return new LinkAnnotation(parameters);
|
54
76
|
|
55
|
-
|
77
|
+
case "Text":
|
78
|
+
return new TextAnnotation(parameters);
|
56
79
|
|
57
|
-
|
80
|
+
case "Widget":
|
81
|
+
let fieldType = (0, _core_utils.getInheritableProperty)({
|
82
|
+
dict,
|
83
|
+
key: "FT"
|
84
|
+
});
|
85
|
+
fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
|
58
86
|
|
59
|
-
|
87
|
+
switch (fieldType) {
|
88
|
+
case "Tx":
|
89
|
+
return new TextWidgetAnnotation(parameters);
|
60
90
|
|
61
|
-
|
91
|
+
case "Btn":
|
92
|
+
return new ButtonWidgetAnnotation(parameters);
|
62
93
|
|
63
|
-
|
94
|
+
case "Ch":
|
95
|
+
return new ChoiceWidgetAnnotation(parameters);
|
96
|
+
}
|
64
97
|
|
65
|
-
|
66
|
-
|
67
|
-
function () {
|
68
|
-
function AnnotationFactory() {
|
69
|
-
_classCallCheck(this, AnnotationFactory);
|
70
|
-
}
|
98
|
+
(0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + "falling back to base field type.");
|
99
|
+
return new WidgetAnnotation(parameters);
|
71
100
|
|
72
|
-
|
73
|
-
|
74
|
-
value: function create(xref, ref, pdfManager, idFactory) {
|
75
|
-
return pdfManager.ensure(this, '_create', [xref, ref, pdfManager, idFactory]);
|
76
|
-
}
|
77
|
-
}, {
|
78
|
-
key: "_create",
|
79
|
-
value: function _create(xref, ref, pdfManager, idFactory) {
|
80
|
-
var dict = xref.fetchIfRef(ref);
|
101
|
+
case "Popup":
|
102
|
+
return new PopupAnnotation(parameters);
|
81
103
|
|
82
|
-
|
83
|
-
return
|
84
|
-
}
|
104
|
+
case "FreeText":
|
105
|
+
return new FreeTextAnnotation(parameters);
|
85
106
|
|
86
|
-
|
87
|
-
|
88
|
-
subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
|
89
|
-
var parameters = {
|
90
|
-
xref: xref,
|
91
|
-
dict: dict,
|
92
|
-
subtype: subtype,
|
93
|
-
id: id,
|
94
|
-
pdfManager: pdfManager
|
95
|
-
};
|
96
|
-
|
97
|
-
switch (subtype) {
|
98
|
-
case 'Link':
|
99
|
-
return new LinkAnnotation(parameters);
|
100
|
-
|
101
|
-
case 'Text':
|
102
|
-
return new TextAnnotation(parameters);
|
103
|
-
|
104
|
-
case 'Widget':
|
105
|
-
var fieldType = (0, _core_utils.getInheritableProperty)({
|
106
|
-
dict: dict,
|
107
|
-
key: 'FT'
|
108
|
-
});
|
109
|
-
fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
|
110
|
-
|
111
|
-
switch (fieldType) {
|
112
|
-
case 'Tx':
|
113
|
-
return new TextWidgetAnnotation(parameters);
|
114
|
-
|
115
|
-
case 'Btn':
|
116
|
-
return new ButtonWidgetAnnotation(parameters);
|
117
|
-
|
118
|
-
case 'Ch':
|
119
|
-
return new ChoiceWidgetAnnotation(parameters);
|
120
|
-
}
|
107
|
+
case "Line":
|
108
|
+
return new LineAnnotation(parameters);
|
121
109
|
|
122
|
-
|
123
|
-
|
110
|
+
case "Square":
|
111
|
+
return new SquareAnnotation(parameters);
|
124
112
|
|
125
|
-
|
126
|
-
|
113
|
+
case "Circle":
|
114
|
+
return new CircleAnnotation(parameters);
|
127
115
|
|
128
|
-
|
129
|
-
|
116
|
+
case "PolyLine":
|
117
|
+
return new PolylineAnnotation(parameters);
|
130
118
|
|
131
|
-
|
132
|
-
|
119
|
+
case "Polygon":
|
120
|
+
return new PolygonAnnotation(parameters);
|
133
121
|
|
134
|
-
|
135
|
-
|
122
|
+
case "Caret":
|
123
|
+
return new CaretAnnotation(parameters);
|
136
124
|
|
137
|
-
|
138
|
-
|
125
|
+
case "Ink":
|
126
|
+
return new InkAnnotation(parameters);
|
139
127
|
|
140
|
-
|
141
|
-
|
128
|
+
case "Highlight":
|
129
|
+
return new HighlightAnnotation(parameters);
|
142
130
|
|
143
|
-
|
144
|
-
|
131
|
+
case "Underline":
|
132
|
+
return new UnderlineAnnotation(parameters);
|
145
133
|
|
146
|
-
|
147
|
-
|
134
|
+
case "Squiggly":
|
135
|
+
return new SquigglyAnnotation(parameters);
|
148
136
|
|
149
|
-
|
150
|
-
|
137
|
+
case "StrikeOut":
|
138
|
+
return new StrikeOutAnnotation(parameters);
|
151
139
|
|
152
|
-
|
153
|
-
|
140
|
+
case "Stamp":
|
141
|
+
return new StampAnnotation(parameters);
|
154
142
|
|
155
|
-
|
156
|
-
|
143
|
+
case "FileAttachment":
|
144
|
+
return new FileAttachmentAnnotation(parameters);
|
157
145
|
|
158
|
-
|
159
|
-
|
146
|
+
default:
|
147
|
+
if (!subtype) {
|
148
|
+
(0, _util.warn)("Annotation is missing the required /Subtype.");
|
149
|
+
} else {
|
150
|
+
(0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + "falling back to base annotation.");
|
151
|
+
}
|
160
152
|
|
161
|
-
|
162
|
-
|
153
|
+
return new Annotation(parameters);
|
154
|
+
}
|
155
|
+
}
|
163
156
|
|
164
|
-
|
165
|
-
return new StampAnnotation(parameters);
|
157
|
+
}
|
166
158
|
|
167
|
-
|
168
|
-
return new FileAttachmentAnnotation(parameters);
|
159
|
+
exports.AnnotationFactory = AnnotationFactory;
|
169
160
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
161
|
+
function getQuadPoints(dict, rect) {
|
162
|
+
if (!dict.has("QuadPoints")) {
|
163
|
+
return null;
|
164
|
+
}
|
165
|
+
|
166
|
+
const quadPoints = dict.getArray("QuadPoints");
|
167
|
+
|
168
|
+
if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) {
|
169
|
+
return null;
|
170
|
+
}
|
171
|
+
|
172
|
+
const quadPointsLists = [];
|
173
|
+
|
174
|
+
for (let i = 0, ii = quadPoints.length / 8; i < ii; i++) {
|
175
|
+
quadPointsLists.push([]);
|
176
176
|
|
177
|
-
|
177
|
+
for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
|
178
|
+
const x = quadPoints[j];
|
179
|
+
const y = quadPoints[j + 1];
|
180
|
+
|
181
|
+
if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) {
|
182
|
+
return null;
|
178
183
|
}
|
179
|
-
}
|
180
|
-
}]);
|
181
184
|
|
182
|
-
|
183
|
-
|
185
|
+
quadPointsLists[i].push({
|
186
|
+
x,
|
187
|
+
y
|
188
|
+
});
|
189
|
+
}
|
190
|
+
}
|
184
191
|
|
185
|
-
|
192
|
+
return quadPointsLists;
|
193
|
+
}
|
186
194
|
|
187
195
|
function getTransformMatrix(rect, bbox, matrix) {
|
188
|
-
|
189
|
-
|
190
|
-
var minX = bounds[0];
|
191
|
-
var minY = bounds[1];
|
192
|
-
var maxX = bounds[2];
|
193
|
-
var maxY = bounds[3];
|
196
|
+
const [minX, minY, maxX, maxY] = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
|
194
197
|
|
195
198
|
if (minX === maxX || minY === maxY) {
|
196
199
|
return [1, 0, 0, 1, rect[0], rect[1]];
|
197
200
|
}
|
198
201
|
|
199
|
-
|
200
|
-
|
202
|
+
const xRatio = (rect[2] - rect[0]) / (maxX - minX);
|
203
|
+
const yRatio = (rect[3] - rect[1]) / (maxY - minY);
|
201
204
|
return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
|
202
205
|
}
|
203
206
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
this.
|
212
|
-
this.setModificationDate(dict.get('M'));
|
213
|
-
this.setFlags(dict.get('F'));
|
214
|
-
this.setRectangle(dict.getArray('Rect'));
|
215
|
-
this.setColor(dict.getArray('C'));
|
207
|
+
class Annotation {
|
208
|
+
constructor(params) {
|
209
|
+
const dict = params.dict;
|
210
|
+
this.setContents(dict.get("Contents"));
|
211
|
+
this.setModificationDate(dict.get("M"));
|
212
|
+
this.setFlags(dict.get("F"));
|
213
|
+
this.setRectangle(dict.getArray("Rect"));
|
214
|
+
this.setColor(dict.getArray("C"));
|
216
215
|
this.setBorderStyle(dict);
|
217
216
|
this.setAppearance(dict);
|
218
217
|
this.data = {
|
@@ -228,228 +227,207 @@ function () {
|
|
228
227
|
};
|
229
228
|
}
|
230
229
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}, {
|
247
|
-
key: "setContents",
|
248
|
-
value: function setContents(contents) {
|
249
|
-
this.contents = (0, _util.stringToPDFString)(contents || '');
|
250
|
-
}
|
251
|
-
}, {
|
252
|
-
key: "setModificationDate",
|
253
|
-
value: function setModificationDate(modificationDate) {
|
254
|
-
this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null;
|
255
|
-
}
|
256
|
-
}, {
|
257
|
-
key: "setFlags",
|
258
|
-
value: function setFlags(flags) {
|
259
|
-
this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
|
260
|
-
}
|
261
|
-
}, {
|
262
|
-
key: "hasFlag",
|
263
|
-
value: function hasFlag(flag) {
|
264
|
-
return this._hasFlag(this.flags, flag);
|
265
|
-
}
|
266
|
-
}, {
|
267
|
-
key: "setRectangle",
|
268
|
-
value: function setRectangle(rectangle) {
|
269
|
-
if (Array.isArray(rectangle) && rectangle.length === 4) {
|
270
|
-
this.rectangle = _util.Util.normalizeRect(rectangle);
|
271
|
-
} else {
|
272
|
-
this.rectangle = [0, 0, 0, 0];
|
273
|
-
}
|
230
|
+
_hasFlag(flags, flag) {
|
231
|
+
return !!(flags & flag);
|
232
|
+
}
|
233
|
+
|
234
|
+
_isViewable(flags) {
|
235
|
+
return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
|
236
|
+
}
|
237
|
+
|
238
|
+
_isPrintable(flags) {
|
239
|
+
return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
|
240
|
+
}
|
241
|
+
|
242
|
+
get viewable() {
|
243
|
+
if (this.flags === 0) {
|
244
|
+
return true;
|
274
245
|
}
|
275
|
-
}, {
|
276
|
-
key: "setColor",
|
277
|
-
value: function setColor(color) {
|
278
|
-
var rgbColor = new Uint8ClampedArray(3);
|
279
246
|
|
280
|
-
|
281
|
-
|
282
|
-
return;
|
283
|
-
}
|
247
|
+
return this._isViewable(this.flags);
|
248
|
+
}
|
284
249
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
250
|
+
get printable() {
|
251
|
+
if (this.flags === 0) {
|
252
|
+
return false;
|
253
|
+
}
|
289
254
|
|
290
|
-
|
291
|
-
|
255
|
+
return this._isPrintable(this.flags);
|
256
|
+
}
|
292
257
|
|
293
|
-
|
294
|
-
|
258
|
+
setContents(contents) {
|
259
|
+
this.contents = (0, _util.stringToPDFString)(contents || "");
|
260
|
+
}
|
295
261
|
|
296
|
-
|
297
|
-
|
262
|
+
setModificationDate(modificationDate) {
|
263
|
+
this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null;
|
264
|
+
}
|
298
265
|
|
299
|
-
|
300
|
-
|
266
|
+
setFlags(flags) {
|
267
|
+
this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
|
268
|
+
}
|
301
269
|
|
302
|
-
|
303
|
-
|
270
|
+
hasFlag(flag) {
|
271
|
+
return this._hasFlag(this.flags, flag);
|
272
|
+
}
|
304
273
|
|
305
|
-
|
306
|
-
|
274
|
+
setRectangle(rectangle) {
|
275
|
+
if (Array.isArray(rectangle) && rectangle.length === 4) {
|
276
|
+
this.rectangle = _util.Util.normalizeRect(rectangle);
|
277
|
+
} else {
|
278
|
+
this.rectangle = [0, 0, 0, 0];
|
279
|
+
}
|
280
|
+
}
|
307
281
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
282
|
+
setColor(color) {
|
283
|
+
const rgbColor = new Uint8ClampedArray(3);
|
284
|
+
|
285
|
+
if (!Array.isArray(color)) {
|
286
|
+
this.color = rgbColor;
|
287
|
+
return;
|
312
288
|
}
|
313
|
-
}, {
|
314
|
-
key: "setBorderStyle",
|
315
|
-
value: function setBorderStyle(borderStyle) {
|
316
|
-
this.borderStyle = new AnnotationBorderStyle();
|
317
289
|
|
318
|
-
|
319
|
-
|
320
|
-
|
290
|
+
switch (color.length) {
|
291
|
+
case 0:
|
292
|
+
this.color = null;
|
293
|
+
break;
|
321
294
|
|
322
|
-
|
323
|
-
|
324
|
-
var dictType = dict.get('Type');
|
295
|
+
case 1:
|
296
|
+
_colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
|
325
297
|
|
326
|
-
|
327
|
-
|
328
|
-
this.borderStyle.setStyle(dict.get('S'));
|
329
|
-
this.borderStyle.setDashArray(dict.getArray('D'));
|
330
|
-
}
|
331
|
-
} else if (borderStyle.has('Border')) {
|
332
|
-
var array = borderStyle.getArray('Border');
|
298
|
+
this.color = rgbColor;
|
299
|
+
break;
|
333
300
|
|
334
|
-
|
335
|
-
|
336
|
-
this.borderStyle.setVerticalCornerRadius(array[1]);
|
337
|
-
this.borderStyle.setWidth(array[2], this.rectangle);
|
301
|
+
case 3:
|
302
|
+
_colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
|
338
303
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
304
|
+
this.color = rgbColor;
|
305
|
+
break;
|
306
|
+
|
307
|
+
case 4:
|
308
|
+
_colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
|
309
|
+
|
310
|
+
this.color = rgbColor;
|
311
|
+
break;
|
312
|
+
|
313
|
+
default:
|
314
|
+
this.color = rgbColor;
|
315
|
+
break;
|
346
316
|
}
|
347
|
-
}
|
348
|
-
key: "setAppearance",
|
349
|
-
value: function setAppearance(dict) {
|
350
|
-
this.appearance = null;
|
351
|
-
var appearanceStates = dict.get('AP');
|
317
|
+
}
|
352
318
|
|
353
|
-
|
354
|
-
|
355
|
-
}
|
319
|
+
setBorderStyle(borderStyle) {
|
320
|
+
this.borderStyle = new AnnotationBorderStyle();
|
356
321
|
|
357
|
-
|
322
|
+
if (!(0, _primitives.isDict)(borderStyle)) {
|
323
|
+
return;
|
324
|
+
}
|
358
325
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
}
|
326
|
+
if (borderStyle.has("BS")) {
|
327
|
+
const dict = borderStyle.get("BS");
|
328
|
+
const dictType = dict.get("Type");
|
363
329
|
|
364
|
-
if (!(0, _primitives.
|
365
|
-
|
330
|
+
if (!dictType || (0, _primitives.isName)(dictType, "Border")) {
|
331
|
+
this.borderStyle.setWidth(dict.get("W"), this.rectangle);
|
332
|
+
this.borderStyle.setStyle(dict.get("S"));
|
333
|
+
this.borderStyle.setDashArray(dict.getArray("D"));
|
366
334
|
}
|
335
|
+
} else if (borderStyle.has("Border")) {
|
336
|
+
const array = borderStyle.getArray("Border");
|
367
337
|
|
368
|
-
|
338
|
+
if (Array.isArray(array) && array.length >= 3) {
|
339
|
+
this.borderStyle.setHorizontalCornerRadius(array[0]);
|
340
|
+
this.borderStyle.setVerticalCornerRadius(array[1]);
|
341
|
+
this.borderStyle.setWidth(array[2], this.rectangle);
|
369
342
|
|
370
|
-
|
371
|
-
|
343
|
+
if (array.length === 4) {
|
344
|
+
this.borderStyle.setDashArray(array[3]);
|
345
|
+
}
|
372
346
|
}
|
373
|
-
|
374
|
-
this.
|
347
|
+
} else {
|
348
|
+
this.borderStyle.setWidth(0);
|
375
349
|
}
|
376
|
-
}
|
377
|
-
key: "loadResources",
|
378
|
-
value: function loadResources(keys) {
|
379
|
-
return this.appearance.dict.getAsync('Resources').then(function (resources) {
|
380
|
-
if (!resources) {
|
381
|
-
return undefined;
|
382
|
-
}
|
350
|
+
}
|
383
351
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
352
|
+
setAppearance(dict) {
|
353
|
+
this.appearance = null;
|
354
|
+
const appearanceStates = dict.get("AP");
|
355
|
+
|
356
|
+
if (!(0, _primitives.isDict)(appearanceStates)) {
|
357
|
+
return;
|
389
358
|
}
|
390
|
-
}, {
|
391
|
-
key: "getOperatorList",
|
392
|
-
value: function getOperatorList(evaluator, task, renderForms) {
|
393
|
-
var _this = this;
|
394
359
|
|
395
|
-
|
396
|
-
return Promise.resolve(new _operator_list.OperatorList());
|
397
|
-
}
|
360
|
+
const normalAppearanceState = appearanceStates.get("N");
|
398
361
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
|
403
|
-
var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
|
404
|
-
var transform = getTransformMatrix(data.rect, bbox, matrix);
|
405
|
-
return resourcesPromise.then(function (resources) {
|
406
|
-
var opList = new _operator_list.OperatorList();
|
407
|
-
opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
|
408
|
-
return evaluator.getOperatorList({
|
409
|
-
stream: _this.appearance,
|
410
|
-
task: task,
|
411
|
-
resources: resources,
|
412
|
-
operatorList: opList
|
413
|
-
}).then(function () {
|
414
|
-
opList.addOp(_util.OPS.endAnnotation, []);
|
415
|
-
|
416
|
-
_this.appearance.reset();
|
417
|
-
|
418
|
-
return opList;
|
419
|
-
});
|
420
|
-
});
|
362
|
+
if ((0, _primitives.isStream)(normalAppearanceState)) {
|
363
|
+
this.appearance = normalAppearanceState;
|
364
|
+
return;
|
421
365
|
}
|
422
|
-
}, {
|
423
|
-
key: "viewable",
|
424
|
-
get: function get() {
|
425
|
-
if (this.flags === 0) {
|
426
|
-
return true;
|
427
|
-
}
|
428
366
|
|
429
|
-
|
367
|
+
if (!(0, _primitives.isDict)(normalAppearanceState)) {
|
368
|
+
return;
|
369
|
+
}
|
370
|
+
|
371
|
+
const as = dict.get("AS");
|
372
|
+
|
373
|
+
if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
|
374
|
+
return;
|
430
375
|
}
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
376
|
+
|
377
|
+
this.appearance = normalAppearanceState.get(as.name);
|
378
|
+
}
|
379
|
+
|
380
|
+
loadResources(keys) {
|
381
|
+
return this.appearance.dict.getAsync("Resources").then(resources => {
|
382
|
+
if (!resources) {
|
383
|
+
return undefined;
|
436
384
|
}
|
437
385
|
|
438
|
-
|
386
|
+
const objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
|
387
|
+
return objectLoader.load().then(function () {
|
388
|
+
return resources;
|
389
|
+
});
|
390
|
+
});
|
391
|
+
}
|
392
|
+
|
393
|
+
getOperatorList(evaluator, task, renderForms, annotationStorage) {
|
394
|
+
if (!this.appearance) {
|
395
|
+
return Promise.resolve(new _operator_list.OperatorList());
|
439
396
|
}
|
440
|
-
}]);
|
441
397
|
|
442
|
-
|
443
|
-
|
398
|
+
const appearance = this.appearance;
|
399
|
+
const data = this.data;
|
400
|
+
const appearanceDict = appearance.dict;
|
401
|
+
const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
|
402
|
+
const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
|
403
|
+
const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
|
404
|
+
const transform = getTransformMatrix(data.rect, bbox, matrix);
|
405
|
+
return resourcesPromise.then(resources => {
|
406
|
+
const opList = new _operator_list.OperatorList();
|
407
|
+
opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
|
408
|
+
return evaluator.getOperatorList({
|
409
|
+
stream: appearance,
|
410
|
+
task,
|
411
|
+
resources,
|
412
|
+
operatorList: opList
|
413
|
+
}).then(() => {
|
414
|
+
opList.addOp(_util.OPS.endAnnotation, []);
|
415
|
+
appearance.reset();
|
416
|
+
return opList;
|
417
|
+
});
|
418
|
+
});
|
419
|
+
}
|
444
420
|
|
445
|
-
|
421
|
+
async save(evaluator, task, annotationStorage) {
|
422
|
+
return null;
|
423
|
+
}
|
446
424
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
function AnnotationBorderStyle() {
|
451
|
-
_classCallCheck(this, AnnotationBorderStyle);
|
425
|
+
}
|
426
|
+
|
427
|
+
exports.Annotation = Annotation;
|
452
428
|
|
429
|
+
class AnnotationBorderStyle {
|
430
|
+
constructor() {
|
453
431
|
this.width = 1;
|
454
432
|
this.style = _util.AnnotationBorderStyleType.SOLID;
|
455
433
|
this.dashArray = [3];
|
@@ -457,861 +435,1100 @@ function () {
|
|
457
435
|
this.verticalCornerRadius = 0;
|
458
436
|
}
|
459
437
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
if ((0, _primitives.isName)(width)) {
|
466
|
-
this.width = 0;
|
467
|
-
return;
|
468
|
-
}
|
438
|
+
setWidth(width, rect = [0, 0, 0, 0]) {
|
439
|
+
if ((0, _primitives.isName)(width)) {
|
440
|
+
this.width = 0;
|
441
|
+
return;
|
442
|
+
}
|
469
443
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
444
|
+
if (Number.isInteger(width)) {
|
445
|
+
if (width > 0) {
|
446
|
+
const maxWidth = (rect[2] - rect[0]) / 2;
|
447
|
+
const maxHeight = (rect[3] - rect[1]) / 2;
|
474
448
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
}
|
449
|
+
if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
|
450
|
+
(0, _util.warn)(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
|
451
|
+
width = 1;
|
479
452
|
}
|
480
|
-
|
481
|
-
this.width = width;
|
482
453
|
}
|
454
|
+
|
455
|
+
this.width = width;
|
483
456
|
}
|
484
|
-
}
|
485
|
-
key: "setStyle",
|
486
|
-
value: function setStyle(style) {
|
487
|
-
if (!(0, _primitives.isName)(style)) {
|
488
|
-
return;
|
489
|
-
}
|
457
|
+
}
|
490
458
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
459
|
+
setStyle(style) {
|
460
|
+
if (!(0, _primitives.isName)(style)) {
|
461
|
+
return;
|
462
|
+
}
|
495
463
|
|
496
|
-
|
497
|
-
|
498
|
-
|
464
|
+
switch (style.name) {
|
465
|
+
case "S":
|
466
|
+
this.style = _util.AnnotationBorderStyleType.SOLID;
|
467
|
+
break;
|
499
468
|
|
500
|
-
|
501
|
-
|
502
|
-
|
469
|
+
case "D":
|
470
|
+
this.style = _util.AnnotationBorderStyleType.DASHED;
|
471
|
+
break;
|
503
472
|
|
504
|
-
|
505
|
-
|
506
|
-
|
473
|
+
case "B":
|
474
|
+
this.style = _util.AnnotationBorderStyleType.BEVELED;
|
475
|
+
break;
|
507
476
|
|
508
|
-
|
509
|
-
|
510
|
-
|
477
|
+
case "I":
|
478
|
+
this.style = _util.AnnotationBorderStyleType.INSET;
|
479
|
+
break;
|
511
480
|
|
512
|
-
|
513
|
-
|
514
|
-
|
481
|
+
case "U":
|
482
|
+
this.style = _util.AnnotationBorderStyleType.UNDERLINE;
|
483
|
+
break;
|
484
|
+
|
485
|
+
default:
|
486
|
+
break;
|
515
487
|
}
|
516
|
-
}
|
517
|
-
key: "setDashArray",
|
518
|
-
value: function setDashArray(dashArray) {
|
519
|
-
if (Array.isArray(dashArray) && dashArray.length > 0) {
|
520
|
-
var isValid = true;
|
521
|
-
var allZeros = true;
|
522
|
-
|
523
|
-
for (var i = 0, len = dashArray.length; i < len; i++) {
|
524
|
-
var element = dashArray[i];
|
525
|
-
var validNumber = +element >= 0;
|
526
|
-
|
527
|
-
if (!validNumber) {
|
528
|
-
isValid = false;
|
529
|
-
break;
|
530
|
-
} else if (element > 0) {
|
531
|
-
allZeros = false;
|
532
|
-
}
|
533
|
-
}
|
488
|
+
}
|
534
489
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
490
|
+
setDashArray(dashArray) {
|
491
|
+
if (Array.isArray(dashArray) && dashArray.length > 0) {
|
492
|
+
let isValid = true;
|
493
|
+
let allZeros = true;
|
494
|
+
|
495
|
+
for (const element of dashArray) {
|
496
|
+
const validNumber = +element >= 0;
|
497
|
+
|
498
|
+
if (!validNumber) {
|
499
|
+
isValid = false;
|
500
|
+
break;
|
501
|
+
} else if (element > 0) {
|
502
|
+
allZeros = false;
|
539
503
|
}
|
540
|
-
}
|
504
|
+
}
|
505
|
+
|
506
|
+
if (isValid && !allZeros) {
|
507
|
+
this.dashArray = dashArray;
|
508
|
+
} else {
|
541
509
|
this.width = 0;
|
542
510
|
}
|
511
|
+
} else if (dashArray) {
|
512
|
+
this.width = 0;
|
543
513
|
}
|
544
|
-
}
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
}
|
514
|
+
}
|
515
|
+
|
516
|
+
setHorizontalCornerRadius(radius) {
|
517
|
+
if (Number.isInteger(radius)) {
|
518
|
+
this.horizontalCornerRadius = radius;
|
550
519
|
}
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
}
|
520
|
+
}
|
521
|
+
|
522
|
+
setVerticalCornerRadius(radius) {
|
523
|
+
if (Number.isInteger(radius)) {
|
524
|
+
this.verticalCornerRadius = radius;
|
557
525
|
}
|
558
|
-
}
|
526
|
+
}
|
559
527
|
|
560
|
-
|
561
|
-
}();
|
528
|
+
}
|
562
529
|
|
563
530
|
exports.AnnotationBorderStyle = AnnotationBorderStyle;
|
564
531
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
532
|
+
class MarkupAnnotation extends Annotation {
|
533
|
+
constructor(parameters) {
|
534
|
+
super(parameters);
|
535
|
+
const dict = parameters.dict;
|
569
536
|
|
570
|
-
|
571
|
-
|
537
|
+
if (dict.has("IRT")) {
|
538
|
+
const rawIRT = dict.getRaw("IRT");
|
539
|
+
this.data.inReplyTo = (0, _primitives.isRef)(rawIRT) ? rawIRT.toString() : null;
|
540
|
+
const rt = dict.get("RT");
|
541
|
+
this.data.replyType = (0, _primitives.isName)(rt) ? rt.name : _util.AnnotationReplyType.REPLY;
|
542
|
+
}
|
543
|
+
|
544
|
+
if (this.data.replyType === _util.AnnotationReplyType.GROUP) {
|
545
|
+
const parent = dict.get("IRT");
|
546
|
+
this.data.title = (0, _util.stringToPDFString)(parent.get("T") || "");
|
547
|
+
this.setContents(parent.get("Contents"));
|
548
|
+
this.data.contents = this.contents;
|
572
549
|
|
573
|
-
|
550
|
+
if (!parent.has("CreationDate")) {
|
551
|
+
this.data.creationDate = null;
|
552
|
+
} else {
|
553
|
+
this.setCreationDate(parent.get("CreationDate"));
|
554
|
+
this.data.creationDate = this.creationDate;
|
555
|
+
}
|
574
556
|
|
575
|
-
|
576
|
-
|
557
|
+
if (!parent.has("M")) {
|
558
|
+
this.data.modificationDate = null;
|
559
|
+
} else {
|
560
|
+
this.setModificationDate(parent.get("M"));
|
561
|
+
this.data.modificationDate = this.modificationDate;
|
562
|
+
}
|
577
563
|
|
578
|
-
|
579
|
-
_this2.data.color = null;
|
580
|
-
}
|
564
|
+
this.data.hasPopup = parent.has("Popup");
|
581
565
|
|
582
|
-
|
566
|
+
if (!parent.has("C")) {
|
567
|
+
this.data.color = null;
|
568
|
+
} else {
|
569
|
+
this.setColor(parent.getArray("C"));
|
570
|
+
this.data.color = this.color;
|
571
|
+
}
|
572
|
+
} else {
|
573
|
+
this.data.title = (0, _util.stringToPDFString)(dict.get("T") || "");
|
574
|
+
this.setCreationDate(dict.get("CreationDate"));
|
575
|
+
this.data.creationDate = this.creationDate;
|
576
|
+
this.data.hasPopup = dict.has("Popup");
|
583
577
|
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
578
|
+
if (!dict.has("C")) {
|
579
|
+
this.data.color = null;
|
580
|
+
}
|
581
|
+
}
|
588
582
|
}
|
589
583
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null;
|
594
|
-
}
|
595
|
-
}]);
|
584
|
+
setCreationDate(creationDate) {
|
585
|
+
this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null;
|
586
|
+
}
|
596
587
|
|
597
|
-
|
598
|
-
}(Annotation);
|
588
|
+
}
|
599
589
|
|
600
590
|
exports.MarkupAnnotation = MarkupAnnotation;
|
601
591
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
var _this3;
|
609
|
-
|
610
|
-
_classCallCheck(this, WidgetAnnotation);
|
611
|
-
|
612
|
-
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(WidgetAnnotation).call(this, params));
|
613
|
-
var dict = params.dict;
|
614
|
-
var data = _this3.data;
|
592
|
+
class WidgetAnnotation extends Annotation {
|
593
|
+
constructor(params) {
|
594
|
+
super(params);
|
595
|
+
const dict = params.dict;
|
596
|
+
const data = this.data;
|
597
|
+
this.ref = params.ref;
|
615
598
|
data.annotationType = _util.AnnotationType.WIDGET;
|
616
|
-
data.fieldName =
|
617
|
-
|
618
|
-
dict
|
619
|
-
key:
|
599
|
+
data.fieldName = this._constructFieldName(dict);
|
600
|
+
const fieldValue = (0, _core_utils.getInheritableProperty)({
|
601
|
+
dict,
|
602
|
+
key: "V",
|
620
603
|
getArray: true
|
621
604
|
});
|
622
|
-
data.
|
605
|
+
data.fieldValue = this._decodeFormValue(fieldValue);
|
606
|
+
data.alternativeText = (0, _util.stringToPDFString)(dict.get("TU") || "");
|
623
607
|
data.defaultAppearance = (0, _core_utils.getInheritableProperty)({
|
624
|
-
dict
|
625
|
-
key:
|
626
|
-
}) ||
|
627
|
-
|
628
|
-
dict
|
629
|
-
key:
|
608
|
+
dict,
|
609
|
+
key: "DA"
|
610
|
+
}) || params.acroForm.get("DA") || "";
|
611
|
+
const fieldType = (0, _core_utils.getInheritableProperty)({
|
612
|
+
dict,
|
613
|
+
key: "FT"
|
630
614
|
});
|
631
615
|
data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
|
632
|
-
|
633
|
-
dict
|
634
|
-
key:
|
635
|
-
}) || _primitives.Dict.empty;
|
616
|
+
this.fieldResources = (0, _core_utils.getInheritableProperty)({
|
617
|
+
dict,
|
618
|
+
key: "DR"
|
619
|
+
}) || params.acroForm.get("DR") || _primitives.Dict.empty;
|
636
620
|
data.fieldFlags = (0, _core_utils.getInheritableProperty)({
|
637
|
-
dict
|
638
|
-
key:
|
621
|
+
dict,
|
622
|
+
key: "Ff"
|
639
623
|
});
|
640
624
|
|
641
625
|
if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
|
642
626
|
data.fieldFlags = 0;
|
643
627
|
}
|
644
628
|
|
645
|
-
data.readOnly =
|
629
|
+
data.readOnly = this.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
|
646
630
|
|
647
|
-
if (data.fieldType ===
|
631
|
+
if (data.fieldType === "Sig") {
|
648
632
|
data.fieldValue = null;
|
649
|
-
|
650
|
-
_this3.setFlags(_util.AnnotationFlag.HIDDEN);
|
633
|
+
this.setFlags(_util.AnnotationFlag.HIDDEN);
|
651
634
|
}
|
652
|
-
|
653
|
-
return _this3;
|
654
635
|
}
|
655
636
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
return '';
|
662
|
-
}
|
637
|
+
_constructFieldName(dict) {
|
638
|
+
if (!dict.has("T") && !dict.has("Parent")) {
|
639
|
+
(0, _util.warn)("Unknown field name, falling back to empty field name.");
|
640
|
+
return "";
|
641
|
+
}
|
663
642
|
|
664
|
-
|
665
|
-
|
666
|
-
|
643
|
+
if (!dict.has("Parent")) {
|
644
|
+
return (0, _util.stringToPDFString)(dict.get("T"));
|
645
|
+
}
|
667
646
|
|
668
|
-
|
647
|
+
const fieldName = [];
|
669
648
|
|
670
|
-
|
671
|
-
|
672
|
-
|
649
|
+
if (dict.has("T")) {
|
650
|
+
fieldName.unshift((0, _util.stringToPDFString)(dict.get("T")));
|
651
|
+
}
|
673
652
|
|
674
|
-
|
653
|
+
let loopDict = dict;
|
675
654
|
|
676
|
-
|
677
|
-
|
655
|
+
while (loopDict.has("Parent")) {
|
656
|
+
loopDict = loopDict.get("Parent");
|
678
657
|
|
679
|
-
|
680
|
-
|
681
|
-
}
|
682
|
-
|
683
|
-
if (loopDict.has('T')) {
|
684
|
-
fieldName.unshift((0, _util.stringToPDFString)(loopDict.get('T')));
|
685
|
-
}
|
658
|
+
if (!(0, _primitives.isDict)(loopDict)) {
|
659
|
+
break;
|
686
660
|
}
|
687
661
|
|
688
|
-
|
689
|
-
|
690
|
-
}, {
|
691
|
-
key: "hasFieldFlag",
|
692
|
-
value: function hasFieldFlag(flag) {
|
693
|
-
return !!(this.data.fieldFlags & flag);
|
694
|
-
}
|
695
|
-
}, {
|
696
|
-
key: "getOperatorList",
|
697
|
-
value: function getOperatorList(evaluator, task, renderForms) {
|
698
|
-
if (renderForms) {
|
699
|
-
return Promise.resolve(new _operator_list.OperatorList());
|
662
|
+
if (loopDict.has("T")) {
|
663
|
+
fieldName.unshift((0, _util.stringToPDFString)(loopDict.get("T")));
|
700
664
|
}
|
701
|
-
|
702
|
-
return _get(_getPrototypeOf(WidgetAnnotation.prototype), "getOperatorList", this).call(this, evaluator, task, renderForms);
|
703
665
|
}
|
704
|
-
}]);
|
705
|
-
|
706
|
-
return WidgetAnnotation;
|
707
|
-
}(Annotation);
|
708
666
|
|
709
|
-
|
710
|
-
|
711
|
-
function (_WidgetAnnotation) {
|
712
|
-
_inherits(TextWidgetAnnotation, _WidgetAnnotation);
|
667
|
+
return fieldName.join(".");
|
668
|
+
}
|
713
669
|
|
714
|
-
|
715
|
-
|
670
|
+
_decodeFormValue(formValue) {
|
671
|
+
if (Array.isArray(formValue)) {
|
672
|
+
return formValue.filter(item => (0, _util.isString)(item)).map(item => (0, _util.stringToPDFString)(item));
|
673
|
+
} else if ((0, _primitives.isName)(formValue)) {
|
674
|
+
return (0, _util.stringToPDFString)(formValue.name);
|
675
|
+
} else if ((0, _util.isString)(formValue)) {
|
676
|
+
return (0, _util.stringToPDFString)(formValue);
|
677
|
+
}
|
716
678
|
|
717
|
-
|
679
|
+
return null;
|
680
|
+
}
|
718
681
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
var alignment = (0, _core_utils.getInheritableProperty)({
|
723
|
-
dict: dict,
|
724
|
-
key: 'Q'
|
725
|
-
});
|
682
|
+
hasFieldFlag(flag) {
|
683
|
+
return !!(this.data.fieldFlags & flag);
|
684
|
+
}
|
726
685
|
|
727
|
-
|
728
|
-
|
686
|
+
getOperatorList(evaluator, task, renderForms, annotationStorage) {
|
687
|
+
if (renderForms) {
|
688
|
+
return Promise.resolve(new _operator_list.OperatorList());
|
729
689
|
}
|
730
690
|
|
731
|
-
|
732
|
-
|
733
|
-
dict: dict,
|
734
|
-
key: 'MaxLen'
|
735
|
-
});
|
736
|
-
|
737
|
-
if (!Number.isInteger(maximumLength) || maximumLength < 0) {
|
738
|
-
maximumLength = null;
|
691
|
+
if (!this._hasText) {
|
692
|
+
return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
|
739
693
|
}
|
740
694
|
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
return _this4;
|
745
|
-
}
|
746
|
-
|
747
|
-
_createClass(TextWidgetAnnotation, [{
|
748
|
-
key: "getOperatorList",
|
749
|
-
value: function getOperatorList(evaluator, task, renderForms) {
|
750
|
-
if (renderForms || this.appearance) {
|
751
|
-
return _get(_getPrototypeOf(TextWidgetAnnotation.prototype), "getOperatorList", this).call(this, evaluator, task, renderForms);
|
695
|
+
return this._getAppearance(evaluator, task, annotationStorage).then(content => {
|
696
|
+
if (this.appearance && content === null) {
|
697
|
+
return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
|
752
698
|
}
|
753
699
|
|
754
|
-
|
700
|
+
const operatorList = new _operator_list.OperatorList();
|
755
701
|
|
756
|
-
if (!this.data.defaultAppearance) {
|
757
|
-
return
|
702
|
+
if (!this.data.defaultAppearance || content === null) {
|
703
|
+
return operatorList;
|
758
704
|
}
|
759
705
|
|
760
|
-
|
706
|
+
const matrix = [1, 0, 0, 1, 0, 0];
|
707
|
+
const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
|
708
|
+
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
|
709
|
+
operatorList.addOp(_util.OPS.beginAnnotation, [this.data.rect, transform, matrix]);
|
710
|
+
const stream = new _stream.StringStream(content);
|
761
711
|
return evaluator.getOperatorList({
|
762
|
-
stream
|
763
|
-
task
|
712
|
+
stream,
|
713
|
+
task,
|
764
714
|
resources: this.fieldResources,
|
765
|
-
operatorList
|
715
|
+
operatorList
|
766
716
|
}).then(function () {
|
717
|
+
operatorList.addOp(_util.OPS.endAnnotation, []);
|
767
718
|
return operatorList;
|
768
719
|
});
|
769
|
-
}
|
770
|
-
}
|
720
|
+
});
|
721
|
+
}
|
771
722
|
|
772
|
-
|
773
|
-
|
723
|
+
async save(evaluator, task, annotationStorage) {
|
724
|
+
if (this.data.fieldValue === annotationStorage[this.data.id]) {
|
725
|
+
return null;
|
726
|
+
}
|
774
727
|
|
775
|
-
|
776
|
-
/*#__PURE__*/
|
777
|
-
function (_WidgetAnnotation2) {
|
778
|
-
_inherits(ButtonWidgetAnnotation, _WidgetAnnotation2);
|
728
|
+
let appearance = await this._getAppearance(evaluator, task, annotationStorage);
|
779
729
|
|
780
|
-
|
781
|
-
|
730
|
+
if (appearance === null) {
|
731
|
+
return null;
|
732
|
+
}
|
782
733
|
|
783
|
-
|
734
|
+
const dict = evaluator.xref.fetchIfRef(this.ref);
|
784
735
|
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
_this5.data.pushButton = _this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
|
736
|
+
if (!(0, _primitives.isDict)(dict)) {
|
737
|
+
return null;
|
738
|
+
}
|
789
739
|
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
740
|
+
const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
|
741
|
+
const newRef = evaluator.xref.getNewRef();
|
742
|
+
const AP = new _primitives.Dict(evaluator.xref);
|
743
|
+
AP.set("N", newRef);
|
744
|
+
const value = annotationStorage[this.data.id];
|
745
|
+
const encrypt = evaluator.xref.encrypt;
|
746
|
+
let originalTransform = null;
|
747
|
+
let newTransform = null;
|
748
|
+
|
749
|
+
if (encrypt) {
|
750
|
+
originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
|
751
|
+
newTransform = encrypt.createCipherTransform(newRef.num, newRef.gen);
|
752
|
+
appearance = newTransform.encryptString(appearance);
|
798
753
|
}
|
799
754
|
|
800
|
-
|
755
|
+
dict.set("V", value);
|
756
|
+
dict.set("AP", AP);
|
757
|
+
dict.set("M", `D:${(0, _util.getModificationDate)()}`);
|
758
|
+
const appearanceDict = new _primitives.Dict(evaluator.xref);
|
759
|
+
appearanceDict.set("Length", appearance.length);
|
760
|
+
appearanceDict.set("Subtype", _primitives.Name.get("Form"));
|
761
|
+
appearanceDict.set("Resources", this.fieldResources);
|
762
|
+
appearanceDict.set("BBox", bbox);
|
763
|
+
const bufferOriginal = [`${this.ref.num} ${this.ref.gen} obj\n`];
|
764
|
+
(0, _writer.writeDict)(dict, bufferOriginal, originalTransform);
|
765
|
+
bufferOriginal.push("\nendobj\n");
|
766
|
+
const bufferNew = [`${newRef.num} ${newRef.gen} obj\n`];
|
767
|
+
(0, _writer.writeDict)(appearanceDict, bufferNew, newTransform);
|
768
|
+
bufferNew.push(" stream\n");
|
769
|
+
bufferNew.push(appearance);
|
770
|
+
bufferNew.push("\nendstream\nendobj\n");
|
771
|
+
return [{
|
772
|
+
ref: this.ref,
|
773
|
+
data: bufferOriginal.join("")
|
774
|
+
}, {
|
775
|
+
ref: newRef,
|
776
|
+
data: bufferNew.join("")
|
777
|
+
}];
|
801
778
|
}
|
802
779
|
|
803
|
-
|
804
|
-
|
805
|
-
value: function _processCheckBox(params) {
|
806
|
-
if ((0, _primitives.isName)(this.data.fieldValue)) {
|
807
|
-
this.data.fieldValue = this.data.fieldValue.name;
|
808
|
-
}
|
780
|
+
async _getAppearance(evaluator, task, annotationStorage) {
|
781
|
+
const isPassword = this.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD);
|
809
782
|
|
810
|
-
|
783
|
+
if (!annotationStorage || isPassword) {
|
784
|
+
return null;
|
785
|
+
}
|
811
786
|
|
812
|
-
|
813
|
-
return;
|
814
|
-
}
|
787
|
+
const value = annotationStorage[this.data.id];
|
815
788
|
|
816
|
-
|
789
|
+
if (value === "") {
|
790
|
+
return "";
|
791
|
+
}
|
817
792
|
|
818
|
-
|
819
|
-
|
820
|
-
|
793
|
+
const defaultPadding = 2;
|
794
|
+
const hPadding = defaultPadding;
|
795
|
+
const totalHeight = this.data.rect[3] - this.data.rect[1];
|
796
|
+
const totalWidth = this.data.rect[2] - this.data.rect[0];
|
797
|
+
const fontInfo = await this._getFontData(evaluator, task);
|
798
|
+
const [font, fontName] = fontInfo;
|
799
|
+
let fontSize = fontInfo[2];
|
800
|
+
fontSize = this._computeFontSize(font, fontName, fontSize, totalHeight);
|
801
|
+
let descent = font.descent;
|
802
|
+
|
803
|
+
if (isNaN(descent)) {
|
804
|
+
descent = 0;
|
805
|
+
}
|
821
806
|
|
822
|
-
|
823
|
-
|
807
|
+
const vPadding = defaultPadding + Math.abs(descent) * fontSize;
|
808
|
+
const defaultAppearance = this.data.defaultAppearance;
|
809
|
+
const alignment = this.data.textAlignment;
|
824
810
|
|
825
|
-
|
826
|
-
|
827
|
-
|
811
|
+
if (this.data.comb) {
|
812
|
+
return this._getCombAppearance(defaultAppearance, value, totalWidth, hPadding, vPadding);
|
813
|
+
}
|
828
814
|
|
829
|
-
|
815
|
+
if (this.data.multiLine) {
|
816
|
+
return this._getMultilineAppearance(defaultAppearance, value, font, fontSize, totalWidth, totalHeight, alignment, hPadding, vPadding);
|
830
817
|
}
|
831
|
-
}, {
|
832
|
-
key: "_processRadioButton",
|
833
|
-
value: function _processRadioButton(params) {
|
834
|
-
this.data.fieldValue = this.data.buttonValue = null;
|
835
|
-
var fieldParent = params.dict.get('Parent');
|
836
818
|
|
837
|
-
|
838
|
-
|
819
|
+
if (alignment === 0 || alignment > 2) {
|
820
|
+
return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 ${hPadding} ${vPadding} Tm (${(0, _util.escapeString)(value)}) Tj` + " ET Q EMC";
|
821
|
+
}
|
839
822
|
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
823
|
+
const renderedText = this._renderText(value, font, fontSize, totalWidth, alignment, hPadding, vPadding);
|
824
|
+
|
825
|
+
return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC";
|
826
|
+
}
|
844
827
|
|
845
|
-
|
828
|
+
async _getFontData(evaluator, task) {
|
829
|
+
const operatorList = new _operator_list.OperatorList();
|
830
|
+
const initialState = {
|
831
|
+
fontSize: 0,
|
832
|
+
font: null,
|
833
|
+
fontName: null,
|
846
834
|
|
847
|
-
|
848
|
-
return;
|
835
|
+
clone() {
|
836
|
+
return this;
|
849
837
|
}
|
850
838
|
|
851
|
-
|
839
|
+
};
|
840
|
+
await evaluator.getOperatorList({
|
841
|
+
stream: new _stream.StringStream(this.data.defaultAppearance),
|
842
|
+
task,
|
843
|
+
resources: this.fieldResources,
|
844
|
+
operatorList,
|
845
|
+
initialState
|
846
|
+
});
|
847
|
+
return [initialState.font, initialState.fontName, initialState.fontSize];
|
848
|
+
}
|
849
|
+
|
850
|
+
_computeFontSize(font, fontName, fontSize, height) {
|
851
|
+
if (fontSize === null || fontSize === 0) {
|
852
|
+
const em = font.charsToGlyphs("M", true)[0].width / 1000;
|
853
|
+
const capHeight = 0.7 * em;
|
854
|
+
fontSize = Math.max(1, Math.floor(height / (1.5 * capHeight)));
|
855
|
+
let fontRegex = new RegExp(`/${fontName}\\s+[0-9\.]+\\s+Tf`);
|
852
856
|
|
853
|
-
if (
|
854
|
-
|
857
|
+
if (this.data.defaultAppearance.search(fontRegex) === -1) {
|
858
|
+
fontRegex = new RegExp(`/${fontName}\\s+Tf`);
|
855
859
|
}
|
856
860
|
|
857
|
-
|
861
|
+
this.data.defaultAppearance = this.data.defaultAppearance.replace(fontRegex, `/${fontName} ${fontSize} Tf`);
|
862
|
+
}
|
858
863
|
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
864
|
+
return fontSize;
|
865
|
+
}
|
866
|
+
|
867
|
+
_renderText(text, font, fontSize, totalWidth, alignment, hPadding, vPadding) {
|
868
|
+
const glyphs = font.charsToGlyphs(text);
|
869
|
+
const scale = fontSize / 1000;
|
870
|
+
let width = 0;
|
871
|
+
|
872
|
+
for (const glyph of glyphs) {
|
873
|
+
width += glyph.width * scale;
|
865
874
|
}
|
866
|
-
}, {
|
867
|
-
key: "_processPushButton",
|
868
|
-
value: function _processPushButton(params) {
|
869
|
-
if (!params.dict.has('A')) {
|
870
|
-
(0, _util.warn)('Push buttons without action dictionaries are not supported');
|
871
|
-
return;
|
872
|
-
}
|
873
875
|
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
876
|
+
let shift;
|
877
|
+
|
878
|
+
if (alignment === 1) {
|
879
|
+
shift = (totalWidth - width) / 2;
|
880
|
+
} else if (alignment === 2) {
|
881
|
+
shift = totalWidth - width - hPadding;
|
882
|
+
} else {
|
883
|
+
shift = hPadding;
|
879
884
|
}
|
880
|
-
}]);
|
881
885
|
|
882
|
-
|
883
|
-
|
886
|
+
shift = shift.toFixed(2);
|
887
|
+
vPadding = vPadding.toFixed(2);
|
888
|
+
return `${shift} ${vPadding} Td (${(0, _util.escapeString)(text)}) Tj`;
|
889
|
+
}
|
884
890
|
|
885
|
-
|
886
|
-
/*#__PURE__*/
|
887
|
-
function (_WidgetAnnotation3) {
|
888
|
-
_inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3);
|
891
|
+
}
|
889
892
|
|
890
|
-
|
891
|
-
|
893
|
+
class TextWidgetAnnotation extends WidgetAnnotation {
|
894
|
+
constructor(params) {
|
895
|
+
super(params);
|
896
|
+
this._hasText = true;
|
897
|
+
const dict = params.dict;
|
892
898
|
|
893
|
-
|
899
|
+
if (!(0, _util.isString)(this.data.fieldValue)) {
|
900
|
+
this.data.fieldValue = "";
|
901
|
+
}
|
894
902
|
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
dict: params.dict,
|
899
|
-
key: 'Opt'
|
903
|
+
let alignment = (0, _core_utils.getInheritableProperty)({
|
904
|
+
dict,
|
905
|
+
key: "Q"
|
900
906
|
});
|
901
907
|
|
902
|
-
if (
|
903
|
-
|
904
|
-
|
905
|
-
for (var i = 0, ii = options.length; i < ii; i++) {
|
906
|
-
var option = xref.fetchIfRef(options[i]);
|
907
|
-
var isOptionArray = Array.isArray(option);
|
908
|
-
_this6.data.options[i] = {
|
909
|
-
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
|
910
|
-
displayValue: (0, _util.stringToPDFString)(isOptionArray ? xref.fetchIfRef(option[1]) : option)
|
911
|
-
};
|
912
|
-
}
|
908
|
+
if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
|
909
|
+
alignment = null;
|
913
910
|
}
|
914
911
|
|
915
|
-
|
916
|
-
|
912
|
+
this.data.textAlignment = alignment;
|
913
|
+
let maximumLength = (0, _core_utils.getInheritableProperty)({
|
914
|
+
dict,
|
915
|
+
key: "MaxLen"
|
916
|
+
});
|
917
|
+
|
918
|
+
if (!Number.isInteger(maximumLength) || maximumLength < 0) {
|
919
|
+
maximumLength = null;
|
917
920
|
}
|
918
921
|
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
+
this.data.maxLen = maximumLength;
|
923
|
+
this.data.multiLine = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
|
924
|
+
this.data.comb = this.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !this.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
|
922
925
|
}
|
923
926
|
|
924
|
-
|
925
|
-
|
927
|
+
_getCombAppearance(defaultAppearance, text, width, hPadding, vPadding) {
|
928
|
+
const combWidth = (width / this.data.maxLen).toFixed(2);
|
929
|
+
const buf = [];
|
926
930
|
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
_inherits(TextAnnotation, _MarkupAnnotation);
|
931
|
+
for (const character of text) {
|
932
|
+
buf.push(`(${(0, _util.escapeString)(character)}) Tj`);
|
933
|
+
}
|
931
934
|
|
932
|
-
|
933
|
-
|
935
|
+
const renderedComb = buf.join(` ${combWidth} 0 Td `);
|
936
|
+
return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 ${hPadding} ${vPadding} Tm ${renderedComb}` + " ET Q EMC";
|
937
|
+
}
|
934
938
|
|
935
|
-
|
939
|
+
_getMultilineAppearance(defaultAppearance, text, font, fontSize, width, height, alignment, hPadding, vPadding) {
|
940
|
+
const lines = text.split(/\r\n|\r|\n/);
|
941
|
+
const buf = [];
|
942
|
+
const totalWidth = width - 2 * hPadding;
|
936
943
|
|
937
|
-
|
938
|
-
|
939
|
-
_this7.data.annotationType = _util.AnnotationType.TEXT;
|
944
|
+
for (const line of lines) {
|
945
|
+
const chunks = this._splitLine(line, font, fontSize, totalWidth);
|
940
946
|
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
_this7.data.rect[2] = _this7.data.rect[0] + DEFAULT_ICON_SIZE;
|
946
|
-
_this7.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
|
947
|
+
for (const chunk of chunks) {
|
948
|
+
const padding = buf.length === 0 ? hPadding : 0;
|
949
|
+
buf.push(this._renderText(chunk, font, fontSize, width, alignment, padding, -fontSize));
|
950
|
+
}
|
947
951
|
}
|
948
952
|
|
949
|
-
|
953
|
+
const renderedText = buf.join("\n");
|
954
|
+
return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 0 ${height} Tm ${renderedText}` + " ET Q EMC";
|
950
955
|
}
|
951
956
|
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
/*#__PURE__*/
|
957
|
-
function (_Annotation3) {
|
958
|
-
_inherits(LinkAnnotation, _Annotation3);
|
957
|
+
_splitLine(line, font, fontSize, width) {
|
958
|
+
if (line.length <= 1) {
|
959
|
+
return [line];
|
960
|
+
}
|
959
961
|
|
960
|
-
|
961
|
-
|
962
|
+
const scale = fontSize / 1000;
|
963
|
+
const whitespace = font.charsToGlyphs(" ", true)[0].width * scale;
|
964
|
+
const chunks = [];
|
965
|
+
let lastSpacePos = -1,
|
966
|
+
startChunk = 0,
|
967
|
+
currentWidth = 0;
|
968
|
+
|
969
|
+
for (let i = 0, ii = line.length; i < ii; i++) {
|
970
|
+
const character = line.charAt(i);
|
971
|
+
|
972
|
+
if (character === " ") {
|
973
|
+
if (currentWidth + whitespace > width) {
|
974
|
+
chunks.push(line.substring(startChunk, i));
|
975
|
+
startChunk = i;
|
976
|
+
currentWidth = whitespace;
|
977
|
+
lastSpacePos = -1;
|
978
|
+
} else {
|
979
|
+
currentWidth += whitespace;
|
980
|
+
lastSpacePos = i;
|
981
|
+
}
|
982
|
+
} else {
|
983
|
+
const charWidth = font.charsToGlyphs(character, false)[0].width * scale;
|
984
|
+
|
985
|
+
if (currentWidth + charWidth > width) {
|
986
|
+
if (lastSpacePos !== -1) {
|
987
|
+
chunks.push(line.substring(startChunk, lastSpacePos + 1));
|
988
|
+
startChunk = i = lastSpacePos + 1;
|
989
|
+
lastSpacePos = -1;
|
990
|
+
currentWidth = 0;
|
991
|
+
} else {
|
992
|
+
chunks.push(line.substring(startChunk, i));
|
993
|
+
startChunk = i;
|
994
|
+
currentWidth = charWidth;
|
995
|
+
}
|
996
|
+
} else {
|
997
|
+
currentWidth += charWidth;
|
998
|
+
}
|
999
|
+
}
|
1000
|
+
}
|
962
1001
|
|
963
|
-
|
1002
|
+
if (startChunk < line.length) {
|
1003
|
+
chunks.push(line.substring(startChunk, line.length));
|
1004
|
+
}
|
964
1005
|
|
965
|
-
|
966
|
-
|
1006
|
+
return chunks;
|
1007
|
+
}
|
967
1008
|
|
968
|
-
|
969
|
-
destDict: params.dict,
|
970
|
-
resultObj: _this8.data,
|
971
|
-
docBaseUrl: params.pdfManager.docBaseUrl
|
972
|
-
});
|
1009
|
+
}
|
973
1010
|
|
974
|
-
|
1011
|
+
class ButtonWidgetAnnotation extends WidgetAnnotation {
|
1012
|
+
constructor(params) {
|
1013
|
+
super(params);
|
1014
|
+
this.checkedAppearance = null;
|
1015
|
+
this.uncheckedAppearance = null;
|
1016
|
+
this.data.checkBox = !this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
|
1017
|
+
this.data.radioButton = this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
|
1018
|
+
this.data.pushButton = this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
|
1019
|
+
|
1020
|
+
if (this.data.checkBox) {
|
1021
|
+
this._processCheckBox(params);
|
1022
|
+
} else if (this.data.radioButton) {
|
1023
|
+
this._processRadioButton(params);
|
1024
|
+
} else if (this.data.pushButton) {
|
1025
|
+
this._processPushButton(params);
|
1026
|
+
} else {
|
1027
|
+
(0, _util.warn)("Invalid field flags for button widget annotation");
|
1028
|
+
}
|
975
1029
|
}
|
976
1030
|
|
977
|
-
|
978
|
-
|
1031
|
+
getOperatorList(evaluator, task, renderForms, annotationStorage) {
|
1032
|
+
if (this.data.pushButton) {
|
1033
|
+
return super.getOperatorList(evaluator, task, false, annotationStorage);
|
1034
|
+
}
|
979
1035
|
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
_inherits(PopupAnnotation, _Annotation4);
|
1036
|
+
if (annotationStorage) {
|
1037
|
+
const value = annotationStorage[this.data.id] || false;
|
1038
|
+
let appearance;
|
984
1039
|
|
985
|
-
|
986
|
-
|
1040
|
+
if (value) {
|
1041
|
+
appearance = this.checkedAppearance;
|
1042
|
+
} else {
|
1043
|
+
appearance = this.uncheckedAppearance;
|
1044
|
+
}
|
987
1045
|
|
988
|
-
|
1046
|
+
if (appearance) {
|
1047
|
+
const savedAppearance = this.appearance;
|
1048
|
+
this.appearance = appearance;
|
1049
|
+
const operatorList = super.getOperatorList(evaluator, task, renderForms, annotationStorage);
|
1050
|
+
this.appearance = savedAppearance;
|
1051
|
+
return operatorList;
|
1052
|
+
}
|
989
1053
|
|
990
|
-
|
991
|
-
|
992
|
-
var dict = parameters.dict;
|
993
|
-
var parentItem = dict.get('Parent');
|
1054
|
+
return Promise.resolve(new _operator_list.OperatorList());
|
1055
|
+
}
|
994
1056
|
|
995
|
-
|
996
|
-
|
997
|
-
|
1057
|
+
return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
async save(evaluator, task, annotationStorage) {
|
1061
|
+
if (this.data.checkBox) {
|
1062
|
+
return this._saveCheckbox(evaluator, task, annotationStorage);
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
if (this.data.radioButton) {
|
1066
|
+
return this._saveRadioButton(evaluator, task, annotationStorage);
|
998
1067
|
}
|
999
1068
|
|
1000
|
-
|
1001
|
-
|
1002
|
-
_this9.data.parentId = dict.getRaw('Parent').toString();
|
1003
|
-
_this9.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || '');
|
1004
|
-
_this9.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || '');
|
1069
|
+
return super.save(evaluator, task, annotationStorage);
|
1070
|
+
}
|
1005
1071
|
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
_this9.setModificationDate(parentItem.get('M'));
|
1072
|
+
async _saveCheckbox(evaluator, task, annotationStorage) {
|
1073
|
+
const defaultValue = this.data.fieldValue && this.data.fieldValue !== "Off";
|
1074
|
+
const value = annotationStorage[this.data.id];
|
1010
1075
|
|
1011
|
-
|
1076
|
+
if (defaultValue === value) {
|
1077
|
+
return null;
|
1012
1078
|
}
|
1013
1079
|
|
1014
|
-
|
1015
|
-
_this9.data.color = null;
|
1016
|
-
} else {
|
1017
|
-
_this9.setColor(parentItem.getArray('C'));
|
1080
|
+
const dict = evaluator.xref.fetchIfRef(this.ref);
|
1018
1081
|
|
1019
|
-
|
1082
|
+
if (!(0, _primitives.isDict)(dict)) {
|
1083
|
+
return null;
|
1020
1084
|
}
|
1021
1085
|
|
1022
|
-
|
1023
|
-
var parentFlags = parentItem.get('F');
|
1086
|
+
const name = _primitives.Name.get(value ? this.data.exportValue : "Off");
|
1024
1087
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1088
|
+
dict.set("V", name);
|
1089
|
+
dict.set("AS", name);
|
1090
|
+
dict.set("M", `D:${(0, _util.getModificationDate)()}`);
|
1091
|
+
const encrypt = evaluator.xref.encrypt;
|
1092
|
+
let originalTransform = null;
|
1093
|
+
|
1094
|
+
if (encrypt) {
|
1095
|
+
originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
|
1028
1096
|
}
|
1029
1097
|
|
1030
|
-
|
1098
|
+
const buffer = [`${this.ref.num} ${this.ref.gen} obj\n`];
|
1099
|
+
(0, _writer.writeDict)(dict, buffer, originalTransform);
|
1100
|
+
buffer.push("\nendobj\n");
|
1101
|
+
return [{
|
1102
|
+
ref: this.ref,
|
1103
|
+
data: buffer.join("")
|
1104
|
+
}];
|
1031
1105
|
}
|
1032
1106
|
|
1033
|
-
|
1034
|
-
|
1107
|
+
async _saveRadioButton(evaluator, task, annotationStorage) {
|
1108
|
+
const defaultValue = this.data.fieldValue === this.data.buttonValue;
|
1109
|
+
const value = annotationStorage[this.data.id];
|
1035
1110
|
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
_inherits(FreeTextAnnotation, _MarkupAnnotation2);
|
1111
|
+
if (defaultValue === value) {
|
1112
|
+
return null;
|
1113
|
+
}
|
1040
1114
|
|
1041
|
-
|
1042
|
-
var _this10;
|
1115
|
+
const dict = evaluator.xref.fetchIfRef(this.ref);
|
1043
1116
|
|
1044
|
-
|
1117
|
+
if (!(0, _primitives.isDict)(dict)) {
|
1118
|
+
return null;
|
1119
|
+
}
|
1045
1120
|
|
1046
|
-
|
1047
|
-
_this10.data.annotationType = _util.AnnotationType.FREETEXT;
|
1048
|
-
return _this10;
|
1049
|
-
}
|
1121
|
+
const name = _primitives.Name.get(value ? this.data.buttonValue : "Off");
|
1050
1122
|
|
1051
|
-
|
1052
|
-
|
1123
|
+
let parentBuffer = null;
|
1124
|
+
const encrypt = evaluator.xref.encrypt;
|
1053
1125
|
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1126
|
+
if (value) {
|
1127
|
+
if ((0, _primitives.isRef)(this.parent)) {
|
1128
|
+
const parent = evaluator.xref.fetch(this.parent);
|
1129
|
+
let parentTransform = null;
|
1058
1130
|
|
1059
|
-
|
1060
|
-
|
1131
|
+
if (encrypt) {
|
1132
|
+
parentTransform = encrypt.createCipherTransform(this.parent.num, this.parent.gen);
|
1133
|
+
}
|
1061
1134
|
|
1062
|
-
|
1135
|
+
parent.set("V", name);
|
1136
|
+
parentBuffer = [`${this.parent.num} ${this.parent.gen} obj\n`];
|
1137
|
+
(0, _writer.writeDict)(parent, parentBuffer, parentTransform);
|
1138
|
+
parentBuffer.push("\nendobj\n");
|
1139
|
+
} else if ((0, _primitives.isDict)(this.parent)) {
|
1140
|
+
this.parent.set("V", name);
|
1141
|
+
}
|
1142
|
+
}
|
1063
1143
|
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
_this11.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L'));
|
1068
|
-
return _this11;
|
1069
|
-
}
|
1144
|
+
dict.set("AS", name);
|
1145
|
+
dict.set("M", `D:${(0, _util.getModificationDate)()}`);
|
1146
|
+
let originalTransform = null;
|
1070
1147
|
|
1071
|
-
|
1072
|
-
|
1148
|
+
if (encrypt) {
|
1149
|
+
originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
|
1150
|
+
}
|
1073
1151
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1152
|
+
const buffer = [`${this.ref.num} ${this.ref.gen} obj\n`];
|
1153
|
+
(0, _writer.writeDict)(dict, buffer, originalTransform);
|
1154
|
+
buffer.push("\nendobj\n");
|
1155
|
+
const newRefs = [{
|
1156
|
+
ref: this.ref,
|
1157
|
+
data: buffer.join("")
|
1158
|
+
}];
|
1159
|
+
|
1160
|
+
if (parentBuffer !== null) {
|
1161
|
+
newRefs.push({
|
1162
|
+
ref: this.parent,
|
1163
|
+
data: parentBuffer.join("")
|
1164
|
+
});
|
1165
|
+
}
|
1078
1166
|
|
1079
|
-
|
1080
|
-
|
1167
|
+
return newRefs;
|
1168
|
+
}
|
1081
1169
|
|
1082
|
-
|
1170
|
+
_processCheckBox(params) {
|
1171
|
+
const customAppearance = params.dict.get("AP");
|
1083
1172
|
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
}
|
1173
|
+
if (!(0, _primitives.isDict)(customAppearance)) {
|
1174
|
+
return;
|
1175
|
+
}
|
1088
1176
|
|
1089
|
-
|
1090
|
-
}(MarkupAnnotation);
|
1177
|
+
const normalAppearance = customAppearance.get("N");
|
1091
1178
|
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
_inherits(CircleAnnotation, _MarkupAnnotation5);
|
1179
|
+
if (!(0, _primitives.isDict)(normalAppearance)) {
|
1180
|
+
return;
|
1181
|
+
}
|
1096
1182
|
|
1097
|
-
|
1098
|
-
var _this13;
|
1183
|
+
const exportValues = normalAppearance.getKeys();
|
1099
1184
|
|
1100
|
-
|
1185
|
+
if (!exportValues.includes("Off")) {
|
1186
|
+
exportValues.push("Off");
|
1187
|
+
}
|
1101
1188
|
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1189
|
+
if (exportValues.length !== 2) {
|
1190
|
+
return;
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
this.data.exportValue = exportValues[0] === "Off" ? exportValues[1] : exportValues[0];
|
1194
|
+
this.checkedAppearance = normalAppearance.get(this.data.exportValue);
|
1195
|
+
this.uncheckedAppearance = normalAppearance.get("Off") || null;
|
1105
1196
|
}
|
1106
1197
|
|
1107
|
-
|
1108
|
-
|
1198
|
+
_processRadioButton(params) {
|
1199
|
+
this.data.fieldValue = this.data.buttonValue = null;
|
1200
|
+
const fieldParent = params.dict.get("Parent");
|
1109
1201
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
function (_MarkupAnnotation6) {
|
1113
|
-
_inherits(PolylineAnnotation, _MarkupAnnotation6);
|
1202
|
+
if ((0, _primitives.isDict)(fieldParent) && fieldParent.has("V")) {
|
1203
|
+
const fieldParentValue = fieldParent.get("V");
|
1114
1204
|
|
1115
|
-
|
1116
|
-
|
1205
|
+
if ((0, _primitives.isName)(fieldParentValue)) {
|
1206
|
+
this.parent = params.dict.getRaw("Parent");
|
1207
|
+
this.data.fieldValue = this._decodeFormValue(fieldParentValue);
|
1208
|
+
}
|
1209
|
+
}
|
1117
1210
|
|
1118
|
-
|
1211
|
+
const appearanceStates = params.dict.get("AP");
|
1119
1212
|
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
var rawVertices = dict.getArray('Vertices');
|
1124
|
-
_this14.data.vertices = [];
|
1213
|
+
if (!(0, _primitives.isDict)(appearanceStates)) {
|
1214
|
+
return;
|
1215
|
+
}
|
1125
1216
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1217
|
+
const normalAppearance = appearanceStates.get("N");
|
1218
|
+
|
1219
|
+
if (!(0, _primitives.isDict)(normalAppearance)) {
|
1220
|
+
return;
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
for (const key of normalAppearance.getKeys()) {
|
1224
|
+
if (key !== "Off") {
|
1225
|
+
this.data.buttonValue = key;
|
1226
|
+
break;
|
1227
|
+
}
|
1131
1228
|
}
|
1132
1229
|
|
1133
|
-
|
1230
|
+
this.checkedAppearance = normalAppearance.get(this.data.buttonValue);
|
1231
|
+
this.uncheckedAppearance = normalAppearance.get("Off") || null;
|
1134
1232
|
}
|
1135
1233
|
|
1136
|
-
|
1137
|
-
|
1234
|
+
_processPushButton(params) {
|
1235
|
+
if (!params.dict.has("A")) {
|
1236
|
+
(0, _util.warn)("Push buttons without action dictionaries are not supported");
|
1237
|
+
return;
|
1238
|
+
}
|
1138
1239
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1240
|
+
_obj.Catalog.parseDestDictionary({
|
1241
|
+
destDict: params.dict,
|
1242
|
+
resultObj: this.data,
|
1243
|
+
docBaseUrl: params.pdfManager.docBaseUrl
|
1244
|
+
});
|
1245
|
+
}
|
1143
1246
|
|
1144
|
-
|
1145
|
-
var _this15;
|
1247
|
+
}
|
1146
1248
|
|
1147
|
-
|
1249
|
+
class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
1250
|
+
constructor(params) {
|
1251
|
+
super(params);
|
1252
|
+
this.data.options = [];
|
1253
|
+
const options = (0, _core_utils.getInheritableProperty)({
|
1254
|
+
dict: params.dict,
|
1255
|
+
key: "Opt"
|
1256
|
+
});
|
1148
1257
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1258
|
+
if (Array.isArray(options)) {
|
1259
|
+
const xref = params.xref;
|
1260
|
+
|
1261
|
+
for (let i = 0, ii = options.length; i < ii; i++) {
|
1262
|
+
const option = xref.fetchIfRef(options[i]);
|
1263
|
+
const isOptionArray = Array.isArray(option);
|
1264
|
+
this.data.options[i] = {
|
1265
|
+
exportValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[0]) : option),
|
1266
|
+
displayValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[1]) : option)
|
1267
|
+
};
|
1268
|
+
}
|
1269
|
+
}
|
1270
|
+
|
1271
|
+
if ((0, _util.isString)(this.data.fieldValue)) {
|
1272
|
+
this.data.fieldValue = [this.data.fieldValue];
|
1273
|
+
} else if (!this.data.fieldValue) {
|
1274
|
+
this.data.fieldValue = [];
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
this.data.combo = this.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
|
1278
|
+
this.data.multiSelect = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
|
1279
|
+
this._hasText = true;
|
1152
1280
|
}
|
1153
1281
|
|
1154
|
-
|
1155
|
-
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
class TextAnnotation extends MarkupAnnotation {
|
1285
|
+
constructor(parameters) {
|
1286
|
+
const DEFAULT_ICON_SIZE = 22;
|
1287
|
+
super(parameters);
|
1288
|
+
const dict = parameters.dict;
|
1289
|
+
this.data.annotationType = _util.AnnotationType.TEXT;
|
1290
|
+
|
1291
|
+
if (this.data.hasAppearance) {
|
1292
|
+
this.data.name = "NoIcon";
|
1293
|
+
} else {
|
1294
|
+
this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
|
1295
|
+
this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
|
1296
|
+
this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
|
1297
|
+
}
|
1298
|
+
|
1299
|
+
if (dict.has("State")) {
|
1300
|
+
this.data.state = dict.get("State") || null;
|
1301
|
+
this.data.stateModel = dict.get("StateModel") || null;
|
1302
|
+
} else {
|
1303
|
+
this.data.state = null;
|
1304
|
+
this.data.stateModel = null;
|
1305
|
+
}
|
1306
|
+
}
|
1156
1307
|
|
1157
|
-
|
1158
|
-
/*#__PURE__*/
|
1159
|
-
function (_MarkupAnnotation7) {
|
1160
|
-
_inherits(CaretAnnotation, _MarkupAnnotation7);
|
1308
|
+
}
|
1161
1309
|
|
1162
|
-
|
1163
|
-
|
1310
|
+
class LinkAnnotation extends Annotation {
|
1311
|
+
constructor(params) {
|
1312
|
+
super(params);
|
1313
|
+
this.data.annotationType = _util.AnnotationType.LINK;
|
1314
|
+
const quadPoints = getQuadPoints(params.dict, this.rectangle);
|
1164
1315
|
|
1165
|
-
|
1316
|
+
if (quadPoints) {
|
1317
|
+
this.data.quadPoints = quadPoints;
|
1318
|
+
}
|
1166
1319
|
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1320
|
+
_obj.Catalog.parseDestDictionary({
|
1321
|
+
destDict: params.dict,
|
1322
|
+
resultObj: this.data,
|
1323
|
+
docBaseUrl: params.pdfManager.docBaseUrl
|
1324
|
+
});
|
1170
1325
|
}
|
1171
1326
|
|
1172
|
-
|
1173
|
-
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
class PopupAnnotation extends Annotation {
|
1330
|
+
constructor(parameters) {
|
1331
|
+
super(parameters);
|
1332
|
+
this.data.annotationType = _util.AnnotationType.POPUP;
|
1333
|
+
let parentItem = parameters.dict.get("Parent");
|
1334
|
+
|
1335
|
+
if (!parentItem) {
|
1336
|
+
(0, _util.warn)("Popup annotation has a missing or invalid parent annotation.");
|
1337
|
+
return;
|
1338
|
+
}
|
1174
1339
|
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1340
|
+
const parentSubtype = parentItem.get("Subtype");
|
1341
|
+
this.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
|
1342
|
+
const rawParent = parameters.dict.getRaw("Parent");
|
1343
|
+
this.data.parentId = (0, _primitives.isRef)(rawParent) ? rawParent.toString() : null;
|
1344
|
+
const rt = parentItem.get("RT");
|
1179
1345
|
|
1180
|
-
|
1181
|
-
|
1346
|
+
if ((0, _primitives.isName)(rt, _util.AnnotationReplyType.GROUP)) {
|
1347
|
+
parentItem = parentItem.get("IRT");
|
1348
|
+
}
|
1182
1349
|
|
1183
|
-
|
1350
|
+
if (!parentItem.has("M")) {
|
1351
|
+
this.data.modificationDate = null;
|
1352
|
+
} else {
|
1353
|
+
this.setModificationDate(parentItem.get("M"));
|
1354
|
+
this.data.modificationDate = this.modificationDate;
|
1355
|
+
}
|
1184
1356
|
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1357
|
+
if (!parentItem.has("C")) {
|
1358
|
+
this.data.color = null;
|
1359
|
+
} else {
|
1360
|
+
this.setColor(parentItem.getArray("C"));
|
1361
|
+
this.data.color = this.color;
|
1362
|
+
}
|
1191
1363
|
|
1192
|
-
|
1193
|
-
|
1364
|
+
if (!this.viewable) {
|
1365
|
+
const parentFlags = parentItem.get("F");
|
1194
1366
|
|
1195
|
-
|
1196
|
-
|
1197
|
-
x: xref.fetchIfRef(originalInkLists[i][j]),
|
1198
|
-
y: xref.fetchIfRef(originalInkLists[i][j + 1])
|
1199
|
-
});
|
1367
|
+
if (this._isViewable(parentFlags)) {
|
1368
|
+
this.setFlags(parentFlags);
|
1200
1369
|
}
|
1201
1370
|
}
|
1202
1371
|
|
1203
|
-
|
1372
|
+
this.data.title = (0, _util.stringToPDFString)(parentItem.get("T") || "");
|
1373
|
+
this.data.contents = (0, _util.stringToPDFString)(parentItem.get("Contents") || "");
|
1204
1374
|
}
|
1205
1375
|
|
1206
|
-
|
1207
|
-
|
1376
|
+
}
|
1377
|
+
|
1378
|
+
class FreeTextAnnotation extends MarkupAnnotation {
|
1379
|
+
constructor(parameters) {
|
1380
|
+
super(parameters);
|
1381
|
+
this.data.annotationType = _util.AnnotationType.FREETEXT;
|
1382
|
+
}
|
1208
1383
|
|
1209
|
-
|
1210
|
-
/*#__PURE__*/
|
1211
|
-
function (_MarkupAnnotation9) {
|
1212
|
-
_inherits(HighlightAnnotation, _MarkupAnnotation9);
|
1384
|
+
}
|
1213
1385
|
|
1214
|
-
|
1215
|
-
|
1386
|
+
class LineAnnotation extends MarkupAnnotation {
|
1387
|
+
constructor(parameters) {
|
1388
|
+
super(parameters);
|
1389
|
+
this.data.annotationType = _util.AnnotationType.LINE;
|
1390
|
+
this.data.lineCoordinates = _util.Util.normalizeRect(parameters.dict.getArray("L"));
|
1391
|
+
}
|
1216
1392
|
|
1217
|
-
|
1393
|
+
}
|
1218
1394
|
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1395
|
+
class SquareAnnotation extends MarkupAnnotation {
|
1396
|
+
constructor(parameters) {
|
1397
|
+
super(parameters);
|
1398
|
+
this.data.annotationType = _util.AnnotationType.SQUARE;
|
1222
1399
|
}
|
1223
1400
|
|
1224
|
-
|
1225
|
-
}(MarkupAnnotation);
|
1401
|
+
}
|
1226
1402
|
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1403
|
+
class CircleAnnotation extends MarkupAnnotation {
|
1404
|
+
constructor(parameters) {
|
1405
|
+
super(parameters);
|
1406
|
+
this.data.annotationType = _util.AnnotationType.CIRCLE;
|
1407
|
+
}
|
1231
1408
|
|
1232
|
-
|
1233
|
-
var _this19;
|
1409
|
+
}
|
1234
1410
|
|
1235
|
-
|
1411
|
+
class PolylineAnnotation extends MarkupAnnotation {
|
1412
|
+
constructor(parameters) {
|
1413
|
+
super(parameters);
|
1414
|
+
this.data.annotationType = _util.AnnotationType.POLYLINE;
|
1415
|
+
const rawVertices = parameters.dict.getArray("Vertices");
|
1416
|
+
this.data.vertices = [];
|
1236
1417
|
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1418
|
+
for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
|
1419
|
+
this.data.vertices.push({
|
1420
|
+
x: rawVertices[i],
|
1421
|
+
y: rawVertices[i + 1]
|
1422
|
+
});
|
1423
|
+
}
|
1240
1424
|
}
|
1241
1425
|
|
1242
|
-
|
1243
|
-
}(MarkupAnnotation);
|
1244
|
-
|
1245
|
-
var SquigglyAnnotation =
|
1246
|
-
/*#__PURE__*/
|
1247
|
-
function (_MarkupAnnotation11) {
|
1248
|
-
_inherits(SquigglyAnnotation, _MarkupAnnotation11);
|
1426
|
+
}
|
1249
1427
|
|
1250
|
-
|
1251
|
-
|
1428
|
+
class PolygonAnnotation extends PolylineAnnotation {
|
1429
|
+
constructor(parameters) {
|
1430
|
+
super(parameters);
|
1431
|
+
this.data.annotationType = _util.AnnotationType.POLYGON;
|
1432
|
+
}
|
1252
1433
|
|
1253
|
-
|
1434
|
+
}
|
1254
1435
|
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1436
|
+
class CaretAnnotation extends MarkupAnnotation {
|
1437
|
+
constructor(parameters) {
|
1438
|
+
super(parameters);
|
1439
|
+
this.data.annotationType = _util.AnnotationType.CARET;
|
1258
1440
|
}
|
1259
1441
|
|
1260
|
-
|
1261
|
-
}(MarkupAnnotation);
|
1442
|
+
}
|
1262
1443
|
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1444
|
+
class InkAnnotation extends MarkupAnnotation {
|
1445
|
+
constructor(parameters) {
|
1446
|
+
super(parameters);
|
1447
|
+
this.data.annotationType = _util.AnnotationType.INK;
|
1448
|
+
const xref = parameters.xref;
|
1449
|
+
const originalInkLists = parameters.dict.getArray("InkList");
|
1450
|
+
this.data.inkLists = [];
|
1267
1451
|
|
1268
|
-
|
1269
|
-
|
1452
|
+
for (let i = 0, ii = originalInkLists.length; i < ii; ++i) {
|
1453
|
+
this.data.inkLists.push([]);
|
1270
1454
|
|
1271
|
-
|
1455
|
+
for (let j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
|
1456
|
+
this.data.inkLists[i].push({
|
1457
|
+
x: xref.fetchIfRef(originalInkLists[i][j]),
|
1458
|
+
y: xref.fetchIfRef(originalInkLists[i][j + 1])
|
1459
|
+
});
|
1460
|
+
}
|
1461
|
+
}
|
1462
|
+
}
|
1272
1463
|
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
class HighlightAnnotation extends MarkupAnnotation {
|
1467
|
+
constructor(parameters) {
|
1468
|
+
super(parameters);
|
1469
|
+
this.data.annotationType = _util.AnnotationType.HIGHLIGHT;
|
1470
|
+
const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
|
1471
|
+
|
1472
|
+
if (quadPoints) {
|
1473
|
+
this.data.quadPoints = quadPoints;
|
1474
|
+
}
|
1276
1475
|
}
|
1277
1476
|
|
1278
|
-
|
1279
|
-
|
1477
|
+
}
|
1478
|
+
|
1479
|
+
class UnderlineAnnotation extends MarkupAnnotation {
|
1480
|
+
constructor(parameters) {
|
1481
|
+
super(parameters);
|
1482
|
+
this.data.annotationType = _util.AnnotationType.UNDERLINE;
|
1483
|
+
const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
|
1280
1484
|
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1485
|
+
if (quadPoints) {
|
1486
|
+
this.data.quadPoints = quadPoints;
|
1487
|
+
}
|
1488
|
+
}
|
1285
1489
|
|
1286
|
-
|
1287
|
-
var _this22;
|
1490
|
+
}
|
1288
1491
|
|
1289
|
-
|
1492
|
+
class SquigglyAnnotation extends MarkupAnnotation {
|
1493
|
+
constructor(parameters) {
|
1494
|
+
super(parameters);
|
1495
|
+
this.data.annotationType = _util.AnnotationType.SQUIGGLY;
|
1496
|
+
const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
|
1290
1497
|
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1498
|
+
if (quadPoints) {
|
1499
|
+
this.data.quadPoints = quadPoints;
|
1500
|
+
}
|
1294
1501
|
}
|
1295
1502
|
|
1296
|
-
|
1297
|
-
|
1503
|
+
}
|
1504
|
+
|
1505
|
+
class StrikeOutAnnotation extends MarkupAnnotation {
|
1506
|
+
constructor(parameters) {
|
1507
|
+
super(parameters);
|
1508
|
+
this.data.annotationType = _util.AnnotationType.STRIKEOUT;
|
1509
|
+
const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
|
1298
1510
|
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1511
|
+
if (quadPoints) {
|
1512
|
+
this.data.quadPoints = quadPoints;
|
1513
|
+
}
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
}
|
1303
1517
|
|
1304
|
-
|
1305
|
-
|
1518
|
+
class StampAnnotation extends MarkupAnnotation {
|
1519
|
+
constructor(parameters) {
|
1520
|
+
super(parameters);
|
1521
|
+
this.data.annotationType = _util.AnnotationType.STAMP;
|
1522
|
+
}
|
1306
1523
|
|
1307
|
-
|
1524
|
+
}
|
1308
1525
|
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1526
|
+
class FileAttachmentAnnotation extends MarkupAnnotation {
|
1527
|
+
constructor(parameters) {
|
1528
|
+
super(parameters);
|
1529
|
+
const file = new _obj.FileSpec(parameters.dict.get("FS"), parameters.xref);
|
1530
|
+
this.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
|
1531
|
+
this.data.file = file.serializable;
|
1314
1532
|
}
|
1315
1533
|
|
1316
|
-
|
1317
|
-
}(MarkupAnnotation);
|
1534
|
+
}
|