Correcting Hindi (Unicode) rendering in Android - android

I successfully added a custom typeface (DroidSansFallBack.ttf) to show Hindi characters instead of Blocks on Pre ICS . All is working well on 4.1+ in any case.
But the rendering order is wrong on Froyo and Gingerbread.
I understand it is not resolved http://code.google.com/p/android/issues/detail?id=4153
What are the possible workarounds to correct the rendering? (I don't want to use images )
EDIT:
Example,
दिन string from values-hi renders as दनि
नक्षत्र renders as नक् ष त र
(On 4.1+ everything renders correctly)

I have a alternative solution for your problem but not exact...
use font....
Typeface tf = Typeface.createFromAsset(getAssets(),"Hindi-SARAL1.TTF");
for नक्षत्र use .......
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("n95");
tv.setTypeface(tf);
and for दिन........ unicode value continues no gap.. i have given a space between &# and 2367;
tv.setText(Html.fromHtml("&# 2367;&# 2342;&# 2344;"));
tv.setTypeface(tf);

I could not find a simple work around for fixing the rendering everywhere. So finally I had to limit the Hindi language feature to devices having android version 4.0 or later.

Related

Android Studio: Layout Preview gives "native typeface cannot be made"

I'm using a font I found on the internet. In particular, the font that is currently causing a problem is Amaranth (Google Fonts link).
I've looked through these questions:
Native typeface cannot be made
RuntimeException: native typeface cannot be made
native typeface cannot be made, exception
custom font in android studio
All of those questions seem to be dealing with crashes that occur on the device at runtime. My problem is that I get this Exception when trying to use Android Studio's Preview tool to preview my layout.
The text I'm seeing in the "Rendering Problems" pop-up is this:
Exception raised during rendering: native typeface cannot be made
java.lang.RuntimeException: native typeface cannot be made   
at android.graphics.Typeface.<init>(Typeface.java:147)   
at android.graphics.Typeface.createFromAsset(Typeface.java:121)   
at app.SegmentButton.onDraw(SegmentButton.java:79)
The code in SegmentButton is this:
#Override
public void onDraw(Canvas canvas) {
// Other code...
String fontPath = "fonts/Amaranth-Bold.otf";
// The next line is the line that causes the "crash"
Typeface tf = Typeface.createFromAsset(mContext.getAssets(), fontPath);
textPaint.setTypeface(tf);
// Other code...
}
I have checked and ensured the following items:
My assets folder is in 'app/src/main/assets'
My fonts folder is in 'app/src/main/assets/fonts'
The file name is exactly "Amaranth-Bold.otf"
This font works exactly as desired when running my app. I have tested this on an LG Optimus Pro G as well as a Droid X. You can see the results in these images:
LG Optimus G Pro Screen Shot
Droid X Screen Shot
As you can see, the fonts show up as desired in both places. As you can probably also see, the Droid X screen shot shows some layout issues that I need to resolve. I'm trying figure out how to do this at design time using the tools built in to Android Studio. This is merely the first issue I'm tackling. I would hate to have to run the app each time in order to make small tweaks to the layout. This is especially true since these are the only two hardware devices I currently have, and I want to test on a much wider variety of screen sizes (and the emulator is sloooooooooow).
Based on my reading of other questions (and primarily based on the fact that the devices load the font fine at runtime), my current conclusions are:
The font file isn't "broken".
The font location isn't wrong.
The typed-in file name isn't wrong (extension, capitalization, etc.)
What else can I try?
I had the same problem yesterday. Android Studio gives you this tip:
Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
Rewrite your onDraw() method like this:
#Override
public void onDraw(Canvas canvas) {
// Other code...
if(!isInEditMode())changeFont();
// Other code...
}
private void changeFont(){
String fontPath = "fonts/Amaranth-Bold.otf";
Typeface tf = Typeface.createFromAsset(mContext.getAssets(), fontPath);
textPaint.setTypeface(tf);
}

how to make gujrati font supported in android app

i'm going make a web site in which i have lots of Gujarati language text.
i found that in many cell phones (Micromax canvas2,etc) Gujarati language is not supported.
so i'm thinking to make a web browser in android which support Gujarati font. so user can use that my web site through my android browser.
plzz help me quickly
Few devices doesn't support Gujarati language packs.
You need to define css and apply it to your webview.
Below post may help you as well.
Android 2.2 webview not supporting Tamil font
Hi Try this this will work fine
TextView mtxt = (TextView) findViewById(R.id.action_settings);
Typeface face1 = Typeface.createFromAsset(getAssets(),
"Lohit-Gujarati.ttf");
mtxt.setTypeface(face1);
mtxt.setText("પૂર્વ વડાપ્રધાન રાજીવ ગાંધીની હત્યા કરનારા 3 આરોપીઓની ફાંસીની સજા સુપ્રિમ કોર્ટે ઉમ્રકેદમાં ફેરવી નાંખી છે.આમ રાજીવગાંધીના" +
"3 હત્યારાઓને હવે ફાંસીની સજા નહી થાય.સુપ્રીમ કોર્ટમાં 3 જજોની બેન્ચે આજે આ ચુકાદો આ");

Typeface is not rendered in Android

I'm trying to set a font like this:
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/myfont.ttf");
textView.setTypeFace(tf);
However, it works for some fonts like Helvetica, or like that, but as soon as I try to load some other fonts, it ignores my typeface and it loads android's default one.
I've checked a looot of answers, and an user stated
Android at the moment when can't set a typeface, instead of throwing an exception, just places system default typeface.
But this is obviously not an answer.
What can I do?
I've even checked sourcecode of TextView, which leaded me to TextPaint, and TextPaint leaded me to Paint but couldn't really find a solution about my issue.
Help would be sooo appreciated.
Thanks.
But this is obviously not an answer.
Well, grammatically it has issues, but it is the answer. Android has had problems loading fonts since Android 1.0, and the API for Typeface does not report success or failure.
What can I do?
Test your typefaces and see which ones work.
If you have licensed the rights to modify the font, you could try loading it into a font editor and saving it again, to see if it is a question of the format of the font file.
Or, contribute changes to the AOSP to improve typeface handling, then wait a few years for those changes to make it out to the majority of Android devices.
Try typeface using SpannableStringBuilder it will work,,
String stringResult="Your unicode string";
SpannableStringBuilder SS = new SpannableStringBuilder(stringResult);
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/myfont.ttf");
if(tf != null)
{
SS.setSpan (new CustomTypefaceSpan("", tf), 0, stringResult.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
}
textView.setText(SS);

Rendering HIndi font on Android 2.3 and lower

I am developing an android App in Hindi but find that few characters are misspelled and broken in Hindi the issue is in http://code.google.com/p/ankidroid/issues/detail?id=1008 but no solution there दिप is rendered as दपि
letters in hindi font above are formed as द + ि + प which should display as दिप but It render as दपि
The same question was put earlier but not resolved so I had to repost it again
Correcting Hindi (Unicode) rendering in Android
Finally I found the solution this is very simple just import the font in my case I am developing web app
#font-face { font-family: hindi; src: url('fonts/k010.TTF'); }
body,h1,h2{ font-family:hindi; }
then type text in your a text editor or MS-word using Kruti devi10 font after You finished change the font to Arial and paste the text in your web App and it will render perfectly
you can use Unicode ...
TextView tv=(TextView)findViewById(R.id.textViewmyView);
final Typeface tf = Typeface.createFromAsset(this.getAssets(), "Hindi-SARAL1.TTF");
tv.setText(Html.fromHtml("&# 2367;&# 2342;&# 2346;"));
tv.setTypeface(tf);
unicode value continues no gap.....
and you can also convert world to unicode via this site...http://mylanguages.org/converter.php but in case of इ 1st use unicode of इ then alphabets Unicode...b/c till android version 4.0 Hindi Unicode not supported proper..

Issue in custom font (RTL labguage)

According to android 2.3 some RTL languages such as Arabic is supported in this new version. However, emulator does not show the fount correctly. In code I have written:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txt = (TextView) findViewById(R.id.myText);
Typeface font = Typeface.createFromAsset(getAssets(), "Larabieb.ttf");
txt.setTypeface(font);
txt.setTextSize(26);
txt.setText("السلام علیک یا حبیبی");
}
but in the output it shows separated characters instead of connected characters.
How can I connect the characters?
As of this date only Samsung's phones running on android support bidi and display of arabic characters. There is nothing wrong with your code. Open the web browser and browse an arabic website you will see the same problem on non-samsung phones.
you can use this tools
Tools.fa("سلام علیکم");
sample image:

Categories

Resources