Skip to main content

AttributedString and Outline

14 replies [Last post]
Anonymous

Hello,

I'm using TextLayouts made by AttributedStrings and I need to outline
(Stroke) the characters. Sadly I didn't find any Outline TextAttribute, so I
would like to know how to implement it.

More generally it would be nice to implement virtually any kind of
TextAttribute i.e. Emboss, Shadow, etc.

Suggestions ?

Mik
--

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Phil Race

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 <
> ============================================================================
>
>
>
> ----- Original Message ----- From: "Phil Race"
> To:
> Sent: Thursday, November 16, 2006 1:08 AM
> Subject: Re: [JAVA2D] AttributedString and Outline
>
>
>> The bitmap glyph images are hinted and gridfitted.
>> This is not done for the returned outline as it
>> doesn't make sense to do that for a pure shape.
>>
>> For most of what you are doing you need outlines
>> anyway as the rasteriser can only return glyph
>> images.
>>
>> -phil.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

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"
To:
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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

Thanks Phil,

I got the picture. It would be nice to have an option to avoid gridfitting
and drawing to the graphics using shapes instead of images. This would be
helpful in the case I underlined in the AttributedStringTest.java

Many thanks to David for his links. They've been really helpful.

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"
To: "Michele Puccini"
Cc:
Sent: Friday, November 17, 2006 3:54 PM
Subject: Re: [JAVA2D] AttributedString and Outline (the return of the glyph
invaders!)

> 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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Phil Race

Vincent Hardy's book Java 2D API Graphics comes with
a GLF toolkit which supports many effects. There are
examples of embossed text and other effects.
I believe the toolkit is available for download.
Use your favourite search engine.

You can also take a look at the java 2D demo.
This does use outlines. Sounds like that isn't
exactly what you want but take a look anyway

Also note that you can set FOREGROUND and BACKGROUND
text attributes which can be a Paint, not just a Color.

-phil.

Michele Puccini wrote:
> Hello,
>
> I'm using TextLayouts made by AttributedStrings and I need to outline
> (Stroke) the characters. Sadly I didn't find any Outline TextAttribute,
> so I
> would like to know how to implement it.
>
> More generally it would be nice to implement virtually any kind of
> TextAttribute i.e. Emboss, Shadow, etc.
>
> Suggestions ?
>
> Mik
> --
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Chris Campbell

Hi Mik,

You might also be able to glean some ideas from the SwingLabs team's
recent work on Painters. The basic approach is to paint text as an
outline (and shapes, images, etc) and then perform various effects on
each layer, for example:
http://weblogs.java.net/blog/joshy/archive/2006/09/introducing_pai_1.html

Chris

Phil Race wrote:
> Vincent Hardy's book Java 2D API Graphics comes with
> a GLF toolkit which supports many effects. There are
> examples of embossed text and other effects.
> I believe the toolkit is available for download.
> Use your favourite search engine.
>
> You can also take a look at the java 2D demo.
> This does use outlines. Sounds like that isn't
> exactly what you want but take a look anyway
>
> Also note that you can set FOREGROUND and BACKGROUND
> text attributes which can be a Paint, not just a Color.
>
> -phil.
>
> Michele Puccini wrote:
>
>> Hello,
>>
>> I'm using TextLayouts made by AttributedStrings and I need to outline
>> (Stroke) the characters. Sadly I didn't find any Outline TextAttribute,
>> so I
>> would like to know how to implement it.
>>
>> More generally it would be nice to implement virtually any kind of
>> TextAttribute i.e. Emboss, Shadow, etc.
>>
>> Suggestions ?
>>
>> Mik
>> --
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

Thanks Chris, but again I would like to put the stress on the fact that:

TextLayout.draw(..);

gives very different results from

g2d.draw(TextLayout.getOutline(..));

While the first one works very well, the second one gives different visual
results and the character shapes are badly spaced. It looks like they're
aligned to int coords. Please run the OutlineTest.java for a quick look.

That's the main reason why I can't overlay TextLayout.draw(..) over a
TextLayout.getOutline() without getting "spurious pixels" around the
characters.

Can you investigate ?

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: "Chris Campbell"
To:
Sent: Monday, November 13, 2006 4:52 PM
Subject: Re: [JAVA2D] AttributedString and Outline

