Saturday, June 25, 2005

 

Hindi and Java

Office has been quite hectic the whole past week. I have come across IBM ICU page and tonight i want to do some reading on the microsoft typography page. However ,the only achievement of this week has been getting to display hindi in a Java swing application. Let me clarify, I am on mac os x so what happened to me might not again happen to you. but anyway this is what happened to me.
I got to matthew blackwell's page through unicode.org. His site has a javascript as well as some alpha level code for a swing java editor. His editor is pretty simple. Basically you have lots of buttons in a Grid that is your keyboard and there is one Text Area on top of it that is your editor. Buttons get their label strings in Unicode corresponding to hindi unicode table and when user presses these soft buttons, you insert the corresponding character in the Text Area.

when i compiled his program on my machine,it did lay out the buttons with hindi fonts, but when u click the buttons, the TextArea was not able to display hindi characters. Nowi have got the JTextArea to display hindi.its simple,all you have to do is to set the correct font for JTextArea. something like

display = new JTextArea();
display.setEditable(true);
// This display that is JtextArea should use hindi font for displaying things

try{
InputStream iostream = new FileInputStream("mangal.ttf");
//java.io.File f = new java.io.File("mangal.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT,iostream);
Font mangal ;
mangal = font.deriveFont(22.0f);
// without this line, we dont get hindi glyphs in JTextArea
display.setFont(mangal);
iostream.close();

}
catch(Exception ex){
System.out.println(ex.getMessage());

}

It remains to be seen if Java is truly portable. i will run this same editor on windows and then again run it on someone;s linux m/c. with bundled font file,it should come allright. Once the Editor works well then i can think of various input methods.I want to do some experiments first.

I think this is what is meant by application support unicode ? Like i tell JTextArea to use a particular font. That font has mappings of unicode character to glyphs. Once the correct font is supplied,the JTextArea can display the glyphs. This lets me to wonder , how PDF files can display the correct glyphs irrespective of the platform ? surely they are not storing images like some web pages to display hindi characters then how come PDF files can display all the characters correctly ? Time to ring the contacts in Adobe Delhi office.

Sunday, June 19, 2005

 

fonts and resolutions

Last day my search took off on a tangent. I was trying to understand what roles fonts play. freetypes.org has some relevant information in their documentation section. Another good reference i found was from jujusoft. however what i realized is , right now i dont need to go into the underpinnings. That can always come later.
what i need to do first is to complete the circle from user's perspective. so i should look at the following points
1) what do i need to do to display hindi content in applications i use.
2) how can i create some hindi content. Like can i start blogging in hindi right away.
I will try to leverage existing applications and systems.
point 1)
Applications that i will try to cover are browsers and word processors.Displaying part is now ok. i have covered that in previous posts. safari browser on mac os x and firefox on windows boxes. For word processor i will cover openoffice. Because i want to cover something that is free. i will also try to cover some simple editor. one in which you can type in a hindi note very quickly.
point 2)
How to input hindi ? This seems to be a bigger issue now. I do not like the keyboard for doing this. and selecting individual characters and inputting them is a bigger pain. So better thing would be to concentrate on a better input method.

Thursday, June 16, 2005

 

How to view hindi pages on windows xp box

You may find this useful if you are on wondows and want hindi support. Again there are lot of resources on net that tell you how to view/input hindi. right now, i am just limiting myself to BBC hindi page,hence forth refered to as the BHP :o). I got my information from www.alanwood.net and www.nepali.info. bottom line is ,install regional language /complex scripts support. google for windows xp internationalization, complex scripts,devanagri etc etc. installing complex script support is breeze. takes around 5 minutes but you have to restart your machine at the end. Then you configure firefox to use devanagri. (I will post my firefox settings tomorrow) so again if you have a windows xp CD ready , the process is more or less painless. The process should be similar for all windows2000+ systems.

Now that i can view hindi pages on my m/c it is time to dig a little deeper and try to understand how this is made possible. what kind of application can do this and what support they expect from the underlying system. what is the meaning of phrases like mac os x is hindi-ready. all the different types of fonts true type ,open type and how fonts provide hints to applications that do the rendering.in other words let me understand the process of converting bits packed in some scheme (encoding) as pixels arranged as letters on screen. what all is involved.

 

Finally I can see good hindi fonts on my mac os x

The goal was to see a nicely rendered BBC hindi site.
Finally after struggling with hindi fonts in safari for quite some time, today i am able to see how i wanted to see http://www.bbc.co.uk/hindi website. To view hindi you require two things, an application that understands unicode (able to interpret UTF-8 kind of encoding ) and good hindi fonts. The application is my web browser, safari on mac os X.
But fonts were an altogether different issue. after surfing internet i got this piece of information that I need to install additional language pack on mac os x ( I have panther 10.3.9) from install disc 2 to get the required hindi fonts. see simon brown's web log for more.
However when i popped in my install disc 2, it only showed an RTF file and i was really clueless as to where all the packages are gone. So i decided to copy hindi fonts from my window system or download them directly from internet.

There are many hindi fonts available on net. However There are certain factor that decide "what is a good hindi font" to have on your system. I tried Yogesh, Mangal from my winXP box , JanaHindi and Gargi to name a few . You should not take propriety fonts , I hate them. And never, never , never agree to download some stupid embedded fonts that work on just one web site. Again all the knowledge on net is in favour of taking an OpenType font. according to adobe's site , these fonts are cross platform and provide good hints to underlying system. I think JanaHindi and Mangal are opentype fonts. I am not sure about this, but will check and verify some day. I am also planning to gather information on the fonts mechanics and what goes under the hood when machines display letters in word processors and applications.

So I just copied /downloaded these hindi fonts to my /users/rjha94/library/fonts folder. Then i opened safari menu, clicked on preferences and then appearance tab. Click on select button to the right of fonts name being displayed. Your font book will open. Add a suitable hindi font to your Font Book and tell safari to use it. thats all you need to do. The process is explained in detail on alanwood.net unicode pages. (an excellent resource)
Time to reload BBC hindi page. Guess what! Now i can see Hindi but this is not the hindi i know. All the matras have gone for a toss and it does not looks good. No self respecting guy would call this hindi. what to do ? I showed the page to my mother and she said , " reading hindi on computer is very difficult ".
So i was stuck with bad fonts. Funny fact is the very same mangal font was rendering the same site on my win xp box quite nicely. I would like to investigate this issue some day. And then i realized my mistake. That i actually have an install DVD and *not* an install CD for mac os X. This article from apple shows how to install packages from install DVD

So the processof making hindi work for you on mac OS X is actually very simple.
only one step to do (and no step if it was done during mac os x installation time itself)
+ install additional languages package
+ open hindi site in safari.
Question is how does safari decide what fonts to pick for display ? suppose i have multiple hindi fonts installed on my system , how do i tell my browser to pick the righ one ? Righ now,i have just taken a short cut and deleted all hindi fonts but those installed by apple.

Finally a nicely rendered BBC hindi site :o)
why safari and why not firefox ? Can i view all the hindi websites today ? answers in the next blog.

This page is powered by Blogger. Isn't yours?