Skip to content

Commit bd70f58

Browse files
committed
Set FontFace weight ranges based on Typr info
1 parent c9cf088 commit bd70f58

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/type/p5.Font.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,18 @@ function createFontFace(name, path, descriptors, rawFont) {
971971
fontArg = path;
972972
}
973973

974+
if ((rawFont?.fvar?.length ?? 0) > 0) {
975+
descriptors = descriptors || {};
976+
for (const [tag, minVal, maxVal, defaultVal, flags, name] of rawFont.fvar[0]) {
977+
if (tag === 'wght') {
978+
descriptors.weight = `${minVal} ${maxVal}`;
979+
} else if (tag === 'wdth') {
980+
descriptors.stretch = `${minVal} ${maxVal}`;
981+
}
982+
// TODO add other descriptors
983+
}
984+
}
985+
974986
// create/return the FontFace object
975987
let face = new FontFace(name, fontArg, descriptors);
976988
if (face.status === 'error') {

0 commit comments

Comments
 (0)