Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 30, 2024
1 parent fb399ef commit 434e9fe
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
36 changes: 30 additions & 6 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10366,6 +10366,7 @@ class TextLayer {
#transform = null;
static #ascentCache = new Map();
static #canvasContexts = new Map();
static #minFontSize = null;
static #pendingTextLayers = new Set();
constructor({
textContentSource,
Expand Down Expand Up @@ -10403,6 +10404,7 @@ class TextLayer {
this.#transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
this.#pageWidth = pageWidth;
this.#pageHeight = pageHeight;
TextLayer.#ensureMinFontSizeComputed();
setLayerDimensions(container, viewport);
this.#capability.promise.catch(() => {}).then(() => {
TextLayer.#pendingTextLayers.delete(this);
Expand Down Expand Up @@ -10477,7 +10479,7 @@ class TextLayer {
if (this.#disableProcessItems) {
return;
}
this.#layoutTextParams.ctx ||= TextLayer.#getCtx(this.#lang);
this.#layoutTextParams.ctx ??= TextLayer.#getCtx(this.#lang);
const textDivs = this.#textDivs,
textContentItemsStr = this.#textContentItemsStr;
for (const item of items) {
Expand Down Expand Up @@ -10540,7 +10542,7 @@ class TextLayer {
divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
}
divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
divStyle.fontSize = `${scaleFactorStr}${(TextLayer.#minFontSize * fontHeight).toFixed(2)}px)`;
divStyle.fontFamily = fontFamily;
textDivProperties.fontSize = fontHeight;
textDiv.setAttribute("role", "presentation");
Expand Down Expand Up @@ -10590,6 +10592,9 @@ class TextLayer {
style
} = div;
let transform = "";
if (TextLayer.#minFontSize > 1) {
transform = `scale(${1 / TextLayer.#minFontSize})`;
}
if (properties.canvasWidth !== 0 && properties.hasText) {
const {
fontFamily
Expand All @@ -10607,7 +10612,7 @@ class TextLayer {
width
} = ctx.measureText(div.textContent);
if (width > 0) {
transform = `scaleX(${canvasWidth * this.#scale / width})`;
transform = `scaleX(${canvasWidth * this.#scale / width}) ${transform}`;
}
}
if (properties.angle !== 0) {
Expand Down Expand Up @@ -10644,6 +10649,19 @@ class TextLayer {
}
return canvasContext;
}
static #ensureMinFontSizeComputed() {
if (this.#minFontSize !== null) {
return;
}
const div = document.createElement("div");
div.style.opacity = 0;
div.style.lineHeight = 1;
div.style.fontSize = "1px";
div.textContent = "X";
document.body.append(div);
this.#minFontSize = div.getBoundingClientRect().height;
div.remove();
}
static #getAscent(fontFamily, lang) {
const cachedAscent = this.#ascentCache.get(fontFamily);
if (cachedAscent) {
Expand Down Expand Up @@ -12500,6 +12518,7 @@ class RenderTask {
}
}
class InternalRenderTask {
#rAF = null;
static #canvasInUse = new WeakSet();
constructor({
callback,
Expand Down Expand Up @@ -12584,6 +12603,10 @@ class InternalRenderTask {
this.running = false;
this.cancelled = true;
this.gfx?.endDrawing();
if (this.#rAF) {
window.cancelAnimationFrame(this.#rAF);
this.#rAF = null;
}
InternalRenderTask.#canvasInUse.delete(this._canvas);
this.callback(error || new RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, extraDelay));
}
Expand Down Expand Up @@ -12611,7 +12634,8 @@ class InternalRenderTask {
}
_scheduleNext() {
if (this._useRequestAnimationFrame) {
window.requestAnimationFrame(() => {
this.#rAF = window.requestAnimationFrame(() => {
this.#rAF = null;
this._nextBound().catch(this._cancelBound);
});
} else {
Expand All @@ -12634,7 +12658,7 @@ class InternalRenderTask {
}
}
const version = "4.4.0";
const build = "c18a987";
const build = "fb3a4e4";

;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
function makeColorComp(n) {
Expand Down Expand Up @@ -19601,7 +19625,7 @@ class DrawLayer {


const pdfjsVersion = "4.4.0";
const pdfjsBuild = "c18a987";
const pdfjsBuild = "fb3a4e4";

var __webpack_exports__AbortException = __webpack_exports__.AbortException;
var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
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.

2 changes: 1 addition & 1 deletion build/pdf.sandbox.mjs.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/pdf.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23180,7 +23180,7 @@ function createOS2Table(properties, charstrings, override) {
lastCharIndex = 255;
}
const bbox = properties.bbox || [0, 0, 0, 0];
const unitsPerEm = override.unitsPerEm || (properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4)) : 1000);
const unitsPerEm = override.unitsPerEm || (properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4).map(Math.abs)) : 1000);
const scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
const typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
let typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
Expand Down Expand Up @@ -24874,7 +24874,7 @@ class Font {
}
properties.seacMap = seacMap;
}
const unitsPerEm = properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4)) : 1000;
const unitsPerEm = properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4).map(Math.abs)) : 1000;
const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
builder.addTable("CFF ", font.data);
builder.addTable("OS/2", createOS2Table(properties, newCharCodeToGlyphId));
Expand Down Expand Up @@ -56281,7 +56281,7 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.4.0";
const pdfjsBuild = "c18a987";
const pdfjsBuild = "fb3a4e4";

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.

32 changes: 25 additions & 7 deletions web/viewer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
useCapture: true,
signal: abortSignal
});
abortSignal?.addEventListener("abort", () => window.cancelAnimationFrame(rAF), {
once: true
});
return state;
}
function parseQueryString(query) {
Expand Down Expand Up @@ -1363,9 +1366,18 @@ class EventBus {
}
}
}
class AutomationEventBus extends EventBus {
class FirefoxEventBus extends EventBus {
#externalServices;
#globalEventNames;
#isInAutomation;
constructor(globalEventNames, externalServices, isInAutomation) {
super();
this.#globalEventNames = globalEventNames;
this.#externalServices = externalServices;
this.#isInAutomation = isInAutomation;
}
dispatch(eventName, data) {
throw new Error("Not implemented: AutomationEventBus.dispatch");
throw new Error("Not implemented: FirefoxEventBus.dispatch");
}
}

Expand All @@ -1390,6 +1402,10 @@ class BaseExternalServices {
throw new Error("Not implemented: updateEditorStates");
}
async getNimbusExperimentData() {}
async getGlobalEventNames() {
return null;
}
dispatchGlobalEvent(_event) {}
}

