Created
January 31, 2020 23:16
-
-
Save aloyr/149034dc2e1b4b6c10ac1f453dc822be to your computer and use it in GitHub Desktop.
use proper font family inside svgs
This file contains 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
(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