Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Feb 18, 2024
1 parent ed7ff7a commit eebd31a
Show file tree
Hide file tree
Showing 47 changed files with 700 additions and 491 deletions.
321 changes: 181 additions & 140 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.

4 changes: 2 additions & 2 deletions build/pdf.sandbox.mjs

Large diffs are not rendered by default.

179 changes: 125 additions & 54 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const AnnotationEditorParamsType = {
INK_OPACITY: 23,
HIGHLIGHT_COLOR: 31,
HIGHLIGHT_DEFAULT_COLOR: 32,
HIGHLIGHT_THICKNESS: 33
HIGHLIGHT_THICKNESS: 33,
HIGHLIGHT_FREE: 34
};
const PermissionFlag = {
PRINT: 0x04,
Expand Down Expand Up @@ -1531,6 +1532,9 @@ function getRotationMatrix(rotation, width, height) {
throw new Error("Invalid rotation");
}
}
function getSizeInBytes(x) {
return Math.ceil(Math.ceil(Math.log2(1 + x)) / 8);
}

;// CONCATENATED MODULE: ./src/core/stream.js

Expand Down Expand Up @@ -25307,6 +25311,10 @@ class Font {
locaEntries[i].endOffset = nextOffset;
break;
}
const last = locaEntries.at(-2);
if (last.offset !== 0 && last.endOffset === 0) {
last.endOffset = oldGlyfDataLength;
}
const missingGlyphs = Object.create(null);
let writeOffset = 0;
itemEncode(locaData, 0, writeOffset);
Expand Down Expand Up @@ -32458,6 +32466,7 @@ class PartialEvaluator {
case OPS.beginMarkedContentProps:
if (!(args[0] instanceof Name)) {
warn(`Expected name for beginMarkedContentProps arg0=${args[0]}`);
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
continue;
}
if (args[0].name === "OC") {
Expand All @@ -32469,6 +32478,7 @@ class PartialEvaluator {
}
if (self.options.ignoreErrors) {
warn(`getOperatorList - ignoring beginMarkedContentProps: "${reason}".`);
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
return;
}
throw reason;
Expand Down Expand Up @@ -37207,6 +37217,7 @@ class CipherTransformFactory {




async function writeObject(ref, obj, buffer, {
encrypt = null
}) {
Expand Down Expand Up @@ -37427,6 +37438,103 @@ function updateXFA({
data
});
}
async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
buffer.push("xref\n");
const indexes = getIndexes(newRefs);
let indexesPosition = 0;
for (const {
ref,
data
} of newRefs) {
if (ref.num === indexes[indexesPosition]) {
buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`);
indexesPosition += 2;
}
buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`);
baseOffset += data.length;
}
computeIDs(baseOffset, xrefInfo, newXref);
buffer.push("trailer\n");
await writeDict(newXref, buffer);
buffer.push("\nstartxref\n", baseOffset.toString(), "\n%%EOF\n");
}
function getIndexes(newRefs) {
const indexes = [];
for (const {
ref
} of newRefs) {
if (ref.num === indexes.at(-2) + indexes.at(-1)) {
indexes[indexes.length - 1] += 1;
} else {
indexes.push(ref.num, 1);
}
}
return indexes;
}
async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
const xrefTableData = [];
let maxOffset = 0;
let maxGen = 0;
for (const {
ref,
data
} of newRefs) {
maxOffset = Math.max(maxOffset, baseOffset);
const gen = Math.min(ref.gen, 0xffff);
maxGen = Math.max(maxGen, gen);
xrefTableData.push([1, baseOffset, gen]);
baseOffset += data.length;
}
newXref.set("Index", getIndexes(newRefs));
const offsetSize = getSizeInBytes(maxOffset);
const maxGenSize = getSizeInBytes(maxGen);
const sizes = [1, offsetSize, maxGenSize];
newXref.set("W", sizes);
computeIDs(baseOffset, xrefInfo, newXref);
const structSize = sizes.reduce((a, x) => a + x, 0);
const data = new Uint8Array(structSize * xrefTableData.length);
const stream = new Stream(data);
stream.dict = newXref;
let offset = 0;
for (const [type, objOffset, gen] of xrefTableData) {
offset = writeInt(type, sizes[0], offset, data);
offset = writeInt(objOffset, sizes[1], offset, data);
offset = writeInt(gen, sizes[2], offset, data);
}
await writeObject(xrefInfo.newRef, stream, buffer, {});
buffer.push("startxref\n", baseOffset.toString(), "\n%%EOF\n");
}
function computeIDs(baseOffset, xrefInfo, newXref) {
if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
const md5 = computeMD5(baseOffset, xrefInfo);
newXref.set("ID", [xrefInfo.fileIds[0], md5]);
}
}
function getTrailerDict(xrefInfo, newRefs, useXrefStream) {
const newXref = new Dict(null);
newXref.set("Prev", xrefInfo.startXRef);
const refForXrefTable = xrefInfo.newRef;
if (useXrefStream) {
newRefs.push({
ref: refForXrefTable,
data: ""
});
newXref.set("Size", refForXrefTable.num + 1);
newXref.set("Type", Name.get("XRef"));
} else {
newXref.set("Size", refForXrefTable.num);
}
if (xrefInfo.rootRef !== null) {
newXref.set("Root", xrefInfo.rootRef);
}
if (xrefInfo.infoRef !== null) {
newXref.set("Info", xrefInfo.infoRef);
}
if (xrefInfo.encryptRef !== null) {
newXref.set("Encrypt", xrefInfo.encryptRef);
}
return newXref;
}
async function incrementalUpdate({
originalData,
xrefInfo,
Expand All @@ -37438,7 +37546,8 @@ async function incrementalUpdate({
needAppearances,
acroFormRef = null,
acroForm = null,
xfaData = null
xfaData = null,
useXrefStream = false
}) {
await updateAcroform({
xref,
Expand All @@ -37458,8 +37567,6 @@ async function incrementalUpdate({
xref
});
}
const newXref = new Dict(null);
const refForXrefTable = xrefInfo.newRef;
let buffer, baseOffset;
const lastByte = originalData.at(-1);
if (lastByte === 0x0a || lastByte === 0x0d) {
Expand All @@ -37469,65 +37576,22 @@ async function incrementalUpdate({
buffer = ["\n"];
baseOffset = originalData.length + 1;
}
newXref.set("Size", refForXrefTable.num + 1);
newXref.set("Prev", xrefInfo.startXRef);
newXref.set("Type", Name.get("XRef"));
if (xrefInfo.rootRef !== null) {
newXref.set("Root", xrefInfo.rootRef);
}
if (xrefInfo.infoRef !== null) {
newXref.set("Info", xrefInfo.infoRef);
}
if (xrefInfo.encryptRef !== null) {
newXref.set("Encrypt", xrefInfo.encryptRef);
}
newRefs.push({
ref: refForXrefTable,
data: ""
});
const newXref = getTrailerDict(xrefInfo, newRefs, useXrefStream);
newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num);
const xrefTableData = [[0, 1, 0xffff]];
const indexes = [0, 1];
let maxOffset = 0;
for (const {
ref,
data
} of newRefs) {
maxOffset = Math.max(maxOffset, baseOffset);
xrefTableData.push([1, baseOffset, Math.min(ref.gen, 0xffff)]);
baseOffset += data.length;
indexes.push(ref.num, 1);
buffer.push(data);
}
newXref.set("Index", indexes);
if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
const md5 = computeMD5(baseOffset, xrefInfo);
newXref.set("ID", [xrefInfo.fileIds[0], md5]);
}
const offsetSize = Math.ceil(Math.log2(maxOffset) / 8);
const sizes = [1, offsetSize, 2];
const structSize = sizes[0] + sizes[1] + sizes[2];
const tableLength = structSize * xrefTableData.length;
newXref.set("W", sizes);
newXref.set("Length", tableLength);
buffer.push(`${refForXrefTable.num} ${refForXrefTable.gen} obj\n`);
await writeDict(newXref, buffer, null);
buffer.push(" stream\n");
const bufferLen = buffer.reduce((a, str) => a + str.length, 0);
const footer = `\nendstream\nendobj\nstartxref\n${baseOffset}\n%%EOF\n`;
const array = new Uint8Array(originalData.length + bufferLen + tableLength + footer.length);
await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer));
const totalLength = buffer.reduce((a, str) => a + str.length, originalData.length);
const array = new Uint8Array(totalLength);
array.set(originalData);
let offset = originalData.length;
for (const str of buffer) {
writeString(str, offset, array);
offset += str.length;
}
for (const [type, objOffset, gen] of xrefTableData) {
offset = writeInt(type, sizes[0], offset, array);
offset = writeInt(objOffset, sizes[1], offset, array);
offset = writeInt(gen, sizes[2], offset, array);
}
writeString(footer, offset, array);
return array;
}

Expand Down Expand Up @@ -55179,7 +55243,13 @@ class PDFDocument {
if (this.linearization) {
stream.reset();
if (find(stream, ENDOBJ_SIGNATURE)) {
startXRef = stream.pos + 6 - stream.start;
stream.skip(6);
let ch = stream.peekByte();
while (isWhiteSpace(ch)) {
stream.pos++;
ch = stream.peekByte();
}
startXRef = stream.pos - stream.start;
}
} else {
const step = 1024;
Expand Down Expand Up @@ -57082,7 +57152,8 @@ class WorkerMessageHandler {
needAppearances,
acroFormRef,
acroForm,
xfaData
xfaData,
useXrefStream: isDict(xref.topDict, "XRef")
}).finally(() => {
xref.resetNewTemporaryRef();
});
Expand Down Expand Up @@ -57202,7 +57273,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.1.0";
const pdfjsBuild = "485e9ce";
const pdfjsBuild = "4ac8ee8";

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.

6 changes: 4 additions & 2 deletions web/locale/be/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ pdfjs-editor-ink-button-label = Маляваць
pdfjs-editor-stamp-button =
.title = Дадаць або змяніць выявы
pdfjs-editor-stamp-button-label = Дадаць або змяніць выявы
pdfjs-editor-remove-button =
.title = Выдаліць
pdfjs-editor-highlight-button =
.title = Вылучэнне
pdfjs-editor-highlight-button-label = Вылучэнне
Expand All @@ -331,6 +329,10 @@ pdfjs-editor-ink-opacity-input = Непразрыстасць
pdfjs-editor-stamp-add-image-button =
.title = Дадаць выяву
pdfjs-editor-stamp-add-image-button-label = Дадаць выяву
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Таўшчыня
pdfjs-editor-free-highlight-thickness-title =
.title = Змяняць таўшчыню пры вылучэнні іншых элементаў, акрамя тэксту
pdfjs-free-text =
.aria-label = Тэкставы рэдактар
pdfjs-free-text-default-content = Пачніце набор тэксту…
Expand Down
6 changes: 4 additions & 2 deletions web/locale/cs/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ pdfjs-editor-ink-button-label = Kreslení
pdfjs-editor-stamp-button =
.title = Přidání či úprava obrázků
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í
Expand All @@ -333,6 +331,10 @@ pdfjs-editor-ink-opacity-input = Průhlednost
pdfjs-editor-stamp-add-image-button =
.title = Přidat obrázek
pdfjs-editor-stamp-add-image-button-label = Přidat obrázek
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Tloušťka
pdfjs-editor-free-highlight-thickness-title =
.title = Změna tloušťky při zvýrazňování jiných položek než textu
pdfjs-free-text =
.aria-label = Textový editor
pdfjs-free-text-default-content = Začněte psát…
Expand Down
18 changes: 10 additions & 8 deletions web/locale/cy/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ pdfjs-of-pages = o { $pagesCount }
# $pagesCount (Number) - the total number of pages in the document
pdfjs-page-of-pages = ({ $pageNumber } o { $pagesCount })
pdfjs-zoom-out-button =
.title = Chwyddo Allan
pdfjs-zoom-out-button-label = Chwyddo Allan
.title = Lleihau
pdfjs-zoom-out-button-label = Lleihau
pdfjs-zoom-in-button =
.title = Chwyddo Mewn
pdfjs-zoom-in-button-label = Chwyddo Mewn
.title = Cynyddu
pdfjs-zoom-in-button-label = Cynyddu
pdfjs-zoom-select =
.title = Chwyddo
pdfjs-presentation-mode-button =
Expand All @@ -44,10 +44,10 @@ pdfjs-save-button =
pdfjs-save-button-label = Cadw
# Used in Firefox for Android as a tooltip for the download button (“download” is a verb).
pdfjs-download-button =
.title = Llwytho i Lawr
.title = Llwytho i lawr
# Used in Firefox for Android as a label for the download button (“download” is a verb).
# Length of the translation matters since we are in a mobile context, with limited screen estate.
pdfjs-download-button-label = Llwytho i Lawr
pdfjs-download-button-label = Llwytho i lawr
pdfjs-bookmark-button =
.title = Tudalen Gyfredol (Gweld URL o'r Dudalen Gyfredol)
pdfjs-bookmark-button-label = Tudalen Gyfredol
Expand Down Expand Up @@ -309,8 +309,6 @@ pdfjs-editor-ink-button-label = Lluniadu
pdfjs-editor-stamp-button =
.title = Ychwanegu neu olygu delweddau
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
Expand All @@ -337,6 +335,10 @@ pdfjs-editor-ink-opacity-input = Didreiddedd
pdfjs-editor-stamp-add-image-button =
.title = Ychwanegu delwedd
pdfjs-editor-stamp-add-image-button-label = Ychwanegu delwedd
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Trwch
pdfjs-editor-free-highlight-thickness-title =
.title = Newid trwch wrth amlygu eitemau heblaw testun
pdfjs-free-text =
.aria-label = Golygydd Testun
pdfjs-free-text-default-content = Cychwyn teipio…
Expand Down
9 changes: 7 additions & 2 deletions web/locale/da/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ pdfjs-editor-ink-button-label = Tegn
pdfjs-editor-stamp-button =
.title = Tilføj eller rediger billeder
pdfjs-editor-stamp-button-label = Tilføj eller rediger billeder
pdfjs-editor-remove-button =
.title = Fjern
pdfjs-editor-highlight-button =
.title = Fremhæv
pdfjs-editor-highlight-button-label = Fremhæv
## Remove button for the various kind of editor.

Expand All @@ -326,6 +327,10 @@ pdfjs-editor-ink-opacity-input = Uigennemsigtighed
pdfjs-editor-stamp-add-image-button =
.title = Tilføj billede
pdfjs-editor-stamp-add-image-button-label = Tilføj billede
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Tykkelse
pdfjs-editor-free-highlight-thickness-title =
.title = Ændr tykkelse, når andre elementer end tekst fremhæves
pdfjs-free-text =
.aria-label = Teksteditor
pdfjs-free-text-default-content = Begynd at skrive…
Expand Down
Loading

0 comments on commit eebd31a

Please sign in to comment.