Skip to content

Instantly share code, notes, and snippets.

@Echooff3
Created December 7, 2020 07:14
Show Gist options
  • Save Echooff3/b43f233128ab2dff75c28a976fa9e714 to your computer and use it in GitHub Desktop.
Save Echooff3/b43f233128ab2dff75c28a976fa9e714 to your computer and use it in GitHub Desktop.
Dynamic Font Loading
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