java.awt.Canvas.getFontMetrics()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中java.awt.Canvas.getFontMetrics()方法的一些代码示例,展示了Canvas.getFontMetrics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Canvas.getFontMetrics()方法的具体详情如下:
包路径:java.awt.Canvas
类名称:Canvas
方法名:getFontMetrics

Canvas.getFontMetrics介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. public static FontMetrics getFontMetrics(Font font){
  2. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  3. GraphicsDevice gd = ge.getDefaultScreenDevice();
  4. GraphicsConfiguration config = gd.getDefaultConfiguration();
  5. Canvas c = new Canvas(config);
  6. return c.getFontMetrics(font);
  7. }

代码示例来源:origin: org.geoserver/gs-wms

  1. @Override
  2. public FontMetrics getFontMetrics(Font f) {
  3. // works also in headless mode
  4. return new Canvas().getFontMetrics(f);
  5. }

代码示例来源:origin: org.databene/databene-commons

  1. public TextIcon(String text, Color foreground, Color background, boolean square, Font font) {
  2. this.text = text;
  3. this.font = font;
  4. FontMetrics metrics = new Canvas().getFontMetrics(font);
  5. this.textWidth = metrics.stringWidth(text);
  6. this.iconWidth = textWidth;
  7. this.iconHeight = font.getSize() + 2;
  8. if (square) {
  9. this.iconWidth = Math.max(this.iconWidth, this.iconHeight);
  10. this.iconHeight = this.iconWidth;
  11. }
  12. this.ascent = metrics.getAscent();
  13. this.foreground = foreground;
  14. this.background = background;
  15. }

代码示例来源:origin: cpesch/RouteConverter

  1. private float getPreferredAlignmentY() {
  2. Font font = getFont();
  3. // deprecated: FontMetrics fm = getToolkit().getFontMetrics(font);
  4. FontMetrics fm = new Canvas().getFontMetrics(font);
  5. float h = fm.getHeight();
  6. float d = fm.getDescent();
  7. return (h - d) / h;
  8. }

代码示例来源:origin: org.databene/databene-commons

  1. public TextOverlayIcon(Icon background, String text, Color color, Font font) {
  2. this.background = background;
  3. this.text = text;
  4. this.color = color;
  5. this.font = font;
  6. this.metrics = new Canvas().getFontMetrics(font);
  7. int textWidth = metrics.stringWidth(text);
  8. int iconWidth = background.getIconWidth();
  9. setIconWidth(Math.max(textWidth, iconWidth));
  10. int textHeight = font.getSize();
  11. int iconHeight = background.getIconHeight();
  12. setIconHeight(Math.max(textHeight, iconHeight));
  13. }

代码示例来源:origin: jenkinsci/embeddable-build-status-plugin

  1. public int measureText(String text) throws IOException {
  2. if (baseUrl != null) {
  3. URL fontURL = new URL(baseUrl, "fonts/verdana.ttf");
  4. InputStream fontStream = fontURL.openStream();
  5. Font defaultFont = null;
  6. try {
  7. defaultFont = Font.createFont(Font.TRUETYPE_FONT, fontStream);
  8. } catch (FontFormatException e) {
  9. throw new IOException(e.getMessage());
  10. }
  11. defaultFont = defaultFont.deriveFont(11f);
  12. Canvas canvas = new Canvas();
  13. FontMetrics fontMetrics = canvas.getFontMetrics(defaultFont);
  14. return fontMetrics.stringWidth(text);
  15. }
  16. return 0;
  17. }

代码示例来源:origin: yannickcr/jenkins-status-badges-plugin

  1. public int measureText( String text )
  2. throws FontFormatException, IOException
  3. {
  4. URL fontURL =
  5. new URL( Jenkins.getInstance().pluginManager.getPlugin( "status-badges" ).baseResourceURL,
  6. "fonts/verdana.ttf" );
  7. InputStream fontStream = fontURL.openStream();
  8. Font defaultFont = Font.createFont( Font.TRUETYPE_FONT, fontStream );
  9. defaultFont = defaultFont.deriveFont( 11f );
  10. Canvas canvas = new Canvas();
  11. FontMetrics fontMetrics = canvas.getFontMetrics( defaultFont );
  12. return fontMetrics.stringWidth( text );
  13. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }
  10. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  7. Scalr.OP_ANTIALIAS);
  8. return new ImageIcon(scaledImage);
  9. }

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

  1. FontMetrics metrics = canvas.getFontMetrics(font);

代码示例来源:origin: com.github.meirfaraj/gcAnalyser-lib

  1. /**
  2. * Gets the preferred size.
  3. *
  4. * @return the preferred size
  5. */
  6. public Dimension getPreferredSize() {
  7. final Canvas c = new Canvas();
  8. final FontMetrics fm = c.getFontMetrics(this.font);
  9. //System.out.println("longest: " + longestString);
  10. configureFormatter();
  11. final int minWidth = fm.stringWidth(this.longestString) + 5;
  12. Dimension bestSize = null;
  13. if (isVertical()) {
  14. bestSize = new Dimension(minWidth, getHeight());
  15. } else {
  16. bestSize = new Dimension(
  17. (int) (ModelChartImpl.this.runningTime * getScaleFactor()),
  18. fm.getHeight());
  19. this.minHalfDistance = minWidth;
  20. }
  21. //System.out.println("pref: " + bestSize);
  22. return bestSize;
  23. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(new JPanel().getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage;
  7. if (!scraper.isEnabled()) {
  8. scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  9. Scalr.OP_GRAYSCALE);
  10. }
  11. else {
  12. scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  13. Scalr.OP_ANTIALIAS);
  14. }
  15. return new ImageIcon(scaledImage);
  16. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private ImageIcon getScaledIcon(ImageIcon original) {
  2. Canvas c = new Canvas();
  3. FontMetrics fm = c.getFontMetrics(new JPanel().getFont());
  4. int height = (int) (fm.getHeight() * 2f);
  5. int width = original.getIconWidth() / original.getIconHeight() * height;
  6. BufferedImage scaledImage;
  7. if (!scraper.isEnabled()) {
  8. scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  9. Scalr.OP_GRAYSCALE);
  10. }
  11. else {
  12. scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
  13. Scalr.OP_ANTIALIAS);
  14. }
  15. return new ImageIcon(scaledImage);
  16. }

代码示例来源:origin: blackears/svgSalamander

  1. fm = c.getFontMetrics(sysFont);

代码示例来源:origin: guru.nidi.com.kitfox/svgSalamander

  1. fm = c.getFontMetrics(sysFont);

相关文章