[api-minor] Remove SVG-rendering from the viewer (PR 15173 follow-up)
This commit is contained in:
parent
b135dadb17
commit
c2f1e65cc3
18
web/app.js
18
web/app.js
@ -27,7 +27,6 @@ import {
|
|||||||
normalizeWheelEventDirection,
|
normalizeWheelEventDirection,
|
||||||
parseQueryString,
|
parseQueryString,
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
RendererType,
|
|
||||||
RenderingStates,
|
RenderingStates,
|
||||||
ScrollMode,
|
ScrollMode,
|
||||||
SidebarView,
|
SidebarView,
|
||||||
@ -512,11 +511,6 @@ const PDFViewerApplication = {
|
|||||||
findController,
|
findController,
|
||||||
scriptingManager:
|
scriptingManager:
|
||||||
AppOptions.get("enableScripting") && pdfScriptingManager,
|
AppOptions.get("enableScripting") && pdfScriptingManager,
|
||||||
renderer:
|
|
||||||
typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
? AppOptions.get("renderer")
|
|
||||||
: null,
|
|
||||||
l10n: this.l10n,
|
l10n: this.l10n,
|
||||||
textLayerMode: AppOptions.get("textLayerMode"),
|
textLayerMode: AppOptions.get("textLayerMode"),
|
||||||
annotationMode: AppOptions.get("annotationMode"),
|
annotationMode: AppOptions.get("annotationMode"),
|
||||||
@ -1714,17 +1708,7 @@ const PDFViewerApplication = {
|
|||||||
this.pdfViewer.cleanup();
|
this.pdfViewer.cleanup();
|
||||||
this.pdfThumbnailViewer?.cleanup();
|
this.pdfThumbnailViewer?.cleanup();
|
||||||
|
|
||||||
if (
|
this.pdfDocument.cleanup();
|
||||||
typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
) {
|
|
||||||
// We don't want to remove fonts used by active page SVGs.
|
|
||||||
this.pdfDocument.cleanup(
|
|
||||||
/* keepLoadedFonts = */ this.pdfViewer.renderer === RendererType.SVG
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.pdfDocument.cleanup();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
forceRendering() {
|
forceRendering() {
|
||||||
|
@ -315,11 +315,6 @@ if (
|
|||||||
value: navigator.language || "en-US",
|
value: navigator.language || "en-US",
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
};
|
};
|
||||||
defaultOptions.renderer = {
|
|
||||||
/** @type {string} */
|
|
||||||
value: "canvas",
|
|
||||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
||||||
};
|
|
||||||
defaultOptions.sandboxBundleSrc = {
|
defaultOptions.sandboxBundleSrc = {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
value:
|
value:
|
||||||
|
@ -31,13 +31,11 @@ import {
|
|||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
shadow,
|
shadow,
|
||||||
SVGGraphics,
|
|
||||||
} from "pdfjs-lib";
|
} from "pdfjs-lib";
|
||||||
import {
|
import {
|
||||||
approximateFraction,
|
approximateFraction,
|
||||||
DEFAULT_SCALE,
|
DEFAULT_SCALE,
|
||||||
OutputScale,
|
OutputScale,
|
||||||
RendererType,
|
|
||||||
RenderingStates,
|
RenderingStates,
|
||||||
roundToDivide,
|
roundToDivide,
|
||||||
TextLayerMode,
|
TextLayerMode,
|
||||||
@ -160,12 +158,6 @@ class PDFPageView {
|
|||||||
|
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = options.eventBus;
|
||||||
this.renderingQueue = options.renderingQueue;
|
this.renderingQueue = options.renderingQueue;
|
||||||
if (
|
|
||||||
typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
) {
|
|
||||||
this.renderer = options.renderer || RendererType.CANVAS;
|
|
||||||
}
|
|
||||||
this.l10n = options.l10n || NullL10n;
|
this.l10n = options.l10n || NullL10n;
|
||||||
|
|
||||||
this.paintTask = null;
|
this.paintTask = null;
|
||||||
@ -519,14 +511,6 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
this._resetZoomLayer();
|
this._resetZoomLayer();
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
||||||
this.svg
|
|
||||||
) {
|
|
||||||
this.paintedViewportMap.delete(this.svg);
|
|
||||||
delete this.svg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update({
|
update({
|
||||||
@ -573,29 +557,6 @@ class PDFPageView {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
||||||
this.svg
|
|
||||||
) {
|
|
||||||
this.cssTransform({
|
|
||||||
target: this.svg,
|
|
||||||
redrawAnnotationLayer: true,
|
|
||||||
redrawAnnotationEditorLayer: true,
|
|
||||||
redrawXfaLayer: true,
|
|
||||||
redrawTextLayer: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.eventBus.dispatch("pagerendered", {
|
|
||||||
source: this,
|
|
||||||
pageNumber: this.id,
|
|
||||||
cssTransform: true,
|
|
||||||
timestamp: performance.now(),
|
|
||||||
error: this._renderError,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let isScalingRestricted = false;
|
let isScalingRestricted = false;
|
||||||
if (this.canvas && this.maxCanvasPixels > 0) {
|
if (this.canvas && this.maxCanvasPixels > 0) {
|
||||||
const outputScale = this.outputScale;
|
const outputScale = this.outputScale;
|
||||||
@ -722,26 +683,18 @@ class PDFPageView {
|
|||||||
redrawTextLayer = false,
|
redrawTextLayer = false,
|
||||||
hideTextLayer = false,
|
hideTextLayer = false,
|
||||||
}) {
|
}) {
|
||||||
// Scale target (canvas or svg), its wrapper and page container.
|
// Scale target (canvas), its wrapper and page container.
|
||||||
|
if (
|
||||||
if (target instanceof HTMLCanvasElement) {
|
(typeof PDFJSDev === "undefined" ||
|
||||||
if (!target.hasAttribute("zooming")) {
|
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
||||||
target.setAttribute("zooming", true);
|
!(target instanceof HTMLCanvasElement)
|
||||||
const { style } = target;
|
) {
|
||||||
style.width = style.height = "";
|
throw new Error("Expected `target` to be a canvas.");
|
||||||
}
|
}
|
||||||
} else {
|
if (!target.hasAttribute("zooming")) {
|
||||||
const div = this.div;
|
target.setAttribute("zooming", true);
|
||||||
const { width, height } = this.viewport;
|
const { style } = target;
|
||||||
|
style.width = style.height = "";
|
||||||
target.style.width =
|
|
||||||
target.parentNode.style.width =
|
|
||||||
div.style.width =
|
|
||||||
Math.floor(width) + "px";
|
|
||||||
target.style.height =
|
|
||||||
target.parentNode.style.height =
|
|
||||||
div.style.height =
|
|
||||||
Math.floor(height) + "px";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalViewport = this.paintedViewportMap.get(target);
|
const originalViewport = this.paintedViewportMap.get(target);
|
||||||
@ -908,12 +861,7 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const paintTask =
|
const paintTask = this.paintOnCanvas(canvasWrapper);
|
||||||
(typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
||||||
this.renderer === RendererType.SVG
|
|
||||||
? this.paintOnSvg(canvasWrapper)
|
|
||||||
: this.paintOnCanvas(canvasWrapper);
|
|
||||||
paintTask.onRenderContinue = renderContinueCallback;
|
paintTask.onRenderContinue = renderContinueCallback;
|
||||||
this.paintTask = paintTask;
|
this.paintTask = paintTask;
|
||||||
|
|
||||||
@ -1092,62 +1040,6 @@ class PDFPageView {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
paintOnSvg(wrapper) {
|
|
||||||
if (
|
|
||||||
!(
|
|
||||||
typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error("Not implemented: paintOnSvg");
|
|
||||||
}
|
|
||||||
let cancelled = false;
|
|
||||||
const ensureNotCancelled = () => {
|
|
||||||
if (cancelled) {
|
|
||||||
throw new RenderingCancelledException(
|
|
||||||
`Rendering cancelled, page ${this.id}`,
|
|
||||||
"svg"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const pdfPage = this.pdfPage;
|
|
||||||
const actualSizeViewport = this.viewport.clone({
|
|
||||||
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
||||||
});
|
|
||||||
const promise = pdfPage
|
|
||||||
.getOperatorList({
|
|
||||||
annotationMode: this.#annotationMode,
|
|
||||||
})
|
|
||||||
.then(opList => {
|
|
||||||
ensureNotCancelled();
|
|
||||||
const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
|
||||||
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
|
||||||
ensureNotCancelled();
|
|
||||||
this.svg = svg;
|
|
||||||
this.paintedViewportMap.set(svg, actualSizeViewport);
|
|
||||||
|
|
||||||
svg.style.width = wrapper.style.width;
|
|
||||||
svg.style.height = wrapper.style.height;
|
|
||||||
this.renderingState = RenderingStates.FINISHED;
|
|
||||||
wrapper.append(svg);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
promise,
|
|
||||||
onRenderContinue(cont) {
|
|
||||||
cont();
|
|
||||||
},
|
|
||||||
cancel() {
|
|
||||||
cancelled = true;
|
|
||||||
},
|
|
||||||
get separateAnnots() {
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string|null} label
|
* @param {string|null} label
|
||||||
*/
|
*/
|
||||||
|
@ -47,7 +47,6 @@ import {
|
|||||||
MAX_SCALE,
|
MAX_SCALE,
|
||||||
MIN_SCALE,
|
MIN_SCALE,
|
||||||
PresentationModeState,
|
PresentationModeState,
|
||||||
RendererType,
|
|
||||||
RenderingStates,
|
RenderingStates,
|
||||||
SCROLLBAR_PADDING,
|
SCROLLBAR_PADDING,
|
||||||
scrollIntoView,
|
scrollIntoView,
|
||||||
@ -266,7 +265,6 @@ class PDFViewer {
|
|||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||||
) {
|
) {
|
||||||
this.removePageBorders = options.removePageBorders || false;
|
this.removePageBorders = options.removePageBorders || false;
|
||||||
this.renderer = options.renderer || RendererType.CANVAS;
|
|
||||||
}
|
}
|
||||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||||
this.isOffscreenCanvasSupported =
|
this.isOffscreenCanvasSupported =
|
||||||
@ -775,11 +773,6 @@ class PDFViewer {
|
|||||||
textLayerMode,
|
textLayerMode,
|
||||||
annotationMode,
|
annotationMode,
|
||||||
imageResourcesPath: this.imageResourcesPath,
|
imageResourcesPath: this.imageResourcesPath,
|
||||||
renderer:
|
|
||||||
typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
? this.renderer
|
|
||||||
: null,
|
|
||||||
useOnlyCssZoom: this.useOnlyCssZoom,
|
useOnlyCssZoom: this.useOnlyCssZoom,
|
||||||
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
||||||
maxCanvasPixels: this.maxCanvasPixels,
|
maxCanvasPixels: this.maxCanvasPixels,
|
||||||
|
@ -46,14 +46,6 @@ const SidebarView = {
|
|||||||
LAYERS: 4,
|
LAYERS: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
const RendererType =
|
|
||||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
||||||
? {
|
|
||||||
CANVAS: "canvas",
|
|
||||||
SVG: "svg",
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const TextLayerMode = {
|
const TextLayerMode = {
|
||||||
DISABLE: 0,
|
DISABLE: 0,
|
||||||
ENABLE: 1,
|
ENABLE: 1,
|
||||||
@ -880,7 +872,6 @@ export {
|
|||||||
PresentationModeState,
|
PresentationModeState,
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
removeNullCharacters,
|
removeNullCharacters,
|
||||||
RendererType,
|
|
||||||
RenderingStates,
|
RenderingStates,
|
||||||
roundToDivide,
|
roundToDivide,
|
||||||
SCROLLBAR_PADDING,
|
SCROLLBAR_PADDING,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user