I'm trying to display unicode characters (more specifically emojis) in my android application. Many of the unicode characters from http://apps.timwhitlock.info/emoji/tables/unicode seem to be unsupported by the default android font system.
For example:
myTextView.setText("\u1F602 \u1F603 \u263A");
will only correctly display the last unicode character (\u263A) according to the link above. Like I said, I'm guessing this a result of unsupported unicode characters by the default font. How do I go about supporting those unicode characters with the default android representation? Do I need to choose a new font, and if so, how do I determine if that font supports what I need?
Thanks!
Related
I am using some custom fonts files in my android app. However they do not support some special characters or other letters than latin. How can i check if a passed string includes any characters that are not supported from my custom font? i saw similar question which mainly focus on the emoji support and rendering.
I have ÷ in .txt file in my android. When this division symbol is shown on android device, I see "�"
To make it worse, my laptop doesn't have division sign on keyboard. I used the above sign from wikipedia.
Any guess how can I resolve this.
You should use the Unicode value for any symbols such as the division symbol you have here.
Try the Unicode U00F7.
When using it within a String format like "\u00F7".
The problem is most likely a font issue, or possibly a unicode encoding issue. The character you pasted is unicode codepoint 0xF7: if the font being used to display your text file does not have a specific glyph for this codepoint, then it will render it using some reserved glyph like the question mark diamond you show. The solution in this case would be to install and use a font which includes an appropriate glyph for this codepoint. For instance, if it is displayed correctly in your web browser, then find out what font your browser is using, and try that. Of course, whether or not you can change the font used to display your text file depends on the application (at least I think: I don't think Android fixes the font across all apps).
Alternatively, it could be an encoding problem. For instance, if you're saving your text file in Latin-1 encoding, then this character will be stored in a single byte with value 0xF7. If the app that you're viewing the file with is assuming it's UTF-8, for instance, then this byte will be interpreted as the first of a multi-byte character, or it may even be invalid. If this is the case, you just need to make sure the encoding you use to save the file is the same as the one being used to display the file. Again, this would be application specific.
More specifically if the font is missing the glyphs for a languages characters(double byte characters, etc) does Android default to another font or does it just show the SBOD(square box of death) symbol in place of the character?
I'm also curious how people handle font internationalization when using custom fonts.
I am not sure but I guess the app needs to handle it.Many apps place images of the symbol when its not supported by the font.Google recently launched Noto-https://www.google.com/get/noto/ which is supposed to support most of the languages.
This question already has answers here:
Is there a "glyph not found" character?
(8 answers)
Closed 7 years ago.
On Android, I want to be able to detect if the font used can display a certain character or not, but as I understand it this is not possible with conventional means as indicated by Check if custom font can display character
To detect this I'm writing the character I want to check to a bitmap and then I write another character that I know is missing to another bitmap and compare the content of the bitmaps. If they are equal the character is missing.
The question is, is there any unicode character whose glyph is (more or less) guaranteed to be missing on fonts typically used on Android phones?
The Unicode replacement character sounds promising when reading about it on Wikipedia:
It is used to indicate problems when a system is not able to render a
stream of data to a correct symbol. It is most commonly seen when a
font does not contain a character, but is also seen when the data is
invalid and does not match any character
However after doing a bit of testing I see that this character is not used to represent missing glyphs on either my Windows 7 computer or the Android phone I've tested with (Motorola Atrix).
There isn't any designated Unicode value for the glyph that is used to render glyphs that are missing in the font used. In the actual font, glyph id 0 should always be the .notdef glyph which is used for all characters that are missing a glyph. However it is not possible this information from the fonts on Android, so it's not possible to use the .notdef glyph directly.
In Unicode there are many reserved/unassigned code points and my limited testing indicate that these code points are rendered using the .notdef glyph. So by using U+0978, which is a reserved code point in the middle of the Devanagari block, I can detect if some other valid, known character exists in the font I want to test.
This is not a future proof solution since new glyphs may be added to reserved code points by the Unicode Consortium in the future. But for my needs it's good enough since what I want to do is a temporary thing that is not relevant any more in the near future.
Update:
The solution to look at U+0978 did not work long. That character was added in the Unicode 7.0 release in June 2014. Another option is to use a glyph that exists in unicode but that is very unlikely to be used in a normal font.
U+124AB in the Early Dynastic Cuneiform block is probably something that doesn't exist in many fonts at all.
I am maintaining an Android app that people use to display strings in various exotic languages like Tibetan or old Greek. Because Android devices come with very few fonts, users can put font files on the SD card, and the app will use them.
QUESTION: Given a string, how can I automatically decide which font file is the most appropriate, so that this string appears without characters being replaced with squares/boxes?
Notes:
Each string is in one language.
Strings are displayed in a WebView.
Custom fonts work, the only problem is deciding which font file to use.
Instead of a single font, it could provide a list of fonts that are acceptable for that string.
Unnecessary context, for the curious: I am trying to develop this feature:
http://code.google.com/p/ankidroid/issues/detail?id=779
UPDATE: I ended up creating the Antisquare Open Source library based on Mostafa's idea.
It has a getSuitableFonts method which is blazingly fast.
Android by itself does not provide enough for such a task. Loading and rendering fonts in Android happens in Skia, which is written in C. Skia detects if a character can't be found in a font and falls back to another font for such characters (not the whole string). That's how Japanese, Hebrew, or Arabic text is shown in Android and that's exactly why these scripts don't have bold face! (Their font is selected through fallback and fallback only selects one font file.)
Unfortunately, this mechanism is not provided in APIs and you have to build similar thing on your own. It seems complicated, but is easier than it looks. All you have to do is:
Prepare lists of characters available in each font file.
For every string find the font that has more characters of the string.
Getting list of characters in each font
You don't have to do this on-the-fly in your Android app. You can prepare the list of characters in each font and put these lists in your app. I say that because this is way easier with tools that may not be available in Android. I would do that through Python scripting in a font app (most serious font tools have awesome Python scripting environments), but these apps are expensive and are for serious type designers. Since you're an Android developer, I recommend using sfntly, a library in Java and C++. Doing what you need (getting a list of Unicode characters available in a font file) is easy with sfntly. This sample works with CMap tables (tables that hold character to glyph mapping) and should be a good starting point for you.
Now the interesting part is that snftly is in Java and you may be able to include that in your Android app and do everything automatically. That's awesome by I recommend you start by getting familiar with snftly.
Selecting the font
After the previous part you'll have a list of Unicode character for every font, and based on these lists selecting the font file that provides most characters of every string is trivial.