Thursday, December 6, 2018

languages - How to make an Android device to display complex rendering of Indic characters?


Please excuse the length of this question. I need to explain all this to help others and to avoid helpful contributors to provide answer without asking clarifications.


My requirement in one line: "to enable an Android phone to display Tamil characters properly".


Elaboration: Tamil, like any other Indian language has complex character rendering system. Unlike English or other Latin based script, it has glyph (what you see in screen) composed of more than one character. Android does not have ability to render such complex scripts (with exceptions). My aim is to know how I can provide such an ability to an Android phone or tablet.


Little background that I gathered so far: To display a glyph in screen, Android first needs a suitable font file. Android device has a folder /system/fonts which has few of them. The most interesting file in that folder is the DroidSansFallback.ttf. As the name suggests, when Android's system fails to find a character in system fonts (that could be DroidSans.ttf or DroidSans-Bold.ttf etc) it falls back to search it in DroidSansFallback.ttf.


By replacing a suitable font file from PC (Latha.ttf or Lohit-Tamil.ttf - these are fonts for Tamil) and DroidSansFallback.ttf will enable to display Tamil characters in the device. It is not so easy to replace and it involves rooting the device and mounting the system as writable.


In spite of those troubles, even if the DroidSansFallback.ttf is replaced, the Tamil characters that are displayed are not rendered properly. The Tamil character "தி" is a conjunct of two characters and instead of getting displayed as "தி", it will be displayed as "த ி" without space in between. Though this is enough to read short messages, it cannot be used to read books etc.


From Android 4.0 on wards, Tamil and other few languages are supported through browser as said in Android 4.x API overview as seen below.


Support for Indic fonts (Devanagari, Bengali, and Tamil, including the complex
character support needed for combining glyphs) in WebView and the built-in Browser


The words to notice is "in WebView and the built-in Browser", which means that Tamil characters will be rendered perfectly if it is rendered as HTML content and will not be rendered otherwise. Opera and other few browsers did this even before Android 4.0 by substituting image instead of character.


I noticed that in few devices that target Indian market (ex: LG Optimus One, most of Samsung phones and tablets) are able to display Tamil properly both in browser and even in places out of browser like in contacts, text messages, file names etc. To my surprise they do this even in Android 2.3 onwards. I also noticed that the same model targeting non-Indian country running same version of Android does not support Tamil character display.


This made me to investigate further and reached a conclusion that Android (as other Linux based OS) depends on a font rendering engine to display such complex characters. The two engines that I came across are Skia and Harfbuzz. I noticed LG uses skia and Samsung uses Harfbuzz libraries in their devices to bring this ability.


I came across many websites suggesting to replaces these libraries and fonts. It did not work and results in freezing. Fortunately I backed up using clockworkmod and hence I restored my phone.


Though I had explained this with Tamil, this is applicable for most of the Indian languages.


Here comes my question (if you are still reading;) ) Now, far sure it is clear that a TTF file should be present to provide characters and an appropriate libraries (libskia.so or libharfbuzz.so) are required to render them correctly. Does any one know how these manufacturers are able to provide the ability? I am even ready to build my own ROM from AOSP (Android Open Source Project).




No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...