mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
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:
commit
16022b81c3
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@
|
|||||||
image.jpg
|
image.jpg
|
||||||
/.project
|
/.project
|
||||||
/.settings/
|
/.settings/
|
||||||
|
.envrc
|
||||||
|
65
build.xml
65
build.xml
@ -27,6 +27,23 @@
|
|||||||
</filelist>
|
</filelist>
|
||||||
</path>
|
</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">
|
<path id="jquery-plugin">
|
||||||
<fileset dir="${src.dir}" includes="LICENSE"/>
|
<fileset dir="${src.dir}" includes="LICENSE"/>
|
||||||
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
|
<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" 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">
|
<target name="build" depends="build-dir,plugins">
|
||||||
<echo>Concatenating files:${line.separator}${prettty-sourcefiles}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
|
<echo>Concatenating files:${line.separator}${prettty-sourcefiles}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
|
||||||
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
|
<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}" />
|
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME}" />
|
||||||
</target>
|
</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"
|
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
|
||||||
classpath="${lib.dir}/compiler.jar" onerror="report"/>
|
classpath="${lib.dir}/compiler.jar" onerror="report"/>
|
||||||
|
|
||||||
@ -81,6 +108,30 @@
|
|||||||
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
|
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
|
||||||
</target>
|
</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">
|
<target name="release" depends="build-dir,build,syntaxcheck">
|
||||||
<jscomp compilationLevel="simple" warning="verbose"
|
<jscomp compilationLevel="simple" warning="verbose"
|
||||||
debug="false"
|
debug="false"
|
||||||
@ -95,6 +146,20 @@
|
|||||||
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
|
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
|
||||||
</target>
|
</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">
|
<target name="clean">
|
||||||
<delete dir="${build.dir}"></delete>
|
<delete dir="${build.dir}"></delete>
|
||||||
</target>
|
</target>
|
||||||
|
@ -58,9 +58,9 @@ _html2canvas.Renderer = function(parseQueue, options){
|
|||||||
|
|
||||||
|
|
||||||
sortZ(parseQueue.zIndex);
|
sortZ(parseQueue.zIndex);
|
||||||
if ( typeof options.renderer._create !== "function" ) {
|
if ( typeof options._renderer._create !== "function" ) {
|
||||||
throw new Error("Invalid renderer defined");
|
throw new Error("Invalid renderer defined");
|
||||||
}
|
}
|
||||||
return options.renderer._create( parseQueue, options, document, queue, _html2canvas );
|
return options._renderer._create( parseQueue, options, document, queue, _html2canvas );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
14
src/Util.js
14
src/Util.js
@ -34,13 +34,19 @@ html2canvas = function( elements, opts ) {
|
|||||||
flashcanvas: undefined, // path to flashcanvas
|
flashcanvas: undefined, // path to flashcanvas
|
||||||
width: null,
|
width: null,
|
||||||
height: 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 = _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;
|
_html2canvas.logging = options.logging;
|
||||||
options.complete = function( images ) {
|
options.complete = function( images ) {
|
||||||
|
@ -135,10 +135,10 @@ _html2canvas.Renderer.SVG = function( options ) {
|
|||||||
|
|
||||||
el = doc.createElementNS(svgNS, "image");
|
el = doc.createElementNS(svgNS, "image");
|
||||||
el.setAttributeNS(xlinkNS, "xlink:href", renderItem['arguments'][0].src);
|
el.setAttributeNS(xlinkNS, "xlink:href", renderItem['arguments'][0].src);
|
||||||
el.setAttribute("width", renderItem['arguments'][0].width);
|
el.setAttribute("width", renderItem['arguments'][7]);
|
||||||
el.setAttribute("height", renderItem['arguments'][0].height);
|
el.setAttribute("height", renderItem['arguments'][8]);
|
||||||
el.setAttribute("x", renderItem['arguments'][5] - renderItem['arguments'][1]);
|
el.setAttribute("x", renderItem['arguments'][5]);
|
||||||
el.setAttribute("y", renderItem['arguments'][6] - renderItem['arguments'][2]);
|
el.setAttribute("y", renderItem['arguments'][6]);
|
||||||
el.setAttribute("clip-path", "url(#clipId" + clipId + ")");
|
el.setAttribute("clip-path", "url(#clipId" + clipId + ")");
|
||||||
// el.setAttribute("xlink:href", );
|
// el.setAttribute("xlink:href", );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user