Created
June 9, 2021 02:34
-
-
Save aminnj/5ca372aa2def72fb017b531c894afdca to your computer and use it in GitHub Desktop.
arial character widths
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
var d1 = document.createElement("div"); | |
d1.id = "test3"; | |
d1.innerHTML = "test"; | |
d1.style = "width: fit-content; padding: 0px; margin: 0px; font-family: Arial, sans-serif;"; | |
document.documentElement.appendChild(d1); | |
var d2 = document.createElement("div"); | |
d2.id = "test3"; | |
document.documentElement.appendChild(d2); | |
d2.innerHTML = ""; | |
var N = 100; | |
for (var i = 32; i < 127; i++) { | |
var s = String.fromCharCode(i).replace(" "," "); | |
d1.innerHTML = s.repeat(N); | |
var width = d1.getBoundingClientRect().width; | |
d2.innerHTML += `"${s}": ${width/N},<br>`; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, thanks!