Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jan 21, 2024
1 parent 5778f44 commit 8bd67ba
Show file tree
Hide file tree
Showing 49 changed files with 1,074 additions and 159 deletions.
785 changes: 689 additions & 96 deletions build/pdf.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdf.mjs.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/pdf.sandbox.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdf.sandbox.mjs.map

Large diffs are not rendered by default.

114 changes: 90 additions & 24 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,6 @@ function stringToUTF8String(str) {
function utf8StringToString(str) {
return unescape(encodeURIComponent(str));
}
function isArrayBuffer(v) {
return typeof v === "object" && v?.byteLength !== undefined;
}
function isArrayEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
Expand Down Expand Up @@ -29121,7 +29118,7 @@ const BOLDITALIC = {
weight: "bold"
};
const substitutionMap = new Map([["Times-Roman", {
local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"],
local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "Linux Libertine O", "Libertinus Serif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"],
style: NORMAL,
ultimate: "serif"
}], ["Times-Bold", {
Expand Down Expand Up @@ -29157,7 +29154,7 @@ const substitutionMap = new Map([["Times-Roman", {
style: BOLDITALIC,
ultimate: "sans-serif"
}], ["Courier", {
local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono"],
local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono", "Linux Libertine Mono O", "Libertinus Mono"],
style: NORMAL,
ultimate: "monospace"
}], ["Courier-Bold", {
Expand Down Expand Up @@ -29249,6 +29246,10 @@ function getStyleToAppend(style) {
}
return "";
}
function getFamilyName(str) {
const keywords = new Set(["thin", "extralight", "ultralight", "demilight", "semilight", "light", "book", "regular", "normal", "medium", "demibold", "semibold", "bold", "extrabold", "ultrabold", "black", "heavy", "extrablack", "ultrablack", "roman", "italic", "oblique", "ultracondensed", "extracondensed", "condensed", "semicondensed", "normal", "semiexpanded", "expanded", "extraexpanded", "ultraexpanded", "bolditalic"]);
return str.split(/[- ,+]+/g).filter(tok => !keywords.has(tok.toLowerCase())).join(" ");
}
function generateFont({
alias,
local,
Expand Down Expand Up @@ -29325,7 +29326,7 @@ function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFont
const italic = /oblique|italic/gi.test(baseFontName);
const style = bold && italic && BOLDITALIC || bold && BOLD || italic && ITALIC || NORMAL;
substitutionInfo = {
css: loadedName,
css: `"${getFamilyName(baseFontName)}",${loadedName}`,
guessFallback: true,
loadedName,
baseFontName,
Expand All @@ -29346,7 +29347,7 @@ function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFont
const guessFallback = ultimate === null;
const fallback = guessFallback ? "" : `,${ultimate}`;
substitutionInfo = {
css: `${loadedName}${fallback}`,
css: `"${getFamilyName(baseFontName)}",${loadedName}${fallback}`,
guessFallback,
loadedName,
baseFontName,
Expand Down Expand Up @@ -29602,7 +29603,6 @@ class ImageResizer {
ImageResizer._goodSquareLength = MIN_IMAGE_DIM;

;// CONCATENATED MODULE: ./src/shared/murmurhash3.js

const SEED = 0xc3d2e1f0;
const MASK_HIGH = 0xffff0000;
const MASK_LOW = 0xffff;
Expand All @@ -29625,11 +29625,11 @@ class MurmurHash3_64 {
data[length++] = code & 0xff;
}
}
} else if (isArrayBuffer(input)) {
} else if (ArrayBuffer.isView(input)) {
data = input.slice();
length = data.byteLength;
} 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 tailLength = length - blockCounts * 4;
Expand Down Expand Up @@ -32877,6 +32877,9 @@ class PartialEvaluator {
textState.translateTextMatrix(0, -charSpacing);
}
}
if (keepWhiteSpace) {
compareWithLastPosition(0);
}
return;
}
const glyphs = font.charsToGlyphs(chars);
Expand Down Expand Up @@ -37264,7 +37267,7 @@ async function writeObject(ref, obj, buffer, {
await writeDict(obj, buffer, transform);
} else if (obj instanceof BaseStream) {
await writeStream(obj, buffer, transform);
} else if (Array.isArray(obj)) {
} else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
await writeArray(obj, buffer, transform);
}
buffer.push("\nendobj\n");
Expand Down Expand Up @@ -37339,7 +37342,7 @@ async function writeValue(value, buffer, transform) {
buffer.push(`/${escapePDFName(value.name)}`);
} else if (value instanceof Ref) {
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);
} else if (typeof value === "string") {
if (transform) {
Expand Down Expand Up @@ -50662,7 +50665,11 @@ class AnnotationFactory {
}));
break;
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;
case AnnotationEditorType.INK:
promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
Expand Down Expand Up @@ -50729,9 +50736,15 @@ class AnnotationFactory {
}));
break;
case AnnotationEditorType.HIGHLIGHT:
promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
evaluatorOptions: options
}));
if (annotation.quadPoints) {
promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
evaluatorOptions: options
}));
} else {
promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
evaluatorOptions: options
}));
}
break;
case AnnotationEditorType.INK:
promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
Expand Down Expand Up @@ -53334,6 +53347,7 @@ class InkAnnotation extends MarkupAnnotation {
color,
opacity,
paths,
outlines,
rect,
rotation,
thickness
Expand All @@ -53343,9 +53357,12 @@ class InkAnnotation extends MarkupAnnotation {
ink.set("Subtype", Name.get("Ink"));
ink.set("CreationDate", `D:${getModificationDate()}`);
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("Rotate", rotation);
if (outlines) {
ink.set("IT", Name.get("InkHighlight"));
}
const bs = new Dict(xref);
ink.set("BS", bs);
bs.set("W", thickness);
Expand All @@ -53361,6 +53378,9 @@ class InkAnnotation extends MarkupAnnotation {
return ink;
}
static async createNewAppearanceStream(annotation, xref, params) {
if (annotation.outlines) {
return this.createNewAppearanceStreamForHighlight(annotation, xref, params);
}
const {
color,
rect,
Expand All @@ -53378,11 +53398,15 @@ class InkAnnotation extends MarkupAnnotation {
} of paths) {
buffer.length = 0;
buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} m`);
for (let i = 2, ii = bezier.length; i < ii; i += 6) {
const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
buffer.push(`${curve} c`);
if (bezier.length === 2) {
buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} l S`);
} else {
for (let i = 2, ii = bezier.length; i < ii; i += 6) {
const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
buffer.push(`${curve} c`);
}
buffer.push("S");
}
buffer.push("S");
appearanceBuffer.push(buffer.join("\n"));
}
const appearance = appearanceBuffer.join("\n");
Expand All @@ -53406,6 +53430,48 @@ class InkAnnotation extends MarkupAnnotation {
ap.dict = appearanceStreamDict;
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 {
constructor(params) {
Expand Down Expand Up @@ -56628,7 +56694,7 @@ class WorkerMessageHandler {
docId,
apiVersion
} = docParams;
const workerVersion = '4.0.0';
const workerVersion = '4.1.0';
if (apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
}
Expand Down Expand Up @@ -57196,8 +57262,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&

;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = '4.0.0';
const pdfjsBuild = '56ca2fd';
const pdfjsVersion = '4.1.0';
const pdfjsBuild = '6e46304';

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

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions web/locale/be/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Дадаць або змяніць выявы
pdfjs-editor-remove-button =
.title = Выдаліць
pdfjs-editor-highlight-button =
.title = Вылучэнне
pdfjs-editor-highlight-button-label = Вылучэнне
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/cs/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Přidání či úprava obrázků
pdfjs-editor-remove-button =
.title = Odebrat
pdfjs-editor-highlight-button =
.title = Zvýraznění
pdfjs-editor-highlight-button-label = Zvýraznění
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/cy/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Ychwanegu neu olygu delweddau
pdfjs-editor-remove-button =
.title = Tynnu
pdfjs-editor-highlight-button =
.title = Amlygu
pdfjs-editor-highlight-button-label = Amlygu
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/de/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Grafiken hinzufügen oder bearbeiten
pdfjs-editor-remove-button =
.title = Entfernen
pdfjs-editor-highlight-button =
.title = Hervorheben
pdfjs-editor-highlight-button-label = Hervorheben
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/dsb/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Wobraze pśidaś abo wobźěłaś
pdfjs-editor-remove-button =
.title = Wótwónoźeś
pdfjs-editor-highlight-button =
.title = Wuzwignuś
pdfjs-editor-highlight-button-label = Wuzwignuś
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/el/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Προσθήκη ή επεξεργασία εικόνων
pdfjs-editor-remove-button =
.title = Αφαίρεση
pdfjs-editor-highlight-button =
.title = Επισήμανση
pdfjs-editor-highlight-button-label = Επισήμανση
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/en-GB/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Add or edit images
pdfjs-editor-remove-button =
.title = Remove
pdfjs-editor-highlight-button =
.title = Highlight
pdfjs-editor-highlight-button-label = Highlight
## Remove button for the various kind of editor.

Expand Down
38 changes: 38 additions & 0 deletions web/locale/eo/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,25 @@ pdfjs-editor-ink-button-label = Desegni
pdfjs-editor-stamp-button =
.title = Aldoni aŭ modifi bildojn
pdfjs-editor-stamp-button-label = Aldoni aŭ modifi bildojn
pdfjs-editor-remove-button =
.title = Forigi
pdfjs-editor-highlight-button =
.title = Elstarigi
pdfjs-editor-highlight-button-label = Elstarigi
## Remove button for the various kind of editor.

pdfjs-editor-remove-ink-button =
.title = Forigi desegnon
pdfjs-editor-remove-freetext-button =
.title = Forigi tekston
pdfjs-editor-remove-stamp-button =
.title = Forigi bildon
pdfjs-editor-remove-highlight-button =
.title = Forigi elstaraĵon
##

# Editor Parameters
pdfjs-editor-free-text-color-input = Koloro
pdfjs-editor-free-text-size-input = Grando
Expand Down Expand Up @@ -347,3 +366,22 @@ pdfjs-editor-resizer-label-bottom-right = Malsupra deksta angulo — ŝanĝi gra
pdfjs-editor-resizer-label-bottom-middle = Malsupra mezo — ŝanĝi grandon
pdfjs-editor-resizer-label-bottom-left = Malsupra maldekstra angulo — ŝanĝi grandon
pdfjs-editor-resizer-label-middle-left = Maldekstra mezo — ŝanĝi grandon
## Color picker

# This means "Color used to highlight text"
pdfjs-editor-highlight-colorpicker-label = Elstarigi koloron
pdfjs-editor-colorpicker-button =
.title = Ŝanĝi koloron
pdfjs-editor-colorpicker-dropdown =
.aria-label = Elekto de koloroj
pdfjs-editor-colorpicker-yellow =
.title = Flava
pdfjs-editor-colorpicker-green =
.title = Verda
pdfjs-editor-colorpicker-blue =
.title = Blua
pdfjs-editor-colorpicker-pink =
.title = Roza
pdfjs-editor-colorpicker-red =
.title = Ruĝa
3 changes: 3 additions & 0 deletions web/locale/es-AR/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Agregar o editar imágenes
pdfjs-editor-remove-button =
.title = Eliminar
pdfjs-editor-highlight-button =
.title = Resaltar
pdfjs-editor-highlight-button-label = Resaltar
## Remove button for the various kind of editor.

Expand Down
3 changes: 3 additions & 0 deletions web/locale/es-CL/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Añadir o editar imágenes
pdfjs-editor-remove-button =
.title = Eliminar
pdfjs-editor-highlight-button =
.title = Destacar
pdfjs-editor-highlight-button-label = Destacar
## Remove button for the various kind of editor.

Expand Down
Loading

0 comments on commit 8bd67ba

Please sign in to comment.