Java检索TextLayout中文本的简单坐标

Java检索TextLayout中文本的简单坐标,java,path-iterator,Java,Path Iterator,我有一个检索字符串形状的函数: private Shape getTextShape(String str, Font font) { BufferedImage bufferImage = new BufferedImage(2,2,BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bufferImage.createGraphics(); FontRenderContext frc = g2d.getFontRenderCon

我有一个检索字符串形状的函数:

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);
}
一旦我得到一个字符串的形状对象,我想得到可以用来绘制字符串的坐标:

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();  
                } 
Font-Font=新字体(空,Font.PLAIN,10);
Shape Shape=getTextShape(“A”,字体);
ArrayList points=新的ArrayList();
PathIterator PathIterator=shape.getPathIterator(null,5.0d);
float[]坐标=新的float[2];
而(!pathierator.isDone()){
pathIterator.currentSegment(coords);
添加(新的数据点(坐标[0],坐标[1]);
pathIterator.next();
} 

问题是points ArrayList是遍历字符串边界的点。有没有一种方法可以通过简单的直线段获得绘制字符串的坐标?不是绘制字符串轮廓的坐标。

你想要什么坐标?问题是你还没有画任何东西-你需要给出绘制字符串的坐标上面的代码给出了这些坐标:
-0.015625,0.0,2.734375,-7.15625,3.75,-7.15625,6.6875,0.0,5.609375,0.0,4.765625,-2.171875,1.78125,-2.171875,0.984375,0.0,-0.015625,0.0,-0.015625,0.0,2.046875,-2.9375,4.484375,-2.9375,3.734375,-4.921875,3.21875,-6.40625,2.84375,-5.046875,2.046875,-2.9375,2.046875,-2.9375]
,其结果是块A位于顶部。我想得到的是画A的坐标,就像ie底部的坐标一样,而不是字母A的轮廓。