Re: font size in pixels?




"mitch" <mgart@xxxxxxxxxx> wrote in message news:1151436278.483166.246430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Suppose you want to use a font that's 12 pixels (not 12 points)
Arial. How would you do it? It seems like the answer has
something to do with FontRenderContext and AffineTransform
but does anybody have code that creates a font with a size in
pixels, or measures the size in pixels of an existing font?
Thanks.


I usually make a whole bunch of FontMetrics and do a binary search. E.g. 12pt too small? What about 24pt? Too big? How about 18 pt? etc.

You can cache the results in a map, e.g.: 12px -> 14.2pt, 13px -> 14.4pt, etc.

- Oliver

.



Relevant Pages

  • font size in pixels?
    ... Suppose you want to use a font that's 12 pixels ... something to do with FontRenderContext and AffineTransform ...
    (comp.lang.java.gui)
  • Re: TextWidth() Alternative?
    ... It returns the width of the text in device logical units. ... course depends on which font is currently selected into the device. ... Printer Object always use device pixels as the device logical units, ... of the text in a RichTextBox then the "screen pixel width" of the text it ...
    (microsoft.public.vb.general.discussion)
  • Re: Advice for OCR solution (or alternative)
    ... My font is not fixed width. ... between each character (sometimes more than one pixels width). ... "Roedy Green" wrote in message ...
    (comp.lang.java.help)
  • Re: Rasterizer differences win98/XP
    ... More precisely, 2*n-1 sampling points, all ... vertically at the pixel's center, horizontally spaced by 1/n pixels, ... This is either a side-effect of your CRT monitor, ... I still suspect that your font was subjected to ...
    (comp.fonts)
  • Re: Speaking of fonts...
    ... understood the situation properly (those who design font rendering ... DPI means how many dots per inch, or pixels in that inch, will be used ... Changing your printer from 24 DPI to 48 DPI, for example, didn't change ...
    (Fedora)