Skip to content

Commit 59e11a0

Browse files
committed
Load the non-picked font so it can still be accessed via CSS
1 parent 609e5d5 commit 59e11a0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/type/p5.Font.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ function font(p5, fn) {
10221022
name,
10231023
src,
10241024
fontDescriptors,
1025-
load: async () => {
1025+
loadWithData: async () => {
10261026
let fontData;
10271027
try {
10281028
const urlMatch = /url\(([^\)]+)\)/.exec(src);
@@ -1035,7 +1035,8 @@ function font(p5, fn) {
10351035
}
10361036
} catch (_e) {}
10371037
return create(this, name, src, fontDescriptors, fontData)
1038-
}
1038+
},
1039+
loadWithoutData: () => create(this, name, src, fontDescriptors)
10391040
});
10401041
}
10411042
}
@@ -1090,7 +1091,15 @@ function font(p5, fn) {
10901091
closestMatch = font;
10911092
}
10921093
}
1093-
return (closestMatch || possibleFonts.at(-1))?.load();
1094+
const picked = (closestMatch || possibleFonts.at(-1));
1095+
for (const font of possibleFonts) {
1096+
if (font !== picked) {
1097+
// Load without parsing data with Typr so that it still can be accessed
1098+
// via regular CSS by name
1099+
font.loadWithoutData();
1100+
}
1101+
}
1102+
return picked?.loadWithData();
10941103
}
10951104

10961105
let pfont;

0 commit comments

Comments
 (0)