Font WORA blues.

R

Roedy Green

Hendrik Maryns sent me a screen shot of one of my Applets running on
his machine. It looks godawful.

I write some JLabel text with Font( "Dialog", Font.BOLD, 16 );

It looks beautiful on my Vista machine, but on his, it looks terrible.
The Font renders 12% bigger so there is not enough room in the various
boxes.

Further, it looks moth-eaten, even more than I might expect from
anti-alias turned off.

I don't yet know what platform/Browser/Java version he is using. Any
thoughts on what could be happening?

<rant>
If you look at http://mindprod.com/applet/fontshowerawt.html you can
view all the fonts available to Java on your machine. Set it to say
15 points. Then look at the various fonts. They won't be ANYWHERE
NEAR the same size! ARGGH!! Spit, splutter. Surely Java should
auto-compensate so that that font families are interchangeable.
</rant>

However, in this case I am using Dialog, a logical font 100% under
Sun's control. Sun have no excuse for it rendering so differently on
different platforms!

Is there some sort of font magnification feature of some platforms
that could be fouling things up?

Any tips for me and the peanut gallery on how to write WORA font code
when you only have one machine?
 
T

Tom Anderson

Not Java's fault?
http://nwalsh.com/comp.fonts/FAQ/cf_8.htm#SEC16

I don't think Java should be changed to misrepresent font sizes.

I think you're right.

But it *is* still *bloody annoying*. And not just in java - in a word
processor or whatever too. You have text in some typeface, you change the
typeface, and it's a completely different size. Why? Because point size
has become meaningless because designers are precious special snowflakes
whose freedom to design creatively, and impose their own beliefs about how
much leading their precious special snowflake font neeeds on its user, is
more import than their users' need to have practical, usable fonts.
Maybe it could have some method of calculating a font size for a
specified font to make that font fit some arbitrary metric (e.g. desired
distance from top of tallest ascender to bottom of lowest descender)

That would be useful. I wrote code to do just that, back in the 1.1 days,
to deal with just the problem Roedy has - getting a font size that is
actually a particular pixel height. It's not too hard, you just write a
function int getFontHeight(Font base, float size, Graphics g) that uses
getFontMetrics etc to work out the font height in pixels, then do an
optimisation in a loop to work out the font size you need to specify to
get the pixel height you want.

tom
 
R

Roedy Green

I don't think Java should be changed to misrepresent font sizes. Maybe
it could have some method of calculating a font size for a specified
font to make that font fit some arbitrary metric (e.g. desired distance
from top of tallest ascender to bottom of lowest descender)

Your frame has a certain size. When a font is substituted, you want
it to take up the same amount of pixel space as the one you used to
design the app.

We need an Font constructor variant that redefines point size to be
max ascender - descender in pixels. e.g. put a boolean on the end to
request normalized sizes or create an ExactFont class. That would
even let you retrofit the feature into older JVMs.
 
R

Roedy Green

That would be useful. I wrote code to do just that, back in the 1.1 days,
to deal with just the problem Roedy has - getting a font size that is
actually a particular pixel height. It's not too hard, you just write a
function int getFontHeight(Font base, float size, Graphics g) that uses
getFontMetrics etc to work out the font height in pixels, then do an
optimisation in a loop to work out the font size you need to specify to
get the pixel height you want.

It is goofy to do that calculation in your app. The info is probably
already buried somewhere in the font file. All it needs is a way to
get at it, or possibly to precalculate and cache it as part of JVM
install.
 
R

RedGrittyBrick

Roedy said:
Your frame has a certain size. When a font is substituted, you want
it to take up the same amount of pixel space as the one you used to
design the app.

We need an Font constructor variant that redefines point size to be
max ascender - descender in pixels. e.g. put a boolean on the end to
request normalized sizes or create an ExactFont class. That would
even let you retrofit the feature into older JVMs.


How do you handle Internationalization? Maybe you can treat this problem
as a subset of the problem of producing a layout that will work with
widely varying string lengths for labels etc.

Just a thought.
 
R

Roedy Green

How do you handle Internationalization? Maybe you can treat this problem
as a subset of the problem of producing a layout that will work with
widely varying string lengths for labels etc.

I have ignored the problem. I provide source. Somebody wanting a
version in another language could tweak the code for himself.

I have posted a fairly detailed design for detailed proposed
international tool, but it does not deal with size problems.

See http://mindprod.com/project/internationaliser.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top