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

@ -27,6 +27,23 @@
</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"/>
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
@ -47,6 +64,8 @@
<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}">
@ -55,6 +74,14 @@
<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>
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
classpath="${lib.dir}/compiler.jar" onerror="report"/>
@ -81,6 +108,30 @@
<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>
</target>
<target name="release" depends="build-dir,build,syntaxcheck">
<jscomp compilationLevel="simple" warning="verbose"
debug="false"
@ -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

@ -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,13 +34,19 @@ 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", );