Skip to content

Commit

Permalink
refix to font name extraction, regenerate one screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Dec 29, 2024
1 parent 9ba2d64 commit 8aadc26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/type/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ function font(p5, fn) {
* @param {...any} args - path, name, onSuccess, onError, descriptors
* @returns a Promise that resolves with a p5.Font instance
*/

p5.prototype.loadFont = async function (...args/*path, name, onSuccess, onError, descriptors*/) {

let { path, name, success, error, descriptors } = parseCreateArgs(...args);
Expand Down Expand Up @@ -572,7 +573,7 @@ function font(p5, fn) {
// load the raw font bytes
let result = await fn.loadBytes(path);
//console.log('result:', result);

if (!result) {
throw Error('Failed to load font data');
}
Expand All @@ -597,11 +598,15 @@ function font(p5, fn) {

} catch (err) {
// failed to parse the font, load it as a simple FontFace
let ident = name || path.substring(path.lastIndexOf('/') + 1);
let ident = name || path
.substring(path.lastIndexOf('/') + 1)
.replace(/\.[^/.]+$/, "");

console.warn(`WARN: No glyph data for '${ident}', retrying as FontFace`);

try {
// create a FontFace object and pass it to p5.Font
pfont = await create(this, name, path, descriptors);
pfont = await create(this, ident, path, descriptors);
}
catch (err) {
if (error) error(err);
Expand Down
2 changes: 0 additions & 2 deletions test/unit/visual/cases/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ visualSuite("Typography", function () {
for (let weight = 400; weight <= 800; weight += 100) {
p5.background(255);
p5.textFont(font);
console.log(p5.textProperties());

p5.textAlign(p5.LEFT, p5.TOP);
p5.textSize(35);
p5.textWeight(weight);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8aadc26

Please sign in to comment.