Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 28, 2024
1 parent 920fb2e commit e185a51
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 89 deletions.
27 changes: 16 additions & 11 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ const OPS = {
paintImageXObjectRepeat: 88,
paintImageMaskXObjectRepeat: 89,
paintSolidColorImageMask: 90,
constructPath: 91
constructPath: 91,
setStrokeTransparent: 92,
setFillTransparent: 93
};
const PasswordResponses = {
NEED_PASSWORD: 1,
Expand Down Expand Up @@ -913,7 +915,7 @@ class BaseCMapReaderFactory {
name
}) {
if (!this.baseUrl) {
throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");
}
if (!name) {
throw new Error("CMap name must be specified.");
Expand Down Expand Up @@ -941,7 +943,7 @@ class BaseStandardFontDataFactory {
filename
}) {
if (!this.baseUrl) {
throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");
}
if (!filename) {
throw new Error("Font filename must be specified.");
Expand Down Expand Up @@ -7734,14 +7736,17 @@ class CanvasGraphics {
this.current.patternFill = true;
}
setStrokeRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b);
this.ctx.strokeStyle = color;
this.current.strokeColor = color;
this.ctx.strokeStyle = this.current.strokeColor = Util.makeHexColor(r, g, b);
}
setStrokeTransparent() {
this.ctx.strokeStyle = this.current.strokeColor = "transparent";
}
setFillRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b);
this.ctx.fillStyle = color;
this.current.fillColor = color;
this.ctx.fillStyle = this.current.fillColor = Util.makeHexColor(r, g, b);
this.current.patternFill = false;
}
setFillTransparent() {
this.ctx.fillStyle = this.current.fillColor = "transparent";
this.current.patternFill = false;
}
_getPattern(objId, matrix = null) {
Expand Down Expand Up @@ -12720,7 +12725,7 @@ class InternalRenderTask {
}
}
const version = "4.5.0";
const build = "e92a6a1";
const build = "0ed4521";

