本文整理了Java中java.awt.Canvas.getFontMetrics()
方法的一些代码示例,展示了Canvas.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Canvas.getFontMetrics()
方法的具体详情如下:
包路径:java.awt.Canvas
类名称:Canvas
方法名:getFontMetrics
暂无
代码示例来源:origin: stackoverflow.com
public static FontMetrics getFontMetrics(Font font){
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration config = gd.getDefaultConfiguration();
Canvas c = new Canvas(config);
return c.getFontMetrics(font);
}
代码示例来源:origin: org.geoserver/gs-wms
@Override
public FontMetrics getFontMetrics(Font f) {
// works also in headless mode
return new Canvas().getFontMetrics(f);
}
代码示例来源:origin: org.databene/databene-commons
public TextIcon(String text, Color foreground, Color background, boolean square, Font font) {
this.text = text;
this.font = font;
FontMetrics metrics = new Canvas().getFontMetrics(font);
this.textWidth = metrics.stringWidth(text);
this.iconWidth = textWidth;
this.iconHeight = font.getSize() + 2;
if (square) {
this.iconWidth = Math.max(this.iconWidth, this.iconHeight);
this.iconHeight = this.iconWidth;
}
this.ascent = metrics.getAscent();
this.foreground = foreground;
this.background = background;
}
代码示例来源:origin: cpesch/RouteConverter
private float getPreferredAlignmentY() {
Font font = getFont();
// deprecated: FontMetrics fm = getToolkit().getFontMetrics(font);
FontMetrics fm = new Canvas().getFontMetrics(font);
float h = fm.getHeight();
float d = fm.getDescent();
return (h - d) / h;
}
代码示例来源:origin: org.databene/databene-commons
public TextOverlayIcon(Icon background, String text, Color color, Font font) {
this.background = background;
this.text = text;
this.color = color;
this.font = font;
this.metrics = new Canvas().getFontMetrics(font);
int textWidth = metrics.stringWidth(text);
int iconWidth = background.getIconWidth();
setIconWidth(Math.max(textWidth, iconWidth));
int textHeight = font.getSize();
int iconHeight = background.getIconHeight();
setIconHeight(Math.max(textHeight, iconHeight));
}
代码示例来源:origin: jenkinsci/embeddable-build-status-plugin
public int measureText(String text) throws IOException {
if (baseUrl != null) {
URL fontURL = new URL(baseUrl, "fonts/verdana.ttf");
InputStream fontStream = fontURL.openStream();
Font defaultFont = null;
try {
defaultFont = Font.createFont(Font.TRUETYPE_FONT, fontStream);
} catch (FontFormatException e) {
throw new IOException(e.getMessage());
}
defaultFont = defaultFont.deriveFont(11f);
Canvas canvas = new Canvas();
FontMetrics fontMetrics = canvas.getFontMetrics(defaultFont);
return fontMetrics.stringWidth(text);
}
return 0;
}
代码示例来源:origin: yannickcr/jenkins-status-badges-plugin
public int measureText( String text )
throws FontFormatException, IOException
{
URL fontURL =
new URL( Jenkins.getInstance().pluginManager.getPlugin( "status-badges" ).baseResourceURL,
"fonts/verdana.ttf" );
InputStream fontStream = fontURL.openStream();
Font defaultFont = Font.createFont( Font.TRUETYPE_FONT, fontStream );
defaultFont = defaultFont.deriveFont( 11f );
Canvas canvas = new Canvas();
FontMetrics fontMetrics = canvas.getFontMetrics( defaultFont );
return fontMetrics.stringWidth( text );
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker
FontMetrics metrics = canvas.getFontMetrics(font);
代码示例来源:origin: com.github.meirfaraj/gcAnalyser-lib
/**
* Gets the preferred size.
*
* @return the preferred size
*/
public Dimension getPreferredSize() {
final Canvas c = new Canvas();
final FontMetrics fm = c.getFontMetrics(this.font);
//System.out.println("longest: " + longestString);
configureFormatter();
final int minWidth = fm.stringWidth(this.longestString) + 5;
Dimension bestSize = null;
if (isVertical()) {
bestSize = new Dimension(minWidth, getHeight());
} else {
bestSize = new Dimension(
(int) (ModelChartImpl.this.runningTime * getScaleFactor()),
fm.getHeight());
this.minHalfDistance = minWidth;
}
//System.out.println("pref: " + bestSize);
return bestSize;
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
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);
}
代码示例来源:origin: blackears/svgSalamander
fm = c.getFontMetrics(sysFont);
代码示例来源:origin: guru.nidi.com.kitfox/svgSalamander
fm = c.getFontMetrics(sysFont);
内容来源于网络,如有侵权,请联系作者删除!