Java - Arabic characters not displaying correctly

2k views Asked by At

In Arabic, letters take different forms depending on where they are to form combined words (similar to cursive). However, Java is displaying some words improperly. They seem to take the correct form but are not combined correctly. Here is the result of a JOptionPane.showMessageDialog

[1] (Edit: Link below, low rep doesn't let me add pics)

Those letters are M-S-J-D written left to right - and note the last two J and D did in fact combin ۔م س ج د

Here is the correct formation when written in NotePad with the Urdu Typesetting font (which is the same font I am using in my program )۔

[2] (Edit: Link below)

At first I thought it was because the letters from my keyboard were different than the unicode (\uXXXX) escape commands; especially since you can see the letters from each don't take exactly the same shape if they were to be combined. I used my keyboard's Urdu setting to type in NotePad where that doesn't work in JCreator; I was using the escape commands.

However I looked up the unicode for keyboard's Urdu setting and they were exactly the same as the codes I was using in JCreator. I then tried using Netbeans because it encodes in UTF-8 (JCreator uses Cp1252), this time I typed the letters directly into the code instead of using the escape command and got exactly the same result in the first image above.

Not all words have this behavior either. Baba ب ا ب ا combines correctly.

Why isn't Java combining these words correctly and how can I fix it? Thanks in advance!

[1] https://i.stack.imgur.com/HEj9y.png [2] https://i.stack.imgur.com/TOUPF.png

Edit: Oh and here is the string, and code I used to set the font as well:

javax.swing.UIManager.put("OptionPane.messageFont", new Font("Urdu Typesetting", Font.PLAIN, 60));
JOptionPane.showMessageDialog(null,"\n\u0645\u0633\u062C\u062F");
1

There are 1 answers

3
Developer Marius Žilėnas On

I don't know arabic :) though on my pc the code

import java.awt.Font;
import javax.swing.JOptionPane;

public class TestArabic
{

    public static void main(String[] args)
    {
        javax.swing.UIManager.put("OptionPane.messageFont", new Font("Urdu Typesetting", Font.PLAIN, 60));
        JOptionPane.showMessageDialog(null,"\n\u0645\u0633\u062C\u062F");
    }    
}

produces following results enter image description here

Let's see what it produces on arabic keyboard for m s j d enter image description here and for msjd it is enter image description here. It is the same as from JOptionPane.showMessageDialog.