File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weird rendering of text outline in AWT

 
Petr Vasicek
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
maw.png
Example of text renreding
[Thumbnail for maw.png]
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Petr Vasicek
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic