RED-6240 - Use Applied Redaction Color in Preview mode

This commit is contained in:
Valentin Mihai 2023-04-03 16:21:14 +03:00
parent cc606ffbe3
commit c4300949d6
4 changed files with 40 additions and 26 deletions

View File

@ -243,8 +243,8 @@ export class FilePreviewScreenComponent
const nonRedactionEntries = annotations.filter(
a => !bool(a.getCustomData('redaction')) || bool(a.getCustomData('changeLogRemoved')),
);
this._readableRedactionsService.setPreviewAnnotationsOpacity(redactions);
this._readableRedactionsService.setPreviewAnnotationsColor(redactions);
this._readableRedactionsService.setAnnotationsColor(redactions, 'redactionColor');
this._readableRedactionsService.setAnnotationsOpacity(redactions);
this._annotationManager.show(redactions);
this._annotationManager.hide(nonRedactionEntries);
this._suggestionsService.hideSuggestionsInPreview(redactions);
@ -694,9 +694,14 @@ export class FilePreviewScreenComponent
this.addActiveScreenSubscription = combineLatest([this._viewModeService.viewMode$, this.state.file$, this._documentViewer.loaded$])
.pipe(
map(
([viewMode, file]) => ['STANDARD', 'TEXT_HIGHLIGHTS'].includes(viewMode) && this.permissionsService.canRotatePage(file),
),
map(([viewMode, file]) => {
if (viewMode === 'REDACTED' && !this._readableRedactionsService.active) {
this._readableRedactionsService.setCustomDrawHandler();
} else {
this._readableRedactionsService.restoreDraw();
}
return ['STANDARD', 'TEXT_HIGHLIGHTS'].includes(viewMode) && this.permissionsService.canRotatePage(file);
}),
tap(canRotate =>
canRotate ? this._viewerHeaderService.enableRotationButtons() : this._viewerHeaderService.disableRotationButtons(),
),

View File

@ -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);
}

View File

@ -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 {
@ -167,8 +166,7 @@ export class AnnotationDrawService {
annotationWrapper.isSuggestion && this._userPreferenceService.getDisplaySuggestionsInPreview()
? this._defaultColorsService.getColor(dossierTemplateId, 'requestAddColor')
: this._defaultColorsService.getColor(dossierTemplateId, 'previewColor');
annotation.setCustomData('redactionColor', String(redactionColor));
annotation.setCustomData('finalRedactionColor', FINAL_REDACTION_COLOR);
annotation.setCustomData('redactionColor', '#0000BB');
annotation.setCustomData('annotationColor', String(annotationWrapper.color));
return annotation;

View File

@ -48,6 +48,33 @@ 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';
ctx.fillStyle = annotation.getCustomData('redactionColor');
ctx.fillRect(annotation.getX(), annotation.getY(), annotation.getWidth(), annotation.getHeight());
},
{
generateAppearance: false,
},
);
}
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 +90,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);
});
}
}