Monday, August 25, 2014

Installing fonts on Android, simple yet unnecessarily tricky

Most android devices come with set of fonts already installed for all the general purpose use with variety of styles and various languages. There is also something called 'fallback' font which ensures that in case a required font is not available, the system falls back to this font with wide range of characters and more generic style to display the text. But sometimes, you really want to use that specific font which is not there on the device or you just 'have' to use a some non-english font because the system by default does not have the font for the language you wish to use. Though upfront it looks like a simple task of installing the font, unfortunately android does not yet provide a simple way of doing it in user space. It is possible for an application to provide a custom font and use it within the application, but that's not really installing it on the device, its applicable only within the app.

Recently while working with some Indic languages on android, I was faced with this problem where I had to display Kannada and Gujarati in browser, but my old ICS device, did not have any Gujarati or Kannada font by default. So I started looking for an app for installing fonts. Interestingly every app I could find required the phone to be rooted. Rooting the device for such a simple task! But anyway had to do it, and that's actually not very difficult with ready to use apps like vroot. Next downloaded one of the popular font installing app, iFont. Good thing about iFont is it provides numerous fonts by default, so if any of them suites your purpose, you may go ahead with it. But if the font you want is not listed, you need to add it to the app and then install it from there. So went ahead and installed the Gujarati font using iFont, it gave some sort of warning that things may break somehow, which I of course ignored. Reboot. And things did break down. All of the text on my screen was just vanished, except for few bits of Gujarati somewhere. So following just the icons, I started the iFont again and somehow figured out the section where my font was listed and tried uninstalling it. Reboot. And everything was back. That was scary for a simple font addition.

Later I figured out from the application logs, what exactly this iFont did. It simply took the backup of DroidSansFallback.ttf font on the system and replaced it with my font. It meant all the characters (glyphs) in fallback font other than Gujarati were gone. For weird reasons, my system was looking into DroidSansFallback.ttf for displaying the normal English text on screen. Hence all the text was vanished. In any case whatever iFont was doing did not seem promising and it also appeared that most available font installers did the same thing. So I fell back to look for a manual procedure.

In general font installing involves just two things, copying the font file to specific location and sourcing some configuration file to declare few properties to the system. On desktops, these things mostly happen automatically, or at the most you have to click the install button and it does everything required. The basic procedure on android is also similar, just that there is no direct button yet. So once the phone/device is rooted, this is what you need to do:

1. Copy the font file to /system/fonts/ directory.
2. Add an entry in some xml file for the font.

Of these, step '1' can be done in multiple ways. but most commonly you will have to use adb shell to get access to the device file system. There is enough documentation on installing android developer environments and using adb shell over internet depending upon your operating system. So not repeating all that. So once connected by adb shell, you can simply use 'adb push MyFont.ttf  /system/fonts/MyFont.ttf' to push the font file from computer to the direct path on the phone. Or you may also use 'adb shell' to get shell access of the android system. By default android will not provide 'cp' command, so you may have to use 'cat inputfile -> outputfile' method to copy. Or you may also download 'busybox' to get ease of using all the general purpose linux commands on android shell. 

For the step '2', again we do not have luxury of fontconfig like tool for configuring everything. So you need to check the font properties, such as 'font-family' on your own, any font viewer on the desktop system would be able to show that much. Now if you have already done the 'busybox' thing mentioned earlier, you may directly use 'vi editor' on the 'adb shell' or you may get the xml file copied to the desktop machine by 'adb pull file', edit on desktop and then push to the device. The file you need to look for is '/system/etc/fallback_fonts.xml'. See the file '/system/etc/system_fonts.xml' for more details on format and possible parameters. Save the file on the device after making proper entries for your font and your font would be installed on the system after reboot.

If you are already used to accessing and editing android system files, this should be a simple two step procedure, otherwise you may need a little getting used to and few google searches to get your way to safely accessing and editing system files. Sorry for not giving the step-by-step guide on this, but that was never the purpose.

Ideally, there shouldn't have been a need to root the phone in first place for simple font installation. It should have been possible to install the font in user domain by simply keeping font file in some user accessible location and a related xml file for describing it. Did not get the logic behind keeping it so inaccessible to common people. Anyone would have done a simple app to give user interface to it. I may not be aware, but if anyone knows better on this, I would love to know it. If indeed there is no other proper way than rooting the device, I think android should give it a serious thought to improve font management, even integrating fontconfig by default may be enough for this.

