I'm trying to get Devanagari ligatures (in Unicode strings) rendered correctly on Mac OS X 10.6.
我正在尝试在Mac OS X 10.6上正确地呈现Devanagari连接(在Unicode字符串中)。
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
).
字符串被绘制在一个JComponent上,并使用RenderingHints进行反锯齿。正确显示绑扎在Windows XP SP2和7,和Ubuntu,但在Mac OS X,绳索是分解(或者说,无法正确合并),变音符号离开他们的岗位,等等。(参看截图,左边正确呈现赢得XP SP2的例子(RenderingHints抗锯齿键),错误的呈现例子Mac OS 10.6.7右边(Antialising默认=)。
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.
我相信所有这些都可能与mac上的默认字符编码是MacRoman(不是UTF-8子集)有关,而其他系统(如Windows)使用UTF-8子集(如WinLatin-1)或cp1252之类的。
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
- 将字体设置为Devanagari MT并没有解决问题。
-
TextAttribute
LIGATURES_ON
didn't solve the problem - TextAttribute LIGATURES_ON并没有解决这个问题。
I'd be extremely thankful for any hints, or code snippets by other developers (preferrably with a Hindi background who develop on Mac).
我非常感谢任何提示,或者其他开发人员的代码片段(更喜欢在Mac上开发的印地语背景)。
4 个解决方案
#1
3
Using the Quartz renderer instead of the Java 2D renderer.
使用石英渲染器而不是Java 2D渲染器。
This make a substantial difference in the quality of glyph rendering. It needs to be done first, as suggested here.
这对雕文渲染的质量有很大的影响。正如这里所建议的,它需要首先完成。
if (System.getProperty("os.name").startsWith("Mac OS X")) {
System.setProperty("apple.awt.graphics.UseQuartz", "true");
}
You might also look at using TextLayout
, as the FontRenderContext
can apply RenderingHints.KEY_FRACTIONALMETRICS
.
您还可以使用TextLayout,因为FontRenderContext可以应用RenderingHints.KEY_FRACTIONALMETRICS。
#2
6
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:
这里是关于Unicode文章中关于结扎的部分的一部分:
Ligatures
绑扎
Many scripts, including Arabic and Devanagari, have special orthographic rules that require certain combinations of letterforms to be combined into special ligature forms. The rules governing ligature formation can be quite complex, requiring special script-shaping technologies such as ACE (Arabic Calligraphic Engine by DecoType in the 1980s and used to generate all the Arabic examples in the printed editions of the Unicode Standard), which became the proof of concept for OpenType (by Adobe and Microsoft), Graphite (by SIL International), or AAT (by Apple).
许多脚本,包括阿拉伯语和Devanagari,都有特殊的拼写规则,要求将字母组合的某些组合组合成特殊的结扎形式。结扎形成规则可能相当复杂,需要特殊script-shaping技术如ACE(阿拉伯语DecoType书法引擎在1980年代和用于生成所有的阿拉伯语例子印刷版本的Unicode标准),这成为OpenType的概念证明(由Adobe和微软),石墨(SIL International),或AAT(苹果)。
Reading further in the AAT (Apple Advanced Typography) article, reveals following information. I recommend reading the whole article.
在AAT(苹果高级排版)文章中进一步阅读,揭示以下信息。我推荐阅读整篇文章。
AAT and OpenType in Mac OS X
AAT和OpenType在Mac OS X。
As of Mac OS X 10.5 Leopard, partial support for OpenType is available. The support is currently limited to Western scripts and Arabic (as of 2011). If a font has AAT tables, they will be used for typography. If the font does not have AAT tables but does have OpenType tables, they will be used to the extent that the system supports them.
在Mac OS X 10.5 Leopard中,OpenType的部分支持是可用的。目前的支持仅限于西方脚本和阿拉伯语(截至2011年)。如果字体有AAT表,它们将被用于排版。如果字体没有AAT表,但是有OpenType表,那么它们将被用于系统支持它们的程度。
This means that many OpenType fonts for Western or Middle Eastern scripts can be used without modification on Mac OS X 10.5, but South Asian scripts such as Thai and Devanagari cannot. These require AAT tables for proper layout.
这意味着,在Mac OS X 10.5上,可以不修改任何针对西方或中东脚本的OpenType字体,但是像泰国和Devanagari这样的南亚脚本不能。这些需要AAT表的适当布局。
And later down in the section about font layout:
接下来是关于字体布局的部分:
Since AAT operates entirely with glyphs and never with characters, all the layout information necessary for producing the proper display resides within the font itself. This allows fonts to be added for new scripts without requiring any specific support from the OS.
由于AAT完全使用符号,且从不使用字符,因此产生适当显示所需的所有布局信息都位于字体本身内。这允许为新脚本添加字体,而不需要操作系统的任何特定支持。
And last:
最后:
AAT for Indic scripts
AAT的印度脚本
For Indic scripts, the only features that are necessary are glyph re-ordering and substitution. AAT supports both of these. As noted above, OpenType fonts for Indic scripts require AAT tables to be added before they will function properly on Mac OS X. Note, however, that this applies only to software dependent upon the system support of OpenType. Programs which provide their own implementation of OpenType will render Indic properly with OpenType fonts. (They may, however, not render Indic fonts with AAT tables correctly.)
对于Indic脚本,唯一需要的特性是符号重新排序和替换。AAT支持这两种方法。如上所述,Indic脚本的OpenType字体需要在Mac OS x上正确运行之前添加AAT表,但是,这只适用于依赖OpenType系统支持的软件。提供自己的OpenType实现的程序将正确地使用OpenType字体。(然而,他们可能不会正确地使用AAT表呈现独立字体。)
Mac OS X 10.5 ships with fonts for Devanagari, Gurmukhi, Gujarati, Thai, *, and Tamil. Fonts for other Indic scripts are available from third parties.
Mac OS X 10.5船用字体为Devanagari, Gurmukhi, Gujarati, Thai,藏文,和泰米尔语。其他Indic脚本的字体可供第三方使用。
Maybe you need to choose a font that explicitly supports Devanagari.
也许您需要选择一个显式支持Devanagari的字体。
#3
1
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.
我在一个项目中遇到了同样的问题,我正在和Gurmukhi脚本一起工作。我现在已经尝试了两种字体,都是用Mac OS X (Gurmukhi MT, Gurmukhi MN)和OpenType表的字体。在Mac OS X上,这两种方法都不适用,但OpenType字体可读性稍强一些。唯一的问题是,“halant”字符并不会呈现像它应该那样的半形式字符。
I think the problem is with the fonts we are using and their compatibility with JAVA on Mac OS X.
我认为问题在于我们正在使用的字体以及它们在Mac OS X上与JAVA的兼容性。
#4
0
I faced the same issue when I tried http://jambula.sourceforge.net on Mac for Tamil language.
当我在Mac上尝试使用泰米尔语时,我遇到了同样的问题。
The workaround I came up with was to use Font.createFont to load an explicit font.
我想出的办法是使用字体。createFont加载显式字体。
You can see a Test program at: TestRendering.java
您可以看到一个测试程序:teforce .java。
java org.jambula.image.TestRendering text.png
renders the Tamil text incorrectly in text.png
在文本中不正确地呈现泰米尔语。
However
然而
java org.jambula.image.TestRendering text.png "/Library/Fonts/Arial Unicode.ttf"
renders it correctly.
使它正确。
It might be due to https://bugs.openjdk.java.net/browse/JDK-7162125.
它可能是由于https://bugs.openjdk.java.net/browse/jdk7162125。
#1
3
Using the Quartz renderer instead of the Java 2D renderer.
使用石英渲染器而不是Java 2D渲染器。
This make a substantial difference in the quality of glyph rendering. It needs to be done first, as suggested here.
这对雕文渲染的质量有很大的影响。正如这里所建议的,它需要首先完成。
if (System.getProperty("os.name").startsWith("Mac OS X")) {
System.setProperty("apple.awt.graphics.UseQuartz", "true");
}
You might also look at using TextLayout
, as the FontRenderContext
can apply RenderingHints.KEY_FRACTIONALMETRICS
.
您还可以使用TextLayout,因为FontRenderContext可以应用RenderingHints.KEY_FRACTIONALMETRICS。
#2
6
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:
这里是关于Unicode文章中关于结扎的部分的一部分:
Ligatures
绑扎
Many scripts, including Arabic and Devanagari, have special orthographic rules that require certain combinations of letterforms to be combined into special ligature forms. The rules governing ligature formation can be quite complex, requiring special script-shaping technologies such as ACE (Arabic Calligraphic Engine by DecoType in the 1980s and used to generate all the Arabic examples in the printed editions of the Unicode Standard), which became the proof of concept for OpenType (by Adobe and Microsoft), Graphite (by SIL International), or AAT (by Apple).
许多脚本,包括阿拉伯语和Devanagari,都有特殊的拼写规则,要求将字母组合的某些组合组合成特殊的结扎形式。结扎形成规则可能相当复杂,需要特殊script-shaping技术如ACE(阿拉伯语DecoType书法引擎在1980年代和用于生成所有的阿拉伯语例子印刷版本的Unicode标准),这成为OpenType的概念证明(由Adobe和微软),石墨(SIL International),或AAT(苹果)。
Reading further in the AAT (Apple Advanced Typography) article, reveals following information. I recommend reading the whole article.
在AAT(苹果高级排版)文章中进一步阅读,揭示以下信息。我推荐阅读整篇文章。
AAT and OpenType in Mac OS X
AAT和OpenType在Mac OS X。
As of Mac OS X 10.5 Leopard, partial support for OpenType is available. The support is currently limited to Western scripts and Arabic (as of 2011). If a font has AAT tables, they will be used for typography. If the font does not have AAT tables but does have OpenType tables, they will be used to the extent that the system supports them.
在Mac OS X 10.5 Leopard中,OpenType的部分支持是可用的。目前的支持仅限于西方脚本和阿拉伯语(截至2011年)。如果字体有AAT表,它们将被用于排版。如果字体没有AAT表,但是有OpenType表,那么它们将被用于系统支持它们的程度。
This means that many OpenType fonts for Western or Middle Eastern scripts can be used without modification on Mac OS X 10.5, but South Asian scripts such as Thai and Devanagari cannot. These require AAT tables for proper layout.
这意味着,在Mac OS X 10.5上,可以不修改任何针对西方或中东脚本的OpenType字体,但是像泰国和Devanagari这样的南亚脚本不能。这些需要AAT表的适当布局。
And later down in the section about font layout:
接下来是关于字体布局的部分:
Since AAT operates entirely with glyphs and never with characters, all the layout information necessary for producing the proper display resides within the font itself. This allows fonts to be added for new scripts without requiring any specific support from the OS.
由于AAT完全使用符号,且从不使用字符,因此产生适当显示所需的所有布局信息都位于字体本身内。这允许为新脚本添加字体,而不需要操作系统的任何特定支持。
And last:
最后:
AAT for Indic scripts
AAT的印度脚本
For Indic scripts, the only features that are necessary are glyph re-ordering and substitution. AAT supports both of these. As noted above, OpenType fonts for Indic scripts require AAT tables to be added before they will function properly on Mac OS X. Note, however, that this applies only to software dependent upon the system support of OpenType. Programs which provide their own implementation of OpenType will render Indic properly with OpenType fonts. (They may, however, not render Indic fonts with AAT tables correctly.)
对于Indic脚本,唯一需要的特性是符号重新排序和替换。AAT支持这两种方法。如上所述,Indic脚本的OpenType字体需要在Mac OS x上正确运行之前添加AAT表,但是,这只适用于依赖OpenType系统支持的软件。提供自己的OpenType实现的程序将正确地使用OpenType字体。(然而,他们可能不会正确地使用AAT表呈现独立字体。)
Mac OS X 10.5 ships with fonts for Devanagari, Gurmukhi, Gujarati, Thai, *, and Tamil. Fonts for other Indic scripts are available from third parties.
Mac OS X 10.5船用字体为Devanagari, Gurmukhi, Gujarati, Thai,藏文,和泰米尔语。其他Indic脚本的字体可供第三方使用。
Maybe you need to choose a font that explicitly supports Devanagari.
也许您需要选择一个显式支持Devanagari的字体。
#3
1
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.
我在一个项目中遇到了同样的问题,我正在和Gurmukhi脚本一起工作。我现在已经尝试了两种字体,都是用Mac OS X (Gurmukhi MT, Gurmukhi MN)和OpenType表的字体。在Mac OS X上,这两种方法都不适用,但OpenType字体可读性稍强一些。唯一的问题是,“halant”字符并不会呈现像它应该那样的半形式字符。
I think the problem is with the fonts we are using and their compatibility with JAVA on Mac OS X.
我认为问题在于我们正在使用的字体以及它们在Mac OS X上与JAVA的兼容性。
#4
0
I faced the same issue when I tried http://jambula.sourceforge.net on Mac for Tamil language.
当我在Mac上尝试使用泰米尔语时,我遇到了同样的问题。
The workaround I came up with was to use Font.createFont to load an explicit font.
我想出的办法是使用字体。createFont加载显式字体。
You can see a Test program at: TestRendering.java
您可以看到一个测试程序:teforce .java。
java org.jambula.image.TestRendering text.png
renders the Tamil text incorrectly in text.png
在文本中不正确地呈现泰米尔语。
However
然而
java org.jambula.image.TestRendering text.png "/Library/Fonts/Arial Unicode.ttf"
renders it correctly.
使它正确。
It might be due to https://bugs.openjdk.java.net/browse/JDK-7162125.
它可能是由于https://bugs.openjdk.java.net/browse/jdk7162125。