BlackBerry - Unicode text display

社会主义新天地 提交于 2019-12-02 15:19:50

问题


I would like to display some Arabic text into LabelField in j2me app on BlackBerry device. Presume that Arabic font is installed on device.

In localization resources, if Arabic locale is used, all text is saved in Unicode sequences. But event if I use such format explicitly, also setting Arabic locale, it's not working:

    Locale.setDefault(Locale.get(Locale.LOCALE_ar, null));
    add(new LabelField("\u0627\u0644\u0639\u0631\u0628\u064A\u0629"));

Please advice:

  • In what format or code page I should save Arabic text?
  • How to display Arabic text in Label using installed Arabic font?

Thank you!


回答1:


Solution is to pass Unicode sequence as a char array:

char[] text = new char[] {'\u0627', '\u0644', '\u0639', 
    '\u0631', '\u0628', '\u064A', '\u0629'};
add(new LabelField(text));

So to display Unicode sequence kept in String, we need to parse this String into chars:

private char[] getUnicodeChars(String string) {
    char[] result = new char[] {};
    String[] charCodes = split(string, "\\");
    result = new char[charCodes.length];
    for (int i = 0; i < charCodes.length; i++) {
        result[i] = (char) Integer.parseInt(charCodes[i].substring(1), 16);
    }
    return result;
}

And somewhere in code:

String txt = "\u0627\u0644\u0639\u0631\u0628\u064A\u0629";
add(new LabelField(getUnicodeChars(txt)));

And there is no need to switch Locale. Of course Arabic font should be installed.




回答2:


I'm displaying the Japanese Yen symbol on the device without having the device locale set to Japanese, simply by passing the string the unicode representation (as you do in your sample) and the j2me handles the rest. However, I'm not sure in such a situation the orientation will be right to left.

By default the device does not have the Arabic font, are you sure it is installed on the device? When you do:

Locale.get(Locale.LOCALE_ar, null)

Do you get back null or a locale value?

CORRECTION: The Yen symbol is not in unicode value but simply as clear text (I get it from the server). If you store the original string in Arabic in the resources (instead of the unicode), what does it show? Notice: putting the clear text in the code doesn't work.



来源:https://stackoverflow.com/questions/1928888/blackberry-unicode-text-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!