Developers' Guide to Defoma Yasuhiro Take (take@debian.org) This document is a tutorial for Debian Developers who maintain font-related package(s). It describes what maintainers of a font package need to do to have their package support Defoma, and what maintainers of an application package accessing fonts need to do step by step. Copyright ©2001 Yasuhiro Take.

This document is free software; you may redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your opinion) any later version.

A copy of the GNU General Public License is available as /usr/share/common-licenses/GPL in the Debian GNU/Linux.

Font Package's TODO

Font packages should register their fonts to Defoma if the font may be used by various applications. Registration and Unregistration should be performed at postinst and postrm respectively of a font package, so maintainers need to edit them. In addition, each font may have various information called hints which represents its appearance and other data used to achieve appropriate configuration for a specific application, so maintainers need to generate hints.

Creating Hintfile.

Hintfile describes several fonts and their hints in a single file. Generally, registration and unregistration of fonts are performed through Hintfile, so creating one is the first step to Defoma-ize a font package.

First of all, enter a package's top directory. If the fonts of the package are located under subdirectory, please enter there, and run the following command.

defoma-hints <category> <font>... 2> hintfile

This command asks various questions for each font listed in <font> which must belong to the specified <category>, and will output Hintfile to hintfile. The hintfile will contain definitions for all the fonts.

If categories of the fonts are partly different, you must run the command and create a hintfile for each category. In other words, category of the fonts described in a single hintfile must be unified.

Note that this command sometimes fails unfortunately because hints-generating routines are not provided for some categories. Currently supported categories are cid, cmap, truetype and type1.

For example, if your font package is placed under ~/font-foo-0.1/, and the type1 fonts foo1.pfa, foo2.pfa and foo3.pfa are located at fonts/ subdirectory, please enter there and run the command like following.

cd ~/font-foo-0.1/fonts defoma-hints type1 foo1.pfa foo2.pfa foo3.pfa > hintfile

Editing Hintfile.

After creating Hintfile, you may possibly want to edit one because mechanically created hints are sometimes not enough. This section describes how to modify a hintfile and its syntax.

Hintfile may contain three elements: category declaration, font definitions and comments. Font definitions and comments are permitted to appear in a single hintfile any number of times, while category declaration must not exist more than once.

Category declaration is generally put at the beginning of a hintfile because it must be put before font definitions. Its syntax is: category <category-name>

Font definition describes one font and its hints. It starts with the begin line and ends with the end line. The begin line also specifies which font is to be defined. Lines between these two lines describes hints of the font. Hintfile must not contain more than one font definition of a single font. The syntax of font definition is: begin <font> <HintTypeA> = <hintA1> <HintTypeB> = <hintB1> <hintB2> ... end

Lines starting with `#' are considered as comments.

Following is the generated hintfile of the mentioned example. category type1 begin /path/to/foo1.pfa FontName = Foo-Regular Family = Foo Weight = Medium Shape = Upright NoSerif GeneralFamily = SansSerif Charset = ISO8859-1 Alias = Foo Priority = 30 X-FontName = -adobe-foo-medium-r-normal--0-0-0-0-p-0-iso8859-1 end begin /path/to/foo2.pfa FontName = Foo-Bold Family = Foo Weight = Bold Shape = Upright NoSerif GeneralFamily = SansSerif Charset = ISO8859-1 Alias = FooBold Priority = 30 X-FontName = -adobe-foo-bold-r-normal--0-0-0-0-p-0-iso8859-1 end begin /path/to/foo3.pfa FontName = Foo-Italic Family = Foo Weight = Medium Shape = Italic NoSerif GeneralFamily = SansSerif Charset = ISO8859-1 Alias = FooItalic Priority = 30 X-FontName = -adobe-foo-medium-i-normal--0-0-0-0-p-0-iso8859-1 end

The first thing you have to do is to change filenames of fonts to the full paths where these fonts are actually installed. Let's asuume that the font-foo.deb installs these fonts into /usr/share/fonts/type1, then the hintfile goes like this:

category type1 begin /usr/share/fonts/type1/foo1.pfa .. begin /usr/share/fonts/type1/foo2.pfa .. begin /usr/share/fonts/type1/foo3.pfa

After this necessary work done, you may want to change or add some hints. The Syntax of describing hints is: <HintType> = <hint>... where <HintType> decides what type of information is described, and <hint> is a value of the <HintType>. You can specify more than one <hint> for one <HintType> by separating them with space.

Hints include information about the appearance. This information should be correctly set to have better results of substituion by Defoma font substitution mechanism. HintTypes for appearance and their description are listed below.

Weight .. represents the weight of a font. Bold and Light are the most values for this HintType.

Width .. is either Variable or Fixed, which represents whether the width of a font varies or not.

GeneralFamily .. is a rough grouping of the appearance of a font. The values of this HintType for alphabetical fonts are Roman, SansSerif, Typewriter and Script. The values for CJK hieroglyphs are Mincho, Gothic and Maru. Symbol is the value for symbolic fonts. You can set your preferred value to this HintType if none of the above matches to your font.

Shape .. includes other appearance information like Serif/NoSerif, Upright/Italic/Oblique, and Condensed/Expanded.

In addition, essential information is also included in hints. As the word `essential' tells, this information is required for most categories. The values for some of the essential HintTypes are predefined. Following is a list of essential information.

