add support for selecting single elements to render

This commit is contained in:
Niklas von Hertzen
2012-02-20 17:16:57 +02:00
parent d5040e119a
commit 0cb252ada9
3 changed files with 220 additions and 2 deletions

View File

@ -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;
};

View File

@ -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){