Merge pull request #92 from bdkzero/master

Support for other renderers than Canvas and fixed image rendering in SVG renderer
This commit is contained in:
Niklas von Hertzen 2012-05-22 05:19:23 -07:00
commit 16022b81c3
6 changed files with 92 additions and 20 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@
image.jpg
/.project
/.settings/
.envrc

View File

@ -22,10 +22,27 @@
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
<file name="renderers/Canvas.js"/>
<file name="renderers/Canvas.js"/>
<file name="html2canvas-post.txt"/>
</filelist>
</path>
</filelist>
</path>
<path id="sourcefiles-allrends">
<filelist dir="${src.dir}">
<file name="LICENSE"/>
<file name="html2canvas-pre.txt"/>
<file name="Core.js"/>
<file name="Generate.js"/>
<file name="Parse.js"/>
<file name="Preload.js"/>
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
<file name="renderers/Canvas.js"/>
<file name="renderers/SVG.js"/>
<file name="html2canvas-post.txt"/>
</filelist>
</path>
<path id="jquery-plugin">
<fileset dir="${src.dir}" includes="LICENSE"/>
@ -46,11 +63,21 @@
</target>
<pathconvert property="prettty-sourcefiles" pathsep="${line.separator}" refid="sourcefiles"></pathconvert>
<pathconvert property="prettty-sourcefiles-allrends" pathsep="${line.separator}" refid="sourcefiles-allrends"></pathconvert>
<target name="build" depends="build-dir,plugins">
<echo>Concatenating files:${line.separator}${prettty-sourcefiles}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
<path refid="sourcefiles"/>
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
<path refid="sourcefiles"/>
</concat>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME}" />
</target>
<target name="build-allrends" depends="build-dir,plugins">
<echo>Concatenating files:${line.separator}${prettty-sourcefiles-allrends}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
<path refid="sourcefiles-allrends"/>
</concat>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME}" />
</target>
@ -75,7 +102,31 @@
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
<file name="renderers/Canvas.js"/>
<file name="renderers/Canvas.js"/>
</sources>
</jscomp>
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
</target>
<target name="syntaxcheck-allrends" depends="build-dir,build-allrends">
<jscomp compilationLevel="simple" warning="verbose"
debug="false"
output="${build.dir}/${JS_NAME_MIN}.tmp">
<externs dir="${lib.dir}">
<file name="${jquery-externs}"/>
</externs>
<sources dir="${src.dir}">
<!-- need to write them again here since the closure compiler doesn't understand filesets,... -->
<file name="LICENSE"/>
<file name="Core.js"/>
<file name="Generate.js"/>
<file name="Parse.js"/>
<file name="Preload.js"/>
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
<file name="renderers/Canvas.js"/>
<file name="renderers/SVG.js"/>
</sources>
</jscomp>
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
@ -95,6 +146,20 @@
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
</target>
<target name="release-allrends" depends="build-dir,build-allrends,syntaxcheck-allrends">
<jscomp compilationLevel="simple" warning="verbose"
debug="false"
output="${build.dir}/${JS_NAME_MIN}">
<externs dir="${lib.dir}">
<file name="${jquery-externs}"/>
</externs>
<sources dir="${build.dir}">
<file name="${JS_NAME}"/>
</sources>
</jscomp>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
</target>
<target name="clean">
<delete dir="${build.dir}"></delete>
</target>

View File

@ -1,4 +1,4 @@
<html>
<html>
<head>
<script type="text/javascript" src="external/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="build/html2canvas.js"></script>
@ -2370,4 +2370,4 @@ body
<div class="copyright">
&copy;Copyright Max Design 2010
</div>
</body></html>
</body></html>

View File

@ -58,9 +58,9 @@ _html2canvas.Renderer = function(parseQueue, options){
sortZ(parseQueue.zIndex);
if ( typeof options.renderer._create !== "function" ) {
if ( typeof options._renderer._create !== "function" ) {
throw new Error("Invalid renderer defined");
}
return options.renderer._create( parseQueue, options, document, queue, _html2canvas );
return options._renderer._create( parseQueue, options, document, queue, _html2canvas );
};

View File

@ -34,14 +34,20 @@ html2canvas = function( elements, opts ) {
flashcanvas: undefined, // path to flashcanvas
width: null,
height: null,
taintTest: true // do a taint test with all images before applying to canvas
};
taintTest: true, // do a taint test with all images before applying to canvas
renderer: "Canvas"
}, renderer;
options = _html2canvas.Util.Extend(opts, options);
options.renderer = options.renderer || _html2canvas.Renderer.Canvas( options );
if (typeof options.renderer === "string" && _html2canvas.Renderer[options.renderer] !== undefined) {
options._renderer = _html2canvas.Renderer[options.renderer]( options );
} else if (typeof options.renderer === "function") {
options._renderer = options.renderer( options );
} else {
throw("Unknown renderer");
}
_html2canvas.logging = options.logging;
options.complete = function( images ) {

View File

@ -135,10 +135,10 @@ _html2canvas.Renderer.SVG = function( options ) {
el = doc.createElementNS(svgNS, "image");
el.setAttributeNS(xlinkNS, "xlink:href", renderItem['arguments'][0].src);
el.setAttribute("width", renderItem['arguments'][0].width);
el.setAttribute("height", renderItem['arguments'][0].height);
el.setAttribute("x", renderItem['arguments'][5] - renderItem['arguments'][1]);
el.setAttribute("y", renderItem['arguments'][6] - renderItem['arguments'][2]);
el.setAttribute("width", renderItem['arguments'][7]);
el.setAttribute("height", renderItem['arguments'][8]);
el.setAttribute("x", renderItem['arguments'][5]);
el.setAttribute("y", renderItem['arguments'][6]);
el.setAttribute("clip-path", "url(#clipId" + clipId + ")");
// el.setAttribute("xlink:href", );