[api-minor] Move, most of, the isPureXfa-handling from PDFViewer and into PDFPageView

By moving this code the "pageviewer"-component example will become slightly more usable on its own, it may simplify a future addition of XFA Foreground document support, and finally also serves as preparation for the following patches.
This commit is contained in:
Jonas Jenwald 2022-12-06 13:38:19 +01:00
parent dd96ee1512
commit ded02941f2
3 changed files with 20 additions and 18 deletions

View File

@ -783,7 +783,7 @@ class PDFDocumentProxy {
* @type {boolean} True if only XFA form.
*/
get isPureXfa() {
return !!this._transport._htmlForXfa;
return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
}
/**
@ -1343,6 +1343,13 @@ class PDFPageProxy {
));
}
/**
* @type {boolean} True if only XFA form.
*/
get isPureXfa() {
return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
}
/**
* @returns {Promise<Object | null>} A promise that is resolved with
* an {Object} with a fake DOM object (a tree structure where elements

View File

@ -753,6 +753,7 @@ class PDFPageView {
if (
!this.textLayer &&
this.textLayerMode !== TextLayerMode.DISABLE &&
!pdfPage.isPureXfa &&
this.textLayerFactory
) {
this._accessibilityManager ||= new TextAccessibilityManager();
@ -878,7 +879,7 @@ class PDFPageView {
}
);
if (this.xfaLayerFactory) {
if (pdfPage.isPureXfa && this.xfaLayerFactory) {
this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
pageDiv: div,
pdfPage,

View File

@ -658,7 +658,6 @@ class PDFViewer {
if (!pdfDocument) {
return;
}
const isPureXfa = pdfDocument.isPureXfa;
const pagesCount = pdfDocument.numPages;
const firstPagePromise = pdfDocument.getPage(1);
// Rendering (potentially) depends on this, hence fetching it immediately.
@ -732,13 +731,13 @@ class PDFViewer {
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
const mode = annotationEditorMode;
if (isPureXfa) {
if (pdfDocument.isPureXfa) {
console.warn("Warning: XFA-editing is not implemented.");
} else if (isValidAnnotationEditorMode(mode)) {
this.#annotationEditorUIManager = new AnnotationEditorUIManager(
this.container,
this.eventBus,
this.pdfDocument?.annotationStorage
pdfDocument?.annotationStorage
);
if (mode !== AnnotationEditorType.NONE) {
this.#annotationEditorUIManager.updateMode(mode);
@ -758,15 +757,6 @@ class PDFViewer {
// see issue 15795.
docStyle.setProperty("--scale-factor", viewport.scale);
const textLayerFactory =
textLayerMode !== TextLayerMode.DISABLE && !isPureXfa ? this : null;
const annotationLayerFactory =
annotationMode !== AnnotationMode.DISABLE ? this : null;
const xfaLayerFactory = isPureXfa ? this : null;
const annotationEditorLayerFactory = this.#annotationEditorUIManager
? this
: null;
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({
container: viewerElement,
@ -776,12 +766,16 @@ class PDFViewer {
defaultViewport: viewport.clone(),
optionalContentConfigPromise,
renderingQueue: this.renderingQueue,
textLayerFactory,
textLayerFactory:
textLayerMode !== TextLayerMode.DISABLE ? this : null,
textLayerMode,
annotationLayerFactory,
annotationLayerFactory:
annotationMode !== AnnotationMode.DISABLE ? this : null,
annotationMode,
xfaLayerFactory,
annotationEditorLayerFactory,
xfaLayerFactory: this,
annotationEditorLayerFactory: this.#annotationEditorUIManager
? this
: null,
textHighlighterFactory: this,
structTreeLayerFactory: this,
imageResourcesPath: this.imageResourcesPath,