本文整理汇总了Java中java.awt.Canvas.getFontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getFontMetrics方法的具体用法?Java Canvas.getFontMetrics怎么用?Java Canvas.getFontMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Canvas
的用法示例。
在下文中一共展示了Canvas.getFontMetrics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScaledIcon
import java.awt.Canvas; //导入方法依赖的package包/类
private ImageIcon getScaledIcon(ImageIcon original) {
Canvas c = new Canvas();
FontMetrics fm = c.getFontMetrics(new JPanel().getFont());
int height = (int) (fm.getHeight() * 2f);
int width = original.getIconWidth() / original.getIconHeight() * height;
BufferedImage scaledImage;
if (!scraper.isEnabled()) {
scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
Scalr.OP_GRAYSCALE);
}
else {
scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
Scalr.OP_ANTIALIAS);
}
return new ImageIcon(scaledImage);
}
示例2: FontSystem
import java.awt.Canvas; //导入方法依赖的package包/类
public FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize)
{
int style;
switch (fontStyle)
{
case com.kitfox.svg.Text.TXST_ITALIC:
style = java.awt.Font.ITALIC;
break;
default:
style = java.awt.Font.PLAIN;
break;
}
int weight;
switch (fontWeight)
{
case com.kitfox.svg.Text.TXWE_BOLD:
case com.kitfox.svg.Text.TXWE_BOLDER:
weight = java.awt.Font.BOLD;
break;
default:
weight = java.awt.Font.PLAIN;
break;
}
sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize);
Canvas c = new Canvas();
fm = c.getFontMetrics(sysFont);
FontFace face = new FontFace();
face.setAscent(fm.getAscent());
face.setDescent(fm.getDescent());
face.setUnitsPerEm(fm.charWidth('M'));
setFontFace(face);
}
示例3: getScaledIcon
import java.awt.Canvas; //导入方法依赖的package包/类
private ImageIcon getScaledIcon(ImageIcon original) {
Canvas c = new Canvas();
FontMetrics fm = c.getFontMetrics(getFont());
int height = (int) (fm.getHeight() * 2f);
int width = original.getIconWidth() / original.getIconHeight() * height;
BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
Scalr.OP_ANTIALIAS);
return new ImageIcon(scaledImage);
}