Android: Display Special Characters - android

I would like to display special characters such as: ṁ ṭ m ē. In case they don't display here as well, this is how the four characters should look like:
In Android, these will display in squares. For other scripts, I am able to come over this problem with using a different font. But in this case setting the font (TextView.setTypeFace) will not solve this issue. These characters display correctly in for example OpenOffice (using Arial or Courier New), but inside Android it doesn't even when using the same fonts).
I also tried having the string saved as a unicode encoded string (e.g. in strings.xml: \u1E41 \u1E6D) getting the same result (in the logs they appear as they should). Any ideas?

If these characters are representable in Unicode, then you should be able to use Html.fromHtml() to get the glyph into a TextView, e.g.
textView.setText(Html.fromHtml("Ӓ"), TextView.BufferType.SPANNABLE);

It was really only a font issue. It was just hard to find a font that supports all characters I need.
Seeing that Google Translate has no problems with transliteration characters motivated me to make a more thorough search for fonts. Below is a list of useful fonts for this purpose:
http://guindo.pntic.mec.es/jmag0042/alphaeng.html (extensive but non-free)
http://users.teilar.gr/~g1951d/
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=FontDownloads
http://www.mufi.info/fonts/

Related

Apply two custom fonts in a paragraph and display them in android

The project I worked on has some rare characters that are not supported by Unicode
"private-use area" (PUA) code points in the range U+EE80 through U+EFF. One custom open type font range from U+0000 to U+FFFF and the other has characters beyond U+FFFF. Both fonts are in the same language.
I need to display the characters based on their PUA range(characters are retrieved from database in random lines, no fixed location for a particular character). I tried different solutions but none of them works(bidi class with typeface, composite fonts, merging fonts, fallback, etc).
Has somebody used custom fonts that can display different font based on their range of PUA code points(character by character) on Android?
If you are using java to develop your android app, java only support unicode system so you cannot use characters beyond unicode system.

Detect if a unicode character is supported?

I'm trying to put together a small android app that can randomly return an emoji to the user. My intention is to just use actual unicode emoji characters, and return them as unicode string characters.
I built a full array of unicode strings that could be randomly chosen from, and many will display correctly. However some are showing up as unsupported characters (a rectangle with an x through it).
Obviously not every platform will support every unicode emoji character, but if possible I'd like a way to determine what is and isn't a supported character. The ideal would be to query for a list of supported characters, but being able to test individual characters would also do the job just fine.
Also check out Paint.hasGlyph(String), which was added in API level 23. You can use this to test if a character like an emoji has a glyph available.
This is what the documentation says:
boolean hasGlyph (String string)
Determine whether the typeface set on the paint has a glyph supporting
the string. The simplest case is when the string contains a single
character, in which this method determines whether the font has the
character. In the case of multiple characters, the method returns true
if there is a single glyph representing the ligature. For example, if
the input is a pair of regional indicator symbols, determine whether
there is an emoji flag for the pair.
Finally, if the string contains a variation selector, the method only
returns true if the fonts contains a glyph specific to that variation.
Checking is done on the entire fallback chain, not just the immediate
font referenced.
See also
How to detect emoji support on Android by code
So, when you talk about a character being "unsupported", it sounds like what you mean is that the current font doesn't have a glyph for the character (and either the application doesn't have fallback logic to find a different font that does, or the system doesn't have any font that does).
In regular Java, this is pretty easy: given an instance of java.awt.Font, you can see if it has a glyph for a given Unicode character by using the canDisplay method.
The Android APIs, for whatever reason, don't seem to expose a way to figure out what font you're actually working with. (android.graphics.Typeface keeps that information private: see "Check the family of a Typeface object in Android".) However, you might at least try something like new java.awt.Font("SansSerif", java.awt.Font.PLAIN, 12) to get a basic 12-point sans-serif font. You'll want to test, of course, to see if that gives a usable approximation for the emoji that the real font will be able to display.
You can use Character.isDefined to check if a character is defined in the version of Unicode on the device.

display built-in emoji keys for inputmethod

I'm building a custom soft keyboard for android and would like to add a layout to include the emoji keys similar to what the default android keyboard (AOSP) is doing. I've searched around but it seems that most people are trying to display custom emoji from images. I'm looking to show the built-in icons that comes with Android (as shown below):
It seems that I should be able to use the Unicode characters to send images from the keyboard, but my first attempt seems to generate only the older versions of the emojis. How do I support the latest emoji the phone can handle? Also, how do I display the emojis in my keyboard as in the image above?
Emoticons-Keyboard
1) instead emitos ,Iam replacing the ImageView containing an asset with a TextView containing a Unicode sequence.
After cross referencing Supported Unicode Sequences as well as the Visual Unicode Database I realized that **u1F601** was a 32 bit Unicode representation, and the 16bit representation can be set like :
EditText messageInput = (EditText) findViewById(R.id.message_input);
messageInput.getText().append("\ud83d\ude01");
2) http://android.appstorm.net/how-to/customization/how-to-use-emojis-on-your-android-device/
Go to https://en.m.wikipedia.org/wiki/Emoji to see which emojis your device supports with unicode.
As you know which emoji is shown depends on the font you use, so to get the latest emojis use NotoColorEmoji.ttf as font for your app.
Thanks for all the suggestions. What I got to work for showing an emoji layout in my custom keyboard was the following:
In the .xml layout file, for each emoji you want to add, create a line like this: <Key android:codes="0x1F602" android:keyLabel="\ud83d\ude02"/>
When committing the key, use: getCurrentInputConnection().commitText(String.valueOf(Character.toChars(primaryCode)), 1);
Emoticon support doesn't work like you think it does. There is no universal set of emojis supported by all android devices, and the emojis your device does support may show differently on different devices. Emojis are done on Android in 1 of 2 ways.
1)Unicode. What emojis the device supports then depends on the font the app is using. You just send the unicode just like you would normal text, and you'd display it on your keyboard by displaying that character. For this method, you guess on which ones the phone will support. And its a total guess, because it depends on what font the app is using.
2)Image spans. You embed an ImageSpannable into the text you send via commitText. The advantage of this is you're sure you have an image (you need to include the images with your app). The disadvantage is it can't be sent to another device, saved, and may not work in all apps (they may not be displaying spannable objects).

How to get system Android emoji drawable by unicode character?

I want to implement an android emoji keyboard just using emoji unicode array, without any extra res.
So for the emoji unicode character, I need to get the drawable from android system, if the system doesn't support the charactor, I just ignore this character.
After some basic research,
emojicon, https://github.com/rockerhieu/emojicon
emojicon, https://github.com/ankushsachdeva/emojicon
These implements all use self made resources.
use TextView setText, tv.setText("\u263A"); TextView can show the resource, but how can I get the resource?
Here's the problem- the system doesn't determine what characters can be displayed. The font does. The font needs to define how to draw every character it will display. That's why you'll see boxes or ? for missing characters- that's the font's default render. There is no method on Android to test if a character will display in a given font (although it would be really nice). And since there's no way to know what font the EditText is using, there's no way to know if a given character is supported. Your best bet is to limit yourself to characters defined in the default Android System font. But even then you're assuming the OEM didn't use a different default font, the user hasn't overridden it, and the app hasn't overridden it. Basically, you're forced to guess and hope.

how to convert ascii fonts to unicode for translation

I am developing an android and ios app which will be translated in multiple languages including english, hindi and gurmukhi. We have some pdf files in Gurmukhi that use ASCII fonts instead of unicode and we need to translate them to other languages so that when we try to copy the text we end up with some weird text. Is there a way to do it?
Thanks in advance.
Every symbol font has its own repertoire, so you need a custom lookup table from the ‘wrong’ character to the real character corresponding to what the glyph looks like in the particular font you are using. You can work out this table by installing the font in question and opening it in the Character Map (charmap.exe), noting down which symbol appears in each of the boxes normally occupied by A, B, C...
There is a converter tool here which knows about some common symbol fonts. If the font you want is in that list, you could try to extract the lookup table by pasting in all the characters in the range 32–126;128–255 (!"#$%&'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ) and grabbing what comes out when converted to ‘Unicode’.
Do you need to do the conversion in the application itself? If so you will typically need to write a character-by-character lookup loop. If not, best to use a tool like this manually to convert the material you want into standard Unicode, because dealing with text encoded in arbitrary symbol fonts is a pain in the neck.

Categories

Resources