List of usage examples for java.awt.font GlyphVector getVisualBounds
public abstract Rectangle2D getVisualBounds();
From source file:Utils.java
public static Shape generateShapeFromText(Font font, String string) { BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); try {/* ww w.ja va 2 s . co m*/ GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string); Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY()); return shape; } finally { g2.dispose(); } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "www.java2s.com www.java2s.com"; Font font = new Font("Serif", Font.PLAIN, 24); FontRenderContext frc = g2.getFontRenderContext(); g2.translate(40, 80);//w ww .j ava2 s . co m GlyphVector gv = font.createGlyphVector(frc, s); System.out.println(gv.getVisualBounds()); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); double theta = (double) i / (double) (length - 1) * Math.PI / 4; AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate(theta); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2.fill(transformedGlyph); } }