Skip to content

Commit f8ed1fe

Browse files
committed
Fix line breaking
1 parent 84b937a commit f8ed1fe

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/core/p5.Renderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Renderer {
3434
rectMode: constants.CORNER,
3535
ellipseMode: constants.CENTER,
3636

37-
textFont: 'sans-serif',
37+
textFont: { family: 'sans-serif' },
3838
textLeading: 15,
3939
leadingSet: false,
4040
textSize: 12,
@@ -485,7 +485,7 @@ class Renderer {
485485
/**
486486
* Helper function to check font type (system or otf)
487487
*/
488-
_isOpenType(f = this.states.textFont) {
488+
_isOpenType({ font: f } = this.states.textFont) {
489489
return typeof f === 'object' && f.data;
490490
}
491491

src/core/p5.Renderer2D.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ class Renderer2D extends Renderer {
14051405
return p;
14061406
}
14071407

1408-
_applyTextProperties() {
1408+
/*_applyTextProperties() {
14091409
let font;
14101410
const p = this._pInst;
14111411
@@ -1435,7 +1435,7 @@ class Renderer2D extends Renderer {
14351435
}
14361436
14371437
return p;
1438-
}
1438+
}*/
14391439

14401440
//////////////////////////////////////////////
14411441
// STRUCTURE

src/type/text2d.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function text2d(p5, fn) {
103103
const RendererTextProps = {
104104
textAlign: { default: fn.LEFT, type: 'Context2d' },
105105
textBaseline: { default: fn.BASELINE, type: 'Context2d' },
106-
textFont: { default: 'sans-serif' },
106+
textFont: { default: { family: 'sans-serif' } },
107107
textLeading: { default: 15 },
108108
textSize: { default: 12 },
109109
textWrap: { default: fn.WORD },
@@ -301,7 +301,7 @@ function text2d(p5, fn) {
301301
}
302302

303303
// update font properties in this.states
304-
this.states.textFont = this.textFontState(font, family, size);
304+
this.states.textFont = { font, family, size };
305305

306306
// convert/update the size in this.states
307307
if (typeof size !== 'undefined') {
@@ -703,7 +703,7 @@ function text2d(p5, fn) {
703703
@param {string} size - the font-size string to compute
704704
@returns {number} - the computed font-size in pixels
705705
*/
706-
Renderer.prototype._fontSizePx = function (theSize, family = this.states.textFont) {
706+
Renderer.prototype._fontSizePx = function (theSize, { family } = this.states.textFont) {
707707

708708
const isNumString = (num) => !isNaN(num) && num.trim() !== '';
709709

@@ -1088,7 +1088,7 @@ function text2d(p5, fn) {
10881088
- font-family must be the last value specified.
10891089
*/
10901090
let { textFont, textSize, lineHeight, fontStyle, fontWeight, fontVariant } = this.states;
1091-
let family = this._parseFontFamily(textFont);
1091+
let family = this._parseFontFamily(textFont.family);
10921092
let style = fontStyle !== fn.NORMAL ? `${fontStyle} ` : '';
10931093
let weight = fontWeight !== fn.NORMAL ? `${fontWeight} ` : '';
10941094
let variant = fontVariant !== fn.NORMAL ? `${fontVariant} ` : '';
@@ -1152,9 +1152,6 @@ function text2d(p5, fn) {
11521152
p5.Renderer2D.prototype.textDrawingContext = function() {
11531153
return this.drawingContext;
11541154
};
1155-
p5.Renderer2D.prototype.textFontState = function(font, family, size) {
1156-
return family;
1157-
};
11581155
p5.Renderer2D.prototype._renderText = function (text, x, y, maxY, minY) {
11591156
let states = this.states;
11601157

@@ -1193,14 +1190,6 @@ function text2d(p5, fn) {
11931190
}
11941191
return this._textDrawingContext;
11951192
};
1196-
p5.RendererGL.prototype.textFontState = function(font, family, size) {
1197-
if (typeof font === 'string' || font instanceof String) {
1198-
throw new Error(
1199-
'In WebGL mode, textFont() needs to be given the result of loadFont() instead of a font family name.'
1200-
);
1201-
}
1202-
return font;
1203-
};
12041193
}
12051194
}
12061195

src/webgl/text.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { Geometry } from './p5.Geometry';
77
function text(p5, fn){
88
// Text/Typography
99
// @TODO:
10-
RendererGL.prototype._applyTextProperties = function() {
10+
//RendererGL.prototype._applyTextProperties = function() {
1111
//@TODO finish implementation
1212
//console.error('text commands not yet implemented in webgl');
13-
};
13+
//};
1414

1515
RendererGL.prototype.textWidth = function(s) {
1616
if (this._isOpenType()) {
17-
return this.states.textFont._textWidth(s, this.states.textSize);
17+
return this.states.textFont.font._textWidth(s, this.states.textSize);
1818
}
1919

2020
return 0; // TODO: error
@@ -700,7 +700,12 @@ function text(p5, fn){
700700
this.states.drawMode = constants.TEXTURE;
701701

702702
// get the cached FontInfo object
703-
const font = this.states.textFont;
703+
const { font } = this.states.textFont;
704+
if (!font) {
705+
throw new Error(
706+
'In WebGL mode, textFont() needs to be given the result of loadFont() instead of a font family name.'
707+
);
708+
}
704709
let fontInfo = this.states.textFont._fontInfo;
705710
if (!fontInfo) {
706711
fontInfo = this.states.textFont._fontInfo = new FontInfo(font);

0 commit comments

Comments
 (0)