FontName .. is a real name of the font. You should not specify more than one values to this HintType. The value should be PostScript-like font name.

Charset .. represents standards of collections of characters which the font contains. The values for this HintType is predefined and is listed below.

ISO8859-n (n = 1..15)

KOI8-R (Russian standard)

KOI8-U (Ukrainian standard)

JISX0208, JISX0212, JISX0201 (Japanese standards)

KSX1001, KSX1003 (Korean standards)

GB2312, GBK, GB18030 (Chinese (PRC) standards)

CNS11643-n (Taiwan national standard)

BIG5 (Taiwan de-facto standard)

BIG5-HKSCS (HongKong standard)

font-specific (for symbolic fonts)

ISO10646-1

UniCharset .. represents actual Charset contained by a font whose Charset is ISO10646-1. ISO10646-1 can be considered as a collection of already existing Charsets, so when Charset of a font is ISO10646-1, UniCharset should represent its actual content.

Encoding .. represents which encoding is used to access the font. Most categories do not limit the encoding, so this HintType is omitted in most cases.

Direction .. represents the direction of writing for which the glyphs of the font are for. The value is either Vertical or Horizontal.

Location .. is only used in truetype category. defoma-hints will automatically set this value, so you do not need to consider about this HintType.

Finally, additional information is also included in hints.

Alias .. represents other name(s) of the font. As the same as FontName, the value for this HintType should be PostScript-like.

Priority .. represents the degree of preference of the font. This value should be specified in an integer between 0 and 99. Generally, beautiful scalable fonts should have higher priority.

X-FontName .. is XLFD(s) of the font, if the font is used in X. Defoma doesn't take part in font configuration in X, so packages must install the font to X separately. Usually the value can be taken from .scale file.

NOTE: x-ttcidfont-conf manages configuration of TrueType and CID fonts for X through the Defoma framework, so font packages for these fonts do not or should not install the font to X separately. Instead, just register fonts to Defoma.

Transform .. controls if the font is transformed into Bold shape and/or Slanted shape. Its values are: Boldize, Slant, NotBoldize and NotSlant.

Multiple Face/Charset in a Single Font.

Some Type1 fonts contain multiple charsets in a single pfa/pfb file, and TrueType Collection fonts (.ttc) contain multiple faces in a single ttc file. It means individual hints are needed for each face/charset. To realize this, defoma provides subhints mechanism.

This is an example of a hintfile for a type1 font with multiple encoding. The font a.pfa (Helvetica) is usually accessed in ISO8859-1 encoding, but by re-encoding the font, it can also be accessed in ISO8859-2 and KOI8-R encodings. category type1 begin /font/a.pfa FaceNum = 3 Inherit = Weight Shape Width Priorty Family GeneralFamily FontName = Helvetica Charset = ISO8859-1 Weight = Medium Shape = Upright NoSerif Family = Helvetica GeneralFamily = SansSerif Priority = 20 X-FontName = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso8859-1 FontName1 = Helvetica-ISO8859-2 Charset1 = ISO8859-2 X-FontName1 = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso8859-2 FontName2 = Helvetica-KOI8-R Charset2 = KOI8-R X-FontName2 = -foo-bar-medium-r-normal--0-0-0-0-p-0-koi8-r end You will find out unfamiliar hinttype FaceNum and Inherit, and numbered hinttypes.

