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