![]() |
Javadoc Font Size ErrorTo be able to create Aspect Ratio v Pixel Size graphs from Java, as here, I need to enumerate fonts and select font sizes. I found a simple Java applet that created a font here: java2s.com. The code has the 'Font Constructor' (I'm using 'Verdana' instead of 'Serif')
Font font = new Font("Verdana", Font.PLAIN, 96);
And the Java Documentation Font Constructor has this description: public Font(String name, int style, int size) Note that the font size is specified to be in points so, as much of the web gets inches, points, and pixels wrong, I ran a check on actual character size. The applet, according to Javadoc, produces the string "Jade" at "96" pt but let's use Notepad to set the same string in the same font but at 72 pt, the largest size we can get in Notepad.
String in Applet at "96" pt
String in Notepad at 72 pt
The character height at 72 pt in Notepad is greater than that in Java at the supposed 96 pt! To check I set the string at 72pt Verdana in "UltraEdit". The result is the same as Notepad. The 'J' character is 77 px high, not 71 px. I suspect that Java doesn't know its points from its pixels. We need to see how many pixels tall is a 'J' in Verdana at a font size of 96 pixels, but using a text editor to display text at a specific pixel font size isn't practicable because text editors only allow one to set point font sizes from a range of preset values. A browser is a better option than a text editor.
String in Applet at "96" pt
String in Firefox at 96 px
We can see that the character height at the Java alleged 96 pt is actually the height at 96 px. What the Java documentation says are point sizes are actually pixel sizes. Let's do an 'online' check. This tutorial site Using Fonts with Applets has an image of the text "Hello World" in "Arial",Font.BOLD,30" and says "The font will be 30 points tall...". In Notepad the nearest font size in points to 30 is 28 so open Notepad and enter "Hello World" with the font set to Arial, Bold, 28 pt. Compare the size of the Notepad text with that on the web site and you will see that the Notepad text is larger even though it's set to 28 pt, a smaller font size then the alleged '30 pt' java text. Java font sizes are in pixels, not points. Looking around the web to see if there was anything out there about this I saw this page Of Fonts and Java2D. The author says that "Java2D mis-renders many glyphs" and has the example where Java2D Times 16 points renders the same as Windows 12 points, but Java 16 pt is really 16 px so let's convert the 16 px to points using a rearranged Equation 3
font size in pixels
font size in points = ------------------- × 72 points per inch
screen dpi
Assuming that the author's screen dpi is 96, the default, we see that:
16
font size in points = ------- × 72 = 12 pt
96
The authors mis-rendering examples arise from the Javadoc error of thinking pixels are points. |
| © 2006 - 2010 Richard Mason |