0

文字列の Shape を取得する関数があります。

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 が文字列の境界を横切る点です。単純な単一の線分を使用して文字列を描画する座標だけを取得する方法はありますか? 紐の輪郭を作る座標ではありません。

4

0 に答える 0