Skip to content

Commit 67d3e0d

Browse files
committed
first commit for SVG powered rendering
1 parent 8a5b09b commit 67d3e0d

File tree

1 file changed

+109
-2
lines changed

1 file changed

+109
-2
lines changed

src/Parse.js

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ _html2canvas.Parse = function ( images, options ) {
1515

1616
var support = {
1717
rangeBounds: false
18+
/*,svgRendering: (function( ){
19+
var img = new Image(),
20+
canvas = document.createElement("canvas"),
21+
ctx = (canvas.getContext === undefined) ? false : canvas.getContext("2d");
22+
if (ctx === false) {
23+
// browser doesn't support canvas, good luck supporting SVG on canvas
24+
return false;
25+
}
26+
canvas.width = canvas.height = 10;
27+
img.src = [
28+
"data:image/svg+xml,",
29+
"<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>",
30+
"<foreignObject width='10' height='10'>",
31+
"<div xmlns='http://www.w3.org/1999/xhtml' style='width:10;height:10;'>",
32+
"sup",
33+
"</div>",
34+
"</foreignObject>",
35+
"</svg>"
36+
].join("");
37+
try {
38+
ctx.drawImage(img, 0, 0);
39+
canvas.toDataURL();
40+
} catch(e) {
41+
return false;
42+
}
43+
h2clog('html2canvas: Parse: SVG powered rendering available');
44+
return true;
45+
46+
})()*/
1847
},
1948
element = (( options.elements === undefined ) ? document.body : options.elements[0]), // select body by default
2049
needReorder = false,
@@ -34,8 +63,86 @@ _html2canvas.Parse = function ( images, options ) {
3463
children,
3564
childrenLen;
3665

37-
38-
66+
/*
67+
SVG powered HTML rendering, non-tainted canvas available from FF 11+ onwards,
68+
but due to bug https://bugzilla.mozilla.org/show_bug.cgi?id=733345 excluding this code out for now
69+
70+
if (support.svgRendering || true) {
71+
(function( body, width, height ){
72+
var img = new Image(),
73+
html = "";
74+
75+
function parseDOM( el ) {
76+
var children = _html2canvas.Util.Children( el ),
77+
len = children.length,
78+
attr,
79+
a,
80+
alen,
81+
elm,
82+
i;
83+
for ( i = 0; i < len; i+=1 ) {
84+
elm = children[ i ];
85+
if ( elm.nodeType === 3 ) {
86+
// Text node
87+
88+
html += elm.nodeValue.replace(/\</g,"&lt;").replace(/\>/g,"&gt;");
89+
} else if ( elm.nodeType === 1 ) {
90+
// Element
91+
if ( !/^(script|meta|title)$/.test(elm.nodeName.toLowerCase()) ) {
92+
93+
html += "<" + elm.nodeName.toLowerCase();
94+
95+
// add attributes
96+
if ( elm.hasAttributes() ) {
97+
attr = elm.attributes;
98+
alen = attr.length;
99+
for ( a = 0; a < alen; a+=1 ) {
100+
html += " " + attr[ a ].name + '="' + attr[ a ].value + '"';
101+
}
102+
}
103+
104+
105+
html += '>';
106+
107+
parseDOM( elm );
108+
109+
110+
html += "</" + elm.nodeName.toLowerCase() + ">";
111+
}
112+
}
113+
114+
}
115+
116+
}
117+
118+
parseDOM( body );
119+
img.src = [
120+
"data:image/svg+xml,",
121+
"<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='" + width + "' height='" + height + "'>",
122+
"<foreignObject width='" + width + "' height='" + height + "'>",
123+
"<html xmlns='http://www.w3.org/1999/xhtml' style='margin:0;'>",
124+
html,
125+
"</html>",
126+
"</foreignObject>",
127+
"</svg>"
128+
].join("");
129+
130+
console.log(img.src);
131+
img.onerror = function(e) {
132+
console.log(e);
133+
};
134+
135+
img.onload = function() {
136+
console.log("loaded");
137+
};
138+
139+
document.body.appendChild(img);
140+
})( document.documentElement, 1280, 1024 );
141+
142+
}
143+
return;
144+
*/
145+
39146
images = images || {};
40147

41148
// Test whether we can use ranges to measure bounding boxes

0 commit comments

Comments
 (0)