Bug 1876508 - Update PDF.js to new version bf9236009521621891d73dd77acc68215cb2cadb r=pdfjs-reviewers,fluent-reviewers,marco,flod

Differential Revision: https://phabricator.services.mozilla.com/D199621
This commit is contained in:
Calixte 2024-01-25 15:35:38 +00:00
parent 6b5127fad2
commit 10ca73335c
12 changed files with 1667 additions and 1012 deletions

View file

@ -18,32 +18,32 @@
// //
export const PdfJsDefaultPreferences = Object.freeze({ export const PdfJsDefaultPreferences = Object.freeze({
"annotationEditorMode": 0, annotationEditorMode: 0,
"annotationMode": 2, annotationMode: 2,
"cursorToolOnLoad": 0, cursorToolOnLoad: 0,
"defaultZoomDelay": 400, defaultZoomDelay: 400,
"defaultZoomValue": "", defaultZoomValue: "",
"disablePageLabels": false, disablePageLabels: false,
"enableHighlightEditor": false, enableHighlightEditor: false,
"enablePermissions": false, enablePermissions: false,
"enablePrintAutoRotate": true, enablePrintAutoRotate: true,
"enableScripting": true, enableScripting: true,
"externalLinkTarget": 0, externalLinkTarget: 0,
"highlightEditorColors": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
"historyUpdateUrl": false, historyUpdateUrl: false,
"ignoreDestinationZoom": false, ignoreDestinationZoom: false,
"forcePageColors": false, forcePageColors: false,
"pageColorsBackground": "Canvas", pageColorsBackground: "Canvas",
"pageColorsForeground": "CanvasText", pageColorsForeground: "CanvasText",
"pdfBugEnabled": false, pdfBugEnabled: false,
"sidebarViewOnLoad": -1, sidebarViewOnLoad: -1,
"scrollModeOnLoad": -1, scrollModeOnLoad: -1,
"spreadModeOnLoad": -1, spreadModeOnLoad: -1,
"textLayerMode": 1, textLayerMode: 1,
"viewOnLoad": 0, viewOnLoad: 0,
"disableAutoFetch": false, disableAutoFetch: false,
"disableFontFace": false, disableFontFace: false,
"disableRange": false, disableRange: false,
"disableStream": false, disableStream: false,
"enableXfa": true enableXfa: true
}); });

File diff suppressed because it is too large Load diff

View file

@ -14,128 +14,114 @@
*/ */
export class SandboxSupportBase { export class SandboxSupportBase {
constructor(win) { constructor(win) {
this.win = win; this.win = win;
this.timeoutIds = new Map(); this.timeoutIds = new Map();
this.commFun = null; this.commFun = null;
}
destroy() {
this.commFun = null;
for (const id of this.timeoutIds.values()) {
this.win.clearTimeout(id);
} }
this.timeoutIds = null; destroy() {
} this.commFun = null;
exportValueToSandbox(val) { for (const id of this.timeoutIds.values()) {
throw new Error("Not implemented"); this.win.clearTimeout(id);
} }
importValueFromSandbox(val) { this.timeoutIds = null;
throw new Error("Not implemented");
}
createErrorForSandbox(errorMessage) {
throw new Error("Not implemented");
}
callSandboxFunction(name, args) {
try {
args = this.exportValueToSandbox(args);
this.commFun(name, args);
} catch (e) {
this.win.console.error(e);
} }
} exportValueToSandbox(val) {
createSandboxExternals() { throw new Error("Not implemented");
const externals = { }
setTimeout: (callbackId, nMilliseconds) => { importValueFromSandbox(val) {
if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") { throw new Error("Not implemented");
return; }
createErrorForSandbox(errorMessage) {
throw new Error("Not implemented");
}
callSandboxFunction(name, args) {
try {
args = this.exportValueToSandbox(args);
this.commFun(name, args);
} catch (e) {
this.win.console.error(e);
} }
if (callbackId === 0) { }
this.win.clearTimeout(this.timeoutIds.get(callbackId)); createSandboxExternals() {
} const externals = {
const id = this.win.setTimeout(() => { setTimeout: (callbackId, nMilliseconds) => {
this.timeoutIds.delete(callbackId); if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") {
this.callSandboxFunction("timeoutCb", { return;
callbackId, }
interval: false if (callbackId === 0) {
}); this.win.clearTimeout(this.timeoutIds.get(callbackId));
}, nMilliseconds); }
this.timeoutIds.set(callbackId, id); const id = this.win.setTimeout(() => {
}, this.timeoutIds.delete(callbackId);
clearTimeout: callbackId => { this.callSandboxFunction("timeoutCb", {
this.win.clearTimeout(this.timeoutIds.get(callbackId)); callbackId,
this.timeoutIds.delete(callbackId); interval: false
}, });
setInterval: (callbackId, nMilliseconds) => { }, nMilliseconds);
if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") { this.timeoutIds.set(callbackId, id);
return; },
} clearTimeout: callbackId => {
const id = this.win.setInterval(() => { this.win.clearTimeout(this.timeoutIds.get(callbackId));
this.callSandboxFunction("timeoutCb", { this.timeoutIds.delete(callbackId);
callbackId, },
interval: true setInterval: (callbackId, nMilliseconds) => {
}); if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") {
}, nMilliseconds); return;
this.timeoutIds.set(callbackId, id); }
}, const id = this.win.setInterval(() => {
clearInterval: callbackId => { this.callSandboxFunction("timeoutCb", {
this.win.clearInterval(this.timeoutIds.get(callbackId)); callbackId,
this.timeoutIds.delete(callbackId); interval: true
}, });
alert: cMsg => { }, nMilliseconds);
if (typeof cMsg !== "string") { this.timeoutIds.set(callbackId, id);
return; },
} clearInterval: callbackId => {
this.win.alert(cMsg); this.win.clearInterval(this.timeoutIds.get(callbackId));
}, this.timeoutIds.delete(callbackId);
confirm: cMsg => { },
if (typeof cMsg !== "string") { alert: cMsg => {
return false; if (typeof cMsg !== "string") {
} return;
return this.win.confirm(cMsg); }
}, this.win.alert(cMsg);
prompt: (cQuestion, cDefault) => { },
if (typeof cQuestion !== "string" || typeof cDefault !== "string") { confirm: cMsg => {
return null; if (typeof cMsg !== "string") {
} return false;
return this.win.prompt(cQuestion, cDefault); }
}, return this.win.confirm(cMsg);
parseURL: cUrl => { },
const url = new this.win.URL(cUrl); prompt: (cQuestion, cDefault) => {
const props = [ if (typeof cQuestion !== "string" || typeof cDefault !== "string") {
"hash", return null;
"host", }
"hostname", return this.win.prompt(cQuestion, cDefault);
"href", },
"origin", parseURL: cUrl => {
"password", const url = new this.win.URL(cUrl);
"pathname", const props = ["hash", "host", "hostname", "href", "origin", "password", "pathname", "port", "protocol", "search", "searchParams", "username"];
"port", return Object.fromEntries(props.map(name => [name, url[name].toString()]));
"protocol", },
"search", send: data => {
"searchParams", if (!data) {
"username" return;
]; }
return Object.fromEntries(props.map(name => [ const event = new this.win.CustomEvent("updatefromsandbox", {
name, detail: this.importValueFromSandbox(data)
url[name].toString() });
])); this.win.dispatchEvent(event);
}, }
send: data => { };
if (!data) { Object.setPrototypeOf(externals, null);
return; return (name, args) => {
} try {
const event = new this.win.CustomEvent("updatefromsandbox", { detail: this.importValueFromSandbox(data) }); const result = externals[name](...args);
this.win.dispatchEvent(event); return this.exportValueToSandbox(result);
} } catch (error) {
}; throw this.createErrorForSandbox(error?.toString() ?? "");
Object.setPrototypeOf(externals, null); }
return (name, args) => { };
try { }
const result = externals[name](...args);
return this.exportValueToSandbox(result);
} catch (error) {
throw this.createErrorForSandbox(error?.toString() ?? "");
}
};
}
} }

View file

