diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index 981901ba0..e3fc9b7ec 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -243,8 +243,10 @@ export class FilePreviewScreenComponent const nonRedactionEntries = annotations.filter( a => !bool(a.getCustomData('redaction')) || bool(a.getCustomData('changeLogRemoved')), ); - this._readableRedactionsService.setPreviewAnnotationsOpacity(redactions); - this._readableRedactionsService.setPreviewAnnotationsColor(redactions); + if (this._readableRedactionsService.active) { + this._readableRedactionsService.setAnnotationsColor(redactions, 'redactionColor'); + this._readableRedactionsService.setAnnotationsOpacity(redactions); + } this._annotationManager.show(redactions); this._annotationManager.hide(nonRedactionEntries); this._suggestionsService.hideSuggestionsInPreview(redactions); @@ -698,6 +700,11 @@ export class FilePreviewScreenComponent ? this._viewerHeaderService.enableRotationButtons() : this._viewerHeaderService.disableRotationButtons(), ), + tap(viewMode => + viewMode === 'REDACTED' && !this._readableRedactionsService.active + ? this._readableRedactionsService.setCustomDrawHandler() + : this._readableRedactionsService.restoreDraw(), + ), ) .subscribe(); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts index 31deca85d..9d81f0a65 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts @@ -42,8 +42,8 @@ export class SuggestionsService { #convertSuggestionsToRedactions(suggestions: Annotation[]): void { suggestions = this.#filterSuggestions(suggestions); suggestions.forEach(s => s.setCustomData('suggestion', 'false')); - this._readableRedactionsService.setPreviewAnnotationsOpacity(suggestions); - this._readableRedactionsService.setPreviewAnnotationsColor(suggestions); + this._readableRedactionsService.setAnnotationsColor(suggestions, 'redactionColor'); + this._readableRedactionsService.setAnnotationsOpacity(suggestions); this._annotationManager.show(suggestions); } diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts index 8f7b17d59..17dc374e7 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts @@ -19,7 +19,6 @@ import Quad = Core.Math.Quad; const DEFAULT_TEXT_ANNOTATION_OPACITY = 1; const DEFAULT_REMOVED_ANNOTATION_OPACITY = 0.2; -const FINAL_REDACTION_COLOR = '#000000'; @Injectable() export class AnnotationDrawService { @@ -165,7 +164,6 @@ export class AnnotationDrawService { ? this._defaultColorsService.getColor(dossierTemplateId, 'requestAddColor') : this._defaultColorsService.getColor(dossierTemplateId, 'previewColor'); annotation.setCustomData('redactionColor', String(redactionColor)); - annotation.setCustomData('finalRedactionColor', FINAL_REDACTION_COLOR); annotation.setCustomData('annotationColor', String(annotationWrapper.color)); return annotation; diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts index 96e2fd278..50e09f693 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts @@ -48,6 +48,36 @@ export class ReadableRedactionsService { title: this.toggleReadableRedactionsBtnTitle, img: this.toggleReadableRedactionsBtnIcon, }); + + if (!this.active) { + this.setCustomDrawHandler(); + } else { + this.restoreDraw(); + } + } + + setCustomDrawHandler(): void { + const annotationClass: any = this._pdf.instance.Core.Annotations.TextHighlightAnnotation; + this._pdf.instance.Core.Annotations.setCustomDrawHandler( + annotationClass, + (ctx: CanvasRenderingContext2D, pageMatrix, rotation, options) => { + const annotation = options.annotation; + ctx.globalCompositeOperation = 'source-over'; + + (options.annotation as any).Quads.forEach(q => { + const yMin = Math.min(q.y1, q.y2, q.y3, q.y4); + const height = Math.sqrt(Math.pow(q.x1 - q.x4, 2) + Math.pow(q.y1 - q.y4, 2)); + const width = Math.sqrt(Math.pow(q.x1 - q.x2, 2) + Math.pow(q.y1 - q.y2, 2)); + ctx.fillStyle = annotation.getCustomData('redactionColor'); + ctx.fillRect(q.x1, yMin, width, height); + }); + }, + ); + } + + restoreDraw(): void { + const annotationClass: any = this._pdf.instance.Core.Annotations.TextHighlightAnnotation; + this._pdf.instance.Core.Annotations.restoreDraw(annotationClass); } setAnnotationsOpacity(annotations: Annotation[], restoreToOriginal = false) { @@ -63,20 +93,4 @@ export class ReadableRedactionsService { annotation['FillColor'] = color; }); } - - setPreviewAnnotationsOpacity(annotations: Annotation[]) { - annotations.forEach(annotation => { - const isSuggestion = bool(annotation.getCustomData('suggestion')); - const restoreToOriginal = !this.active && !isSuggestion; - this.setAnnotationsOpacity([annotation], restoreToOriginal); - }); - } - - setPreviewAnnotationsColor(annotations: Annotation[]) { - annotations.forEach(annotation => { - const isSuggestion = bool(annotation.getCustomData('suggestion')); - const color = this.active || isSuggestion ? 'redactionColor' : 'finalRedactionColor'; - this.setAnnotationsColor([annotation], color); - }); - } } diff --git a/apps/red-ui/src/app/services/notifications.service.ts b/apps/red-ui/src/app/services/notifications.service.ts index 3a8297b12..399cc5734 100644 --- a/apps/red-ui/src/app/services/notifications.service.ts +++ b/apps/red-ui/src/app/services/notifications.service.ts @@ -89,19 +89,6 @@ export class NotificationsService extends EntitiesService