summaryrefslogtreecommitdiffstats
path: root/toolkit/components/pdfjs/content
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:21:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:21:19 +0000
commit520a92573ce79e3628762e4ce06e284d50c2e548 (patch)
treedd7bece82fdce266f06a6a2a6043264255631ee7 /toolkit/components/pdfjs/content
parentAdding debian version 115.10.0esr-1~deb12u1. (diff)
downloadfirefox-esr-520a92573ce79e3628762e4ce06e284d50c2e548.tar.xz
firefox-esr-520a92573ce79e3628762e4ce06e284d50c2e548.zip
Merging upstream version 115.11.0esr.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/pdfjs/content')
-rw-r--r--toolkit/components/pdfjs/content/build/pdf.js94
-rw-r--r--toolkit/components/pdfjs/content/build/pdf.worker.js110
2 files changed, 128 insertions, 76 deletions
diff --git a/toolkit/components/pdfjs/content/build/pdf.js b/toolkit/components/pdfjs/content/build/pdf.js
index 017a45914e..d2034d412b 100644
--- a/toolkit/components/pdfjs/content/build/pdf.js
+++ b/toolkit/components/pdfjs/content/build/pdf.js
@@ -829,6 +829,18 @@ function normalizeUnicode(str) {
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 */
@@ -965,7 +977,6 @@ function getDocument(src) {
};
const transportParams = {
ignoreErrors,
- isEvalSupported,
disableFontFace,
fontExtraProperties,
enableXfa,
@@ -2153,7 +2164,6 @@ class WorkerTransport {
}
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
@@ -4760,7 +4770,6 @@ class FontLoader {
exports.FontLoader = FontLoader;
class FontFaceObject {
constructor(translatedData, {
- isEvalSupported = true,
disableFontFace = false,
ignoreErrors = false,
inspectFont = null
@@ -4769,7 +4778,6 @@ class FontFaceObject {
for (const i in translatedData) {
this[i] = translatedData[i];
}
- this.isEvalSupported = isEvalSupported !== false;
this.disableFontFace = disableFontFace === true;
this.ignoreErrors = ignoreErrors === true;
this._inspectFont = inspectFont;
@@ -4824,22 +4832,72 @@ class FontFaceObject {
throw ex;
}
(0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
- 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(""));
+ if (!Array.isArray(cmds) || cmds.length === 0) {
+ return this.compiledGlyphs[character] = function (c, size) {};
}
- 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);
}
};
}
diff --git a/toolkit/components/pdfjs/content/build/pdf.worker.js b/toolkit/components/pdfjs/content/build/pdf.worker.js
index 62305d24a9..87999f64a6 100644
--- a/toolkit/components/pdfjs/content/build/pdf.worker.js
+++ b/toolkit/components/pdfjs/content/build/pdf.worker.js
@@ -1421,6 +1421,18 @@ function normalizeUnicode(str) {
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 */
@@ -11304,6 +11316,10 @@ class PartialEvaluator {
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,
@@ -11316,7 +11332,7 @@ class PartialEvaluator {
loadedName: baseDict.loadedName,
composite,
fixedPitch: false,
- fontMatrix: dict.getArray("FontMatrix") || _util.FONT_IDENTITY_MATRIX,
+ fontMatrix,
firstChar,
lastChar,
toUnicode,
@@ -30781,22 +30797,13 @@ function lookupCmap(ranges, unicode) {
}
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);
@@ -30855,17 +30862,11 @@ function compileGlyf(code, cmds, font) {
}
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 {
@@ -30955,22 +30956,13 @@ function compileGlyf(code, cmds, font) {
}
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,
@@ -31140,17 +31132,11 @@ function compileCharString(charStringCode, cmds, font, glyphId) {
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);
}
@@ -31317,6 +31303,22 @@ function compileCharString(charStringCode, cmds, font, glyphId) {
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) {
@@ -31334,8 +31336,7 @@ class CompiledFont {
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) {
@@ -31363,20 +31364,13 @@ class CompiledFont {
(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.");