0

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.

  • what coordinates do you want where?? – gpasch Apr 13 '16 at 20:03
  • the thing is you havent drawn anything yet - you need to give the coordinates where the string will be painted – gpasch Apr 13 '16 at 20:13
  • The code above gives these coordinates: `-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]` which results in the block A at the top of [link](http://imgur.com/a/AGK45). What I would like is to get the coordinates to draw the A like the one at the bottom of [link](http://imgur.com/a/AGK45) ie. not an outline of the letter A. – Hoootie88 Apr 28 '16 at 22:22

0 Answers0