背景知识很少..
我正在使用 Java 和 LWJGL。 我编写了一个 TextRenderer
类,它使用缓存的字形页面呈现文本。 字形本身在 Java2D 中渲染为 BufferedImage,并与字形测量值一起打包到纹理页面中。 TextRenderer
使用缓存的信息将字符绘制为纹理四边形。
所有这些都运行良好,除了一件事:缺少字距调整。 当然,没有必要,因为文本看起来不错,但如果我能够访问字体字距调整信息,它会提高质量。
问题是..
是否可以使用纯 Java 获取字距调整信息,并以可跨 Windows、Linux 和 MacOS X 移植的方式? 当我编写 TextRenderer
时,我简单地环顾四周,但找不到这样的方法。
一种可能的解决方案
如果没有办法用纯 Java 来做到这一点,我正在考虑使用编写一个单独的工具Freetype。 正如其功能页面所列:
FreeType 2 提供的信息
通常无法从其他地方获得
类似的字体引擎,例如字距调整
距离、字形名称、垂直
指标等
该工具会将常见字符的字距调整对存储到一个文件中,我的文本渲染器将加载并使用该文件 所以如果你们没有提出更好的选择,这可能就是我会做的。 :)
Little background..
I'm in the process of making an OpenGL game using Java and LWJGL. I've written a TextRenderer
-class that renders text using cached pages of glyphs. The glyphs itself are rendered in Java2D to BufferedImage
s and packed into texture pages along with the glyph measurements. TextRenderer
draws the characters as textured quads, using the cached information.
All this works well, except for one thing: missing kerning. Granted, it's not necessary to have as the text looks fine as it is, but it would improve the quality if I had access to the font kerning information.
And the question is..
Is it possible to obtain the kerning information using plain Java, in a way that would be portable across Windows, Linux and MacOS X? Back when I wrote the TextRenderer
I briefly looked around but could not find such a way..
One possible solution
If there is no way of doing this in pure Java, I was thinking of writing a separate tool using Freetype. As listed in their features page:
FreeType 2 provides information that
is often not available from other
similar font engines, like kerning
distances, glyph names, vertical
metrics, etc.
The tool would store the kerning pairs for common characters into a file that my text renderer would load in and make use of. So this is probably what I will do if you guys don't come up with a better alternative. :)
发布评论
评论(2)
从 Java SE 6 开始,Java 可以在字体提供字距调整信息时提供该信息。 默认情况下它是关闭的,可以像这样打开:
此论坛线程包含有关该主题的更详细的讨论:
http://forums.sun.com/thread.jspa?threadID=5359127
Starting with Java SE 6, Java can provide kerning information when the font provides it. It is off by default and can be turned on like this:
This forum thread contains a more detailed discussion on the topic:
http://forums.sun.com/thread.jspa?threadID=5359127
我所知道的唯一能够正确读取字距调整信息“somwhat”的库是 iText 和 FOP。
http://www.1t3xt.info/api/com/ lowagie/text/pdf/BaseFont.html
http:// /svn.apache.org/viewvc/xmlgraphics/fop/tags/fop-0_95/src/java/org/apache/fop/fonts/ (指向 svn 的链接,因为似乎没有在线 api)
The only libraries I know of that read the kerning info "somwhat" correctly are iText and FOP from Apache.
http://www.1t3xt.info/api/com/lowagie/text/pdf/BaseFont.html
http://svn.apache.org/viewvc/xmlgraphics/fop/tags/fop-0_95/src/java/org/apache/fop/fonts/ (a link to the svn as there seems to be no online api)