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:
TextAttribute
LIGATURES_ON
didn't solve the problemI'd be extremely thankful for any hints, or code snippets by other developers (preferrably with a Hindi background who develop on Mac).
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.
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With