@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
712 lines • 132 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { NumericTextBox } from '@syncfusion/ej2-inputs';
import { createElement, Browser, isNullOrUndefined, isBlazor } from '@syncfusion/ej2-base';
import { Dialog } from '@syncfusion/ej2-popups';
import { DropDownButton } from '@syncfusion/ej2-splitbuttons';
import { Point } from '@syncfusion/ej2-drawings';
/**
* @hidden
*/
var MeasurementScaleRatio = /** @class */ (function () {
function MeasurementScaleRatio() {
}
return MeasurementScaleRatio;
}());
export { MeasurementScaleRatio };
/**
* @hidden
*/
var MeasureAnnotation = /** @class */ (function () {
function MeasureAnnotation(pdfviewer, pdfViewerBase) {
/**
* @private
*/
this.measureShapeCount = 0;
/**
* @private
*/
this.isAddAnnotationProgramatically = false;
/**
* @private
*/
this.scaleRatioCollection = [];
this.scaleRatioAddCollection = [];
this.pdfViewer = pdfviewer;
this.pdfViewerBase = pdfViewerBase;
}
Object.defineProperty(MeasureAnnotation.prototype, "pixelToPointFactor", {
/**
* @private
* @returns {number} - number
*/
get: function () {
return (72 / 96);
},
enumerable: true,
configurable: true
});
/**
* @param {any} shapeAnnotations - It describes about the shape annotations
* @param {number} pageNumber - It describes about the page number
* @param {boolean} isImportAction - It describes about whether the isImportAction is true or not
* @param {boolean} isAnnotOrderAction - It describes about whether the isAnnotOrderAction is true or not
* @private
* @returns {void}
*/
MeasureAnnotation.prototype.renderMeasureShapeAnnotations = function (shapeAnnotations, pageNumber, isImportAction, isAnnotOrderAction) {
if (shapeAnnotations) {
if (shapeAnnotations.length >= 1) {
var measureAnnots = this.pdfViewer.annotation.getStoredAnnotations(pageNumber, shapeAnnotations, '_annotations_shape_measure');
if (!measureAnnots || isImportAction || isAnnotOrderAction) {
var _loop_1 = function (i) {
var annotation = shapeAnnotations[parseInt(i.toString(), 10)];
var annotationObject = null;
this_1.measureShapeCount = this_1.measureShapeCount + 1;
annotation.annotationAddMode = this_1.pdfViewer.annotationModule.
findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
var isAnnotationRotated = void 0;
if (annotation.ShapeAnnotationType) {
if (isImportAction) {
if (this_1.pdfViewerBase.isJsonImported) {
annotation.Bounds = this_1.pdfViewerBase.
importJsonForRotatedDocuments(annotation.Rotate, pageNumber, annotation.Bounds, annotation.AnnotationRotation);
isAnnotationRotated = this_1.pdfViewerBase.isPageRotated;
}
}
var vertexPoints = null;
if (annotation.VertexPoints) {
vertexPoints = [];
if (isImportAction && this_1.pdfViewerBase.isJsonImported) {
vertexPoints = this_1.pdfViewerBase.
calculateVertexPoints(annotation.Rotate, pageNumber, annotation.VertexPoints, annotation.AnnotationRotation);
}
else {
for (var j = 0; j < annotation.VertexPoints.length; j++) {
var x = annotation.VertexPoints[parseInt(j.toString(), 10)].X ?
annotation.VertexPoints[parseInt(j.toString(), 10)].X :
annotation.VertexPoints[parseInt(j.toString(), 10)].x;
var y = annotation.VertexPoints[parseInt(j.toString(), 10)].Y ?
annotation.VertexPoints[parseInt(j.toString(), 10)].Y :
annotation.VertexPoints[parseInt(j.toString(), 10)].y;
var point = { x: x, y: y };
vertexPoints.push(point);
}
}
}
if (annotation.Bounds && annotation.EnableShapeLabel === true) {
annotation.LabelBounds = this_1.pdfViewer.annotationModule.
inputElementModule.calculateLabelBoundsFromLoadedDocument(annotation.Bounds);
annotation.LabelBorderColor = annotation.LabelBorderColor ?
annotation.LabelBorderColor : annotation.StrokeColor;
annotation.FontColor = annotation.FontColor ? annotation.FontColor : annotation.StrokeColor;
annotation.LabelFillColor = annotation.LabelFillColor ? annotation.LabelFillColor : annotation.FillColor;
annotation.FontSize = annotation.FontSize ? annotation.FontSize : 16;
annotation.LabelSettings = annotation.LabelSettings ? annotation.LabelSettings :
this_1.pdfViewer.shapeLabelSettings;
}
annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings :
this_1.pdfViewer.annotationModule.updateAnnotationSettings(annotation);
if (annotation.IsLocked) {
annotation.AnnotationSettings.isLock = annotation.IsLocked;
}
annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions :
this_1.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
var isPrint = annotation.IsPrint;
var measureObject = {
ratio: annotation.Calibrate.Ratio, x: this_1.getNumberFormatArray(annotation.Calibrate.X),
distance: this_1.getNumberFormatArray(annotation.Calibrate.Distance),
area: this_1.getNumberFormatArray(annotation.Calibrate.Area),
angle: this_1.getNumberFormatArray(annotation.Calibrate.Angle),
volume: this_1.getNumberFormatArray(annotation.Calibrate.Volume),
targetUnitConversion: annotation.Calibrate.TargetUnitConversion
};
if (annotation.Calibrate.Depth) {
measureObject.depth = annotation.Calibrate.Depth;
}
var left = annotation.Bounds.X ? annotation.Bounds.X : annotation.Bounds.x;
var top_1 = annotation.Bounds.Y ? annotation.Bounds.Y : annotation.Bounds.y;
var width = annotation.Bounds.Width ? annotation.Bounds.Width : annotation.Bounds.width;
var height = annotation.Bounds.Height ? annotation.Bounds.Height : annotation.Bounds.height;
annotationObject = {
id: 'measure' + this_1.measureShapeCount, shapeAnnotationType: annotation.ShapeAnnotationType, author: annotation.Author, allowedInteractions: annotation.allowedInteractions, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject,
note: annotation.Note, strokeColor: annotation.StrokeColor, fillColor: annotation.FillColor,
opacity: annotation.Opacity, thickness: annotation.Thickness,
rectangleDifference: annotation.RectangleDifference,
borderStyle: annotation.BorderStyle, borderDashArray: annotation.BorderDashArray,
rotateAngle: annotation.RotateAngle, isCloudShape: annotation.IsCloudShape,
cloudIntensity: annotation.CloudIntensity, vertexPoints: vertexPoints,
lineHeadStart: annotation.LineHeadStart, lineHeadEnd: annotation.LineHeadEnd,
isLocked: annotation.IsLocked, pageNumber: pageNumber,
bounds: { left: left, top: top_1, width: width, height: height, right: annotation.Bounds.Right,
bottom: annotation.Bounds.Bottom },
caption: annotation.Caption, captionPosition: annotation.CaptionPosition, calibrate: measureObject,
leaderLength: annotation.LeaderLength, leaderLineExtension: annotation.LeaderLineExtension,
leaderLineOffset: annotation.LeaderLineOffset, indent: annotation.Indent,
annotName: annotation.AnnotName, comments: this_1.pdfViewer.annotationModule.
getAnnotationComments(annotation.Comments, annotation, annotation.Author),
review: { state: annotation.State, stateModel: annotation.StateModel,
modifiedDate: annotation.ModifiedDate, author: annotation.Author },
labelContent: annotation.LabelContent, enableShapeLabel: annotation.EnableShapeLabel,
labelFillColor: annotation.LabelFillColor,
fontColor: annotation.FontColor, labelBorderColor: annotation.LabelBorderColor,
fontSize: annotation.FontSize,
labelBounds: annotation.LabelBounds, annotationSelectorSettings: this_1.getSettings(annotation),
labelSettings: annotation.LabelSettings, annotationSettings: annotation.AnnotationSettings,
customData: this_1.pdfViewer.annotation.getCustomData(annotation),
isPrint: annotation.IsPrint, isCommentLock: annotation.IsCommentLock,
isAnnotationRotated: isAnnotationRotated
};
var vPoints = annotationObject.vertexPoints;
if (vertexPoints == null) {
vPoints = [];
}
var annotationSelectorSettings = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings;
if (isNullOrUndefined(annotation.AnnotationSelectorSettings)) {
this_1.pdfViewerBase.annotationSelectorSettingLoad(annotation);
}
else {
annotation.AnnotationSelectorSettings = annotationSelectorSettings;
}
annotation.allowedInteractions = annotation.AllowedInteractions ?
annotation.AllowedInteractions : this_1.pdfViewer.annotationModule.
updateAnnotationAllowedInteractions(annotation);
var annot_1 = {
id: 'measure' + this_1.measureShapeCount, shapeAnnotationType: this_1.getShapeType(annotationObject), author: annotationObject.author, allowedInteractions: annotation.allowedInteractions, modifiedDate: annotationObject.modifiedDate,
subject: annotationObject.subject, notes: annotationObject.note, fillColor: annotationObject.fillColor,
strokeColor: annotationObject.strokeColor, opacity: annotationObject.opacity,
thickness: annotationObject.thickness, borderStyle: annotationObject.borderStyle, borderDashArray: annotationObject.borderDashArray.toString(), rotateAngle: parseFloat(annotationObject.rotateAngle.split('Angle')[1]),
isCloudShape: annotationObject.isCloudShape, cloudIntensity: annotationObject.cloudIntensity,
taregetDecoraterShapes: this_1.pdfViewer.annotation.getArrowType(annotationObject.lineHeadEnd),
sourceDecoraterShapes: this_1.pdfViewer.annotation.getArrowType(annotationObject.lineHeadStart),
vertexPoints: vPoints, bounds: { x: annotationObject.bounds.left, y: annotationObject.bounds.top,
width: annotationObject.bounds.width, height: annotationObject.bounds.height },
leaderHeight: annotationObject.leaderLength, pageIndex: pageNumber,
annotName: annotationObject.annotName, comments: annotationObject.comments,
review: annotationObject.review,
measureType: this_1.getMeasureType(annotationObject),
labelContent: annotation.LabelContent, enableShapeLabel: annotation.EnableShapeLabel,
labelFillColor: annotation.LabelFillColor,
fontColor: annotation.FontColor, labelBorderColor: annotation.LabelBorderColor,
fontSize: annotation.FontSize,
labelBounds: annotation.LabelBounds, annotationSelectorSettings: annotation.AnnotationSelectorSettings,
annotationSettings: annotationObject.annotationSettings, annotationAddMode: annotation.annotationAddMode,
isPrint: isPrint, isCommentLock: annotationObject.isCommentLock, customData: annotationObject.customData
};
if (this_1.scaleRatioCollection) {
var matchedScaleRatio = this_1.scaleRatioCollection.find(function (item) { return item.annotName === annot_1.annotName; });
if (matchedScaleRatio && matchedScaleRatio.id === undefined) {
matchedScaleRatio.id = annot_1.id;
}
}
this_1.pdfViewer.annotation.storeAnnotations(pageNumber, annotationObject, '_annotations_shape_measure');
this_1.pdfViewer.add(annot_1);
if (this_1.isAddAnnotationProgramatically) {
var settings = {
opacity: annot_1.opacity, strokeColor: annot_1.strokeColor, thickness: annot_1.thickness,
modifiedDate: annot_1.modifiedDate,
width: annot_1.bounds.width, height: annot_1.bounds.height
};
this_1.pdfViewer.fireAnnotationAdd(annot_1.pageIndex, annot_1.annotName, annotation.ShapeAnnotationType, annot_1.bounds, settings);
}
}
};
var this_1 = this;
for (var i = 0; i < shapeAnnotations.length; i++) {
_loop_1(i);
}
}
}
else if (shapeAnnotations.shapeAnnotationType) {
var annotationObject = this.createAnnotationObject(shapeAnnotations);
this.updateScaleRatioCollection();
var measureSettings = this.pdfViewer.measurementSettings;
if (measureSettings.conversionUnit !== 'in' || measureSettings.displayUnit !== 'in' || measureSettings.scaleRatio !== 1) {
var ratioString = annotationObject.calibrate.ratio.split('=').map(function (ratioString) { return ratioString.trim(); });
var _a = ratioString[0].split(' '), srcValueStr = _a[0], unit = _a[1];
var _b = ratioString[1].split(' '), destValueStr = _b[0], displayUnit = _b[1];
var destValue = parseFloat(destValueStr);
var depthValue = measureSettings.depth ? measureSettings.depth : 96;
var srcValue = parseFloat(srcValueStr);
var scaleRatio = {
annotName: annotationObject.annotName,
displayUnit: displayUnit,
unit: unit,
ratio: destValue / srcValue,
destValue: destValue,
srcValue: srcValue,
volumeDepth: depthValue,
depthValue: depthValue,
ratioString: ratioString
};
this.scaleRatioCollection.push(scaleRatio);
}
else if (!isNullOrUndefined(this.measureRatioObject)) {
this.measureRatioObject['id'] = annotationObject.id;
this.measureRatioObject['annotName'] = annotationObject.annotName;
this.scaleRatioCollection.push(__assign({}, this.measureRatioObject));
}
else {
var srcValue = (this.sourceTextBox && this.sourceTextBox.value) ? this.sourceTextBox.value : 1;
var destValue = (this.destTextBox && this.destTextBox.value) ? this.destTextBox.value : 1;
this.measureRatioObject = {
id: annotationObject.id,
annotName: annotationObject.annotName,
displayUnit: this.displayUnit,
unit: this.unit,
depthValue: this.volumeDepth,
volumeDepth: this.volumeDepth,
ratioString: srcValue + ' ' + this.unit + ' = ' + destValue + ' ' + this.displayUnit,
ratio: destValue / srcValue
};
this.scaleRatioCollection.push(__assign({}, this.measureRatioObject));
this.scaleRatioAddCollection.push(__assign({}, this.measureRatioObject));
}
this.pdfViewer.annotationModule.isFormFieldShape = false;
this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotationObject, '_annotations_shape_measure');
if (shapeAnnotations) {
shapeAnnotations.customData = annotationObject.customData;
}
this.pdfViewer.annotationModule.triggerAnnotationAdd(shapeAnnotations);
}
}
};
/**
* @param {any} annotation - It describes about the annotation
* @private
* @returns {any} - any
*/
MeasureAnnotation.prototype.getSettings = function (annotation) {
var selector = this.pdfViewer.annotationSelectorSettings;
if (annotation.AnnotationSelectorSettings) {
selector = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings;
}
else {
selector = this.getSelector(annotation.Subject);
}
return selector;
};
/**
* @param {AnnotType} type - It describes about the annotation type
* @private
* @returns {void}
*/
MeasureAnnotation.prototype.setAnnotationType = function (type) {
var author = 'Guest';
var subject = '';
var customData;
this.updateMeasureproperties();
this.pdfViewerBase.disableTextSelectionMode();
switch (type) {
case 'Distance': {
this.currentAnnotationMode = 'Distance';
var modifiedDateDist = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.distanceSettings.author ? this.pdfViewer.distanceSettings.author : 'Guest';
subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.distanceSettings.subject ? this.pdfViewer.distanceSettings.subject : 'Distance calculation';
customData = !isNullOrUndefined(this.pdfViewer.annotationSettings.customData) ?
this.pdfViewer.annotationSettings.customData : this.pdfViewer.distanceSettings.customData ?
this.pdfViewer.distanceSettings.customData : null;
this.pdfViewer.drawingObject = {
sourceDecoraterShapes: this.pdfViewer.annotation.getArrowType(this.distanceStartHead),
taregetDecoraterShapes: this.pdfViewer.annotation.getArrowType(this.distanceEndHead), measureType: 'Distance',
fillColor: this.distanceFillColor, notes: '', strokeColor: this.distanceStrokeColor, leaderHeight: this.leaderLength,
opacity: this.distanceOpacity, thickness: this.distanceThickness, borderDashArray: this.distanceDashArray.toString(),
shapeAnnotationType: 'Distance', author: author, subject: subject, isCommentLock: false, customData: customData
};
this.pdfViewer.tool = 'Distance';
break;
}
case 'Perimeter': {
this.currentAnnotationMode = 'Perimeter';
var modifiedDatePeri = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.perimeterSettings.author ? this.pdfViewer.perimeterSettings.author : 'Guest';
subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.perimeterSettings.subject ? this.pdfViewer.perimeterSettings.subject : 'Perimeter calculation';
this.pdfViewer.drawingObject = {
shapeAnnotationType: 'LineWidthArrowHead', fillColor: this.perimeterFillColor, notes: '', strokeColor: this.perimeterStrokeColor, opacity: this.perimeterOpacity,
thickness: this.perimeterThickness, sourceDecoraterShapes: this.pdfViewer.annotation.getArrowType(this.perimeterStartHead),
taregetDecoraterShapes: this.pdfViewer.annotation.getArrowType(this.perimeterEndHead), measureType: 'Perimeter', borderDashArray: this.perimeterDashArray.toString(),
author: author, subject: subject, isCommentLock: false, customData: customData
};
this.pdfViewer.tool = 'Perimeter';
break;
}
case 'Area': {
this.currentAnnotationMode = 'Area';
var modifiedDateArea = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.areaSettings.author ? this.pdfViewer.areaSettings.author : 'Guest';
subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.areaSettings.subject ? this.pdfViewer.areaSettings.subject : 'Area calculation';
this.pdfViewer.drawingObject = {
shapeAnnotationType: 'Polygon', fillColor: this.areaFillColor, notes: '', strokeColor: this.areaStrokeColor,
thickness: this.areaThickness, opacity: this.areaOpacity, measureType: 'Area',
modifiedDate: modifiedDateArea, borderStyle: '', borderDashArray: '0',
author: author, subject: subject, isCommentLock: false, customData: customData
};
this.pdfViewer.tool = 'Polygon';
break;
}
case 'Radius': {
this.currentAnnotationMode = 'Radius';
var modifiedDateRad = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.radiusSettings.author ? this.pdfViewer.radiusSettings.author : 'Guest';
subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.radiusSettings.subject ? this.pdfViewer.radiusSettings.subject : 'Radius calculation';
customData = !isNullOrUndefined(this.pdfViewer.annotationSettings.customData) ?
this.pdfViewer.annotationSettings.customData : this.pdfViewer.radiusSettings.customData ?
this.pdfViewer.radiusSettings.customData : null;
this.pdfViewer.drawingObject = {
shapeAnnotationType: 'Radius', fillColor: this.radiusFillColor, notes: '', strokeColor: this.radiusStrokeColor, opacity: this.radiusOpacity,
thickness: this.radiusThickness, measureType: 'Radius', modifiedDate: modifiedDateRad, borderStyle: '', borderDashArray: '0',
author: author, subject: subject, isCommentLock: false, customData: customData
};
this.pdfViewer.tool = 'DrawTool';
break;
}
case 'Volume': {
this.currentAnnotationMode = 'Volume';
var modifiedDateVol = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.volumeSettings.author ? this.pdfViewer.volumeSettings.author : 'Guest';
subject = (this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.volumeSettings.subject ? this.pdfViewer.volumeSettings.subject : 'Volume calculation';
this.pdfViewer.drawingObject = {
shapeAnnotationType: 'Polygon', notes: '', fillColor: this.volumeFillColor, strokeColor: this.volumeStrokeColor,
opacity: this.volumeOpacity, thickness: this.volumeThickness, measureType: 'Volume',
modifiedDate: modifiedDateVol, borderStyle: '', borderDashArray: '0',
author: author, subject: subject, isCommentLock: false, customData: customData
};
this.pdfViewer.tool = 'Polygon';
break;
}
}
};
MeasureAnnotation.prototype.updateMeasureproperties = function () {
this.distanceFillColor = this.pdfViewer.distanceSettings.fillColor ? this.pdfViewer.distanceSettings.fillColor : '#ff0000';
this.distanceStrokeColor = this.pdfViewer.distanceSettings.strokeColor ? this.pdfViewer.distanceSettings.strokeColor : '#ff0000';
this.distanceOpacity = this.pdfViewer.distanceSettings.opacity ? this.pdfViewer.distanceSettings.opacity : 1;
this.distanceThickness = this.pdfViewer.distanceSettings.thickness ? this.pdfViewer.distanceSettings.thickness : 1;
this.distanceDashArray = this.pdfViewer.distanceSettings.borderDashArray ? this.pdfViewer.distanceSettings.borderDashArray : 0;
this.leaderLength = this.pdfViewer.distanceSettings.leaderLength != null ? this.pdfViewer.distanceSettings.leaderLength : 40;
this.distanceStartHead = this.pdfViewer.distanceSettings.lineHeadStartStyle ? this.pdfViewer.distanceSettings.lineHeadStartStyle : 'Closed';
this.distanceEndHead = this.pdfViewer.distanceSettings.lineHeadEndStyle ? this.pdfViewer.distanceSettings.lineHeadEndStyle : 'Closed';
this.perimeterFillColor = this.pdfViewer.perimeterSettings.fillColor ? this.pdfViewer.perimeterSettings.fillColor : '#ffffff00';
this.perimeterStrokeColor = this.pdfViewer.perimeterSettings.strokeColor ? this.pdfViewer.perimeterSettings.strokeColor : '#ff0000';
this.perimeterOpacity = this.pdfViewer.perimeterSettings.opacity ? this.pdfViewer.perimeterSettings.opacity : 1;
this.perimeterThickness = this.pdfViewer.perimeterSettings.thickness ? this.pdfViewer.perimeterSettings.thickness : 1;
this.perimeterDashArray = this.pdfViewer.perimeterSettings.borderDashArray ? this.pdfViewer.perimeterSettings.borderDashArray : 0;
this.perimeterStartHead = this.pdfViewer.perimeterSettings.lineHeadStartStyle ? this.pdfViewer.perimeterSettings.lineHeadStartStyle : 'Open';
this.perimeterEndHead = this.pdfViewer.perimeterSettings.lineHeadEndStyle ? this.pdfViewer.perimeterSettings.lineHeadEndStyle : 'Open';
this.areaFillColor = this.pdfViewer.areaSettings.fillColor ? this.pdfViewer.areaSettings.fillColor : '#ffffff00';
this.areaStrokeColor = this.pdfViewer.areaSettings.strokeColor ? this.pdfViewer.areaSettings.strokeColor : '#ff0000';
this.areaOpacity = this.pdfViewer.areaSettings.opacity ? this.pdfViewer.areaSettings.opacity : 1;
this.areaThickness = this.pdfViewer.areaSettings.thickness ? this.pdfViewer.areaSettings.thickness : 1;
this.radiusFillColor = this.pdfViewer.radiusSettings.fillColor ? this.pdfViewer.radiusSettings.fillColor : '#ffffff00';
this.radiusStrokeColor = this.pdfViewer.radiusSettings.strokeColor ? this.pdfViewer.radiusSettings.strokeColor : '#ff0000';
this.radiusOpacity = this.pdfViewer.radiusSettings.opacity ? this.pdfViewer.radiusSettings.opacity : 1;
this.radiusThickness = this.pdfViewer.radiusSettings.thickness ? this.pdfViewer.radiusSettings.thickness : 1;
this.volumeFillColor = this.pdfViewer.volumeSettings.fillColor ? this.pdfViewer.volumeSettings.fillColor : '#ffffff00';
this.volumeStrokeColor = this.pdfViewer.volumeSettings.strokeColor ? this.pdfViewer.volumeSettings.strokeColor : '#ff0000';
this.volumeOpacity = this.pdfViewer.volumeSettings.opacity ? this.pdfViewer.volumeSettings.opacity : 1;
this.volumeThickness = this.pdfViewer.volumeSettings.thickness ? this.pdfViewer.volumeSettings.thickness : 1;
var scaleRatioObject = this.scaleRatioAddCollection[this.scaleRatioAddCollection.length - 1];
if (this.currentScaleRatio && this.currentScaleRatio.unit !== this.pdfViewer.measurementSettings.conversionUnit.toLowerCase()) {
this.unit = this.currentScaleRatio.unit;
}
else if (this.pdfViewer.measurementSettings.conversionUnit.toLowerCase() !== 'in') {
this.unit = this.pdfViewer.measurementSettings.conversionUnit.toLowerCase();
}
else if (scaleRatioObject) {
this.unit = scaleRatioObject.unit;
}
else {
this.unit = this.pdfViewer.measurementSettings.conversionUnit.toLowerCase();
}
if (this.currentScaleRatio && this.currentScaleRatio.displayUnit !==
this.pdfViewer.measurementSettings.conversionUnit.toLowerCase()) {
this.displayUnit = this.currentScaleRatio.displayUnit;
}
else if (this.pdfViewer.measurementSettings.displayUnit.toLowerCase() !== 'in') {
this.displayUnit = this.pdfViewer.measurementSettings.displayUnit.toLowerCase();
}
else if (scaleRatioObject) {
this.displayUnit = scaleRatioObject.displayUnit;
}
else {
this.displayUnit = this.pdfViewer.measurementSettings.displayUnit.toLowerCase();
}
if (this.currentScaleRatio && this.currentScaleRatio.ratio !== this.pdfViewer.measurementSettings.scaleRatio) {
this.ratio = this.currentScaleRatio.ratio;
}
else if (this.pdfViewer.measurementSettings.scaleRatio !== 1) {
this.ratio = this.pdfViewer.measurementSettings.scaleRatio;
}
else if (scaleRatioObject) {
this.ratio = scaleRatioObject.ratio;
}
else if (isNullOrUndefined(this.ratio) || this.ratio === this.pdfViewer.measurementSettings.scaleRatio) {
this.ratio = this.pdfViewer.measurementSettings.scaleRatio;
}
if (this.currentScaleRatio && this.currentScaleRatio.volumeDepth !== this.pdfViewer.measurementSettings.depth) {
this.volumeDepth = this.currentScaleRatio.volumeDepth;
}
else if (this.pdfViewer.measurementSettings.scaleRatio !== 1) {
this.volumeDepth = this.pdfViewer.measurementSettings.depth;
}
else if (scaleRatioObject) {
this.volumeDepth = scaleRatioObject.volumeDepth;
}
else {
this.volumeDepth = this.pdfViewer.measurementSettings.depth ? this.pdfViewer.measurementSettings.depth : 96;
}
this.scaleRatioString = '1 ' + this.unit + ' = ' + this.ratio.toString() + ' ' + this.displayUnit;
this.currentScaleRatio = null;
};
MeasureAnnotation.prototype.createAnnotationObject = function (annotationModel) {
var bound;
var labelBound;
var annotationName = this.pdfViewer.annotation.createGUID();
var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('shape_measure', (annotationModel.pageIndex + 1), annotationModel.measureType);
if (commentsDivid) {
document.getElementById(commentsDivid).id = annotationName;
}
annotationModel.annotName = annotationName;
// eslint-disable-next-line
annotationModel.author = annotationModel && annotationModel.author != 'Guest' ? annotationModel.author : this.pdfViewer.annotationModule.updateAnnotationAuthor('measure', annotationModel.subject);
this.pdfViewer.annotation.stickyNotesAnnotationModule.addTextToComments(annotationName, annotationModel.notes);
if (annotationModel.wrapper.bounds) {
bound = {
left: annotationModel.wrapper.bounds.x, top: annotationModel.wrapper.bounds.y,
height: annotationModel.wrapper.bounds.height, width: annotationModel.wrapper.bounds.width,
right: annotationModel.wrapper.bounds.right, bottom: annotationModel.wrapper.bounds.bottom
};
labelBound = this.pdfViewer.annotationModule.inputElementModule.calculateLabelBounds(annotationModel.wrapper.bounds);
}
else {
bound = { left: 0, top: 0, height: 0, width: 0, right: 0, bottom: 0 };
labelBound = { left: 0, top: 0, height: 0, width: 0, right: 0, bottom: 0 };
}
var borderDashArray = parseInt(annotationModel.borderDashArray, 10);
borderDashArray = isNaN(borderDashArray) ? 0 : borderDashArray;
var measure = { ratio: this.scaleRatioString, x: [this.createNumberFormat('x')], distance: [this.createNumberFormat('d')], area: [this.createNumberFormat('a')] };
if (annotationModel.measureType === 'Volume') {
measure.depth = this.volumeDepth;
}
var annotationSettings = this.pdfViewer.annotationModule.findAnnotationSettings(annotationModel, true);
var allowedInteractions = this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotationModel);
annotationModel.isPrint = annotationSettings.isPrint;
var setting = this.pdfViewer.shapeLabelSettings;
var labelSettings = { borderColor: annotationModel.strokeColor, fillColor: annotationModel.fillColor,
fontColor: annotationModel.fontColor, fontSize: annotationModel.fontSize, labelContent: annotationModel.labelContent,
labelHeight: setting.labelHeight, labelWidth: setting.labelMaxWidth, opacity: annotationModel.opacity
};
return {
id: annotationModel.id, shapeAnnotationType: this.getShapeAnnotType(annotationModel.measureType),
author: annotationModel.author, allowedInteractions: allowedInteractions,
subject: annotationModel.subject, note: annotationModel.notes, strokeColor: annotationModel.strokeColor,
fillColor: annotationModel.fillColor, opacity: annotationModel.opacity, thickness: annotationModel.thickness,
borderStyle: annotationModel.borderStyle, borderDashArray: borderDashArray, bounds: bound,
modifiedDate: this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(),
rotateAngle: 'RotateAngle' + annotationModel.rotateAngle, isCloudShape: annotationModel.isCloudShape, cloudIntensity: annotationModel.cloudIntensity,
vertexPoints: annotationModel.vertexPoints, lineHeadStart: this.pdfViewer.annotation.
getArrowTypeForCollection(annotationModel.sourceDecoraterShapes),
lineHeadEnd: this.pdfViewer.annotation.getArrowTypeForCollection(annotationModel.taregetDecoraterShapes),
rectangleDifference: [], isLocked: annotationSettings.isLock,
leaderLength: annotationModel.leaderHeight, leaderLineExtension: 2, leaderLineOffset: 0, calibrate: measure, caption: true, captionPosition: 'Top',
indent: this.getIndent(annotationModel.measureType), annotName: annotationName, comments: [], review: { state: '', stateModel: '', modifiedDate: this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime(), author: annotationModel.author },
labelContent: annotationModel.labelContent, enableShapeLabel: annotationModel.enableShapeLabel,
labelFillColor: annotationModel.labelFillColor,
labelBorderColor: annotationModel.labelBorderColor, fontColor: annotationModel.fontColor, fontSize: annotationModel.fontSize,
labelBounds: labelBound, annotationSelectorSettings: this.getSelector(annotationModel.subject),
labelSettings: labelSettings, annotationSettings: annotationSettings,
customData: this.pdfViewer.annotation.getMeasureData(annotationModel.subject), isPrint: annotationModel.isPrint,
isCommentLock: annotationModel.isCommentLock, isAnnotationRotated: false,
pageNumber: annotationModel.pageIndex
};
};
MeasureAnnotation.prototype.getSelector = function (type) {
var selector = this.pdfViewer.annotationSelectorSettings;
if ((type === 'Distance calculation') && this.pdfViewer.distanceSettings.annotationSelectorSettings) {
selector = this.pdfViewer.distanceSettings.annotationSelectorSettings;
}
else if ((type === 'Perimeter calculation') && this.pdfViewer.perimeterSettings.annotationSelectorSettings) {
selector = this.pdfViewer.perimeterSettings.annotationSelectorSettings;
}
else if ((type === 'Area calculation') && this.pdfViewer.areaSettings.annotationSelectorSettings) {
selector = this.pdfViewer.areaSettings.annotationSelectorSettings;
}
else if ((type === 'Radius calculation') && this.pdfViewer.radiusSettings.annotationSelectorSettings) {
selector = this.pdfViewer.radiusSettings.annotationSelectorSettings;
}
else if ((type === 'Volume calculation') && this.pdfViewer.volumeSettings.annotationSelectorSettings) {
selector = this.pdfViewer.volumeSettings.annotationSelectorSettings;
}
return selector;
};
MeasureAnnotation.prototype.getShapeAnnotType = function (measureType) {
var annotationType;
switch (measureType) {
case 'Distance':
annotationType = 'Line';
break;
case 'Perimeter':
annotationType = 'Polyline';
break;
case 'Area':
case 'Volume':
annotationType = 'Polygon';
break;
case 'Radius':
annotationType = 'Circle';
break;
}
return annotationType;
};
MeasureAnnotation.prototype.getShapeType = function (shape) {
var shapeType;
if (shape.shapeAnnotationType === 'Line') {
shapeType = 'Distance';
}
else if (shape.shapeAnnotationType === 'Polyline') {
shapeType = 'LineWidthArrowHead';
}
else if (shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonDimension') {
shapeType = 'Polygon';
}
else if ((shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonRadius') || shape.shapeAnnotationType === 'Circle') {
shapeType = 'Radius';
}
else if (shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonVolume') {
shapeType = 'Polygon';
}
return shapeType;
};
MeasureAnnotation.prototype.getMeasureType = function (shape) {
var measureType;
if (shape.shapeAnnotationType === 'Line') {
measureType = 'Distance';
}
else if (shape.shapeAnnotationType === 'Polyline') {
measureType = 'Perimeter';
}
else if (shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonDimension') {
measureType = 'Area';
}
else if ((shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonRadius') || shape.shapeAnnotationType === 'Circle') {
measureType = 'Radius';
}
else if (shape.shapeAnnotationType === 'Polygon' && shape.indent === 'PolygonVolume') {
measureType = 'Volume';
}
return measureType;
};
MeasureAnnotation.prototype.getIndent = function (measureType) {
var indent;
switch (measureType) {
case 'Distance':
indent = 'LineDimension';
break;
case 'Perimeter':
indent = 'PolyLineDimension';
break;
case 'Area':
indent = 'PolygonDimension';
break;
case 'Radius':
indent = 'PolygonRadius';
break;
case 'Volume':
indent = 'PolygonVolume';
break;
}
return indent;
};
MeasureAnnotation.prototype.getNumberFormatArray = function (list) {
var numberFormatArray = [];
if (list) {
for (var i = 0; i < list.length; i++) {
numberFormatArray[parseInt(i.toString(), 10)] = { unit: list[parseInt(i.toString(), 10)].Unit,
fractionalType: list[parseInt(i.toString(), 10)].FractionalType,
conversionFactor: list[parseInt(i.toString(), 10)].ConversionFactor,
denominator: list[parseInt(i.toString(), 10)].Denominator,
formatDenominator: list[parseInt(i.toString(), 10)].FormatDenominator };
}
}
return numberFormatArray;
};
MeasureAnnotation.prototype.createNumberFormat = function (type) {
var cFactor = 1;
var unit = this.displayUnit;
if (type === 'x') {
cFactor = this.getFactor(this.unit);
}
if (type === 'a') {
unit = 'sq ' + this.displayUnit;
}
var numberFormat = { unit: unit, fractionalType: 'D', conversionFactor: cFactor, denominator: 100, formatDenominator: false };
return numberFormat;
};
/**
* @private
* @returns {string} - string
*/
MeasureAnnotation.prototype.saveMeasureShapeAnnotations = function () {
var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_shape_measure');
var annotations = [];
for (var j = 0; j < this.pdfViewerBase.pageCount; j++) {
annotations[parseInt(j.toString(), 10)] = [];
}
if (storeObject && !this.pdfViewer.annotationSettings.skipDownload) {
var annotationCollection = JSON.parse(JSON.stringify(storeObject));
for (var i = 0; i < annotationCollection.length; i++) {
var newArray = [];
var pageAnnotationObject = annotationCollection[parseInt(i.toString(), 10)];
if (pageAnnotationObject) {
for (var z = 0; pageAnnotationObject.annotations.length > z; z++) {
this.pdfViewer.annotationModule.updateModifiedDate(pageAnnotationObject.annotations[parseInt(z.toString(), 10)]);
if (this.pdfViewerBase.isJsonExported) {
if (pageAnnotationObject.annotations[parseInt(z.toString(), 10)].isAnnotationRotated) {
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds =
this.pdfViewer.annotation.getBounds(pageAnnotationObject.
annotations[parseInt(z.toString(), 10)].bounds, pageAnnotationObject.pageIndex);
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].vertexPoints =
this.pdfViewer.annotation.getVertexPoints(pageAnnotationObject.
annotations[parseInt(z.toString(), 10)].vertexPoints, pageAnnotationObject.pageIndex);
}
else {
var pageDetails = this.pdfViewerBase.pageSize[pageAnnotationObject.pageIndex];
if (pageDetails) {
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].annotationRotation = pageDetails.rotation;
}
}
}
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds =
JSON.stringify(this.pdfViewer.annotation.
getBounds(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds, pageAnnotationObject.pageIndex));
var strokeColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor;
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor =
JSON.stringify(this.getRgbCode(strokeColorString));
var fillColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fillColor;
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fillColor =
JSON.stringify(this.getRgbCode(fillColorString));
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].vertexPoints =
JSON.stringify(this.pdfViewer.annotation.
getVertexPoints(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].vertexPoints, pageAnnotationObject.pageIndex));
if (pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference !== null) {
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference =
JSON.stringify(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference);
}
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].calibrate =
this.getStringifiedMeasure(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].calibrate);
if (pageAnnotationObject.annotations[parseInt(z.toString(), 10)].enableShapeLabel === true) {
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelBounds =
JSON.stringify(this.pdfViewer.annotationModule.inputElementModule.calculateLabelBounds(JSON.parse(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds), pageAnnotationObject.pageIndex));
var labelFillColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelFillColor;
pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelFillColor =
JSON.stringify(this.getRgbCode(labelFillColorString));
var labelBorderColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelBorderColor;
pageAnnotat