Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit 4d18e52

Browse files
author
Ali Ahmed Sahi
committed
Distance, Underline and Strikeout Annotation Added
1 parent e5e06ef commit 4d18e52

File tree

5 files changed

+194
-2
lines changed

5 files changed

+194
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ Thumbs.db
88
/storage/[Tt]emp/
99
/storage/GroupDocs.annotation*.xml
1010
*.lic
11+
/.settings/
12+
*.classpath
13+
*.project

src/main/webapp/app.controller.pageCanvas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
'use strict';
33

44
function main($rootScope, $scope, AnnotationListFactory, FilesFactory, DocumentInfoFactory) {
5-
6-
$scope.docInfo = DocumentInfoFactory.get();
5+
6+
$rootScope.docInfo = DocumentInfoFactory.get();
77
$scope.selectedFile = FilesFactory.selectedFile;
88
$scope.annotationsList = AnnotationListFactory.query();
99
$rootScope.selectedDrawingTool = 'select';

src/main/webapp/app.controller.tools.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
$scope.selectRectangleTool = function ($event) {
77
$rootScope.selectedDrawingTool = 'rectangle';
88
};
9+
$scope.selectDistanceTool = function ($event) {
10+
$rootScope.selectedDrawingTool = 'distance';
11+
};
912
$scope.selectArrowTool = function ($event) {
1013
$rootScope.selectedDrawingTool = 'arrow';
1114
};
@@ -18,6 +21,12 @@
1821
$scope.selectPointTool = function ($event) {
1922
$rootScope.selectedDrawingTool = 'point';
2023
};
24+
$scope.selectUnderlineTool = function ($event) {
25+
$rootScope.selectedDrawingTool = 'underline';
26+
};
27+
$scope.selectStrikeoutTool = function ($event) {
28+
$rootScope.selectedDrawingTool = 'strikeout';
29+
};
2130

2231
$scope.selectSelectTool();
2332
}

src/main/webapp/app.directive.gdxAnnoPage.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@
114114
currentObject.fillColor = 'black';
115115
currentObject.strokeWidth = 2;
116116
break;
117+
case 'underline':
118+
var start = new ps.Point(event.point);
119+
$rootScope.startRow = getStartRow($rootScope.docInfo,start,attrs);
120+
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(start.x));
121+
if($rootScope.startText.length>1){
122+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight), new ps.Point($rootScope.startText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
123+
currentObject.strokeColor = 'black';
124+
currentObject.strokeWidth = 2;
125+
}
126+
else if($rootScope.startText.length>1){
127+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight), new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
128+
currentObject.strokeColor = 'black';
129+
currentObject.strokeWidth = 2;
130+
}
131+
break;
132+
case 'strikeout':
133+
var start = new ps.Point(event.point);
134+
$rootScope.startRow = getStartRow($rootScope.docInfo,start,attrs);
135+
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(start.x));
136+
if($rootScope.startText.length>1){
137+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2), new ps.Point($rootScope.startText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
138+
currentObject.strokeColor = 'black';
139+
currentObject.strokeWidth = 2;
140+
}
141+
else if($rootScope.startText.length>1){
142+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2), new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
143+
currentObject.strokeColor = 'black';
144+
currentObject.strokeWidth = 2;
145+
}
146+
break;
117147
}
118148
};
119149

