Created
December 7, 2020 07:14
-
-
Save Echooff3/b43f233128ab2dff75c28a976fa9e714 to your computer and use it in GitHub Desktop.
Dynamic Font Loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.loadFont = async(base64) => { | |
const byteArray = Uint8Array.from(atob(base64), c => c.charCodeAt(0)); | |
// Add font face 'customFont' to an element. It will fallback until a font gets loaded | |
const font = new FontFace('customFont', byteArray); | |
// wait for font to be loaded | |
await font.load(); | |
// add font to document | |
document.fonts.add(font); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment