AbstractAWTDrawVisitor implements IDrawVisitor { protected Point getTextBasePoint(String text, double xCoord, double yCoord, Graphics2D graphics) { FontMetrics fontMetrics = graphics.getFontMetrics(); Rectangle2D stringBounds = fontMetrics.getStringBounds(text, graphics); int[] point = this.transformPoint(xCoord, yCoord); int baseX = (int) (point[0] - (stringBounds.getWidth() / 2)); int baseY = (int) (point[1] + (fontMetrics.getAscent() - stringBounds.getHeight() / 2)); return new Point(baseX, baseY); }  int[] transformPoint(double xCoord, double yCoord); void transformPoint(double[] xy); @Override void setTransform(AffineTransform transform);  }
@Test public void testGetTextBasePoint() { AbstractAWTDrawVisitor visitor = new NestedAWTDrawVisitor(); visitor.setTransform(new AffineTransform()); Image image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) image.getGraphics(); Point point = visitor.getTextBasePoint("Foo", 3, 5, g2d); Assert.assertNotNull(point); }