2012-08-15 35 views
3

我需要在我的应用程序中获取矢量形式(点和曲线)中字母的形状。我可以很容易地获得Font实例,并且看起来GlyphVector类能够给我所需的Shape。但要创建从FontGlyphVector,我需要有一些FontRenderContex是否有可能从字体中获取矢量形式的字符?

我在渲染某些东西时不执行此操作,因此我看不到如何得到那个FontRenderContex。是否可以创建一些默认的FontRenderContex或绕过它?

+1

看起来你可以用'new FontRenderContext(null,false,false)'来创建它。你尝试过吗? – 2012-08-15 13:46:11

+0

@Banthar - 是的,似乎我能从中得到一些有趣的东西。谢谢! – Rogach 2012-08-15 13:49:06

回答

1

您的应用程序中是否有任何扩展Graphics2D?这样,您可以访问getFontRenderContext方法。

我的意思是,你可以使用构造函数中的一个,但我看到这个在文档的FontRenderContext

Typically, instances of FontRenderContext are obtained from a Graphics2D object. 
A FontRenderContext which is directly constructed will most likely not represent 
any actual graphics device, and may lead to unexpected or incorrect results. 
+0

嗯。这是有道理的,但究竟是那些结果呢?我的意思是,我可以忍受小的(半像素)不准确,但如果它会导致奇怪的连接点混乱,那不是我想要的。 – Rogach 2012-08-15 13:57:44

+0

我会想象如果这些不准确性很小,他们会在文档中稍微有点不同。这种措辞让我觉得结果可能会更糟糕。 – 2012-08-15 14:03:03

1

我不知道,如果这个工程,但你可以得到FontRenderContext从来自BufferedImage对象的Graphics2D对象;

BufferedImage img = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g2 = img.getGraphics(); 
FontRenderContext frc = g2.getFontRenderContext(); 
相关问题