aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Weird rendering of text outline in AWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Weird rendering of text outline in AWT" Watch "Weird rendering of text outline in AWT" New topic
Author

Weird rendering of text outline in AWT

Petr Vasicek
Greenhorn

Joined: Jan 04, 2006
Posts: 5
I've followed a tutorial on creating a text with border here: http://java.sun.com/developer/onlineTraining/Media/2DText/style.html, using java.awt.Graphics2D.

It works, but only for thin outlines. If i make the outline thicker, the sharp points in the text (in letters like A, M or W) get overly "stretched". Please see the attached picture, it's hard to describe this effect.

As a workaround, I tried to use transformations and the fill() command to "draw a rectangle" with the text in a for-cycle in black and then fill() the text in white in the middle of it. This approach works great, but is really very slow and I would need to resize the text dynamically in my program

This is the code I'm using with the original method I found in the tutorial:



This is a method in my Text class, so there are variables like color, borderRatio which are available. It seems to me that this is a bug in text outlining which happens with very sharp points in the text. Is there any way around it, some settings that can resolve this issue? Or any workaround (except the one I mentioned)?

Many thanks!



[Thumbnail for maw.png]

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

You could try some of the RenderingHints, particularly the ones for anti-aliasing and render quality. Or you could use the approach at Java World -- Jazz up the standard Java fonts. Or thee's a code sample rather like yours on java2s.com.


luck, db
There are no new questions, but there may be new answers.
Petr Vasicek
Greenhorn

Joined: Jan 04, 2006
Posts: 5
Thanks Darryl for your reply, it made me try the example from java2s and when I was adding setStroke command I realized that the constructor of BasicStroke can have more parameters, played with it a bit and resolved the issue:
Basically anything apart from BasicStroke.JOIN_MITER as the third parameter will do.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Petr Vasicek wrote:Thanks Darryl for your reply, it made me try the example from java2s and when I was adding setStroke command I realized that the constructor of BasicStroke can have more parameters, played with it a bit and resolved the issue:

You're welcome, and well done!
 
jQuery in Action, 2nd edition
 
subject: Weird rendering of text outline in AWT