Skip to content

Commit a34dbfc

Browse files
authored
fix: font face descriptors in chrome 38 (#490)
In chrome 38 if some attribute is undefined the font is not loaded
2 parents 890bb80 + e23e750 commit a34dbfc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/core/text-rendering/font-face-types/WebTrFontFace.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class WebTrFontFace extends TrFontFace {
4949
const determinedDescriptors = this.descriptors;
5050

5151
// Convert TrFontFaceDescriptors to CSS FontFaceDescriptors
52-
const cssDescriptors: FontFaceDescriptors = {
52+
let cssDescriptors: FontFaceDescriptors = {
5353
style: determinedDescriptors.style,
5454
weight:
5555
typeof determinedDescriptors.weight === 'number'
@@ -61,6 +61,13 @@ export class WebTrFontFace extends TrFontFace {
6161
display: determinedDescriptors.display,
6262
};
6363

64+
for (const k in cssDescriptors) {
65+
const key = k as keyof FontFaceDescriptors;
66+
if (cssDescriptors[key] === undefined) {
67+
delete cssDescriptors[key];
68+
}
69+
}
70+
6471
const fontFace = new FontFace(
6572
fontFamily,
6673
`url(${fontUrlWithoutParentheses})`,
@@ -71,14 +78,12 @@ export class WebTrFontFace extends TrFontFace {
7178
fontFace
7279
.load()
7380
.then(() => {
74-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
7581
(this.loaded as boolean) = true;
7682
this.emit('loaded');
7783
})
7884
.catch(console.error);
7985
} else {
8086
// Default font
81-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
8287
(this.loaded as boolean) = true;
8388
this.emit('loaded');
8489
}

0 commit comments

Comments
 (0)