Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
898 views
in Technique[技术] by (71.8m points)

macos - Rendering Devanagari ligatures (Unicode) in Java Swing JComponent on Mac OS X

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...