;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
function makeColorComp(n) {
Expand Down Expand Up @@ -19707,7 +19712,7 @@ class DrawLayer {


const pdfjsVersion = "4.5.0";
const pdfjsBuild = "e92a6a1";
const pdfjsBuild = "0ed4521";

var __webpack_exports__AbortException = __webpack_exports__.AbortException;
var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
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.

78 changes: 53 additions & 25 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ const OPS = {
paintImageXObjectRepeat: 88,
paintImageMaskXObjectRepeat: 89,
paintSolidColorImageMask: 90,
constructPath: 91
constructPath: 91,
setStrokeTransparent: 92,
setFillTransparent: 93
};
const PasswordResponses = {
NEED_PASSWORD: 1,
Expand Down Expand Up @@ -1528,6 +1530,9 @@ function getNewAnnotationsMap(annotationStorage) {
}
return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
}
function stringToAsciiOrUTF16BE(str) {
return isAscii(str) ? str : stringToUTF16String(str, true);
}
function isAscii(str) {
return /^[\x00-\x7F]*$/.test(str);
}
Expand Down Expand Up @@ -2275,7 +2280,8 @@ class ColorSpace {
}
}
}
throw new FormatError(`Unrecognized ColorSpace: ${cs.name}`);
warn(`Unrecognized ColorSpace: ${cs.name}`);
return this.singletons.gray;
}
}
if (Array.isArray(cs)) {
Expand Down Expand Up @@ -2350,10 +2356,12 @@ class ColorSpace {
const range = params.getArray("Range");
return new LabCS(whitePoint, blackPoint, range);
default:
throw new FormatError(`Unimplemented ColorSpace object: ${mode}`);
warn(`Unimplemented ColorSpace object: ${mode}`);
return this.singletons.gray;
}
}
throw new FormatError(`Unrecognized ColorSpace object: ${cs}`);
warn(`Unrecognized ColorSpace object: ${cs}`);
return this.singletons.gray;
}
static isDefaultDecode(decode, numComps) {
if (!Array.isArray(decode)) {
Expand Down Expand Up @@ -31233,9 +31241,7 @@ class PartialEvaluator {
resources,
localColorSpaceCache
}).then(function (colorSpace) {
if (colorSpace) {
stateManager.state.fillColorSpace = colorSpace;
}
stateManager.state.fillColorSpace = colorSpace || ColorSpace.singletons.gray;
}));
return;
}
Expand All @@ -31251,9 +31257,7 @@ class PartialEvaluator {
resources,
localColorSpaceCache
}).then(function (colorSpace) {
if (colorSpace) {
stateManager.state.strokeColorSpace = colorSpace;
}
stateManager.state.strokeColorSpace = colorSpace || ColorSpace.singletons.gray;
}));
return;
}
Expand Down Expand Up @@ -31296,7 +31300,12 @@ class PartialEvaluator {
args = ColorSpace.singletons.rgb.getRgb(args, 0);
break;
case OPS.setFillColorN:
cs = stateManager.state.fillColorSpace;
cs = stateManager.state.patternFillColorSpace;
if (!cs) {
args = [];
fn = OPS.setFillTransparent;
break;
}
if (cs.name === "Pattern") {
next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
return;
Expand All @@ -31305,7 +31314,12 @@ class PartialEvaluator {
fn = OPS.setFillRGBColor;
break;
case OPS.setStrokeColorN:
cs = stateManager.state.strokeColorSpace;
cs = stateManager.state.patternStrokeColorSpace;
if (!cs) {
args = [];
fn = OPS.setStrokeTransparent;
break;
}
if (cs.name === "Pattern") {
next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
return;
Expand Down Expand Up @@ -33321,8 +33335,22 @@ class EvalState {
this.ctm = new Float32Array(IDENTITY_MATRIX);
this.font = null;
this.textRenderingMode = TextRenderingMode.FILL;
this.fillColorSpace = ColorSpace.singletons.gray;
this.strokeColorSpace = ColorSpace.singletons.gray;
this._fillColorSpace = ColorSpace.singletons.gray;
this._strokeColorSpace = ColorSpace.singletons.gray;
this.patternFillColorSpace = null;
this.patternStrokeColorSpace = null;
}
get fillColorSpace() {
return this._fillColorSpace;
}
set fillColorSpace(colorSpace) {
this._fillColorSpace = this.patternFillColorSpace = colorSpace;
}
get strokeColorSpace() {
return this._strokeColorSpace;
}
set strokeColorSpace(colorSpace) {
this._strokeColorSpace = this.patternStrokeColorSpace = colorSpace;
}
clone() {
return Object.create(this);
Expand Down Expand Up @@ -36633,6 +36661,7 @@ async function incrementalUpdate({




const MAX_DEPTH = 40;
const StructElementType = {
PAGE_CONTENT: 1,
Expand Down Expand Up @@ -36917,19 +36946,19 @@ class StructTreeRoot {
const tagDict = new Dict(xref);
tagDict.set("S", Name.get(type));
if (title) {
tagDict.set("T", title);
tagDict.set("T", stringToAsciiOrUTF16BE(title));
}
if (lang) {
tagDict.set("Lang", lang);
}
if (alt) {
tagDict.set("Alt", alt);
tagDict.set("Alt", stringToAsciiOrUTF16BE(alt));
}
if (expanded) {
tagDict.set("E", expanded);
tagDict.set("E", stringToAsciiOrUTF16BE(expanded));
}
if (actualText) {
tagDict.set("ActualText", actualText);
tagDict.set("ActualText", stringToAsciiOrUTF16BE(actualText));
}
await this.#updateParentTag({
structTreeParent,
Expand Down Expand Up @@ -50882,8 +50911,7 @@ class WidgetAnnotation extends Annotation {
path: this.data.fieldName,
value
};
const encoder = val => isAscii(val) ? val : stringToUTF16String(val, true);
dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
dict.set("V", Array.isArray(value) ? value.map(stringToAsciiOrUTF16BE) : stringToAsciiOrUTF16BE(value));
this.amendSavedDict(annotationStorage, dict);
const maybeMK = this._getMKDict(rotation);
if (maybeMK) {
Expand Down Expand Up @@ -52062,12 +52090,12 @@ class FreeTextAnnotation extends MarkupAnnotation {
freetext.set("Rect", rect);
const da = `/Helv ${fontSize} Tf ${getPdfColor(color, true)}`;
freetext.set("DA", da);
freetext.set("Contents", isAscii(value) ? value : stringToUTF16String(value, true));
freetext.set("Contents", stringToAsciiOrUTF16BE(value));
freetext.set("F", 4);
freetext.set("Border", [0, 0, 0]);
freetext.set("Rotate", rotation);
if (user) {
freetext.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
freetext.set("T", stringToAsciiOrUTF16BE(user));
}
if (apRef || ap) {
const n = new Dict(xref);
Expand Down Expand Up @@ -52638,7 +52666,7 @@ class HighlightAnnotation extends MarkupAnnotation {
highlight.set("C", Array.from(color, c => c / 255));
highlight.set("CA", opacity);
if (user) {
highlight.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
highlight.set("T", stringToAsciiOrUTF16BE(user));
}
if (apRef || ap) {
const n = new Dict(xref);
Expand Down Expand Up @@ -52874,7 +52902,7 @@ class StampAnnotation extends MarkupAnnotation {
stamp.set("Border", [0, 0, 0]);
stamp.set("Rotate", rotation);
if (user) {
stamp.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
stamp.set("T", stringToAsciiOrUTF16BE(user));
}
if (apRef || ap) {
const n = new Dict(xref);
Expand Down Expand Up @@ -56388,7 +56416,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.5.0";
const pdfjsBuild = "e92a6a1";
const pdfjsBuild = "0ed4521";

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.

Loading

0 comments on commit e185a51

Please sign in to comment.