Skip to content

Commit e98a609

Browse files
committed
fix two minor bugs: font-name discovery, textProps circular ref
1 parent 77e89ee commit e98a609

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/type/p5.Font.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ function font(p5, fn) {
572572
// load the raw font bytes
573573
let result = await fn.loadBytes(path);
574574
//console.log('result:', result);
575-
575+
576576
if (!result) {
577577
throw Error('Failed to load font data');
578578
}
@@ -597,11 +597,13 @@ function font(p5, fn) {
597597

598598
} catch (err) {
599599
// failed to parse the font, load it as a simple FontFace
600-
let ident = name || path.substring(path.lastIndexOf('/') + 1);
600+
let ident = name || path
601+
.substring(path.lastIndexOf('/') + 1)
602+
.replace(/\.[^/.]+$/, "");
601603
console.warn(`WARN: No glyph data for '${ident}', retrying as FontFace`);
602604
try {
603605
// create a FontFace object and pass it to p5.Font
604-
pfont = await create(this, name, path, descriptors);
606+
pfont = await create(this, ident, path, descriptors);
605607
}
606608
catch (err) {
607609
if (error) error(err);

src/type/text2d.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ function text2d(p5, fn) {
103103
textLeading: { default: 15 },
104104
textSize: { default: 12 },
105105
textWrap: { default: fn.WORD },
106-
107-
// added v2.0
108106
fontStretch: { default: fn.NORMAL, isShorthand: true }, // font-stretch: { default: normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded }
109107
fontWeight: { default: fn.NORMAL, isShorthand: true }, // font-stretch: { default: normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded }
110108
lineHeight: { default: fn.NORMAL, isShorthand: true }, // line-height: { default: normal | number | length | percentage }
@@ -456,17 +454,28 @@ function text2d(p5, fn) {
456454
return this._pInst;
457455
}
458456

459-
// getter: get props from this.textDrawingContext()
457+
// getter: get props from drawingContext
458+
let context = this.textDrawingContext();
460459
properties = ContextTextProps.reduce((props, p) => {
461-
props[p] = this.textDrawingContext()[p];
460+
props[p] = context[p];
462461
return props;
463462
}, {});
464463

465-
// add renderer.states props
464+
// add renderer props
466465
Object.keys(RendererTextProps).forEach(p => {
467-
properties[p] = this.states[p];
468466
if (RendererTextProps[p]?.type === 'Context2d') {
469-
properties[p] = this.textDrawingContext()[p];
467+
properties[p] = context[p];
468+
}
469+
else { // a renderer.states property
470+
if (p === 'textFont') {
471+
// avoid circular ref. inside textFont
472+
properties[p] = Object.assign({}, this._currentTextFont());
473+
delete properties[p]._pInst;
474+
console.log('textFont: ', properties[p]);
475+
}
476+
else {
477+
properties[p] = this.states[p];
478+
}
470479
}
471480
});
472481

0 commit comments

Comments
 (0)