本文整理汇总了Java中sun.font.FontDesignMetrics类的典型用法代码示例。如果您正苦于以下问题:Java FontDesignMetrics类的具体用法?Java FontDesignMetrics怎么用?Java FontDesignMetrics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FontDesignMetrics类属于sun.font包,在下文中一共展示了FontDesignMetrics类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFontMetrics
import sun.font.FontDesignMetrics; //导入依赖的package包/类
public FontMetrics getFontMetrics() {
if (this.fontMetrics != null) {
return this.fontMetrics;
}
/* NB the constructor and the setter disallow "font" being null */
return this.fontMetrics =
FontDesignMetrics.getMetrics(font, getFontRenderContext());
}
示例2: getFontMetrics
import sun.font.FontDesignMetrics; //导入依赖的package包/类
public static FontMetrics getFontMetrics(JComponent c, Font font) {
FontRenderContext frc = getFRCProperty(c);
if (frc == null) {
frc = DEFAULT_FRC;
}
return FontDesignMetrics.getMetrics(font, frc);
}
示例3: getStringBounds
import sun.font.FontDesignMetrics; //导入依赖的package包/类
/**
* Returns the logical bounds of the specified array of characters
* in the specified <code>FontRenderContext</code>. The logical
* bounds contains the origin, ascent, advance, and height, which
* includes the leading. The logical bounds does not always enclose
* all the text. For example, in some languages and in some fonts,
* accent marks can be positioned above the ascent or below the
* descent. To obtain a visual bounding box, which encloses all the
* text, use the {@link TextLayout#getBounds() getBounds} method of
* <code>TextLayout</code>.
* <p>Note: The returned bounds is in baseline-relative coordinates
* (see {@link java.awt.Font class notes}).
* @param chars an array of characters
* @param beginIndex the initial offset in the array of
* characters
* @param limit the end offset in the array of characters
* @param frc the specified <code>FontRenderContext</code>
* @return a <code>Rectangle2D</code> that is the bounding box of the
* specified array of characters in the specified
* <code>FontRenderContext</code>.
* @throws IndexOutOfBoundsException if <code>beginIndex</code> is
* less than zero, or <code>limit</code> is greater than the
* length of <code>chars</code>, or <code>beginIndex</code>
* is greater than <code>limit</code>.
* @see FontRenderContext
* @see Font#createGlyphVector
* @since 1.2
*/
public Rectangle2D getStringBounds(char [] chars,
int beginIndex, int limit,
FontRenderContext frc) {
if (beginIndex < 0) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > chars.length) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
// this code should be in textlayout
// quick check for simple text, assume GV ok to use if simple
boolean simple = values == null ||
(values.getKerning() == 0 && values.getLigatures() == 0 &&
values.getBaselineTransform() == null);
if (simple) {
simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
}
if (simple) {
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc);
return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex);
} else {
// need char array constructor on textlayout
String str = new String(chars, beginIndex, limit - beginIndex);
TextLayout tl = new TextLayout(str, this, frc);
return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
tl.getAscent() + tl.getDescent() +
tl.getLeading());
}
}
示例4: size
import sun.font.FontDesignMetrics; //导入依赖的package包/类
@Override
public Dimension size(Component component) {
if (!(component instanceof Text))
throw new IllegalArgumentException("Text layout must only be used on texts.");
int width = 0;
int height = 0;
Text text = (Text) component;
Insets insets = text.getPadding();
if (insets != null) {
width += insets.left + insets.right;
height += insets.top + insets.bottom;
}
DropShadow shadow = text.getDropShadow();
if (shadow != null) {
width += shadow.getOffsetX();
height += shadow.getOffsetY();
}
Font font = text.getFont();
if (font != null) {
String string = text.getText();
if (string != null && string.length() > 0) {
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font);
if (metrics != null) {
Graphics graphics = null;
BufferedImage cache = text.getCachedImage();
if (cache != null)
graphics = cache.getGraphics();
Rectangle2D rect = metrics.getStringBounds(string, graphics);
width += rect.getWidth();
height += rect.getHeight();
}
}
}
return new Dimension(width, height);
}