Skip to content

Commit 0b86e39

Browse files
author
lauren mccarthy
committed
fixing text(str, x, y, w, h) closes #339
1 parent dd8165d commit 0b86e39

File tree

3 files changed

+30
-60
lines changed

3 files changed

+30
-60
lines changed

lib/p5.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.3.4 August 27, 2014 */
1+
/*! p5.js v0.3.4 August 28, 2014 */
22
var shim = function (require) {
33
window.requestDraw = function () {
44
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
@@ -4457,7 +4457,8 @@ var typographyloading_displaying = function (require, core, canvas) {
44574457
var p5 = core;
44584458
var canvas = canvas;
44594459
p5.prototype.text = function () {
4460-
this.drawingContext.font = this._textStyle + ' ' + this._textSize + 'px ' + this._textFont;
4460+
var str = this._textStyle + ' ' + this._textSize + 'px ' + this._textFont;
4461+
this.drawingContext.font = str;
44614462
if (arguments.length === 3) {
44624463
if (this._doFill) {
44634464
this.drawingContext.fillText(arguments[0], arguments[1], arguments[2]);
@@ -4469,32 +4470,32 @@ var typographyloading_displaying = function (require, core, canvas) {
44694470
var words = arguments[0].split(' ');
44704471
var line = '';
44714472
var vals = canvas.modeAdjust(arguments[1], arguments[2], arguments[3], arguments[4], this._rectMode);
4472-
vals.y += this._textLeading;
4473+
var y = vals.y + this._textLeading;
44734474
for (var n = 0; n < words.length; n++) {
44744475
var testLine = line + words[n] + ' ';
44754476
var metrics = this.drawingContext.measureText(testLine);
44764477
var testWidth = metrics.width;
4477-
if (vals.y > vals.h) {
4478+
if (y > vals.y + vals.h) {
44784479
break;
44794480
} else if (testWidth > vals.w && n > 0) {
44804481
if (this._doFill) {
4481-
this.drawingContext.fillText(line, vals.x, vals.y);
4482+
this.drawingContext.fillText(line, vals.x, y);
44824483
}
44834484
if (this._doStroke) {
4484-
this.drawingContext.strokeText(line, vals.x, vals.y);
4485+
this.drawingContext.strokeText(line, vals.x, y);
44854486
}
44864487
line = words[n] + ' ';
4487-
vals.y += this._textLeading;
4488+
y += this._textLeading;
44884489
} else {
44894490
line = testLine;
44904491
}
44914492
}
4492-
if (vals.y <= vals.h) {
4493+
if (y <= vals.y + vals.h) {
44934494
if (this._doFill) {
4494-
this.drawingContext.fillText(line, vals.x, vals.y);
4495+
this.drawingContext.fillText(line, vals.x, y);
44954496
}
44964497
if (this._doStroke) {
4497-
this.drawingContext.strokeText(line, vals.x, vals.y);
4498+
this.drawingContext.strokeText(line, vals.x, y);
44984499
}
44994500
}
45004501
}

0 commit comments

Comments
 (0)