diff --git a/src/Renderer.js b/src/Renderer.js index f0dcd5739..9b8f6270d 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -77,6 +77,8 @@ html2canvas.Renderer = function(parseQueue, opts){ i, queueLen, a, + newCanvas, + bounds, storageLen, renderItem, fstyle; @@ -171,6 +173,34 @@ html2canvas.Renderer = function(parseQueue, opts){ html2canvas.log("html2canvas: Renderer: Canvas renderer done - returning canvas obj"); // this.canvasRenderStorage(queue,this.ctx); + queueLen = options.elements.length; + + if (queueLen === 1) { + if (options.elements[ 0 ] instanceof Element && options.elements[ 0 ].nodeName !== "BODY") { + // crop image to the bounds of selected (single) element + bounds = html2canvas.Util.Bounds( options.elements[ 0 ] ); + newCanvas = doc.createElement('canvas'); + newCanvas.width = bounds.width; + newCanvas.height = bounds.height; + ctx = newCanvas.getContext("2d"); + ctx.drawImage( canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height ); + delete canvas; + return newCanvas; + } + } else { + // TODO clip and resize multiple elements + /* + for ( i = 0; i < queueLen; i+=1 ) { + if (options.elements[ i ] instanceof Element) { + + } + + }*/ + } + + + + return canvas; } @@ -384,11 +414,10 @@ html2canvas.Renderer = function(parseQueue, opts){ //}); + return this; }; - - diff --git a/src/plugins/jquery.plugin.html2canvas.js b/src/plugins/jquery.plugin.html2canvas.js index f119438d0..296f53221 100644 --- a/src/plugins/jquery.plugin.html2canvas.js +++ b/src/plugins/jquery.plugin.html2canvas.js @@ -10,6 +10,9 @@ $message = null, timeoutTimer = false, timer = date.getTime(); + options = options || {}; + options.elements = this; + html2canvas.logging = options && options.logging; html2canvas.Preload(this[0], $.extend({ complete: function(images){ diff --git a/tests/origin.html b/tests/origin.html new file mode 100644 index 000000000..ce596ca3f --- /dev/null +++ b/tests/origin.html @@ -0,0 +1,186 @@ + + + + + + + + + + display/box/float/clear test + + + + +
+
+ toggle +
+
+ +
+
+ bar maids, +
+
+

+ sing to me, erbarme dich +

+
+
+

+ This is a nonsensical document, but syntactically valid HTML 4.0. All 100% conformant CSS1 agents should be able to render the document elements above this paragraph indistinguishably (to the pixel) from this reference rendering, (except font rasterization and form widgets). All discrepancies should be traceable to CSS1 implementation shortcomings. Once you have finished evaluating this test, you can return to the parent page. +

+ +