--- a/toolkit/components/pdfjs/content/build/pdf.js
+++ b/toolkit/components/pdfjs/content/build/pdf.js
@@ -824,16 +824,28 @@ function normalizeUnicode(str) {
if (!NormalizeRegex) {
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"]]);
}
return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
});
}
+const FontRenderOps = {
+ BEZIER_CURVE_TO: 0,
+ MOVE_TO: 1,
+ LINE_TO: 2,
+ QUADRATIC_CURVE_TO: 3,
+ RESTORE: 4,
+ SAVE: 5,
+ SCALE: 6,
+ TRANSFORM: 7,
+ TRANSLATE: 8
+};
+exports.FontRenderOps = FontRenderOps;
/***/ }),
/* 2 */
/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
Object.defineProperty(exports, "__esModule", ({
@@ -960,17 +972,16 @@ function getDocument(src) {
fontExtraProperties,
useSystemFonts,
cMapUrl: useWorkerFetch ? cMapUrl : null,
standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
}
};
const transportParams = {
ignoreErrors,
- isEvalSupported,
disableFontFace,
fontExtraProperties,
enableXfa,
ownerDocument,
disableAutoFetch,
pdfBug,
styleElement
};
@@ -2148,17 +2159,16 @@ class WorkerTransport {
if ("error" in exportedData) {
const exportedError = exportedData.error;
(0, _util.warn)(`Error during font loading: ${exportedError}`);
this.commonObjs.resolve(id, exportedError);
break;
}
const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null;
const font = new _font_loader.FontFaceObject(exportedData, {
- isEvalSupported: params.isEvalSupported,
disableFontFace: params.disableFontFace,
ignoreErrors: params.ignoreErrors,
inspectFont
});
this.fontLoader.bind(font).catch(reason => {
return messageHandler.sendWithPromise("FontFallback", {
id
});
@@ -4755,26 +4765,24 @@ class FontLoader {
}
_prepareFontLoadEvent(font, request) {
throw new Error("Not implemented: _prepareFontLoadEvent");
}
}
exports.FontLoader = FontLoader;
class FontFaceObject {
constructor(translatedData, {
- isEvalSupported = true,
disableFontFace = false,
ignoreErrors = false,
inspectFont = null
}) {
this.compiledGlyphs = Object.create(null);
for (const i in translatedData) {
this[i] = translatedData[i];
}
- this.isEvalSupported = isEvalSupported !== false;
this.disableFontFace = disableFontFace === true;
this.ignoreErrors = ignoreErrors === true;
this._inspectFont = inspectFont;
}
createNativeFontFace() {
if (!this.data || this.disableFontFace) {
return null;
}
@@ -4819,32 +4827,82 @@ class FontFaceObject {
let cmds;
try {
cmds = objs.get(this.loadedName + "_path_" + character);
} catch (ex) {
if (!this.ignoreErrors) {
throw ex;
}
(0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
+ }
+ if (!Array.isArray(cmds) || cmds.length === 0) {
return this.compiledGlyphs[character] = function (c, size) {};
}
- if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
- const jsBuf = [];
- for (const current of cmds) {
- const args = current.args !== undefined ? current.args.join(",") : "";
- jsBuf.push("c.", current.cmd, "(", args, ");\n");
- }
- return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
- }
- return this.compiledGlyphs[character] = function (c, size) {
- for (const current of cmds) {
- if (current.cmd === "scale") {
- current.args = [size, -size];
- }
- c[current.cmd].apply(c, current.args);
+ const commands = [];
+ for (let i = 0, ii = cmds.length; i < ii;) {
+ switch (cmds[i++]) {
+ case _util.FontRenderOps.BEZIER_CURVE_TO:
+ {
+ const [a, b, c, d, e, f] = cmds.slice(i, i + 6);
+ commands.push(ctx => ctx.bezierCurveTo(a, b, c, d, e, f));
+ i += 6;
+ }
+ break;
+ case _util.FontRenderOps.MOVE_TO:
+ {
+ const [a, b] = cmds.slice(i, i + 2);
+ commands.push(ctx => ctx.moveTo(a, b));
+ i += 2;
+ }
+ break;
+ case _util.FontRenderOps.LINE_TO:
+ {
+ const [a, b] = cmds.slice(i, i + 2);
+ commands.push(ctx => ctx.lineTo(a, b));
+ i += 2;
+ }
+ break;
+ case _util.FontRenderOps.QUADRATIC_CURVE_TO:
+ {
+ const [a, b, c, d] = cmds.slice(i, i + 4);
+ commands.push(ctx => ctx.quadraticCurveTo(a, b, c, d));
+ i += 4;
+ }
+ break;
+ case _util.FontRenderOps.RESTORE:
+ commands.push(ctx => ctx.restore());
+ break;
+ case _util.FontRenderOps.SAVE:
+ commands.push(ctx => ctx.save());
+ break;
+ case _util.FontRenderOps.SCALE:
+ _util.assert(commands.length === 2, "Scale command is only valid at the third position.");
+ break;
+ case _util.FontRenderOps.TRANSFORM:
+ {
+ const [a, b, c, d, e, f] = cmds.slice(i, i + 6);
+ commands.push(ctx => ctx.transform(a, b, c, d, e, f));
+ i += 6;
+ }
+ break;
+ case _util.FontRenderOps.TRANSLATE:
+ {
+ const [a, b] = cmds.slice(i, i + 2);
+ commands.push(ctx => ctx.translate(a, b));
+ i += 2;
+ }
+ break;
+ }
+ }
+ return this.compiledGlyphs[character] = function glyphDrawer(ctx, size) {
+ commands[0](ctx);
+ commands[1](ctx);
+ ctx.scale(size, -size);
+ for (let i = 2, ii = commands.length; i < ii; i++) {
+ commands[i](ctx);
}
};
}
}
exports.FontFaceObject = FontFaceObject;
/***/ }),
/* 10 */
--- a/toolkit/components/pdfjs/content/build/pdf.worker.js
+++ b/toolkit/components/pdfjs/content/build/pdf.worker.js
@@ -1416,16 +1416,28 @@ function normalizeUnicode(str) {
if (!NormalizeRegex) {
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"]]);
}
return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
});
}
+const FontRenderOps = {
+ BEZIER_CURVE_TO: 0,
+ MOVE_TO: 1,
+ LINE_TO: 2,
+ QUADRATIC_CURVE_TO: 3,
+ RESTORE: 4,
+ SAVE: 5,
+ SCALE: 6,
+ TRANSFORM: 7,
+ TRANSLATE: 8
+};
+exports.FontRenderOps = FontRenderOps;
/***/ }),
/* 3 */
/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
Object.defineProperty(exports, "__esModule", ({
@@ -11299,29 +11311,33 @@ class PartialEvaluator {
if (standardFontName) {
fontFile = await this.fetchStandardFontData(standardFontName);
isInternalFont = !!fontFile;
}
if (!isInternalFont && this.options.useSystemFonts) {
systemFontInfo = (0, _font_substitutions.getFontSubstitution)(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName);
}
}
+ let fontMatrix = dict.getArray("FontMatrix");
+ if (!Array.isArray(fontMatrix) || fontMatrix.length !== 6 || fontMatrix.some(x => typeof x !== "number")) {
+ fontMatrix = _util.FONT_IDENTITY_MATRIX;
+ }
properties = {
type,
name: fontName.name,
subtype,
file: fontFile,
length1,
length2,
length3,
isInternalFont,
loadedName: baseDict.loadedName,
composite,
fixedPitch: false,
- fontMatrix: dict.getArray("FontMatrix") || _util.FONT_IDENTITY_MATRIX,
+ fontMatrix,
firstChar,
lastChar,
toUnicode,
bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
ascent: descriptor.get("Ascent"),
descent: descriptor.get("Descent"),
xHeight: descriptor.get("XHeight") || 0,
capHeight: descriptor.get("CapHeight") || 0,
@@ -30776,32 +30792,23 @@ function lookupCmap(ranges, unicode) {
}
return {
charCode: code,
glyphId: gid
};
}
function compileGlyf(code, cmds, font) {
function moveTo(x, y) {
- cmds.push({
- cmd: "moveTo",
- args: [x, y]
- });
+ cmds.add(_util.FontRenderOps.MOVE_TO, [x, y]);
}
function lineTo(x, y) {
- cmds.push({
- cmd: "lineTo",
- args: [x, y]
- });
+ cmds.add(_util.FontRenderOps.LINE_TO, [x, y]);
}
function quadraticCurveTo(xa, ya, x, y) {
- cmds.push({
- cmd: "quadraticCurveTo",
- args: [xa, ya, x, y]
- });
+ cmds.add(_util.FontRenderOps.QUADRATIC_CURVE_TO, [xa, ya, x, y]);
}
let i = 0;
const numberOfContours = getInt16(code, i);
let flags;
let x = 0,
y = 0;
i += 10;
if (numberOfContours < 0) {
@@ -30850,27 +30857,21 @@ function compileGlyf(code, cmds, font) {
scaleX = getFloat214(code, i);
scale01 = getFloat214(code, i + 2);
scale10 = getFloat214(code, i + 4);
scaleY = getFloat214(code, i + 6);
i += 8;
}
const subglyph = font.glyphs[glyphIndex];
if (subglyph) {
- cmds.push({
- cmd: "save"
- }, {
- cmd: "transform",
- args: [scaleX, scale01, scale10, scaleY, x, y]
- });
+ cmds.add(_util.FontRenderOps.SAVE);
+ cmds.add(_util.FontRenderOps.TRANSFORM, [scaleX, scale01, scale10, scaleY, x, y]);
if (!(flags & 0x02)) {}
compileGlyf(subglyph, cmds, font);
- cmds.push({
- cmd: "restore"
- });
+ cmds.add(_util.FontRenderOps.RESTORE);
}
} while (flags & 0x20);
} else {
const endPtsOfContours = [];
let j, jj;
for (j = 0; j < numberOfContours; j++) {
endPtsOfContours.push(getUint16(code, i));
i += 2;
@@ -30950,32 +30951,23 @@ function compileGlyf(code, cmds, font) {
}
}
startPoint = endPoint + 1;
}
}
}
function compileCharString(charStringCode, cmds, font, glyphId) {
function moveTo(x, y) {
- cmds.push({
- cmd: "moveTo",
- args: [x, y]
- });
+ cmds.add(_util.FontRenderOps.MOVE_TO, [x, y]);
}
function lineTo(x, y) {
- cmds.push({
- cmd: "lineTo",
- args: [x, y]
- });
+ cmds.add(_util.FontRenderOps.LINE_TO, [x, y]);
}
function bezierCurveTo(x1, y1, x2, y2, x, y) {
- cmds.push({
- cmd: "bezierCurveTo",
- args: [x1, y1, x2, y2, x, y]
- });
+ cmds.add(_util.FontRenderOps.BEZIER_CURVE_TO, [x1, y1, x2, y2, x, y]);
}
const stack = [];
let x = 0,
y = 0;
let stems = 0;
function parse(code) {
let i = 0;
while (i < code.length) {
@@ -31135,27 +31127,21 @@ function compileCharString(charStringCod
}
break;
case 14:
if (stack.length >= 4) {
const achar = stack.pop();
const bchar = stack.pop();
y = stack.pop();
x = stack.pop();
- cmds.push({
- cmd: "save"
- }, {
- cmd: "translate",
- args: [x, y]
- });
+ cmds.add(_util.FontRenderOps.SAVE);
+ cmds.add(_util.FontRenderOps.TRANSLATE, [x, y]);
let cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[_encodings.StandardEncoding[achar]]));
compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
- cmds.push({
- cmd: "restore"
- });
+ cmds.add(_util.FontRenderOps.RESTORE);
cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[_encodings.StandardEncoding[bchar]]));
compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
}
return;
case 18:
stems += stack.length >> 1;
stackClean = true;
break;
@@ -31312,16 +31298,32 @@ function compileCharString(charStringCod
if (stackClean) {
stack.length = 0;
}
}
}
parse(charStringCode);
}
const NOOP = [];
+class Commands {
+ cmds = [];
+ add(cmd, args) {
+ if (args) {
+ if (args.some(arg => typeof arg !== "number")) {
+ warn(`Commands.add - "${cmd}" has at least one non-number arg: "${args}".`);
+ const newArgs = args.map(arg => typeof arg === "number" ? arg : 0);
+ this.cmds.push(cmd, ...newArgs);
+ } else {
+ this.cmds.push(cmd, ...args);
+ }
+ } else {
+ this.cmds.push(cmd);
+ }
+ }
+}
class CompiledFont {
constructor(fontMatrix) {
if (this.constructor === CompiledFont) {
(0, _util.unreachable)("Cannot initialize CompiledFont.");
}
this.fontMatrix = fontMatrix;
this.compiledGlyphs = Object.create(null);
this.compiledCharCodeToGlyphId = Object.create(null);
@@ -31329,18 +31331,17 @@ class CompiledFont {
getPathJs(unicode) {
const {
charCode,
glyphId
} = lookupCmap(this.cmap, unicode);
let fn = this.compiledGlyphs[glyphId];
if (!fn) {
try {
- fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
- this.compiledGlyphs[glyphId] = fn;
+ fn = this.compiledGlyphs[glyphId] = this.compileGlyph(this.glyphs[glyphId], glyphId);
} catch (ex) {
this.compiledGlyphs[glyphId] = NOOP;
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
this.compiledCharCodeToGlyphId[charCode] = glyphId;
}
throw ex;
}
}
@@ -31358,30 +31359,23 @@ class CompiledFont {
const fdIndex = this.fdSelect.getFDIndex(glyphId);
if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
const fontDict = this.fdArray[fdIndex];
fontMatrix = fontDict.getByName("FontMatrix") || _util.FONT_IDENTITY_MATRIX;
} else {
(0, _util.warn)("Invalid fd index for glyph index.");
}
}
- const cmds = [{
- cmd: "save"
- }, {
- cmd: "transform",
- args: fontMatrix.slice()
- }, {
- cmd: "scale",
- args: ["size", "-size"]
- }];
+ const cmds = new Commands();
+ cmds.add(_util.FontRenderOps.SAVE);
+ cmds.add(_util.FontRenderOps.TRANSFORM, fontMatrix.slice());
+ cmds.add(_util.FontRenderOps.SCALE);
this.compileGlyphImpl(code, cmds, glyphId);
- cmds.push({
- cmd: "restore"
- });
- return cmds;
+ cmds.add(_util.FontRenderOps.RESTORE);
+ return cmds.cmds;
}
compileGlyphImpl() {
(0, _util.unreachable)("Children classes should implement this.");
}
hasBuiltPath(unicode) {
const {
charCode,
glyphId