Letters following curve

E

Eustace

I am writing a program that draws arcs and I need to have titles over
each arc. I can use

painter2D.drawString(...);

and even

painter2D.rotate(...);

so that the title will appear at an angle, but what I really want to do
is to have the letters follow the curve of the arc.

I suppose a way to do this is to position each letter of the title and
then rotate each one separately. This is complicated, and besides I
cannot (or it's hard to) calculate with accuracy the desired angle of
rotation of each letter.

Is there another way to do it?

emf
 
E

Eric Sosman

I am writing a program that draws arcs and I need to have titles over
each arc. I can use

painter2D.drawString(...);

and even

painter2D.rotate(...);

so that the title will appear at an angle, but what I really want to do
is to have the letters follow the curve of the arc.

I suppose a way to do this is to position each letter of the title and
then rotate each one separately. This is complicated, and besides I
cannot (or it's hard to) calculate with accuracy the desired angle of
rotation of each letter.

Is there another way to do it?

Googling for "curved text in java" gets several likely-
looking hits, including

http://www.java2s.com/Code/Java/2D-Graphics-GUI/Drawtextalongacurve.htm
 
E

Eustace

Calculating the angle should not be difficult, assuming you have a
reasonable way to define the arc. For example, if the arc is defined as
a segment of an ellipse, then the tangent at the letter's position along
the arc is easily determined, and of course the tangent defines the
baseline rotation for the letter.

Then you have to determine what position along the arc the letter is
drawn. However, that also should not be that hard. The string will
take a certain length without transformation, with each letter being at
a specific position. So simply map the straight-line distances for the
untransformed string onto the arc on which you want to draw the string.
That will allow you to find positions for the individual characters
along the arc.

As for making it easier, well…that's what OOP is all about. Write a
simple class that does the harder work of enumerating each character and
drawing it individually with the appropriate rotation for its position.
Once you've done that, then where you actually have the need to draw
entire strings along some arc, just use that class. Then the code where
you need that drawing done remains nice and simple.

Pete

It was easier than I thought. Even for an ellipse. Though there are
minor adjustments necessary because the coordinates do not point to the
middle of the character. And then, clearly monospaced font appears
better... Thanks, emf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top