@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
908 lines • 117 kB
JavaScript
import { updateColorWithOpacity } from '../../index';
import { Browser, isBlazor, isNullOrUndefined } from '@syncfusion/ej2-base';
/**
* RedactionAnnotation class to handle redaction annotations
*
* @hidden
*/
var Redaction = /** @class */ (function () {
/**
* Constructor for RedactionAnnotation class
* @param {PdfViewer} pdfviewer - The PDF Viewer instance
* @param {PdfViewerBase} pdfViewerBase - The PDF Viewer Base instance
*/
function Redaction(pdfviewer, pdfViewerBase) {
/**
* @private
*/
this.redactionPageNumbers = [];
/**
* @private
*/
this.redactionCount = 0;
/**
* @private
*/
this.isAddAnnotationProgramatically = false;
/**
* @private
*/
this.isRepeat = false;
/**
* @private
*/
this.overlayText = '';
/**
* @private
*/
this.isRedactionHovered = false;
this.previousTool = '';
this.isAnnotationHoverd = false;
this.hoveredRedactionAnnotName = '';
/**
* @private
*/
this.hoveredRedactionId = '';
this.pdfViewer = pdfviewer;
this.pdfViewerBase = pdfViewerBase;
this.initializeRedactionProperties();
}
/**
* Update annotation details for programmatic addition
* @param {RedactionSettingsModel} options - The redaction settings
* @param {IPoint} offset - The offset point
* @returns {any} The redaction annotation object
* @private
*/
Redaction.prototype.updateAddAnnotationDetails = function (options, offset) {
if (!options) {
offset = options.bound || { x: 10, y: 10 };
}
else {
offset.x = options.bound && !isNullOrUndefined(options.bound.x) ? options.bound.x : 10;
offset.y = options.bound && !isNullOrUndefined(options.bound.y) ? options.bound.y : 10;
}
// Initialize the annotation settings
var annotationSelectorSettings = options.annotationSelectorSettings ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.annotationSelectorSettings) ||
this.pdfViewer.annotationSelectorSettings;
var annotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.redactionSettings);
var allowedInteractions = options.allowedInteractions ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.allowedInteractions) ||
this.pdfViewer.annotationSettings.allowedInteractions;
// Creating the CurrentDate and Annotation name
var currentDateString = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
var annotationName = 'redaction_' + this.pdfViewer.annotation.createGUID();
// Get properties from options or default values
var pageNumber = options.pageNumber !== undefined ? options.pageNumber : 0;
var author = options.author ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.author) ||
this.pdfViewer.annotationSettings.author ||
'Guest';
var markerFillColor = this.pdfViewer.annotationModule.hexToRgba(options.markerFillColor ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.markerFillColor) ||
'rgba(255, 255, 255, 1)');
var fillColor = this.pdfViewer.annotationModule.hexToRgba(options.fillColor ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.fillColor) ||
'rgba(0, 0, 0, 0)');
var markerBorderColor = this.pdfViewer.annotationModule.
hexToRgba(options.markerBorderColor ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.markerBorderColor) ||
'rgba(255, 0, 0, 1)');
var markerOpacity = options.markerOpacity ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.markerOpacity) ||
1;
var isPrint = !isNullOrUndefined(options.isPrint) ?
!!options.isPrint :
(this.pdfViewer.redactionSettings && !isNullOrUndefined(this.pdfViewer.redactionSettings.isPrint)) ?
!!this.pdfViewer.redactionSettings.isPrint :
true;
var isLock = !isNullOrUndefined(options.isLock) ?
!!options.isLock :
(this.pdfViewer.redactionSettings && !isNullOrUndefined(this.pdfViewer.redactionSettings.isLock)) ?
!!this.pdfViewer.redactionSettings.isLock :
false;
var overlayText = options.overlayText ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.overlayText) ||
'';
var fontColor = this.pdfViewer.annotationModule.hexToRgba(options.fontColor ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.fontColor) ||
'rgba(255, 0, 0, 1)');
var fontSize = !isNullOrUndefined(options.fontSize) ?
options.fontSize || 10 :
(this.pdfViewer.redactionSettings && !isNullOrUndefined(this.pdfViewer.redactionSettings.fontSize)) ?
this.pdfViewer.redactionSettings.fontSize || 10 :
10;
var fontFamily = options.fontFamily ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.fontFamily) ||
'Helvetica';
var textAlign = options.textAlignment ||
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.textAlignment) ||
'center';
// Set width and height
var width = options.bound ? options.bound.width : 100;
var height = options.bound ? options.bound.height : 50;
// Update annotation settings
annotationSettings.isLock = isLock;
annotationSettings.minHeight = options.minHeight || 0;
annotationSettings.minWidth = options.minWidth || 0;
annotationSettings.maxWidth = options.maxWidth || 0;
annotationSettings.maxHeight = options.maxHeight || 0;
// Creating Redaction Annotation object with its proper properties
var redactionAnnotation = [];
var redaction = {
Id: ('redaction' + this.redactionCount++) || 'redaction_' + this.pdfViewer.annotation.createGUID(),
AllowedInteractions: options.allowedInteractions || allowedInteractions,
AnnotName: annotationName,
AnnotType: 'redaction',
AnnotationSelectorSettings: annotationSelectorSettings,
AnnotationSettings: annotationSettings,
Author: author,
Bounds: {
X: offset.x,
Y: offset.y,
Width: width,
Height: height,
Left: offset.x, Top: offset.y,
Location: { X: offset.x, Y: offset.y },
Size: { Height: height, IsEmpty: false, Width: width }
},
Comments: [],
CustomData: options.customData || null,
CreatedDate: currentDateString,
ExistingCustomData: null,
FillColor: fillColor,
FontColor: fontColor,
FontSize: fontSize,
FontFamily: fontFamily,
IsCommentLock: false,
IsLocked: isLock,
IsPrint: isPrint,
MarkerFillColor: markerFillColor,
MarkerBorderColor: markerBorderColor,
MarkerOpacity: markerOpacity,
ModifiedDate: currentDateString,
Note: '',
OverlayText: overlayText,
IsRepeat: options.isRepeat || false,
RotateAngle: 'RotateAngle0',
ShapeAnnotationType: 'Redaction',
State: '',
StateModel: 'Review',
Subject: 'Redaction',
TextAlign: textAlign
};
// Adding the annotation object to an array
redactionAnnotation[0] = redaction;
// Create the annotation collection for the page if it doesn't exist
var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_redaction');
var annotObject = [];
if (storeObject) {
annotObject = JSON.parse(JSON.stringify(storeObject));
}
// Create annotation object for storage
var annotationObject = {
shapeAnnotationType: 'Redaction',
author: author,
modifiedDate: currentDateString,
subject: 'Redaction',
note: '',
bounds: {
left: offset.x,
top: offset.y,
width: width,
height: height,
right: offset.x + width,
bottom: offset.y + height
},
rotateAngle: '0',
isLocked: isLock,
annotName: annotationName,
pageNumber: pageNumber,
annotationId: annotationName,
annotationSelectorSettings: annotationSelectorSettings,
customData: options.customData || {},
overlayText: overlayText,
isRepeat: options.isRepeat || false,
fontColor: fontColor,
fillColor: fillColor,
fontSize: fontSize,
fontFamily: fontFamily,
textAlign: textAlign,
markerFillColor: markerFillColor,
markerBorderColor: markerBorderColor,
markerOpacity: markerOpacity,
isPrint: isPrint,
id: redactionAnnotation[0].Id,
comments: [],
review: {},
isCommentLock: false,
isReadonly: false,
annotationSettings: annotationSettings,
allowedInteractions: allowedInteractions
};
var index = this.pdfViewer.annotation.getPageCollection(annotObject, pageNumber);
if (index === -1 || !annotObject[index]) {
var pageAnnotations = {
pageIndex: pageNumber,
annotations: [annotationObject]
};
annotObject.push(pageAnnotations);
}
else {
annotObject[index].annotations.push(annotationObject);
}
redactionAnnotation[0].Id = annotationObject.id;
// Return the annotation in the correct format for the pdfAnnotation object
return { redactionAnnotation: redactionAnnotation };
};
/**
* Handle redaction annotation hover
* @param {PdfAnnotationBaseModel} annotation - The annotation being hovered
* @param {number} pageIndex - The page index
* @param {any} currentAnnot - currentAnnot
* @returns {void}
* @private
*/
Redaction.prototype.handleRedactionHover = function (annotation, pageIndex, currentAnnot) {
var currentAnnotationId = annotation.id || '';
this.previousTool = this.pdfViewer.tool;
this.hoveredRedactionAnnotName = annotation.annotName;
var selectedAnnotationIsRedaction = false;
if (this.pdfViewer.selectedItems.annotations && this.pdfViewer.selectedItems.annotations.length > 0 && this.pdfViewer.selectedItems.annotations[0].id === 'diagram_helper') {
selectedAnnotationIsRedaction = true;
}
if (currentAnnotationId !== 'diagram_helper' && this.hoveredRedactionId !== 'diagram_helper' && !selectedAnnotationIsRedaction) {
// If hovering over a different annotation than before, reset the previous one
if (this.isRedactionHovered && this.hoveredRedactionId !== currentAnnotationId) {
this.resetRedactionHover();
}
// Apply hover effect to the current annotation
if (!this.isRedactionHovered || this.hoveredRedactionId !== currentAnnotationId) {
// Store the original fill color
annotation.originalFillColor = annotation.markerFillColor || '';
// Change the fill color to yellow on hover
if (annotation.wrapper && annotation.wrapper.children && annotation.wrapper.children.length > 0 && annotation.fillColor) {
var fillColor = updateColorWithOpacity(annotation.fillColor, 1);
annotation.wrapper.children[0].style.fill = fillColor;
annotation.wrapper.children[0].style.strokeColor = fillColor;
annotation.wrapper.children[0].style.opacity = 1;
}
if (annotation.annotationAddMode === 'TextRedaction') {
this.orginalFillColor = annotation.markerFillColor;
this.orginalBorderColor = annotation.markerBorderColor;
this.orginalOpacity = annotation.markerOpacity;
}
// Render overlay text if it exists
if (annotation.overlayText) {
this.pdfViewer.annotation.redactionOverlayTextModule.renderRedactionOverlayText(annotation, currentAnnot);
}
this.isAnnotationHoverd = true;
// Re-render the annotation with the new color
var canvasElement = document.getElementById(this.pdfViewer.element.id + '_annotationCanvas_' + pageIndex);
if (canvasElement) {
this.pdfViewer.renderDrawing(canvasElement, pageIndex);
}
this.isAnnotationHoverd = false;
// Set flag to prevent re-rendering on every mouse move
this.isRedactionHovered = true;
this.hoveredRedactionId = currentAnnotationId;
}
}
};
/**
* Reset redaction annotation hover state
* @returns {void}
* @private
*/
Redaction.prototype.resetRedactionHover = function () {
if (this.isRedactionHovered) {
this.pdfViewer.tool = this.previousTool;
this.previousTool = '';
this.isAnnotationHoverd = false;
// Check in selectedItems.annotations
if (this.pdfViewer.selectedItems && this.pdfViewer.selectedItems.annotations) {
for (var i = 0; i < this.pdfViewer.selectedItems.annotations.length; i++) {
var annotation = this.pdfViewer.selectedItems.annotations[i];
if (annotation && annotation.shapeAnnotationType === 'Redaction') {
// Remove overlay text
if (annotation.overlayText) {
this.pdfViewer.annotation.redactionOverlayTextModule.removeRedactionOverlayText(annotation);
}
// Reset fill color
if (annotation.originalFillColor) {
if (annotation.wrapper && annotation.wrapper.children && annotation.wrapper.children.length > 0) {
var opacity = annotation.markerOpacity > 1 ? annotation.markerOpacity / 100 :
annotation.markerOpacity;
var fillColor = updateColorWithOpacity(annotation.originalFillColor, annotation.markerOpacity);
annotation.wrapper.children[0].style.fill = fillColor;
annotation.wrapper.children[0].style.strokeColor = annotation.markerBorderColor;
annotation.wrapper.children[0].style.opacity = opacity;
}
delete annotation.originalFillColor;
}
// Re-render the annotation with the original color
var canvasElement = document.getElementById(this.pdfViewer.element.id + '_annotationCanvas_' + annotation.pageIndex);
if (canvasElement) {
this.pdfViewer.renderDrawing(canvasElement, annotation.pageIndex);
}
}
}
}
// Also check in nameTable
if (this.pdfViewer.nameTable) {
// If we have a specific hovered redaction ID, only reset that one
if (this.hoveredRedactionId && this.pdfViewer.nameTable[this.hoveredRedactionId]) {
var annotation = this.pdfViewer.nameTable[this.hoveredRedactionId];
if (annotation && annotation.shapeAnnotationType === 'Redaction') {
// Remove overlay text
if (annotation.overlayText) {
this.pdfViewer.annotation.redactionOverlayTextModule.removeRedactionOverlayText(annotation);
}
// Reset fill color
if (annotation.originalFillColor) {
if (annotation.wrapper && annotation.wrapper.children && annotation.wrapper.children.length > 0) {
var opacity = annotation.markerOpacity > 1 ? annotation.markerOpacity / 100 :
annotation.markerOpacity;
var fillColor = updateColorWithOpacity(annotation.originalFillColor, annotation.markerOpacity);
annotation.wrapper.children[0].style.fill = fillColor;
annotation.wrapper.children[0].style.strokeColor = annotation.markerBorderColor;
annotation.wrapper.children[0].style.opacity = opacity;
}
delete annotation.originalFillColor;
}
// Re-render the annotation with the original color
var canvasElement = document.getElementById(this.pdfViewer.element.id + '_annotationCanvas_' + annotation.pageIndex);
if (canvasElement) {
this.pdfViewer.renderDrawing(canvasElement, annotation.pageIndex);
}
}
}
else {
// Otherwise check all annotations in the nameTable
for (var key in this.pdfViewer.nameTable) {
if (Object.prototype.hasOwnProperty.call(this.pdfViewer.nameTable, key)) {
var annotation = this.pdfViewer.nameTable[key];
if (annotation && annotation.shapeAnnotationType === 'Redaction') {
// Remove overlay text
if (annotation.overlayText) {
this.pdfViewer.annotation.redactionOverlayTextModule.removeRedactionOverlayText(annotation);
}
// Reset fill color
if (annotation.originalFillColor) {
if (annotation.wrapper && annotation.wrapper.children && annotation.wrapper.children.length > 0) {
var opacity = annotation.markerOpacity > 1 ? annotation.markerOpacity / 100 :
annotation.markerOpacity;
var fillColor = updateColorWithOpacity(annotation.originalFillColor, annotation.markerOpacity);
annotation.wrapper.children[0].style.fill = fillColor;
annotation.wrapper.children[0].style.strokeColor = annotation.markerBorderColor;
annotation.wrapper.children[0].style.opacity = opacity;
}
delete annotation.originalFillColor;
}
// Re-render the annotation with the original color
var canvasElement = document.getElementById(this.pdfViewer.element.id + '_annotationCanvas_' + annotation.pageIndex);
if (canvasElement) {
this.pdfViewer.renderDrawing(canvasElement, annotation.pageIndex);
}
}
}
}
}
}
// Reset the hover state
this.isRedactionHovered = false;
this.hoveredRedactionId = '';
}
};
/**
* Initialize redaction properties with default values or from settings
* @returns {void}
* @private
*/
Redaction.prototype.initializeRedactionProperties = function () {
if (this.pdfViewer.redactionSettings) {
this.redactionFillColor = this.pdfViewer.redactionSettings.markerFillColor || 'rgba(0, 0, 0, 1)';
this.redactionMarkerFillColor = this.pdfViewer.redactionSettings.markerFillColor || 'rgba(255, 255, 255, 1)';
this.redactionBorderColor = this.pdfViewer.redactionSettings.markerBorderColor || 'rgba(255, 0, 0, 1)';
this.redactionOutlineOpacity = this.pdfViewer.redactionSettings.markerOpacity || 1;
}
else {
this.redactionFillColor = 'rgba(0, 0, 0, 1)';
this.redactionMarkerFillColor = 'rgba(255, 255, 255, 1)';
this.redactionBorderColor = 'rgba(255, 0, 0, 1)';
this.redactionOutlineOpacity = 1;
}
this.redactionPageNumbers = [];
};
/**
* Render redaction annotations on the page
* @param {any} redactionAnnotations - The redaction annotations to render
* @param {number} pageNumber - The page number to render on
* @param {boolean} isImportAction - Whether this is an import action
* @param {any} isAnnotOrderAction - Whether this is an isAnnotOrderAction
* @returns {void}
* @private
*/
Redaction.prototype.renderRedactionAnnotations = function (redactionAnnotations, pageNumber, isImportAction, isAnnotOrderAction) {
var isAdded = false;
if (!isImportAction) {
for (var p = 0; p < this.redactionPageNumbers.length; p++) {
if (this.redactionPageNumbers[parseInt(p.toString(), 10)] === pageNumber) {
var pageAnnotations = this.getAnnotations(pageNumber, null);
// Check if annotation already exists
if (pageAnnotations !== null && redactionAnnotations) {
for (var k = 0; k < pageAnnotations.length; k++) {
for (var l = 0; l < pageAnnotations.length; l++) {
var redactAnnot = redactionAnnotations[l] ? redactionAnnotations[l] :
redactionAnnotations;
var annotationName = redactAnnot.annotName ?
redactAnnot.annotName : redactAnnot.AnnotName;
var pageAnnotationName = pageAnnotations[k].annotName ?
pageAnnotations[k].annotName : pageAnnotations[k].AnnotName;
if (pageAnnotationName && annotationName && pageAnnotationName === annotationName) {
isAdded = true;
break;
}
}
if (isAdded) {
break;
}
}
}
break;
}
}
}
if (redactionAnnotations && (!isAdded || isAnnotOrderAction)) {
if (redactionAnnotations.length > 0) {
this.redactionPageNumbers.push(pageNumber);
for (var i = 0; i < redactionAnnotations.length; i++) {
var annotation = redactionAnnotations[i];
annotation.annotationAddMode =
this.pdfViewer.annotationModule.findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
var annotationObject = {};
var position = annotation.Bound ? annotation.Bound : annotation.Bounds;
var author = annotation.Author || '';
annotation.AnnotationSettings = annotation.AnnotationSettings ?
annotation.AnnotationSettings : this.pdfViewer.annotationModule.updateAnnotationSettings(annotation);
annotation.allowedInteractions = annotation.AllowedInteractions ?
annotation.AllowedInteractions :
this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
var isPrint = true;
if (!isNullOrUndefined(annotation.IsPrint)) {
isPrint = annotation.IsPrint;
}
else {
isPrint = !isNullOrUndefined(annotation.isPrint) ? annotation.isPrint : annotation.AnnotationSettings.isPrint;
}
if (annotation.IsLocked) {
annotation.AnnotationSettings.isLock = annotation.IsLocked;
}
// Create redaction annotation object
annotationObject = {
shapeAnnotationType: 'Redaction',
author: author,
modifiedDate: annotation.ModifiedDate || new Date().toLocaleString(),
subject: annotation.Subject || '',
note: annotation.Note || '',
bounds: {
left: position.X,
top: position.Y,
width: position.Width,
height: position.Height,
right: position.Right,
bottom: position.Bottom
},
rotateAngle: annotation.RotateAngle || '0',
isLocked: annotation.IsLocked || false,
annotName: annotation.AnnotName,
pageNumber: pageNumber,
annotationSelectorSettings: annotation.AnnotationSelectorSettings || this.pdfViewer.annotationSelectorSettings,
customData: this.pdfViewer.annotation.getCustomData(annotation),
overlayText: annotation.OverlayText || '',
isRepeat: annotation.IsRepeat,
fontColor: annotation.FontColor || 'rgba(255, 0, 0, 1)',
fillColor: annotation.FillColor || 'rgba(0, 0, 0, 1)',
fontSize: annotation.FontSize || 14,
fontFamily: annotation.FontFamily || 'Helvetica',
textAlign: annotation.TextAlign || 'center',
markerFillColor: annotation.MarkerFillColor || 'rgba(255, 255, 255, 1)',
markerBorderColor: annotation.MarkerBorderColor || 'rgba(255, 0, 0, 1)',
markerOpacity: annotation.MarkerOpacity || 1,
annotationSettings: annotation.AnnotationSettings,
allowedInteractions: annotation.allowedInteractions,
isPrint: isPrint,
annotationId: annotation.AnnotName || '',
id: (annotation.Id || ('redaction' + this.redactionCount++) || this.pdfViewer.annotationModule.createGUID() || 'redaction_id'),
comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author),
review: {
state: annotation.State, stateModel: annotation.StateModel,
modifiedDate: annotation.ModifiedDate, author: annotation.Author
},
isCommentLock: false,
isReadonly: annotation.IsReadonly || false
};
// Create PdfAnnotationBaseModel for redaction
var annot = {
author: author,
modifiedDate: annotationObject.modifiedDate,
annotName: annotationObject.annotName,
pageIndex: pageNumber,
bounds: {
x: position.X,
y: position.Y,
width: position.Width,
height: position.Height
},
strokeColor: annotationObject.markerBorderColor,
fillColor: annotationObject.fillColor,
thickness: 1,
comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author),
id: annotationObject.id,
shapeAnnotationType: 'Redaction',
annotType: 'Redaction',
subject: annotationObject.subject,
notes: annotationObject.note,
annotationSelectorSettings: annotationObject.annotationSelectorSettings,
annotationSettings: annotationObject.annotationSettings,
annotationAddMode: annotation.annotationAddMode,
allowedInteractions: annotation.allowedInteractions,
isLocked: annotation.isLocked,
isPrint: isPrint,
overlayText: annotationObject.overlayText,
isRepeat: annotationObject.isRepeat,
markerFillColor: annotationObject.markerFillColor,
markerBorderColor: annotationObject.markerBorderColor || 'rgba(255, 0, 0, 1)',
markerOpacity: annotationObject.markerOpacity || 1,
fontColor: annotationObject.fontColor,
fontSize: annotationObject.fontSize,
fontFamily: annotationObject.fontFamily,
textAlign: annotationObject.textAlign
};
// Add the annotation to the viewer
this.pdfViewer.add(annot);
// // Draw the redaction annotation
this.drawRedactionAnnotation(pageNumber, annot);
// Store in session storage
this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotationObject, '_annotations_redaction');
// Fire annotation add event if needed
if (this.isAddAnnotationProgramatically) {
var settings = {
shapeAnnotationType: annotationObject.shapeAnnotationType,
markerBorderColor: annot.strokeColor,
markerFillColor: annotationObject.markerFillColor,
opacity: annot.opacity,
overlayText: annotationObject.overlayText || '',
fontColor: annotationObject.fontColor,
fontSize: annotationObject.fontSize || 14,
fontFamily: annotationObject.fontFamily,
textAlign: annotationObject.textAlign,
author: author,
subject: annotationObject.subject,
modifiedDate: annotationObject.modifiedDate
};
this.pdfViewer.fireAnnotationAdd(annot.pageIndex || 0, annot.annotName || '', 'Redaction', annot.bounds, settings);
}
}
if (this.pdfViewer.toolbarModule && this.pdfViewer.toolbarModule.redactionToolbarModule) {
this.pdfViewer.toolbarModule.redactionToolbarModule.showHideRedactIcon(true);
}
}
else if (redactionAnnotations.shapeAnnotationType && redactionAnnotations.shapeAnnotationType === 'Redaction') {
var annotation = this.createAnnotationObject(redactionAnnotations);
if (!isNullOrUndefined(redactionAnnotations.formFieldAnnotationType) &&
redactionAnnotations.formFieldAnnotationType !== '') {
this.pdfViewer.annotationModule.isFormFieldShape = true;
}
else {
this.pdfViewer.annotationModule.isFormFieldShape = false;
}
if (annotation) {
this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotation, '_annotations_redaction');
this.pdfViewer.annotationModule.triggerAnnotationAdd(redactionAnnotations);
}
}
}
};
Redaction.prototype.createAnnotationObject = function (annotation) {
var bounds;
var annotationName = this.pdfViewer.annotation.createGUID();
if (!annotation.formFieldAnnotationType) {
var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('redaction', (annotation.pageIndex + 1), annotation.shapeAnnotationType);
if (commentsDivid) {
document.getElementById(commentsDivid).id = annotationName;
}
}
if (annotation.id) {
var obj = this.pdfViewer.nameTable[annotation.id];
this.updateRedactionProperties(obj);
}
annotation.annotName = annotationName;
if (annotation.wrapper.bounds) {
bounds = {
left: annotation.wrapper.bounds.x,
top: annotation.wrapper.bounds.y, height: annotation.wrapper.bounds.height, width: annotation.wrapper.bounds.width,
right: annotation.wrapper.bounds.right, bottom: annotation.wrapper.bounds.bottom
};
}
else {
bounds = {
left: 0, top: 0, height: 0, width: 0, right: 0, bottom: 0
};
}
var annotationObject = {
shapeAnnotationType: 'Redaction',
author: annotation.author,
modifiedDate: annotation.modifiedDate || new Date().toLocaleString(),
subject: annotation.subject || '',
note: annotation.note || '',
bounds: bounds,
rotateAngle: annotation.rotateAngle || '0',
isLocked: annotation.isLocked || false,
annotName: annotation.annotName,
pageNumber: annotation.pageIndex,
annotationSelectorSettings: annotation.annotationSelectorSettings || this.pdfViewer.annotationSelectorSettings,
customData: this.pdfViewer.redactionSettings.customData || {},
overlayText: annotation.overlayText || '',
isRepeat: annotation.isRepeat,
fontColor: annotation.fontColor || 'rgba(255, 0, 0, 1)',
fillColor: annotation.fillColor || 'rgba(0, 0, 0, 1)',
fontSize: annotation.fontSize || 14,
fontFamily: annotation.fontFamily || 'Helvetica',
textAlign: annotation.textAlign || 'center',
markerFillColor: annotation.markerFillColor || 'rgba(255, 255, 255, 1)',
markerBorderColor: annotation.markerBorderColor || 'rgba(255, 0, 0, 1)',
markerOpacity: annotation.markerOpacity || 1,
annotationSettings: annotation.annotationSettings,
allowedInteractions: this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation),
isPrint: annotation.isPrint,
annotationId: annotation.annotName || '',
id: annotation.id || '',
comments: annotation.comments,
isCommentLock: annotation.isCommentLock,
isReadonly: annotation.isReadonly || false,
review: {
state: '',
stateModel: '',
modifiedDate: this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(),
author: annotation.author
}
};
this.updateRedactionProperties(annotationObject);
return annotationObject;
};
Redaction.prototype.updateRedactionProperties = function (annotation) {
if (!this.pdfViewer.redactionSettings) {
return;
}
var rs = this.pdfViewer.redactionSettings;
annotation.fillColor = !isNullOrUndefined(rs.fillColor) ? rs.fillColor : !isNullOrUndefined(annotation.fillColor) ? annotation.fillColor : 'rgba(0, 0, 0, 1)';
annotation.fontColor = !isNullOrUndefined(rs.fontColor) ? rs.fontColor : !isNullOrUndefined(annotation.fontColor) ? annotation.fontColor : 'rgba(255, 0, 0, 1)';
annotation.isRepeat = !isNullOrUndefined(rs.isRepeat) ? rs.isRepeat :
!isNullOrUndefined(annotation.isRepeat) ? annotation.isRepeat : false;
annotation.overlayText = !isNullOrUndefined(rs.overlayText) ? rs.overlayText : !isNullOrUndefined(annotation.overlayText) ? annotation.overlayText : '';
annotation.fontSize = !isNullOrUndefined(rs.fontSize) ? rs.fontSize :
!isNullOrUndefined(annotation.fontSize) ? annotation.fontSize : 14;
annotation.fontFamily = !isNullOrUndefined(rs.fontFamily) ? rs.fontFamily : !isNullOrUndefined(annotation.fontFamily) ? annotation.fontFamily : 'Helvetica';
annotation.textAlign = !isNullOrUndefined(rs.textAlignment) ? rs.textAlignment : !isNullOrUndefined(annotation.textAlign) ? annotation.textAlign : 'center';
annotation.markerFillColor = !isNullOrUndefined(rs.markerFillColor) ? rs.markerFillColor : !isNullOrUndefined(annotation.markerFillColor) ? annotation.markerFillColor : 'rgba(255, 255, 255, 1)';
annotation.markerBorderColor = !isNullOrUndefined(rs.markerBorderColor) ? rs.markerBorderColor : !isNullOrUndefined(annotation.markerBorderColor) ? annotation.markerBorderColor : 'rgba(255, 0, 0, 1)';
annotation.markerOpacity = !isNullOrUndefined(rs.markerOpacity) ? rs.markerOpacity :
!isNullOrUndefined(annotation.markerOpacity) ? annotation.markerOpacity : 1;
};
Redaction.prototype.drawRedactionAnnotation = function (pageNumber, annotation, canvas) {
var bounds = annotation.bounds;
if (canvas) {
this.pdfViewer.renderDrawing(canvas, pageNumber);
}
else {
var canvasElement = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageNumber);
if (canvasElement) {
this.pdfViewer.renderDrawing(canvasElement, pageNumber);
}
}
};
/**
* Get annotation settings specific to redaction
* @param {any} annotation - The annotation to get settings for
* @returns {any} The annotation settings
* @private
*/
Redaction.prototype.getSettings = function (annotation) {
var settings = {};
settings.pageNumber = annotation.pageNumber;
settings.bounds = annotation.bounds;
settings.annotationSelectorSettings = this.getSelector('Redaction', annotation.subject);
settings.markerFillColor = annotation.markerFillColor || this.redactionFillColor;
settings.markerBorderColor = annotation.markerBorderColor || this.redactionBorderColor;
settings.markerOpacity = annotation.markerOpacity || this.redactionOutlineOpacity;
// settings.opacity = annotation.opacity || this.redactionOpacity;
settings.overlayText = annotation.overlayText || '';
settings.fontColor = annotation.fontColor || 'rgba(255, 0, 0, 1)';
settings.fontSize = annotation.fontSize || 14;
settings.fontFamily = annotation.fontFamily || 'Helvetica';
settings.textAlign = annotation.textAlign || 'center';
return settings;
};
/**
* Set annotation type to Redaction
* @param {AnnotationType} type - The annotation type
* @returns {void}
* @private
*/
Redaction.prototype.setAnnotationType = function (type) {
if (type === 'Redaction') {
this.initializeRedactionProperties();
// this.pdfViewerBase.disableTextSelectionMode();
var modifiedDate = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
var author = (this.pdfViewer.annotationSettings.author !== 'Guest') ?
this.pdfViewer.annotationSettings.author :
(this.pdfViewer.redactionSettings && this.pdfViewer.redactionSettings.author) ?
this.pdfViewer.redactionSettings.author : 'Guest';
var opacity = this.pdfViewer.redactionSettings.markerOpacity ? (this.pdfViewer.redactionSettings.markerOpacity > 1 ?
(this.pdfViewer.redactionSettings.markerOpacity / 100) : this.pdfViewer.redactionSettings.markerOpacity) : 1;
this.pdfViewer.drawingObject = {
shapeAnnotationType: 'Redaction',
// type: 'Redaction',
strokeColor: this.redactionBorderColor,
fillColor: this.pdfViewer.redactionSettings.fillColor || 'rgba(0, 0, 0, 1)',
fontColor: this.pdfViewer.redactionSettings.fontColor || 'rgba(255, 0, 0, 1)',
opacity: opacity,
notes: '',
thickness: 1,
fontSize: 14,
fontFamily: 'Helvetica',
borderDashArray: '0',
textAlign: 'center',
modifiedDate: modifiedDate,
author: author,
subject: 'Redaction',
overlayText: this.pdfViewer.redactionSettings.overlayText || '',
markerFillColor: this.redactionMarkerFillColor,
markerBorderColor: this.redactionBorderColor,
markerOpacity: this.redactionOutlineOpacity,
isCommentLock: false
};
this.pdfViewer.tool = 'DrawTool';
}
};
/**
* Update redaction annotation collections
* @param {any} annotation - The annotation to update
* @param {number} pageNumber - The page number
* @returns {IRedactionAnnotation | null} The updated annotation object
* @private
*/
Redaction.prototype.updateRedactionAnnotationCollections = function (annotation, pageNumber) {
var currentAnnotObject = null;
if (annotation) {
var isLock = false;
if (annotation.IsLocked) {
isLock = annotation.IsLocked;
}
var author = annotation.Author || '';
var allowedInteractions = annotation.AllowedInteractions ||
this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
if (annotation.Bound) {
var annotationObject = {
id: 'redaction' + this.redactionCount++,
shapeAnnotationType: 'Redaction',
author: author,
modifiedDate: annotation.ModifiedDate || new Date().toLocaleString(),
subject: annotation.Subject || '',
note: annotation.Note || '',
overlayText: annotation.OverlayText || '',
fontColor: annotation.FontColor || 'rgba(255, 0, 0, 1)',
fontSize: annotation.FontSize || 14,
fontFamily: annotation.FontFamily || 'Helvetica',
textAlign: annotation.TextAlign || 'center',
markerFillColor: annotation.MarkerFillColor || 'rgba(255, 255, 255, 1)',
markerBorderColor: annotation.MarkerBorderColor || 'rgba(255, 0, 0, 1)',
markerOpacity: annotation.MarkerOpacity || 1,
fillColor: annotation.fillColor || 'rgba(0, 0, 0, 1)',
isRepeat: annotation.IsRepeat || false,
bounds: {
left: annotation.Bound.X,
top: annotation.Bound.Y,
width: annotation.Bound.Width,
height: annotation.Bound.Height,
right: annotation.Bound.Right,
bottom: annotation.Bound.Bottom
},
rotateAngle: annotation.RotateAngle || '0',
isLocked: isLock,
annotationId: annotation.AnnotName,
pageNumber: pageNumber,
customData: this.pdfViewer.annotation.getCustomData(annotation),
allowedInteractions: allowedInteractions,
annotName: annotation.AnnotName,
annotationSelectorSettings: this.getSelector('Redaction', annotation.Subject),
annotationSettings: annotation.AnnotationSettings ||
this.pdfViewer.annotationModule.updateAnnotationSettings(annotation),
isPrint: annotation.IsPrint !== undefined ? annotation.IsPrint : true,
comments: annotation.Comments ? this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author) : [],
review: {
state: annotation.State,
stateModel: annotation.StateModel,
modifiedDate: annotation.ModifiedDate,
author: annotation.Author
},
isCommentLock: annotation.IsCommentLock,
// Add the missing properties:
isReadonly: annotation.IsReadonly || false
};
if (annotationObject.isLocked) {
annotationObject.annotationSettings.isLock = annotationObject.isLocked;
}
currentAnnotObject = annotationObject;
}
}
return currentAnnotObject;
};
/**
* Modify redaction annotation in collection
* @param {string} property - The property to modify
* @param {number} pageNumber - The page number
* @param {any} annotationBase - The annotation to modify
* @returns {IRedactionAnnotation | null} The modified annotation
* @private
*/
Redaction.prototype.modifyInCollection = function (property, pageNumber, annotationBase) {
if (!isNullOrUndefined(annotationBase.formFieldAnnotationType) &&
annotationBase.formFieldAnnotationType !== '') {
this.pdfViewer.annotationModule.isFormFieldShape = true;
}
else {
this.pdfViewer.annotationModule.isFormFieldShape = false;
}
this.pdfViewerBase.updateDocumentEditedProperty(true);
var currentAnnotObject = null;
if (annotationBase) {
if (property === 'bounds') {
this.pdfViewer.annotationModule.stickyNotesAnnotationModule.updateAnnotationModifiedDate(annotationBase, true);
}
}
var pageAnnotations = this.getAnnotations(pageNumber, null);
if (pageAnnotations != null && annotationBase) {
for (var i = 0; i < pageAnnotations.length; i++) {
if (annotationBase.id === pageAnnotations[i].id ||
annotationBase.annotName === pageAnnotations[i].annotName) {
if (property === 'bounds') {
pageAnnotations[i].bounds = {
// x: annotationBase.bounds.x,
// y: annotationBase.bounds.y,
left: annotationBase.bounds.x,
top: annotationBase.bounds.y,
height: annotationBase.bounds.height,
width: annotationBase.bounds.width,
right: annotationBase.bounds.right ? annotationBase.bounds.right : annotationBase.wrapper.bounds.right,
bottom: annotationBase.bounds.bottom ? annotationBase.bounds.bottom : annotationBase.wrapper.bounds.bottom
};
}
else if (property === 'fillColor') {
pageAnnotations[i].fillColor = annotationBase.fillColor;
}
else if (property === 'useOverlayText') {
pageAnnotations[i].useOverlayText = annotationBase.useOverlayText;
}
else if (property === 'isRepeat') {
pageAnnotations[i].isRepeat = annotationBase.isRepeat;
}
else if (property === 'fill') {
pageAnnotations[i].markerFillColor = annotationBase.wrapper.children[0].style.fill;
}
else if (property === 'stroke') {
pageAnnotations[i].markerBorderColor = annotationBase.wrapper.children[0].style.strokeColor;
}
else if (property === 'opacity') {
pageAnnotations[i].markerOpacity = annotationBase.markerOpacity;
}
else if (property === 'overlayText') {
pageAnnotations[i].overlayText = annotationBase.overlayText;
}
else if (property === 'fontColor') {
pageAnnotations[i].fontColor = annotationBase.fontColor;
}
else if (property === 'fontSize') {
pageAnnotations[i]