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.

Comments:
सेब में क्या आप फ़ायर्फ़ाक्स पर हिंदी ठीक से देख पाते हैं? इसके लिए क्या करना पड़ता है? सफ़ारी में तो कोई दिक्कत नही होती है लेकिन अन्य ब्राउज़रों पर सिर्फ़ सवालिया निशान दिखते हैं।
 
Post a Comment

<< Home

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