Developers' Guide to Defoma
Chapter 1 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.
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
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.
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.
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.
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.
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.
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.
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.