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
@@ -25,12 +25,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
25
25
|
value: true
|
26
26
|
});
|
27
27
|
exports.addLinkAttributes = addLinkAttributes;
|
28
|
+
exports.deprecated = deprecated;
|
28
29
|
exports.getFilenameFromUrl = getFilenameFromUrl;
|
29
30
|
exports.isFetchSupported = isFetchSupported;
|
30
31
|
exports.isValidFetchUrl = isValidFetchUrl;
|
31
32
|
exports.loadScript = loadScript;
|
32
|
-
exports.
|
33
|
-
exports.PDFDateString = exports.StatTimer = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.BaseCMapReaderFactory = exports.DOMCanvasFactory = exports.BaseCanvasFactory = exports.DEFAULT_LINK_REL = exports.LinkTarget = exports.RenderingCancelledException = exports.PageViewport = void 0;
|
33
|
+
exports.StatTimer = exports.RenderingCancelledException = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.BaseCMapReaderFactory = exports.BaseCanvasFactory = void 0;
|
34
34
|
|
35
35
|
var _util = require("../shared/util.js");
|
36
36
|
|
@@ -483,11 +483,18 @@ function isValidFetchUrl(url, baseUrl) {
|
|
483
483
|
}
|
484
484
|
}
|
485
485
|
|
486
|
-
function loadScript(src) {
|
486
|
+
function loadScript(src, removeScriptElement = false) {
|
487
487
|
return new Promise((resolve, reject) => {
|
488
488
|
const script = document.createElement("script");
|
489
489
|
script.src = src;
|
490
|
-
|
490
|
+
|
491
|
+
script.onload = function (evt) {
|
492
|
+
if (removeScriptElement) {
|
493
|
+
script.remove();
|
494
|
+
}
|
495
|
+
|
496
|
+
resolve(evt);
|
497
|
+
};
|
491
498
|
|
492
499
|
script.onerror = function () {
|
493
500
|
reject(new Error(`Cannot load script at: ${script.src}`));
|
@@ -36,7 +36,7 @@ function createFetchOptions(headers, withCredentials, abortController) {
|
|
36
36
|
return {
|
37
37
|
method: "GET",
|
38
38
|
headers,
|
39
|
-
signal: abortController
|
39
|
+
signal: abortController?.signal,
|
40
40
|
mode: "cors",
|
41
41
|
credentials: withCredentials ? "include" : "same-origin",
|
42
42
|
redirect: "follow"
|
@@ -69,7 +69,7 @@ class PDFFetchStream {
|
|
69
69
|
}
|
70
70
|
|
71
71
|
get _progressiveDataLength() {
|
72
|
-
return this._fullRequestReader
|
72
|
+
return this._fullRequestReader?._loaded ?? 0;
|
73
73
|
}
|
74
74
|
|
75
75
|
getFullReader() {
|
@@ -254,7 +254,7 @@ class PDFFetchStreamRangeReader {
|
|
254
254
|
|
255
255
|
this._reader = response.body.getReader();
|
256
256
|
}).catch(reason => {
|
257
|
-
if (reason
|
257
|
+
if (reason?.name === "AbortError") {
|
258
258
|
return;
|
259
259
|
}
|
260
260
|
|
@@ -128,8 +128,7 @@ class BaseFontLoader {
|
|
128
128
|
}
|
129
129
|
|
130
130
|
get isFontLoadingAPISupported() {
|
131
|
-
|
132
|
-
return (0, _util.shadow)(this, "isFontLoadingAPISupported", supported);
|
131
|
+
return (0, _util.shadow)(this, "isFontLoadingAPISupported", !!this._document?.fonts);
|
133
132
|
}
|
134
133
|
|
135
134
|
get isSyncFontLoadingSupported() {
|
@@ -167,7 +166,7 @@ exports.FontLoader = FontLoader;
|
|
167
166
|
} else {
|
168
167
|
const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
|
169
168
|
|
170
|
-
if (m
|
169
|
+
if (m?.[1] >= 14) {
|
171
170
|
supported = true;
|
172
171
|
}
|
173
172
|
}
|
package/lib/display/metadata.js
CHANGED
@@ -28,19 +28,23 @@ exports.Metadata = void 0;
|
|
28
28
|
|
29
29
|
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var _xml_parser = require("
|
31
|
+
var _xml_parser = require("../shared/xml_parser.js");
|
32
32
|
|
33
33
|
class Metadata {
|
34
34
|
constructor(data) {
|
35
35
|
(0, _util.assert)(typeof data === "string", "Metadata: input is not a string");
|
36
36
|
data = this._repair(data);
|
37
|
-
const parser = new _xml_parser.SimpleXMLParser(
|
37
|
+
const parser = new _xml_parser.SimpleXMLParser({
|
38
|
+
lowerCaseName: true
|
39
|
+
});
|
38
40
|
const xmlDocument = parser.parseFromString(data);
|
39
41
|
this._metadataMap = new Map();
|
40
42
|
|
41
43
|
if (xmlDocument) {
|
42
44
|
this._parse(xmlDocument);
|
43
45
|
}
|
46
|
+
|
47
|
+
this._data = data;
|
44
48
|
}
|
45
49
|
|
46
50
|
_repair(data) {
|
@@ -83,49 +87,79 @@ class Metadata {
|
|
83
87
|
});
|
84
88
|
}
|
85
89
|
|
90
|
+
_getSequence(entry) {
|
91
|
+
const name = entry.nodeName;
|
92
|
+
|
93
|
+
if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
|
94
|
+
return null;
|
95
|
+
}
|
96
|
+
|
97
|
+
return entry.childNodes.filter(node => node.nodeName === "rdf:li");
|
98
|
+
}
|
99
|
+
|
100
|
+
_getCreators(entry) {
|
101
|
+
if (entry.nodeName !== "dc:creator") {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
|
105
|
+
if (!entry.hasChildNodes()) {
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
|
109
|
+
const seqNode = entry.childNodes[0];
|
110
|
+
const authors = this._getSequence(seqNode) || [];
|
111
|
+
|
112
|
+
this._metadataMap.set(entry.nodeName, authors.map(node => node.textContent.trim()));
|
113
|
+
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
|
86
117
|
_parse(xmlDocument) {
|
87
118
|
let rdf = xmlDocument.documentElement;
|
88
119
|
|
89
|
-
if (rdf.nodeName
|
120
|
+
if (rdf.nodeName !== "rdf:rdf") {
|
90
121
|
rdf = rdf.firstChild;
|
91
122
|
|
92
|
-
while (rdf && rdf.nodeName
|
123
|
+
while (rdf && rdf.nodeName !== "rdf:rdf") {
|
93
124
|
rdf = rdf.nextSibling;
|
94
125
|
}
|
95
126
|
}
|
96
127
|
|
97
|
-
|
98
|
-
|
99
|
-
if (!rdf || nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
|
128
|
+
if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
|
100
129
|
return;
|
101
130
|
}
|
102
131
|
|
103
|
-
const
|
104
|
-
|
105
|
-
for (let i = 0, ii = children.length; i < ii; i++) {
|
106
|
-
const desc = children[i];
|
107
|
-
|
108
|
-
if (desc.nodeName.toLowerCase() !== "rdf:description") {
|
132
|
+
for (const desc of rdf.childNodes) {
|
133
|
+
if (desc.nodeName !== "rdf:description") {
|
109
134
|
continue;
|
110
135
|
}
|
111
136
|
|
112
|
-
for (
|
113
|
-
|
114
|
-
const entry = desc.childNodes[j];
|
115
|
-
const name = entry.nodeName.toLowerCase();
|
137
|
+
for (const entry of desc.childNodes) {
|
138
|
+
const name = entry.nodeName;
|
116
139
|
|
117
|
-
|
140
|
+
if (name === "#text") {
|
141
|
+
continue;
|
118
142
|
}
|
143
|
+
|
144
|
+
if (this._getCreators(entry)) {
|
145
|
+
continue;
|
146
|
+
}
|
147
|
+
|
148
|
+
this._metadataMap.set(name, entry.textContent.trim());
|
119
149
|
}
|
120
150
|
}
|
121
151
|
}
|
122
152
|
|
153
|
+
getRaw() {
|
154
|
+
return this._data;
|
155
|
+
}
|
156
|
+
|
123
157
|
get(name) {
|
124
|
-
return this._metadataMap.
|
158
|
+
return this._metadataMap.get(name) ?? null;
|
125
159
|
}
|
126
160
|
|
127
161
|
getAll() {
|
128
|
-
return
|
162
|
+
return (0, _util.objectFromEntries)(this._metadataMap);
|
129
163
|
}
|
130
164
|
|
131
165
|
has(name) {
|
@@ -29,7 +29,7 @@ exports.TilingPattern = void 0;
|
|
29
29
|
|
30
30
|
var _util = require("../shared/util.js");
|
31
31
|
|
32
|
-
|
32
|
+
const ShadingIRs = {};
|
33
33
|
|
34
34
|
function applyBoundingBox(ctx, bbox) {
|
35
35
|
if (!bbox || typeof Path2D === "undefined") {
|
@@ -45,18 +45,17 @@ function applyBoundingBox(ctx, bbox) {
|
|
45
45
|
|
46
46
|
ShadingIRs.RadialAxial = {
|
47
47
|
fromIR: function RadialAxial_fromIR(raw) {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
const type = raw[1];
|
49
|
+
const bbox = raw[2];
|
50
|
+
const colorStops = raw[3];
|
51
|
+
const p0 = raw[4];
|
52
|
+
const p1 = raw[5];
|
53
|
+
const r0 = raw[6];
|
54
|
+
const r1 = raw[7];
|
55
55
|
return {
|
56
|
-
type: "Pattern",
|
57
56
|
getPattern: function RadialAxial_getPattern(ctx) {
|
58
57
|
applyBoundingBox(ctx, bbox);
|
59
|
-
|
58
|
+
let grad;
|
60
59
|
|
61
60
|
if (type === "axial") {
|
62
61
|
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
|
@@ -64,8 +63,8 @@ ShadingIRs.RadialAxial = {
|
|
64
63
|
grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
|
65
64
|
}
|
66
65
|
|
67
|
-
for (
|
68
|
-
|
66
|
+
for (let i = 0, ii = colorStops.length; i < ii; ++i) {
|
67
|
+
const c = colorStops[i];
|
69
68
|
grad.addColorStop(c[0], c[1]);
|
70
69
|
}
|
71
70
|
|
@@ -75,13 +74,13 @@ ShadingIRs.RadialAxial = {
|
|
75
74
|
}
|
76
75
|
};
|
77
76
|
|
78
|
-
|
77
|
+
const createMeshCanvas = function createMeshCanvasClosure() {
|
79
78
|
function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
const coords = context.coords,
|
80
|
+
colors = context.colors;
|
81
|
+
const bytes = data.data,
|
82
|
+
rowSize = data.width * 4;
|
83
|
+
let tmp;
|
85
84
|
|
86
85
|
if (coords[p1 + 1] > coords[p2 + 1]) {
|
87
86
|
tmp = p1;
|
@@ -110,32 +109,32 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
110
109
|
c2 = tmp;
|
111
110
|
}
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
112
|
+
const x1 = (coords[p1] + context.offsetX) * context.scaleX;
|
113
|
+
const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
|
114
|
+
const x2 = (coords[p2] + context.offsetX) * context.scaleX;
|
115
|
+
const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
|
116
|
+
const x3 = (coords[p3] + context.offsetX) * context.scaleX;
|
117
|
+
const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
|
119
118
|
|
120
119
|
if (y1 >= y3) {
|
121
120
|
return;
|
122
121
|
}
|
123
122
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
for (
|
123
|
+
const c1r = colors[c1],
|
124
|
+
c1g = colors[c1 + 1],
|
125
|
+
c1b = colors[c1 + 2];
|
126
|
+
const c2r = colors[c2],
|
127
|
+
c2g = colors[c2 + 1],
|
128
|
+
c2b = colors[c2 + 2];
|
129
|
+
const c3r = colors[c3],
|
130
|
+
c3g = colors[c3 + 1],
|
131
|
+
c3b = colors[c3 + 2];
|
132
|
+
const minY = Math.round(y1),
|
133
|
+
maxY = Math.round(y3);
|
134
|
+
let xa, car, cag, cab;
|
135
|
+
let xb, cbr, cbg, cbb;
|
136
|
+
|
137
|
+
for (let y = minY; y <= maxY; y++) {
|
139
138
|
if (y < y2) {
|
140
139
|
let k;
|
141
140
|
|
@@ -182,11 +181,11 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
182
181
|
cbr = c1r - (c1r - c3r) * k;
|
183
182
|
cbg = c1g - (c1g - c3g) * k;
|
184
183
|
cbb = c1b - (c1b - c3b) * k;
|
185
|
-
|
186
|
-
|
187
|
-
|
184
|
+
const x1_ = Math.round(Math.min(xa, xb));
|
185
|
+
const x2_ = Math.round(Math.max(xa, xb));
|
186
|
+
let j = rowSize * y + x1_ * 4;
|
188
187
|
|
189
|
-
for (
|
188
|
+
for (let x = x1_; x <= x2_; x++) {
|
190
189
|
k = (xa - x) / (xa - xb);
|
191
190
|
|
192
191
|
if (k < 0) {
|
@@ -204,20 +203,20 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
204
203
|
}
|
205
204
|
|
206
205
|
function drawFigure(data, figure, context) {
|
207
|
-
|
208
|
-
|
209
|
-
|
206
|
+
const ps = figure.coords;
|
207
|
+
const cs = figure.colors;
|
208
|
+
let i, ii;
|
210
209
|
|
211
210
|
switch (figure.type) {
|
212
211
|
case "lattice":
|
213
|
-
|
214
|
-
|
215
|
-
|
212
|
+
const verticesPerRow = figure.verticesPerRow;
|
213
|
+
const rows = Math.floor(ps.length / verticesPerRow) - 1;
|
214
|
+
const cols = verticesPerRow - 1;
|
216
215
|
|
217
216
|
for (i = 0; i < rows; i++) {
|
218
|
-
|
217
|
+
let q = i * verticesPerRow;
|
219
218
|
|
220
|
-
for (
|
219
|
+
for (let j = 0; j < cols; j++, q++) {
|
221
220
|
drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
|
222
221
|
drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
|
223
222
|
}
|
@@ -238,18 +237,18 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
238
237
|
}
|
239
238
|
|
240
239
|
function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
240
|
+
const EXPECTED_SCALE = 1.1;
|
241
|
+
const MAX_PATTERN_SIZE = 3000;
|
242
|
+
const BORDER_SIZE = 2;
|
243
|
+
const offsetX = Math.floor(bounds[0]);
|
244
|
+
const offsetY = Math.floor(bounds[1]);
|
245
|
+
const boundsWidth = Math.ceil(bounds[2]) - offsetX;
|
246
|
+
const boundsHeight = Math.ceil(bounds[3]) - offsetY;
|
247
|
+
const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
248
|
+
const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
249
|
+
const scaleX = boundsWidth / width;
|
250
|
+
const scaleY = boundsHeight / height;
|
251
|
+
const context = {
|
253
252
|
coords,
|
254
253
|
colors,
|
255
254
|
offsetX: -offsetX,
|
@@ -257,9 +256,9 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
257
256
|
scaleX: 1 / scaleX,
|
258
257
|
scaleY: 1 / scaleY
|
259
258
|
};
|
260
|
-
|
261
|
-
|
262
|
-
|
259
|
+
const paddedWidth = width + BORDER_SIZE * 2;
|
260
|
+
const paddedHeight = height + BORDER_SIZE * 2;
|
261
|
+
let canvas, tmpCanvas, i, ii;
|
263
262
|
|
264
263
|
if (webGLContext.isEnabled) {
|
265
264
|
canvas = webGLContext.drawFigures({
|
@@ -274,11 +273,11 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
274
273
|
canvas = tmpCanvas.canvas;
|
275
274
|
} else {
|
276
275
|
tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
|
277
|
-
|
278
|
-
|
276
|
+
const tmpCtx = tmpCanvas.context;
|
277
|
+
const data = tmpCtx.createImageData(width, height);
|
279
278
|
|
280
279
|
if (backgroundColor) {
|
281
|
-
|
280
|
+
const bytes = data.data;
|
282
281
|
|
283
282
|
for (i = 0, ii = bytes.length; i < ii; i += 4) {
|
284
283
|
bytes[i] = backgroundColor[0];
|
@@ -310,18 +309,17 @@ var createMeshCanvas = function createMeshCanvasClosure() {
|
|
310
309
|
|
311
310
|
ShadingIRs.Mesh = {
|
312
311
|
fromIR: function Mesh_fromIR(raw) {
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
312
|
+
const coords = raw[2];
|
313
|
+
const colors = raw[3];
|
314
|
+
const figures = raw[4];
|
315
|
+
const bounds = raw[5];
|
316
|
+
const matrix = raw[6];
|
317
|
+
const bbox = raw[7];
|
318
|
+
const background = raw[8];
|
320
319
|
return {
|
321
|
-
type: "Pattern",
|
322
320
|
getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
|
323
321
|
applyBoundingBox(ctx, bbox);
|
324
|
-
|
322
|
+
let scale;
|
325
323
|
|
326
324
|
if (shadingFill) {
|
327
325
|
scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
|
@@ -329,13 +327,13 @@ ShadingIRs.Mesh = {
|
|
329
327
|
scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
|
330
328
|
|
331
329
|
if (matrix) {
|
332
|
-
|
330
|
+
const matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
|
333
331
|
|
334
332
|
scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
|
335
333
|
}
|
336
334
|
}
|
337
335
|
|
338
|
-
|
336
|
+
const temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
|
339
337
|
|
340
338
|
if (!shadingFill) {
|
341
339
|
ctx.setTransform.apply(ctx, owner.baseTransform);
|
@@ -355,7 +353,6 @@ ShadingIRs.Mesh = {
|
|
355
353
|
ShadingIRs.Dummy = {
|
356
354
|
fromIR: function Dummy_fromIR() {
|
357
355
|
return {
|
358
|
-
type: "Pattern",
|
359
356
|
getPattern: function Dummy_fromIR_getPattern() {
|
360
357
|
return "hotpink";
|
361
358
|
}
|
@@ -364,7 +361,7 @@ ShadingIRs.Dummy = {
|
|
364
361
|
};
|
365
362
|
|
366
363
|
function getShadingPatternFromIR(raw) {
|
367
|
-
|
364
|
+
const shadingIR = ShadingIRs[raw[0]];
|
368
365
|
|
369
366
|
if (!shadingIR) {
|
370
367
|
throw new Error(`Unknown IR type: ${raw[0]}`);
|
@@ -373,12 +370,12 @@ function getShadingPatternFromIR(raw) {
|
|
373
370
|
return shadingIR.fromIR(raw);
|
374
371
|
}
|
375
372
|
|
376
|
-
|
377
|
-
|
373
|
+
const TilingPattern = function TilingPatternClosure() {
|
374
|
+
const PaintType = {
|
378
375
|
COLORED: 1,
|
379
376
|
UNCOLORED: 2
|
380
377
|
};
|
381
|
-
|
378
|
+
const MAX_PATTERN_SIZE = 3000;
|
382
379
|
|
383
380
|
function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
|
384
381
|
this.operatorList = IR[2];
|
@@ -391,36 +388,35 @@ var TilingPattern = function TilingPatternClosure() {
|
|
391
388
|
this.color = color;
|
392
389
|
this.canvasGraphicsFactory = canvasGraphicsFactory;
|
393
390
|
this.baseTransform = baseTransform;
|
394
|
-
this.type = "Pattern";
|
395
391
|
this.ctx = ctx;
|
396
392
|
}
|
397
393
|
|
398
394
|
TilingPattern.prototype = {
|
399
395
|
createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
396
|
+
const operatorList = this.operatorList;
|
397
|
+
const bbox = this.bbox;
|
398
|
+
const xstep = this.xstep;
|
399
|
+
const ystep = this.ystep;
|
400
|
+
const paintType = this.paintType;
|
401
|
+
const tilingType = this.tilingType;
|
402
|
+
const color = this.color;
|
403
|
+
const canvasGraphicsFactory = this.canvasGraphicsFactory;
|
408
404
|
(0, _util.info)("TilingType: " + tilingType);
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
405
|
+
const x0 = bbox[0],
|
406
|
+
y0 = bbox[1],
|
407
|
+
x1 = bbox[2],
|
408
|
+
y1 = bbox[3];
|
413
409
|
|
414
|
-
|
410
|
+
const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
|
415
411
|
|
416
|
-
|
412
|
+
const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
|
417
413
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
414
|
+
const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
|
415
|
+
const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
|
416
|
+
const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
|
417
|
+
const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
|
418
|
+
const tmpCtx = tmpCanvas.context;
|
419
|
+
const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
|
424
420
|
graphics.groupLevel = owner.groupLevel;
|
425
421
|
this.setFillAndStrokeStyleToContext(graphics, paintType, color);
|
426
422
|
graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
|
@@ -433,8 +429,8 @@ var TilingPattern = function TilingPatternClosure() {
|
|
433
429
|
},
|
434
430
|
getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
|
435
431
|
step = Math.abs(step);
|
436
|
-
|
437
|
-
|
432
|
+
const maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
|
433
|
+
let size = Math.ceil(step * scale);
|
438
434
|
|
439
435
|
if (size >= maxSize) {
|
440
436
|
size = maxSize;
|
@@ -449,8 +445,8 @@ var TilingPattern = function TilingPatternClosure() {
|
|
449
445
|
},
|
450
446
|
clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
|
451
447
|
if (Array.isArray(bbox) && bbox.length === 4) {
|
452
|
-
|
453
|
-
|
448
|
+
const bboxWidth = x1 - x0;
|
449
|
+
const bboxHeight = y1 - y0;
|
454
450
|
graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
|
455
451
|
graphics.clip();
|
456
452
|
graphics.endPath();
|
@@ -462,7 +458,7 @@ var TilingPattern = function TilingPatternClosure() {
|
|
462
458
|
|
463
459
|
switch (paintType) {
|
464
460
|
case PaintType.COLORED:
|
465
|
-
|
461
|
+
const ctx = this.ctx;
|
466
462
|
context.fillStyle = ctx.fillStyle;
|
467
463
|
context.strokeStyle = ctx.strokeStyle;
|
468
464
|
current.fillColor = ctx.fillStyle;
|
@@ -470,7 +466,7 @@ var TilingPattern = function TilingPatternClosure() {
|
|
470
466
|
break;
|
471
467
|
|
472
468
|
case PaintType.UNCOLORED:
|
473
|
-
|
469
|
+
const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
|
474
470
|
|
475
471
|
context.fillStyle = cssColor;
|
476
472
|
context.strokeStyle = cssColor;
|
@@ -486,7 +482,7 @@ var TilingPattern = function TilingPatternClosure() {
|
|
486
482
|
ctx = this.ctx;
|
487
483
|
ctx.setTransform.apply(ctx, this.baseTransform);
|
488
484
|
ctx.transform.apply(ctx, this.matrix);
|
489
|
-
|
485
|
+
const temporaryPatternCanvas = this.createPatternCanvas(owner);
|
490
486
|
return ctx.createPattern(temporaryPatternCanvas, "repeat");
|
491
487
|
}
|
492
488
|
};
|
package/lib/display/svg.js
CHANGED
@@ -893,7 +893,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
893
893
|
this.embeddedFonts[fontObj.loadedName] = fontObj;
|
894
894
|
}
|
895
895
|
|
896
|
-
current.fontMatrix = fontObj.fontMatrix
|
896
|
+
current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
897
897
|
let bold = "normal";
|
898
898
|
|
899
899
|
if (fontObj.black) {
|
@@ -924,7 +924,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
924
924
|
endText() {
|
925
925
|
const current = this.current;
|
926
926
|
|
927
|
-
if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement
|
927
|
+
if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
|
928
928
|
current.element = current.txtElement;
|
929
929
|
this.clip("nonzero");
|
930
930
|
this.endPath();
|
@@ -954,7 +954,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
954
954
|
}
|
955
955
|
|
956
956
|
setStrokeRGBColor(r, g, b) {
|
957
|
-
this.current.strokeColor = _util.Util.
|
957
|
+
this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
|
958
958
|
}
|
959
959
|
|
960
960
|
setFillAlpha(fillAlpha) {
|
@@ -962,7 +962,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
962
962
|
}
|
963
963
|
|
964
964
|
setFillRGBColor(r, g, b) {
|
965
|
-
this.current.fillColor = _util.Util.
|
965
|
+
this.current.fillColor = _util.Util.makeHexColor(r, g, b);
|
966
966
|
this.current.tspan = this.svgFactory.createElement("svg:tspan");
|
967
967
|
this.current.xcoords = [];
|
968
968
|
this.current.ycoords = [];
|
@@ -1050,7 +1050,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
1050
1050
|
this.transformMatrix = matrix;
|
1051
1051
|
|
1052
1052
|
if (paintType === 2) {
|
1053
|
-
const cssColor = _util.Util.
|
1053
|
+
const cssColor = _util.Util.makeHexColor(...color);
|
1054
1054
|
|
1055
1055
|
this.current.fillColor = cssColor;
|
1056
1056
|
this.current.strokeColor = cssColor;
|