Skip to content

Commit f166dad

Browse files
committed
Make circles blue.
Remove draw time radius assignment. Honor creation radius. Creation radius set to 10. Create circle by selecting a single point.
1 parent 867c63a commit f166dad

File tree

9 files changed

+227
-57
lines changed

9 files changed

+227
-57
lines changed

dist/pdf-annotate.js

Lines changed: 121 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pdf-annotate.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/UI/circle.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import PDFJSAnnotate from '../PDFJSAnnotate';
2+
import config from '../config';
3+
import { appendChild } from '../render/appendChild';
4+
import {
5+
findSVGAtPoint,
6+
getMetadata,
7+
convertToSvgPoint
8+
} from './utils';
9+
10+
let _enabled = false;
11+
let _type;
12+
13+
/**
14+
* Handle document.mouseup event
15+
*
16+
* @param {Event} e The DOM event to handle
17+
*/
18+
function handleDocumentMouseup(e) {
19+
let svg = findSVGAtPoint(e.clientX, e.clientY);
20+
if (!svg) {
21+
return;
22+
}
23+
let rect = svg.getBoundingClientRect();
24+
saveCircle(svg, _type, {
25+
x: e.clientX - rect.left,
26+
y: e.clientY - rect.top
27+
}, "0000FF");
28+
}
29+
30+
/**
31+
* Save a circle annotation
32+
*
33+
* @param {String} type The type of circle (circle, emptycircle, fillcircle)
34+
* @param {Object} pt The point to use for annotation
35+
* @param {String} color The color of the rects
36+
*/
37+
function saveCircle(svg, type, pt, color) {
38+
// Initialize the annotation
39+
let svg_pt = convertToSvgPoint([ pt.x, pt.y ], svg)
40+
let annotation = {
41+
type,
42+
color,
43+
cx: svg_pt[0],
44+
cy: svg_pt[1],
45+
r: 10
46+
};
47+
48+
let { documentId, pageNumber } = getMetadata(svg);
49+
50+
// Add the annotation
51+
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
52+
.then((annotation) => {
53+
appendChild(svg, annotation);
54+
});
55+
}
56+
57+
/**
58+
* Enable circle behavior
59+
*/
60+
export function enableCircle(type) {
61+
_type = type;
62+
63+
if (_enabled) { return; }
64+
65+
_enabled = true;
66+
document.addEventListener('mouseup', handleDocumentMouseup);
67+
}
68+
69+
/**
70+
* Disable circle behavior
71+
*/
72+
export function disableCircle() {
73+
if (!_enabled) { return; }
74+
75+
_enabled = false;
76+
document.removeEventListener('mouseup', handleDocumentMouseup);
77+
}

src/UI/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { disablePen, enablePen, setPen } from './pen';
44
import { disableArrow, enableArrow, setArrow } from './arrow';
55
import { disablePoint, enablePoint } from './point';
66
import { disableRect, enableRect } from './rect';
7+
import { disableCircle, enableCircle } from './circle';
78
import { disableText, enableText, setText } from './text';
89
import { createPage, renderPage } from './page';
910

@@ -13,6 +14,7 @@ export default {
1314
disablePen, enablePen, setPen,
1415
disablePoint, enablePoint,
1516
disableRect, enableRect,
17+
disableCircle, enableCircle,
1618
disableArrow, enableArrow,
1719
disableText, enableText, setText,
1820
createPage, renderPage

src/UI/rect.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getSelectionRects() {
4444
*/
4545
function handleDocumentMousedown(e) {
4646
let svg;
47-
if ((_type !== 'area' && _type !== 'circle' && _type !== 'fillcircle' && _type !== 'emptycircle')|| !(svg = findSVGAtPoint(e.clientX, e.clientY))) {
47+
if (_type !== 'area' || !(svg = findSVGAtPoint(e.clientX, e.clientY))) {
4848
return;
4949
}
5050

@@ -89,7 +89,7 @@ function handleDocumentMousemove(e) {
8989
*/
9090
function handleDocumentMouseup(e) {
9191
let rects;
92-
if ((_type !== 'area' && _type !== 'circle'&& _type !== 'fillcircle'&& _type !== 'emptycircle') && (rects = getSelectionRects())) {
92+
if (_type !== 'area' && (rects = getSelectionRects())) {
9393
let svg = findSVGAtPoint(rects[0].left, rects[0].top);
9494
saveRect(_type, [...rects].map((r) => {
9595
return {
@@ -99,7 +99,7 @@ function handleDocumentMouseup(e) {
9999
height: r.height
100100
};
101101
}));
102-
} else if ((_type === 'area' || _type === 'circle'|| _type === 'fillcircle'|| _type === 'emptycircle') && overlay) {
102+
} else if (_type === 'area' && overlay) {
103103
let svg = overlay.parentNode.querySelector(config.annotationSvgQuery());
104104
let rect = svg.getBoundingClientRect();
105105
saveRect(_type, [{
@@ -144,7 +144,6 @@ function handleDocumentKeyup(e) {
144144
*/
145145
function saveRect(type, rects, color) {
146146
let svg = findSVGAtPoint(rects[0].left, rects[0].top);
147-
let node;
148147
let annotation;
149148

150149
if (!svg) {
@@ -196,15 +195,6 @@ function saveRect(type, rects, color) {
196195
annotation.height = rect.height;
197196
}
198197

199-
if (type === 'circle'||type === 'emptycircle'||type === 'fillcircle') {
200-
let rect = annotation.rectangles[0];
201-
delete annotation.rectangles;
202-
annotation.cx = rect.x + rect.width / 2;
203-
annotation.cy = rect.y + rect.height / 2;
204-
annotation.r = rect.width; // ignored right now
205-
annotation.r = rect.height; // ignored right now
206-
}
207-
208198
let { documentId, pageNumber } = getMetadata(svg);
209199

210200
// Add the annotation

0 commit comments

Comments
 (0)