Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 12, 2024
1 parent 9df376e commit ad424d0
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 68 deletions.
10 changes: 5 additions & 5 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4673,7 +4673,7 @@ class InternalRenderTask {
}
}
const version = "4.3.0";
const build = "1b811ac";
const build = "b676540";

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down Expand Up @@ -5174,7 +5174,7 @@ class TilingPattern {
static MAX_PATTERN_SIZE = 3000;
constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
this.operatorList = IR[2];
this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
this.matrix = IR[3];
this.bbox = IR[4];
this.xstep = IR[5];
this.ystep = IR[6];
Expand Down Expand Up @@ -7066,7 +7066,7 @@ class CanvasGraphics {
}
this.save();
this.baseTransformStack.push(this.baseTransform);
if (Array.isArray(matrix) && matrix.length === 6) {
if (matrix) {
this.transform(...matrix);
}
this.baseTransform = (0,display_utils.getCurrentTransform)(this.ctx);
Expand Down Expand Up @@ -7179,7 +7179,7 @@ class CanvasGraphics {
if (this.baseTransform) {
this.ctx.setTransform(...this.baseTransform);
}
if (Array.isArray(rect) && rect.length === 4) {
if (rect) {
const width = rect[2] - rect[0];
const height = rect[3] - rect[1];
if (hasOwnCanvas && this.annotationCanvasMap) {
Expand Down Expand Up @@ -18377,7 +18377,7 @@ _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.t


const pdfjsVersion = "4.3.0";
const pdfjsBuild = "1b811ac";
const pdfjsBuild = "b676540";

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down
2 changes: 1 addition & 1 deletion build/pdf.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/pdf.sandbox.mjs

Large diffs are not rendered by default.

140 changes: 84 additions & 56 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,21 @@ function readUint32(data, offset) {
function isWhiteSpace(ch) {
return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
}
function isBooleanArray(arr, len) {
return Array.isArray(arr) && (len === null || arr.length === len) && arr.every(x => typeof x === "boolean");
}
function isNumberArray(arr, len) {
return Array.isArray(arr) && (len === null || arr.length === len) && arr.every(x => typeof x === "number");
}
function lookupMatrix(arr, fallback) {
return isNumberArray(arr, 6) ? arr : fallback;
}
function lookupRect(arr, fallback) {
return isNumberArray(arr, 4) ? arr : fallback;
}
function lookupNormalRect(arr, fallback) {
return isNumberArray(arr, 4) ? Util.normalizeRect(arr) : fallback;
}
function parseXFAPath(path) {
const positionPattern = /(.+)\[(\d+)\]$/;
return path.split(".").map(component => {
Expand Down Expand Up @@ -24938,30 +24950,36 @@ class BaseShading {
class RadialAxialShading extends BaseShading {
constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
super();
this.coordsArr = dict.getArray("Coords");
this.shadingType = dict.get("ShadingType");
let coordsLen = 0;
if (this.shadingType === ShadingType.AXIAL) {
coordsLen = 4;
} else if (this.shadingType === ShadingType.RADIAL) {
coordsLen = 6;
}
this.coordsArr = dict.getArray("Coords");
if (!isNumberArray(this.coordsArr, coordsLen)) {
throw new FormatError("RadialAxialShading: Invalid /Coords array.");
}
const cs = ColorSpace.parse({
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
xref,
resources,
pdfFunctionFactory,
localColorSpaceCache
});
const bbox = dict.getArray("BBox");
this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
this.bbox = lookupNormalRect(dict.getArray("BBox"), null);
let t0 = 0.0,
t1 = 1.0;
if (dict.has("Domain")) {
const domainArr = dict.getArray("Domain");
t0 = domainArr[0];
t1 = domainArr[1];
const domainArr = dict.getArray("Domain");
if (isNumberArray(domainArr, 2)) {
[t0, t1] = domainArr;
}
let extendStart = false,
extendEnd = false;
if (dict.has("Extend")) {
const extendArr = dict.getArray("Extend");
extendStart = extendArr[0];
extendEnd = extendArr[1];
const extendArr = dict.getArray("Extend");
if (isBooleanArray(extendArr, 2)) {
[extendStart, extendEnd] = extendArr;
}
if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
const [x1, y1, r1, x2, y2, r2] = this.coordsArr;
Expand Down Expand Up @@ -25045,8 +25063,10 @@ class RadialAxialShading extends BaseShading {
this.colorStops = colorStops;
}
getIR() {
const coordsArr = this.coordsArr;
const shadingType = this.shadingType;
const {
coordsArr,
shadingType
} = this;
let type, p0, p1, r0, r1;
if (shadingType === ShadingType.AXIAL) {
p0 = [coordsArr[0], coordsArr[1]];
Expand Down Expand Up @@ -25175,8 +25195,7 @@ class MeshShading extends BaseShading {
}
const dict = stream.dict;
this.shadingType = dict.get("ShadingType");
const bbox = dict.getArray("BBox");
this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
this.bbox = lookupNormalRect(dict.getArray("BBox"), null);
const cs = ColorSpace.parse({
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
xref,
Expand Down Expand Up @@ -25668,14 +25687,26 @@ class DummyShading extends BaseShading {
}
}
function getTilingPatternIR(operatorList, dict, color) {
const matrix = dict.getArray("Matrix");
const bbox = Util.normalizeRect(dict.getArray("BBox"));
const matrix = lookupMatrix(dict.getArray("Matrix"), IDENTITY_MATRIX);
const bbox = lookupNormalRect(dict.getArray("BBox"), null);
if (!bbox || bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
throw new FormatError(`Invalid getTilingPatternIR /BBox array.`);
}
const xstep = dict.get("XStep");
if (typeof xstep !== "number") {
throw new FormatError(`Invalid getTilingPatternIR /XStep value.`);
}
const ystep = dict.get("YStep");
if (typeof ystep !== "number") {
throw new FormatError(`Invalid getTilingPatternIR /YStep value.`);
}
const paintType = dict.get("PaintType");
if (!Number.isInteger(paintType)) {
throw new FormatError(`Invalid getTilingPatternIR /PaintType value.`);
}
const tilingType = dict.get("TilingType");
if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
if (!Number.isInteger(tilingType)) {
throw new FormatError(`Invalid getTilingPatternIR /TilingType value.`);
}
return ["TilingPattern", color, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
}
Expand Down Expand Up @@ -29844,9 +29875,8 @@ class PartialEvaluator {
}
async buildFormXObject(resources, xobj, smask, operatorList, task, initialState, localColorSpaceCache) {
const dict = xobj.dict;
const matrix = dict.getArray("Matrix");
let bbox = dict.getArray("BBox");
bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
const matrix = lookupMatrix(dict.getArray("Matrix"), null);
const bbox = lookupNormalRect(dict.getArray("BBox"), null);
let optionalContent, groupOptions;
if (dict.has("OC")) {
optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources);
Expand Down Expand Up @@ -30581,7 +30611,7 @@ class PartialEvaluator {
localShadingPatternCache
});
if (objId) {
const matrix = dict.getArray("Matrix");
const matrix = lookupMatrix(dict.getArray("Matrix"), null);
operatorList.addOp(fn, ["Shading", objId, matrix]);
}
return undefined;
Expand Down Expand Up @@ -31778,8 +31808,8 @@ class PartialEvaluator {
}
const currentState = stateManager.state.clone();
const xObjStateManager = new StateManager(currentState);
const matrix = xobj.dict.getArray("Matrix");
if (Array.isArray(matrix) && matrix.length === 6) {
const matrix = lookupMatrix(xobj.dict.getArray("Matrix"), null);
if (matrix) {
xObjStateManager.transform(matrix);
}
enqueueChunk();
Expand Down Expand Up @@ -32520,10 +32550,7 @@ class PartialEvaluator {
const isType3Font = type === "Type3";
if (!descriptor) {
if (isType3Font) {
let bbox = dict.getArray("FontBBox");
if (!isNumberArray(bbox, 4)) {
bbox = [0, 0, 0, 0];
}
const bbox = lookupNormalRect(dict.getArray("FontBBox"), [0, 0, 0, 0]);
descriptor = new Dict(null);
descriptor.set("FontName", Name.get(type));
descriptor.set("FontBBox", bbox);
Expand Down Expand Up @@ -32645,14 +32672,8 @@ class PartialEvaluator {
systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName, type);
}
}
let fontMatrix = dict.getArray("FontMatrix");
if (!isNumberArray(fontMatrix, 6)) {
fontMatrix = FONT_IDENTITY_MATRIX;
}
let bbox = descriptor.getArray("FontBBox") || dict.getArray("FontBBox");
if (!isNumberArray(bbox, 4)) {
bbox = undefined;
}
const fontMatrix = lookupMatrix(dict.getArray("FontMatrix"), FONT_IDENTITY_MATRIX);
const bbox = lookupNormalRect(descriptor.getArray("FontBBox") || dict.getArray("FontBBox"), undefined);
let ascent = descriptor.get("Ascent");
if (typeof ascent !== "number") {
ascent = undefined;
Expand Down Expand Up @@ -37295,7 +37316,7 @@ class Catalog {
const color = outlineDict.getArray("C");
const count = outlineDict.get("Count");
let rgbColor = blackColor;
if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
if (isNumberArray(color, 3) && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
}
const outlineItem = {
Expand Down Expand Up @@ -49571,7 +49592,7 @@ function getPdfColorArray(color) {
}
function getQuadPoints(dict, rect) {
const quadPoints = dict.getArray("QuadPoints");
if (!Array.isArray(quadPoints) || quadPoints.length === 0 || quadPoints.length % 8 > 0) {
if (!isNumberArray(quadPoints, null) || quadPoints.length === 0 || quadPoints.length % 8 > 0) {
return null;
}
const quadPointsLists = [];
Expand Down Expand Up @@ -49765,7 +49786,7 @@ class Annotation {
return this._hasFlag(this.flags, flag);
}
setRectangle(rectangle) {
this.rectangle = Array.isArray(rectangle) && rectangle.length === 4 ? Util.normalizeRect(rectangle) : [0, 0, 0, 0];
this.rectangle = lookupNormalRect(rectangle, [0, 0, 0, 0]);
}
setColor(color) {
this.color = getRgbColor(color);
Expand Down Expand Up @@ -49918,8 +49939,8 @@ class Annotation {
}
const appearanceDict = appearance.dict;
const resources = await this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"], appearance);
const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
const bbox = lookupRect(appearanceDict.getArray("BBox"), [0, 0, 1, 1]);
const matrix = lookupMatrix(appearanceDict.getArray("Matrix"), IDENTITY_MATRIX);
const transform = getTransformMatrix(rect, bbox, matrix);
const opList = new OperatorList();
let optionalContent;
Expand Down Expand Up @@ -49994,7 +50015,9 @@ class Annotation {
}
if (text.length > 1 || text[0]) {
const appearanceDict = this.appearance.dict;
this.data.textPosition = this._transformPoint(firstPosition, appearanceDict.getArray("BBox"), appearanceDict.getArray("Matrix"));
const bbox = lookupRect(appearanceDict.getArray("BBox"), null);
const matrix = lookupMatrix(appearanceDict.getArray("Matrix"), null);
this.data.textPosition = this._transformPoint(firstPosition, bbox, matrix);
this.data.textContent = text;
}
}
Expand Down Expand Up @@ -51046,7 +51069,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
const appearance = value ? this.checkedAppearance : this.uncheckedAppearance;
if (appearance) {
const savedAppearance = this.appearance;
const savedMatrix = appearance.dict.getArray("Matrix") || IDENTITY_MATRIX;
const savedMatrix = lookupMatrix(appearance.dict.getArray("Matrix"), IDENTITY_MATRIX);
if (rotation) {
appearance.dict.set("Matrix", this.getRotationMatrix(annotationStorage));
}
Expand Down Expand Up @@ -51632,8 +51655,7 @@ class PopupAnnotation extends Annotation {
warn("Popup annotation has a missing or invalid parent annotation.");
return;
}
const parentRect = parentItem.getArray("Rect");
this.data.parentRect = Array.isArray(parentRect) && parentRect.length === 4 ? Util.normalizeRect(parentRect) : null;
this.data.parentRect = lookupNormalRect(parentItem.getArray("Rect"), null);
const rt = parentItem.get("RT");
if (isName(rt, AnnotationReplyType.GROUP)) {
parentItem = parentItem.get("IRT");
Expand Down Expand Up @@ -51871,7 +51893,7 @@ class LineAnnotation extends MarkupAnnotation {
this.data.annotationType = AnnotationType.LINE;
this.data.hasOwnCanvas = this.data.noRotate;
this.data.noHTML = false;
const lineCoordinates = dict.getArray("L");
const lineCoordinates = lookupRect(dict.getArray("L"), [0, 0, 0, 0]);
this.data.lineCoordinates = Util.normalizeRect(lineCoordinates);
this.setLineEndings(dict.getArray("LE"));
this.data.lineEndings = this.lineEndings;
Expand Down Expand Up @@ -52007,7 +52029,7 @@ class PolylineAnnotation extends MarkupAnnotation {
this.data.lineEndings = this.lineEndings;
}
const rawVertices = dict.getArray("Vertices");
if (!Array.isArray(rawVertices)) {
if (!isNumberArray(rawVertices, null)) {
return;
}
for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
Expand Down Expand Up @@ -52077,11 +52099,18 @@ class InkAnnotation extends MarkupAnnotation {
}
for (let i = 0, ii = rawInkLists.length; i < ii; ++i) {
this.data.inkLists.push([]);
if (!Array.isArray(rawInkLists[i])) {
continue;
}
for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) {
this.data.inkLists[i].push({
x: xref.fetchIfRef(rawInkLists[i][j]),
y: xref.fetchIfRef(rawInkLists[i][j + 1])
});
const x = xref.fetchIfRef(rawInkLists[i][j]),
y = xref.fetchIfRef(rawInkLists[i][j + 1]);
if (typeof x === "number" && typeof y === "number") {
this.data.inkLists[i].push({
x,
y
});
}
}
}
if (!this.appearance) {
Expand Down Expand Up @@ -53482,9 +53511,8 @@ class Page {
if (this.xfaData) {
return this.xfaData.bbox;
}
let box = this._getInheritableProperty(name, true);
if (Array.isArray(box) && box.length === 4) {
box = Util.normalizeRect(box);
const box = lookupNormalRect(this._getInheritableProperty(name, true), null);
if (box) {
if (box[2] - box[0] > 0 && box[3] - box[1] > 0) {
return box;
}
Expand Down Expand Up @@ -56061,7 +56089,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.3.0";
const pdfjsBuild = "1b811ac";
const pdfjsBuild = "b676540";

var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };
Expand Down
2 changes: 1 addition & 1 deletion build/pdf.worker.mjs.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions web/viewer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9173,7 +9173,6 @@ class PDFPageView {
this.renderingState = _ui_utils_js__WEBPACK_IMPORTED_MODULE_1__.RenderingStates.RUNNING;
const canvasWrapper = document.createElement("div");
canvasWrapper.classList.add("canvasWrapper");
canvasWrapper.setAttribute("aria-hidden", true);
this.#addLayer(canvasWrapper, "canvasWrapper");
if (!this.textLayer && this.#textLayerMode !== _ui_utils_js__WEBPACK_IMPORTED_MODULE_1__.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
this._accessibilityManager ||= new _text_accessibility_js__WEBPACK_IMPORTED_MODULE_9__.TextAccessibilityManager();
Expand Down Expand Up @@ -14993,7 +14992,7 @@ _app_js__WEBPACK_IMPORTED_MODULE_3__ = (__webpack_async_dependencies__.then ? (a


const pdfjsVersion = "4.3.0";
const pdfjsBuild = "1b811ac";
const pdfjsBuild = "b676540";
const AppConstants = {
LinkTarget: _pdf_link_service_js__WEBPACK_IMPORTED_MODULE_2__.LinkTarget,
RenderingStates: _ui_utils_js__WEBPACK_IMPORTED_MODULE_0__.RenderingStates,
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.mjs.map

Large diffs are not rendered by default.

0 comments on commit ad424d0

Please sign in to comment.