Reputation:
I have a font object and a String. I want to return a Shape Object that is a representation of the String. I have a whole bunch of other classes that will display the String and take care of it.
I'm having trouble figuring out how to do this when I do not have a graphics/graphics2d object. Any Help? I have searched the net but had trouble finding helpful links.
public class SpecializationOfTester extends ParentTester {
private String str;
private Font font;
public SpecializationOfTester(String str, Font font) {
this.font = font;
this.str = str;
}
public Shape getShape()
{
Shape s;
//
//
return s;
}
}
Thanks
Upvotes: 3
Views: 372
Reputation: 205765
You can use GlyphVector#getOutline()
, as mentioned here. You can create a graphics context in a BufferedImage
, as discussed in Using Headless Mode in the Java SE Platform.
See also these appealing examples:
PictureText
, due to Andrew Thompson.
Test
, due to Savvas Dalkitsis.
Upvotes: 6