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 7, 2024
1 parent c94dc70 commit d6f6f13
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 123 deletions.
159 changes: 86 additions & 73 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.

82 changes: 58 additions & 24 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32540,7 +32540,8 @@ class PartialEvaluator {
seenStyles = new Set(),
viewBox,
markedContentData = null,
disableNormalization = false
disableNormalization = false,
keepWhiteSpace = false
}) {
resources ||= Dict.empty;
stateManager ||= new StateManager(new TextState());
Expand Down Expand Up @@ -32579,10 +32580,10 @@ class PartialEvaluator {
const ret = twoLastChars[twoLastCharsPos] !== " " && twoLastChars[nextPos] === " ";
twoLastChars[twoLastCharsPos] = char;
twoLastCharsPos = nextPos;
return ret;
return !keepWhiteSpace && ret;
}
function shouldAddWhitepsace() {
return twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
return !keepWhiteSpace && twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
}
function resetLastChars() {
twoLastChars[0] = twoLastChars[1] = " ";
Expand Down Expand Up @@ -32894,7 +32895,7 @@ class PartialEvaluator {
glyphWidth = glyph.vmetric ? glyph.vmetric[0] : -glyphWidth;
}
let scaledDim = glyphWidth * scale;
if (category.isWhitespace) {
if (!keepWhiteSpace && category.isWhitespace) {
if (!font.vertical) {
charSpacing += scaledDim + textState.wordSpacing;
textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
Expand Down Expand Up @@ -33216,7 +33217,8 @@ class PartialEvaluator {
seenStyles,
viewBox,
markedContentData,
disableNormalization
disableNormalization,
keepWhiteSpace
}).then(function () {
if (!sinkWrapper.enqueueInvoked) {
emptyXObjectCache.set(name, xobj.dict.objId, true);
Expand Down Expand Up @@ -35132,6 +35134,21 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
}
return this.resources;
}
static getFirstPositionInfo(rect, rotation, fontSize) {
const [x1, y1, x2, y2] = rect;
let w = x2 - x1;
let h = y2 - y1;
if (rotation % 180 !== 0) {
[w, h] = [h, w];
}
const lineHeight = LINE_FACTOR * fontSize;
const lineDescent = LINE_DESCENT_FACTOR * fontSize;
return {
coords: [0, h + lineDescent - lineHeight],
bbox: [0, 0, w, h],
matrix: rotation !== 0 ? getRotationMatrix(rotation, h, lineHeight) : undefined
};
}
createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) {
const ctx = this._createContext();
const lines = [];
Expand Down Expand Up @@ -51174,6 +51191,7 @@ class Annotation {
task,
resources,
includeMarkedContent: true,
keepWhiteSpace: true,
sink,
viewBox
});
Expand All @@ -51183,18 +51201,22 @@ class Annotation {
}
if (text.length > 1 || text[0]) {
const appearanceDict = this.appearance.dict;
const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
const rect = this.data.rect;
const transform = getTransformMatrix(rect, bbox, matrix);
transform[4] -= rect[0];
transform[5] -= rect[1];
firstPosition = Util.applyTransform(firstPosition, transform);
firstPosition = Util.applyTransform(firstPosition, matrix);
this.data.textPosition = firstPosition;
this.data.textPosition = this._transformPoint(firstPosition, appearanceDict.getArray("BBox"), appearanceDict.getArray("Matrix"));
this.data.textContent = text;
}
}
_transformPoint(coords, bbox, matrix) {
const {
rect
} = this.data;
bbox ||= [0, 0, 1, 1];
matrix ||= [1, 0, 0, 1, 0, 0];
const transform = getTransformMatrix(rect, bbox, matrix);
transform[4] -= rect[0];
transform[5] -= rect[1];
coords = Util.applyTransform(coords, transform);
return Util.applyTransform(coords, matrix);
}
getFieldObject() {
if (this.data.kidIds) {
return {
Expand Down Expand Up @@ -52863,29 +52885,41 @@ class FreeTextAnnotation extends MarkupAnnotation {
} = params;
this.data.annotationType = AnnotationType.FREETEXT;
this.setDefaultAppearance(params);
if (this.appearance) {
this._hasAppearance = !!this.appearance;
if (this._hasAppearance) {
const {
fontColor,
fontSize
} = parseAppearanceStream(this.appearance, evaluatorOptions, xref);
this.data.defaultAppearanceData.fontColor = fontColor;
this.data.defaultAppearanceData.fontSize = fontSize || 10;
} else if (this._isOffscreenCanvasSupported) {
const strokeAlpha = params.dict.get("CA");
const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
} else {
this.data.defaultAppearanceData.fontSize ||= 10;
const {
fontColor,
fontSize
} = this.data.defaultAppearanceData;
this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
} else {
warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
if (this._contents.str) {
this.data.textContent = this._contents.str.split(/\r\n?|\n/);
const {
coords,
bbox,
matrix
} = FakeUnicodeFont.getFirstPositionInfo(this.rectangle, this.rotation, fontSize);
this.data.textPosition = this._transformPoint(coords, bbox, matrix);
}
if (this._isOffscreenCanvasSupported) {
const strokeAlpha = params.dict.get("CA");
const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
} else {
warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
}
}
}
get hasTextContent() {
return !!this.appearance;
return this._hasAppearance;
}
static createNewDict(annotation, xref, {
apRef,
Expand Down Expand Up @@ -57163,7 +57197,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = '4.0.0';
const pdfjsBuild = '9e14d04';
const pdfjsBuild = '29faa38';

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.

137 changes: 137 additions & 0 deletions web/locale/bg/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ pdfjs-open-file-button-label = Отваряне
pdfjs-print-button =
.title = Отпечатване
pdfjs-print-button-label = Отпечатване
pdfjs-save-button =
.title = Запазване
pdfjs-save-button-label = Запазване
# Used in Firefox for Android as a tooltip for the download button (“download” is a verb).
pdfjs-download-button =
.title = Изтегляне
# 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 = Изтегляне
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 @@ -63,6 +81,9 @@ pdfjs-cursor-text-select-tool-button-label = Инструмент за избо
pdfjs-cursor-hand-tool-button =
.title = Включване на инструмента ръка
pdfjs-cursor-hand-tool-button-label = Инструмент ръка
pdfjs-scroll-page-button =
.title = Използване на плъзгане на страници
pdfjs-scroll-page-button-label = Плъзгане на страници
pdfjs-scroll-vertical-button =
.title = Използване на вертикално плъзгане
pdfjs-scroll-vertical-button-label = Вертикално плъзгане
Expand Down Expand Up @@ -154,19 +175,28 @@ pdfjs-printing-not-ready = Внимание: Този PDF файл не е на

pdfjs-toggle-sidebar-button =
.title = Превключване на страничната лента
pdfjs-toggle-sidebar-notification-button =
.title = Превключване на страничната лента (документът има структура/прикачени файлове/слоеве)
pdfjs-toggle-sidebar-button-label = Превключване на страничната лента
pdfjs-document-outline-button =
.title = Показване на структурата на документа (двукратно щракване за свиване/разгъване на всичко)
pdfjs-document-outline-button-label = Структура на документа
pdfjs-attachments-button =
.title = Показване на притурките
pdfjs-attachments-button-label = Притурки
pdfjs-layers-button =
.title = Показване на слоевете (двукратно щракване за възстановяване на всички слоеве към състоянието по подразбиране)
pdfjs-layers-button-label = Слоеве
pdfjs-thumbs-button =
.title = Показване на миниатюрите
pdfjs-thumbs-button-label = Миниатюри
pdfjs-current-outline-item-button =
.title = Намиране на текущия елемент от структурата
pdfjs-current-outline-item-button-label = Текущ елемент от структурата
pdfjs-findbar-button =
.title = Намиране в документа
pdfjs-findbar-button-label = Търсене
pdfjs-additional-layers = Допълнителни слоеве
## Thumbnails panel item (tooltip and alt text for images)

Expand All @@ -192,9 +222,25 @@ pdfjs-find-next-button =
pdfjs-find-next-button-label = Следваща
pdfjs-find-highlight-checkbox = Открояване на всички
pdfjs-find-match-case-checkbox-label = Съвпадение на регистъра
pdfjs-find-match-diacritics-checkbox-label = Без производни букви
pdfjs-find-entire-word-checkbox-label = Цели думи
pdfjs-find-reached-top = Достигнато е началото на документа, продължаване от края
pdfjs-find-reached-bottom = Достигнат е краят на документа, продължаване от началото
# Variables:
# $current (Number) - the index of the currently active find result
# $total (Number) - the total number of matches in the document
pdfjs-find-match-count =
{ $total ->
[one] { $current } от { $total } съвпадение
*[other] { $current } от { $total } съвпадения
}
# Variables:
# $limit (Number) - the maximum number of matches
pdfjs-find-match-count-limit =
{ $limit ->
[one] Повече от { $limit } съвпадение
*[other] Повече от { $limit } съвпадения
}
pdfjs-find-not-found = Фразата не е намерена
## Predefined zoom values
Expand All @@ -209,6 +255,10 @@ pdfjs-page-scale-percent = { $scale }%
## PDF page

# Variables:
# $page (Number) - the page number
pdfjs-page-landmark =
.aria-label = Страница { $page }
## Loading indicator messages

Expand All @@ -220,6 +270,10 @@ pdfjs-rendering-error = Грешка при изчертаване на стра
## Annotations

# Variables:
# $date (Date) - the modification date of the annotation
# $time (Time) - the modification time of the annotation
pdfjs-annotation-date-string = { $date }, { $time }
# .alt: This is used as a tooltip.
# Variables:
# $type (String) - an annotation type from a list defined in the PDF spec
Expand All @@ -238,10 +292,93 @@ pdfjs-web-fonts-disabled = Уеб-шрифтовете са забранени:
## Editing

pdfjs-editor-free-text-button =
.title = Текст
pdfjs-editor-free-text-button-label = Текст
pdfjs-editor-ink-button =
.title = Рисуване
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 = Размер
pdfjs-editor-ink-color-input = Цвят
pdfjs-editor-ink-thickness-input = Дебелина
pdfjs-editor-ink-opacity-input = Прозрачност
pdfjs-editor-stamp-add-image-button =
.title = Добавяне на изображение
pdfjs-editor-stamp-add-image-button-label = Добавяне на изображение
pdfjs-free-text =
.aria-label = Текстов редактор
pdfjs-free-text-default-content = Започнете да пишете…
pdfjs-ink =
.aria-label = Промяна на рисунка
pdfjs-ink-canvas =
.aria-label = Изображение, създадено от потребител
## Alt-text dialog

# Alternative text (alt text) helps when people can't see the image.
pdfjs-editor-alt-text-button-label = Алтернативен текст
pdfjs-editor-alt-text-edit-button-label = Промяна на алтернативния текст
pdfjs-editor-alt-text-dialog-label = Изберете от възможностите
pdfjs-editor-alt-text-dialog-description = Алтернативният текст помага на потребителите, когато не могат да видят изображението или то не се зарежда.
pdfjs-editor-alt-text-add-description-label = Добавяне на описание
pdfjs-editor-alt-text-add-description-description = Стремете се към 1-2 изречения, описващи предмета, настройката или действията.
pdfjs-editor-alt-text-mark-decorative-label = Отбелязване като декоративно
pdfjs-editor-alt-text-mark-decorative-description = Използва се за орнаменти или декоративни изображения, като контури и водни знаци.
pdfjs-editor-alt-text-cancel-button = Отказ
pdfjs-editor-alt-text-save-button = Запазване
pdfjs-editor-alt-text-decorative-tooltip = Отбелязване като декоративно
# .placeholder: This is a placeholder for the alt text input area
pdfjs-editor-alt-text-textarea =
.placeholder = Например, „Млад мъж седи на маса и се храни“
## Editor resizers
## This is used in an aria label to help to understand the role of the resizer.

pdfjs-editor-resizer-label-top-left = Горен ляв ъгъл — преоразмеряване
pdfjs-editor-resizer-label-top-middle = Горе в средата — преоразмеряване
pdfjs-editor-resizer-label-top-right = Горен десен ъгъл — преоразмеряване
pdfjs-editor-resizer-label-middle-right = Дясно в средата — преоразмеряване
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 = Червено
12 changes: 12 additions & 0 deletions web/locale/br/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ pdfjs-download-button =
# 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ñ
pdfjs-bookmark-button-label = Pajenn a-vremañ
# Used in Firefox for Android.
pdfjs-open-in-app-button =
.title = Digeriñ en arload
# 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 = Digeriñ en arload
## Secondary toolbar and context menu

Expand Down Expand Up @@ -277,6 +284,11 @@ pdfjs-editor-ink-button-label = Tresañ
pdfjs-editor-free-text-color-input = Liv
pdfjs-editor-free-text-size-input = Ment
pdfjs-editor-ink-color-input = Liv
pdfjs-editor-ink-thickness-input = Tevder
pdfjs-editor-ink-opacity-input = Boullder
pdfjs-editor-stamp-add-image-button =
.title = Ouzhpennañ ur skeudenn
pdfjs-editor-stamp-add-image-button-label = Ouzhpennañ ur skeudenn
## Alt-text dialog

Expand Down
Loading

0 comments on commit d6f6f13

Please sign in to comment.