mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #14247 from calixteman/button
[api-minor] Render pushbuttons on their own canvas (bug 1737260)
This commit is contained in:
commit
3209c013c4
13 changed files with 333 additions and 86 deletions
|
@ -32,6 +32,13 @@
|
|||
height: 100%;
|
||||
}
|
||||
|
||||
.annotationLayer .buttonWidgetAnnotation.pushButton > canvas {
|
||||
position: relative;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.annotationLayer .linkAnnotation > a:hover,
|
||||
.annotationLayer .buttonWidgetAnnotation.pushButton > a:hover {
|
||||
opacity: 0.2;
|
||||
|
|
|
@ -36,6 +36,7 @@ import { SimpleLinkService } from "./pdf_link_service.js";
|
|||
* @property {Promise<Object<string, Array<Object>> | null>}
|
||||
* [fieldObjectsPromise]
|
||||
* @property {Object} [mouseState]
|
||||
* @property {Map<string, Canvas>} [annotationCanvasMap]
|
||||
*/
|
||||
|
||||
class AnnotationLayerBuilder {
|
||||
|
@ -55,6 +56,7 @@ class AnnotationLayerBuilder {
|
|||
hasJSActionsPromise = null,
|
||||
fieldObjectsPromise = null,
|
||||
mouseState = null,
|
||||
annotationCanvasMap = null,
|
||||
}) {
|
||||
this.pageDiv = pageDiv;
|
||||
this.pdfPage = pdfPage;
|
||||
|
@ -68,6 +70,7 @@ class AnnotationLayerBuilder {
|
|||
this._hasJSActionsPromise = hasJSActionsPromise;
|
||||
this._fieldObjectsPromise = fieldObjectsPromise;
|
||||
this._mouseState = mouseState;
|
||||
this._annotationCanvasMap = annotationCanvasMap;
|
||||
|
||||
this.div = null;
|
||||
this._cancelled = false;
|
||||
|
@ -105,6 +108,7 @@ class AnnotationLayerBuilder {
|
|||
hasJSActions,
|
||||
fieldObjects,
|
||||
mouseState: this._mouseState,
|
||||
annotationCanvasMap: this._annotationCanvasMap,
|
||||
};
|
||||
|
||||
if (this.div) {
|
||||
|
@ -153,6 +157,8 @@ class DefaultAnnotationLayerFactory {
|
|||
* @param {Object} [mouseState]
|
||||
* @param {Promise<Object<string, Array<Object>> | null>}
|
||||
* [fieldObjectsPromise]
|
||||
* @param {Map<string, Canvas> | null} [annotationCanvasMap] - Map some
|
||||
* annotation ids with canvases used to render them.
|
||||
* @returns {AnnotationLayerBuilder}
|
||||
*/
|
||||
createAnnotationLayerBuilder(
|
||||
|
@ -165,7 +171,8 @@ class DefaultAnnotationLayerFactory {
|
|||
enableScripting = false,
|
||||
hasJSActionsPromise = null,
|
||||
mouseState = null,
|
||||
fieldObjectsPromise = null
|
||||
fieldObjectsPromise = null,
|
||||
annotationCanvasMap = null
|
||||
) {
|
||||
return new AnnotationLayerBuilder({
|
||||
pageDiv,
|
||||
|
@ -179,6 +186,7 @@ class DefaultAnnotationLayerFactory {
|
|||
hasJSActionsPromise,
|
||||
fieldObjectsPromise,
|
||||
mouseState,
|
||||
annotationCanvasMap,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -850,7 +850,12 @@ class BaseViewer {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this._doc.style.setProperty("--zoom-factor", newScale);
|
||||
this._doc.style.setProperty(
|
||||
"--viewport-scale-factor",
|
||||
newScale * PixelsPerInch.PDF_TO_CSS_UNITS
|
||||
);
|
||||
|
||||
const updateArgs = { scale: newScale };
|
||||
for (const pageView of this._pages) {
|
||||
|
@ -1480,6 +1485,7 @@ class BaseViewer {
|
|||
* @param {Object} [mouseState]
|
||||
* @param {Promise<Object<string, Array<Object>> | null>}
|
||||
* [fieldObjectsPromise]
|
||||
* @param {Map<string, Canvas>} [annotationCanvasMap]
|
||||
* @returns {AnnotationLayerBuilder}
|
||||
*/
|
||||
createAnnotationLayerBuilder(
|
||||
|
@ -1492,7 +1498,8 @@ class BaseViewer {
|
|||
enableScripting = null,
|
||||
hasJSActionsPromise = null,
|
||||
mouseState = null,
|
||||
fieldObjectsPromise = null
|
||||
fieldObjectsPromise = null,
|
||||
annotationCanvasMap = null
|
||||
) {
|
||||
return new AnnotationLayerBuilder({
|
||||
pageDiv,
|
||||
|
@ -1510,6 +1517,7 @@ class BaseViewer {
|
|||
fieldObjectsPromise:
|
||||
fieldObjectsPromise || this.pdfDocument?.getFieldObjects(),
|
||||
mouseState: mouseState || this._scriptingManager?.mouseState,
|
||||
annotationCanvasMap,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,8 @@ class IPDFAnnotationLayerFactory {
|
|||
* @param {Object} [mouseState]
|
||||
* @param {Promise<Object<string, Array<Object>> | null>}
|
||||
* [fieldObjectsPromise]
|
||||
* @property {Map<string, Canvas> | null} [annotationCanvasMap] - Map some
|
||||
* annotation ids with canvases used to render them.
|
||||
* @returns {AnnotationLayerBuilder}
|
||||
*/
|
||||
createAnnotationLayerBuilder(
|
||||
|
@ -187,7 +189,8 @@ class IPDFAnnotationLayerFactory {
|
|||
enableScripting = false,
|
||||
hasJSActionsPromise = null,
|
||||
mouseState = null,
|
||||
fieldObjectsPromise = null
|
||||
fieldObjectsPromise = null,
|
||||
annotationCanvasMap = null
|
||||
) {}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,8 @@ class PDFPageView {
|
|||
this._renderError = null;
|
||||
this._isStandalone = !this.renderingQueue?.hasViewer();
|
||||
|
||||
this._annotationCanvasMap = null;
|
||||
|
||||
this.annotationLayer = null;
|
||||
this.textLayer = null;
|
||||
this.zoomLayer = null;
|
||||
|
@ -322,17 +324,20 @@ class PDFPageView {
|
|||
if (optionalContentConfigPromise instanceof Promise) {
|
||||
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
||||
}
|
||||
if (this._isStandalone) {
|
||||
const doc = document.documentElement;
|
||||
doc.style.setProperty("--zoom-factor", this.scale);
|
||||
}
|
||||
|
||||
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
||||
const viewportScale = this.scale * PixelsPerInch.PDF_TO_CSS_UNITS;
|
||||
this.viewport = this.viewport.clone({
|
||||
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
scale: viewportScale,
|
||||
rotation: totalRotation,
|
||||
});
|
||||
|
||||
if (this._isStandalone) {
|
||||
const { style } = document.documentElement;
|
||||
style.setProperty("--zoom-factor", this.scale);
|
||||
style.setProperty("--viewport-scale-factor", viewportScale);
|
||||
}
|
||||
|
||||
if (this.svg) {
|
||||
this.cssTransform({
|
||||
target: this.svg,
|
||||
|
@ -418,6 +423,7 @@ class PDFPageView {
|
|||
) {
|
||||
this.annotationLayer.cancel();
|
||||
this.annotationLayer = null;
|
||||
this._annotationCanvasMap = null;
|
||||
}
|
||||
if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
|
||||
this.xfaLayer.cancel();
|
||||
|
@ -580,6 +586,27 @@ class PDFPageView {
|
|||
}
|
||||
this.textLayer = textLayer;
|
||||
|
||||
if (
|
||||
this._annotationMode !== AnnotationMode.DISABLE &&
|
||||
this.annotationLayerFactory
|
||||
) {
|
||||
this._annotationCanvasMap ||= new Map();
|
||||
this.annotationLayer ||=
|
||||
this.annotationLayerFactory.createAnnotationLayerBuilder(
|
||||
div,
|
||||
pdfPage,
|
||||
/* annotationStorage = */ null,
|
||||
this.imageResourcesPath,
|
||||
this._annotationMode === AnnotationMode.ENABLE_FORMS,
|
||||
this.l10n,
|
||||
/* enableScripting = */ null,
|
||||
/* hasJSActionsPromise = */ null,
|
||||
/* mouseState = */ null,
|
||||
/* fieldObjectsPromise = */ null,
|
||||
/* annotationCanvasMap */ this._annotationCanvasMap
|
||||
);
|
||||
}
|
||||
|
||||
if (this.xfaLayer?.div) {
|
||||
// The xfa layer needs to stay on top.
|
||||
div.appendChild(this.xfaLayer.div);
|
||||
|
@ -653,6 +680,10 @@ class PDFPageView {
|
|||
textLayer.setTextContentStream(readableStream);
|
||||
textLayer.render();
|
||||
}
|
||||
|
||||
if (this.annotationLayer) {
|
||||
this._renderAnnotationLayer();
|
||||
}
|
||||
});
|
||||
},
|
||||
function (reason) {
|
||||
|
@ -660,28 +691,6 @@ class PDFPageView {
|
|||
}
|
||||
);
|
||||
|
||||
if (
|
||||
this._annotationMode !== AnnotationMode.DISABLE &&
|
||||
this.annotationLayerFactory
|
||||
) {
|
||||
if (!this.annotationLayer) {
|
||||
this.annotationLayer =
|
||||
this.annotationLayerFactory.createAnnotationLayerBuilder(
|
||||
div,
|
||||
pdfPage,
|
||||
/* annotationStorage = */ null,
|
||||
this.imageResourcesPath,
|
||||
this._annotationMode === AnnotationMode.ENABLE_FORMS,
|
||||
this.l10n,
|
||||
/* enableScripting = */ null,
|
||||
/* hasJSActionsPromise = */ null,
|
||||
/* mouseState = */ null,
|
||||
/* fieldObjectsPromise = */ null
|
||||
);
|
||||
}
|
||||
this._renderAnnotationLayer();
|
||||
}
|
||||
|
||||
if (this.xfaLayerFactory) {
|
||||
if (!this.xfaLayer) {
|
||||
this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(
|
||||
|
@ -804,6 +813,7 @@ class PDFPageView {
|
|||
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
|
||||
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + "px";
|
||||
canvas.style.height = roundToDivide(viewport.height, sfy[1]) + "px";
|
||||
|
||||
// Add the viewport so it's known what it was originally drawn with.
|
||||
this.paintedViewportMap.set(canvas, viewport);
|
||||
|
||||
|
@ -817,6 +827,7 @@ class PDFPageView {
|
|||
viewport: this.viewport,
|
||||
annotationMode: this._annotationMode,
|
||||
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
||||
annotationCanvasMap: this._annotationCanvasMap,
|
||||
};
|
||||
const renderTask = this.pdfPage.render(renderContext);
|
||||
renderTask.onContinue = function (cont) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
--page-border: 9px solid transparent;
|
||||
--spreadHorizontalWrapped-margin-LR: -3.5px;
|
||||
--zoom-factor: 1;
|
||||
--viewport-scale-factor: 1;
|
||||
}
|
||||
|
||||
@media screen and (forced-colors: active) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue