Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Dec 24, 2023
1 parent 53cac2d commit 8c246b0
Show file tree
Hide file tree
Showing 55 changed files with 1,467 additions and 39 deletions.
59 changes: 39 additions & 20 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4057,10 +4057,10 @@ class WorkerTransport {
});
messageHandler.on("commonobj", ([id, type, exportedData]) => {
if (this.destroyed) {
return;
return null;
}
if (this.commonObjs.has(id)) {
return;
return null;
}
switch (type) {
case "Font":
Expand Down Expand Up @@ -4089,6 +4089,24 @@ class WorkerTransport {
this.commonObjs.resolve(id, font);
});
break;
case "CopyLocalImage":
const {
imageRef
} = exportedData;
(0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(imageRef, "The imageRef must be defined.");
for (const pageProxy of this.#pageCache.values()) {
for (const [, data] of pageProxy.objs) {
if (data.ref !== imageRef) {
continue;
}
if (!data.dataLen) {
return null;
}
this.commonObjs.resolve(id, structuredClone(data));
return data.dataLen;
}
}
break;
case "FontPath":
case "Image":
case "Pattern":
Expand All @@ -4097,6 +4115,7 @@ class WorkerTransport {
default:
throw new Error(`Got unknown common object type ${type}`);
}
return null;
});
messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
if (this.destroyed) {
Expand All @@ -4113,20 +4132,8 @@ class WorkerTransport {
switch (type) {
case "Image":
pageProxy.objs.resolve(id, imageData);
if (imageData) {
let length;
if (imageData.bitmap) {
const {
width,
height
} = imageData;
length = width * height * 4;
} else {
length = imageData.data?.length || 0;
}
if (length > _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MAX_IMAGE_SIZE_TO_CACHE) {
pageProxy._maybeCleanupAfterRender = true;
}
if (imageData?.dataLen > _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MAX_IMAGE_SIZE_TO_CACHE) {
pageProxy._maybeCleanupAfterRender = true;
}
break;
case "Pattern":
Expand Down Expand Up @@ -4354,7 +4361,7 @@ class PDFObjects {
}
has(objId) {
const obj = this.#objs[objId];
return obj?.capability.settled || false;
return obj?.capability.settled ?? false;
}
resolve(objId, data = null) {
const obj = this.#ensureObj(objId);
Expand All @@ -4370,6 +4377,18 @@ class PDFObjects {
}
this.#objs = Object.create(null);
}
*[Symbol.iterator]() {
for (const objId in this.#objs) {
const {
capability,
data
} = this.#objs[objId];
if (!capability.settled) {
continue;
}
yield [objId, data];
}
}
}
class RenderTask {
#internalRenderTask = null;
Expand Down Expand Up @@ -4531,7 +4550,7 @@ class InternalRenderTask {
}
}
const version = '4.0.0';
const build = '91188cf';
const build = '3b94e9f';

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down Expand Up @@ -13064,7 +13083,7 @@ class AnnotationEditorUIManager {
this.#activeEditor = null;
this.#selectedEditors.clear();
this.#commandManager.destroy();
this.#altTextManager.destroy();
this.#altTextManager?.destroy();
if (this.#focusMainContainerTimeoutId) {
clearTimeout(this.#focusMainContainerTimeoutId);
this.#focusMainContainerTimeoutId = null;
Expand Down Expand Up @@ -16628,7 +16647,7 @@ _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.t


const pdfjsVersion = '4.0.0';
const pdfjsBuild = '91188cf';
const pdfjsBuild = '3b94e9f';

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down
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.

32 changes: 25 additions & 7 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31435,6 +31435,7 @@ class PartialEvaluator {
}
const objId = `mask_${this.idFactory.createObjId()}`;
operatorList.addDependency(objId);
imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
this._sendImgData(objId, imgData);
args = [{
data: objId,
Expand Down Expand Up @@ -31476,14 +31477,32 @@ class PartialEvaluator {
cacheGlobally = false;
if (this.parsingType3Font) {
objId = `${this.idFactory.getDocId()}_type3_${objId}`;
} else if (imageRef) {
} else if (cacheKey && imageRef) {
cacheGlobally = this.globalImageCache.shouldCache(imageRef, this.pageIndex);
if (cacheGlobally) {
assert(!isInline, "Cannot cache an inline image globally.");
objId = `${this.idFactory.getDocId()}_${objId}`;
}
}
operatorList.addDependency(objId);
args = [objId, w, h];
operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
if (cacheGlobally && w * h > 250000) {
const localLength = await this.handler.sendWithPromise("commonobj", [objId, "CopyLocalImage", {
imageRef
}]);
if (localLength) {
this.globalImageCache.setData(imageRef, {
objId,
fn: OPS.paintImageXObject,
args,
optionalContent,
byteSize: 0
});
this.globalImageCache.addByteSize(imageRef, localLength);
return;
}
}
PDFImage.buildImage({
xref: this.xref,
res: resources,
Expand All @@ -31493,16 +31512,16 @@ class PartialEvaluator {
localColorSpaceCache
}).then(async imageObj => {
imgData = await imageObj.createImageData(false, this.options.isOffscreenCanvasSupported);
if (cacheKey && imageRef && cacheGlobally) {
const length = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
this.globalImageCache.addByteSize(imageRef, length);
imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
imgData.ref = imageRef;
if (cacheGlobally) {
this.globalImageCache.addByteSize(imageRef, imgData.dataLen);
}
return this._sendImgData(objId, imgData, cacheGlobally);
}).catch(reason => {
warn(`Unable to decode image "${objId}": "${reason}".`);
return this._sendImgData(objId, null, cacheGlobally);
});
operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
if (cacheKey) {
const cacheData = {
fn: OPS.paintImageXObject,
Expand All @@ -31513,7 +31532,6 @@ class PartialEvaluator {
if (imageRef) {
this._regionalImageCache.set(null, imageRef, cacheData);
if (cacheGlobally) {
assert(!isInline, "Cannot cache an inline image globally.");
this.globalImageCache.setData(imageRef, {
objId,
fn: OPS.paintImageXObject,
Expand Down Expand Up @@ -57145,7 +57163,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = '4.0.0';
const pdfjsBuild = '91188cf';
const pdfjsBuild = '3b94e9f';

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.

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

pdfjs-editor-remove-ink-button =
.title = Выдаліць малюнак
pdfjs-editor-remove-freetext-button =
.title = Выдаліць тэкст
pdfjs-editor-remove-stamp-button =
.title = Выдаліць выяву
pdfjs-editor-remove-highlight-button =
.title = Выдаліць падфарбоўку
##

# Editor Parameters
pdfjs-editor-free-text-color-input = Колер
pdfjs-editor-free-text-size-input = Памер
Expand Down Expand Up @@ -349,3 +365,22 @@ pdfjs-editor-resizer-label-bottom-right = Правы ніжні кут — зм
pdfjs-editor-resizer-label-bottom-middle = Пасярэдзіне ўнізе — змяніць памер
pdfjs-editor-resizer-label-bottom-left = Левы ніжні кут — змяніць памер
pdfjs-editor-resizer-label-middle-left = Пасярэдзіне злева — змяніць памер
## Color picker

# This means "Color used to highlight text"
pdfjs-editor-highlight-colorpicker-label = Колер падфарбоўкі
pdfjs-editor-colorpicker-button =
.title = Змяніць колер
pdfjs-editor-colorpicker-dropdown =
.aria-label = Выбар колеру
pdfjs-editor-colorpicker-yellow =
.title = Жоўты
pdfjs-editor-colorpicker-green =
.title = Зялёны
pdfjs-editor-colorpicker-blue =
.title = Блакітны
pdfjs-editor-colorpicker-pink =
.title = Ружовы
pdfjs-editor-colorpicker-red =
.title = Чырвоны
30 changes: 30 additions & 0 deletions web/locale/br/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ pdfjs-open-file-button-label = Digeriñ ur restr
pdfjs-print-button =
.title = Moullañ
pdfjs-print-button-label = Moullañ
pdfjs-save-button =
.title = Enrollañ
pdfjs-save-button-label = Enrollañ
# Used in Firefox for Android as a tooltip for the download button (“download” is a verb).
pdfjs-download-button =
.title = Pellgargañ
# 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 = Pellgargañ
## Secondary toolbar and context menu

Expand Down Expand Up @@ -252,10 +261,31 @@ pdfjs-web-fonts-disabled = Diweredekaet eo an nodrezhoù web: n'haller ket arver
## Editing

pdfjs-editor-free-text-button =
.title = Testenn
pdfjs-editor-free-text-button-label = Testenn
pdfjs-editor-ink-button =
.title = Tresañ
pdfjs-editor-ink-button-label = Tresañ
## Remove button for the various kind of editor.


##

# Editor Parameters
pdfjs-editor-free-text-color-input = Liv
pdfjs-editor-free-text-size-input = Ment
pdfjs-editor-ink-color-input = Liv
## Alt-text dialog

pdfjs-editor-alt-text-cancel-button = Nullañ
pdfjs-editor-alt-text-save-button = Enrollañ
## Editor resizers
## This is used in an aria label to help to understand the role of the resizer.


## Color picker

35 changes: 35 additions & 0 deletions web/locale/cs/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ 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
## Remove button for the various kind of editor.

pdfjs-editor-remove-ink-button =
.title = Odebrat kresbu
pdfjs-editor-remove-freetext-button =
.title = Odebrat text
pdfjs-editor-remove-stamp-button =
.title = Odebrat obrázek
pdfjs-editor-remove-highlight-button =
.title = Odebrat zvýraznění
##

# Editor Parameters
pdfjs-editor-free-text-color-input = Barva
pdfjs-editor-free-text-size-input = Velikost
Expand Down Expand Up @@ -351,3 +367,22 @@ pdfjs-editor-resizer-label-bottom-right = Pravý dolní roh — změna velikosti
pdfjs-editor-resizer-label-bottom-middle = Střed dole — změna velikosti
pdfjs-editor-resizer-label-bottom-left = Levý dolní roh — změna velikosti
pdfjs-editor-resizer-label-middle-left = Vlevo uprostřed — změna velikosti
## Color picker

# This means "Color used to highlight text"
pdfjs-editor-highlight-colorpicker-label = Barva zvýraznění
pdfjs-editor-colorpicker-button =
.title = Změna barvy
pdfjs-editor-colorpicker-dropdown =
.aria-label = Výběr barev
pdfjs-editor-colorpicker-yellow =
.title = Žlutá
pdfjs-editor-colorpicker-green =
.title = Zelená
pdfjs-editor-colorpicker-blue =
.title = Modrá
pdfjs-editor-colorpicker-pink =
.title = Růžová
pdfjs-editor-colorpicker-red =
.title = Červená
33 changes: 33 additions & 0 deletions web/locale/cy/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ pdfjs-editor-stamp-button =
pdfjs-editor-stamp-button-label = Ychwanegu neu olygu delweddau
pdfjs-editor-remove-button =
.title = Tynnu
## Remove button for the various kind of editor.

pdfjs-editor-remove-ink-button =
.title = Dileu lluniad
pdfjs-editor-remove-freetext-button =
.title = Dileu testun
pdfjs-editor-remove-stamp-button =
.title = Dileu delwedd
pdfjs-editor-remove-highlight-button =
.title = Tynnu amlygiad
##

# Editor Parameters
pdfjs-editor-free-text-color-input = Lliw
pdfjs-editor-free-text-size-input = Maint
Expand Down Expand Up @@ -357,3 +371,22 @@ pdfjs-editor-resizer-label-bottom-right = Y gornel dde isaf — newid maint
pdfjs-editor-resizer-label-bottom-middle = Canol gwaelod — newid maint
pdfjs-editor-resizer-label-bottom-left = Y gornel chwith isaf — newid maint
pdfjs-editor-resizer-label-middle-left = Chwith canol — newid maint
## Color picker

# This means "Color used to highlight text"
pdfjs-editor-highlight-colorpicker-label = Lliw amlygu
pdfjs-editor-colorpicker-button =
.title = Newid lliw
pdfjs-editor-colorpicker-dropdown =
.aria-label = Dewisiadau lliw
pdfjs-editor-colorpicker-yellow =
.title = Melyn
pdfjs-editor-colorpicker-green =
.title = Gwyrdd
pdfjs-editor-colorpicker-blue =
.title = Glas
pdfjs-editor-colorpicker-pink =
.title = Pinc
pdfjs-editor-colorpicker-red =
.title = Coch
Loading

0 comments on commit 8c246b0

Please sign in to comment.