From c8a63b9aa4b6973f7a2e62cd5b8f691041ce0df8 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sun, 12 Sep 2021 12:23:34 +0300 Subject: [PATCH] update pdfviewer utils --- .../modules/dossier/utils/pdf-viewer.utils.ts | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts index 40193f2c3..625355307 100644 --- a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts +++ b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts @@ -1,4 +1,3 @@ -// import { Annotations, WebViewerInstance } from '@pdftron/webviewer'; import { ViewMode } from '@models/file/view-mode'; import { translateQuads } from '@utils/pdf-coordinates'; import { Rectangle } from '@redaction/red-ui-http'; @@ -37,18 +36,19 @@ const DISABLED_HOTKEYS = [ 'H', 'K', 'U' -]; +] as const; export class PdfViewerUtils { - instance: WebViewerInstance; - viewMode: ViewMode; ready = false; - multiSelectActive: boolean; - constructor(instance: WebViewerInstance, viewMode: ViewMode, multiSelectActive: boolean) { - this.instance = instance; - this.viewMode = viewMode; - this.multiSelectActive = multiSelectActive; + constructor(readonly instance: WebViewerInstance, public viewMode: ViewMode, public multiSelectActive: boolean) {} + + private get _documentViewer() { + return this.instance?.Core.documentViewer; + } + + private get _annotationManager() { + return this.instance?.Core.annotationManager; } get isCompareMode() { @@ -61,9 +61,7 @@ export class PdfViewerUtils { get currentPage() { try { - return this.isCompareMode - ? Math.ceil(this.instance?.Core.documentViewer?.getCurrentPage() / 2) - : this.instance?.Core.documentViewer?.getCurrentPage(); + return this.isCompareMode ? Math.ceil(this._currentInternalPage / 2) : this._currentInternalPage; } catch (e) { return null; } @@ -75,9 +73,7 @@ export class PdfViewerUtils { } try { - return this.isCompareMode - ? Math.ceil(this.instance?.Core.documentViewer?.getPageCount() / 2) - : this.instance?.Core.documentViewer?.getPageCount(); + return this.isCompareMode ? Math.ceil(this._totalInternalPages / 2) : this._totalInternalPages; } catch (e) { return null; } @@ -115,12 +111,12 @@ export class PdfViewerUtils { } translateQuads(page: number, quads: any) { - const rotation = this.instance.Core.documentViewer.getCompleteRotation(page); + const rotation = this._documentViewer.getCompleteRotation(page); return translateQuads(page, rotation, quads); } toPosition(page: number, selectedQuad: any): Rectangle { - const pageHeight = this.instance.Core.documentViewer.getPageHeight(page); + const pageHeight = this._documentViewer.getPageHeight(page); const height = selectedQuad.y2 - selectedQuad.y4; return { page: page, @@ -134,7 +130,7 @@ export class PdfViewerUtils { } deselectAllAnnotations() { - this.instance.Core.annotationManager.deselectAllAnnotations(); + this._annotationManager.deselectAllAnnotations(); } selectAnnotations($event: AnnotationWrapper[] | { annotations: AnnotationWrapper[]; multiSelect: boolean }) { @@ -153,24 +149,23 @@ export class PdfViewerUtils { } const annotationsFromViewer = annotations.map(ann => this._getAnnotationById(ann.id)); - this.instance.Core.annotationManager.selectAnnotations(annotationsFromViewer); + this._annotationManager.selectAnnotations(annotationsFromViewer); // this.navigateToPage(annotations[0].pageNumber*this.paginationOffset); - this.instance.Core.annotationManager.jumpToAnnotation(annotationsFromViewer[0]); + this._annotationManager.jumpToAnnotation(annotationsFromViewer[0]); } deselectAnnotations(annotations: AnnotationWrapper[]) { const ann = annotations.map(a => this._getAnnotationById(a.id)); - this.instance.Core.annotationManager.deselectAnnotations(ann); + this._annotationManager.deselectAnnotations(ann); } private _navigateToPage(pageNumber) { - const activePage = this.instance.Core.documentViewer.getCurrentPage(); - if (activePage !== pageNumber) { - this.instance.Core.documentViewer.displayPageLocation(pageNumber, 0, 0); + if (this._currentInternalPage !== pageNumber) { + this._documentViewer.displayPageLocation(pageNumber, 0, 0); } } private _getAnnotationById(id: string): Annotation { - return this.instance.Core.annotationManager.getAnnotationById(id); + return this._annotationManager.getAnnotationById(id); } }