UNPKG

@syncfusion/ej2-pdfviewer

Version:
675 lines 111 kB
import { PdfViewerBase } from '../../index'; 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 MeasureAnnotation = /** @class */ (function () { function MeasureAnnotation(pdfviewer, pdfViewerBase) { /** * @private */ this.measureShapeCount = 0; /** * @private */ this.isAddAnnotationProgramatically = false; 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) { for (var i = 0; i < shapeAnnotations.length; i++) { var annotation = shapeAnnotations[parseInt(i.toString(), 10)]; var annotationObject = null; this.measureShapeCount = this.measureShapeCount + 1; annotation.annotationAddMode = this.pdfViewer.annotationModule. findAnnotationMode(annotation, pageNumber, annotation.AnnotType); var isAnnotationRotated = void 0; if (annotation.ShapeAnnotationType) { if (isImportAction) { if (this.pdfViewerBase.isJsonImported) { annotation.Bounds = this.pdfViewerBase. importJsonForRotatedDocuments(annotation.Rotate, pageNumber, annotation.Bounds, annotation.AnnotationRotation); isAnnotationRotated = this.pdfViewerBase.isPageRotated; } } var vertexPoints = null; if (annotation.VertexPoints) { vertexPoints = []; if (isImportAction && this.pdfViewerBase.isJsonImported) { vertexPoints = this.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.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.pdfViewer.shapeLabelSettings; } annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings : this.pdfViewer.annotationModule.updateAnnotationSettings(annotation); if (annotation.IsLocked) { annotation.AnnotationSettings.isLock = annotation.IsLocked; } annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions : this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation); var isPrint = annotation.IsPrint; var measureObject = { ratio: annotation.Calibrate.Ratio, x: this.getNumberFormatArray(annotation.Calibrate.X), distance: this.getNumberFormatArray(annotation.Calibrate.Distance), area: this.getNumberFormatArray(annotation.Calibrate.Area), angle: this.getNumberFormatArray(annotation.Calibrate.Angle), volume: this.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.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, 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.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.getSettings(annotation), labelSettings: annotation.LabelSettings, annotationSettings: annotation.AnnotationSettings, customData: this.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.pdfViewerBase.annotationSelectorSettingLoad(annotation); } else { annotation.AnnotationSelectorSettings = annotationSelectorSettings; } annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions : this.pdfViewer.annotationModule. updateAnnotationAllowedInteractions(annotation); var annot = { id: 'measure' + this.measureShapeCount, shapeAnnotationType: this.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.pdfViewer.annotation.getArrowType(annotationObject.lineHeadEnd), sourceDecoraterShapes: this.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.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 }; this.pdfViewer.annotation.storeAnnotations(pageNumber, annotationObject, '_annotations_shape_measure'); this.pdfViewer.add(annot); if (this.isAddAnnotationProgramatically) { var settings = { opacity: annot.opacity, strokeColor: annot.strokeColor, thickness: annot.thickness, modifiedDate: annot.modifiedDate, width: annot.bounds.width, height: annot.bounds.height }; this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, annotation.ShapeAnnotationType, annot.bounds, settings); } } } } } else if (shapeAnnotations.shapeAnnotationType) { var annotationObject = this.createAnnotationObject(shapeAnnotations); 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; this.unit = this.pdfViewer.measurementSettings.conversionUnit.toLowerCase(); this.displayUnit = this.pdfViewer.measurementSettings.displayUnit.toLowerCase(); if (isNullOrUndefined(this.ratio) || this.ratio !== this.pdfViewer.measurementSettings.scaleRatio) { this.ratio = this.pdfViewer.measurementSettings.scaleRatio; } this.volumeDepth = this.pdfViewer.measurementSettings.depth; this.scaleRatioString = '1 ' + this.unit + ' = ' + this.ratio.toString() + ' ' + this.displayUnit; }; 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 }; }; 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 = PdfViewerBase.sessionStorageManager.getItem(this.pdfViewerBase.documentId + '_annotations_shape_measure'); if (this.pdfViewerBase.isStorageExceed) { storeObject = this.pdfViewerBase.annotationStorage[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(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; pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelBorderColor = JSON.stringify(this.getRgbCode(labelBorderColorString)); pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelSettings.fillColor = labelFillColorString; var fontColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].labelSettings.fontColor; pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fontColor = JSON.stringify(this.getRgbCode(fontColorString)); } } newArray = pageAnnotationObject.annotations; } annotations[pageAnnotationObject.pageIndex] = newArray; } } return JSON.stringify(annotations); }; /** * @private * @returns {void} */ MeasureAnnotation.prototype.createScaleRatioWindow = function () { var _this = this; if (!isBlazor()) { var elementID = this.pdfViewer.element.id; var dialogDiv = createElement('div', { id: elementID + '_scale_ratio_window', className: 'e-pv-scale-ratio-window' }); this.pdfViewerBase.pageContainer.appendChild(dialogDiv); var contentElement = this.createRatioUI(); this.scaleRatioDialog = new Dialog({ showCloseIcon: true, closeOnEscape: false, isModal: true, header: this.pdfViewer.localeObj.getConstant('Scale Ratio'), target: this.pdfViewer.element, content: contentElement, close: function () { _this.sourceTextBox.destroy(); _this.convertUnit.destroy(); _this.destTextBox.destroy(); _this.dispUnit.destroy(); _this.scaleRatioDialog.destroy(); var dialogElement = _this.pdfViewerBase.getElement('_scale_ratio_window'); dialogElement.parentElement.removeChild(dialogElement); } }); if (!Browser.isDevice || this.pdfViewer.enableDesktopMode) { this.scaleRatioDialog.buttons = [ { buttonModel: { content: this.pdfViewer.localeObj.getConstant('OK'), isPrimary: true }, click: this.onOkClicked.bind(this) }, { buttonModel: { content: this.pdfViewer.localeObj.getConstant('Cancel') }, click: this.onCancelClicked.bind(this) } ]; } else { this.scaleRatioDialog.buttons = [ { buttonModel: { content: this.pdfViewer.localeObj.getConstant('Cancel') }, click: this.onCancelClicked.bind(this) }, { buttonModel: { content: this.pdfViewer.localeObj.getConstant('OK'), isPrimary: true }, click: this.onOkClicked.bind(this) } ]; } if (this.pdfViewer.enableRtl) { this.scaleRatioDialog.enableRtl = true; } this.scaleRatioDialog.appendTo(dialogDiv); this.convertUnit.content = this.createContent(this.pdfViewer.localeObj.getConstant(this.unit)).outerHTML; this.dispUnit.content = this.createContent(this.pdfViewer.localeObj.getConstant(this.displayUnit)).outerHTML; this.depthUnit.content = this.createContent(this.pdfViewer.localeObj.getConstant(this.displayUnit)).outerHTML; } else { this.pdfViewer._dotnetInstance.invokeMethodAsync('OpenScaleRatioDialog'); } }; MeasureAnnotation.prototype.createRatioUI = function () { var element = createElement('div'); var elementID = this.pdfViewer.element.id; var items = [{ text: this.pdfViewer.localeObj.getConstant('pt'), label: 'pt' }, { text: this.pdfViewer.localeObj.getConstant('in'), label: 'in' }, { text: this.pdfViewer.localeObj.getConstant('mm'), label: 'mm' }, { text: this.pdfViewer.localeObj.getConstant('cm'), label: 'cm' }, { text: this.pdfViewer.localeObj.getConstant('p'), label: 'p' }, { text: this.pdfViewer.localeObj.getConstant('ft'), label: 'ft' }, { text: this.pdfViewer.localeObj.getConstant('ft_in'), label: 'ft_in' }, { text: this.pdfViewer.localeObj.getConstant('m'), label: 'm' }]; var labelText = createElement('div', { id: elementID + '_scale_ratio_label', className: 'e-pv-scale-ratio-text' }); labelText.textContent = this.pdfViewer.localeObj.getConstant('Scale Ratio'); element.appendChild(labelText); var sourceContainer = createElement('div', { id: elementID + '_scale_src_container' }); element.appendChild(sourceContainer); var srcInputElement = this.createInputElement('input', 'e-pv-scale-ratio-src-input', elementID + '_src_input', sourceContainer); this.sourceTextBox = new NumericTextBox({ value: this.srcValue ? this.srcValue : 1, format: '##', cssClass: 'e-pv-scale-ratio-src-input', min: 1, max: 100 }, srcInputElement); var srcUnitElement = this.createInputElement('button', 'e-pv-scale-ratio-src-unit', elementID + '_src_unit', sourceContainer); this.convertUnit = new DropDownButton({ items: items, cssClass: 'e-pv-scale-ratio-src-unit' }, srcUnitElement); this.convertUnit.select = this.convertUnitSelect.bind(this); var destinationContainer = createElement('div', { id: elementID + '_scale_dest_container' }); var destInputElement = this.createInputElement('input', 'e-pv-scale-ratio-dest-input', elementID + '_dest_input', destinationContainer); this.destTextBox = new NumericTextBox({ value: this.destValue ? this.destValue : 1, format: '##', cssClass: 'e-pv-scale-ratio-dest-input', min: 1, max: 100 }, destInputElement); var destUnitElement = this.createInputElement('button', 'e-pv-scale-ratio-dest-unit', elementID + '_dest_unit', destinationContainer); this.dispUnit = new DropDownButton({ items: items, cssClass: 'e-pv-scale-ratio-dest-unit' }, destUnitElement); this.dispUnit.select = this.dispUnitSelect.bind(this); element.appendChild(destinationContainer); var d