Added timer/statistics for rendering

This commit is contained in:
Niklas von Hertzen
2011-07-17 02:42:45 +03:00
parent 3193e1a20b
commit 45381454b4
7 changed files with 61 additions and 21 deletions

View File

@ -216,4 +216,5 @@ html2canvas.prototype.drawBackgroundRepeat = function(image,x,y,width,height,elx
width-sourceX, // destination width
height-sourceY // destination height
);
this.numDraws++;
}

View File

@ -29,6 +29,7 @@ function html2canvas(el, userOptions) {
this.imagesLoaded = 0;
this.images = [];
this.fontData = [];
this.numDraws = 0;
this.ignoreElements = "IFRAME|OBJECT|PARAM";
this.ignoreRe = new RegExp("("+this.ignoreElements+")");
@ -45,7 +46,9 @@ function html2canvas(el, userOptions) {
}*/
// Start script
this.init();
this.init();
return this;
}
@ -144,6 +147,6 @@ html2canvas.prototype.finish = function(){
newCanvas.height = window.innerHeight;
}
this.opts.ready(this.canvas);
this.opts.ready(this);
}

View File

@ -89,6 +89,7 @@ html2canvas.prototype.newElement = function(el){
if (el.nodeName=="IMG"){
image = _.loadImage(_.getAttr(el,'src'));
if (image){
this.ctx.drawImage(
image,
0, //sx
@ -101,6 +102,7 @@ html2canvas.prototype.newElement = function(el){
bounds.height - (borders[0].width + borders[2].width + parseInt(_.getCSS(el,'padding-top'),10) + parseInt(_.getCSS(el,'padding-bottom'),10)) //dh
);
this.numDraws++;
}else{
this.log("Error loading <img>:" + _.getAttr(el,'src'));
}
@ -122,6 +124,7 @@ html2canvas.prototype.newElement = function(el){
html2canvas.prototype.printText = function(currentText,x,y){
if (this.trim(currentText).length>0){
this.ctx.fillText(currentText,x,y);
this.numDraws++;
}
}
@ -132,5 +135,6 @@ html2canvas.prototype.newRect = function(x,y,w,h,bgcolor){
if (bgcolor!="transparent"){
this.ctx.fillStyle = bgcolor;
this.ctx.fillRect (x, y, w, h);
this.numDraws++;
}
}

View File

@ -13,18 +13,28 @@
new html2canvas(this.get(0), {
logging: true,
ready: function(canvas) {
ready: function(renderer) {
var finishTime = new Date();
// console.log((finishTime.getTime()-timer)/1000);
document.body.appendChild(renderer.canvas);
document.body.appendChild(canvas);
var canvas = $(canvas);
var canvas = $(renderer.canvas);
canvas.css('position','absolute')
.css('left',0).css('top',0);
// $('body').append(canvas);
$(canvas).siblings().toggle();
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)/1000) + " seconds<br />Total of "+renderer.numDraws+" draws performed",4000);
$(window).click(function(){
if (!canvas.is(':visible')){
$(canvas).toggle().siblings().toggle();
@ -42,15 +52,16 @@
});
function throwMessage(msg){
function throwMessage(msg,duration){
window.clearTimeout(timeoutTimer);
timeoutTimer = window.setTimeout(function(){
message.fadeOut(function(){
message.remove();
});
},2000);
},duration || 2000);
$(message).remove();
message = $('<div />').text(msg).css({
message = $('<div />').html(msg).css({
margin:0,
padding:10,
background: "#000",
@ -64,6 +75,7 @@
borderRadius:12,
width:'auto',
height:'auto',
textAlign:'center',
textDecoration:'none'
}).hide().fadeIn().appendTo('body');
}