Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 26, 2024
1 parent 757d9a0 commit 287021b
Show file tree
Hide file tree
Showing 8 changed files with 728 additions and 639 deletions.
1,149 changes: 630 additions & 519 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.

77 changes: 44 additions & 33 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8860,13 +8860,17 @@ class Parser {
this.shift();
return imageStream;
}
_findStreamLength(startPos, signature) {
#findStreamLength(startPos) {
const {
stream
} = this.lexer;
stream.pos = startPos;
const SCAN_BLOCK_LENGTH = 2048;
const signatureLength = signature.length;
const signatureLength = "endstream".length;
const END_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64]);
const endLength = END_SIGNATURE.length;
const PARTIAL_SIGNATURE = [new Uint8Array([0x73, 0x74, 0x72, 0x65, 0x61, 0x6d]), new Uint8Array([0x73, 0x74, 0x65, 0x61, 0x6d]), new Uint8Array([0x73, 0x74, 0x72, 0x65, 0x61])];
const normalLength = signatureLength - endLength;
while (stream.pos < stream.end) {
const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
const scanLength = scanBytes.length - signatureLength;
Expand All @@ -8876,12 +8880,34 @@ class Parser {
let pos = 0;
while (pos < scanLength) {
let j = 0;
while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
while (j < endLength && scanBytes[pos + j] === END_SIGNATURE[j]) {
j++;
}
if (j >= signatureLength) {
stream.pos += pos;
return stream.pos - startPos;
if (j >= endLength) {
let found = false;
for (const part of PARTIAL_SIGNATURE) {
const partLen = part.length;
let k = 0;
while (k < partLen && scanBytes[pos + j + k] === part[k]) {
k++;
}
if (k >= normalLength) {
found = true;
break;
}
if (k >= partLen) {
const lastByte = scanBytes[pos + j + k];
if (isWhiteSpace(lastByte)) {
info(`Found "${bytesToString([...END_SIGNATURE, ...part])}" when ` + "searching for endstream command.");
found = true;
}
break;
}
}
if (found) {
stream.pos += pos;
return stream.pos - startPos;
}
}
pos++;
}
Expand All @@ -8904,27 +8930,9 @@ class Parser {
if (this.tryShift() && isCmd(this.buf2, "endstream")) {
this.shift();
} else {
const ENDSTREAM_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d]);
let actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
const actualLength = this.#findStreamLength(startPos);
if (actualLength < 0) {
const MAX_TRUNCATION = 1;
for (let i = 1; i <= MAX_TRUNCATION; i++) {
const end = ENDSTREAM_SIGNATURE.length - i;
const TRUNCATED_SIGNATURE = ENDSTREAM_SIGNATURE.slice(0, end);
const maybeLength = this._findStreamLength(startPos, TRUNCATED_SIGNATURE);
if (maybeLength >= 0) {
const lastByte = stream.peekBytes(end + 1)[end];
if (!isWhiteSpace(lastByte)) {
break;
}
info(`Found "${bytesToString(TRUNCATED_SIGNATURE)}" when ` + "searching for endstream command.");
actualLength = maybeLength;
break;
}
}
if (actualLength < 0) {
throw new FormatError("Missing endstream command.");
}
throw new FormatError("Missing endstream command.");
}
length = actualLength;
lexer.nextChar();
Expand Down Expand Up @@ -22755,8 +22763,7 @@ function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
let nextAvailableFontCharCode = privateUseOffetStart;
let privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
const isInPrivateArea = code => PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1] || PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1];
for (let originalCharCode in charCodeToGlyphId) {
originalCharCode |= 0;
for (const originalCharCode in charCodeToGlyphId) {
let glyphId = charCodeToGlyphId[originalCharCode];
if (!hasGlyph(glyphId)) {
continue;
Expand Down Expand Up @@ -24451,7 +24458,7 @@ class Font {
tag: "post",
data: createPostTable(properties)
};
const charCodeToGlyphId = [];
const charCodeToGlyphId = Object.create(null);
function hasGlyph(glyphId) {
return !missingGlyphs[glyphId];
}
Expand Down Expand Up @@ -30395,7 +30402,11 @@ class PartialEvaluator {
if (this.fontCache.has(fontRef)) {
return this.fontCache.get(fontRef);
}
font = this.xref.fetchIfRef(fontRef);
try {
font = this.xref.fetchIfRef(fontRef);
} catch (ex) {
warn(`loadFont - lookup failed: "${ex}".`);
}
}
if (!(font instanceof Dict)) {
if (!this.options.ignoreErrors && !this.parsingType3Font) {
Expand Down Expand Up @@ -54543,7 +54554,7 @@ class PDFDocument {
if (type instanceof Ref) {
type = await xref.fetchAsync(type);
}
if (isName(type, "Page") || !obj.has("Type") && !obj.has("Kids")) {
if (isName(type, "Page") || !obj.has("Type") && !obj.has("Kids") && obj.has("Contents")) {
if (!catalog.pageKidsCountCache.has(ref)) {
catalog.pageKidsCountCache.put(ref, 1);
}
Expand Down Expand Up @@ -54828,7 +54839,7 @@ class BasePdfManager {
this._password = args.password;
this.enableXfa = args.enableXfa;
args.evaluatorOptions.isOffscreenCanvasSupported &&= FeatureTest.isOffscreenCanvasSupported;
this.evaluatorOptions = args.evaluatorOptions;
this.evaluatorOptions = Object.freeze(args.evaluatorOptions);
}
get docId() {
return this._docId;
Expand Down Expand Up @@ -56092,7 +56103,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.3.0";
const pdfjsBuild = "63b66b4";
const pdfjsBuild = "17e09e5";

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.

12 changes: 2 additions & 10 deletions web/locale/ia/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ pdfjs-download-button-label = Discargar
pdfjs-bookmark-button =
.title = Pagina actual (vide le URL del pagina actual)
pdfjs-bookmark-button-label = Pagina actual
# Used in Firefox for Android.
pdfjs-open-in-app-button =
.title = Aperir in app
# Used in Firefox for Android.
# Length of the translation matters since we are in a mobile context, with limited screen estate.
pdfjs-open-in-app-button-label = Aperir in app
## Secondary toolbar and context menu

Expand All @@ -67,8 +61,8 @@ pdfjs-first-page-button =
.title = Ir al prime pagina
pdfjs-first-page-button-label = Ir al prime pagina
pdfjs-last-page-button =
.title = Ir al prime pagina
pdfjs-last-page-button-label = Ir al prime pagina
.title = Ir al ultime pagina
pdfjs-last-page-button-label = Ir al ultime pagina
pdfjs-page-rotate-cw-button =
.title = Rotar in senso horari
pdfjs-page-rotate-cw-button-label = Rotar in senso horari
Expand Down Expand Up @@ -304,8 +298,6 @@ pdfjs-editor-stamp-button-label = Adder o rediger imagines
pdfjs-editor-highlight-button =
.title = Evidentia
pdfjs-editor-highlight-button-label = Evidentia
pdfjs-highlight-floating-button =
.title = Evidentiar
pdfjs-highlight-floating-button1 =
.title = Evidentiar
.aria-label = Evidentiar
Expand Down
Loading

0 comments on commit 287021b

Please sign in to comment.