Java的图形:从字体构造的FontMetrics,没有一个Graphics2D [英] Java Graphics: Constructing FontMetrics from Font, without a Graphics2D

查看:367
本文介绍了Java的图形:从字体构造的FontMetrics,没有一个Graphics2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已知

的FontMetrics

有从字体

的FontMetrics 受保护的构造

问:

给定一个字体对象,有没有办法来构造一个的FontMetrics 对象,而无需通过<$ C $打算C> Graphics2D.setFont , Graphics2D.getFontMetric()

上下文

我在玩像渲染算法的TeX。我需要计算边框和放大器;这样的用于从* .PFB文件的各种字符。我可以构建从* .PFB文件中的字体对象。我需要一个的FontMetrics 对象来获取上升,下降幅度。它只是似乎非常难看,让我有构建一个未使用的中间Graphics对象只是为了获得在的FontMetrics


解决方案

  

给定一个字体对象,有没有办法来构造一个的FontMetrics 对象,而无需通过<$ C $打算C> Graphics2D.setFont , Graphics2D.getFontMetric()


请参阅 BufferedImage.createGraphics() 或的 的getGraphics() 一个替代的方式来获得在图形实例。

Known

Given FontMetrics

There is a protected constructor for FontMetrics from Font.

Question:

Given a Font object, is there a way to construct a FontMetrics object without going through Graphics2D.setFont, Graphics2D.getFontMetric()?

Context

I'm playing with a TeX like rendering algorithm. I need to calculate bounding boxes & the such for various characters from a *.pfb file. I can construct a Font object from the *.pfb file. I need a FontMetrics object to get the ascent, descent, width. It just seems very ugly for me to have to construct an unused intermediate Graphics object just to get at the FontMetrics.

解决方案

Given a Font object, is there a way to construct a FontMetrics object without going through Graphics2D.setFont, Graphics2D.getFontMetric()?

See BufferedImage.createGraphics() or getGraphics() for an alternative way to get the Graphics instance.

这篇关于Java的图形:从字体构造的FontMetrics,没有一个Graphics2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