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

This make a substantial difference in the quality of glyph rendering. It needs to be done first, as suggested here .

Up vote 20 down vote favorite 2 share g+ share fb share tw.

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. Thanks a lot in advance and please let me know should you need code or any other information. UPDATE 15 June 2011: 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).

I'll set a bounty for this now. UPDATE 22 June 2011: The answer is: use Mac OS X' own Quartz renderer by simply setting the respective System property. You can do this as suggested in trashgod's answer.

Thank you to everyone involved in finally answering this. Java osx unicode rendering ligature link|improve this question edited Jun 22 '11 at 13:49 asked May 13 '11 at 16:16s. D45212 100% accept rate.

3 I don't know about this stuff at all, but looks very interesting and I would like to learn more about it. Can you please post some links? Advance?

! – Bhushan May 13 '11 at 16:27 1 I think you hunch is wrong, but I can’t tell you what the right answer is. CP1252 is no more a UTF-8 subset than is MacRoman; Latin1 is a UTF-8 subset, though.

This very probably has nothing at all to do with Java’s notoriously dumb old broken default 8-bit encoding issue. I would really like to learn it, though. – tchrist May 13 '11 at 22:44 @Bhushan: Thanks for your interest.

I'm afraid I haven't got any helpful links to share. Yet. Once I find something (or get some help here), I'll let everyone know.

@tchrist: Of course you're right about cp1252! I'm not a char encoding expert, though I'm afraid I'll have to be one before soon. Here's the info I've found about character encoding on Mac v Win: Java Devel Guide for OS X.

Thanks for your interest & correction! – s. D May 13 '11 at 23:17 @tchrist again: I've edited the post to more obviously reflect the difference between Latin1 & cp1252.

– s. D May 13 '11 at 23:25 1 Does this text render correctly in non-Java Mac programs? For example, if you paste it in TextEdit.

App, does it look right? (Unfortunately, I know nothing about Devanagari, so I can't easily figure out the characters from your screenshot. ) – Ken May 13 '117 at 4:47.

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.

Although you started your answer with a quote from my own comment (in which I principally answered my own question, haha), this is still the best answer as it was supplied before I could comment that I have solved the problem, and additionally you added value by supplying a piece of code to query for OS, as well as hinting at TextLayout (although it's a bit out of context for my sepcific issue), hence I will award the bounty to you. Thanks! – s.

D Jun 22 '11 at 13:44 Glad it helped. Indeed, without the query, the setting hangs on Windows. – trashgod Jun 22 '11 at 20:52.

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.

Thank you very much for your great research! I thought I had read everything that is to be read on Wikipedia (could be I was stuck with the German pages though). Will follow up on this here once I've tried it.

Might take a couple of days though. – s. D May 17 '11 at 15:49 Update: I've found out that the only font that comes with Mac OS X that has an AAT table and includes Devanagari glyphs is, surprisingly, Devanagari MT.

I will try to set that Font and see what happens. Once my MacBook is delivered. Thanks for all your help!

– s. D May 20 '11 at 17:02 I've just tested it with Devanagari MT (the font that ships with Mac OS X 10.6), and it doesn't work. I'll start to rip my hair out just now then.

Must be a Java rather than a Mac OS X problem after all (or a combination of the two). Thanks for your help, though, much appreciated! – s.

D Jun 15 '11 at 12:38 I'm sorry that it didn't work. Good luck then! Seems, you need it ... :-) – MicSim Jun 15 '11 at 14:26 Thanks a lot.

I've one last clue (using the Quartz renderer instead of the Java 2D renderer), and then I'll just hire someone from India who actually uses Devanagari to solve this for me. – s. D Jun 15 '11 at 14:32.

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.

Try setting the System property for the Quartz renderer to "true", as suggested by myself, trashgod and updated in my original question. I'd be interested in hearing how this works for you. – s.

D Jun 22 '11 at 13:50.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions