Thursday, June 19, 2008

Adding Fonts in Linux to X Font Subsystem

This weekend, a new problem came my way.The problem may seem too small, but of wide implications where a customer-related environment is involved.We had installed linux to support the developer community in our organization,I had to attend to varied levels of problems in these machines which gave me ample opportunity to play with networking,applications,libraries,configurations in enterprise linux systems.All these machines were Red Hat Enterprise Linux v3 or 4. Lets come to what exactly it is.

We know that Openoffice is the standard Office application in linux and it draws font information from the installed fonts of the system.Here the root of the problem is that during installation, the language support in the OS was limited to US English and only its fonts were installed.

Now, the developers had a new area of work in a new project which made them to deal with documents encoded in Japanese.These were confidential data.The developer needed to decode the data using some online translator page from Excite or Google.But, when they opened the document,Japanese characters were not visible at all.


So,I had come right into this scene assuming that Japanese Language support has to be turned on either in the OS or in the application.First, i tried with enabling Japanese support in Openoffice.For that, you have to just turn on 'Asian Languages' support from Tools > Options.(Click on image for a detailed screenshot)



But from there itself, the problem was still visible for me.Under the new Japanese font support subsystem, no new fonts were visible.This meant that in the system, Japanese fonts were not installed.Also, the display of characters at the Japanese font part in the documents was still blank.

I tried restarting application and later, the OS at-large anticipating any change...but all in vain.
Now what is the course to be taken ?


Of course...download a Japanese font and install it to the OS.For that, i set out on google search .At last, i came to Wazu Japan's Gallery of Japanese Unicode fonts which were open (http://www.wazu.jp/gallery/Fonts_Japanese.html).I downloaded a less painful ttf font called Mona which was encoded in Japanese Font subsystem.

Now...what if the format of fonts were not supported in Linux.For that also, i went on to an extensive search.Lastly, i came to a convincible method to add fonts support to linux at a CentOS page.But most of the configuration in CentOS is supported in Enterprise Linux also.


To install the font, the procedure is as follows(This is for the Core X Font Subsystem):

1. Download the font to directories /usr/share/fonts and Create the /usr/share/fonts/local/ directory (if it does not already exist):

# mkdir /usr/share/fonts/local/


2. Copy the new font file into /usr/share/fonts/local/


3. Update the font information by issuing the following commands (note that, due to formatting restrictions, the following commands may appear on more than one line; in use, each commands should be entered on a single line):


# ttmkfdir -d /usr/share/fonts/local/ -o /usr/share/fonts/local/fonts.scale
mkfontdir /usr/share/fonts/local/

4. If you had to create /usr/share/fonts/local/, you must then add it to the X font server (xfs) path:

# chkfontpath --add /usr/share/fonts/local/

5. Adding new fonts to the fontconfig font subsystem is more straightforward; the new font file only needs to be copied into the /usr/share/fonts/ directory (individual users can modify their personal font configuration by copying the font file into the ~/.fonts/ directory).


6. After the new font has been copied, use fc-cache to update the font information cache:
fc-cache

# fc-cache <directory>

(Where directory would be either the /usr/share/fonts/ or ~/.fonts/ directories.)


Individual users may also install fonts graphically, by browsing fonts:/// in Nautilus, and dragging the new font files there.


NOTE: If the font filename ends with ".gz", it has been compressed with gzip, and must be decompressed (with the gunzip command) before the fontconfig font subsystem can use the font. Now,what did i see when i started Office once again, new font was listed under 'Fonts'

Epilogue:

The Japanese characters were visible now in both Openoffice Writer and Impress and it came under 'Fonts' in the Text Toolbar.




User could now easily start testing translations on Google Translator by copying the text directly from Openoffice Impress.

Please refer to XFont Subsystem documentation in Linux for major ideas involved in this article