> Hi Mik,
>
> You might also be able to glean some ideas from the SwingLabs team's
> recent work on Painters. The basic approach is to paint text as an
> outline (and shapes, images, etc) and then perform various effects on
> each layer, for example:
> http://weblogs.java.net/blog/joshy/archive/2006/09/introducing_pai_1.html
>
> Chris
>
>
> Phil Race wrote:
>> Vincent Hardy's book Java 2D API Graphics comes with
>> a GLF toolkit which supports many effects. There are
>> examples of embossed text and other effects.
>> I believe the toolkit is available for download.
>> Use your favourite search engine.
>>
>> You can also take a look at the java 2D demo.
>> This does use outlines. Sounds like that isn't
>> exactly what you want but take a look anyway
>>
>> Also note that you can set FOREGROUND and BACKGROUND
>> text attributes which can be a Paint, not just a Color.
>>
>> -phil.
>>
>> Michele Puccini wrote:
>>
>>> Hello,
>>>
>>> I'm using TextLayouts made by AttributedStrings and I need to outline
>>> (Stroke) the characters. Sadly I didn't find any Outline TextAttribute,
>>> so I
>>> would like to know how to implement it.
>>>
>>> More generally it would be nice to implement virtually any kind of
>>> TextAttribute i.e. Emboss, Shadow, etc.
>>>
>>> Suggestions ?
>>>
>>> Mik
>>> --
>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff JAVA2D-INTEREST". For general help, send
>>> email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>> ===========================================================================
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send email
>> to
>> listserv@java.sun.com and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Phil Race

The bitmap glyph images are hinted and gridfitted.
This is not done for the returned outline as it
doesn't make sense to do that for a pure shape.

For most of what you are doing you need outlines
anyway as the rasteriser can only return glyph
images.

-phil.

Michele Puccini wrote:
> Thanks Chris, but again I would like to put the stress on the fact that:
>
> TextLayout.draw(..);
>
> gives very different results from
>
> g2d.draw(TextLayout.getOutline(..));
>
> While the first one works very well, the second one gives different visual
> results and the character shapes are badly spaced. It looks like they're
> aligned to int coords. Please run the OutlineTest.java for a quick look.
>
> That's the main reason why I can't overlay TextLayout.draw(..) over a
> TextLayout.getOutline() without getting "spurious pixels" around the
> characters.
>
> Can you investigate ?
>
> 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: "Chris Campbell"
> To:
> Sent: Monday, November 13, 2006 4:52 PM
> Subject: Re: [JAVA2D] AttributedString and Outline
>
>
>> Hi Mik,
>>
>> You might also be able to glean some ideas from the SwingLabs team's
>> recent work on Painters. The basic approach is to paint text as an
>> outline (and shapes, images, etc) and then perform various effects on
>> each layer, for example:
>> http://weblogs.java.net/blog/joshy/archive/2006/09/introducing_pai_1.html
>>
>> Chris
>>
>>
>> Phil Race wrote:
>>> Vincent Hardy's book Java 2D API Graphics comes with
>>> a GLF toolkit which supports many effects. There are
>>> examples of embossed text and other effects.
>>> I believe the toolkit is available for download.
>>> Use your favourite search engine.
>>>
>>> You can also take a look at the java 2D demo.
>>> This does use outlines. Sounds like that isn't
>>> exactly what you want but take a look anyway
>>>
>>> Also note that you can set FOREGROUND and BACKGROUND
>>> text attributes which can be a Paint, not just a Color.
>>>
>>> -phil.
>>>
>>> Michele Puccini wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm using TextLayouts made by AttributedStrings and I need to outline
>>>> (Stroke) the characters. Sadly I didn't find any Outline TextAttribute,
>>>> so I
>>>> would like to know how to implement it.
>>>>
>>>> More generally it would be nice to implement virtually any kind of
>>>> TextAttribute i.e. Emboss, Shadow, etc.
>>>>
>>>> Suggestions ?
>>>>
>>>> Mik
>>>> --
>>>>
>>>> ===========================================================================
>>>>
>>>>
>>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>>> body
>>>> of the message "signoff JAVA2D-INTEREST". For general help, send
>>>> email to
>>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff JAVA2D-INTEREST". For general help, send email
>>> to
>>> listserv@java.sun.com and include in the body of the message "help".
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

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 <
============================================================================

----- Original Message -----
From: "Phil Race"
To:
Sent: Thursday, November 16, 2006 1:08 AM
Subject: Re: [JAVA2D] AttributedString and Outline

> The bitmap glyph images are hinted and gridfitted.
> This is not done for the returned outline as it
> doesn't make sense to do that for a pure shape.
>
> For most of what you are doing you need outlines
> anyway as the rasteriser can only return glyph
> images.
>
> -phil.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[AttributedStringTest.java]

"Jan Bösenberg (INCORS GmbH)"

Michele,

