diff options
Diffstat (limited to 'libjava/java/awt/FontMetrics.java')
-rw-r--r-- | libjava/java/awt/FontMetrics.java | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/libjava/java/awt/FontMetrics.java b/libjava/java/awt/FontMetrics.java index cb76f50..1520d59 100644 --- a/libjava/java/awt/FontMetrics.java +++ b/libjava/java/awt/FontMetrics.java @@ -38,6 +38,10 @@ exception statement from your version. */ package java.awt; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.text.CharacterIterator; + // FIXME: I leave many methods basically unimplemented. This // should be reviewed. @@ -349,6 +353,111 @@ toString() + ",descent=" + getDescent() + ",height=" + getHeight() + "]"); } -} // class FontMetrics +// Generic FontRenderContext used when getLineMetrics is called with a +// plain Graphics object. +private static final FontRenderContext gRC = new FontRenderContext(null, + false, + false); + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param text The string to calculate metrics from. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + */ +public LineMetrics getLineMetrics(String text, Graphics g) +{ + return getLineMetrics(text, 0, text.length(), g); +} +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param text The string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(String text, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(text, begin, limit, rc); +} + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param chars The string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(char[] chars, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(chars, begin, limit, rc); +} + +/** + * Returns a {@link LineMetrics} object constructed with the + * specified text and the {@link FontRenderContext} of the Graphics + * object when it is an instance of Graphics2D or a generic + * FontRenderContext with a null transform, not anti-aliased and not + * using fractional metrics. + * + * @param ci An iterator over the string to calculate metrics from. + * @param begin Index of first character in <code>text</code> to measure. + * @param limit Index of last character in <code>text</code> to measure. + * @param g The Graphics object that will be used. + * + * @return A new {@link LineMetrics} object. + * + * @throws IndexOutOfBoundsException if the range [begin, limit] is + * invalid in <code>text</code>. + */ +public LineMetrics getLineMetrics(CharacterIterator ci, int begin, + int limit, Graphics g) +{ + FontRenderContext rc; + if (g instanceof Graphics2D) + rc = ((Graphics2D) g).getFontRenderContext(); + else + rc = gRC; + return font.getLineMetrics(ci, begin, limit, rc); +} +} |