Letters following curve

Discussion in 'Java' started by Eustace, May 29, 2010.

  1. Eustace

    Eustace Guest

    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

    --
    It ain't THAT, babe! - A radical reinterpretation
    https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
     
    Eustace, May 29, 2010
    #1
    1. Advertising

  2. Eustace

    Eric Sosman Guest

    On 5/29/2010 5:51 PM, Eustace wrote:
    > 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

    --
    Eric Sosman
    lid
     
    Eric Sosman, May 29, 2010
    #2
    1. Advertising

  3. Eustace

    Eustace Guest

    On 2010-05-29 18:16 Peter Duniho wrote:
    > Eustace wrote:
    >> 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?

    >
    > 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

    --
    It ain't THAT, babe! - A radical reinterpretation
    https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
     
    Eustace, Jun 1, 2010
    #3
  4. Eustace

    Eustace Guest

    On 2010-05-29 18:20 Eric Sosman wrote:
    > On 5/29/2010 5:51 PM, Eustace wrote:
    >> 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


    Interesting. However the letters seem a little more inclined than I
    think they should, and I haven't yet found out why and how to affect it.
    emf

    --
    It ain't THAT, babe! - A radical reinterpretation
    https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
     
    Eustace, Jun 1, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy S.

    Learning Curve on 2.0

    Jeremy S., Sep 9, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    382
    clintonG
    Sep 10, 2005
  2. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    0
    Views:
    351
    =?Utf-8?B?ZGF2aWQ=?=
    Feb 16, 2006
  3. Merrigan
    Replies:
    4
    Views:
    575
    Chris
    Dec 14, 2007
  4. Hicham Mouline
    Replies:
    2
    Views:
    373
    Jerry Coffin
    Sep 14, 2009
  5. Venugopal
    Replies:
    11
    Views:
    1,533
    Tassilo v. Parseval
    Nov 5, 2003
Loading...

Share This Page