在 Mac OS X 上的 Java Swing JComponent 中呈现梵文连字 (Unicode)
我正在尝试在 Mac OS X 10.6 上正确呈现梵文连字(Unicode 字符串)。
字符串在 JComponent
上绘制,并采用 RenderingHints
进行抗锯齿。连字在 Windows XP SP2 和 7 以及 Ubuntu 中正确显示,但在 Mac OS X 中,连字被分解(或者更确切地说,没有正确合并),变音符号被移离其位置等。(参见下面的屏幕截图,左侧为 Win XP SP2 的正确渲染示例(使用 RenderingHints
抗锯齿键 ON
),右侧为 Mac OS X 10.6.7 的错误渲染示例(抗锯齿 DEFAULT
= OFF
)。
我已将字体设置如下,因此它应该在任何系统上使用默认字体:
new Font(null,Font.PLAIN,20);
我相信这一切可能与默认字体有关。 Mac 上的字符编码是 MacRoman(不是 UTF-8 子集),而其他系统(如 Windows)使用 UTF-8 子集(如 WinLatin-1)或 cp1252 等,
即使手头有这些信息,我'我对如何处理这个问题一无所知。因此,如果有人能够指出正确的方向,我将非常感激
我已经尝试了很多方法:
- 将字体设置为 Devanagari MT 并没有解决问题
TextAttribute
LIGATURES_ON
没有无法解决问题
我将非常感谢其他开发人员(最好具有在 Mac 上开发的印地语背景)的任何提示或代码片段。
I'm trying to get Devanagari ligatures (in Unicode strings) rendered correctly on Mac OS X 10.6.
The strings are drawn on a JComponent
and take RenderingHints
for Antialiasing. The ligatures are displayed correctly in Windows XP SP2 and 7, and Ubuntu, but in Mac OS X, the ligatures are decomposed (or rather, not merged correctly), diacritics are moved away from their positions, etc. (cf. screenshots below, correct rendering example from Win XP SP2 on the left (with RenderingHints
Antialiasing Key ON
), wrong rendering example from Mac OS X 10.6.7 on the right (Antialising DEFAULT
= OFF
).
I have set the font as follows, so it should use a default font on any system:
new Font(null,Font.PLAIN,20);
I believe all this might have something to do with the fact that the default character encoding on Macs is MacRoman (NOT a UTF-8 subset), and that other systems (like Windows) use a UTF-8 subset (such as WinLatin-1) or cp1252 or such.
Even with this information at hand, I'm in the dark about how to handle this problem. Thus I would be very grateful if someone was able to point me in the right direction.
I've tried a number of things already:
- Setting the font to Devanagari MT didn't solve the issue
TextAttribute
LIGATURES_ON
didn't solve the problem
I'd be extremely thankful for any hints, or code snippets by other developers (preferrably with a Hindi background who develop on Mac).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己不是专家,但这里有一些建议。据我从维基百科了解到,问题很可能是你的字体。提前对长引用表示歉意,否则我可以直接链接两篇维基百科文章。
以下是Unicode 文章中有关连字的部分内容:
进一步阅读 AAT(Apple 高级排版) 文章,揭示以下信息。我建议阅读整篇文章。
稍后在有关字体布局的部分中:
最后:
也许您需要选择一种明确支持天城文的字体。
I'm not an expert myself, but here some pointers. As far as I understood from Wikipedia, the problem is very likely to be your font. Apologies in advance for the long quotes, but else I could have just linked the 2 Wikipedia articles.
Here a part of the section about ligatures from the Unicode article:
Reading further in the AAT (Apple Advanced Typography) article, reveals following information. I recommend reading the whole article.
And later down in the section about font layout:
And last:
Maybe you need to choose a font that explicitly supports Devanagari.
这对字形渲染的质量产生了很大的影响。需要先按照此处的建议完成此操作。
您还可以考虑使用
TextLayout< /code>
,因为
FontRenderContext
可以应用RenderingHints.KEY_FRACTIONALMETRICS
。This make a substantial difference in the quality of glyph rendering. It needs to be done first, as suggested here.
You might also look at using
TextLayout
, as theFontRenderContext
can applyRenderingHints.KEY_FRACTIONALMETRICS
.我正在使用 Gurmukhi 脚本进行的项目遇到了完全相同的问题。我现在已经尝试了与 Mac OS X(Gurmukhi MT、Gurmukhi MN)捆绑的 AAT 表字体和 OpenType 表字体。这两种字体在 Mac OS X 上的 JAVA 中都不起作用,但 OpenType 字体的可读性稍好一些。唯一的问题是“halant”字符没有像它应该的那样呈现字符的半形式。
我认为问题在于我们使用的字体及其与 Mac OS X 上的 JAVA 的兼容性。
I'm having this exact same problem with a project I am working on with Gurmukhi script. I've now tried both fonts with AAT tables that come bundles with Mac OS X (Gurmukhi MT, Gurmukhi MN) and fonts with OpenType tables. Neither works in JAVA on Mac OS X, but the OpenType fonts are slightly more readable. The only problem is that the "halant" character doesn't render the half forms of characters like it should.
I think the problem is with the fonts we are using and their compatibility with JAVA on Mac OS X.
当我在 Mac 上尝试泰米尔语 http://jambula.sourceforge.net 时,我遇到了同样的问题。
我想出的解决方法是使用 Font.createFont 加载显式字体。
您可以在以下位置查看测试程序: TestRendering.java
在 text.png 中错误地呈现泰米尔语文本,
但是
正确地呈现它。
这可能是由于 https://bugs.openjdk.java.net/browse/JDK- 7162125。
I faced the same issue when I tried http://jambula.sourceforge.net on Mac for Tamil language.
The workaround I came up with was to use Font.createFont to load an explicit font.
You can see a Test program at: TestRendering.java
renders the Tamil text incorrectly in text.png
However
renders it correctly.
It might be due to https://bugs.openjdk.java.net/browse/JDK-7162125.