Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 7, 2024
1 parent 434e9fe commit 70f922d
Show file tree
Hide file tree
Showing 9 changed files with 332 additions and 166 deletions.
186 changes: 101 additions & 85 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.

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

Large diffs are not rendered by default.

90 changes: 72 additions & 18 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2023 Mozilla Foundation
* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,6 +65,7 @@ const RenderingIntentFlag = {
ANNOTATIONS_FORMS: 0x10,
ANNOTATIONS_STORAGE: 0x20,
ANNOTATIONS_DISABLE: 0x40,
IS_EDITING: 0x80,
OPLIST: 0x100
};
const AnnotationMode = {
Expand Down Expand Up @@ -16267,6 +16268,7 @@ function clearUnicodeCaches() {




const SEAC_ANALYSIS_ENABLED = true;
const FontFlags = {
FixedPitch: 1,
Expand Down Expand Up @@ -16345,6 +16347,41 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
function normalizeFontName(name) {
return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, "");
}
const getVerticalPresentationForm = getLookupTableFactory(t => {
t[0x2013] = 0xfe32;
t[0x2014] = 0xfe31;
t[0x2025] = 0xfe30;
t[0x2026] = 0xfe19;
t[0x3001] = 0xfe11;
t[0x3002] = 0xfe12;
t[0x3008] = 0xfe3f;
t[0x3009] = 0xfe40;
t[0x300a] = 0xfe3d;
t[0x300b] = 0xfe3e;
t[0x300c] = 0xfe41;
t[0x300d] = 0xfe42;
t[0x300e] = 0xfe43;
t[0x300f] = 0xfe44;
t[0x3010] = 0xfe3b;
t[0x3011] = 0xfe3c;
t[0x3014] = 0xfe39;
t[0x3015] = 0xfe3a;
t[0x3016] = 0xfe17;
t[0x3017] = 0xfe18;
t[0xfe4f] = 0xfe34;
t[0xff01] = 0xfe15;
t[0xff08] = 0xfe35;
t[0xff09] = 0xfe36;
t[0xff0c] = 0xfe10;
t[0xff1a] = 0xfe13;
t[0xff1b] = 0xfe14;
t[0xff1f] = 0xfe16;
t[0xff3b] = 0xfe47;
t[0xff3d] = 0xfe48;
t[0xff3f] = 0xfe33;
t[0xff5b] = 0xfe37;
t[0xff5d] = 0xfe38;
});

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

Expand Down Expand Up @@ -24954,6 +24991,12 @@ class Font {
warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
}
}
if (this.missingFile && this.vertical && fontChar.length === 1) {
const vertical = getVerticalPresentationForm()[fontChar.charCodeAt(0)];
if (vertical) {
fontChar = unicode = String.fromCharCode(vertical);
}
}
glyph = new fonts_Glyph(charcode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
return this._glyphCache[charcode] = glyph;
}
Expand Down Expand Up @@ -32440,6 +32483,9 @@ class PartialEvaluator {
map[charCode] = String.fromCodePoint(token);
return;
}
if (token.length % 2 !== 0) {
token = "\u0000" + token;
}
const str = [];
for (let k = 0; k < token.length; k += 2) {
const w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
Expand Down Expand Up @@ -49892,7 +49938,8 @@ class Annotation {
subtype: params.subtype,
hasOwnCanvas: false,
noRotate: !!(this.flags & AnnotationFlag.NOROTATE),
noHTML: isLocked && isContentLocked
noHTML: isLocked && isContentLocked,
isEditable: false
};
if (params.collectFields) {
const kids = dict.get("Kids");
Expand Down Expand Up @@ -49938,6 +49985,9 @@ class Annotation {
}
return this.printable;
}
mustBeViewedWhenEditing(isEditing, modifiedIds = null) {
return isEditing ? !this.data.isEditable : !modifiedIds?.has(this.data.id);
}
get viewable() {
if (this.data.quadPoints === null) {
return false;
Expand Down Expand Up @@ -50119,7 +50169,7 @@ class Annotation {
});
});
}
async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
async getOperatorList(evaluator, task, intent, annotationStorage) {
const {
hasOwnCanvas,
id,
Expand Down Expand Up @@ -50674,20 +50724,20 @@ class WidgetAnnotation extends Annotation {
}
return str;
}
async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
if (renderForms && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) {
async getOperatorList(evaluator, task, intent, annotationStorage) {
if (intent & RenderingIntentFlag.ANNOTATIONS_FORMS && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) {
return {
opList: new OperatorList(),
separateForm: true,
separateCanvas: false
};
}
if (!this._hasText) {
return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
return super.getOperatorList(evaluator, task, intent, annotationStorage);
}
const content = await this._getAppearance(evaluator, task, intent, annotationStorage);
if (this.appearance && content === null) {
return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
return super.getOperatorList(evaluator, task, intent, annotationStorage);
}
const opList = new OperatorList();
if (!this._defaultAppearance || content === null) {
Expand Down Expand Up @@ -51253,7 +51303,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
warn("Invalid field flags for button widget annotation");
}
}
async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
async getOperatorList(evaluator, task, intent, annotationStorage) {
if (this.data.pushButton) {
return super.getOperatorList(evaluator, task, intent, false, annotationStorage);
}
Expand All @@ -51265,7 +51315,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
rotation = storageEntry ? storageEntry.rotation : null;
}
if (value === null && this.appearance) {
return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
return super.getOperatorList(evaluator, task, intent, annotationStorage);
}
if (value === null || value === undefined) {
value = this.data.checkBox ? this.data.fieldValue === this.data.exportValue : this.data.fieldValue === this.data.buttonValue;
Expand All @@ -51278,7 +51328,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
appearance.dict.set("Matrix", this.getRotationMatrix(annotationStorage));
}
this.appearance = appearance;
const operatorList = super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
const operatorList = super.getOperatorList(evaluator, task, intent, annotationStorage);
this.appearance = savedAppearance;
appearance.dict.set("Matrix", savedMatrix);
return operatorList;
Expand Down Expand Up @@ -51895,7 +51945,8 @@ class PopupAnnotation extends Annotation {
class FreeTextAnnotation extends MarkupAnnotation {
constructor(params) {
super(params);
this.data.hasOwnCanvas = !this.data.noHTML;
this.data.hasOwnCanvas = this.data.noRotate;
this.data.isEditable = !this.data.noHTML;
this.data.noHTML = false;
const {
evaluatorOptions,
Expand Down Expand Up @@ -53887,7 +53938,8 @@ class Page {
task,
intent,
cacheKey,
annotationStorage = null
annotationStorage = null,
modifiedIds = null
}) {
const contentStreamPromise = this.getContentStream();
const resourcesPromise = this.loadResources(["ColorSpace", "ExtGState", "Font", "Pattern", "Properties", "Shading", "XObject"]);
Expand Down Expand Up @@ -53984,13 +54036,14 @@ class Page {
};
}
const renderForms = !!(intent & RenderingIntentFlag.ANNOTATIONS_FORMS),
isEditing = !!(intent & RenderingIntentFlag.IS_EDITING),
intentAny = !!(intent & RenderingIntentFlag.ANY),
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
const opListPromises = [];
for (const annotation of annotations) {
if (intentAny || intentDisplay && annotation.mustBeViewed(annotationStorage, renderForms) || intentPrint && annotation.mustBePrinted(annotationStorage)) {
opListPromises.push(annotation.getOperatorList(partialEvaluator, task, intent, renderForms, annotationStorage).catch(function (reason) {
if (intentAny || intentDisplay && annotation.mustBeViewed(annotationStorage, renderForms) && annotation.mustBeViewedWhenEditing(isEditing, modifiedIds) || intentPrint && annotation.mustBePrinted(annotationStorage)) {
opListPromises.push(annotation.getOperatorList(partialEvaluator, task, intent, annotationStorage).catch(function (reason) {
warn("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
return {
opList: null,
Expand Down Expand Up @@ -55710,7 +55763,7 @@ class WorkerMessageHandler {
docId,
apiVersion
} = docParams;
const workerVersion = "4.4.0";
const workerVersion = "4.5.0";
if (apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
}
Expand Down Expand Up @@ -56178,7 +56231,8 @@ class WorkerMessageHandler {
task,
intent: data.intent,
cacheKey: data.cacheKey,
annotationStorage: data.annotationStorage
annotationStorage: data.annotationStorage,
modifiedIds: data.modifiedIds
}).then(function (operatorListInfo) {
finishWorkerTask(task);
if (start) {
Expand Down Expand Up @@ -56280,8 +56334,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&

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

const pdfjsVersion = "4.4.0";
const pdfjsBuild = "fb3a4e4";
const pdfjsVersion = "4.5.0";
const pdfjsBuild = "5ee6169";

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.

42 changes: 17 additions & 25 deletions web/locale/zh-TW/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ pdfjs-download-button-label = 下載
pdfjs-bookmark-button =
.title = 目前頁面(含目前檢視頁面的網址)
pdfjs-bookmark-button-label = 目前頁面
# Used in Firefox for Android.
pdfjs-open-in-app-button =
.title = 在應用程式中開啟
# 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 = 用程式開啟
## Secondary toolbar and context menu

Expand All @@ -82,8 +76,8 @@ pdfjs-cursor-hand-tool-button =
.title = 開啟頁面移動工具
pdfjs-cursor-hand-tool-button-label = 頁面移動工具
pdfjs-scroll-page-button =
.title = 使用頁面捲動功能
pdfjs-scroll-page-button-label = 頁面捲動功能
.title = 使用單頁捲動版面
pdfjs-scroll-page-button-label = 單頁捲動
pdfjs-scroll-vertical-button =
.title = 使用垂直捲動版面
pdfjs-scroll-vertical-button-label = 垂直捲動
Expand All @@ -108,8 +102,8 @@ pdfjs-spread-even-button-label = 偶數跨頁
pdfjs-document-properties-button =
.title = 文件內容…
pdfjs-document-properties-button-label = 文件內容…
pdfjs-document-properties-file-name = 檔案名稱:
pdfjs-document-properties-file-size = 檔案大小:
pdfjs-document-properties-file-name = 檔案名稱
pdfjs-document-properties-file-size = 檔案大小
# Variables:
# $size_kb (Number) - the PDF file size in kilobytes
# $size_b (Number) - the PDF file size in bytes
Expand All @@ -118,21 +112,21 @@ pdfjs-document-properties-kb = { $size_kb } KB({ $size_b } 位元組)
# $size_mb (Number) - the PDF file size in megabytes
# $size_b (Number) - the PDF file size in bytes
pdfjs-document-properties-mb = { $size_mb } MB({ $size_b } 位元組)
pdfjs-document-properties-title = 標題:
pdfjs-document-properties-author = 作者:
pdfjs-document-properties-subject = 主旨:
pdfjs-document-properties-keywords = 關鍵字:
pdfjs-document-properties-creation-date = 建立日期:
pdfjs-document-properties-modification-date = 修改日期:
pdfjs-document-properties-title = 標題
pdfjs-document-properties-author = 作者
pdfjs-document-properties-subject = 主旨
pdfjs-document-properties-keywords = 關鍵字
pdfjs-document-properties-creation-date = 建立日期
pdfjs-document-properties-modification-date = 修改日期
# Variables:
# $date (Date) - the creation/modification date of the PDF file
# $time (Time) - the creation/modification time of the PDF file
pdfjs-document-properties-date-string = { $date } { $time }
pdfjs-document-properties-creator = 建立者:
pdfjs-document-properties-producer = PDF 產生器:
pdfjs-document-properties-version = PDF 版本:
pdfjs-document-properties-page-count = 頁數:
pdfjs-document-properties-page-size = 頁面大小:
pdfjs-document-properties-creator = 建立者
pdfjs-document-properties-producer = PDF 產生器
pdfjs-document-properties-version = PDF 版本
pdfjs-document-properties-page-count = 頁數
pdfjs-document-properties-page-size = 頁面大小
pdfjs-document-properties-page-size-unit-inches = in
pdfjs-document-properties-page-size-unit-millimeters = mm
pdfjs-document-properties-page-size-orientation-portrait = 垂直
Expand All @@ -156,7 +150,7 @@ pdfjs-document-properties-page-size-dimension-name-string = { $width } × { $hei

# The linearization status of the document; usually called "Fast Web View" in
# English locales of Adobe software.
pdfjs-document-properties-linearized = 快速 Web 檢視:
pdfjs-document-properties-linearized = 快速 Web 檢視
pdfjs-document-properties-linearized-yes =
pdfjs-document-properties-linearized-no =
pdfjs-document-properties-close-button = 關閉
Expand Down Expand Up @@ -296,8 +290,6 @@ pdfjs-editor-stamp-button-label = 新增或編輯圖片
pdfjs-editor-highlight-button =
.title = 強調
pdfjs-editor-highlight-button-label = 強調
pdfjs-highlight-floating-button =
.title = 強調
pdfjs-highlight-floating-button1 =
.title = 強調
.aria-label = 強調
Expand Down Expand Up @@ -331,7 +323,7 @@ pdfjs-editor-free-highlight-thickness-title =
.title = 更改強調文字以外的項目時的線條粗細
pdfjs-free-text =
.aria-label = 文本編輯器
pdfjs-free-text-default-content = 開始打字
pdfjs-free-text-default-content = 在此打字
pdfjs-ink =
.aria-label = 圖形編輯器
pdfjs-ink-canvas =
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
<button id="editorInk" class="toolbarButton" disabled="disabled" title="Draw" role="radio" aria-checked="false" aria-controls="editorInkParamsToolbar" tabindex="33" data-l10n-id="pdfjs-editor-ink-button">
<span data-l10n-id="pdfjs-editor-ink-button-label">Draw</span>
</button>
<button id="editorStamp" class="toolbarButton hidden" disabled="disabled" title="Add or edit images" role="radio" aria-checked="false" aria-controls="editorStampParamsToolbar" tabindex="34" data-l10n-id="pdfjs-editor-stamp-button">
<button id="editorStamp" class="toolbarButton" disabled="disabled" title="Add or edit images" role="radio" aria-checked="false" aria-controls="editorStampParamsToolbar" tabindex="34" data-l10n-id="pdfjs-editor-stamp-button">
<span data-l10n-id="pdfjs-editor-stamp-button-label">Add or edit images</span>
</button>
</div>
Expand Down
Loading

0 comments on commit 70f922d

Please sign in to comment.