Thursday, December 22, 2011

How to add Indian Languages to Android ICS (4.0.3)

Google is officially supporting the Indian languages rendering from 4.0.3 onwards.
The AOSP code supports rendering of three Indian languages in Web-kit. (Devanagari, Tamil, and Bengali).
I just added support for the other Indian languages as well. Tested it on my Nexus-S device

Prerequisites :

Follow these instructions:

1) Download the "Binary" file of the Indian language from this link.
         Ex: lohit-kananda-ttf-2.5.0.tar.gz

2) Untar the downloaded file and Copy the extracted folder into  
    external/lohit-fonts directory
        Ex: lohit-kannada-ttf-2.5.0

3) Rename the folder name to lohit-kannada-ttf

4) Modify the Android.mk file which is present in external\lohit-fonts directory

       ifneq ($(SMALLER_FONT_FOOTPRINT),true)
            extra_lohit_fonts := Lohit-Bengali.ttf Lohit-Tamil.ttf Lohit-Kannada.ttf
        endif 


       include $(CLEAR_VARS)
        LOCAL_MODULE := Lohit-Kannada.ttf
        LOCAL_SRC_FILES := lohit-kannada-ttf/$(LOCAL_MODULE)
        LOCAL_MODULE_CLASS := ETC
        LOCAL_MODULE_TAGS := optional
        LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
        include $(BUILD_PREBUILT)

5) Modify the FontAndroid.cpp file (external/webkit/source/webcore/platform/graphics/android)

    a) Add an language entry to CustomScript enum
             enum CustomScript {
               Bengali,
               Devanagari,

               Kannada,
               .......
              };

    b) Add the ttf file path to the TextRunWalker Paths

           const char* TextRunWalker::paths[] = {
              "/system/fonts/Lohit-Bengali.ttf",
             "/system/fonts/Lohit-Devanagari.ttf",

             "/system/fonts/Lohit-Kannada.ttf",
             ........
          };

    c) Now setup the Font for Script Run
         TextRunWalker::setupFontForScriptRun()
          {
            case HB_Script_Kannada:
              complexPlatformData = setupComplexFont(Kannada, platformData);
            break;

          }
 
6) Add the *.ttf file in Fallback_fonts.xml (frameworks\base\data\fonts)

Note : Assamese language is not enabled as Harfbuzz is not supporting this language.

