Time for a few quick comments
>>> Alternatively you can convert the string to a Shape and perform
you will get worse looking text this way. It will also be much slower.
> Another alternative (preferable to creating a Shape, I think) is > to render the string into an Image, and then rotate the image.
As well as the string itself an image will carry the background with it so this is probably not the best way to go for most people. And except for quadrant rotations I would not expect great results.
Rotate the graphics and draw the text along the lines of a previous poster is the most straightforward solution and that will get accelerated too in the future and is fairly snappy even in software.
As for measuring the text, there are many APIs for this - too many! But the only one that is trying to be "pixel perfect" is java.awt.font.GlyphVector.getPixelBounds() which is however consequently expensive and won't work for complex text. Try to use something like java.awt.font.TextLayout.getBounds() for that - its not going to be as pixel perfect but will work for complex text. You may even be able to get away with java.awt.font.GlyphVector.getVisualBounds() if you don't use complex text. Did I mention there are a lot of APIS for this? In fact I probably still missed one ..
-phil.
Chet Haase wrote:
Another alternative (preferable to creating a Shape, I think) is to render the string into an Image, and then rotate the image. Or better yet: render the rorate string into the image, and then just copy the image (no transform involved).
This approach is not worth the hassle if you are constantly changing the string orientation, or if you are only rendering it once. Butif you are constantly rendering the same string at the same orientation, then it might be worth the hassle/ memory-footprint tradeoff to get a performance boost from doing a simple image copy instead of a transformed text operation.
Worth mentioning as an option, anyway.
Chet.
Alexey Ushakov wrote:
I think that first approach is more preferable.
Shape of the string is just outline of the string. It does not contain all necessary information (like hinting for example) for drawing string. This could affect quality especially in case of strings of small sizes.
Though, such approach could be used with strings of large sizes for performance reason.
Alexey
On Tue, Mar 22, 2005 at 10:32:27AM -0500, Nidel, Mike wrote:
The answer to your first question is relatively simple:
Before you draw the string, you can do a transform() on the Graphics2D. You pass in an AffineTransform that you create with AffineTransform.getRotateInstance(theta).
Alternatively you can convert the string to a Shape and perform a rotation on the Shape itself.
As for your second question, I don't think I can help you there. This information will change depending on whether you're using anti-aliasing or not. You may be able to convert your string into a Shape and do some kind of operation to iterate over all of the pixels in the shape... but I'm not sure.
Mike
-----Original Message----- From: Discussion list for Java 2D API [mailto:[EMAIL PROTECTED] Behalf Of Sven Mielordt Sent: Tuesday, March 22, 2005 10:21 AM To: [EMAIL PROTECTED] Subject: [JAVA2D] drawString() on Graphics2D question
Hi fellows,
I have a short question concerning drawString() on Graphics2D. When using it, the string is printed horizontally. But how can I print text vertically or at arbitrary angles???
A refining question concerns the number of pixels needed for the string. Is there any method to find out how many pixels in all directions will be occupied?
Thank you, Sven ______________________________________________________________ Verschicken Sie romantische, coole und witzige Bilder per SMS! Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
============================================================== ============= 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".
===========================================================================
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".
===========================================================================
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".
=========================================================================== 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".
=========================================================================== 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".