I have not tested your showcase but I think I know what you mean.
Probably the only way to achieve what you want is to implement your own
outline rendering by draw the string five times. Four times using the
foreground color with x, y offsets (1, -1), (1, 1), (-1, 1), (-1, -1),
and finally once without offset using the background color (or white if
there is no background color). This will not look perfect and the glyphs
will not really be hollow as you would expect from and outlined glyph,
but maybe while TextLayout has no support for an Outline attribute this
will do the job.

Cheers

Jan

Michele Puccini schrieb:
> 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 <
> ============================================================================
>
>
>
> ----- Original Message -----
> From: "Phil Race"
> To:
> Sent: Thursday, November 16, 2006 1:08 AM
> Subject: Re: [JAVA2D] AttributedString and Outline
>
>
>> The bitmap glyph images are hinted and gridfitted.
>> This is not done for the returned outline as it
>> doesn't make sense to do that for a pure shape.
>>
>> For most of what you are doing you need outlines
>> anyway as the rasteriser can only return glyph
>> images.
>>
>> -phil.
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

Thanks Jan,

the trick is what I call "old school". It takes me back to the good old
Amiga days..
Of course it is only applicable to a very limited number of cases. An
outline of 9 pixels will request much more than five times..

What I want to focus here is that maybe we're facing a bug in the TextLayout
implementation.
Give a try to my src code and get a picture of what I mean.

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: ""Jan Bösenberg (INCORS GmbH)""
To:
Sent: Thursday, November 16, 2006 10:53 AM
Subject: Re: [JAVA2D] AttributedString and Outline (the return of the glyph
invaders!)

> Michele,
>
> I have not tested your showcase but I think I know what you mean.
> Probably the only way to achieve what you want is to implement your own
> outline rendering by draw the string five times. Four times using the
> foreground color with x, y offsets (1, -1), (1, 1), (-1, 1), (-1, -1),
> and finally once without offset using the background color (or white if
> there is no background color). This will not look perfect and the glyphs
> will not really be hollow as you would expect from and outlined glyph,
> but maybe while TextLayout has no support for an Outline attribute this
> will do the job.
>
>
> Cheers
>
> Jan
>
>
> Michele Puccini schrieb:
>> 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 <
>> ============================================================================
>>
>>
>>
>> ----- Original Message -----
>> From: "Phil Race"
>> To:
>> Sent: Thursday, November 16, 2006 1:08 AM
>> Subject: Re: [JAVA2D] AttributedString and Outline
>>
>>
>>> The bitmap glyph images are hinted and gridfitted.
>>> This is not done for the returned outline as it
>>> doesn't make sense to do that for a pure shape.
>>>
>>> For most of what you are doing you need outlines
>>> anyway as the rasteriser can only return glyph
>>> images.
>>>
>>> -phil.
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

"Jan Bösenberg (INCORS GmbH)"

Hi Michele,

can't you simply use getOutline(AffineTransform transform) in TextLayout?

Cheers

Jan

Michele Puccini schrieb:
> Hello,
>
> I'm using TextLayouts made by AttributedStrings and I need to outline
> (Stroke) the characters. Sadly I didn't find any Outline
> TextAttribute, so I
> would like to know how to implement it.
>
> More generally it would be nice to implement virtually any kind of
> TextAttribute i.e. Emboss, Shadow, etc.
>
> Suggestions ?
>
> Mik
> --
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

Jan,

the outline computed from the TextLayout.getOutline() does not respect the
correct metrics, spacing of the TextLayout. There's a big visual difference
between:

TextLayout.draw(g2d,x,y);

and

Graphics2D.draw(TextLayout.getOutline(..));

Try it by yourself and see what happens (use antialiasing and fractional
metrics).

Cheers,

Mik
--

----- Original Message -----
From: ""Jan Bösenberg (INCORS GmbH)""
To:
Cc: "Michele Puccini"
Sent: Friday, November 10, 2006 3:25 PM
Subject: Re: [JAVA2D] AttributedString and Outline

> Hi Michele,
>
> can't you simply use getOutline(AffineTransform transform) in TextLayout?
>
>
> Cheers
>
> Jan
>
>
> Michele Puccini schrieb:
>> Hello,
>>
>> I'm using TextLayouts made by AttributedStrings and I need to outline
>> (Stroke) the characters. Sadly I didn't find any Outline TextAttribute,
>> so I
>> would like to know how to implement it.
>>
>> More generally it would be nice to implement virtually any kind of
>> TextAttribute i.e. Emboss, Shadow, etc.
>>
>> Suggestions ?
>>
>> Mik
>> --

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".