Domanda

I'm using J2ME polish to develop an app on two samsung devices, the app supports arabic language. On Samsung star wifi, the app works fine, but on a device like samsung GT-S3653 all letters appears dis-assembled any help will be highly appreciated Thanks

È stato utile?

Soluzione

I speake farsi and I had the same problem in about 4 years ago.You have some way to solve this problem:
1-using custom fonts.
2-reshape your text before display it.
A good article in about first,is "MIDP Terminal Emulation, Part 3: Custom Fonts for MIDP".But for arabic letters I think that is not simple.
In about second way,say you would to replace any character in your text with correct character.This means when you have:

String str = "به";   

If get str characters they will be look like:
{1576,1607} that is like "ب ه" instead of "به".So you would to replace incorrect Unicode with correct Unicode codes(in this case correct characters are: {65169, 65258}).You can use "Arabic Reshapers" even reshapers that designed for android!I saw 2 link for this reshapers:1-github 2-Arabic Android(I'm persian developer and so i do not try them).With using a good Arabic reshaper also you may have problem with character arranging from left to right instead of right to left.(some phones draw characters from left to right and other from right to left).I use below class to detect that ordering is true(from right to left) or not:

public class DetectOrdering{   
public static boolean hasTrueOrdering()
{
    boolean b = false;
    try {
        char[] chArr = {65169, 65258};
        String str = new String(chArr);
        System.out.println(str);
        int width = f1.charWidth(chArr[1]) / 2;
        int height = f1.getHeight();
        image1 = Image.createImage(width, height);
        image2 = Image.createImage(width, height);
        Graphics g1 = image1.getGraphics();
        Graphics g2 = image2.getGraphics();
        g1.drawString(str, 0, 0, 0);
        g2.drawChar(chArr[1], 0, 0, 0);
        int[] im1 = new int[width * height];
        int[] im2 = new int[width * height];

        image1.getRGB(im1, 0, width, 0, 0, width, height);
        image2.getRGB(im2, 0, width, 0, 0, width, height);
        if (areEqualIntArrrays(im1, im2)) {
            b = true;
        } else {
            b = false;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return b;
}

private static boolean areEqualIntArrrays(int[] i1, int[] i2) {
    if (i1.length != i2.length) {
        return false;
    } else {
        for (int i = 0; i < i1.length; i++) {
            if (i1[i] != i2[i]) {
                return false;
            }
        }
    }
    return true;
}
}    

If DetectOrdering.hasTrueOrdering() returns true,sure that phone draw Arabic characters from right to left and display your String.If returns false it draws from left to right.If phone draws Arabic character from left to right you would to reverse string after reshape it and then you can display it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top