There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It very much depends on where, when and how (and why?) you are trying to determine this information. For example. If you are trying to do this within a windows application, that will be writing to the local screen using a pre-selected font, there are a whole raft of entrypoints for dealing with fonts, querying the metrics, and determining the bounds. Which calls you would need to use is very much dependant upon upon what you are trying to achieve. Other graphical APIs, Tk, Gtk, X etc. will all (probably) have equivalent sets of APIs for doing this. However, if you are working on a CGI/HTML application and are hoping to work out how many pixels of screen real estate any given string will occupy, forget it it and give up now:) Whatever you do at the server end to try and determine this is doomed to fail. Even if you specify the exact font and size, each browser may choose to render that font and size with more or less inter-character and inter-word spacing, larger or smaller margins and use (or not) kerning, all of which will completely derail your server-side calculations. If the fontsize you specify is not available, then the browser may choose to synthesize it from a size that is available, but it is unlikely (if not impossible) that it will reach a similar set of metrics to those you have used in your calculations. If the font you specify is not available, it will substitute a "similar font", and again you are screwed. Finally, most if not all browsers allow the user to override the fonts specified by the author and substitute larger, smaller or completely different fonts. I use this facility all the time, opting for small fonts that pack as much text onto my screen as possible. Partially sighted people will tend to opt for larger fonts. If this is your target, then not only is it impossible to do, you should probably be asking yourself why you want to do it. In reply to Re: Font size by pixels.
by BrowserUk
|
|