Re: [JAVA2D] AttributedString and Outline (the return of the glyph invaders!)

2006-11-17 Thread Michele Puccini

Phil,

so, correct me if I'm wrong, the TextLayout.draw() rasterizes every single
glyph (and its TextAttributes) to separate images before drawing them to the
Graphics ?

I can understand the complexity behind glyphs, fonts, graphics and text, but
.. is there a specific reason why we need to align to the pixel grid ? Maybe
we would get the same features of the Texlayout by rasterizing outlines and
effects straight to the Graphics and getting sub-pixel precision. Maybe not.
Now it's your turn ;)

Cheers,

Mik


ClassX Development Italy  Via Francesca, 368/I I-56030 S.M. a Monte (PI) 
Tel.(+39)-0587-705153  Fax.(+39)-0587-705153  WEB: http://www.classx.it  





- Original Message -
From: Phil Race [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, November 16, 2006 10:36 PM
Subject: Re: [JAVA2D] AttributedString and Outline (the return of the glyph
invaders!)



First, its not a bug in TextLayout drawString behaves identically.
You can prove this as follows, instead of your AttributedString use

Font fo = new Font(Serif, Font.PLAIN, 12);
fo = fo.deriveFont(AffineTransform.getScaleInstance(2 +
scale, 3));
g.setColor(Color.white);
g.setFont(fo);
g2d.drawString(text, x, y);

Second, text does not scale linearly because of the same hinting
and gridfitting effects I described earlier, and the glyphs are
fitted to the pixel grid and you are specifying fractional point sizes.

FRACTIONAL_METRICS is being specified but that affects only the
accumulation of the advance. It doesn't change the images.
You'd probably see a similar effect with the outline if you
disabled FRACTIONAL_METRICS.


-phil.



Michele Puccini wrote:

Thanks Phil,

I did a little mistake: is not a problem of the outline, which is indeed
correct.
Well, a piece of code is worth a thousand words.

The attached sample shows the animated difference between
TextLayout.draw() and g2d.draw(TextLayout.getOutline). Please give it a
try and see what happens. Is is quite funny to see the glyphs in the
first line jumping one pixel to the other just like the space invaders
in that old arcade game ;)

As you will see from the animation, the glyphs rendered with
TextLayout.draw() jump from one pixel to the other (at int coords ?),
while the glyph outlines are rendered with the expected quality.
Funny enough, the red cursor on the C letter is rendered at float
coords.

So, in my opinion, TextLayout.draw() does not give the expected quality
resuls and this is a pity as it really is very useful.

Cheers,

Mik



ClassX Development Italy  Via Francesca, 368/I I-56030 S.M. a Monte
(PI) 
Tel.(+39)-0587-705153  Fax.(+39)-0587-705153  WEB:
http://www.classx.it  




===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] AttributedString and Outline (the return of the glyph invaders!)

2006-11-17 Thread Phil Race

Michele Puccini wrote:

Phil,

so, correct me if I'm wrong, the TextLayout.draw() rasterizes every
single
glyph (and its TextAttributes) to separate images before drawing them
to the
Graphics ?


Yes. That's the way almost all font rendering systems work. The separate
images
are a 'glyph cache'


I can understand the complexity behind glyphs, fonts, graphics and
text, but
.. is there a specific reason why we need to align to the pixel grid ?
Maybe
we would get the same features of the Texlayout by rasterizing
outlines and
effects straight to the Graphics and getting sub-pixel precision.
Maybe not.
Now it's your turn ;)


There is no guarantee that scan conversion by the graphics rasterisation
process
would produce the same results. A simple example is that many TrueType
fonts - especially east asian ones - contain embedded bitmaps. Use outlines
and it will be illegible,
Also this way would be much slower. Go ahead and time drawString()
vs getOutline.fill() .for more than a couple of iterations.

So in summary the difference is expected and understandable.

-phil.

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] AttributedString and Outline (the return of the glyph invaders!)

2006-11-17 Thread David Eisner
Michele Puccini wrote:
 I can understand the complexity behind glyphs, fonts, graphics and
 text, but
 .. is there a specific reason why we need to align to the pixel grid ?
 Maybe
 we would get the same features of the Texlayout by rasterizing
 outlines and
 effects straight to the Graphics and getting sub-pixel precision.
 Maybe not.

I'm no expert, but these links might be helpful in explaining why grid
fitting is (sometimes) necessary:

http://freetype.sourceforge.net/autohinting/background.html

This is longer, but has figures:

http://developer.apple.com/textfonts/TTRefMan/RM02/Chap2.html

-David

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.