Non-numbered hints contain hints for the default charset ISO8859-1 in the same way as usual Type1 fonts. Hints can be inherited to subhints, and Inherit hinttype decides which hinttypes to be inherited, so hints that are common to most of the subhints like Family, Weight and Shape, you should set the hinttype Inherit.

FaceNum hinttype specifies how many subhints the hints contain. In this example, there are two subhints plus default hints, so its value is set to 3.

Numbered hints are called subhints, which consist of charset specific hints. In this example, subhints only contains FontName, Charset and X-FontName. Other important hinttypes are inherited from Non-numbered hints.

Here's another example for a Unicode Type1 font, which is usually accessed in Unicode encoding, and by re-encoding the font, it can also be accessed in ISO8859-1, ISO8859-2 and ISO8859-3. category type1 begin /font/b.pfa FaceNum = 4 Inherit = Weight Shape Width Proirty Family GeneralFamily FontName = Helvetica-Unicode Charset = ISO10646-1 UniCharset = ISO8859-1 ISO8859-2 ISO8859-3 Weight = Medium Shape = Upright NoSerif Family = Helvetica GeneralFamily = SansSerif Priority = 20 X-FontName = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso10646-1 FontName1 = Helvetica-ISO8859-1 Charset1 = ISO8859-1 X-FontName1 = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso8859-1 FontName2 = Helvetica-ISO8859-2 Charset2 = ISO8859-2 X-FontName1 = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso8859-2 FontName1 = Helvetica-ISO8859-3 Charset1 = ISO8859-3 X-FontName1 = -foo-bar-medium-r-normal--0-0-0-0-p-0-iso8859-3 end Note that the value of non-numbered Charset is ISO10646-1 and UniCharset represents what charsets the Unicode Type1 font actually consists of.

This is an example for Unicode TrueType fonts whose glyphs are correspondent to a collection of ISO8859-1, ISO8859-2 and ISO8859-3. category truetype begin /font/c.ttf FontName = Verdy-Bold Charset = ISO8859-1 ISO8859-2 ISO8859-3 ISO10646-1 UniCharset = ISO8859-1 ISO8859-2 ISO8859-3 Encoding = Unicode Location = English Slovenian Turkish Weight = Bold Shape = NoSerif GeneralFamily = SansSerif Family = Verdy end No subhint is needed to represent multiple charsets of TrueType fonts. Setting Charset to the available charsets will do.

Packaging.

Now let's build a Defoma-aware font package. To make things easier, using debhelper is strongly recommended. Following tutorial describes about a debhelper-based package.

Using dh_installdefoma.

Since defoma 0.7.0, it provides a debhelper program for defoma named dh_installdefoma. Using this program makes it much easier to defoma-ize a package.

Put the hintfile into debian/ subdirectory and name it as defoma-hints. mv fonts/hintfile debian/defoma-hints

Edit debian/rules to calldh_installdefoma in binary-indep or binary-arch phase. it may be best to add it just after dh_installdebconf. (ex: debian/rules) binary-indep: build install dh_testdir dh_testroot dh_installdebconf dh_installdefoma dh_installdocs ...

Edit debian/control to make the package depend and build-depend on defoma. (ex: debian/control) Build-Depends: defoma (>= 0.7.0) ... Depends: defoma ...

Without using dh_installdefoma.

Although using dh_installdefoma is strongly recommended, sometimes you have to do what dh_installdefoma does manually. Following lists describes this ordinal way of defoma-izing.

Put hintfile(s) into debian/ subdirectory. mv fonts/hintfile debian/

Edit the debian/rules file to install the hintfile(s) into etc/defoma/hints/ directory as <package-name>.hints. (ex: debian/rules) PKG = <package-name> DIR = `pwd`/debian/$(PKG) install: build ... install -m 644 debian/hintfile \ $(DIR)/etc/defoma/hints/$(PKG).hints

To create the etc/defoma/hints directory before actually installing the hintfile there, edit debian/dirs. (ex: debian/dirs) etc/defoma/hints

The hintfile must be a conffile, so edit debian/conffiles. (ex: debian/conffiles) /etc/defoma/hints/<package-name>.hints

Registration of fonts must be performed at postinst. Edit debian/postinst to call defoma-font with reregister-all command. NOTE that the command is not register-all. Using this command is able to not only just register fonts described in a hintfile, but also update revised hints to Defoma, so this command is used for both newly installing and upgrading purpose. (ex: debian/postinst) ... FILE='/etc/defoma/hints/<package-name>.hints' if [ "$1" = configure ]; then /usr/bin/defoma-font reregister-all $FILE fi

Unregistration of fonts must be performed at prerm when the package is going to be removed. Edit debian/prerm to call defoma-font with purge-all command. (ex: debian/prerm) ... FILE='/etc/defoma/hints/<package-name>.hints' if [ "$1" = remove ]; then /usr/bin/defoma-font purge-all $FILE fi

Edit debian/control to make the package depend on defoma. (ex: debian/control) ... Depends: defoma ...

Application Package's HOWTO

Applications that are configurable about fonts and have users configure about fonts by some means are able to achieve dynamic configuration about fonts through Defoma framework. This chapter describes how to build a Defoma-aware application package step by step.

Prepare a Defoma-configuration script. This script is provided by each application that uses the Defoma framework and configures fonts for its application. It is called whenever a font is installed or removed, so that it updates the configuration about fonts. How to write a Defoma-configuration script is not described in this document, so please refer others.

The Defoma configuration script must be put under debian/ subdirectory and its name should be <package-name>.defoma.

Edit debian/rules to call dh_installdefoma in binary-arch or binary-indep phase. (ex: debian/rules) binary-indep: build install dh_testdir dh_testroot dh_installdebconf dh_installdefoma dh_installdocs ...

FYI, dh_installdefoma actually performs the following steps.

Edit debian/rules file to install the script into usr/share/defoma/scripts. (ex: debian/rules) DIR = `pwd`/debian/<package-name> ... install: build ... install -m 644 debian/<package-name>.defoma \ $(DIR)/usr/share/defoma/scripts

Edit debian/dirs file to create usr/share/defoma/scripts and var/lib/defoma/<package-name>.d directories. (ex: debian/dirs) usr/share/defoma/scripts var/lib/defoma/<package-name>.d

When the application package is installed, the Defoma-configuration script needs to configure about installed fonts for the application. To make it possible, edit debian/postinst file to call defoma-app with update command. (ex: debian/postinst) ... if [ "$1" = configure ]; then /usr/bin/defoma-app update <package-name> fi ...

When the application package is removed/upgraded, the Defoma-configuration script needs to clean up the configuration. Edit debian/prerm file to call defoma-app with purge/clean command respectively. (ex: debian/prerm) ... if [ "$1" = remove ]; then /usr/bin/defoma-app purge <package-name> fi if [ "$1" = upgrade ]; then /usr/bin/defoma-app clean <package-name> fi ...

In addition, when the application package is removed, /var/lib/defoma/<package-name>.d directory MUST be removed without fail. Edit debian/postrm file to remove the directory. (ex: debian/postrm) ... if [ "$1" = remove ]; then /bin/rm -fr /var/lib/defoma/<package-name>.d fi ...

If the application package provides a public subst-rule (see Defoma::Subst manpage), the rulefile should be created at postinst if the rulefile doesn't exist. Edit debian/postinst file to call defoma-subst with new-rule command. It should be called before defoma-app. (ex: debian/postinst) ... if [ "$1" = configure ]; then if [ ! -f "/etc/defoma/<rulename>.subst-rule ]; then /usr/bin/defoma-subst new-rule <rulename> fi .. /usr/bin/defoma-app update <package-name> fi

Created rulefile is considered as conffile, so it must be removed when the package is purged. Edit debian/postrm file to remove the rulefile at purge. (ex: debian/postrm) ... FILE='/etc/defoma/<rulename>.subst-rule' if [ "$1" = purge ]; then /bin/rm -f $FILE $FILE˜ fi

Edit debian/control to make the package depend on defoma. (ex: debian/control) Build-Depends: defoma (>= 0.7.0) ... Depends: defoma (>= x.y.z) ... Which version to depend is decided by what function the script makes use of. See /usr/share/doc/defoma-doc/version-dependency.txt for more detail.

It is recommended to provide README.Defoma which describes categories which the script accepts and installs to, and HintTypes which the script particularly uses.