Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Chet Haase
Clarification:

 > 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.
You can create an image with a transparent background and render
the text to it.  When you copy the image, only the text pixels
will be copied.
There's sample code for doing just this in the Intermediate Images
article on java.sun.com.
And except for quadrant rotations I would not expect great results.
Not sure what this means - rendering the string to an image and then
copying the image to the screen (or back buffer) should give
you exactly the same results as rendering the string directly
to the screen/back-buffer.
Rotating the image may give you different results than rotating
the string, but if you take the "better yet" suggestion for
pre-rotating the string into the image, then the results should
be exactly the same.
But I agree that this is really only a workaround for current
lack of acceleration for this operation; we hope to handle
all of this implicitly in future releases.
Chet.

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

Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Phil Race
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".
===

Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Chet Haase
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".


Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Alexey Ushakov
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".


Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Nidel, Mike
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".


Re: [JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread David Gilbert
Sven Mielordt wrote:
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
_

Here is a utility method that I use for JFreeChart - it seems to work
pretty well:
   /**
* A utility method for drawing rotated text.
* 
* A common rotation is -Math.PI/2 which draws text 'vertically'
(with the
* top of the characters on the left).
*
* @param text  the text.
* @param g2  the graphics device.
* @param textX  the x-coordinate for the text (before rotation).
* @param textY  the y-coordinate for the text (before rotation).
* @param angle  the angle of the (clockwise) rotation (in radians).
* @param rotateX  the point about which the text is rotated.
* @param rotateY  the point about which the text is rotated.
*/
   public static void drawRotatedString(final String text,
final Graphics2D g2,
final float textX,
final float textY,
final double angle,
final float rotateX,
final float rotateY) {
   if ((text == null) || (text.equals(""))) {
   return;
   }
   final AffineTransform saved = g2.getTransform();
   // apply the rotation...
   final AffineTransform rotate = AffineTransform.getRotateInstance(
   angle, rotateX, rotateY
   );
   g2.transform(rotate);
   if (useDrawRotatedStringWorkaround) {
   // workaround for JDC bug ID 4312117 and others...
   final TextLayout tl = new TextLayout(
   text, g2.getFont(), g2.getFontRenderContext()
   );
   tl.draw(g2, textX, textY);
   }
   else {
   // replaces this code...
   g2.drawString(text, textX, textY);
   }
   g2.setTransform(saved);
   }
A couple of comments on the code:
(1)  the method allows you to specify the text anchor point and the
rotation point separately - that is used in our library to provide a
range of different alignment options.  Just pass in the same (x, y)
point for the rotation point for the simplest case.
(2)  the 'useDrawRotatedStringWorkaround' flag just gives two different
ways to draw the text, as a workaround for some JDK bugs (probably fixed
now, I don't get so many reports about the problem anymore).  I know
that one method failed on some platforms and the other method failed on
some other platforms, but I forget which.
Regards,
Dave Gilbert
JFreeChart Project Leader
===
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".


[JAVA2D] drawString() on Graphics2D question

2005-03-22 Thread Sven Mielordt
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".