removed
[ikiwiki.git] / docs / handbook / handbook-x-fonts.mdwn
1
2 ----
3
4
5
6 # 5.5 Using Fonts in X11 
7
8
9
10  ***Contributed by Murray Stokely. ***
11
12
13
14 ## 5.5.1 Type1 Fonts 
15
16
17
18  The default fonts that ship with X11 are less than ideal for typical desktop publishing applications. Large presentation fonts show up jagged and unprofessional looking, and small fonts in  **Netscape®**  are almost completely unintelligible. However, there are several free, high quality Type1 (Post***Script®) fonts available which can be readily used with X11. For instance, the Freefonts collection (['fonts/freefonts'](http://pkgsrc.se/fonts/freefonts)) includes a lot of fonts, but most of them are intended for use in graphics software such as the  **Gimp** , and are not complete enough to serve as screen fonts. In addition, X11 can be configured to use True***Type® fonts with a minimum of effort. For more details on this, see the [X(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=X&section=7) manual page or the [ section on TrueType fonts](x-fonts.html#TRUETYPE).
19
20
21
22  To install the Freefonts font collection from the pkgsrc framework, run the following commands:
23
24
25
26      
27
28     # cd /usr/pkgsrc/fonts/freefonts
29
30     # bmake install clean
31
32
33
34
35
36  And likewise with the other collections. To have the X server detect these fonts, add an appropriate line to the X server configuration file in `/etc/X11/xorg.conf`, which reads:
37
38
39
40      
41
42     FontPath "/usr/pkg/lib/X11/fonts/freefont/"
43
44
45
46
47
48  Alternatively, at the command line in the X session run:
49
50
51
52      
53
54     % xset fp+ /usr/pkg/lib/X11/fonts/freefont/
55
56     % xset fp rehash
57
58
59
60
61
62  This will work but will be lost when the X session is closed, unless it is added to the startup file (`~/.xinitrc` for a normal `startx` session, or `~/.xsession` when logging in through a graphical login manager like  **XDM** ). A third way is to use the new `/usr/pkg/xorg/etc/fonts/local.conf` file: see the section on [ anti-aliasing](x-fonts.html#ANTIALIAS).
63
64
65
66 ## 5.5.2 TrueType® Fonts 
67
68
69
70   **X.org**  has built in support for rendering True***Type fonts. There are two different modules that can enable this functionality. The freetype module is used in this example because it is more consistent with the other font rendering back-ends. To enable the freetype module just add the following line to the `"Module"` section of the `/etc/X11/xorg.conf` file.
71
72
73
74      
75
76     Load  "freetype"
77
78
79
80
81
82  Now make a directory for the True***Type fonts (for example, `/usr/pkg/xorg/lib/X11/fonts/TrueType`) and copy all of the True***Type fonts into this directory. Keep in mind that True***Type fonts cannot be directly taken from a Macintosh®; they must be in UNIX®/MS-DOS®/Windows® format for use by X11. Once the files have been copied into this directory, use  **ttmkfdir**  to create a `fonts.dir` file, so that the X font renderer knows that these new files have been installed. 'ttmkfdir' is available from the pkgsrc framework as [`fonts/ttmkfdir2`](http://pkgsrc.se/fonts/ttmkfdir2).
83
84
85
86      
87
88     # cd /usr/pkg/xorg/lib/X11/fonts/TrueType
89
90     # ttmkfdir -o fonts.dir
91
92
93
94
95
96  Now add the True***Type directory to the font path. This is just the same as described above for [ Type1](x-fonts.html#TYPE1) fonts, that is, use
97
98
99
100     
101
102     % xset fp+ /usr/pkg/xorg/lib/X11/fonts/TrueType
103
104     % xset fp rehash
105
106
107
108
109
110  or add a `FontPath` line to the `xorg.conf` file.
111
112
113
114  That's it. Now  **Netscape** ,  **Gimp** , ***'Star***Office™***', and all of the other X applications should now recognize the installed True***Type fonts. Extremely small fonts (as with text in a high resolution display on a web page) and extremely large fonts (within  **Star`Office** ) will look much better now.
115
116
117
118 ## 5.5.3 Anti-Aliased Fonts 
119
120
121
122  ***Updated by Joe Marcus Clarke. ***
123
124
125
126  Anti-aliasing has been available in X11 since  **XFree86**  4.0.2. However, font configuration was cumbersome before the introduction of  **XFree86**  4.3.0. Beginning with  **XFree86**  4.3.0, all fonts in X11 that are found in `/usr/pkg/xorg/lib/X11/fonts/` and `~/.fonts/` are automatically made available for anti-aliasing to Xft-aware applications. Not all applications are Xft-aware, but many have received Xft support. Examples of Xft-aware applications include Qt 2.3 and higher (the toolkit for the  **KDE**  desktop), GTK+ 2.0 and higher (the toolkit for the  **GNOME**  desktop), and  **Mozilla**  1.2 and higher.
127
128
129
130  In order to control which fonts are anti-aliased, or to configure anti-aliasing properties, create (or edit, if it already exists) the file `/usr/pkg/xorg/lib/etc/fonts/local.conf`. Several advanced features of the Xft font system can be tuned using this file; this section describes only some simple possibilities. For more details, please see [fonts-conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=fonts-conf&section=5).
131
132
133
134  This file must be in XML format. Pay careful attention to case, and make sure all tags are properly closed. The file begins with the usual XML header  followed by a DOCTYPE definition, and then the `<fontconfig>` tag:
135
136
137
138      
139
140           <?xml version="1.0"?>;
141
142           <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
143
144           <fontconfig>
145
146
147
148
149
150  As previously stated, all fonts in `/usr/pkg/xorg/lib/X11/fonts/` as well as `~/.fonts/` are already made available to Xft-aware applications. If you wish to add another directory outside of these two directory trees, add a line similar to the following to `/usr/pkg/lib/etc/fonts/local.conf`:
151
152
153
154      
155
156     <dir>/path/to/my/fonts</dir>;
157
158
159
160
161
162  After adding new fonts, and especially new font directories, you should run the following command to rebuild the font caches:
163
164
165
166      
167
168     # fc-cache -f
169
170
171
172
173
174  Anti-aliasing makes borders slightly fuzzy, which makes very small text more readable and removes "staircases" from large text, but can cause eyestrain if applied to normal text. To exclude font sizes smaller than 14 point from anti-aliasing, include these lines:
175
176
177
178      
179
180             <match target="font">
181
182                 <test name#"size" compare"less">
183
184                     <double>14</double>
185
186                 </test>
187
188                 <edit name#"antialias" mode"assign">
189
190                     <bool>false</bool>
191
192                 </edit>
193
194             </match>
195
196             <match target="font">
197
198                 <test name#"pixelsize" compare"less" qual="any">
199
200                     <double>14</double>
201
202                 </test>
203
204                 <edit mode#"assign" name"antialias">
205
206                     <bool>false</bool>
207
208                 </edit>
209
210             </match>
211
212
213
214
215
216  Spacing for some monospaced fonts may also be inappropriate with anti-aliasing. This seems to be an issue with  **KDE** , in particular. One possible fix for this is to force the spacing for such fonts to be 100. Add the following lines:
217
218
219
220      
221
222            <match target#"pattern" name"family">
223
224                <test qual#"any" name"family">
225
226                    <string>fixed</string>
227
228                </test>
229
230                <edit name#"family" mode"assign">
231
232                    <string>mono</string>
233
234                </edit>
235
236             </match>
237
238             <match target#"pattern" name"family">
239
240                 <test qual#"any" name"family">
241
242                     <string>console</string>
243
244                 </test>
245
246                 <edit name#"family" mode"assign">
247
248                     <string>mono</string>
249
250                 </edit>
251
252             </match>
253
254
255
256
257
258  (this aliases the other common names for fixed fonts as `"mono"`), and then add:
259
260
261
262      
263
264              <match target#"pattern" name"family">
265
266                  <test qual#"any" name"family">
267
268                      <string>mono</string>
269
270                  </test>
271
272                  <edit name#"spacing" mode"assign">
273
274                      <int>100</int>
275
276                  </edit>
277
278              </match>
279
280
281
282
283
284  Certain fonts, such as Helvetica, may have a problem when anti-aliased. Usually this manifests itself as a font that seems cut in half vertically. At worst, it may cause applications such as  **Mozilla**  to crash. To avoid this, consider adding the following to `local.conf`:
285
286
287
288      
289
290              <match target#"pattern" name"family">
291
292                  <test qual#"any" name"family">
293
294                      <string>Helvetica</string>
295
296                  </test>
297
298                  <edit name#"family" mode"assign">
299
300                      <string>sans-serif</string>
301
302                  </edit>
303
304              </match>
305
306
307
308
309
310  Once you have finished editing `local.conf` make sure you end the file with the `</fontconfig>` tag. Not doing this will cause your changes to be ignored.
311
312
313
314  The default font set that comes with X11 is not very desirable when it comes to anti-aliasing. A much better set of default fonts can be found in the ['fonts/vera-ttf'](http://pkgsrc.se/fonts/vera-ttf) port. This port will install a `/usr/pkg/lib/etc/fonts/local.conf` file if one does not exist already. If the file does exist, the port will create a `/usr/pkg/lib/etc/fonts/local.conf-vera ` file. Merge the contents of this file into `/usr/pkg/lib/etc/fonts/local.conf`, and the Bitstream fonts will automatically replace the default X11 Serif, Sans Serif, and Monospaced fonts.
315
316
317
318  Finally, users can add their own settings via their personal `.fonts.conf` files. To do this, each user should simply create a `~/.fonts.conf`. This file must also be in XML format.
319
320
321
322  One last point: with an LCD screen, sub-pixel sampling may be desired. This basically treats the (horizontally separated) red, green and blue components separately to improve the horizontal resolution; the results can be dramatic. To enable this, add the line somewhere in the `local.conf` file:
323
324
325
326      
327
328              <match target="font">
329
330                  <test qual#"all" name"rgba">
331
332                      <const>unknown</const>
333
334                  </test>
335
336                  <edit name#"rgba" mode"assign">
337
338                      <const>rgb</const>
339
340                  </edit>
341
342              </match>
343
344
345
346
347
348    **Note:** Depending on the sort of display, `rgb` may need to be changed to `bgr`, `vrgb` or `vbgr`: experiment and see which works best.
349
350
351
352
353
354  Anti-aliasing should be enabled the next time the X server is started. However, programs must know how to take advantage of it. At present, the Qt toolkit does, so the entire  **KDE**  environment can use anti-aliased fonts. GTK+ and  **GNOME**  can also be made to use anti-aliasing via the "Font" capplet (see [x11-wm.html#X11-WM-GNOME-ANTIALIAS Section 5.7.1.3] for details). By default,  **Mozilla**  1.2 and greater will automatically use anti-aliasing. To disable this, rebuild  **Mozilla**  with the `-DWITHOUT_XFT` flag.
355
356
357
358 ----
359
360
361