From: Eustace on 29 May 2010 17:51 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
From: Peter Duniho on 29 May 2010 18:16 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
From: Eric Sosman on 29 May 2010 18:20 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 esosman(a)ieee-dot-org.invalid
From: Eustace on 1 Jun 2010 15:39 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
From: Eustace on 1 Jun 2010 16:15 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
|
Pages: 1 Prev: Suggession for your website Next: This is the way i make my dream and monthly income |