在 Mac OS X 上的 Java Swing JComponent 中呈现梵文连字 (Unicode)

发布于 2024-11-07 18:05:01 字数 911 浏览 4 评论 0原文

我正在尝试在 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.

correct and incorrect rendering of the same string

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

喜爱纠缠 2024-11-14 18:05:01

我自己不是专家,但这里有一些建议。据我从维基百科了解到,问题很可能是你的字体。提前对长引用表示歉意,否则我可以直接链接两篇维基百科文章。

以下是Unicode 文章中有关连字的部分内容:

连字

许多文字,包括阿拉伯语和梵文,都有特殊的拼写规则,要求将某些字母形式的组合组合成特殊的连字形式。 管理连字形成的规则可能相当复杂,需要特殊的脚本成形技术,例如 ACE(DecoType 在 20 世纪 80 年代开发的阿拉伯书法引擎,用于生成 Unicode 印刷版中的所有阿拉伯语示例) Standard),它成为 OpenType(由 Adob​​e 和 Microsoft 提供)、Graphite(由 SIL International 提供)或 AAT(由 Apple 提供)的概念证明。

进一步阅读 AAT(Apple 高级排版) 文章,揭示以下信息。我建议阅读整篇文章。

Mac OS X 中的 AAT 和 OpenType

从 Mac OS X 10.5 Leopard 开始,提供了对 OpenType 的部分支持。目前支持仅限于西方文字和阿拉伯语(截至 2011 年)。如果字体具有 AAT 表,它们将用于排版。如果字体没有 AAT 表,但有 OpenType 表,则将在系统支持的范围内使用它们。

这意味着西方或中东文字的许多 OpenType 字体无需修改即可在 Mac OS X 10.5 上使用,但泰语和梵文等南亚文字则不能使用。这些需要 AAT 表进行正确布局。

稍后在有关字体布局的部分中:

由于 AAT 完全使用字形而不是字符来操作,生成正确显示所需的所有布局信息都驻留在字体本身中。这允许为新脚本添加字体,而无需任何特定的操作来自操作系统的支持。

最后:

印度文字的 AAT

对于印度文字,唯一需要的功能是字形重新排序和替换。 AAT 支持这两者。如上所述,印度语脚本的 OpenType 字体需要添加 AAT 表才能在 Mac OS X 上正常运行。但请注意,这仅适用于依赖于 OpenType 系统支持的软件。提供自己的 OpenType 实现的程序将使用 OpenType 字体正确呈现 Indic。 (但是,它们可能无法使用 AAT 表正确呈现印度字体。)​​

Mac OS X 10.5 附带天城文、古尔穆基文、古吉拉特文、泰文、藏文和泰米尔文字体。其他印度文字的字体可从第三方获得。

也许您需要选择一种明确支持天城文的字体。

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:

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).

Reading further in the AAT (Apple Advanced Typography) article, reveals following information. I recommend reading the whole article.

AAT and OpenType in 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.

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.

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.

And last:

AAT for Indic scripts

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.)

Mac OS X 10.5 ships with fonts for Devanagari, Gurmukhi, Gujarati, Thai, Tibetan, and Tamil. Fonts for other Indic scripts are available from third parties.

Maybe you need to choose a font that explicitly supports Devanagari.

孤君无依 2024-11-14 18:05:01

使用 Quartz 渲染器而不是 Java 2D 渲染器。

这对字形渲染的质量产生了很大的影响。需要先按照此处的建议完成此操作。

if (System.getProperty("os.name").startsWith("Mac OS X")) {
    System.setProperty("apple.awt.graphics.UseQuartz", "true");
}

您还可以考虑使用 TextLayout< /code>,因为 FontRenderContext 可以应用 RenderingHints.KEY_FRACTIONALMETRICS

Using the Quartz renderer instead of the Java 2D renderer.

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.

岁月打碎记忆 2024-11-14 18:05:01

我正在使用 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.

时光病人 2024-11-14 18:05:01

当我在 Mac 上尝试泰米尔语 http://jambula.sourceforge.net 时,我遇到了同样的问题。

我想出的解决方法是使用 Font.createFont 加载显式字体。

您可以在以下位置查看测试程序: TestRendering.java

java org.jambula.image.TestRendering text.png

在 text.png 中错误地呈现泰米尔语文本,

但是

java org.jambula.image.TestRendering text.png "/Library/Fonts/Arial Unicode.ttf"

正确地呈现它。

这可能是由于 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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文