From d8d560e9e80f86057f08e27d92fafb283c92f533 Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Mon, 18 Jul 2011 19:21:55 +0300 Subject: [PATCH] minor fix for text positioning --- build/html2canvas.js | 9 ++++++--- build/html2canvas.min.js | 5 ++--- src/Text.js | 9 ++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/build/html2canvas.js b/build/html2canvas.js index b39cfe9..d7a2c69 100644 --- a/build/html2canvas.js +++ b/build/html2canvas.js @@ -1005,16 +1005,17 @@ html2canvas.prototype.newText = function(el,textNode,ctx){ text_align = text_align.replace(["-webkit-auto"],["auto"]) - if (this.opts.letterRendering == false && /^(left|right|justify|center|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){ + if (this.opts.letterRendering == false && /^(left|right|justify|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){ // this.setContextVariable(ctx,"textAlign",text_align); renderWords = true; - renderList = textNode.nodeValue.split(/\b/); + renderList = textNode.nodeValue.split(/(\b| )/); }else{ - this.setContextVariable(ctx,"textAlign","left"); + // this.setContextVariable(ctx,"textAlign","left"); renderList = textNode.nodeValue.split(""); } + this.setContextVariable(ctx,"fillStyle",color); this.setContextVariable(ctx,"font",font); @@ -1024,6 +1025,8 @@ html2canvas.prototype.newText = function(el,textNode,ctx){ var oldTextNode = textNode; for(var c=0;ce.zIndex.length;)e.zIndex+="0";for(e.zIndex+=c;b+f+c.toString().length>e.zIndex.length;)e.zIndex+="0";c++});return a=a.sort(function(a,b){return a.zIndexb.zIndex?1:0})}; html2canvas.prototype.setContextVariable=function(a,b,c){a.storage?a.storage.push({type:"variable",name:b,arguments:c}):a[b]=c}; html2canvas.prototype.newText=function(a,b,c){var d=this.getCSS(a,"font-family"),e=this.getCSS(a,"font-size"),f=this.getCSS(a,"color"),g=this.getCSS(a,"font-weight"),k=this.getCSS(a,"font-style"),i=this.getCSS(a,"font-variant"),j=this.getCSS(a,"text-decoration"),h=this.getCSS(a,"text-align"),l=this.getCSS(a,"letter-spacing");b.nodeValue=this.textTransform(b.nodeValue,this.getCSS(a,"text-transform"));if(this.trim(b.nodeValue).length>0){switch(g){case "401":g="bold"}if(j!="none")var m=this.fontMetrics(d, -e);a=i+" "+g+" "+k+" "+e+" "+d;h=h.replace(["-webkit-auto"],["auto"]);this.opts.letterRendering==!1&&/^(left|right|justify|center|auto)$/.test(h)&&/^(normal|none)$/.test(l)?h=b.nodeValue.split(/\b/):(this.setContextVariable(c,"textAlign","left"),h=b.nodeValue.split(""));this.setContextVariable(c,"fillStyle",f);this.setContextVariable(c,"font",a);for(l=0;l-1)return this.fontData[c+1];c=document.createElement("div");document.getElementsByTagName("body")[0].appendChild(c);$(c).css({visibility:"hidden",fontFamily:a,fontSize:b,margin:0,padding:0});var d=document.createElement("img");d.src="http://html2canvas.hertzen.com/images/8.jpg";d.width=1;d.height=1;$(d).css({margin:0,padding:0});var e=document.createElement("span");$(e).css({fontFamily:a,fontSize:b,margin:0, padding:0});e.appendChild(document.createTextNode("Hidden Text"));c.appendChild(e);c.appendChild(d);var f=d.offsetTop-e.offsetTop+1;c.removeChild(e);c.appendChild(document.createTextNode("Hidden Text"));$(c).css("line-height","normal");$(d).css("vertical-align","super");d={baseline:f,lineWidth:1,middle:d.offsetTop-c.offsetTop+1};this.fontData.push(a+"-"+b);this.fontData.push(d);$(c).remove();return d}; html2canvas.prototype.textTransform=function(a,b){switch(b){case "lowercase":return a.toLowerCase();case "capitalize":return a.replace(/(^|\s|:|-|\(|\))([a-z])/g,function(a,b,e){return b+e.toUpperCase()});case "uppercase":return a.toUpperCase();default:return a}};html2canvas.prototype.trim=function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")};html2canvas.prototype.parseElement=function(a,b){var c=this;this.each(a.children,function(a,e){c.parsing(e,b)});this.Renderer(this.contextStacks);this.finish()}; diff --git a/src/Text.js b/src/Text.js index 4cad5af..1200630 100644 --- a/src/Text.js +++ b/src/Text.js @@ -40,16 +40,17 @@ html2canvas.prototype.newText = function(el,textNode,ctx){ text_align = text_align.replace(["-webkit-auto"],["auto"]) - if (this.opts.letterRendering == false && /^(left|right|justify|center|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){ + if (this.opts.letterRendering == false && /^(left|right|justify|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){ // this.setContextVariable(ctx,"textAlign",text_align); renderWords = true; - renderList = textNode.nodeValue.split(/\b/); + renderList = textNode.nodeValue.split(/(\b| )/); }else{ - this.setContextVariable(ctx,"textAlign","left"); + // this.setContextVariable(ctx,"textAlign","left"); renderList = textNode.nodeValue.split(""); } + this.setContextVariable(ctx,"fillStyle",color); this.setContextVariable(ctx,"font",font); @@ -59,6 +60,8 @@ html2canvas.prototype.newText = function(el,textNode,ctx){ var oldTextNode = textNode; for(var c=0;c