update for rename of docs/user/DebugKernelCrashDumps.mdwn to docs/user/list/DebugKern...
[ikiwiki.git] / docs / handbook / handbook-x-fonts.mdwn
1 \r
2 ----\r
3 \r
4 # 5.5 Using Fonts in X11 \r
5 \r
6  ***Contributed by Murray Stokely. ***\r
7 \r
8 ## 5.5.1 Type1 Fonts \r
9 \r
10  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&section7) manual page or the [ section on TrueType fonts](x-fonts.html#TRUETYPE).\r
11 \r
12  To install the Freefonts font collection from the pkgsrc framework, run the following commands:\r
13 \r
14      \r
15     # cd /usr/pkgsrc/fonts/freefonts\r
16     # bmake install clean\r
17 \r
18 \r
19  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:\r
20 \r
21      \r
22     FontPath "/usr/pkg/lib/X11/fonts/freefont/"\r
23 \r
24 \r
25  Alternatively, at the command line in the X session run:\r
26 \r
27      \r
28     % xset fp+ /usr/pkg/lib/X11/fonts/freefont/\r
29     % xset fp rehash\r
30 \r
31 \r
32  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).\r
33 \r
34 ## 5.5.2 TrueType® Fonts \r
35 \r
36   **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.\r
37 \r
38      \r
39     Load  "freetype"\r
40 \r
41 \r
42  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).\r
43 \r
44      \r
45     # cd /usr/pkg/xorg/lib/X11/fonts/TrueType\r
46     # ttmkfdir -o fonts.dir\r
47 \r
48 \r
49  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\r
50 \r
51     \r
52     % xset fp+ /usr/pkg/xorg/lib/X11/fonts/TrueType\r
53     % xset fp rehash\r
54 \r
55 \r
56  or add a `FontPath` line to the `xorg.conf` file.\r
57 \r
58  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.\r
59 \r
60 ## 5.5.3 Anti-Aliased Fonts \r
61 \r
62  ***Updated by Joe Marcus Clarke. ***\r
63 \r
64  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.\r
65 \r
66  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&section5).\r
67 \r
68  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:\r
69 \r
70      \r
71           <?xml version="1.0"?>;\r
72           <!DOCTYPE fontconfig SYSTEM "fonts.dtd">\r
73           <fontconfig>\r
74 \r
75 \r
76  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`:\r
77 \r
78      \r
79     <dir>/path/to/my/fonts</dir>;\r
80 \r
81 \r
82  After adding new fonts, and especially new font directories, you should run the following command to rebuild the font caches:\r
83 \r
84      \r
85     # fc-cache -f\r
86 \r
87 \r
88  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:\r
89 \r
90      \r
91             <match target="font">\r
92                 <test name#"size" compare"less">\r
93                     <double>14</double>\r
94                 </test>\r
95                 <edit name#"antialias" mode"assign">\r
96                     <bool>false</bool>\r
97                 </edit>\r
98             </match>\r
99             <match target="font">\r
100                 <test name#"pixelsize" compare"less" qual="any">\r
101                     <double>14</double>\r
102                 </test>\r
103                 <edit mode#"assign" name"antialias">\r
104                     <bool>false</bool>\r
105                 </edit>\r
106             </match>\r
107 \r
108 \r
109  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:\r
110 \r
111      \r
112            <match target#"pattern" name"family">\r
113                <test qual#"any" name"family">\r
114                    <string>fixed</string>\r
115                </test>\r
116                <edit name#"family" mode"assign">\r
117                    <string>mono</string>\r
118                </edit>\r
119             </match>\r
120             <match target#"pattern" name"family">\r
121                 <test qual#"any" name"family">\r
122                     <string>console</string>\r
123                 </test>\r
124                 <edit name#"family" mode"assign">\r
125                     <string>mono</string>\r
126                 </edit>\r
127             </match>\r
128 \r
129 \r
130  (this aliases the other common names for fixed fonts as `"mono"`), and then add:\r
131 \r
132      \r
133              <match target#"pattern" name"family">\r
134                  <test qual#"any" name"family">\r
135                      <string>mono</string>\r
136                  </test>\r
137                  <edit name#"spacing" mode"assign">\r
138                      <int>100</int>\r
139                  </edit>\r
140              </match>\r
141 \r
142 \r
143  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`:\r
144 \r
145      \r
146              <match target#"pattern" name"family">\r
147                  <test qual#"any" name"family">\r
148                      <string>Helvetica</string>\r
149                  </test>\r
150                  <edit name#"family" mode"assign">\r
151                      <string>sans-serif</string>\r
152                  </edit>\r
153              </match>\r
154 \r
155 \r
156  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.\r
157 \r
158  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.\r
159 \r
160  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.\r
161 \r
162  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:\r
163 \r
164      \r
165              <match target="font">\r
166                  <test qual#"all" name"rgba">\r
167                      <const>unknown</const>\r
168                  </test>\r
169                  <edit name#"rgba" mode"assign">\r
170                      <const>rgb</const>\r
171                  </edit>\r
172              </match>\r
173 \r
174 \r
175    **Note:** Depending on the sort of display, `rgb` may need to be changed to `bgr`, `vrgb` or `vbgr`: experiment and see which works best.\r
176 \r
177 \r
178  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.\r
179 \r
180 ----\r
181 \r