Apart from that, the apps like iFont can also do away with dangerously insane modification of fallback font. It virtually disables everything that needs to fall back, and given the number of languages, a lot of people do need to fall back for basic viewing of text. Anyway the app needs root access, so why not use it responsibly and make only intended changes to simple configuration files instead of other shortcuts. Hopefully the upcoming versions of android will have better font management by default, especially since use of non-english languages is consistently growing on mobile platform where this feature could become increasingly critical.

[Also read at: GnowTantra]

Tuesday, August 19, 2014

15th Aug, Independence Day, a Beggar and a Tea

On this 15th August, afternoon, I was sipping on a tea at a roadside stall, sitting on a bench, waiting for a colleague, when I heard an aged female voice over my head, 'चहा पाजतु का दादा' ('would you help with some tea'). Before I could realize that there was a fairly old couple, woman having a limped leg, and old man, mostly her husband in 70s, were asking the two cab drivers for some tea, the cab drivers responded, 'पाजतु ना' (sure why not). I generally have a strict rule of not heeding to the pleas of beggars (and I have my moral position on that considering the beggar mafia openly ruling the streets in Mumbai), but once in a while some one catches your attention and you just can't help stopping yourself from doing something if not just giving away 2 rupees. This time the instant assurance of the cab driver to buy them two cups of tea caught my eye and especially ear. The old couple did not look exactly like beggars, their clothes were fine for someone from rural area, just helpless people out of home, out of money and without any support at all. The driver asked her about her situation, whether she has a family etc. to which the woman told him about her only son, a drunkard, who is selling off every vessel and nut of the house for his liquor, his beaten up wife has left the house and prefers staying at her parents, even the land and farm in the village are on the way to get sold, the son has lost so much of himself that he even runs after his father with a knife in hand for money for his drink. So finally, they have been thrown out to roam on streets and beg for 2 rupees as the old man could not get any physical work, while woman was already on one leg and a stick in hand. Quite a heart-touching story it was, and for most of it, it looked real.

I was silently appreciating the cab drivers kindness of lending the tea for two, just then he said something to the woman, something so drastic, unimaginable, sudden and sharp, that it took that moment to a completely different level for me. "Now listen to me, do one thing, both of you, there's a railway-station nearby, just go there. Walk a few yards beyond the platform and then just sleep on the tracks. And ohh yes! bring your son too and make him go under the train before you go." Cruel. Disgusting insults on two lives of more than 70 years by someone in his 30s, in exchange of two 'cutting chai' Rs 6 each. Realization of why one poor showed some pity on another poor, for being able to insult in such a way and enjoy the authority to do so for just 12 bucks was worse than my own cruel rule of ignoring beggars and a little guilt that follows at times. But that was not the end. The woman was adamant for continuation of her son's life, as well as her own. Death was not an option for her, life, no matter what it meant had to be lived. I didn't understand the need of her 2-3 sentences of adamant denial to the man who advised death, but appreciated the will to survive.

Once this was settled, the drivers gone, and couple calmly sipping the tea, I initiated a talk with the woman with no specific plan. As she went on about her helplessness, and as she said 'our nature is of giving not begging, but have to do it', it had both a reflection of a decent past, a little bit of pride, and huge hollowness of everything before survival. With an intent to help in a more meaningful manner, I asked her to stop roaming around like beggars at this age, asked if she knew anything about any charitable organizations nearby. On knowing that the couple knew nothing of the sorts, I gave them options where they could find some help. At least a roof, and some food on daily basis. This included some charitable orphanages, Temple trusts, rich spiritual shrines nearby, including a Balaji temple, Gurudwara, Sai Baba temple, a list of social and govt organizations who could help, and were within few minutes distance by train, the nearest of them being a Buddha vihar at a 5 mins of walking distance. She looked intrigued and willing to consider those suggestions over the option of begging on streets. But then something happened that took me on another mental journey altogether.

This woman, defeated by life, defeated by the conditions, betrayed by her own blood, having been asked to die in exchange of two cutting chai, having lost the meaning of her life if anything was there, came closer and in a slightly lowered voice, repeated the list of places I suggested, took names of all the gods, whose named trusts I suggested, went on adding gods from her own list, and said she will go to any of them, Balaji will do, even Sai Baba will do, "but I will NOT go to the Buddha temple!" Shocked and taken aback, I tried to recompose and asked "why not, its just there, beyond this street" but "No, not that. No Buddha temple!"

My friend had arrived, he called me out, and off we went. I kept looking back for a while, not sure if indeed physically turning my neck or just in my thoughts, but her words kept coming back.

Its not that I didn't get what she meant, she certainly did not know a thing about Buddha's teachings, so there was no way I could take it as an offence against Buddha, also since I wasn't selling her any religion or preaching there, merely advising on what places she could go, being an atheist actually listing most of the temples, her choice of any of them had no bearing on what I should have felt. But why would a woman, in her condition, rather than making a simple choice of where she should go, takes efforts to let me know where she would NOT go, no matter what. So all my educated and intellectual friends, please spare a moment to think over it why this would have happened. Why for a poor Hindu (ahh well there were enough signs on them to suggest that, so don't bring up the stereotypical allegation of stereotyping religion. Sometimes common sense prevails), a Sikh charity is all right, any imaginary god is fine, government is fine, even a Muslim sage is fine, but not a very own Indian real person of the stature of Buddha whose teachings have shaped major part of our accommodating non-violent culture, not so fine? Put your grey cells to work and make me understand the contradiction to the intellectual Indian's constant rhetoric that Buddha is very much Hindu and very much a part of the same system, just another 'panth'(branch), in the same family of spiritual and cultural traditions against the practicality of this unusual separatism.

No, its not just Buddha. Of course he does not fit as well as the intellectuals try to fit him into the Indian Hindu nationalist spiritual rhetoric. But there is something deeper than that. If you know even a little bit about rural Maharashtra, Buddha means only one thing, the new God of the 'untouchable' people, the 'untouchable God'. By all means the emotional journey over the sad life of a poor old couple, took me through several planes and suddenly dropped in the pile of castes. Making me realize that even beggars could have a false-pride, note that its not your good romantic self-esteem, its an outrageous, unnatural, hollow pride. And my dear friends, I know some of you who love me a little extra would be jumping to put the credit of bringing caste into this, but no, it was forced. Forced by the woman thrashed on the roads, by her own son, still having a hollow sense of pride and separatism based on a very 'important(?)' aspect of her life, the caste. Being unnecessarily looked down or rejected by the people with possessions is not at all new for someone from depressed class, but being looked down, for no reason from someone with no possessions, no powers, no resources and no knowledge, only on the basis of a false sense of caste-pride and that hollow dignity was all new experience that intellectual educated Indians will rarely understand. No my dear friends, its not that a beggar cannot look down upon someone, its not that a beggar cannot have a self-esteem, every researcher and every sage who lives on donation amounts and free alms is a beggar, so any beggar with apt possessions in various moral and ethical forms can and should have the dignity, self-esteem, self-respect, but when its based on something as stupid and as ugly as caste, its not a self-esteem, its a farce, ugly farce, that's going on for generations after generations. Its everywhere, and each one of the depressed class human, and not just human but even their God, is facing it every day. I could give number of examples of casteist attitudes and insults thrown towards people I know personally, experiences of my own, but don't want to dilute the intensity of this one experience, they are more of a regular offences, everybody likes to turn blind eye to them. But no matter how much you deny, caste is 'the' en-slaver of Indian mind, just remember how you got married or how in future you would and you would know what I mean. The society and the mind of Indians are still not free from this mental gutter which does transform itself into physical plagues on a regular basis. The freedom is a long awaited dream and far away target. Hope the real freedom will rise some day. May the old couple get to any one of the place and spend their remaining life in peace and in search of meaning, not just bread and pride.

[P.S. So my educated intellectual friends, no matter what your opinions are, on what basis they are formed, and no matter how much you declare yourself not guilty of being part and fuel in this entire scheme of caste based discrimination, atrocious culture and separatism, if you utter a word about caste being just a political tool, not a social evil as much, it being only irrelevant and non-existent or a non-significant problem, and claim that your religion(whichever it is) has no base for this menace, and its the dalits/untouchables that are responsible for its existence, just imagine the level of sanity that would be attributed to you. If there is any anger or bitterness in my words, its not against the poor lady, she is just another slave of the system, so the anger is against this system, against this culture. Also this is not just a random rambling, yes there would be proactive opponents who would ask what's the use of all these rants. But before going into the usefulness of words against actions and before some outrageous good-for-nothing person asks about the evidence of action(the usual 'what have YOU done'), let me remind that I am not obliged to answer that, this is a collection words and thoughts based on personal experience without any specific target, apart from a simple objective of expression and hope that even if some of the people realize how deep rooted the imprints of caste and its false pride and divisiveness are on the Indian mind, even if only a few realize how much disservice this attitude of forced separatism with false superiority is doing towards overall economic, social and spiritual growth of the people of this country and people who follow this culture, even if only one person at a time changes his/her mental attitude on reading such snippets of experiences, it would be enough for this much writing effort. You don't inhale each breath with a plan to change the world, with every breath its only the oxygen that matters, rest goes on independently. Hope sane people get sane message to ponder upon from this slightly painful but a lot more disturbing experience. (uff, see how many defenses one has to be prepared with even before talking about such topics in a supposedly free speech society!)]