Question

I discovered today that Android can't display a small handful of Japanese characters that I'm using in my Japanese-English dictionary app.

The problem comes when I attempt to display the character via TextView.setText(). All of the characters below show up as blank when I attempt to display them in a TextView. It doesn't appear to be an issue with encoding, though - I'm storing the characters in a SQLite database and have verified that Android can understand the characters. Casting the characters to (int) retrieves proper Unicode decimal escapes for all but one of the characters:

String component = cursor.getString(cursor.getColumnIndex("component"));
Log.i("CursorAdapterGridComponents", "Character Code: " + (int) component.charAt(0) + "(" + component + ")");

I had to use Character.codePointAt() to get the decimal escape for the one problematic character:

int codePoint = Character.codePointAt(component, 0);

I don't think I'm doing anything wrong, and as String's are by default UTF-16 encoded, there should be nothing preventing them from displaying the characters.

Below are all of the decimal escapes for the seven problematic characters:

  1. ⺅ Character Code: 11909(⺅)
  2. ⺌ Character Code: 11916(⺌)
  3. ⺾ Character Code: 11966(⺾)
  4. ⻏ Character Code: 11983(⻏)
  5. ⻖ Character Code: 11990(⻖)
  6. ⺹ Character Code: 11961(⺹)
  7. 𠆢 Character Code: 131490(𠆢)

Plugging the first six values into http://unicode-table.com/en/ revealed their corresponding Unicode numbers, so I have no doubt that they're valid UTF-8 characters.

The seventh character could only be retrieved from a table of UTF-16 characters: http://www.fileformat.info/info/unicode/char/201a2/browsertest.htm. I could not use its 5-character Unicode number in setText() (as in "\u201a2") because, as I discovered earlier today, Android has no support for Unicode strings past 0xFFFF. As a result, the string was evaluated as "\u201a" + "2". That still doesn't explain why the first six characters won't show up.

What are my options at this point? My first instinct is to just make graphics out of the problematic characters, but Android's highly variable DPI environment makes this a challenging proposition. Is using another font in my app an option? Aside from that, I really have no idea how to proceed.

Was it helpful?

Solution

Is using another font in my app an option?

Sure. Find a font that you are licensed to distribute with your app and has these characters. Package the font in your assets/ directory. Create a Typeface object for that font face. Apply that font to necessary widgets using setTypeface() on TextView.

Here is a sample application demonstrating applying a custom font to a TextView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top