Make system fonts work more reliably (#8602)
* Make system fonts work more reliably * Make it more sophisticated * Missing semicolon * Apply suggestions * Fix formatting Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> * Create FontWatcher-test.tsx * Add actual tests * Fix some errors * Apply suggestions * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Fix FontWatcher tests * Correct test fixture Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
b4d657b21f
commit
5b51efd861
4 changed files with 86 additions and 16 deletions
|
@ -64,6 +64,20 @@ export class FontWatcher implements IWatcher {
|
|||
};
|
||||
|
||||
private setSystemFont = ({ useSystemFont, font }) => {
|
||||
document.body.style.fontFamily = useSystemFont ? font : "";
|
||||
if (useSystemFont) {
|
||||
// Make sure that fonts with spaces in their names get interpreted properly
|
||||
document.body.style.fontFamily = font
|
||||
.split(',')
|
||||
.map(font => {
|
||||
font = font.trim();
|
||||
if (!font.startsWith('"') && !font.endsWith('"')) {
|
||||
font = `"${font}"`;
|
||||
}
|
||||
return font;
|
||||
})
|
||||
.join(',');
|
||||
} else {
|
||||
document.body.style.fontFamily = "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue