|
@@ -287,8 +287,6 @@ class PDFPageView {
|
|
|
// this.contentContainer = null
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (this.compdfAnnotationLayer) return
|
|
|
}
|
|
|
|
|
|
handleSearch(searchResults) {
|
|
@@ -471,209 +469,6 @@ class PDFPageView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- renderPage() {
|
|
|
- if (this.renderingState !== RenderingStates.INITIAL) {
|
|
|
- console.error("Must be in new state before drawing");
|
|
|
- this.reset(); // Ensure that we reset all state to prevent issues.
|
|
|
- }
|
|
|
- const { div, viewport, pdfPage, annotations, annotationsAll } = this;
|
|
|
-
|
|
|
- if (!pdfPage) {
|
|
|
- this.renderingState = RenderingStates.FINISHED;
|
|
|
- throw new Error("pdfPage is not loaded");
|
|
|
- }
|
|
|
-
|
|
|
- this.renderingState = RenderingStates.RUNNING;
|
|
|
-
|
|
|
- const canvasWrapper = document.createElement("div");
|
|
|
- canvasWrapper.classList.add("canvasWrapper");
|
|
|
- div.append(canvasWrapper)
|
|
|
-
|
|
|
- const canvas = document.createElement("canvas");
|
|
|
- canvas.setAttribute("role", "presentation");
|
|
|
-
|
|
|
- canvas.hidden = true;
|
|
|
- let isCanvasHidden = true;
|
|
|
- const showCanvas = function () {
|
|
|
- if (isCanvasHidden) {
|
|
|
- canvas.hidden = false;
|
|
|
- isCanvasHidden = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- canvasWrapper.append(canvas);
|
|
|
- this.canvas = canvas
|
|
|
-
|
|
|
- const radio = window.devicePixelRatio || 1
|
|
|
- this.radio = radio
|
|
|
- const { width, height, scale } = viewport
|
|
|
-
|
|
|
- const canvasWidth = Math.round(width * radio)
|
|
|
- const canvasHeight = Math.round(height * radio)
|
|
|
-
|
|
|
- canvas.width = canvasWidth
|
|
|
- canvas.height = canvasHeight
|
|
|
- const { style } = canvas;
|
|
|
- style.width = Math.round(width) + "px"
|
|
|
- style.height = Math.round(height) + "px"
|
|
|
-
|
|
|
- this.paintedViewportMap.set(canvas, viewport)
|
|
|
-
|
|
|
- const renderTask = (this.renderTask = this.internalRenderTask({
|
|
|
- width,
|
|
|
- height,
|
|
|
- scale: scale * radio
|
|
|
- }))
|
|
|
-
|
|
|
- const resultPromise = renderTask.promise.then(
|
|
|
- async () => {
|
|
|
- showCanvas();
|
|
|
- await this.finishRenderTask();
|
|
|
-
|
|
|
- this.#renderTextLayer();
|
|
|
-
|
|
|
- if (this.annotationLayer) {
|
|
|
- await this._renderAnnotationLayer();
|
|
|
- }
|
|
|
-
|
|
|
- if (!this.annotationEditorLayer) {
|
|
|
- const { annotationEditorUIManager, annotationStorage } = this.layerProperties();
|
|
|
-
|
|
|
- if (!annotationEditorUIManager) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.annotationEditorLayer = new PDFAnnotationLayer({
|
|
|
- uiManager: annotationEditorUIManager,
|
|
|
- annotationStorage,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- annotations,
|
|
|
- accessibilityManager: this._accessibilityManager,
|
|
|
- });
|
|
|
- }
|
|
|
- this._renderAnnotationEditorLayer();
|
|
|
-
|
|
|
- if (!this.compdfAnnotationLayer) {
|
|
|
- this.compdfAnnotationLayer = new ComPDFAnnotationLayer({
|
|
|
- documentViewer: this.documentViewer,
|
|
|
- annotationStore: this.annotationStore,
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- pageViewer: this,
|
|
|
- annotations,
|
|
|
- annotationsAll,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- enableReply: this.enableReply,
|
|
|
- $t: this.$t
|
|
|
- })
|
|
|
- }
|
|
|
- this.compdfAnnotationLayer.render(this.viewport)
|
|
|
-
|
|
|
- // this.AnnotationManager = new AnnotationManager({
|
|
|
- // annotations,
|
|
|
- // container: div,
|
|
|
- // viewport: this.viewport,
|
|
|
- // })
|
|
|
-
|
|
|
- if (!this.contentContainer) {
|
|
|
- this.contentContainer = new ContentContainer({
|
|
|
- annotationStore: this.annotationStore,
|
|
|
- pageViewer: this,
|
|
|
- annotations,
|
|
|
- annotationsAll,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- $t: this.$t,
|
|
|
- contentEditHistoryManager: this.contentEditHistoryManager
|
|
|
- })
|
|
|
- this.mode === 'editor' && this.contentContainer.init()
|
|
|
- } else if (this.mode === 'editor') {
|
|
|
- await this.contentContainer.render()
|
|
|
- }
|
|
|
-
|
|
|
- if (!this.textSelection) {
|
|
|
- this.textSelection = new TextSelection({
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- container: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex],
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- tool: this.tool,
|
|
|
- toolMode: this.toolMode,
|
|
|
- color: this.color,
|
|
|
- pageViewer: this
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- if (!this.textSearch) {
|
|
|
- this.textSearch = new TextSearch({
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- container: div,
|
|
|
- results: this.searchResults,
|
|
|
- })
|
|
|
- if (this.#activeSearch) {
|
|
|
- this.textSearch.setActiveSearchResult(this.#activeSearch)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (this.cropPage?.cropping) {
|
|
|
- this.cropPage.draw()
|
|
|
- }
|
|
|
- if (!this.cropPage) {
|
|
|
- this.cropPage = new CropPage({
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- container: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex],
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- tool: this.tool,
|
|
|
- toolMode: this.toolMode,
|
|
|
- color: this.color,
|
|
|
- pageViewer: this,
|
|
|
- annotationStore: this.annotationStore
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.cropPage.updateInitialProps()
|
|
|
- }
|
|
|
- if (this.tool === 'cropPage') {
|
|
|
- this.cropPage.init()
|
|
|
- }
|
|
|
- },
|
|
|
- error => {
|
|
|
- console.log(error)
|
|
|
- return this.finishRenderTask(error);
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- div.setAttribute("data-loaded", true);
|
|
|
-
|
|
|
- this.eventBus.dispatch("pagerender", {
|
|
|
- source: this,
|
|
|
- pageNumber: this.id,
|
|
|
- });
|
|
|
- return resultPromise
|
|
|
- }
|
|
|
-
|
|
|
internalRenderTask({
|
|
|
width,
|
|
|
height,
|