From 83e9f53940b667cef642a5c98f9a78dcd78e96ce Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Wed, 10 Nov 2021 09:45:08 +0200 Subject: [PATCH] some code cleanup --- .../services/annotation-actions.service.ts | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts index d257e5cc6..32d5004e0 100644 --- a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts @@ -398,8 +398,6 @@ export class AnnotationActionsService { viewerAnnotation.setRotationControlEnabled(false); annotationManager.redrawAnnotation(viewerAnnotation); annotationManager.selectAnnotation(viewerAnnotation); - - // console.log(viewerAnnotation); } private async _extractTextAndPositions(viewer: WebViewerInstance, annotationId: string) { @@ -407,35 +405,37 @@ export class AnnotationActionsService { const document = await viewer.Core.documentViewer.getDocument().getPDFDoc(); const page = await document.getPage(viewerAnnotation.getPageNumber()); - let quads = (viewerAnnotation).Quads; - if (!quads) { - quads = [this._annotationDrawService.annotationToQuads(viewerAnnotation, viewer)]; - const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quads[0]); + if (viewerAnnotation instanceof Core.Annotations.TextHighlightAnnotation) { + const words = []; + const rectangles: IRectangle[] = []; + for (const quad of viewerAnnotation.Quads) { + const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quad); + rectangles.push(rect); + const pdfNetRect = new viewer.Core.PDFNet.Rect( + rect.topLeft.x, + rect.topLeft.y, + rect.topLeft.x + rect.width, + rect.topLeft.y + rect.height, + ); + const quadWords = await this._extractTextFromRect(viewer, page, pdfNetRect); + words.push(...quadWords); + } + + return { + text: words.join(' '), + positions: rectangles, + }; + } else { + const rect = toPosition( + viewerAnnotation.getPageNumber(), + await page.getPageHeight(), + this._annotationDrawService.annotationToQuads(viewerAnnotation, viewer), + ); return { positions: [rect], text: null, }; } - - const words = []; - const rectangles: IRectangle[] = []; - for (const quad of quads) { - const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quad); - rectangles.push(rect); - const pdfNetRect = new viewer.Core.PDFNet.Rect( - rect.topLeft.x, - rect.topLeft.y, - rect.topLeft.x + rect.width, - rect.topLeft.y + rect.height, - ); - const quadWords = await this._extractTextFromRect(viewer, page, pdfNetRect); - words.push(...quadWords); - } - - return { - text: words.join(' '), - positions: rectangles, - }; } private async _extractTextFromRect(viewer: WebViewerInstance, page: Core.PDFNet.Page, rect: Core.PDFNet.Rect) {