@@ -141,6 +171,31 @@
141171
currentObject.position.x += event.delta.x;
142172
currentObject.position.y += event.delta.y;
143173
break;
174+
case 'underline':
175+
if(currentObject){
176+
var end = new ps.Point(event.point);
177+
var endText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(end.x));
178+
if(endText.length>1){
179+
currentObject.add(new ps.Point(endText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
180+
}
181+
else if(endText.length>0){
182+
currentObject.add(new ps.Point(endText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
183+
}
184+
}
185+
break;
186+
case 'strikeout':
187+
if(currentObject){
188+
var end = new ps.Point(event.point);
189+
var endText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(end.x));
190+
if(endText.length>1){
191+
currentObject.add(new ps.Point(endText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
192+
}
193+
else if(endText.length>0){
194+
currentObject.add(new ps.Point(endText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
195+
}
196+
197+
}
198+
break;
144199
case 'arrow':
145200
if (currentObject) {
146201
currentObject.remove();
@@ -163,6 +218,40 @@
163218
currentObject.strokeColor = 'black';
164219
currentObject.strokeWidth = 2;
165220
break;
221+
case 'distance':
222+
if(currentObject){
223+
currentObject.remove();
224+
}
225+
var start = new ps.Point(event.downPoint);
226+
var end = new ps.Point(event.point);
227+
var textX = (start.x + end.x)/2;
228+
var textY = (start.y + end.y)/2;
229+
var textPoint = new ps.Point(textX, textY);
230+
var tailLine = new ps.Path.Line(start, end);
231+
var textPosition = end.add(start);
232+
var tailVector = end.subtract(start);
233+
var headLine = tailVector.normalize(10);
234+
var tailArrow = tailVector.normalize(-10);
235+
currentObject = new ps.Group([
236+
new ps.Path([start, end]),
237+
new ps.Path([
238+
end.add(headLine.rotate(150)),
239+
end,
240+
end.add(headLine.rotate(-150))
241+
]),
242+
new ps.Path([
243+
start.add(tailArrow.rotate(-150)),
244+
start,
245+
start.add(tailArrow.rotate(150))
246+
]),
247+
new ps.PointText(textPoint)
248+
]);
249+
250+
currentObject.strokeColor = 'black';
251+
currentObject.strokeWidth = 2;
252+
currentObject._children[3].content = Math.floor(currentObject._children[0].length) + " px";
253+
currentObject._children[3].strokeWidth = 0.5;
254+
break;
166255
}
167256
};
168257

@@ -214,6 +303,43 @@
214303
ant.svgPath = currentObject.exportSVG().firstChild.getAttribute('d');
215304
ant.svgPath += " " + currentObject.exportSVG().lastChild.getAttribute('d');
216305
break;
306+
case 'distance':
307+
ant = {
308+
type : 12,
309+
svgPath : currentObject.exportSVG().children[0].getAttribute('d')+ " " + currentObject.exportSVG().children[1].getAttribute('d') + " " + currentObject.exportSVG().children[2].getAttribute('d'),
310+
text : currentObject.children[3].content,
311+
box : {
312+
x: currentObject.children[3].position.x,
313+
y: currentObject.children[3].position.y,
314+
width: 0,
315+
height: 0
316+
}
317+
};
318+
break;
319+
case 'underline':
320+
ant = {
321+
type : 11,
322+
svgPath : currentObject.exportSVG().getAttribute('d'),
323+
box: {
324+
x: currentObject.bounds.x,
325+
y: currentObject.bounds.y,
326+
width: 0,
327+
height: 0
328+
},
329+
};
330+
break;
331+
case 'strikeout':
332+
ant = {
333+
type : 11,
334+
svgPath : currentObject.exportSVG().getAttribute('d'),
335+
box: {
336+
x: currentObject.bounds.x,
337+
y: currentObject.bounds.y,
338+
width: 0,
339+
height: 0
340+
},
341+
};
342+
break;
217343
}
218344

219345
if (ant.type) {
@@ -309,9 +435,51 @@
309435
arrow.strokeWidth = 2;
310436
arrow.name = item.annotation.guid;
311437
break;
438+
case 11:
439+
var line = new ps.Path();
440+
line.pathData = item.annotation.svgPath;
441+
line.strokeColor = 'black';
442+
line.strokeWidth = 2;
443+
line.name = item.annotation.guid;
444+
break;
445+
case 3:
446+
var line = new ps.Path();
447+
line.pathData = item.annotation.svgPath;
448+
line.strokeColor = 'black';
449+
line.strokeWidth = 2;
450+
line.name = item.annotation.guid;
451+
break;
452+
case 12:
453+
var distance = new ps.Group([
454+
new ps.Path(item.annotation.svgPath.split(" ")[0]),
455+
new ps.Path(item.annotation.svgPath.split(" ")[1]),
456+
new ps.Path(item.annotation.svgPath.split(" ")[2]),
457+
new ps.PointText(new ps.Point(item.annotation.box.x, item.annotation.box.y))
458+
]);
459+
distance.strokeColor = 'black';
460+
distance.strokeWidth = 2;
461+
distance.children[3].content = Math.floor(distance.children[0].length) + " px";
462+
distance.children[3].strokeWidth = 0.5;
463+
distance.name = item.annotation.guid;
464+
break;
312465
}
313466
})
314467
}
468+
function getStartRow(docInfo,start,attrs){
469+
var startRow = [];
470+
for(var i = 0; i<30; i++){
471+
startRow = docInfo.pages[attrs.number-1].rows.filter(x => Math.floor(x.lineTop) == (Math.floor(start.y)-i ));
472+
if(startRow.length>0)
473+
return startRow;
474+
}
475+
if(startRow.length == 0)
476+
for(var i = 0; i<30; i++){
477+
startRow = docInfo.pages[attrs.number-1].rows.filter(x => Math.floor(x.lineTop) == (Math.floor(start.y)+i ));
478+
if(startRow.length>0)
479+
return startRow;
480+
}
481+
482+
}
315483

316484
function setupAnnotationDeletion($rootScope, AnnotationFactory, scope, element, attrs) {
317485
var ps = paper.PaperScope.get(scope.paperScopeId);

src/main/webapp/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ <h1>GroupDocs.Annotation for Java</h1>
7474
<md-icon>arrow_forward</md-icon>
7575
<md-tooltip>Arrow</md-tooltip>
7676
</md-button>
77+
<md-button class="md-icon-button" aria-label="Distance" ng-click="selectDistanceTool()">
78+
<md-icon>compare_arrows</md-icon>
79+
<md-tooltip>Distance</md-tooltip>
80+
</md-button>
81+
<md-button class="md-icon-button" aria-label="Underline" ng-click="selectUnderlineTool()">
82+
<md-icon>format_underlined</md-icon>
83+
<md-tooltip>Underline</md-tooltip>
84+
</md-button>
85+
<md-button class="md-icon-button" aria-label="Strikeout" ng-click="selectStrikeoutTool()">
86+
<md-icon>format_strikethrough</md-icon>
87+
<md-tooltip>Strikeout</md-tooltip>
88+
</md-button>
7789
</div>
7890
</div>
7991
<md-content flex id="content" ng-controller="PageCanvasController">

0 commit comments

Comments
 (0)