Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

text orientation

101 views
Skip to first unread message

David Duncan

unread,
Mar 25, 1999, 3:00:00 AM3/25/99
to
Hello,

I'm writing an application that involves plotting charts. Does anyone know
how to orient text so that it starts at the bottom of the page and continues
upwards (i.e. normal text that is turned 90 degrees anti-clockwise)? This is
needed to label one of the axes on the chart. I don't think that there are
any methods in the JDK packages that achieve this but perhaps someone has
written a method for the same purpose?

Thanks in advance,

David

Joachim Lous

unread,
Mar 25, 1999, 3:00:00 AM3/25/99
to
David Duncan wrote:
> I'm writing an application that involves plotting charts. Does anyone know
> how to orient text so that it starts at the bottom of the page and continues
> upwards (i.e. normal text that is turned 90 degrees anti-clockwise)? This is
> needed to label one of the axes on the chart. I don't think that there are
> any methods in the JDK packages that achieve this

Java 2D does this just fine. Might be a bit overkill, but on the other
hand
it's probably the best choice for drawing nice charts in the first place,
especially since it supports antialiasing. Gradients, texturing and
blending might come in handy too.

-Joachim.

Dave Postill

unread,
Mar 30, 1999, 3:00:00 AM3/30/99
to
[This followup was posted to comp.lang.java.programmer, cc: the cited author, David Duncan]

In article <7ddbl5$pkf$1...@starburst.uk.insnet.net>, on Thu, 25 Mar 1999 12:59:05 -0000, "David
Duncan" <drdu...@mistral.co.uk> wrote:

> Hello,


>
> I'm writing an application that involves plotting charts. Does anyone know
> how to orient text so that it starts at the bottom of the page and continues
> upwards (i.e. normal text that is turned 90 degrees anti-clockwise)? This is
> needed to label one of the axes on the chart. I don't think that there are

> any methods in the JDK packages that achieve this but perhaps someone has
> written a method for the same purpose?

FAQ: <http://www.afu.com/javafaq.html> Q10.1 "How can I write text at an angle?"

davep
--
Dave Postill Investment Intelligence Systems Corp
Galaxy Support Leader +44 (0)171 628 6960 [voice]
<mailto:da...@iisc.co.uk> +44 (0)171 638 7528 [fax]
<mailto:dave.p...@pobox.com> <http://www.iisc.co.uk>

Richard Freedman

unread,
Apr 1, 1999, 3:00:00 AM4/1/99
to
I just worked this one out, and thought I'd respond, since the faq wasn't
very helpful in my situation, and probably isn't for the situation that
David described.

Correct me if I'm wrong, but:

The method described in the faq works great if you want to apply a transform
to the entire graphics context. If all you want is some rotated text on top
of something that you've already drawn, this doesn't seem to be the way to do it.

What I did instead was to derive a font with the desired transform, and then use
that font in a drawText call, thusly:

private void label_line(Graphics g, double x, double y, double theta, String label) {

Graphics2D g2D = (Graphics2D)g;

// Create a rotation transformation for the font.
AffineTransform fontAT = new AffineTransform();

// get the current font
Font theFont = g2D.getFont();

// Derive a new font using a rotatation transform
fontAT.rotate(theta);
Font theDerivedFont = theFont.deriveFont(fontAT);

// set the derived font in the Graphics2D context
g2D.setFont(theDerivedFont);

// Render a string using the derived font
g2D.drawString(label, (int)x1, (int)y1);

// put the original font back
g2D.setFont(theFont);
}


theta (the rotation angle) is in radians.

For vertical text, use 90 * java.lang.Math.PI/180
or 270 * java.lang.Math.PI/180

depending on whether you want the text top-top-bottom or bottom-to-top


I hope that this will save you hours of aggravation.

--
==============================================
Richard Freedman
Sr. Software Engineer
CHI Systems, Inc.
mailto:rfr...@voicenet.com
http://www.chiinc.com
==============================================

0 new messages