Skip to content
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

Fix usage of default fonts #6861

Merged
merged 1 commit into from
Mar 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,13 @@ class Renderer2D extends p5.Renderer {
this._setProperty('_textStyle', this._textFont.font.styleName);
}

let fontNameString = font || 'sans-serif';
if (/\s/.exec(fontNameString)) {
// If the name includes spaces, surround in quotes
fontNameString = `"${fontNameString}"`;
}
this.drawingContext.font = `${this._textStyle || 'normal'} ${this._textSize ||
12}px "${font || 'sans-serif'}"`;
12}px ${fontNameString}`;

this.drawingContext.textAlign = this._textAlign;
if (this._textBaseline === constants.CENTER) {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ var spec = {
'visual/cases': [
// Add the visual tests that you want run as part of CI here. Feel free
// to omit some for speed if they should only be run manually.
'webgl'
'webgl',
'typography'
]
};
document.write(
Expand Down
20 changes: 20 additions & 0 deletions test/unit/visual/cases/typography.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
visualSuite('Typography', function() {
visualSuite('textFont() with default fonts', function() {
visualTest('With the default font', function (p5, screenshot) {
p5.createCanvas(50, 50);
p5.textSize(20);
p5.textAlign(p5.LEFT, p5.TOP);
p5.text('test', 0, 0);
screenshot();
});

visualTest('With the default monospace font', function (p5, screenshot) {
p5.createCanvas(50, 50);
p5.textSize(20);
p5.textFont('monospace');
p5.textAlign(p5.LEFT, p5.TOP);
p5.text('test', 0, 0);
screenshot();
});
});
}, { focus: true });
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
2 changes: 1 addition & 1 deletion test/visual/visualTestList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// List all visual test files here that should be manually run
const visualTestList = ['webgl'];
const visualTestList = ['webgl', 'typography'];

for (const file of visualTestList) {
document.write(
Expand Down