context fixes + default font size added

This commit is contained in:
Vadim Namniak
2014-10-08 22:53:50 -04:00
parent 5b7a7f9cfe
commit f464af8c5d
4 changed files with 10 additions and 10 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
/*! CanvasTextWrapper (https://github.com/namniak/CanvasTextWrapper)
* Version: 0.1.0
* Version: 0.2.0
*
* MIT License (http://www.opensource.org/licenses/mit-license.html)
* Copyright (c) 2014 Vadim Namniak
@@ -16,7 +16,7 @@
paddingY: 0, // zero px top & bottom text padding relative to canvas or parent
fitParent: false, // text is tested to fit canvas width
lineBreak: 'auto', // text fills the element's (canvas or parent) width going to a new line on a whole word
sizeToFill: false // text is resized to fill the container height (given font size is ignored)
sizeToFill: false // text is resized to fill the container (given font size is ignored)
};
window.CanvasTextWrapper = function(canvas, text, opts) {
@@ -34,7 +34,7 @@
}
// extract font size
this.lineHeight = parseInt(this.font.replace(/^\D+/g, ''), 10);
this.lineHeight = parseInt(this.font.replace(/^\D+/g, ''), 10) || 18;
// validate all set properties
this.validate();
@@ -78,10 +78,10 @@
this.setTextVerticalAlign(textPos, textBlockHeight);
for (var i = 0; i < lines.length; i++) {
this.setTextHorizontalAlign(context, textPos, elementWidth, lines[i]);
this.setTextHorizontalAlign(this.context, textPos, elementWidth, lines[i]);
textPos.y = parseInt(textPos.y) + parseInt(this.lineHeight);
context.fillText(lines[i], textPos.x, textPos.y);
this.context.fillText(lines[i], textPos.x, textPos.y);
}
},
@@ -196,4 +196,4 @@
}
}
};
})();
})();