Skip to content

Instantly share code, notes, and snippets.

View msageryd's full-sized avatar

Michael Sageryd msageryd

  • Sweden
View GitHub Profile
@msageryd
msageryd / textWidth.js
Created November 16, 2022 07:38 — forked from gka/textWidth.js
Approximate text width based on estimated character widths...
var textWidth = (function() {
function charW(w, c) {
if (c == 'W' || c == 'M') w += 15;
else if (c == 'w' || c == 'm') w += 12;
else if (c == 'I' || c == 'i' || c == 'l' || c == 't' || c == 'f') w += 4;
else if (c == 'r') w += 8;
else if (c == c.toUpperCase()) w += 12;
else w += 10;
return w;
}