From a1889cd702c4f02d7de6ee646007cffc0c78d5f5 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Mon, 18 Jul 2011 13:17:45 +0300 Subject: [PATCH] moved border drawing to Borders.js --- src/Border.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Draw.js | 47 ++++++----------------------------------------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/Border.js b/src/Border.js index 200e465..c77136f 100644 --- a/src/Border.js +++ b/src/Border.js @@ -15,4 +15,51 @@ html2canvas.prototype.getBorderData = function(el){ return borders; -} \ No newline at end of file +} + +html2canvas.prototype.drawBorders = function(el,ctx, x, y, w, h){ + + /* + * TODO add support for different border-style's than solid + */ + var borders = this.getBorderData(el); + var _ = this; + + this.each(borders,function(borderSide,borderData){ + if (borderData.width>0){ + var bx = x, + by = y, + bw = w, + bh = h-(borders[2].width); + switch(borderSide){ + case 0: + // top border + bh = borders[0].width; + break; + case 1: + // right border + bx = x+w-(borders[1].width); + bw = borders[1].width; + break; + case 2: + // bottom border + by = (by+h)-(borders[2].width); + bh = borders[2].width; + break; + case 3: + // left border + bw = borders[3].width; + break; + } + + _.newRect(ctx,bx,by,bw,bh,borderData.color); + + + + } + + }); + + return borders; + +}; diff --git a/src/Draw.js b/src/Draw.js index da7296f..613e9fb 100644 --- a/src/Draw.js +++ b/src/Draw.js @@ -14,7 +14,10 @@ html2canvas.prototype.newElement = function(el,parentStack){ image; var bgcolor = this.getCSS(el,"background-color"); - var zindex = this.formatZ(this.getCSS(el,"z-index"),this.getCSS(el,"position"),parentStack.zIndex,el.parentNode); + + parentStack = parentStack || {}; + + var zindex = this.formatZ(this.getCSS(el,"zIndex"),this.getCSS(el,"position"),parentStack.zIndex,el.parentNode); //console.log(el.nodeName+":"+zindex+":"+this.getCSS(el,"position")+":"+this.numDraws+":"+this.getCSS(el,"z-index")) @@ -33,46 +36,8 @@ html2canvas.prototype.newElement = function(el,parentStack){ this.setContextVariable(ctx,"globalAlpha",stack.opacity); - /* - * TODO add support for different border-style's than solid - */ - var borders = this.getBorderData(el); - - this.each(borders,function(borderSide,borderData){ - if (borderData.width>0){ - var bx = x, - by = y, - bw = w, - bh = h-(borders[2].width); - switch(borderSide){ - case 0: - // top border - bh = borders[0].width; - break; - case 1: - // right border - bx = x+w-(borders[1].width); - bw = borders[1].width; - break; - case 2: - // bottom border - by = (by+h)-(borders[2].width); - bh = borders[2].width; - break; - case 3: - // left border - bw = borders[3].width; - break; - } - - _.newRect(ctx,bx,by,bw,bh,borderData.color); - - - - } - - }); - + // draw element borders + var borders = this.drawBorders(el, ctx, bounds.left, bounds.top, bounds.width, bounds.height); if (this.ignoreRe.test(el.nodeName) && this.opts.iframeDefault != "transparent"){