我有一个检索字符串形状的函数:
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);
}
一旦我得到一个字符串的 Shape 对象,我想要可以用来绘制字符串的坐标:
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();
}
问题是点 ArrayList 是遍历字符串边界的点。有没有办法只使用简单的单线段来获取绘制字符串的坐标?不是构成字符串轮廓的坐标。