Friday Mar 20, 2009

"Can JavaFX speak my language?"


An attempt to answer two simple questions...
  • Can JavaFX speak my language?
  • How to load custom fonts in JavaFX?

There are many languages for which Java does not provide built-in support. Also you may want to use some nice custom font instead of the logical font. You may also want to ensure that the application looks fine across platforms and does not render boxes or look ugly on some platforms.

JavaFX allows you to package your font along with the application. So that you can use the font with your application and its guaranteed that the application looks fine on all platforms. Here I'll try to render some characters using my mother tongue - Malayalam. Oh! Yes! its a palindrome.

First I downloaded Malayalam font from Indix website. I'll use RRRaghuMalayalam.ttf in my application.

I copied the RRRaghuMalayalam.ttf font file under src/fontttf/fonts/ directory. fontttf is package name of the application. Next I created a mapping file - fonts.mf under src/META-INF/. In mapping file I specified a name for the font and the location of font as shown below. I named the font as Malayalam Font.

Malayalam\\ Font = /fontttf/fonts/RRRaghuMalayalam.ttf

Now the directory structure looks as shown below.

Now lets use this new font in our application. That is simple!. We can just specify the font name as "Malayalam Font". No additional settings required.

Text {
    font: Font {
        name: "Malayalam Font"
        size: 40
    }
    content: "\\u0d2e\\u0d32\\u0d2f\\u0d3e\\u0d33\\u0d02"
}

<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/FontTTF/FontTTF.js"></script>

For Applet mode, click on above image

For standalone mode

Cool! Now JavaFX can speak my language! Can it speak your language?
You need to try it out!

Source:

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_custom_fonts";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>
<script type="text/javascript"> digg_skin = 'compact'; digg_window = 'new'; </script>

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« March 2015
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today