Using custom fonts with mixed-language text on iOS and Android - android

We are working on an app that requires RTL and LTR language text on the same screen, often in the same sentence, rendered using custom fonts. This poses several non-trivial problems:
The design uses different custom fonts for each of the LTR and RTL
languages. If we use the LTR font, the RTL text doesnt look good and vice
versa.
RTL fonts have greater line heights than LTR fonts so if the line
height is adjusted for RTL, it gets messed up in LTR and vice versa.
One suggestion is to use text markup for language boundaries in multiline text. Then based on markup we will use the equivalent of <span>s in text labels and apply a custom font to each span with custom line height. This sounds like a solution that will require significant text processing on the device and may not be portable, so the questions are:
Has any one successfully tried this approach for mixed-language text rendering?
Are there any other suggestions to render mixed language text on mobile devices?

On android you can add different layout xmls for both ltr and rtl, just like you do for mdpi/hdpi/etc.. Thats the approach (as far as I know) you are expected to take. IOs I have no idea.

Related

What is the difference between paddingLeft and paddingStart in Android?

I was trying to set the padding of a LinearLayout in XML layouts of Android.
But it gives me 2 options - paddingLeft and paddingStart.
What are the differences, and is one the more correct/better attribute to use?
I want the best answer, because this needs the best quality code.
The short answer is: paddingStart is right-to-left (RTL)-aware, which paddingLeft is not.
You should favor paddingStart to make your app RTL-friendly, but make sure you test it (there's a developer option to force RTL on in your language, so you don't have to test your app in a language that you can't read).
If the user is in a locale that writes from right to left (RTL), then paddingStart will be applied on the right side, while if they're in a left-to-right (LTR) locale (such as English), it will be applied on the left side. paddingLeft, on the other hand, will always be applied on the left, regardless of the locale's text direction.
This is useful, because layouts are often reversed in RTL locales. For instance, a contacts list with contact photos might show the contact photo on the left for LTR locales, and on the right for RTL locales. Since the padding for the photo might be different than the padding for the other side of the item, you'd specify the paddings with paddingStart (for the photo's padding) and paddingEnd (for the padding on the other side of the item).
it's all about RTL support, if you choose paddingLeft then when your app operates in RTL Locale eg. Arabic your padding will be reversed. so, using paddingStart and paddingEnd is much more safer when trying to work with RTL world like Urdu or Arabic...etc.
Note : this doesn't matter if you assign the same values for Left and right padding, it obviously will behave the same in LTR and RTL worlds.

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.

Raised colon ligature in Android?

Is there a way to enable your app to use raised colons between numbers for a font in Android? I believe the Roboto font supports it based on the lock screen which shows the colon vertically centered, as opposed to some other apps.
Here's an example of what I mean, the top one is what the Roboto font looks like by default (the colon is too low) and the bottom one is what it looks like on the lock screen:
Try unicode glyph U+02F8 -- hopefully the font supports it.
Thanks to the other comment I found one that works (the one mentioned is too high for me)
https://www.compart.com/en/unicode/U+A789
Simply copy&paste this character ꞉
Example: 8꞉93
At least my Pixel 3a displays that one correctly centered

Android Hebrew (RTL) Integration

I'm working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)
I have manually change the alignment to right in layout xml file. When a sentence contains digits (in the middle of it), the digits appear in a mirror view:
29 appears as 92, 21:45 appears as 54:12 and 2,000 appears as 000,2.
Also, when a sentence starts with digits or English characters, they get thrown to the end of the sentence messing it all up.
I think for android version 4.0.3 it supports Hebrew. I have check that in emulator.
So for older versions is there correct way to implement Hebrew?
Please help.
I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:
U+200E - left-to-right mark
U+200F - right-to-left mark
For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.
Unicode also has the following bidi formatting codes:
U+202A - left-to-right embedding
U+202B - right-to-left embedding
U+202C - pop directional formatting (cancels the previous embedding or override)
U+202D - left-to-right override
U+202E - right-to-left override
For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)
The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.
EDIT
As far as code is concerned, here's an example of how it might be done in Java:
String text = "גרסה \u200e2.100\u200e זמינה";
In XML, it might be:
<string name="update_available">גרסה ‎2.100‎ זמינה</string>
here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק

Using hebrew with the android emulator

I want to be able to run a "Hello World" application on my android emulator in hebrew
How can I do that? is it supported?
thanks
Though android does not have complete support for Hebrew if you are just displaying text, then it turns out to be pretty easy to do.
First you want to add a Hebrew font to your app. For this you simply put a true type font file (with Hebrew characters) in your assets directory. Then you load the font and use it on your view. For any view that inherits from TextView (which includes just about any view that displays text), you do the following:
AssetManager assets = getAssets();
Typeface font = Typeface.createFromAsset(assets, "hebrewfont.ttf");
view.setTypeface(font);
This will cause Hebrew characters to be visible. You may need to use the RTL mode character (\u200F) to force your text to display in the correct order. You may also need to set the gravity to right in order to right align the text.
I've found no way to get the scrollbar to appear on the left side. :( Cantilation marks to however display properly starting in android 2.2. I've tested Nequdot in all versions since 1.5, and they work as well. You may want to use some of the precombined characters, such as shuruq (\ufb35) instead of vav+dagesh (\u05d5\u05bc), as this isn't necessarily handled properly.
I have had good results with the DejaVu font, which is freely available.
Although this has been asked a long time ago, there is a native Hebrew support in later versions. The avd with API15 (Android 4.0.3) can display Hebrew nicely out of the box. I'm not sure which version is the earliest with this capability.

Categories

Resources