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:
r00ster 2022-05-23 18:29:16 +02:00 committed by GitHub
parent b4d657b21f
commit 5b51efd861
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 16 deletions

View file

@ -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 = "";
}
};
}