-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf_draw.js
86 lines (76 loc) · 2.09 KB
/
pdf_draw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// by Chtiwi Malek ===> CODICODE.COM
var mousePressed = false;
var lastX, lastY;
var ctx;
function InitThis() {
ctx = document.getElementById('pdf_renderer').getContext("2d");
$('#pdf_renderer').mousedown(function (e) {
mousePressed = true;
Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, false);
});
$('#pdf_renderer').mousemove(function (e) {
if (mousePressed) {
Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, true);
}
});
$('#pdf_renderer').mouseup(function (e) {
if (mousePressed) {
mousePressed = false;
cPush();
}
});
$('#pdf_renderer').mouseleave(function (e) {
if (mousePressed) {
mousePressed = false;
cPush();
}
});
drawImage();
}
function drawImage() {
render();
cPush();
}
function Draw(x, y, isDown) {
if (isDown) {
ctx.beginPath();
ctx.strokeStyle = $('#selColor').val();
ctx.lineWidth = $('#selWidth').val();
ctx.lineJoin = "round";
ctx.moveTo(lastX, lastY);
ctx.lineTo(x, y);
ctx.closePath();
ctx.stroke();
}
lastX = x;
lastY = y;
}
var cPushArray = new Array();
var cStep = -1;
function cPush() {
cStep++;
if (cStep < cPushArray.length) { cPushArray.length = cStep; }
cPushArray.push(document.getElementById('pdf_renderer').toDataURL());
document.title = "CheeseDuck Writing Service";
}
function cUndo() {
if(cStep == 0){
render();
}
if (cStep > 0) {
cStep--;
var canvasPic = new Image();
canvasPic.src = cPushArray[cStep];
canvasPic.onload = function () { ctx.drawImage(canvasPic, 0, 0); }
document.title = "CheeseDuck Writing Service";
}
}
function cRedo() {
if (cStep <= cPushArray.length-1) {
cStep++;
var canvasPic = new Image();
canvasPic.src = cPushArray[cStep];
canvasPic.onload = function () { ctx.drawImage(canvasPic, 0, 0); }
document.title = "CheeseDuck Writing Service";
}
}