Java的图形:从字体构造的FontMetrics,没有一个Graphics2D [英] Java Graphics: Constructing FontMetrics from Font, without a Graphics2D
问题描述
已知
有从字体
。
的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
fromFont
.Question:
Given a
Font
object, is there a way to construct aFontMetrics
object without going throughGraphics2D.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 theFontMetrics
.解决方案Given a
Font
object, is there a way to construct aFontMetrics
object without going throughGraphics2D.setFont
,Graphics2D.getFontMetric()
?See
BufferedImage.createGraphics()
orgetGraphics()
for an alternative way to get theGraphics
instance.这篇关于Java的图形:从字体构造的FontMetrics,没有一个Graphics2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!