Skip to content

Commit db236e6

Browse files
authored
Merge pull request #7727 from processing/fix/variable-font-firefox
Set FontFace weight ranges based on Typr info
2 parents c9cf088 + e02bd37 commit db236e6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: src/type/p5.Font.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,14 @@ export class Font {
684684
let axs;
685685
if ((this.data?.fvar?.length ?? 0) > 0) {
686686
const fontAxes = this.data.fvar[0];
687-
axs = fontAxes.map(([tag, minVal, maxVal, defaultVal, flags, name]) => {
687+
axs = fontAxes.map(([tag, minVal, defaultVal, maxVal, flags, name]) => {
688688
if (!renderer) return defaultVal;
689689
if (tag === 'wght') {
690690
return renderer.states.fontWeight;
691691
} else if (tag === 'wdth') {
692692
// TODO: map from keywords (normal, ultra-condensed, etc) to values
693693
// return renderer.states.fontStretch
694-
return defaultVal;
694+
return 100;
695695
} else if (renderer.textCanvas().style.fontVariationSettings) {
696696
const match = new RegExp(`\\b${tag}\s+(\d+)`)
697697
.exec(renderer.textCanvas().style.fontVariationSettings);
@@ -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, defaultVal, maxVal, 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') {

Diff for: test/unit/visual/cases/typography.js

-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ visualSuite("Typography", function () {
113113
p5.createCanvas(100, 100);
114114
const font = await p5.loadFont(
115115
'/unit/assets/BricolageGrotesque-Variable.ttf',
116-
{ weight: '200 800' }
117116
);
118117
for (let weight = 400; weight <= 800; weight += 100) {
119118
p5.background(255);
@@ -130,7 +129,6 @@ visualSuite("Typography", function () {
130129
p5.createCanvas(100, 100, p5.WEBGL);
131130
const font = await p5.loadFont(
132131
'/unit/assets/BricolageGrotesque-Variable.ttf',
133-
{ weight: '200 800' }
134132
);
135133
for (let weight = 400; weight <= 800; weight += 100) {
136134
p5.push();

0 commit comments

Comments
 (0)