File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing text along a line

 
Veronique Kus
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to implement drawing text along lines, or rather cubic curves. I found this page very useful ("Text along a path" section). However, this code draws text at the beginning of the line. What I need is to draw text at the end of the line. I tried modifying the code given on the website (TextStroke.java) and I came up with the below class (my code changes are enclosed in //MY CHANGES (...) //END OF MY CHANGES and most of the comments is my trying to understand this code):



I'm also posting two further classes which, together which the class above form an application which demonstrates what I am trying to achieve and my problem.




This sort of works but there are a couple of problems:
- one or more letters get missing when I reposition the curve
- sometimes the string disappears completely
- when I swap line ends (I move the end of the line to the left of its start), the string is not drawn correctly

I find all this very confusing and it took me ages to even figure out what I have done so far. It is the first time I'm working with the PathIterator and GlyphVector classes and so I am really struggling to understand the content of class which does the work of drawing the string. I would REALLY appreaciate some help with getting this to work correctly... anyone, please?

Also, I wanted to ask why in line 88 of the first class the nextAdvance variable, which seems to me to represent the horizontal advance along the baseline caused by the next charcter in the string, is calculated as:
nextAdvance = glyphVector.getGlyphMetrics( currentChar ).getAdvance() * 0.5f;
Specifically, if glyphVector.getGlyphMetrics( currentChar ).getAdvance() gives us the advance, why are we multiplying it by 0.5f??
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Veronique Kus wrote:Specifically, if glyphVector.getGlyphMetrics( currentChar ).getAdvance() gives us the advance, why are we multiplying it by 0.5f??

I'm no expert on the main question, but if I wanted to discover why in someone else's code a factor of 0.5F is applied, I would change that factor to different values (probably in a range of about 0.1 to 10) and see how it affected the visual representation.
 
Veronique Kus
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did that and I noticed no difference to be honest... really strange!
EDIT: Now you said that I looked again and turned out my program was using one copy of the class and I was changing a different copy... Let's see what happens when I fix this!
EDIT2: Same thing again... have no idea why this time.
 
Veronique Kus
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone, pleeeease? This is driving me crazy :-/
 
Veronique Kus
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I made a very minor change to the code thanks to which the second letter of the word on the curve isn't drawn in the same place as the first letter, which was the case in the previous version. However, I still have serious problems with:
a) transforming the string when you invert the start&end point of the curve. The String is still drawn upside down when you drag the right end of the curve to be the left end.
b) the string still disappears randomly during repositioning of the curve.



Oh and the "rotate" parameter which I introduced to the constructor says whether the string should be transformed (but I don't know how) because now the line is going the other way round (as in a) above the code).

I'm really hoping for some help... I'm doing what I can but I am really struggling and this code is an important part of an important project wich I have to hand in very soon :-(
 
Veronique Kus
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, solved the string rotation problem! Now there's the most difficult thing left - the dissapearing string... it disappears/appears when I reposition the end points or the control points and I have no idea why.......

The newest version of the string-drawing class with one problem remaining:
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic