[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,
|
||||
parseQueryString,
|
||||
ProgressBar,
|
||||
RendererType,
|
||||
RenderingStates,
|
||||
ScrollMode,
|
||||
SidebarView,
|
||||
@ -512,11 +511,6 @@ const PDFViewerApplication = {
|
||||
findController,
|
||||
scriptingManager:
|
||||
AppOptions.get("enableScripting") && pdfScriptingManager,
|
||||
renderer:
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||
? AppOptions.get("renderer")
|
||||
: null,
|
||||
l10n: this.l10n,
|
||||
textLayerMode: AppOptions.get("textLayerMode"),
|
||||
annotationMode: AppOptions.get("annotationMode"),
|
||||
@ -1714,17 +1708,7 @@ const PDFViewerApplication = {
|
||||
this.pdfViewer.cleanup();
|
||||
this.pdfThumbnailViewer?.cleanup();
|
||||
|
||||
if (
|
||||
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();
|
||||
}
|
||||
this.pdfDocument.cleanup();
|
||||
},
|
||||
|
||||
forceRendering() {
|
||||
|
@ -315,11 +315,6 @@ if (
|
||||
value: navigator.language || "en-US",
|
||||
kind: OptionKind.VIEWER,
|
||||
};
|
||||
defaultOptions.renderer = {
|
||||
/** @type {string} */
|
||||
value: "canvas",
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
};
|
||||
defaultOptions.sandboxBundleSrc = {
|
||||
/** @type {string} */
|
||||
value:
|
||||
|
@ -31,13 +31,11 @@ import {
|
||||
RenderingCancelledException,
|
||||
setLayerDimensions,
|
||||
shadow,
|
||||
SVGGraphics,
|
||||
} from "pdfjs-lib";
|
||||
import {
|
||||
approximateFraction,
|
||||
DEFAULT_SCALE,
|
||||
OutputScale,
|
||||
RendererType,
|
||||
RenderingStates,
|
||||
roundToDivide,
|
||||
TextLayerMode,
|
||||
@ -160,12 +158,6 @@ class PDFPageView {
|
||||
|
||||
this.eventBus = options.eventBus;
|
||||
this.renderingQueue = options.renderingQueue;
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||
) {
|
||||
this.renderer = options.renderer || RendererType.CANVAS;
|
||||
}
|
||||
this.l10n = options.l10n || NullL10n;
|
||||
|
||||
this.paintTask = null;
|
||||
@ -519,14 +511,6 @@ class PDFPageView {
|
||||
}
|
||||
this._resetZoomLayer();
|
||||
}
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
||||
this.svg
|
||||
) {
|
||||
this.paintedViewportMap.delete(this.svg);
|
||||
delete this.svg;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (this.canvas && this.maxCanvasPixels > 0) {
|
||||
const outputScale = this.outputScale;
|
||||
@ -722,26 +683,18 @@ class PDFPageView {
|
||||
redrawTextLayer = false,
|
||||
hideTextLayer = false,
|
||||
}) {
|
||||
// Scale target (canvas or svg), its wrapper and page container.
|
||||
|
||||
if (target instanceof HTMLCanvasElement) {
|
||||
if (!target.hasAttribute("zooming")) {
|
||||
target.setAttribute("zooming", true);
|
||||
const { style } = target;
|
||||
style.width = style.height = "";
|
||||
}
|
||||
} else {
|
||||
const div = this.div;
|
||||
const { width, height } = this.viewport;
|
||||
|
||||
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";
|
||||
// Scale target (canvas), its wrapper and page container.
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
||||
!(target instanceof HTMLCanvasElement)
|
||||
) {
|
||||
throw new Error("Expected `target` to be a canvas.");
|
||||
}
|
||||
if (!target.hasAttribute("zooming")) {
|
||||
target.setAttribute("zooming", true);
|
||||
const { style } = target;
|
||||
style.width = style.height = "";
|
||||
}
|
||||
|
||||
const originalViewport = this.paintedViewportMap.get(target);
|
||||
@ -908,12 +861,7 @@ class PDFPageView {
|
||||
}
|
||||
};
|
||||
|
||||
const paintTask =
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
||||
this.renderer === RendererType.SVG
|
||||
? this.paintOnSvg(canvasWrapper)
|
||||
: this.paintOnCanvas(canvasWrapper);
|
||||
const paintTask = this.paintOnCanvas(canvasWrapper);
|
||||
paintTask.onRenderContinue = renderContinueCallback;
|
||||
this.paintTask = paintTask;
|
||||
|
||||
@ -1092,62 +1040,6 @@ class PDFPageView {
|
||||
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
|
||||
*/
|
||||
|
@ -47,7 +47,6 @@ import {
|
||||
MAX_SCALE,
|
||||
MIN_SCALE,
|
||||
PresentationModeState,
|
||||
RendererType,
|
||||
RenderingStates,
|
||||
SCROLLBAR_PADDING,
|
||||
scrollIntoView,
|
||||
@ -266,7 +265,6 @@ class PDFViewer {
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||
) {
|
||||
this.removePageBorders = options.removePageBorders || false;
|
||||
this.renderer = options.renderer || RendererType.CANVAS;
|
||||
}
|
||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||
this.isOffscreenCanvasSupported =
|
||||
@ -775,11 +773,6 @@ class PDFViewer {
|
||||
textLayerMode,
|
||||
annotationMode,
|
||||
imageResourcesPath: this.imageResourcesPath,
|
||||
renderer:
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||
? this.renderer
|
||||
: null,
|
||||
useOnlyCssZoom: this.useOnlyCssZoom,
|
||||
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
||||
maxCanvasPixels: this.maxCanvasPixels,
|
||||
|
@ -46,14 +46,6 @@ const SidebarView = {
|
||||
LAYERS: 4,
|
||||
};
|
||||
|
||||
const RendererType =
|
||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||
? {
|
||||
CANVAS: "canvas",
|
||||
SVG: "svg",
|
||||
}
|
||||
: null;
|
||||
|
||||
const TextLayerMode = {
|
||||
DISABLE: 0,
|
||||
ENABLE: 1,
|
||||
@ -880,7 +872,6 @@ export {
|
||||
PresentationModeState,
|
||||
ProgressBar,
|
||||
removeNullCharacters,
|
||||
RendererType,
|
||||
RenderingStates,
|
||||
roundToDivide,
|
||||
SCROLLBAR_PADDING,
|
||||
|
Loading…
Reference in New Issue
Block a user