[api-minor] Move the getXfaPageViewport helper into the XfaLayer class

This small helper function only exists to support printing of XFA documents, in the viewer, hence it seems like a good idea to (ever so slightly) reduce the official API surface a little bit.
This commit is contained in:
Jonas Jenwald 2026-05-16 10:25:25 +02:00
parent eda97fe8fc
commit e8f07d7ca3
6 changed files with 17 additions and 26 deletions

View File

@ -348,21 +348,6 @@ class PDFDateString {
}
}
/**
* NOTE: This is (mostly) intended to support printing of XFA forms.
*/
function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
const { width, height } = xfaPage.attributes.style;
const viewBox = [0, 0, parseInt(width, 10), parseInt(height, 10)];
return new PageViewport({
viewBox,
userUnit: 1,
scale,
rotation,
});
}
function getRGBA(color) {
if (color.startsWith("#")) {
// #RRGGBB or #RRGGBBAA
@ -845,7 +830,6 @@ export {
getPdfFilenameFromUrl,
getRGB,
getRGBA,
getXfaPageViewport,
isDataScheme,
isPdfFile,
isValidFetchUrl,

View File

@ -15,10 +15,10 @@
// eslint-disable-next-line max-len
/** @typedef {import("./annotation_storage").AnnotationStorage} AnnotationStorage */
/** @typedef {import("./page_viewport").PageViewport} PageViewport */
// eslint-disable-next-line max-len
/** @typedef {import("../../web/pdf_link_service.js").PDFLinkService} PDFLinkService */
import { PageViewport } from "./page_viewport.js";
import { XfaText } from "./xfa_text.js";
/**
@ -293,6 +293,20 @@ class XfaLayer {
parameters.div.style.transform = transform;
parameters.div.hidden = false;
}
/**
* NOTE: This is (mostly) intended to support printing of XFA forms.
*/
static getPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
const { width, height } = xfaPage.attributes.style;
return new PageViewport({
viewBox: [0, 0, parseInt(width, 10), parseInt(height, 10)],
userUnit: 1,
scale,
rotation,
});
}
}
export { XfaLayer };

View File

@ -55,7 +55,6 @@ import {
getPdfFilenameFromUrl,
getRGB,
getRGBA,
getXfaPageViewport,
isDataScheme,
isPdfFile,
noContextMenu,
@ -122,7 +121,6 @@ globalThis.pdfjsLib = {
getRGB,
getRGBA,
getUuid,
getXfaPageViewport,
GlobalWorkerOptions,
ImageKind,
InvalidPDFException,
@ -186,7 +184,6 @@ export {
getRGB,
getRGBA,
getUuid,
getXfaPageViewport,
GlobalWorkerOptions,
ImageKind,
InvalidPDFException,

View File

@ -46,7 +46,6 @@ import {
getPdfFilenameFromUrl,
getRGB,
getRGBA,
getXfaPageViewport,
isDataScheme,
isPdfFile,
noContextMenu,
@ -106,7 +105,6 @@ const expectedAPI = Object.freeze({
getRGB,
getRGBA,
getUuid,
getXfaPageViewport,
GlobalWorkerOptions,
ImageKind,
InvalidPDFException,

View File

@ -38,7 +38,6 @@ const {
getRGB,
getRGBA,
getUuid,
getXfaPageViewport,
GlobalWorkerOptions,
ImageKind,
InvalidPDFException,
@ -102,7 +101,6 @@ export {
getRGB,
getRGBA,
getUuid,
getXfaPageViewport,
GlobalWorkerOptions,
ImageKind,
InvalidPDFException,

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib";
import { PixelsPerInch, XfaLayer } from "pdfjs-lib";
import { SimpleLinkService } from "./pdf_link_service.js";
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
@ -51,7 +51,7 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
linkService,
xfaHtml: xfaPage,
});
const viewport = getXfaPageViewport(xfaPage, { scale });
const viewport = XfaLayer.getPageViewport(xfaPage, { scale });
builder.render({ viewport, intent: "print" });
page.append(builder.div);