Skip to content

Instantly share code, notes, and snippets.

@aloyr
Created January 31, 2020 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloyr/149034dc2e1b4b6c10ac1f453dc822be to your computer and use it in GitHub Desktop.
Save aloyr/149034dc2e1b4b6c10ac1f453dc822be to your computer and use it in GitHub Desktop.
use proper font family inside svgs
(function() {
document.querySelectorAll('svg tspan, svg text').forEach(e => {
var currentFont = e.getAttribute('font-family');
if (!currentFont) {
return;
}
currentFont = currentFont.replace(/'/g, '');
var modes = {
'Thin': 100,
'ExtraLight': 200,
'Light': 300,
'Normal': 400,
'Regular': 400,
'Medium': 500,
'SemiBold': 600,
'Bold': 700,
'ExtraBold': 800,
'Black': 900
}
var fontFamily = currentFont.split('-');
var last = fontFamily.pop();
if (Object.keys(modes).includes(last)) {
e.style.fontFamily = fontFamily.join('-');
e.style.fontWeight = modes[last];
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment