Thursday, January 17, 2008

Font Manager and GNUstep Backend

Since a few font-related things were brought up in the previous article, there is a GNUstep application, Font Manager, to view installed fonts in the system. To download it from svn, execute this:

svn co http://svn.gna.org/svn/etoile/trunk/Etoile/Services/User/FontManager FontManager



You can see a list of fonts in the system and preview text with different fonts, sizes and colours. Different styles of the same font is grouped together. It is quite convenient to see them all and pick the good ones to use. Then where is the font name to be used in user defaults of NSFont and NSPreferredFonts as in previous article ? To know the answer, you need to know which GNUstep backend you are using.

GNUstep provides different backends to draw text and graphics. The default one is art backend and the alternative one is cairo backend. If you install GNUstep without knowing anything about backend, you probably have art backend. By default, you will see only one font in Font Manager, Helvetica, unless you install extra ones as in previous article. Art backend use nfont package as discussed here. If you look into nfont package, you will find a file FontInfo.plist. For each style (face) of font, there is a corresponding PostScriptName. This PostScriptName is the name you will use in NSFont and NSPreferredFonts.

Cairo backend use fontconfig instead of nfont package. In this way, it shares fonts with X window. The font name to use in user defaults is less obvious. You can try the name listed under Fonts in Font Manager or the name in the preview panel on the most right. The rule of thumb is that if you want to use normal font, do not add Roman in font name. If you do want bold or italic font, you should use the name on the preview panel containing Bold, Italic, or others.

To show the difference, this is the screenshot from art backend:

FontManager-1

And this is from cairo backend:

FontManager-2

While cairo backend handles graphics better, art backend does supports ligature nicely.

For advanced users, you can switch between backends easily. As mentioned in INSTALL of gnustep-back, you can install art backend and cairo backend side-by-side:

./configure --enable-graphics=art --with-name=art; make; sudo make install

./configure --enable-graphics=cairo --with-name=cairo; make; sudo make install

Then you can select backend with

defaults write NSGlobalDomain GSBackend libgnustep-cairo

or

defaults write NSGlobalDomain GSBackend libgnustep-art

If you specify fonts for NSFont or NSPreferredFonts, remember that these two backends may use different font name. Therefore, you may get warnings about missing font when you switch from one backend to another.

Font Manager works on both Mac OS X (Cocoa) and GNUstep. It plans to support font enable and disable. It may be challenging because Cocoa, art backend and cairo backend all use different mechanism to manage fonts.



Previous articles in this series:

  • Gomoku and Localization in GNUstep


  • No comments: