I'm making a command line version of shields.io for fun, so no browser/v8 engine. I have most of the program nailed down but given a string I cannot determine how long, in pixels, it will end up on the screen, and thus adjust my background. My current solution is just to get sum of the width of every character in my string (precalculated from a js script I ran in a browser). But when you add special characters and the fact that different letter combinations have different spacing in between I usually end up with shields that are either too big or too small.
So I'm looking for the algorithm that, given a font family, returns the width of the string.