@ -1074,9 +1074,6 @@ class AForm {
} }
AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) { AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) {
const event = globalThis.event; const event = globalThis.event;
if (!event.value) {
return;
}
let value = this.AFMakeNumber(event.value); let value = this.AFMakeNumber(event.value);
if (value === null) { if (value === null) {
event.value = ""; event.value = "";
@ -1686,23 +1683,27 @@ class EventDispatcher {
} }
event.value = null; event.value = null;
const target = this._objects[targetId]; const target = this._objects[targetId];
let savedValue = target.obj.value; let savedValue = target.obj._getValue();
this.runActions(source, target, event, "Calculate"); this.runActions(source, target, event, "Calculate");
if (!event.rc) { if (!event.rc) {
continue; continue;
} }
if (event.value !== null) { if (event.value !== null) {
target.obj.value = event.value; target.obj.value = event.value;
} else {
event.value = target.obj._getValue();
} }
event.value = target.obj.value;
this.runActions(target, target, event, "Validate"); this.runActions(target, target, event, "Validate");
if (!event.rc) { if (!event.rc) {
if (target.obj.value !== savedValue) { if (target.obj._getValue() !== savedValue) {
target.wrapped.value = savedValue; target.wrapped.value = savedValue;
} }
continue; continue;
} }
savedValue = event.value = target.obj.value; if (event.value === null) {
event.value = target.obj._getValue();
}
savedValue = target.obj._getValue();
let formattedValue = null; let formattedValue = null;
if (this.runActions(target, target, event, "Format")) { if (this.runActions(target, target, event, "Format")) {
formattedValue = event.value?.toString?.(); formattedValue = event.value?.toString?.();
@ -3486,66 +3487,26 @@ class Util extends PDFObject {
return this.printd("m/d/yy h:MM:ss tt", oDate); return this.printd("m/d/yy h:MM:ss tt", oDate);
} }
const handlers = { const handlers = {
mmmm: data => { mmmm: data => this._months[data.month],
return this._months[data.month]; mmm: data => this._months[data.month].substring(0, 3),
}, mm: data => (data.month + 1).toString().padStart(2, "0"),
mmm: data => { m: data => (data.month + 1).toString(),
return this._months[data.month].substring(0, 3); dddd: data => this._days[data.dayOfWeek],
}, ddd: data => this._days[data.dayOfWeek].substring(0, 3),
mm: data => { dd: data => data.day.toString().padStart(2, "0"),
return (data.month + 1).toString().padStart(2, "0"); d: data => data.day.toString(),
}, yyyy: data => data.year.toString(),
m: data => { yy: data => (data.year % 100).toString().padStart(2, "0"),
return (data.month + 1).toString(); HH: data => data.hours.toString().padStart(2, "0"),
}, H: data => data.hours.toString(),
dddd: data => { hh: data => (1 + (data.hours + 11) % 12).toString().padStart(2, "0"),
return this._days[data.dayOfWeek]; h: data => (1 + (data.hours + 11) % 12).toString(),
}, MM: data => data.minutes.toString().padStart(2, "0"),
ddd: data => { M: data => data.minutes.toString(),
return this._days[data.dayOfWeek].substring(0, 3); ss: data => data.seconds.toString().padStart(2, "0"),
}, s: data => data.seconds.toString(),
dd: data => { tt: data => data.hours < 12 ? "am" : "pm",
return data.day.toString().padStart(2, "0"); t: data => data.hours < 12 ? "a" : "p"
},
d: data => {
return data.day.toString();
},
yyyy: data => {
return data.year.toString();
},
yy: data => {
return (data.year % 100).toString().padStart(2, "0");
},
HH: data => {
return data.hours.toString().padStart(2, "0");
},
H: data => {
return data.hours.toString();
},
hh: data => {
return (1 + (data.hours + 11) % 12).toString().padStart(2, "0");
},
h: data => {
return (1 + (data.hours + 11) % 12).toString();
},
MM: data => {
return data.minutes.toString().padStart(2, "0");
},
M: data => {
return data.minutes.toString();
},
ss: data => {
return data.seconds.toString().padStart(2, "0");
},
s: data => {
return data.seconds.toString();
},
tt: data => {
return data.hours < 12 ? "am" : "pm";
},
t: data => {
return data.hours < 12 ? "a" : "p";
}
}; };
const data = { const data = {
year: oDate.getFullYear(), year: oDate.getFullYear(),
@ -3996,8 +3957,8 @@ function initSandbox(params) {
;// CONCATENATED MODULE: ./src/pdf.scripting.js ;// CONCATENATED MODULE: ./src/pdf.scripting.js
const pdfjsVersion = '4.1.30'; const pdfjsVersion = "4.1.86";
const pdfjsBuild = 'a22b5a4f0'; const pdfjsBuild = "bf9236009";
globalThis.pdfjsScripting = { globalThis.pdfjsScripting = {
initSandbox: initSandbox initSandbox: initSandbox
}; };

View file

@ -92,7 +92,8 @@ const AnnotationEditorParamsType = {
INK_THICKNESS: 22, INK_THICKNESS: 22,
INK_OPACITY: 23, INK_OPACITY: 23,
HIGHLIGHT_COLOR: 31, HIGHLIGHT_COLOR: 31,
HIGHLIGHT_DEFAULT_COLOR: 32 HIGHLIGHT_DEFAULT_COLOR: 32,
HIGHLIGHT_THICKNESS: 33
}; };
const PermissionFlag = { const PermissionFlag = {
PRINT: 0x04, PRINT: 0x04,
@ -530,43 +531,43 @@ class Util {
if (transform[0]) { if (transform[0]) {
if (transform[0] < 0) { if (transform[0] < 0) {
temp = minMax[0]; temp = minMax[0];
minMax[0] = minMax[1]; minMax[0] = minMax[2];
minMax[1] = temp; minMax[2] = temp;
} }
minMax[0] *= transform[0]; minMax[0] *= transform[0];
minMax[1] *= transform[0]; minMax[2] *= transform[0];
if (transform[3] < 0) { if (transform[3] < 0) {
temp = minMax[2]; temp = minMax[1];
minMax[2] = minMax[3]; minMax[1] = minMax[3];
minMax[3] = temp; minMax[3] = temp;
} }
minMax[2] *= transform[3]; minMax[1] *= transform[3];
minMax[3] *= transform[3]; minMax[3] *= transform[3];
} else { } else {
temp = minMax[0]; temp = minMax[0];
minMax[0] = minMax[2]; minMax[0] = minMax[1];
minMax[2] = temp; minMax[1] = temp;
temp = minMax[1]; temp = minMax[2];
minMax[1] = minMax[3]; minMax[2] = minMax[3];
minMax[3] = temp; minMax[3] = temp;
if (transform[1] < 0) { if (transform[1] < 0) {
temp = minMax[2]; temp = minMax[1];
minMax[2] = minMax[3]; minMax[1] = minMax[3];
minMax[3] = temp; minMax[3] = temp;
} }
minMax[2] *= transform[1]; minMax[1] *= transform[1];
minMax[3] *= transform[1]; minMax[3] *= transform[1];
if (transform[2] < 0) { if (transform[2] < 0) {
temp = minMax[0]; temp = minMax[0];
minMax[0] = minMax[1]; minMax[0] = minMax[2];
minMax[1] = temp; minMax[2] = temp;
} }
minMax[0] *= transform[2]; minMax[0] *= transform[2];
minMax[1] *= transform[2]; minMax[2] *= transform[2];
} }
minMax[0] += transform[4]; minMax[0] += transform[4];
minMax[1] += transform[4]; minMax[1] += transform[5];
minMax[2] += transform[5]; minMax[2] += transform[4];
minMax[3] += transform[5]; minMax[3] += transform[5];
} }
static transform(m1, m2) { static transform(m1, m2) {
@ -631,59 +632,48 @@ class Util {
} }
return [xLow, yLow, xHigh, yHigh]; return [xLow, yLow, xHigh, yHigh];
} }
static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) { static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
const tvalues = [], if (t <= 0 || t >= 1) {
bounds = [[], []]; return;
let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
for (let i = 0; i < 2; ++i) {
if (i === 0) {
b = 6 * x0 - 12 * x1 + 6 * x2;
a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
c = 3 * x1 - 3 * x0;
} else {
b = 6 * y0 - 12 * y1 + 6 * y2;
a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
c = 3 * y1 - 3 * y0;
}
if (Math.abs(a) < 1e-12) {
if (Math.abs(b) < 1e-12) {
continue;
}
t = -c / b;
if (0 < t && t < 1) {
tvalues.push(t);
}
continue;
}
b2ac = b * b - 4 * c * a;
sqrtb2ac = Math.sqrt(b2ac);
if (b2ac < 0) {
continue;
}
t1 = (-b + sqrtb2ac) / (2 * a);
if (0 < t1 && t1 < 1) {
tvalues.push(t1);
}
t2 = (-b - sqrtb2ac) / (2 * a);
if (0 < t2 && t2 < 1) {
tvalues.push(t2);
}
} }
let j = tvalues.length, const mt = 1 - t;
mt; const tt = t * t;
const jlen = j; const ttt = tt * t;
while (j--) { const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
t = tvalues[j]; const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
mt = 1 - t; minMax[0] = Math.min(minMax[0], x);
bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3; minMax[1] = Math.min(minMax[1], y);
bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3; minMax[2] = Math.max(minMax[2], x);
minMax[3] = Math.max(minMax[3], y);
}
static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
if (Math.abs(a) < 1e-12) {
if (Math.abs(b) >= 1e-12) {
this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
}
return;
} }
bounds[0][jlen] = x0; const delta = b ** 2 - 4 * c * a;
bounds[1][jlen] = y0; if (delta < 0) {
bounds[0][jlen + 1] = x3; return;
bounds[1][jlen + 1] = y3; }
bounds[0].length = bounds[1].length = jlen + 2; const sqrtDelta = Math.sqrt(delta);
return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])]; const a2 = 2 * a;
this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
}
static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
if (minMax) {
minMax[0] = Math.min(minMax[0], x0, x3);
minMax[1] = Math.min(minMax[1], y0, y3);
minMax[2] = Math.max(minMax[2], x0, x3);
minMax[3] = Math.max(minMax[3], y0, y3);
} else {
minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
}
this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
return minMax;
} }
} }
const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac]; const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
@ -737,9 +727,6 @@ function stringToUTF8String(str) {
function utf8StringToString(str) { function utf8StringToString(str) {
return unescape(encodeURIComponent(str)); return unescape(encodeURIComponent(str));
} }
function isArrayBuffer(v) {
return typeof v === "object" && v?.byteLength !== undefined;
}
function isArrayEqual(arr1, arr2) { function isArrayEqual(arr1, arr2) {
if (arr1.length !== arr2.length) { if (arr1.length !== arr2.length) {
return false; return false;
@ -780,9 +767,7 @@ function normalizeUnicode(str) {
NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu; NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;
NormalizationMap = new Map([["ſt", "ſt"]]); NormalizationMap = new Map([["ſt", "ſt"]]);
} }
return str.replaceAll(NormalizeRegex, (_, p1, p2) => { return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
});
} }
function getUuid() { function getUuid() {
return crypto.randomUUID(); return crypto.randomUUID();
@ -1366,6 +1351,15 @@ const XMLEntities = {
0x22: "&quot;", 0x22: "&quot;",
0x27: "&apos;" 0x27: "&apos;"
}; };
function* codePointIter(str) {
for (let i = 0, ii = str.length; i < ii; i++) {
const char = str.codePointAt(i);
if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
i++;
}
yield char;
}
}
function encodeToXmlString(str) { function encodeToXmlString(str) {
const buffer = []; const buffer = [];
let start = 0; let start = 0;
@ -11290,9 +11284,7 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
} = await fetchBuiltInCMap(name); } = await fetchBuiltInCMap(name);
const cMap = new CMap(true); const cMap = new CMap(true);
if (compressionType === CMapCompressionType.BINARY) { if (compressionType === CMapCompressionType.BINARY) {
return new BinaryCMapReader().process(cMapData, cMap, useCMap => { return new BinaryCMapReader().process(cMapData, cMap, useCMap => extendCMap(cMap, fetchBuiltInCMap, useCMap));
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
});
} }
if (compressionType === CMapCompressionType.NONE) { if (compressionType === CMapCompressionType.NONE) {
const lexer = new Lexer(new Stream(cMapData)); const lexer = new Lexer(new Stream(cMapData));
@ -25279,15 +25271,11 @@ class Font {
endOffset: 0 endOffset: 0
}); });
} }
locaEntries.sort((a, b) => { locaEntries.sort((a, b) => a.offset - b.offset);
return a.offset - b.offset;
});
for (i = 0; i < numGlyphs; i++) { for (i = 0; i < numGlyphs; i++) {
locaEntries[i].endOffset = locaEntries[i + 1].offset; locaEntries[i].endOffset = locaEntries[i + 1].offset;
} }
locaEntries.sort((a, b) => { locaEntries.sort((a, b) => a.index - b.index);
return a.index - b.index;
});
for (i = 0; i < numGlyphs; i++) { for (i = 0; i < numGlyphs; i++) {
const { const {
offset, offset,
@ -29590,7 +29578,6 @@ class ImageResizer {
ImageResizer._goodSquareLength = MIN_IMAGE_DIM; ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
;// CONCATENATED MODULE: ./src/shared/murmurhash3.js ;// CONCATENATED MODULE: ./src/shared/murmurhash3.js
const SEED = 0xc3d2e1f0; const SEED = 0xc3d2e1f0;
const MASK_HIGH = 0xffff0000; const MASK_HIGH = 0xffff0000;
const MASK_LOW = 0xffff; const MASK_LOW = 0xffff;
@ -29613,11 +29600,11 @@ class MurmurHash3_64 {
data[length++] = code & 0xff; data[length++] = code & 0xff;
} }
} }
} else if (isArrayBuffer(input)) { } else if (ArrayBuffer.isView(input)) {
data = input.slice(); data = input.slice();
length = data.byteLength; length = data.byteLength;
} else { } else {
throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array."); throw new Error("Invalid data format, must be a string or TypedArray.");
} }
const blockCounts = length >> 2; const blockCounts = length >> 2;
const tailLength = length - blockCounts * 4; const tailLength = length - blockCounts * 4;
@ -31312,21 +31299,20 @@ class PartialEvaluator {
} }
const args = group ? [matrix, null] : [matrix, bbox]; const args = group ? [matrix, null] : [matrix, bbox];
operatorList.addOp(OPS.paintFormXObjectBegin, args); operatorList.addOp(OPS.paintFormXObjectBegin, args);
return this.getOperatorList({ await this.getOperatorList({
stream: xobj, stream: xobj,
task, task,
resources: dict.get("Resources") || resources, resources: dict.get("Resources") || resources,
operatorList, operatorList,
initialState initialState
}).then(function () {
operatorList.addOp(OPS.paintFormXObjectEnd, []);
if (group) {
operatorList.addOp(OPS.endGroup, [groupOptions]);
}
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
}); });
operatorList.addOp(OPS.paintFormXObjectEnd, []);
if (group) {
operatorList.addOp(OPS.endGroup, [groupOptions]);
}
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
} }
_sendImgData(objId, imgData, cacheGlobally = false) { _sendImgData(objId, imgData, cacheGlobally = false) {
const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null; const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
@ -31624,28 +31610,25 @@ class PartialEvaluator {
throw reason; throw reason;
}); });
} }
handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) { async handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) {
const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null; const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
return this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo).then(translated => { let translated = await this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo);
if (!translated.font.isType3Font) { if (translated.font.isType3Font) {
return translated; try {
} await translated.loadType3Data(this, resources, task);
return translated.loadType3Data(this, resources, task).then(function () {
operatorList.addDependencies(translated.type3Dependencies); operatorList.addDependencies(translated.type3Dependencies);
return translated; } catch (reason) {
}).catch(reason => { translated = new TranslatedFont({
return new TranslatedFont({
loadedName: "g_font_error", loadedName: "g_font_error",
font: new ErrorFont(`Type3 font load error: ${reason}`), font: new ErrorFont(`Type3 font load error: ${reason}`),
dict: translated.font, dict: translated.font,
evaluatorOptions: this.options evaluatorOptions: this.options
}); });
}); }
}).then(translated => { }
state.font = translated.font; state.font = translated.font;
translated.send(this.handler); translated.send(this.handler);
return translated.loadedName; return translated.loadedName;
});
} }
handleText(chars, state) { handleText(chars, state) {
const font = state.font; const font = state.font;
@ -31701,12 +31684,10 @@ class PartialEvaluator {
break; break;
case "Font": case "Font":
isSimpleGState = false; isSimpleGState = false;
promise = promise.then(() => { promise = promise.then(() => this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
return this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) { operatorList.addDependency(loadedName);
operatorList.addDependency(loadedName); gStateObj.push([key, [loadedName, value[1]]]);
gStateObj.push([key, [loadedName, value[1]]]); }));
});
});
break; break;
case "BM": case "BM":
gStateObj.push([key, normalizeBlendMode(value)]); gStateObj.push([key, normalizeBlendMode(value)]);
@ -31718,9 +31699,7 @@ class PartialEvaluator {
} }
if (value instanceof Dict) { if (value instanceof Dict) {
isSimpleGState = false; isSimpleGState = false;
promise = promise.then(() => { promise = promise.then(() => this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache));
return this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache);
});
gStateObj.push([key, true]); gStateObj.push([key, true]);
} else { } else {
warn("Unsupported SMask type"); warn("Unsupported SMask type");
@ -31750,14 +31729,13 @@ class PartialEvaluator {
break; break;
} }
} }
return promise.then(function () { await promise;
if (gStateObj.length > 0) { if (gStateObj.length > 0) {
operatorList.addOp(OPS.setGState, [gStateObj]); operatorList.addOp(OPS.setGState, [gStateObj]);
} }
if (isSimpleGState) { if (isSimpleGState) {
localGStateCache.set(cacheKey, gStateRef, gStateObj); localGStateCache.set(cacheKey, gStateRef, gStateObj);
} }
});
} }
loadFont(fontName, font, resources, fallbackFontDict = null, cssFontInfo = null) { loadFont(fontName, font, resources, fallbackFontDict = null, cssFontInfo = null) {
const errorFont = async () => { const errorFont = async () => {
@ -31875,14 +31853,14 @@ class PartialEvaluator {
case OPS.rectangle: case OPS.rectangle:
const x = args[0] + args[2]; const x = args[0] + args[2];
const y = args[1] + args[3]; const y = args[1] + args[3];
minMax = [Math.min(args[0], x), Math.max(args[0], x), Math.min(args[1], y), Math.max(args[1], y)]; minMax = [Math.min(args[0], x), Math.min(args[1], y), Math.max(args[0], x), Math.max(args[1], y)];
break; break;
case OPS.moveTo: case OPS.moveTo:
case OPS.lineTo: case OPS.lineTo:
minMax = [args[0], args[0], args[1], args[1]]; minMax = [args[0], args[1], args[0], args[1]];
break; break;
default: default:
minMax = [Infinity, -Infinity, Infinity, -Infinity]; minMax = [Infinity, Infinity, -Infinity, -Infinity];
break; break;
} }
operatorList.addOp(OPS.constructPath, [[fn], args, minMax]); operatorList.addOp(OPS.constructPath, [[fn], args, minMax]);
@ -31899,15 +31877,15 @@ class PartialEvaluator {
const x = args[0] + args[2]; const x = args[0] + args[2];
const y = args[1] + args[3]; const y = args[1] + args[3];
minMax[0] = Math.min(minMax[0], args[0], x); minMax[0] = Math.min(minMax[0], args[0], x);
minMax[1] = Math.max(minMax[1], args[0], x); minMax[1] = Math.min(minMax[1], args[1], y);
minMax[2] = Math.min(minMax[2], args[1], y); minMax[2] = Math.max(minMax[2], args[0], x);
minMax[3] = Math.max(minMax[3], args[1], y); minMax[3] = Math.max(minMax[3], args[1], y);
break; break;
case OPS.moveTo: case OPS.moveTo:
case OPS.lineTo: case OPS.lineTo:
minMax[0] = Math.min(minMax[0], args[0]); minMax[0] = Math.min(minMax[0], args[0]);
minMax[1] = Math.max(minMax[1], args[0]); minMax[1] = Math.min(minMax[1], args[1]);
minMax[2] = Math.min(minMax[2], args[1]); minMax[2] = Math.max(minMax[2], args[0]);
minMax[3] = Math.max(minMax[3], args[1]); minMax[3] = Math.max(minMax[3], args[1]);
break; break;
} }
@ -32701,19 +32679,16 @@ class PartialEvaluator {
hasEOL: textChunk.hasEOL hasEOL: textChunk.hasEOL
}; };
} }
function handleSetFont(fontName, fontRef) { async function handleSetFont(fontName, fontRef) {
return self.loadFont(fontName, fontRef, resources).then(function (translated) { const translated = await self.loadFont(fontName, fontRef, resources);
if (!translated.font.isType3Font) { if (translated.font.isType3Font) {
return translated; try {
} await translated.loadType3Data(self, resources, task);
return translated.loadType3Data(self, resources, task).catch(function () {}).then(function () { } catch {}
return translated; }
}); textState.loadedName = translated.loadedName;
}).then(function (translated) { textState.font = translated.font;
textState.loadedName = translated.loadedName; textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
textState.font = translated.font;
textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
});
} }
function applyInverseRotation(x, y, matrix) { function applyInverseRotation(x, y, matrix) {
const scale = Math.hypot(matrix[0], matrix[1]); const scale = Math.hypot(matrix[0], matrix[1]);
@ -33334,10 +33309,10 @@ class PartialEvaluator {
throw reason; throw reason;
}); });
} }
extractDataStructures(dict, baseDict, properties) { async extractDataStructures(dict, properties) {
const xref = this.xref; const xref = this.xref;
let cidToGidBytes; let cidToGidBytes;
const toUnicodePromise = this.readToUnicode(properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode")); const toUnicodePromise = this.readToUnicode(properties.toUnicode);
if (properties.composite) { if (properties.composite) {
const cidSystemInfo = dict.get("CIDSystemInfo"); const cidSystemInfo = dict.get("CIDSystemInfo");
if (cidSystemInfo instanceof Dict) { if (cidSystemInfo instanceof Dict) {
@ -33426,16 +33401,13 @@ class PartialEvaluator {
properties.baseEncodingName = baseEncodingName; properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0; properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.dict = dict; properties.dict = dict;
return toUnicodePromise.then(readToUnicode => { properties.toUnicode = await toUnicodePromise;
properties.toUnicode = readToUnicode; const builtToUnicode = await this.buildToUnicode(properties);
return this.buildToUnicode(properties); properties.toUnicode = builtToUnicode;
}).then(builtToUnicode => { if (cidToGidBytes) {
properties.toUnicode = builtToUnicode; properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
if (cidToGidBytes) { }
properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode); return properties;
}
return properties;
});
} }
_simpleFontToUnicode(properties, forceGlyphs = false) { _simpleFontToUnicode(properties, forceGlyphs = false) {
assert(!properties.composite, "Must be a simple font."); assert(!properties.composite, "Must be a simple font.");
@ -33557,27 +33529,28 @@ class PartialEvaluator {
} }
return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar); return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
} }
readToUnicode(cmapObj) { async readToUnicode(cmapObj) {
if (!cmapObj) { if (!cmapObj) {
return Promise.resolve(null); return null;
} }
if (cmapObj instanceof Name) { if (cmapObj instanceof Name) {
return CMapFactory.create({ const cmap = await CMapFactory.create({
encoding: cmapObj, encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound, fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null useCMap: null
}).then(function (cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff);
}
return new ToUnicodeMap(cmap.getMap());
}); });
} else if (cmapObj instanceof BaseStream) { if (cmap instanceof IdentityCMap) {
return CMapFactory.create({ return new IdentityToUnicodeMap(0, 0xffff);
encoding: cmapObj, }
fetchBuiltInCMap: this._fetchBuiltInCMapBound, return new ToUnicodeMap(cmap.getMap());
useCMap: null }
}).then(function (cmap) { if (cmapObj instanceof BaseStream) {
try {
const cmap = await CMapFactory.create({
encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null
});
if (cmap instanceof IdentityCMap) { if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff); return new IdentityToUnicodeMap(0, 0xffff);
} }
@ -33601,7 +33574,7 @@ class PartialEvaluator {
map[charCode] = String.fromCodePoint(...str); map[charCode] = String.fromCodePoint(...str);
}); });
return new ToUnicodeMap(map); return new ToUnicodeMap(map);
}, reason => { } catch (reason) {
if (reason instanceof AbortException) { if (reason instanceof AbortException) {
return null; return null;
} }
@ -33610,9 +33583,9 @@ class PartialEvaluator {
return null; return null;
} }
throw reason; throw reason;
}); }
} }
return Promise.resolve(null); return null;
} }
readCidToGidMap(glyphsData, toUnicode) { readCidToGidMap(glyphsData, toUnicode) {
const result = []; const result = [];
@ -33767,7 +33740,7 @@ class PartialEvaluator {
throw new FormatError("invalid font Subtype"); throw new FormatError("invalid font Subtype");
} }
let composite = false; let composite = false;
let hash, toUnicode; let hash;
if (type.name === "Type0") { if (type.name === "Type0") {
const df = dict.get("DescendantFonts"); const df = dict.get("DescendantFonts");
if (!df) { if (!df) {
@ -33786,6 +33759,7 @@ class PartialEvaluator {
const firstChar = dict.get("FirstChar") || 0, const firstChar = dict.get("FirstChar") || 0,
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff); lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
const descriptor = dict.get("FontDescriptor"); const descriptor = dict.get("FontDescriptor");
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
if (descriptor) { if (descriptor) {
hash = new MurmurHash3_64(); hash = new MurmurHash3_64();
const encoding = baseDict.getRaw("Encoding"); const encoding = baseDict.getRaw("Encoding");
@ -33815,7 +33789,6 @@ class PartialEvaluator {
} }
} }
hash.update(`${firstChar}-${lastChar}`); hash.update(`${firstChar}-${lastChar}`);
toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
if (toUnicode instanceof BaseStream) { if (toUnicode instanceof BaseStream) {
const stream = toUnicode.str || toUnicode; const stream = toUnicode.str || toUnicode;
const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start); const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
@ -33887,7 +33860,6 @@ class PartialEvaluator {
cssFontInfo cssFontInfo
}) { }) {
const isType3Font = type === "Type3"; const isType3Font = type === "Type3";
let properties;
if (!descriptor) { if (!descriptor) {
if (isType3Font) { if (isType3Font) {
descriptor = new Dict(null); descriptor = new Dict(null);
@ -33902,7 +33874,7 @@ class PartialEvaluator {
const metrics = this.getBaseFontMetrics(baseFontName); const metrics = this.getBaseFontMetrics(baseFontName);
const fontNameWoStyle = baseFontName.split("-")[0]; const fontNameWoStyle = baseFontName.split("-")[0];
const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic); const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
properties = { const properties = {
type, type,
name: baseFontName, name: baseFontName,
loadedName: baseDict.loadedName, loadedName: baseDict.loadedName,
@ -33929,19 +33901,18 @@ class PartialEvaluator {
if (!properties.isInternalFont && this.options.useSystemFonts) { if (!properties.isInternalFont && this.options.useSystemFonts) {
properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName); properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName);
} }
return this.extractDataStructures(dict, dict, properties).then(newProperties => { const newProperties = await this.extractDataStructures(dict, properties);
if (widths) { if (widths) {
const glyphWidths = []; const glyphWidths = [];
let j = firstChar; let j = firstChar;
for (const width of widths) { for (const width of widths) {
glyphWidths[j++] = this.xref.fetchIfRef(width); glyphWidths[j++] = this.xref.fetchIfRef(width);
}
newProperties.widths = glyphWidths;
} else {
newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
} }
return new Font(baseFontName, file, newProperties); newProperties.widths = glyphWidths;
}); } else {
newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
}
return new Font(baseFontName, file, newProperties);
} }
} }
let fontName = descriptor.get("FontName"); let fontName = descriptor.get("FontName");
@ -34008,7 +33979,7 @@ class PartialEvaluator {
systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName); systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName);
} }
} }
properties = { const properties = {
type, type,
name: fontName.name, name: fontName.name,
subtype, subtype,
@ -34049,10 +34020,9 @@ class PartialEvaluator {
properties.cMap = cMap; properties.cMap = cMap;
properties.vertical = properties.cMap.vertical; properties.vertical = properties.cMap.vertical;
} }
return this.extractDataStructures(dict, baseDict, properties).then(newProperties => { const newProperties = await this.extractDataStructures(dict, properties);
this.extractWidths(dict, descriptor, newProperties); this.extractWidths(dict, descriptor, newProperties);
return new Font(fontName.name, fontFile, newProperties); return new Font(fontName.name, fontFile, newProperties);
});
} }
static buildFontPaths(font, glyphs, handler, evaluatorOptions) { static buildFontPaths(font, glyphs, handler, evaluatorOptions) {
function buildPath(fontChar) { function buildPath(fontChar) {
@ -34332,7 +34302,7 @@ class EvalState {
} }
class EvaluatorPreprocessor { class EvaluatorPreprocessor {
static get opMap() { static get opMap() {
return shadow(this, "opMap", { return shadow(this, "opMap", Object.assign(Object.create(null), {
w: { w: {
id: OPS.setLineWidth, id: OPS.setLineWidth,
numArgs: 1, numArgs: 1,
@ -34708,7 +34678,7 @@ class EvaluatorPreprocessor {
nu: null, nu: null,
nul: null, nul: null,
null: null null: null
}); }));
} }
static MAX_INVALID_PATH_OPS = 10; static MAX_INVALID_PATH_OPS = 10;
constructor(stream, xref, stateManager = new StateManager()) { constructor(stream, xref, stateManager = new StateManager()) {
@ -35008,31 +34978,6 @@ class FakeUnicodeFont {
} }
this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`); this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`);
} }
get toUnicodeRef() {
if (!FakeUnicodeFont._toUnicodeRef) {
const toUnicode = `/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (Adobe)
/Ordering (UCS) /Supplement 0 >> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
1 beginbfrange
<0000> <FFFF> <0000>
endbfrange
endcmap CMapName currentdict /CMap defineresource pop end end`;
const toUnicodeStream = FakeUnicodeFont.toUnicodeStream = new StringStream(toUnicode);
const toUnicodeDict = new Dict(this.xref);
toUnicodeStream.dict = toUnicodeDict;
toUnicodeDict.set("Length", toUnicode.length);
FakeUnicodeFont._toUnicodeRef = this.xref.getNewPersistentRef(toUnicodeStream);
}
return FakeUnicodeFont._toUnicodeRef;
}
get fontDescriptorRef() { get fontDescriptorRef() {
if (!FakeUnicodeFont._fontDescriptorRef) { if (!FakeUnicodeFont._fontDescriptorRef) {
const fontDescriptor = new Dict(this.xref); const fontDescriptor = new Dict(this.xref);
@ -35093,7 +35038,7 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
baseFont.set("Subtype", Name.get("Type0")); baseFont.set("Subtype", Name.get("Type0"));
baseFont.set("Encoding", Name.get("Identity-H")); baseFont.set("Encoding", Name.get("Identity-H"));
baseFont.set("DescendantFonts", [this.descendantFontRef]); baseFont.set("DescendantFonts", [this.descendantFontRef]);
baseFont.set("ToUnicode", this.toUnicodeRef); baseFont.set("ToUnicode", Name.get("Identity-H"));
return this.xref.getNewPersistentRef(baseFont); return this.xref.getNewPersistentRef(baseFont);
} }
get resources() { get resources() {
@ -35148,8 +35093,8 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
lines.push(line); lines.push(line);
const lineWidth = ctx.measureText(line).width; const lineWidth = ctx.measureText(line).width;
maxWidth = Math.max(maxWidth, lineWidth); maxWidth = Math.max(maxWidth, lineWidth);
for (const char of line.split("")) { for (const code of codePointIter(line)) {
const code = char.charCodeAt(0); const char = String.fromCodePoint(code);
let width = this.widths.get(code); let width = this.widths.get(code);
if (width === undefined) { if (width === undefined) {
const metrics = ctx.measureText(char); const metrics = ctx.measureText(char);
@ -37255,7 +37200,7 @@ async function writeObject(ref, obj, buffer, {
await writeDict(obj, buffer, transform); await writeDict(obj, buffer, transform);
} else if (obj instanceof BaseStream) { } else if (obj instanceof BaseStream) {
await writeStream(obj, buffer, transform); await writeStream(obj, buffer, transform);
} else if (Array.isArray(obj)) { } else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
await writeArray(obj, buffer, transform); await writeArray(obj, buffer, transform);
} }
buffer.push("\nendobj\n"); buffer.push("\nendobj\n");
@ -37330,7 +37275,7 @@ async function writeValue(value, buffer, transform) {
buffer.push(`/${escapePDFName(value.name)}`); buffer.push(`/${escapePDFName(value.name)}`);
} else if (value instanceof Ref) { } else if (value instanceof Ref) {
buffer.push(`${value.num} ${value.gen} R`); buffer.push(`${value.num} ${value.gen} R`);
} else if (Array.isArray(value)) { } else if (Array.isArray(value) || ArrayBuffer.isView(value)) {
await writeArray(value, buffer, transform); await writeArray(value, buffer, transform);
} else if (typeof value === "string") { } else if (typeof value === "string") {
if (transform) { if (transform) {
@ -37524,9 +37469,7 @@ async function incrementalUpdate({
ref: refForXrefTable, ref: refForXrefTable,
data: "" data: ""
}); });
newRefs = newRefs.sort((a, b) => { newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num);
return a.ref.num - b.ref.num;
});
const xrefTableData = [[0, 1, 0xffff]]; const xrefTableData = [[0, 1, 0xffff]];
const indexes = [0, 1]; const indexes = [0, 1];
let maxOffset = 0; let maxOffset = 0;
@ -39036,9 +38979,7 @@ class Catalog {
break; break;
case "PrintPageRange": case "PrintPageRange":
if (Array.isArray(value) && value.length % 2 === 0) { if (Array.isArray(value) && value.length % 2 === 0) {
const isValid = value.every((page, i, arr) => { const isValid = value.every((page, i, arr) => Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages);
return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages;
});
if (isValid) { if (isValid) {
prefValue = value; prefValue = value;
} }
@ -40010,12 +39951,10 @@ function getRelevant(data) {
if (!data) { if (!data) {
return []; return [];
} }
return data.trim().split(/\s+/).map(e => { return data.trim().split(/\s+/).map(e => ({
return { excluded: e[0] === "-",
excluded: e[0] === "-", viewname: e.substring(1)
viewname: e.substring(1) }));
};
});
} }
function getColor(data, def = [0, 0, 0]) { function getColor(data, def = [0, 0, 0]) {
let [r, g, b] = def; let [r, g, b] = def;
@ -50653,7 +50592,11 @@ class AnnotationFactory {
})); }));
break; break;
case AnnotationEditorType.HIGHLIGHT: case AnnotationEditorType.HIGHLIGHT:
promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies)); if (annotation.quadPoints) {
promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
} else {
promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
}
break; break;
case AnnotationEditorType.INK: case AnnotationEditorType.INK:
promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies)); promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
@ -50720,9 +50663,15 @@ class AnnotationFactory {
})); }));
break; break;
case AnnotationEditorType.HIGHLIGHT: case AnnotationEditorType.HIGHLIGHT:
promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { if (annotation.quadPoints) {
evaluatorOptions: options promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
})); evaluatorOptions: options
}));
} else {
promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
evaluatorOptions: options
}));
}
break; break;
case AnnotationEditorType.INK: case AnnotationEditorType.INK:
promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
@ -51740,9 +51689,7 @@ class WidgetAnnotation extends Annotation {
path: this.data.fieldName, path: this.data.fieldName,
value value
}; };
const encoder = val => { const encoder = val => isAscii(val) ? val : stringToUTF16String(val, true);
return 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(encoder) : encoder(value));
this.amendSavedDict(annotationStorage, dict); this.amendSavedDict(annotationStorage, dict);
const maybeMK = this._getMKDict(rotation); const maybeMK = this._getMKDict(rotation);
@ -52880,7 +52827,7 @@ class FreeTextAnnotation extends MarkupAnnotation {
const strokeAlpha = params.dict.get("CA"); const strokeAlpha = params.dict.get("CA");
const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif"); const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha); this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream); this._streams.push(this.appearance);
} else { } else {
warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly."); warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
} }
@ -53296,6 +53243,7 @@ class InkAnnotation extends MarkupAnnotation {
color, color,
opacity, opacity,
paths, paths,
outlines,
rect, rect,
rotation, rotation,
thickness thickness
@ -53305,9 +53253,12 @@ class InkAnnotation extends MarkupAnnotation {
ink.set("Subtype", Name.get("Ink")); ink.set("Subtype", Name.get("Ink"));
ink.set("CreationDate", `D:${getModificationDate()}`); ink.set("CreationDate", `D:${getModificationDate()}`);
ink.set("Rect", rect); ink.set("Rect", rect);
ink.set("InkList", paths.map(p => p.points)); ink.set("InkList", outlines?.points || paths.map(p => p.points));
ink.set("F", 4); ink.set("F", 4);
ink.set("Rotate", rotation); ink.set("Rotate", rotation);
if (outlines) {
ink.set("IT", Name.get("InkHighlight"));
}
const bs = new Dict(xref); const bs = new Dict(xref);
ink.set("BS", bs); ink.set("BS", bs);
bs.set("W", thickness); bs.set("W", thickness);
@ -53323,6 +53274,9 @@ class InkAnnotation extends MarkupAnnotation {
return ink; return ink;
} }
static async createNewAppearanceStream(annotation, xref, params) { static async createNewAppearanceStream(annotation, xref, params) {
if (annotation.outlines) {
return this.createNewAppearanceStreamForHighlight(annotation, xref, params);
}
const { const {
color, color,
rect, rect,
@ -53372,6 +53326,48 @@ class InkAnnotation extends MarkupAnnotation {
ap.dict = appearanceStreamDict; ap.dict = appearanceStreamDict;
return ap; return ap;
} }
static async createNewAppearanceStreamForHighlight(annotation, xref, params) {
const {
color,
rect,
outlines: {
outline
},
opacity
} = annotation;
const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"];
appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} m`);
for (let i = 6, ii = outline.length; i < ii; i += 6) {
if (isNaN(outline[i]) || outline[i] === null) {
appearanceBuffer.push(`${numberToString(outline[i + 4])} ${numberToString(outline[i + 5])} l`);
} else {
const curve = outline.slice(i, i + 6).map(numberToString).join(" ");
appearanceBuffer.push(`${curve} c`);
}
}
appearanceBuffer.push("h f");
const appearance = appearanceBuffer.join("\n");
const appearanceStreamDict = new Dict(xref);
appearanceStreamDict.set("FormType", 1);
appearanceStreamDict.set("Subtype", Name.get("Form"));
appearanceStreamDict.set("Type", Name.get("XObject"));
appearanceStreamDict.set("BBox", rect);
appearanceStreamDict.set("Length", appearance.length);
const resources = new Dict(xref);
const extGState = new Dict(xref);
resources.set("ExtGState", extGState);
appearanceStreamDict.set("Resources", resources);
const r0 = new Dict(xref);
extGState.set("R0", r0);
r0.set("BM", Name.get("Multiply"));
if (opacity !== 1) {
r0.set("ca", opacity);
r0.set("Type", Name.get("ExtGState"));
}
const ap = new StringStream(appearance);
ap.dict = appearanceStreamDict;
return ap;
}
} }
class HighlightAnnotation extends MarkupAnnotation { class HighlightAnnotation extends MarkupAnnotation {
constructor(params) { constructor(params) {
@ -53606,9 +53602,7 @@ class StampAnnotation extends MarkupAnnotation {
const jpegBufferPromise = canvas.convertToBlob({ const jpegBufferPromise = canvas.convertToBlob({
type: "image/jpeg", type: "image/jpeg",
quality: 1 quality: 1
}).then(blob => { }).then(blob => blob.arrayBuffer());
return blob.arrayBuffer();
});
const xobjectName = Name.get("XObject"); const xobjectName = Name.get("XObject");
const imageName = Name.get("Image"); const imageName = Name.get("Image");
const image = new Dict(xref); const image = new Dict(xref);
@ -56594,7 +56588,7 @@ class WorkerMessageHandler {
docId, docId,
apiVersion apiVersion
} = docParams; } = docParams;
const workerVersion = '4.1.30'; const workerVersion = "4.1.86";
if (apiVersion !== workerVersion) { if (apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
} }
@ -57155,8 +57149,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js ;// CONCATENATED MODULE: ./src/pdf.worker.js
const pdfjsVersion = '4.1.30'; const pdfjsVersion = "4.1.86";
const pdfjsBuild = 'a22b5a4f0'; const pdfjsBuild = "bf9236009";
var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler; var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler }; export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };

View file

@ -18,12 +18,17 @@
text-align:initial; text-align:initial;
inset:0; inset:0;
overflow:hidden; overflow:hidden;
opacity:0.25; opacity:1;
line-height:1; line-height:1;
text-size-adjust:none; text-size-adjust:none;
forced-color-adjust:none; forced-color-adjust:none;
transform-origin:0 0; transform-origin:0 0;
z-index:2; z-index:2;
caret-color:CanvasText;
&.drawing{
touch-action:none;
}
:is(span, br){ :is(span, br){
color:transparent; color:transparent;
@ -34,17 +39,22 @@
} }
.highlight{ .highlight{
--highlight-bg-color:rgb(180 0 170); --highlight-bg-color:rgb(180 0 170 / 0.25);
--highlight-selected-bg-color:rgb(0 100 0); --highlight-selected-bg-color:rgb(0 100 0 / 0.25);
--highlight-backdrop-filter:none;
--highlight-selected-backdrop-filter:none;
@media screen and (forced-colors: active){ @media screen and (forced-colors: active){
--highlight-bg-color:Highlight; --highlight-bg-color:transparent;
--highlight-selected-bg-color:ButtonText; --highlight-selected-bg-color:transparent;
--highlight-backdrop-filter:var(--hcm-highlight-filter);
--highlight-selected-backdrop-filter:var(--hcm-highlight-selected-filter);
} }
margin:-1px; margin:-1px;
padding:1px; padding:1px;
background-color:var(--highlight-bg-color); background-color:var(--highlight-bg-color);
backdrop-filter:var(--highlight-backdrop-filter);
border-radius:4px; border-radius:4px;
&.appended{ &.appended{
@ -65,11 +75,12 @@
&.selected{ &.selected{
background-color:var(--highlight-selected-bg-color); background-color:var(--highlight-selected-bg-color);
backdrop-filter:var(--highlight-selected-backdrop-filter);
} }
} }
::selection{ ::selection{
background:AccentColor; background:color-mix(in srgb, AccentColor, transparent 75%);
} }
.endOfContent{ .endOfContent{
@ -101,7 +112,6 @@
--input-disabled-border-color:GrayText; --input-disabled-border-color:GrayText;
--input-hover-border-color:Highlight; --input-hover-border-color:Highlight;
--link-outline:1.5px solid LinkText; --link-outline:1.5px solid LinkText;
--hcm-highlight-filter:invert(100%);
.textWidgetAnnotation :is(input, textarea):required, .textWidgetAnnotation :is(input, textarea):required,
.choiceWidgetAnnotation select:required, .choiceWidgetAnnotation select:required,
@ -785,6 +795,13 @@
--scale-factor:1; --scale-factor:1;
padding-bottom:var(--pdfViewer-padding-bottom); padding-bottom:var(--pdfViewer-padding-bottom);
--hcm-highlight-filter:none;
--hcm-highlight-selected-filter:none;
@media screen and (forced-colors: active){
--hcm-highlight-filter:invert(100%);
}
} }
.pdfViewer .canvasWrapper{ .pdfViewer .canvasWrapper{

View file

@ -182,15 +182,13 @@ function parseQueryString(query) {
} }
return params; return params;
} }
const InvisibleCharactersRegExp = /[\x00-\x1F]/g; const InvisibleCharsRegExp = /[\x00-\x1F]/g;
function removeNullCharacters(str, replaceInvisible = false) { function removeNullCharacters(str, replaceInvisible = false) {
if (!InvisibleCharactersRegExp.test(str)) { if (!InvisibleCharsRegExp.test(str)) {
return str; return str;
} }
if (replaceInvisible) { if (replaceInvisible) {
return str.replaceAll(InvisibleCharactersRegExp, m => { return str.replaceAll(InvisibleCharsRegExp, m => m === "\x00" ? "" : " ");
return m === "\x00" ? "" : " ";
});
} }
return str.replaceAll("\x00", ""); return str.replaceAll("\x00", "");
} }
@ -992,9 +990,7 @@ function addLinkAttributes(link, {
} else { } else {
link.href = ""; link.href = "";
link.title = `Disabled: ${url}`; link.title = `Disabled: ${url}`;
link.onclick = () => { link.onclick = () => false;
return false;
};
} }
let targetStr = ""; let targetStr = "";
switch (target) { switch (target) {
@ -2128,9 +2124,7 @@ class PDFFindController {
const extractTextCapability = new PromiseCapability(); const extractTextCapability = new PromiseCapability();
this._extractTextPromises[i] = extractTextCapability.promise; this._extractTextPromises[i] = extractTextCapability.promise;
promise = promise.then(() => { promise = promise.then(() => {
return this._pdfDocument.getPage(i + 1).then(pdfPage => { return this._pdfDocument.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => {
return pdfPage.getTextContent(textOptions);
}).then(textContent => {
const strBuf = []; const strBuf = [];
for (const textItem of textContent.items) { for (const textItem of textContent.items) {
strBuf.push(textItem.str); strBuf.push(textItem.str);
@ -5036,7 +5030,7 @@ class PDFViewer {
#scaleTimeoutId = null; #scaleTimeoutId = null;
#textLayerMode = TextLayerMode.ENABLE; #textLayerMode = TextLayerMode.ENABLE;
constructor(options) { constructor(options) {
const viewerVersion = '4.1.30'; const viewerVersion = "4.1.86";
if (version !== viewerVersion) { if (version !== viewerVersion) {
throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`);
} }
@ -5440,7 +5434,8 @@ class PDFViewer {
}); });
this.viewer.style.setProperty("--scale-factor", viewport.scale); this.viewer.style.setProperty("--scale-factor", viewport.scale);
if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") { if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") {
this.viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight")); this.viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
this.viewer.style.setProperty("--hcm-highlight-selected-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "ButtonText"));
} }
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({ const pageView = new PDFPageView({
@ -7636,9 +7631,7 @@ const PDFViewerApplication = {
this.pdfRenderingQueue.renderHighestPriority(); this.pdfRenderingQueue.renderHighestPriority();
}, },
beforePrint() { beforePrint() {
this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => { this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => this.pdfDocument?.annotationStorage.print);
return this.pdfDocument?.annotationStorage.print;
});
if (this.printService) { if (this.printService) {
return; return;
} }
@ -8617,34 +8610,34 @@ const PDFPrintServiceFactory = {
class BasePreferences { class BasePreferences {
#defaults = Object.freeze({ #defaults = Object.freeze({
"annotationEditorMode": 0, annotationEditorMode: 0,
"annotationMode": 2, annotationMode: 2,
"cursorToolOnLoad": 0, cursorToolOnLoad: 0,
"defaultZoomDelay": 400, defaultZoomDelay: 400,
"defaultZoomValue": "", defaultZoomValue: "",
"disablePageLabels": false, disablePageLabels: false,
"enableHighlightEditor": false, enableHighlightEditor: false,
"enablePermissions": false, enablePermissions: false,
"enablePrintAutoRotate": true, enablePrintAutoRotate: true,
"enableScripting": true, enableScripting: true,
"externalLinkTarget": 0, externalLinkTarget: 0,
"highlightEditorColors": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
"historyUpdateUrl": false, historyUpdateUrl: false,
"ignoreDestinationZoom": false, ignoreDestinationZoom: false,
"forcePageColors": false, forcePageColors: false,
"pageColorsBackground": "Canvas", pageColorsBackground: "Canvas",
"pageColorsForeground": "CanvasText", pageColorsForeground: "CanvasText",
"pdfBugEnabled": false, pdfBugEnabled: false,
"sidebarViewOnLoad": -1, sidebarViewOnLoad: -1,
"scrollModeOnLoad": -1, scrollModeOnLoad: -1,
"spreadModeOnLoad": -1, spreadModeOnLoad: -1,
"textLayerMode": 1, textLayerMode: 1,
"viewOnLoad": 0, viewOnLoad: 0,
"disableAutoFetch": false, disableAutoFetch: false,
"disableFontFace": false, disableFontFace: false,
"disableRange": false, disableRange: false,
"disableStream": false, disableStream: false,
"enableXfa": true enableXfa: true
}); });
#prefs = Object.create(null); #prefs = Object.create(null);
#initializedPromise = null; #initializedPromise = null;
@ -8657,13 +8650,13 @@ class BasePreferences {
prefs prefs
}) => { }) => {
const BROWSER_PREFS = { const BROWSER_PREFS = {
"canvasMaxAreaInBytes": -1, canvasMaxAreaInBytes: -1,
"isInAutomation": false, isInAutomation: false,
"supportsDocumentFonts": true, supportsDocumentFonts: true,
"supportsIntegratedFind": false, supportsIntegratedFind: false,
"supportsMouseWheelZoomCtrlKey": true, supportsMouseWheelZoomCtrlKey: true,
"supportsMouseWheelZoomMetaKey": true, supportsMouseWheelZoomMetaKey: true,
"supportsPinchToZoom": true supportsPinchToZoom: true
}; };
const options = Object.create(null); const options = Object.create(null);
for (const [name, defaultVal] of Object.entries(BROWSER_PREFS)) { for (const [name, defaultVal] of Object.entries(BROWSER_PREFS)) {
@ -9249,8 +9242,8 @@ PDFPrintServiceFactory.instance = {
const pdfjsVersion = '4.1.30'; const pdfjsVersion = "4.1.86";
const pdfjsBuild = 'a22b5a4f0'; const pdfjsBuild = "bf9236009";
const AppConstants = null; const AppConstants = null;
window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationConstants = AppConstants; window.PDFViewerApplicationConstants = AppConstants;

View file

@ -18,12 +18,17 @@
text-align:initial; text-align:initial;
inset:0; inset:0;
overflow:hidden; overflow:hidden;
opacity:0.25; opacity:1;
line-height:1; line-height:1;
text-size-adjust:none; text-size-adjust:none;
forced-color-adjust:none; forced-color-adjust:none;
transform-origin:0 0; transform-origin:0 0;
z-index:2; z-index:2;
caret-color:CanvasText;
&.drawing{
touch-action:none;
}
:is(span, br){ :is(span, br){
color:transparent; color:transparent;
@ -34,17 +39,22 @@
} }
.highlight{ .highlight{
--highlight-bg-color:rgb(180 0 170); --highlight-bg-color:rgb(180 0 170 / 0.25);
--highlight-selected-bg-color:rgb(0 100 0); --highlight-selected-bg-color:rgb(0 100 0 / 0.25);
--highlight-backdrop-filter:none;
--highlight-selected-backdrop-filter:none;
@media screen and (forced-colors: active){ @media screen and (forced-colors: active){
--highlight-bg-color:Highlight; --highlight-bg-color:transparent;
--highlight-selected-bg-color:ButtonText; --highlight-selected-bg-color:transparent;
--highlight-backdrop-filter:var(--hcm-highlight-filter);
--highlight-selected-backdrop-filter:var(--hcm-highlight-selected-filter);
} }
margin:-1px; margin:-1px;
padding:1px; padding:1px;
background-color:var(--highlight-bg-color); background-color:var(--highlight-bg-color);
backdrop-filter:var(--highlight-backdrop-filter);
border-radius:4px; border-radius:4px;
&.appended{ &.appended{
@ -65,11 +75,12 @@
&.selected{ &.selected{
background-color:var(--highlight-selected-bg-color); background-color:var(--highlight-selected-bg-color);
backdrop-filter:var(--highlight-selected-backdrop-filter);
} }
} }
::selection{ ::selection{
background:AccentColor; background:color-mix(in srgb, AccentColor, transparent 75%);
} }
.endOfContent{ .endOfContent{
@ -101,7 +112,6 @@
--input-disabled-border-color:GrayText; --input-disabled-border-color:GrayText;
--input-hover-border-color:Highlight; --input-hover-border-color:Highlight;
--link-outline:1.5px solid LinkText; --link-outline:1.5px solid LinkText;
--hcm-highlight-filter:invert(100%);
.textWidgetAnnotation :is(input, textarea):required, .textWidgetAnnotation :is(input, textarea):required,
.choiceWidgetAnnotation select:required, .choiceWidgetAnnotation select:required,
@ -774,7 +784,10 @@
position:absolute; position:absolute;
mix-blend-mode:var(--blend-mode); mix-blend-mode:var(--blend-mode);
fill-rule:evenodd;
&:not(.free){
fill-rule:evenodd;
}
} }
&.highlightOutline{ &.highlightOutline{
@ -1706,25 +1719,25 @@
.annotationEditorLayer{ .annotationEditorLayer{
&[data-main-rotation="0"]{ &[data-main-rotation="0"]{
.highlightEditor > .editToolbar{ .highlightEditor:not(.free) > .editToolbar{
rotate:0deg; rotate:0deg;
} }
} }
&[data-main-rotation="90"]{ &[data-main-rotation="90"]{
.highlightEditor > .editToolbar{ .highlightEditor:not(.free) > .editToolbar{
rotate:270deg; rotate:270deg;
} }
} }
&[data-main-rotation="180"]{ &[data-main-rotation="180"]{
.highlightEditor > .editToolbar{ .highlightEditor:not(.free) > .editToolbar{
rotate:180deg; rotate:180deg;
} }
} }
&[data-main-rotation="270"]{ &[data-main-rotation="270"]{
.highlightEditor > .editToolbar{ .highlightEditor:not(.free) > .editToolbar{
rotate:90deg; rotate:90deg;
} }
} }
@ -1733,14 +1746,17 @@
position:absolute; position:absolute;
background:transparent; background:transparent;
z-index:1; z-index:1;
transform-origin:0 0;
cursor:auto; cursor:auto;
max-width:100%; max-width:100%;
max-height:100%; max-height:100%;
border:none; border:none;
outline:none; outline:none;
pointer-events:none; pointer-events:none;
transform:none; transform-origin:0 0;
&:not(.free){
transform:none;
}
.internal{ .internal{
position:absolute; position:absolute;
@ -1793,6 +1809,10 @@
&:has(.dropdown:not(.hidden)){ &:has(.dropdown:not(.hidden)){
background-color:var(--editor-toolbar-hover-bg-color); background-color:var(--editor-toolbar-hover-bg-color);
&::after{
scale:-1;
}
} }
.dropdown{ .dropdown{
@ -1851,21 +1871,22 @@
height:auto; height:auto;
padding-inline:10px; padding-inline:10px;
padding-block:10px 16px; padding-block:10px 16px;
gap:16px;
display:flex; display:flex;
flex-direction:column; flex-direction:column;
box-sizing:border-box; box-sizing:border-box;
.editorParamsLabel{
width:-moz-fit-content;
width:fit-content;
inset-inline-start:0;
}
.colorPicker{ .colorPicker{
display:flex; display:flex;
flex-direction:column; flex-direction:column;
gap:8px; gap:8px;
#highlightColorPickerLabel{
width:-moz-fit-content;
width:fit-content;
inset-inline-start:0;
}
.dropdown{ .dropdown{
display:flex; display:flex;
justify-content:space-between; justify-content:space-between;
@ -1903,6 +1924,60 @@
} }
} }
} }
#editorHighlightThickness{
display:flex;
flex-direction:column;
align-items:center;
gap:4px;
align-self:stretch;
.editorParamsLabel{
width:100%;
height:auto;
align-self:stretch;
}
.thicknessPicker{
display:flex;
justify-content:space-between;
align-items:center;
align-self:stretch;
--example-color:#bfbfc9;
@media (prefers-color-scheme: dark){
--example-color:#80808e;
}
@media screen and (forced-colors: active){
--example-color:HighlightText;
}
&::before{
content:"";
width:8px;
aspect-ratio:1;
display:block;
border-radius:100%;
background-color:var(--example-color);
}
.editorParamsSlider{
width:unset;
height:14px;
}
&::after{
content:"";
width:24px;
aspect-ratio:1;
display:block;
border-radius:100%;
background-color:var(--example-color);
}
}
}
} }
:root{ :root{
@ -1947,6 +2022,13 @@
--scale-factor:1; --scale-factor:1;
padding-bottom:var(--pdfViewer-padding-bottom); padding-bottom:var(--pdfViewer-padding-bottom);
--hcm-highlight-filter:none;
--hcm-highlight-selected-filter:none;
@media screen and (forced-colors: active){
--hcm-highlight-filter:invert(100%);
}
} }
.pdfViewer .canvasWrapper{ .pdfViewer .canvasWrapper{

View file

@ -121,6 +121,12 @@ See https://github.com/adobe-type-tools/cmap-resources
<div id="editorHighlightColorPicker" class="colorPicker"> <div id="editorHighlightColorPicker" class="colorPicker">
<span id="highlightColorPickerLabel" class="editorParamsLabel" data-l10n-id="pdfjs-editor-highlight-colorpicker-label">Highlight color</span> <span id="highlightColorPickerLabel" class="editorParamsLabel" data-l10n-id="pdfjs-editor-highlight-colorpicker-label">Highlight color</span>
</div> </div>
<div id="editorHighlightThickness">
<label for="editorFreeHighlightThickness" class="editorParamsLabel" data-l10n-id="pdfjs-editor-free-highlight-thickness-input">Thickness</label>
<div class="thicknessPicker">
<input type="range" id="editorFreeHighlightThickness" class="editorParamsSlider" value="12" min="8" max="24" step="1" tabindex="101">
</div>
</div>
</div> </div>
</div> </div>

View file

@ -182,15 +182,13 @@ function parseQueryString(query) {
} }
return params; return params;
} }
const InvisibleCharactersRegExp = /[\x00-\x1F]/g; const InvisibleCharsRegExp = /[\x00-\x1F]/g;
function removeNullCharacters(str, replaceInvisible = false) { function removeNullCharacters(str, replaceInvisible = false) {
if (!InvisibleCharactersRegExp.test(str)) { if (!InvisibleCharsRegExp.test(str)) {
return str; return str;
} }
if (replaceInvisible) { if (replaceInvisible) {
return str.replaceAll(InvisibleCharactersRegExp, m => { return str.replaceAll(InvisibleCharsRegExp, m => m === "\x00" ? "" : " ");
return m === "\x00" ? "" : " ";
});
} }
return str.replaceAll("\x00", ""); return str.replaceAll("\x00", "");
} }
@ -992,9 +990,7 @@ function addLinkAttributes(link, {
} else { } else {
link.href = ""; link.href = "";
link.title = `Disabled: ${url}`; link.title = `Disabled: ${url}`;
link.onclick = () => { link.onclick = () => false;
return false;
};
} }
let targetStr = ""; let targetStr = "";
switch (target) { switch (target) {
@ -1673,7 +1669,8 @@ class AnnotationEditorParams {
editorInkColor, editorInkColor,
editorInkThickness, editorInkThickness,
editorInkOpacity, editorInkOpacity,
editorStampAddImage editorStampAddImage,
editorFreeHighlightThickness
}) { }) {
const dispatchEvent = (typeStr, value) => { const dispatchEvent = (typeStr, value) => {
this.eventBus.dispatch("switchannotationeditorparams", { this.eventBus.dispatch("switchannotationeditorparams", {
@ -1700,6 +1697,9 @@ class AnnotationEditorParams {
editorStampAddImage.addEventListener("click", () => { editorStampAddImage.addEventListener("click", () => {
dispatchEvent("CREATE"); dispatchEvent("CREATE");
}); });
editorFreeHighlightThickness.addEventListener("input", function () {
dispatchEvent("HIGHLIGHT_THICKNESS", this.valueAsNumber);
});
this.eventBus._on("annotationeditorparamschanged", evt => { this.eventBus._on("annotationeditorparamschanged", evt => {
for (const [type, value] of evt.details) { for (const [type, value] of evt.details) {
switch (type) { switch (type) {
@ -1718,6 +1718,9 @@ class AnnotationEditorParams {
case AnnotationEditorParamsType.INK_OPACITY: case AnnotationEditorParamsType.INK_OPACITY:
editorInkOpacity.value = value; editorInkOpacity.value = value;
break; break;
case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
editorFreeHighlightThickness.value = value;
break;
} }
} }
}); });
@ -3040,9 +3043,7 @@ class PDFFindController {
const extractTextCapability = new PromiseCapability(); const extractTextCapability = new PromiseCapability();
this._extractTextPromises[i] = extractTextCapability.promise; this._extractTextPromises[i] = extractTextCapability.promise;
promise = promise.then(() => { promise = promise.then(() => {
return this._pdfDocument.getPage(i + 1).then(pdfPage => { return this._pdfDocument.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => {
return pdfPage.getTextContent(textOptions);
}).then(textContent => {
const strBuf = []; const strBuf = [];
for (const textItem of textContent.items) { for (const textItem of textContent.items) {
strBuf.push(textItem.str); strBuf.push(textItem.str);
@ -7634,7 +7635,7 @@ class PDFViewer {
#scaleTimeoutId = null; #scaleTimeoutId = null;
#textLayerMode = TextLayerMode.ENABLE; #textLayerMode = TextLayerMode.ENABLE;
constructor(options) { constructor(options) {
const viewerVersion = '4.1.30'; const viewerVersion = "4.1.86";
if (version !== viewerVersion) { if (version !== viewerVersion) {
throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`);
} }
@ -8038,7 +8039,8 @@ class PDFViewer {
}); });
this.viewer.style.setProperty("--scale-factor", viewport.scale); this.viewer.style.setProperty("--scale-factor", viewport.scale);
if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") { if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") {
this.viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight")); this.viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
this.viewer.style.setProperty("--hcm-highlight-selected-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "ButtonText"));
} }
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({ const pageView = new PDFPageView({
@ -10743,9 +10745,7 @@ const PDFViewerApplication = {
this.pdfRenderingQueue.renderHighestPriority(); this.pdfRenderingQueue.renderHighestPriority();
}, },
beforePrint() { beforePrint() {
this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => { this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => this.pdfDocument?.annotationStorage.print);
return this.pdfDocument?.annotationStorage.print;
});
if (this.printService) { if (this.printService) {
return; return;
} }
@ -11724,34 +11724,34 @@ const PDFPrintServiceFactory = {
class BasePreferences { class BasePreferences {
#defaults = Object.freeze({ #defaults = Object.freeze({
"annotationEditorMode": 0, annotationEditorMode: 0,
"annotationMode": 2, annotationMode: 2,
"cursorToolOnLoad": 0, cursorToolOnLoad: 0,
"defaultZoomDelay": 400, defaultZoomDelay: 400,
"defaultZoomValue": "", defaultZoomValue: "",
"disablePageLabels": false, disablePageLabels: false,
"enableHighlightEditor": false, enableHighlightEditor: false,
"enablePermissions": false, enablePermissions: false,
"enablePrintAutoRotate": true, enablePrintAutoRotate: true,
"enableScripting": true, enableScripting: true,
"externalLinkTarget": 0, externalLinkTarget: 0,
"highlightEditorColors": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
"historyUpdateUrl": false, historyUpdateUrl: false,
"ignoreDestinationZoom": false, ignoreDestinationZoom: false,
"forcePageColors": false, forcePageColors: false,
"pageColorsBackground": "Canvas", pageColorsBackground: "Canvas",
"pageColorsForeground": "CanvasText", pageColorsForeground: "CanvasText",
"pdfBugEnabled": false, pdfBugEnabled: false,
"sidebarViewOnLoad": -1, sidebarViewOnLoad: -1,
"scrollModeOnLoad": -1, scrollModeOnLoad: -1,
"spreadModeOnLoad": -1, spreadModeOnLoad: -1,
"textLayerMode": 1, textLayerMode: 1,
"viewOnLoad": 0, viewOnLoad: 0,
"disableAutoFetch": false, disableAutoFetch: false,
"disableFontFace": false, disableFontFace: false,
"disableRange": false, disableRange: false,
"disableStream": false, disableStream: false,
"enableXfa": true enableXfa: true
}); });
#prefs = Object.create(null); #prefs = Object.create(null);
#initializedPromise = null; #initializedPromise = null;
@ -11764,13 +11764,13 @@ class BasePreferences {
prefs prefs
}) => { }) => {
const BROWSER_PREFS = { const BROWSER_PREFS = {
"canvasMaxAreaInBytes": -1, canvasMaxAreaInBytes: -1,
"isInAutomation": false, isInAutomation: false,
"supportsDocumentFonts": true, supportsDocumentFonts: true,
"supportsIntegratedFind": false, supportsIntegratedFind: false,
"supportsMouseWheelZoomCtrlKey": true, supportsMouseWheelZoomCtrlKey: true,
"supportsMouseWheelZoomMetaKey": true, supportsMouseWheelZoomMetaKey: true,
"supportsPinchToZoom": true supportsPinchToZoom: true
}; };
const options = Object.create(null); const options = Object.create(null);
for (const [name, defaultVal] of Object.entries(BROWSER_PREFS)) { for (const [name, defaultVal] of Object.entries(BROWSER_PREFS)) {
@ -12321,8 +12321,8 @@ PDFPrintServiceFactory.instance = {
const pdfjsVersion = '4.1.30'; const pdfjsVersion = "4.1.86";
const pdfjsBuild = 'a22b5a4f0'; const pdfjsBuild = "bf9236009";
const AppConstants = null; const AppConstants = null;
window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationConstants = AppConstants; window.PDFViewerApplicationConstants = AppConstants;
@ -12447,7 +12447,8 @@ function getViewerConfiguration() {
editorInkColor: document.getElementById("editorInkColor"), editorInkColor: document.getElementById("editorInkColor"),
editorInkThickness: document.getElementById("editorInkThickness"), editorInkThickness: document.getElementById("editorInkThickness"),
editorInkOpacity: document.getElementById("editorInkOpacity"), editorInkOpacity: document.getElementById("editorInkOpacity"),
editorStampAddImage: document.getElementById("editorStampAddImage") editorStampAddImage: document.getElementById("editorStampAddImage"),
editorFreeHighlightThickness: document.getElementById("editorFreeHighlightThickness")
}, },
printContainer: document.getElementById("printContainer"), printContainer: document.getElementById("printContainer"),
openFileInput: null, openFileInput: null,

View file

@ -20,8 +20,8 @@ origin:
# Human-readable identifier for this version/release # Human-readable identifier for this version/release
# Generally "version NNN", "tag SSS", "bookmark SSS" # Generally "version NNN", "tag SSS", "bookmark SSS"
release: a22b5a4f02d046b5113630b1c333281841cbe309 (2024-01-16T21:27:14Z). release: bf9236009521621891d73dd77acc68215cb2cadb (2024-01-25T09:07:48Z).
revision: a22b5a4f02d046b5113630b1c333281841cbe309 revision: bf9236009521621891d73dd77acc68215cb2cadb
# The package's license, where possible using the mnemonic from # The package's license, where possible using the mnemonic from
# https://spdx.org/licenses/ # https://spdx.org/licenses/

View file

@ -349,6 +349,8 @@ pdfjs-editor-ink-opacity-input = Opacity
pdfjs-editor-stamp-add-image-button = pdfjs-editor-stamp-add-image-button =
.title = Add image .title = Add image
pdfjs-editor-stamp-add-image-button-label = Add image pdfjs-editor-stamp-add-image-button-label = Add image
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Thickness
pdfjs-free-text = pdfjs-free-text =
.aria-label = Text Editor .aria-label = Text Editor