Merge pull request #16543 from Snuffleupagus/limit-more-to-GENERIC

Limit more code to GENERIC builds
This commit is contained in:
Jonas Jenwald 2023-06-15 13:58:52 +02:00 committed by GitHub
commit a37f7d2477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1614 additions and 1640 deletions

View File

@ -1552,6 +1552,9 @@ class PDFPageProxy {
annotationMode = AnnotationMode.ENABLE, annotationMode = AnnotationMode.ENABLE,
printAnnotationStorage = null, printAnnotationStorage = null,
} = {}) { } = {}) {
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
throw new Error("Not implemented: getOperatorList");
}
function operatorListChanged() { function operatorListChanged() {
if (intentState.operatorList.lastChunk) { if (intentState.operatorList.lastChunk) {
intentState.opListReadCapability.resolve(intentState.operatorList); intentState.opListReadCapability.resolve(intentState.operatorList);

View File

@ -21,41 +21,33 @@ import {
ImageKind, ImageKind,
OPS, OPS,
TextRenderingMode, TextRenderingMode,
unreachable,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
import { isNodeJS } from "../shared/is_node.js"; import { isNodeJS } from "../shared/is_node.js";
/** @type {any} */ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
// eslint-disable-next-line import/no-mutable-exports throw new Error(
let SVGGraphics = class { 'Module "SVGGraphics" shall not be used outside GENERIC builds.'
constructor() { );
unreachable("Not implemented: SVGGraphics"); }
}
};
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { const SVG_DEFAULTS = {
const SVG_DEFAULTS = {
fontStyle: "normal", fontStyle: "normal",
fontWeight: "normal", fontWeight: "normal",
fillColor: "#000000", fillColor: "#000000",
}; };
const XML_NS = "http://www.w3.org/XML/1998/namespace"; const XML_NS = "http://www.w3.org/XML/1998/namespace";
const XLINK_NS = "http://www.w3.org/1999/xlink"; const XLINK_NS = "http://www.w3.org/1999/xlink";
const LINE_CAP_STYLES = ["butt", "round", "square"]; const LINE_CAP_STYLES = ["butt", "round", "square"];
const LINE_JOIN_STYLES = ["miter", "round", "bevel"]; const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
const createObjectURL = function ( const createObjectURL = function (
data, data,
contentType = "", contentType = "",
forceDataSchema = false forceDataSchema = false
) { ) {
if ( if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
URL.createObjectURL &&
typeof Blob !== "undefined" &&
!forceDataSchema
) {
return URL.createObjectURL(new Blob([data], { type: contentType })); return URL.createObjectURL(new Blob([data], { type: contentType }));
} }
// Blob/createObjectURL is not available, falling back to data schema. // Blob/createObjectURL is not available, falling back to data schema.
@ -74,9 +66,9 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4]; buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
} }
return buffer; return buffer;
}; };
const convertImgDataToPng = (function () { const convertImgDataToPng = (function () {
const PNG_HEADER = new Uint8Array([ const PNG_HEADER = new Uint8Array([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
]); ]);
@ -177,9 +169,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
}); });
return output instanceof Uint8Array ? output : new Uint8Array(output); return output instanceof Uint8Array ? output : new Uint8Array(output);
} catch (e) { } catch (e) {
warn( warn("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
"Not compressing PNG because zlib.deflateSync is unavailable: " + e
);
} }
return deflateSyncUncompressed(literals); return deflateSyncUncompressed(literals);
@ -317,9 +307,9 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind; imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind;
return encode(imgData, kind, forceDataSchema, isMask); return encode(imgData, kind, forceDataSchema, isMask);
}; };
})(); })();
class SVGExtraState { class SVGExtraState {
constructor() { constructor() {
this.fontSizeScale = 1; this.fontSizeScale = 1;
this.fontWeight = SVG_DEFAULTS.fontWeight; this.fontWeight = SVG_DEFAULTS.fontWeight;
@ -376,10 +366,9 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
} }
// eslint-disable-next-line no-inner-declarations function opListToTree(opList) {
function opListToTree(opList) {
let opTree = []; let opTree = [];
const tmp = []; const tmp = [];
@ -398,16 +387,15 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
} }
} }
return opTree; return opTree;
} }
/** /**
* Format a float number as a string. * Format a float number as a string.
* *
* @param value {number} - The float number to format. * @param value {number} - The float number to format.
* @returns {string} * @returns {string}
*/ */
// eslint-disable-next-line no-inner-declarations function pf(value) {
function pf(value) {
if (Number.isInteger(value)) { if (Number.isInteger(value)) {
return value.toString(); return value.toString();
} }
@ -422,9 +410,9 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
i--; i--;
} while (s[i] === "0"); } while (s[i] === "0");
return s.substring(0, s[i] === "." ? i : i + 1); return s.substring(0, s[i] === "." ? i : i + 1);
} }
/** /**
* Format a transform matrix as a string. The standard rotation, scale and * Format a transform matrix as a string. The standard rotation, scale and
* translation matrices are replaced by their shorter forms, and for * translation matrices are replaced by their shorter forms, and for
* identity matrices an empty string is returned to save memory. * identity matrices an empty string is returned to save memory.
@ -432,8 +420,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
* @param m {Array} - The transform matrix to format. * @param m {Array} - The transform matrix to format.
* @returns {string} * @returns {string}
*/ */
// eslint-disable-next-line no-inner-declarations function pm(m) {
function pm(m) {
if (m[4] === 0 && m[5] === 0) { if (m[4] === 0 && m[5] === 0) {
if (m[1] === 0 && m[2] === 0) { if (m[1] === 0 && m[2] === 0) {
if (m[0] === 1 && m[3] === 1) { if (m[0] === 1 && m[3] === 1) {
@ -454,16 +441,16 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
`matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` +
`${pf(m[5])})` `${pf(m[5])})`
); );
} }
// The counts below are relevant for all pages, so they have to be global // The counts below are relevant for all pages, so they have to be global
// instead of being members of `SVGGraphics` (which is recreated for // instead of being members of `SVGGraphics` (which is recreated for
// each page). // each page).
let clipCount = 0; let clipCount = 0;
let maskCount = 0; let maskCount = 0;
let shadingCount = 0; let shadingCount = 0;
SVGGraphics = class { class SVGGraphics {
constructor(commonObjs, objs, forceDataSchema = false) { constructor(commonObjs, objs, forceDataSchema = false) {
deprecated( deprecated(
"The SVG back-end is no longer maintained and *may* be removed in the future." "The SVG back-end is no longer maintained and *may* be removed in the future."
@ -731,14 +718,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this.nextLine(); this.nextLine();
break; break;
case OPS.transform: case OPS.transform:
this.transform( this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
args[0],
args[1],
args[2],
args[3],
args[4],
args[5]
);
break; break;
case OPS.constructPath: case OPS.constructPath:
this.constructPath(args[0], args[1]); this.constructPath(args[0], args[1]);
@ -892,11 +872,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
x += charWidth; x += charWidth;
} }
current.tspan.setAttributeNS( current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
null,
"x",
current.xcoords.map(pf).join(" ")
);
if (vertical) { if (vertical) {
current.tspan.setAttributeNS( current.tspan.setAttributeNS(
null, null,
@ -1328,15 +1304,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
case OPS.curveTo3: case OPS.curveTo3:
x = args[j + 2]; x = args[j + 2];
y = args[j + 3]; y = args[j + 3];
d.push( d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
"C",
pf(args[j]),
pf(args[j + 1]),
pf(x),
pf(y),
pf(x),
pf(y)
);
j += 4; j += 4;
break; break;
case OPS.closePath: case OPS.closePath:
@ -1741,7 +1709,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
} }
return this.tgrp; return this.tgrp;
} }
};
} }
export { SVGGraphics }; export { SVGGraphics };

View File

@ -69,7 +69,6 @@ import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.
import { AnnotationEditorUIManager } from "./display/editor/tools.js"; import { AnnotationEditorUIManager } from "./display/editor/tools.js";
import { AnnotationLayer } from "./display/annotation_layer.js"; import { AnnotationLayer } from "./display/annotation_layer.js";
import { GlobalWorkerOptions } from "./display/worker_options.js"; import { GlobalWorkerOptions } from "./display/worker_options.js";
import { SVGGraphics } from "./display/svg.js";
import { XfaLayer } from "./display/xfa_layer.js"; import { XfaLayer } from "./display/xfa_layer.js";
/* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */
@ -79,6 +78,11 @@ const pdfjsVersion =
const pdfjsBuild = const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0; typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
const SVGGraphics =
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")
? require("./display/svg.js").SVGGraphics
: null;
export { export {
AbortException, AbortException,
AnnotationEditorLayer, AnnotationEditorLayer,