35 comments:

  1. Really helpful! But a question here.
    Though you can see the proper rendering of glyphs in Browser,there is still a problem with it when I copy a word and paste in messaging.

    Kindly help!

    ReplyDelete
  2. @Unknown,

    In Android, the Graphics Rendering will happens through a seperate channel and the Webkit Rendering in an another channel. As of now, google is supporting the indian language rendering support with Webkit only.
    The messaging will fall under the category of "Graphics Rendering". In this only Indian characters without matra's are able to display.

    ReplyDelete
  3. Thank You, With this I feel that it is a little complicated as everything has to be set up from scratch.Am I right? Any guidance?

    ReplyDelete
  4. Can this steps work on android 2.3 platform. my mobile is running on Cyanogen mod ROM. currently i've installed kannada by replacing and renaming kannada font with droidsansfallback.ttf file. but its not rendering correctly. Please help.

    ReplyDelete
  5. @Bushan,
    Replacing the droidsansfallback.ttf with the kannada font doesn't guarantee the proper rendering. I can call it as a kind of "Hacking"
    From ICS onwards, Android is using "Harfbuzz" (which is an OpenType text shaping engine) for rendering.
    If you happens to be an Android developer and you can explore ICS and GB source code.
    Merge the ICS rendering changes to GB and give it a try.
    Source code path : external/webkit/source/webcore/platform/graphics/android
    In the above path, merge Font*.* files and Harfbuzz*.* files

    ReplyDelete
  6. @Unknown:
    Yup for the end users it's little complicated. But, for the android developers it's just an half-day effort.

    ReplyDelete
  7. WebKit does its own rendering - so this is nowhere near proper support for complex script rendering in Android. Unless it works in texting, calendar, dictionary applications and so on it is pretty useless.

    Anyway ordinary users can't reasonably be expected to go through all these complex steps just to use their language on their Android phone.

    ReplyDelete
  8. P.S. Frankly the Ministry of Communications and Information Technology of the Indian Government - and those of all other SAARC nations - should ban the import and sale of smartphones that don't support their languages. Then we would see this fixed overnight.

    ReplyDelete
  9. @Sandeep,
    I am not a devloper, but would like to render kannada on Ginger bread version. Help me if you have any solution.

    ReplyDelete
  10. Is it possible with X8 running CM9 Paul's Rom?

    ReplyDelete
  11. @sree,

    Yup, it's possible on CM9. Apply the above changes onto this branch.
    https://github.com/CyanogenMod/android_external_webkit/blob/ics/Source/WebCore/platform/graphics/android/FontAndroid.cpp

    ReplyDelete
  12. Could you pls explain/simplify this?

    ReplyDelete
  13. I need explanation at line 2-how's the folder added to the directory(I am not a programmer!)Pls...
    I would like to add Malayalam to the fonts lists

    ReplyDelete
  14. @CFynn
    What you are saying is correct.Google has added the support for Indian language in 4.0 but here in UAE they supported Arabic from version 2.1
    @sandeep
    I have already installed CM9 nightly on SGS here they have support for हिंदी but rendering is not proper. instead of हिंदी (हिन्दी) it is rendering हिनीदी. so tell me is it possible anything i can do so it will render properly.
    I am not programmer/developer if possible pls provide tutorial/guide to do this.

    ReplyDelete
  15. If rendering is not proper for your script with CM9 then you should report it as a bug at http://code.google.com/p/cyanogenmod/issues/

    If no one reports the problem there, it is unlikely to get fixed

    ReplyDelete
  16. @swap

    That is what is frustrating - if there is Arabic support you would think it would be straightforward to add support for Devanagri, Tamil, Kannada, Bangla, Sinhala, Khmer, Tibetan, etc. by adding or enabling the code from Harbuzz that handles those scripts to the shaping engine which is already handling Arabic.

    There are a few phones, including Sony Ericsson ST and MT series, running Android 2.1 that do support many complex scripts, including Indic, because the manufacturers have added or enabled their own support.

    If you see the script but letters are not combining properly at all, and you are not getting proper half forms and some vowel marks are in the wrong places, it means the font is installed but there is no complex script rendering being applied. If only some letters are not combining properly, but others are, it could be that the shaping engine is applying the OpenType features in the font in the wrong order or that one of the features is not being applied at all.

    I also have a phone running Maemo Linux (Nokia N900), and complex script rendering works fine for all scripts on that device - all I have to do is install the fonts and keyboard layouts for the scripts I need if they are not already present. If there is no keyboard layout for a particular script, it is also very easy to create one without any real programming knowledge. All smart phones should work like that.

    ReplyDelete
  17. @cfynn
    could you just give steps to do that

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Nokia N900 (Maemo 5)already has support for several scripts
      For others simply install the latest version of the UKeyboard package. It has keyboard layouts for many scripts and will also install the required fonts.
      If you need to make a layout for another script, there is information at http://talk.maemo.org/showthread.php?t=41903 on how to do this.

      On Nokia N9 (Meego) you gain root and install the font need in /usr/share/fonts. If there is no keyboard for your script these can be created using a simple XML file.
      Delete

      Delete
  18. Hi All.. I just bought a brand new HTC One X and I am so much in love with it.. only issue I have is I dont see any kannada fonts on it. I know the very purpose of this article is to help me do that.. but I am very new to android technlogoy, can I just follow the steps blindly and try it ? Also ,does this procedure require rooting of the phone ? I heard if we root the phone, the warranty gets void. Is it so ? PLS HELP ! I WANT MY KANNADA ON MY PHONE !

    ReplyDelete
  19. Buy an iPhone which supports all Indian Languages out of box.

    ReplyDelete
    Replies
    1. If iPhone can take care of Indic fonts, why other smart phone manufacturers cant ?

      Delete
  20. on CM9, Hindi, Tamil, Bengali is rendering fine in browser. but in the system still lacks with correct rendering. without doing above steps, I tried just replacing DroidSans.ttf with kannada unicode font file, observed in facebook, all comments and posts posted in kannada font are rendering correctly, only the menu and other options still lacks with complex rendering.

    If you can make a APK file or flashable zip file for above changes, definitely going to help us a lot.

    A Tamil person has created a APK file (avaiable in android market) for installing and rendering tamil font file in system and applications in Gingerbread ROMS.

    Please help us.

    Thanks in advance.

    ReplyDelete
  21. Many Sony-Ericcson ST and MT series Android phones support proper rendering of Indic scripts right out of the box. So, if you want an Android phone that works properly with Indic scripts with no hassle, I suggest you try one of these models.

    ReplyDelete
  22. @bhushan
    Whatever u r saying is correct the rendering is good for browser but not for system if you get any pls share here.
    @cfynn
    I already have samsung galaxy s is it possible that we can copy and paste the sony rendering scripts to out phone or any other procedure is there? if yes pls share here.

    ReplyDelete
  23. Result is I love kannada..... I am new to android, and I have micromax A110, I am not able to see the kannada font in browser N facebook... Please dont tell the steps. I am not a computer user or technically good... Please help me..... I want Kannada.....

    ReplyDelete
  24. Installed lohit-kananda-ttf-2.5.0 font and every thing worked fine.. but the number pad in my Xperia Neo L MT25i got affected, and the * and # symbols displaying like flowers and all numbers are displaying little above in input area...

    any fix is their for this...?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  25. My phone is running ICS 4.0.4. I'm not able to find out where to make those file changes? I'm not able to find those folders in my phone. I mean where is that lohit font directory, where is the android.mk file? Can someone help please?

    ReplyDelete
  26. Can someone please tell me where I can get list of Indic Languages supported by Android platform for display and for input ..the support should be native without help of any third party tool or add in etc.

    Thanks in advance

    ReplyDelete
  27. The Rocket Droid Pc is a HDMI Android TV Dongle on Steroids! Plug it into your TV and experience the Android UI & Gaming like never before.
    Rocket Droid pc

    ReplyDelete
  28. Hi Sandeep, I want to develop an app in Odia language,where several notifications would go through out a day. I want to know if it is possible to use the above described method to view the font in all android devices.

    ReplyDelete
  29. Thanks for posting this is very helpful for me.

    Videocon offers one of the best postpaid prepaid service for more information contact our website.

    ReplyDelete