Hello all. As usual, I'm trying to do something a little weird here. And as usual, I'm stuck. That's why I'm turning to the Moose for help.
Without going into too much background detail, I need to parse a bunch of words separated by spaces, like a long paragraph, into an list. Each element in the list will be a
String containing a section of the paragraph not to exceed a given length. I don't want to split any words. This processing will be done in preparation to print onto (annotate) an image file.
In other words, I need to create a non-graphical
word wrapper.
I could write a class that does pretty much I've described to this point (although any sample code someone else already has working would be great.) The real kicker is that I want to be able to specify a font size and face for the method to take under consideration in calculating the contents of each String. I would need to somehow specify a maximum number of pixels(?)
as the length of each line.
This class would also need to calculate the offset between the 'sentence' Strings to print them down the page (the image.)
Here's a high-level use case of how I'd envision this to work:
TextWrapper tw = new TextWrapper();
tw.setTextToWrap("Here's the stuff we want to wrap all over the place, blah, blah, blah");
tw.setFont(new Font("Arial",Font.PLAIN,10);
tw.setMaxPixels(1000);
tw.wrapIt();
for (int i = 0; i < tw.getNumLines(); i++) {
String nextLine = (String)tw.getLine(i);
// write out each line
}
There may be a way to accomplish the end results using awt components, but I haven't been able to figure this out so far.
Thanks in advance for any assistance,
Rick <><