Skip to content

Context font is now updated whenever text properties are set. #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/typography/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ define(function (require) {
*/
p5.prototype.textSize = function(s) {
this._setProperty('_textSize', s);
this._applyTextProperties();
};

/**
Expand Down Expand Up @@ -147,6 +148,7 @@ define(function (require) {
s === constants.ITALIC ||
s === constants.BOLD) {
this._setProperty('_textStyle', s);
this._applyTextProperties();
}
};

Expand All @@ -171,6 +173,15 @@ define(function (require) {
return this.drawingContext.measureText(s).width;
};

/**
* Helper fxn to apply text properties.
*
*/
p5.prototype._applyTextProperties = function () {
var str = this._textStyle + ' ' + this._textSize + 'px ' + this._textFont;
this.drawingContext.font = str;
};

return p5;

});
3 changes: 1 addition & 2 deletions src/typography/loading_displaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ define(function (require) {
* </div>
*/
p5.prototype.text = function () {
var str = this._textStyle + ' ' + this._textSize + 'px ' + this._textFont;
this.drawingContext.font = str;
if (arguments.length === 3) {
if (this._doFill) {
this.drawingContext.fillText(arguments[0], arguments[1], arguments[2]);
Expand Down Expand Up @@ -119,6 +117,7 @@ define(function (require) {
*/
p5.prototype.textFont = function(str) {
this._setProperty('_textFont', str); //pend temp?
this._applyTextProperties();
};

return p5;
Expand Down