-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.xhtml
executable file
·182 lines (146 loc) · 6.52 KB
/
demo.xhtml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="stylesheets/master.css" />
<title>Final SVG vs. Canvas battle</title>
<script type="text/javascript" src="javascripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="javascripts/rgbcolor.js"></script>
<script type="text/javascript" src="javascripts/canvg.js"></script>
<script type="text/javascript" src="javascripts/pixel_toolbar.js"></script>
<script type="text/javascript" src="javascripts/pixel_canvas.js"></script>
<script type="text/javascript" src="javascripts/vector_svg.js"></script>
<script type="text/javascript" src="javascripts/canvas_to_svg.js"></script>
<script type="text/javascript" src="javascripts/svg_to_canvas.js"></script>
<script type="text/javascript" src="javascripts/mouse.js"></script>
<script type="text/javascript" src="javascripts/random.js"></script>
<script type="text/javascript" src="javascripts/svg_todataurl.js"></script>
<script type="text/javascript">
<![CDATA[
var svg = null;
var canvas = null;
window.onload = function() {
canvas = document.getElementById("canvas");
svg = document.getElementById("svg");
PixelCanvas.init(canvas);
// var canvastool = document.getElementById("canvasarea").getElementsByClassName("toolbar")[0];
// activatePixelToolbar(canvastool, PixelCanvas);
VectorSVG.init(svg);
for (var i = 0; i < 3; i++) {
VectorSVG.addRandomCircle();
PixelCanvas.drawRandomPixel();
}
}
function export_img(data_url) {
$("#export_img").attr("src", data_url);
}
function export_window(data_url) {
window.open(data_url);
}
function break_now(klass) {
// TODO: efekti
$("." + klass).addClass("broken");
}
function will_break(klass) {
// TODO: efekti
$("." + klass).addClass("will_break_canvas");
$("." + klass).each(function(a) {
this.href += " break_now('will_read_canvas');";
})
}
]]>
</script>
</head>
<body>
<h1>From SVG to Canvas and Back (demo)</h1>
<div id="svgarea_flow">
<h2>SVG</h2>
<div class="toolbar">
<a href="javascript:alert('Click that SVG area with your mouse!')">circle</a>
<a href="javascript:VectorSVG.addImage('gordo-small.png');">png image</a>
<a href="javascript:VectorSVG.addImage('gordo.svg'); will_break('might_break_canvas');">svg image</a>
<a class="will_read_canvas" href="javascript:CanvasToSVG.convert(canvas, svg);">import canvas</a>
<a href="javascript:VectorSVG.clearCanvas();">clear</a>
</div>
<svg id="svg" width="500" height="300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" />
</div>
<div id="canvasarea_flow">
<h2>Canvas</h2>
<div class="toolbar">
<a href="javascript:alert('Click and drag the Canvas area with your mouse!')">pixel</a>
<a href="javascript:PixelCanvas.drawImage('gordo-small.png');">png image</a>
<a href="javascript:PixelCanvas.drawImage('gordo.svg');">svg image</a>
<a class="might_break_canvas" href="javascript:SVGToCanvas.convertCanvg(svg, canvas);">import svg</a>
<a href="javascript:PixelCanvas.clearCanvas();">clear</a>
</div>
<canvas id="canvas" width="500" height="300">NO CANVAS FOR YOU</canvas>
</div>
<div id="demolist">
<ol>
<li>Canvas to SVG
<ul>
<li><a class="will_read_canvas" href="javascript:CanvasToSVG.convert(canvas, svg);">Canvas.toDataURL("image/png");</a>
<ul>
<li>Works with all major browsers, including IE9.</li>
</ul>
</li>
</ul>
</li>
<li>SVG to Canvas
<ul>
<li><a class="might_break_canvas" href="javascript:SVGToCanvas.convertCanvg(svg, canvas);">SVG.toDataURL('image/png');</a>
<ul>
<li>Emulated with <a href="http://code.google.com/p/canvg/">canvg</a>.</li>
<li>Works with all major browsers, including IE9.</li>
<li>Canvas becomes write-only only if the imported SVG has images from different origin, <a href="javascript:VectorSVG.addImage('gordo.svg'); will_break('might_break_canvas');">or embedded svg images</a>.</li>
</ul>
</li>
<li>
<a href="javascript:SVGToCanvas.convertServer(svg, canvas);">Server-side conversion with Ajax</a>
<ul>
<li>Works with all major browsers, including IE9.</li>
</ul>
</li>
<li><a class="will_break_canvas" href="javascript:SVGToCanvas.convert(svg, canvas); break_now('will_read_canvas');">Draw SVG to Canvas with canvas.drawImage()</a>
<ul>
<li>Canvas becomes write-only! (<code>origin-clean</code> <em>dirty</em>)</li>
<li>Works with Webkit (Chrome and Safari).</li>
</ul>
</li>
</ul>
</li>
<li>Exporting as a file
<ol>
<li>Canvas→PNG
<ol>
<li>Right-click→Save as… (Firefox supports it)</li>
<li class="will_read_canvas"><a href="javascript:export_img(canvas.toDataURL());">Canvas.toDataURL</a> (<a href="javascript:export_window(canvas.toDataURL());">new window</a>)</li>
</ol>
</li>
<li>SVG→PNG
<ol>
<li><a href="javascript:SVGToCanvas.exportPNGserver(svg, export_img);">Server-side</a></li>
<li><a class="might_break_canvas" href="javascript:SVGToCanvas.exportPNGcanvg(svg, export_img);">SVG.toDataURL('image/png')</a></li>
</ol>
</li>
<li>SVG→SVG file
<ol>
<li>Right-click→Save as… (IE9 supports it)</li>
<li><a href="javascript:SVGToCanvas.exportSVG(svg, export_img);">SVG.toDataURL('image/svg+xml')</a> (<a href="javascript:SVGToCanvas.exportSVG(svg, export_window);">new window</a>)</li>
</ol>
</li>
</ol>
</li>
</ol>
</div>
<img id="export_img" alt="placeholder for exported svg/pixel data"/>
<dl id="legend">
<dt>Legend (based on background-color):</dt>
<dd><span class="broken">This won't work anymore, because Canvas' <code>origin-clean</code> is <var>dirty</var>. Maybe you broke it?</span></dd>
<dd><span class="will_break_canvas">Beware! This will set Canvas' <code>origin-clean</code> <var>dirty</var>, making Canvas write-only.</span></dd>
<dd><span class="might_break_canvas_legend">This <em>might</em> set Canvas' <code>origin-clean</code> <var>dirty</var>, depending on whether you're transferring images inside SVG data.</span></dd>
</dl>
<p>Dare to look <a href="demo-full.xhtml">the full demo page</a>?</p>
</body>
</html>