;// CONCATENATED MODULE: ./web/preferences.js
Expand Down Expand Up @@ -2750,6 +2766,9 @@ class DOMLocalization extends Localization {
this.pauseObserving();
if (this.roots.size === 0) {
this.mutationObserver = null;
if (this.windowElement && this.pendingrAF) {
this.windowElement.cancelAnimationFrame(this.pendingrAF);
}
this.windowElement = null;
this.pendingrAF = null;
this.pendingElements.clear();
Expand Down Expand Up @@ -2897,9 +2916,6 @@ class L10n {
}
this.#elements.clear();
this.#l10n.pauseObserving();
await new Promise(resolve => {
window.requestAnimationFrame(resolve);
});
}
pause() {
this.#l10n.pauseObserving();
Expand Down Expand Up @@ -12101,6 +12117,7 @@ const PDFViewerApplication = {
isViewerEmbedded: window.parent !== window,
url: "",
baseUrl: "",
_allowedGlobalEventsPromise: null,
_downloadUrl: "",
_eventBusAbortController: null,
_windowAbortController: null,
Expand Down Expand Up @@ -12245,7 +12262,8 @@ const PDFViewerApplication = {
externalServices,
l10n
} = this;
const eventBus = AppOptions.get("isInAutomation") ? new AutomationEventBus() : new EventBus();
let eventBus;
eventBus = new EventBus();
this.eventBus = eventBus;
this.overlayManager = new OverlayManager();
const pdfRenderingQueue = new PDFRenderingQueue();
Expand Down Expand Up @@ -14320,7 +14338,7 @@ function webViewerReportTelemetry({


const pdfjsVersion = "4.4.0";
const pdfjsBuild = "c18a987";
const pdfjsBuild = "fb3a4e4";
const AppConstants = {
LinkTarget: LinkTarget,
RenderingStates: RenderingStates,
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.mjs.map

Large diffs are not rendered by default.

0 comments on commit 434e9fe

Please sign in to comment.