I have a function that retrieves the Shape of a string:
private Shape getTextShape(String str, Font font) {
BufferedImage bufferImage = new BufferedImage(2,2,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferImage.createGraphics();
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout tl = new TextLayout(str, font, frc);
return tl.getOutline(null);
}
Once I get the Shape object of a string, I want to coordinates that can be used to draw the string:
Font font = new Font(null, Font.PLAIN, 10);
Shape shape = getTextShape("A",font);
ArrayList<DPoint> points = new ArrayList<DPoint>();
PathIterator pathIterator = shape.getPathIterator(null, 5.0d);
float[] coords = new float[2];
while (!pathIterator.isDone()) {
pathIterator.currentSegment(coords);
points.add(new DPoint(coords[0], coords[1]));
pathIterator.next();
}
The problem is the points ArrayList is the points that traverse the boundary of the string. Is there a way to get just the coordinates that draws the string using simple single line segment? Not the coordinates that make an outline of the string.