Skip to content

Commit 7ac9042

Browse files
committed
minor fix for text positioning
1 parent f801222 commit 7ac9042

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

build/html2canvas.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,16 +1005,17 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
10051005
text_align = text_align.replace(["-webkit-auto"],["auto"])
10061006

10071007

1008-
if (this.opts.letterRendering == false && /^(left|right|justify|center|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){
1008+
if (this.opts.letterRendering == false && /^(left|right|justify|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){
10091009
// this.setContextVariable(ctx,"textAlign",text_align);
10101010
renderWords = true;
1011-
renderList = textNode.nodeValue.split(/\b/);
1011+
renderList = textNode.nodeValue.split(/(\b| )/);
10121012

10131013
}else{
1014-
this.setContextVariable(ctx,"textAlign","left");
1014+
// this.setContextVariable(ctx,"textAlign","left");
10151015
renderList = textNode.nodeValue.split("");
10161016
}
10171017

1018+
10181019

10191020
this.setContextVariable(ctx,"fillStyle",color);
10201021
this.setContextVariable(ctx,"font",font);
@@ -1024,6 +1025,8 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
10241025

10251026
var oldTextNode = textNode;
10261027
for(var c=0;c<renderList.length;c++){
1028+
1029+
// TODO only do the splitting for non-range prints
10271030
var newTextNode = oldTextNode.splitText(renderList[c].length);
10281031

10291032

build/html2canvas.min.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Text.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
4040
text_align = text_align.replace(["-webkit-auto"],["auto"])
4141

4242

43-
if (this.opts.letterRendering == false && /^(left|right|justify|center|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){
43+
if (this.opts.letterRendering == false && /^(left|right|justify|auto)$/.test(text_align) && /^(normal|none)$/.test(letter_spacing)){
4444
// this.setContextVariable(ctx,"textAlign",text_align);
4545
renderWords = true;
46-
renderList = textNode.nodeValue.split(/\b/);
46+
renderList = textNode.nodeValue.split(/(\b| )/);
4747

4848
}else{
49-
this.setContextVariable(ctx,"textAlign","left");
49+
// this.setContextVariable(ctx,"textAlign","left");
5050
renderList = textNode.nodeValue.split("");
5151
}
5252

53+
5354

5455
this.setContextVariable(ctx,"fillStyle",color);
5556
this.setContextVariable(ctx,"font",font);
@@ -59,6 +60,8 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
5960

6061
var oldTextNode = textNode;
6162
for(var c=0;c<renderList.length;c++){
63+
64+
// TODO only do the splitting for non-range prints
6265
var newTextNode = oldTextNode.splitText(renderList[c].length);
6366

6467

0 commit comments

Comments
 (0)