Here you can find the source of getTextBounds(AttributedString text, Graphics2D g2)
Parameter | Description |
---|---|
text | the attributed string (<code>null</code> not permitted). |
g2 | the graphics target (<code>null</code> not permitted). |
null
).
public static Rectangle2D getTextBounds(AttributedString text, Graphics2D g2)
//package com.java2s; /* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version./* ww w . j a v a 2 s.co m*/ * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * AttrStringUtils.java * -------------------- * (C) Copyright 2013, 2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 01-Aug-2013 : Version 1, backported from JFreeChart-FSE (DG); * 18-Mar-2014 : Added getTextBounds() method (DG); * */ import java.awt.Graphics2D; import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; import java.text.AttributedString; public class Main { /** * Returns the bounds for the attributed string. * * @param text the attributed string (<code>null</code> not permitted). * @param g2 the graphics target (<code>null</code> not permitted). * * @return The bounds (never <code>null</code>). * * @since 1.0.18 */ public static Rectangle2D getTextBounds(AttributedString text, Graphics2D g2) { TextLayout tl = new TextLayout(text.getIterator(), g2.getFontRenderContext()); return tl.getBounds(); } }