1 42 43 package org.jfree.text; 44 45 import java.awt.FontMetrics ; 46 import java.awt.Graphics2D ; 47 import java.awt.geom.Rectangle2D ; 48 49 54 public class G2TextMeasurer implements TextMeasurer { 55 56 57 private Graphics2D g2; 58 59 64 public G2TextMeasurer(final Graphics2D g2) { 65 this.g2 = g2; 66 } 67 68 77 public float getStringWidth(final String text, 78 final int start, final int end) { 79 final FontMetrics fm = this.g2.getFontMetrics(); 80 final Rectangle2D bounds = TextUtilities.getTextBounds( 81 text.substring(start, end), this.g2, fm 82 ); 83 final float result = (float) bounds.getWidth(); 84 return result; 85 } 86 87 } 88 89 | Popular Tags |