-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas_lib.js
67 lines (56 loc) · 1.53 KB
/
canvas_lib.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
colorjack.currentWindow = {
getWindowView: function() {
return colorjack.document.defaultView.window;
},
createCanvasLayer: function(w,h) {
var layer = colorjack.document.createElement('canvas');
layer.style.position = "absolute"; // containing block
layer.style.visibility = "hidden";
if (w && h) {
colorjack.currentWindow.setCanvasSize(layer, w, h);
}
return layer;
},
setCanvasSize: function(layer,w,h) {
layer.setAttribute('width', w);
layer.setAttribute('height', h);
},
setBorder: function(layer, width, color, style) {
var border = width + "px " + color;
if (style !== undefined) {
border += " solid";
}
layer.style.border = border;
},
getBackgroundColor: function() {
var bg;
try {
bg = colorjack.document.body.bgColor;
} catch (ignore) {}
return bg || white;
},
/* GraphicsLib */
createBufferImage: function(x,y,w,h,image) {
var canvas = colorjack.document.createElement('canvas');
//canvas.width = w;
//canvas.height = h;
//canvas.style.width = w + "px";
//canvas.style.height = h + "px";
canvas.setAttribute('width', w);
canvas.setAttribute('height', h);
var context = canvas.getContext('2d');
x = Math.round(x);
y = Math.round(y);
w = Math.round(w);
h = Math.round(h);
context.drawImage(image, x,y,w,h, 0,0,w,h);
var result = context.canvas;
return result;
},
restoreBufferImage: function(ctx,buffer,x,y,w,h) {
ctx.save();
ctx.globalCompositeOperation = "copy";
ctx.drawImage(buffer, 0, 0, w, h, x, y, w, h);
ctx.restore();
}
};