Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/typography/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ p5.prototype.textLeading = function(theLeading) {
*/
p5.prototype.textSize = function(theSize) {
p5._validateParameters('textSize', arguments);

// New FES Warning Logic
if (arguments.length > 0 && theSize <= 0) {
p5._friendlyError(
`textSize() was called with a value of ${theSize}. ` +
'Text size must be a positive number greater than 0 to render correctly and prevent text overlapping when wrapping.'
);
}
return this._renderer.textSize(...arguments);
};

Expand Down
10 changes: 10 additions & 0 deletions test/unit/typography/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ suite('Typography Attributes', function() {
myp5.textSize('30');
});
});
// NEW TEST ADDED
test('should trigger FES warning if textSize is 0 or negative', function() {
p5.disableFriendlyErrors = false;
expect(function() {
myp5.textSize(0);
}).to.generateFriendlyError();
expect(function() {
myp5.textSize(-5);
}).to.generateFriendlyError();
});
});

suite('p5.prototype.textStyle', function() {
Expand Down