I have an OpenGL renderer that uses FreeType to render text. I would like to be able to use system fonts packaged with Android. There is a way on iOS to get the ttf font data for system fonts (see accepted answer here: On iOS, can I access the system-provided font's TTF file). Is there something equivalent on Android? Is there an API for getting the source file for a system font based on the font name, ideally without having to do any guesswork about where certain system files are stored?
Related
I'm using a unique font for a web app that will be built using phone gap and deployed to Android. For android do I need to include all these different formats?
ttf, eot, woff and svg
I would rather not load a bunch of font files if they aren't necessary.
It doesn't hurt, TTF, SVG are widely used, EOT is not supported at all. The browser should only load one font file not all four so it doesn't hurt to have then declared for support sake.
http://caniuse.com/#feat=ttf
http://caniuse.com/#feat=woff
http://caniuse.com/#feat=svg
http://caniuse.com/#feat=eot
If you can can (ie you have font in that format) just use ttf fonts on android.
I have developed an application which contains a WebView for loading additional URL contents, but I have an issue.
The issue is that when I load a local language URL, some devices don't support local languages special characters, so some empty squares are shown.
How can I load an additional font in my application or device?
Custom fonts are not that easy in android. You will need some .ttf files, which You must load at runtime as typeface.
This link has nice information, also about best practices, on how to deal with custom fonts properly.
Check out:
Android - Using Custom Font
If your webview is showing an online page (as opposed to a html file which is compiled into the assets somewhere, like Cordova/phonegap does), you perhaps should look at using a web font in the css. The easiest thing to do is uses google have a few hosted, see:
https://developers.google.com/fonts/docs/getting_started#Quick_Start
http://www.google.com/fonts (is the full list of fonts)
Hope that helps. (other webfont options are available).
This question already has answers here:
Extracting glyph-path information from ttf files
(3 answers)
How to use kerning pairs extracted from a TTF file to correctly show glyphs as Path2D in Java?
(2 answers)
Closed 2 years ago.
Android does not support the Urdu Nastaliq font properly (the word is broken up and the exact shape (Nastaliq) of the word is not made).
I have used Typeface for this as
TextView tx=(TextView)this.findViewById(R.id.tt);
tx.setTypeface(Typeface.createFromAsset(getAssets(),"TTF font Path"));
I am able to get the exact formating of the Nastaliq Font in java using the AWT package like
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Path for ttf file"));
Font dynamicFont32Pt = font.deriveFont (32f);
JLabel textLabel = new JLabel(textMessage);
textLabel.setFont(dynamicFont32Pt);
But Android also does not support the AWT Package Properly (java.awt.Font.createFont() and deriveFont()), So we decided to make a render engine for the .ttf file for Urdu.
Now my question is-
Can we get the urdu Font (properly) rendering in Android without needing a Rendering Engine?
If not, then
How can I read the .ttf file (All tables like 'glyp', 'head') in Android?
How can I draw a TTF font, that is, a vector font that does not require a PNG?
The answer from the Extracting glyph-path information from ttf files question can interest you: basically, it points to the Batik library which has code to parse a TTF file in Java (to transform it to SVG).
You should check my question How to use kerning pairs extracted from a TTF file to correctly show glyphs as Path2D in Java?. Instead of Batik, I recommend using Apache FOP. It is simple and easy to use. The advantage is that you read the font only once and you embed the Glyphs into your app. However, Apache FOP only works for TTF, not for OTF (it is possible too, but I am still working on that). Batik uses Java AWT to render strings. The problem is that your app needs to read the font file each time it runs. In the method I am suggesting you can use an embedded mini vectorized font, or you can use an embedded vectorized string for small texts. The problem of this approach is that widths only work properly in painting time. To be able to use the glyphs you recover from the font file using awt, you need to read the kerning pairs and widths directly from the file to be able to display the text properly. This is explained in the answers to the question. Also check the question How to read kerning pairs table from TTF file in Android?. The advantage of using vectorized glyphs is that your app is independent of font files and operating system.
You can see that I am using this system on Windows, but you can do the same for Android. Fonts are easier to deal with on Windows and most fonts there are TTF. In reality you can develop your vectorized font on Windows and just use the resulting class in Android. That's the beauty of this method. I generate my fonts using println and copying and pasting it in a new class file. I don't even bother in writing a file.
I saw that on iPhone there is a truetype font called Apple Color Emoji. It contains the emoticons that exist on iPhones which can be used in any application.
I wonder:
How is this font displayed in multicolor?! Truetype fonts can only include black and white glyphs.
Can this font, or one like it, be used on Android phones?
Apple is using a proprietary extension to the OpenType standard. Basically, they just store pre-rasterized color PNGs in a proprietary extension "block" within the TTF file (reference, corroboration).
The only reason this works is because they also provide the full stack between that font extension and the screen (font rasterization, system graphics library, text rendering widgets). There's no standardized way to accomplish this across all platforms/libraries.
The font uses embedded PNGs and they are stored in a sbix table.
Apple Color Emoji cannot be used in Android, but a Google CBLC/CBDT formatted font can.
There are four methods for implementing color in Open Type fonts right now:
Apple's SBIX - Embedded PNGs
Google's CBLC+CBDT - Embedded PNGs
Microsoft's COLR+CPAL - Colored glyphs
Adobe/Mozilla/W3C's SVG+CPAL - SVG in OpenType
The complete list of OpenType tables.
You can disassemble/reassemble the font using ttx from FontTools(pypi, github) for more details.
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.