|
| 1 | +/* Copyright 2014 Mozilla Foundation |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ |
| 17 | +// eslint-disable-next-line max-len |
| 18 | +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ |
| 19 | +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ |
| 20 | +/** @typedef {import("./interfaces").IL10n} IL10n */ |
| 21 | +// eslint-disable-next-line max-len |
| 22 | +/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ |
| 23 | +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ |
| 24 | +// eslint-disable-next-line max-len |
| 25 | +/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ |
| 26 | +// eslint-disable-next-line max-len |
| 27 | +/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ |
| 28 | +/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ |
| 29 | +/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ |
| 30 | +/** @typedef {import("./ui_utils").EventBus} EventBus */ |
| 31 | + |
| 32 | +import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; |
| 33 | +import { NullL10n } from "./l10n_utils.js"; |
| 34 | +import { SimpleLinkService } from "./pdf_link_service.js"; |
| 35 | +import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; |
| 36 | +import { TextLayerBuilder } from "./text_layer_builder.js"; |
| 37 | +import { XfaLayerBuilder } from "./xfa_layer_builder.js"; |
| 38 | + |
| 39 | +/** |
| 40 | + * @implements IPDFAnnotationLayerFactory |
| 41 | + */ |
| 42 | +class DefaultAnnotationLayerFactory { |
| 43 | + /** |
| 44 | + * @param {HTMLDivElement} pageDiv |
| 45 | + * @param {PDFPageProxy} pdfPage |
| 46 | + * @param {AnnotationStorage} [annotationStorage] |
| 47 | + * @param {string} [imageResourcesPath] - Path for image resources, mainly |
| 48 | + * for annotation icons. Include trailing slash. |
| 49 | + * @param {boolean} renderForms |
| 50 | + * @param {IL10n} l10n |
| 51 | + * @param {boolean} [enableScripting] |
| 52 | + * @param {Promise<boolean>} [hasJSActionsPromise] |
| 53 | + * @param {Object} [mouseState] |
| 54 | + * @param {Promise<Object<string, Array<Object>> | null>} |
| 55 | + * [fieldObjectsPromise] |
| 56 | + * @param {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some |
| 57 | + * annotation ids with canvases used to render them. |
| 58 | + * @returns {AnnotationLayerBuilder} |
| 59 | + */ |
| 60 | + createAnnotationLayerBuilder( |
| 61 | + pageDiv, |
| 62 | + pdfPage, |
| 63 | + annotationStorage = null, |
| 64 | + imageResourcesPath = "", |
| 65 | + renderForms = true, |
| 66 | + l10n = NullL10n, |
| 67 | + enableScripting = false, |
| 68 | + hasJSActionsPromise = null, |
| 69 | + mouseState = null, |
| 70 | + fieldObjectsPromise = null, |
| 71 | + annotationCanvasMap = null |
| 72 | + ) { |
| 73 | + return new AnnotationLayerBuilder({ |
| 74 | + pageDiv, |
| 75 | + pdfPage, |
| 76 | + imageResourcesPath, |
| 77 | + renderForms, |
| 78 | + linkService: new SimpleLinkService(), |
| 79 | + l10n, |
| 80 | + annotationStorage, |
| 81 | + enableScripting, |
| 82 | + hasJSActionsPromise, |
| 83 | + fieldObjectsPromise, |
| 84 | + mouseState, |
| 85 | + annotationCanvasMap, |
| 86 | + }); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +/** |
| 91 | + * @implements IPDFStructTreeLayerFactory |
| 92 | + */ |
| 93 | +class DefaultStructTreeLayerFactory { |
| 94 | + /** |
| 95 | + * @param {PDFPageProxy} pdfPage |
| 96 | + * @returns {StructTreeLayerBuilder} |
| 97 | + */ |
| 98 | + createStructTreeLayerBuilder(pdfPage) { |
| 99 | + return new StructTreeLayerBuilder({ |
| 100 | + pdfPage, |
| 101 | + }); |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +/** |
| 106 | + * @implements IPDFTextLayerFactory |
| 107 | + */ |
| 108 | +class DefaultTextLayerFactory { |
| 109 | + /** |
| 110 | + * @param {HTMLDivElement} textLayerDiv |
| 111 | + * @param {number} pageIndex |
| 112 | + * @param {PageViewport} viewport |
| 113 | + * @param {boolean} enhanceTextSelection |
| 114 | + * @param {EventBus} eventBus |
| 115 | + * @param {TextHighlighter} highlighter |
| 116 | + * @returns {TextLayerBuilder} |
| 117 | + */ |
| 118 | + createTextLayerBuilder( |
| 119 | + textLayerDiv, |
| 120 | + pageIndex, |
| 121 | + viewport, |
| 122 | + enhanceTextSelection = false, |
| 123 | + eventBus, |
| 124 | + highlighter |
| 125 | + ) { |
| 126 | + return new TextLayerBuilder({ |
| 127 | + textLayerDiv, |
| 128 | + pageIndex, |
| 129 | + viewport, |
| 130 | + enhanceTextSelection, |
| 131 | + eventBus, |
| 132 | + highlighter, |
| 133 | + }); |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +/** |
| 138 | + * @implements IPDFXfaLayerFactory |
| 139 | + */ |
| 140 | +class DefaultXfaLayerFactory { |
| 141 | + /** |
| 142 | + * @param {HTMLDivElement} pageDiv |
| 143 | + * @param {PDFPageProxy} pdfPage |
| 144 | + * @param {AnnotationStorage} [annotationStorage] |
| 145 | + * @param {Object} [xfaHtml] |
| 146 | + */ |
| 147 | + createXfaLayerBuilder( |
| 148 | + pageDiv, |
| 149 | + pdfPage, |
| 150 | + annotationStorage = null, |
| 151 | + xfaHtml = null |
| 152 | + ) { |
| 153 | + return new XfaLayerBuilder({ |
| 154 | + pageDiv, |
| 155 | + pdfPage, |
| 156 | + annotationStorage, |
| 157 | + linkService: new SimpleLinkService(), |
| 158 | + xfaHtml, |
| 159 | + }); |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +export { |
| 164 | + DefaultAnnotationLayerFactory, |
| 165 | + DefaultStructTreeLayerFactory, |
| 166 | + DefaultTextLayerFactory, |
| 167 | + DefaultXfaLayerFactory, |
| 168 | +}; |
0 commit comments