Is there a way to figure out how many pixels a string of characters takes up from it's font size?
Ie. what is the pixel width of "this string" in Arial 8pt?
"I'm exploring some ways to get text to fit within a certain pixel width of an html table cell."
That's not how the web works. The best you can do is suggest a typeface at a certain size, but you need to accomodate the fact that anyone can change the typeface and size as they personally see fit.
If you're OK having text just 'disapear' then wrap the text in a fixed-sized div with overflow set to hidden.
Thanks for the replies.
I'm exploring some ways to get text to fit within a certain pixel width of an html table cell. Ideally I'd like truncate the text with an ellipses after a certain number of characters, so it wouldn't have to be 100% accurate... but I'd be okay with an html/css solution (which I'm also not having much luck with) that just makes the text go bye bye after x pixels.
Anyway, thanks again.
To get the width of a string set in a given font, you need:
- font size
- the font itself (advance widths at least)
- to know if kerning is on, and if so, account for it as well
- if it's TrueType (as Arial is), and you're looking at the hinted widths, you need to actually run the glyphs as programs to see whether the widths change
This assumes the text isn't justified and has nothing else to mess up its spacing....
Regards,
T
Captured from web.archive.org on 13 Oct 2013. view this capture