Android font rendering, i am getting very bad view - android

I am using arial.ttf in my project. In genymotion emulator,in some mobile devices my text view is look good. But in Sony Xperia tablet 4.1.1 i have a text rendering problem. Text looking very bad. What should i do?
<TextView
android:id="#+id/yazi1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Ret"
android:textColor="#color/siyah"
android:textColorHint="#color/siyah"
android:textSize="#dimen/font14" />
Typeface tfArial = Typeface.createFromAsset(getAssets(), "arial_tur2.ttf")
screenshot http://hizliresim.com/ynJjWk

Use OTF instead of TTF. That can be your problem. I was in this situation and changing the file with OTF solved my problem.
OTF is more likely to be a “better” font, as it supports more advanced typesetting features (smallcaps, alternates, ligatures and so on actually inside the font rather than in fiddly separate expert set fonts). It can also contain either spline (TTF-style) or Bezier (PostScript Type 1-style) curves, so hopefully you're getting the shapes the font was originally designed in and not a potentially-poorer-quality conversion.
On the other hand, if you're downloading free fonts from shovelware sites, you're unlikely to get any of that. Indeed, you may simple be getting a TTF font renamed to OTF.

Related

android itext using assets fonts in Android Studio

I'm trying to create Persian pdf files in my android application using www.itextpdf.com but I get java.io.IOException arial.ttf not found as file or resource. Here is the code with the problem.
BaseFont font = BaseFont.createFont("arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
this code is fine in eclipse(java project not android) but wont work in Android studio. I don't know how to address the ttf file. Any help would be appreciated.
This is obvious: Android does not have Arial font.
You have to ship the appropriate font for your script (Persian) along with your application and read the font from resources/assets/etc.
See also How to retrieve a list of available/installed fonts in android?.
UPD:
Once you have your file in assets, grab an AssetManager via getAssets() and use it to read the bytes from the font. This answer might be useful.
Afterwards you are free to create your font like this:
BaseFont.createFont("arial.ttf", BaseFont.IDENTITY_H, true, false, bytes, null);
Meanwhile, I strongly encourage you to read thoroughly on the licensing of the fonts that are shipped with Windows to determine whether you are able to copy-paste Arial font into your application and then use it like this (I doubt so).
Take a look here:
Attribute
customAttrs:fontType="free_mono"
The TextView
<com.seamusdawkins.fontcustom.CustomTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="#string/str_text_default"
android:textSize="30dp"
customAttrs:fontType="free_mono"
android:gravity="center"/>
See this link for more information.

Android custom font not mapping properly

I have to implement Nepali Font on my application and for that I have used unicode font named DroidSansDevanagari-Regular.ttf.The reason I have used this font is that on my Rooted Galaxy S2 I900,I have installed Resurrection Remix 3.06 JB(AOKP) which renders Nepali Font correctly. And under system/fonts folder I have found this DroidSansDevanagari-Regular.ttf font,which is responsible for displaying Nepali Font.
Further I have used the correct way of using custom font
Typeface font =
Typeface.createFromAsset(context.getAssets(),
"fonts/DroidSansDevanagari- Regular.ttf");
someTextView.setTypeface(font);
And though my application displays the Nepali Font it doesn't correctly maps the font.Using same font I get correct mapping on Rooted Galaxy S2 phone,but I can't get correct mapping on other phones. Let me illustrate this by picture
Correct Mapping
InCorrect Mapping
So,my question is how to map the font in correct manner as done by my Rooted Galaxy S2 phone.For that do I have to look upon AOKP project and look upon EditText or Typeface classes.Please provide me guidance on how to correctly map the fonts on each and every device
Thanks in advance
For correct font mapping ,indic text renderer is the best solution I found so far.But before implementing this library,please look upon the solution explained on this issue in order to render fonts with long texts and without any line spacing in between words

Changing the android typeface doesn't work

I am using the following line of code to change the font type in android application :L
Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/Abumohammed.ttf");
textView.setTypeface(font);
I am sure that Abumohammed.ttf is in assets/fonts folder .. but the font don't change and don't has any effect on the textview !!
Android does not support every font file. When it fails, it tends to fail silently, showing the default font instead. I have no idea what Android does not like about some of them.
I would find some font that definitely works, such as this one, and try it to make sure that the rest of your code is OK. If indeed you determine that the font file does not work, AFAIK you have no choice but to find some other font.
I was annoyed enough by this that I thought I'd share some results of my digging. I tried a few font files that ended up using the fallback font. To 'fix' some of these files, I simply had to open the file in FontForge, then File->Generate Font and re-save as TTF. This allowed some that were not showing to draw properly.
Others required moving the glyphs from the Microsoft area (U+F030) to U+0030 range.
I haven't educated myself on what 'Generate Font' actually does. But, now that I know HOW to fix it, I can at least start to figure out why it isn't working. I suspect this can only be fixed in the AOSP tree however.

Customize Android Fonts

Now, I'm developing an android application, which needs to show some special characters. I need this font "Arial Unicode MS" to show the characters correctly. And I add the following code in my main activity:
EditText editText = (EditText) findViewById(R.id.flipped_window);
Typeface font = Typeface.createFromAsset(getAssets(),"ARIALUNI.TTF");
editText.setTypeface(font);
It does work. However, the size of this font file is too big, it's 22,731 kb.
Is there better solution for this problem? Thanks.
Your real problem is redistributing a copyrighted font. :-)
As Craig mentioned, you're illegally redistributing a copyrighted font.
My best guess would be to first look at all the glyphs available in Droid Sans; in my experience, it should be good enough unless you're looking to use it for formatting.
If you can't do that, create the symbols you need as PNG or GIF images and insert them inline. (GIFs will be substantially smaller for black & white).
buddy, you can decrease font size with Font creator software with elimination unused characters in font. you can decrease it to 50,60kb also :-)
password download link : www.downloadsoftware.ir

Display unicode characters in TextView Android

There are a number of posts all over the internet on this topic, however none of them have been able to isolate and solve the problem.
I am trying to show some special UTF-8 encoded symbols stored in a SQLite database using a TextView, however all it shows is boxes. I understand what this means is that right font is not installed. But when I print those symbols using Arial font on Mac it works.
I am trying to use an Arial typeface on the device and the emulator.
Any advise.
It works on your Mac because the font used by your mac contains those special characters. It would be impossible to create a fontfile that contains all characters defined in unicode. Chinese fonts are a good example: none of them contain all of the ~60.000 known Chinese characters because the font file would be huge and unusable.
You could try using the font from your Mac on android (might be copyright issues - try finding a free font that contains the characters: package the (ttf) file in your application, for example in the /assets folder, and then in your application load that font with
TypeFace typeFace = Typeface.createFromAsset(assetmanager,"fontfile.ttf");
You can then use this in a TextView like so:
TextView view = (TextView) findById(R.id.mytext);
view.setTypeFace(typeFace);
If I'm understanding your situation correctly, you might want to consider the StringEscapeUtils.unescapeXml() method. It's in the common-lang.jar file available here: http://commons.apache.org/lang/
It will take encoded symbols (for example ' for an apostrophe) and get you to a proper character.

Categories

Resources