]> git.wh0rd.org - fontconfig.git/blob - doc/fontconfig-user.sgml
Rework documentation to build man pages for each function
[fontconfig.git] / doc / fontconfig-user.sgml
1 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
2 <!--
3 $Id$
4
5 Copyright © 2003 Keith Packard
6
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
11 documentation, and that the name of Keith Packard not be used in
12 advertising or publicity pertaining to distribution of the software without
13 specific, written prior permission. Keith Packard makes no
14 representations about the suitability of this software for any purpose. It
15 is provided "as is" without express or implied warranty.
16
17 KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23 PERFORMANCE OF THIS SOFTWARE.
24 -->
25 <refentry>
26 <refmeta>
27 <refentrytitle>fonts.conf</refentrytitle>
28 <manvolnum>5</manvolnum>
29 </refmeta>
30 <refnamediv>
31 <refname>fonts.conf</refname>
32 <refpurpose>Font configuration files</refpurpose>
33 </refnamediv>
34 <refsynopsisdiv>
35 <synopsis>
36 /etc/fonts/fonts.conf
37 /etc/fonts/fonts.dtd
38 ~/.fonts.conf
39 </synopsis>
40 </refsynopsisdiv>
41 <refsect1><title>DESCRIPTION</title>
42 <para>
43 Fontconfig is a library designed to provide system-wide font configuration,
44 customization and application access.
45 </para>
46 </refsect1>
47 <refsect1><title>FUNCTIONAL OVERVIEW</title>
48 <para>
49 Fontconfig contains two essential modules, the configuration module which
50 builds an internal configuration from XML files and the matching module
51 which accepts font patterns and returns the nearest matching font.
52 </para>
53 <refsect2><title>FONT CONFIGURATION</title>
54 <para>
55 The configuration module consists of the FcConfig datatype, libexpat and
56 FcConfigParse which walks over an XML tree and ammends a configuration with
57 data found within. From an external perspective, configuration of the
58 library consists of generating a valid XML tree and feeding that to
59 FcConfigParse. The only other mechanism provided to applications for
60 changing the running configuration is to add fonts and directories to the
61 list of application-provided font files.
62 </para><para>
63 The intent is to make font configurations relatively static, and shared by
64 as many applications as possible. It is hoped that this will lead to more
65 stable font selection when passing names from one application to another.
66 XML was chosen as a configuration file format because it provides a format
67 which is easy for external agents to edit while retaining the correct
68 structure and syntax.
69 </para><para>
70 Font configuration is separate from font matching; applications needing to
71 do their own matching can access the available fonts from the library and
72 perform private matching. The intent is to permit applications to pick and
73 choose appropriate functionality from the library instead of forcing them to
74 choose between this library and a private configuration mechanism. The hope
75 is that this will ensure that configuration of fonts for all applications
76 can be centralized in one place. Centralizing font configuration will
77 simplify and regularize font installation and customization.
78 </para>
79 </refsect2>
80 <refsect2>
81 <title>FONT PROPERTIES</title>
82 <para>
83 While font patterns may contain essentially any properties, there are some
84 well known properties with associated types. Fontconfig uses some of these
85 properties for font matching and font completion. Others are provided as a
86 convenience for the applications rendering mechanism.
87 </para>
88 <programlisting>
89 Property Type Description
90 --------------------------------------------------------------
91 family String Font family name
92 style String Font style. Overrides weight and slant
93 slant Int Italic, oblique or roman
94 weight Int Light, medium, demibold, bold or black
95 size Double Point size
96 aspect Double Stretches glyphs horizontally before hinting
97 pixelsize Double Pixel size
98 spacing Int Proportional, monospace or charcell
99 foundry String Font foundry name
100 antialias Bool Whether glyphs can be antialiased
101 hinting Bool Whether the rasterizer should use hinting
102 verticallayout Bool Use vertical layout
103 autohint Bool Use autohinter instead of normal hinter
104 globaladvance Bool Use font global advance data
105 file String The filename holding the font
106 index Int The index of the font within the file
107 ftface FT_Face Use the specified FreeType face object
108 rasterizer String Which rasterizer is in use
109 outline Bool Whether the glyphs are outlines
110 scalable Bool Whether glyphs can be scaled
111 scale Double Scale factor for point->pixel conversions
112 dpi Double Target dots per inch
113 rgba Int unknown, rgb, bgr, vrgb, vbgr,
114 none - subpixel geometry
115 minspace Bool Eliminate leading from line spacing
116 charset CharSet Unicode chars encoded by the font
117 lang String List of RFC-3066-style languages this
118 font supports
119 </programlisting>
120 </refsect2>
121 <refsect2>
122 <title>FONT MATCHING</title>
123 <para>
124 Fontconfig performs matching by measuring the distance from a provided
125 pattern to all of the available fonts in the system. The closest matching
126 font is selected. This ensures that a font will always be returned, but
127 doesn't ensure that it is anything like the requested pattern.
128 </para><para>
129 Font matching starts with an application constructed pattern. The desired
130 attributes of the resulting font are collected together in a pattern. Each
131 property of the pattern can contain one or more values; these are listed in
132 priority order; matches earlier in the list are considered "closer" than
133 matches later in the list.
134 </para><para>
135 The initial pattern is modified by applying the list of editing instructions
136 specific to patterns found in the configuration; each consists of a match
137 predicate and a set of editing operations. They are executed in the order
138 they appeared in the configuration. Each match causes the associated
139 sequence of editing operations to be applied.
140 </para><para>
141 After the pattern has been edited, a sequence of default substitutions are
142 performed to canonicalize the set of available properties; this avoids the
143 need for the lower layers to constantly provide default values for various
144 font properties during rendering.
145 </para><para>
146 The canonical font pattern is finally matched against all available fonts.
147 The distance from the pattern to the font is measured for each of several
148 properties: foundry, charset, family, lang, spacing, pixelsize, style,
149 slant, weight, antialias, rasterizer and outline. This list is in priority
150 order -- results of comparing earlier elements of this list weigh more
151 heavily than later elements.
152 </para><para>
153 There is one special case to this rule; family names are split into two
154 bindings; strong and weak. Strong family names are given greater precedence
155 in the match than lang elements while weak family names are given lower
156 precedence than lang elements. This permits the document language to drive
157 font selection when any document specified font is unavailable.
158 </para><para>
159 The pattern representing that font is augmented to include any properties
160 found in the pattern but not found in the font itself; this permits the
161 application to pass rendering instructions or any other data through the
162 matching system. Finally, the list of editing instructions specific to
163 fonts found in the configuration are applied to the pattern. This modified
164 pattern is returned to the application.
165 </para><para>
166 The return value contains sufficient information to locate and rasterize the
167 font, including the file name, pixel size and other rendering data. As
168 none of the information involved pertains to the FreeType library,
169 applications are free to use any rasterization engine or even to take
170 the identified font file and access it directly.
171 </para><para>
172 The match/edit sequences in the configuration are performed in two passes
173 because there are essentially two different operations necessary -- the
174 first is to modify how fonts are selected; aliasing families and adding
175 suitable defaults. The second is to modify how the selected fonts are
176 rasterized. Those must apply to the selected font, not the original pattern
177 as false matches will often occur.
178 </para>
179 </refsect2>
180 <refsect2><title>FONT NAMES</title>
181 <para>
182 Fontconfig provides a textual representation for patterns that the library
183 can both accept and generate. The representation is in three parts, first a
184 list of family names, second a list of point sizes and finally a list of
185 additional properties:
186 </para>
187 <programlisting>
188 &lt;families&gt;-&lt;point sizes&gt;:&lt;name1&gt;=&lt;values1&gt;:&lt;name2&gt;=&lt;values2&gt;...
189 </programlisting>
190 <para>
191 Values in a list are separated with commas. The name needn't include either
192 families or point sizes; they can be elided. In addition, there are
193 symbolic constants that simultaneously indicate both a name and a value.
194 Here are some examples:
195 </para>
196 <programlisting>
197 Name Meaning
198 ----------------------------------------------------------
199 Times-12 12 point Times Roman
200 Times-12:bold 12 point Times Bold
201 Courier:italic Courier Italic in the default size
202 Monospace:matrix=1 .1 0 1 The users preferred monospace font
203 with artificial obliquing
204 </programlisting>
205 </refsect2>
206 </refsect1>
207 <refsect1><title>LANG TAGS</title>
208 <para>
209 Each font in the database contains a list of languages it supports. This is
210 computed by comparing the Unicode coverage of the font with the orthography
211 of each language. Languages are tagged using an RFC-3066 compatible naming
212 and occur in two parts -- the ISO639 language tag followed a hyphen and then
213 by the ISO 3166 country code. The hyphen and country code may be elided.
214 </para><para>
215 Fontconfig has orthographies for several languages built into the library.
216 No provision has been made for adding new ones aside from rebuilding the
217 library. It currently supports 122 of the 139 languages named in ISO 639-1,
218 141 of the languages with two-letter codes from ISO 639-2 and another 30
219 languages with only three-letter codes.
220 </para>
221 </refsect1>
222 <refsect1><title>CONFIGURATION FILE FORMAT</title>
223 <para>
224 Configuration files for fontconfig are stored in XML format; this
225 format makes external configuration tools easier to write and ensures that
226 they will generate syntactically correct configuration files. As XML
227 files are plain text, they can also be manipulated by the expert user using
228 a text editor.
229 </para><para>
230 The fontconfig document type definition resides in the external entity
231 "fonts.dtd"; this is normally stored in the default font configuration
232 directory (/etc/fonts). Each configuration file should contain the
233 following structure:
234 <programlisting>
235 &lt;?xml version="1.0"?&gt;
236 &lt;!DOCTYPE fontconfig SYSTEM "fonts.dtd"&gt;
237 &lt;fontconfig&gt;
238 ...
239 &lt;/fontconfig&gt;
240 </programlisting>
241 </para>
242 <refsect2><title><literal>&lt;fontconfig&gt;</literal></title><para>
243 This is the top level element for a font configuration and can contain
244 <sgmltag>dir</>, <sgmltag>cache</>, <sgmltag>include</>, <sgmltag>match</> and <sgmltag>alias</> elements in any order.
245 </para></refsect2>
246 <refsect2><title><sgmltag>dir</></title><para>
247 This element contains a directory name which will be scanned for font files
248 to include in the set of available fonts.
249 </para></refsect2>
250 <refsect2><title><sgmltag>cache</></title><para>
251 This element contains a file name for the per-user cache of font
252 information. If it starts with '~', it refers to a file in the users
253 home directory. This file is used to hold information about fonts that
254 isn't present in the per-directory cache files. It is automatically
255 maintained by the fontconfig library. The default for this file
256 is ``~/.fonts.cache-<sgmltag>version</>'', where <sgmltag>version</> is the font configuration
257 file version number (currently 1).
258 </para></refsect2>
259 <refsect2><title><sgmltag>include ignore_missing="no"</></title><para>
260 This element contains the name of an additional configuration file. When
261 the XML datatype is traversed by FcConfigParse, the contents of the file
262 will also be incorporated into the configuration by passing the filename to
263 FcConfigLoadAndParse. If 'ignore_missing' is set to "yes" instead of the
264 default "no", a missing file will elicit no warning message from the library.
265 </para></refsect2>
266 <refsect2><title><sgmltag>config</></title><para>
267 This element provides a place to consolodate additional configuration
268 information. <sgmltag>config</> can contain <sgmltag>blank</> and <sgmltag>rescan</> elements in any
269 order.
270 </para></refsect2>
271 <refsect2><title><sgmltag>blank</></title><para>
272 Fonts often include "broken" glyphs which appear in the encoding but are
273 drawn as blanks on the screen. Within the <sgmltag>blank</> element, place each
274 Unicode characters which is supposed to be blank in an <sgmltag>int</> element.
275 Characters outside of this set which are drawn as blank will be elided from
276 the set of characters supported by the font.
277 </para></refsect2>
278 <refsect2><title><sgmltag>rescan</></title><para>
279 The <sgmltag>rescan</> element holds an <sgmltag>int</> element which indicates the default
280 interval between automatic checks for font configuration changes.
281 Fontconfig will validate all of the configuration files and directories and
282 automatically rebuild the internal datastructures when this interval passes.
283 </para></refsect2>
284 <refsect2><title><sgmltag>match target="pattern"</></title><para>
285 This element holds first a (possibly empty) list of <sgmltag>test</> elements and then
286 a (possibly empty) list of <sgmltag>edit</> elements. Patterns which match all of the
287 tests are subjected to all the edits. If 'target' is set to "font" instead
288 of the default "pattern", then this element applies to the font name
289 resulting from a match rather than a font pattern to be matched.
290 </para></refsect2>
291 <refsect2><title><sgmltag>test qual="any" name="property" compare="eq"</></title><para>
292 This element contains a single value which is compared with the pattern
293 property "property" (substitute any of the property names seen
294 above). 'compare' can be one of "eq", "not_eq", "less", "less_eq", "more", or
295 "more_eq". 'qual' may either be the default, "any", in which case the match
296 succeeds if any value associated with the property matches the test value, or
297 "all", in which case all of the values associated with the property must
298 match the test value.
299 </para></refsect2>
300 <refsect2><title><sgmltag>edit name="property" mode="assign" binding="weak"</></title><para>
301 This element contains a list of expression elements (any of the value or
302 operator elements). The expression elements are evaluated at run-time and
303 modify the property "property". The modification depends on whether
304 "property" was matched by one of the associated <sgmltag>test</> elements, if so, the
305 modification may affect the first matched value. Any values inserted into
306 the property are given the indicated binding. 'mode' is one of:
307 <programlisting>
308 Mode With Match Without Match
309 ---------------------------------------------------------------------
310 "assign" Replace matching value Replace all values
311 "assign_replace" Replace all values Replace all values
312 "prepend" Insert before matching Insert at head of list
313 "prepend_first" Insert at head of list Insert at head of list
314 "append" Append after matching Append at end of list
315 "append_last" Append at end of list Append at end of list
316 </programlisting>
317 </para></refsect2>
318 <refsect2><title><sgmltag>int</>, <sgmltag>double</>, <sgmltag>string</>, <sgmltag>bool</></title><para>
319 These elements hold a single value of the indicated type. <sgmltag>bool</> elements
320 hold either true or false.
321 </para></refsect2>
322 <refsect2><title><sgmltag>matrix</></title><para>
323 This element holds the four <sgmltag>double</> elements of an affine
324 transformation.
325 </para></refsect2>
326 <refsect2><title><sgmltag>name</></title><para>
327 Holds a property name. Evaluates to the first value from the property of
328 the font, not the pattern.
329 </para></refsect2>
330 <refsect2><title><sgmltag>const</></title><para>
331 Holds the name of a constant; these are always integers and serve as
332 symbolic names for common font values:
333 <programlisting>
334 Constant Property Value
335 -------------------------------------
336 light weight 0
337 medium weight 100
338 demibold weight 180
339 bold weight 200
340 black weight 210
341 roman slant 0
342 italic slant 100
343 oblique slant 110
344 proportional spacing 0
345 mono spacing 100
346 charcell spacing 110
347 unknown rgba 0
348 rgb rgba 1
349 bgr rgba 2
350 vrgb rgba 3
351 vbgr rgba 4
352 none rgba 5
353 </programlisting>
354 </para>
355 </refsect2>
356 <refsect2>
357 <title><sgmltag>or</>, <sgmltag>and</>, <sgmltag>plus</>, <sgmltag>minus</>, <sgmltag>times</>, <sgmltag>divide</></title>
358 <para>
359 These elements perform the specified operation on a list of expression
360 elements. <sgmltag>or</> and <sgmltag>and</> are boolean, not bitwise.
361 </para>
362 </refsect2>
363 <refsect2>
364 <title><sgmltag>eq</>, <sgmltag>not_eq</>, <sgmltag>less</>, <sgmltag>less_eq</>, <sgmltag>more</>, <sgmltag>more_eq</></title>
365 <para>
366 These elements compare two values, producing a boolean result.
367 </para></refsect2>
368 <refsect2><title><sgmltag>not</></title><para>
369 Inverts the boolean sense of its one expression element
370 </para></refsect2>
371 <refsect2><title><sgmltag>if</></title><para>
372 This element takes three expression elements; if the value of the first is
373 true, it produces the value of the second, otherwise it produces the value
374 of the third.
375 </para></refsect2>
376 <refsect2><title><sgmltag>alias</></title><para>
377 Alias elements provide a shorthand notation for the set of common match
378 operations needed to substitute one font family for another. They contain a
379 <sgmltag>family</> element followed by optional <sgmltag>prefer</>, <sgmltag>accept</> and <sgmltag>default</>
380 elements. Fonts matching the <sgmltag>family</> element are edited to prepend the
381 list of <sgmltag>prefer</>ed families before the matching <sgmltag>family</>, append the
382 <sgmltag>accept</>able familys after the matching <sgmltag>family</> and append the <sgmltag>default</>
383 families to the end of the family list.
384 </para></refsect2>
385 <refsect2><title><sgmltag>family</></title><para>
386 Holds a single font family name
387 </para></refsect2>
388 <refsect2><title><sgmltag>prefer</>, <sgmltag>accept</>, <sgmltag>default</></title><para>
389 These hold a list of <sgmltag>family</> elements to be used by the <sgmltag>alias</> element.
390 <sgmltag>/article</>
391 </para></refsect2>
392 </refsect1>
393 <refsect1><title>EXAMPLE CONFIGURATION FILE</title>
394 <refsect2><title>System configuration file</title>
395 <para>
396 This is an example of a system-wide configuration file
397 </para>
398 <programlisting>
399 &lt;?xml version="1.0"?&gt;
400 &lt;!DOCTYPE fontconfig SYSTEM "fonts.dtd"&gt;
401 &lt;!-- /etc/fonts/fonts.conf file to configure system font access --&gt;
402 &lt;fontconfig&gt;
403 &lt;!--
404 Find fonts in these directories
405 --&gt;
406 &lt;dir&gt;/usr/X11R6/lib/X11/fonts/truetype&lt;/dir&gt;
407 &lt;dir&gt;/usr/X11R6/lib/X11/fonts/Type1&lt;/dir&gt;
408
409 &lt;!--
410 Accept deprecated 'mono' alias, replacing it with 'monospace'
411 --&gt;
412 &lt;match target="pattern"&gt;
413 &lt;test qual="any" name="family"&gt;&lt;string&gt;mono&lt;/string&gt;&lt;/test&gt;
414 &lt;edit name="family" mode="assign"&gt;&lt;string&gt;monospace&lt;/string&gt;&lt;/edit&gt;
415 &lt;/match&gt;
416
417 &lt;!--
418 Names not including any well known alias are given 'sans'
419 --&gt;
420 &lt;match target="pattern"&gt;
421 &lt;test qual="all" name="family" mode="not_eq"&gt;sans&lt;/test&gt;
422 &lt;test qual="all" name="family" mode="not_eq"&gt;serif&lt;/test&gt;
423 &lt;test qual="all" name="family" mode="not_eq"&gt;monospace&lt;/test&gt;
424 &lt;edit name="family" mode="append_last"&gt;&lt;string&gt;sans&lt;/string&gt;&lt;/edit&gt;
425 &lt;/match&gt;
426
427 &lt;!--
428 Load per-user customization file, but don't complain
429 if it doesn't exist
430 --&gt;
431 &lt;include ignore_missing="yes"&gt;~/.fonts.conf&lt;/include&gt;
432
433 &lt;!--
434 Alias well known font names to available TrueType fonts.
435 These substitute TrueType faces for similar Type1
436 faces to improve screen appearance.
437 --&gt;
438 &lt;alias&gt;
439 &lt;family&gt;Times&lt;/family&gt;
440 &lt;prefer&gt;&lt;family&gt;Times New Roman&lt;/family&gt;&lt;/prefer&gt;
441 &lt;default&gt;&lt;family&gt;serif&lt;/family&gt;&lt;/default&gt;
442 &lt;/alias&gt;
443 &lt;alias&gt;
444 &lt;family&gt;Helvetica&lt;/family&gt;
445 &lt;prefer&gt;&lt;family&gt;Verdana&lt;/family&gt;&lt;/prefer&gt;
446 &lt;default&gt;&lt;family&gt;sans&lt;/family&gt;&lt;/default&gt;
447 &lt;/alias&gt;
448 &lt;alias&gt;
449 &lt;family&gt;Courier&lt;/family&gt;
450 &lt;prefer&gt;&lt;family&gt;Courier New&lt;/family&gt;&lt;/prefer&gt;
451 &lt;default&gt;&lt;family&gt;monospace&lt;/family&gt;&lt;/default&gt;
452 &lt;/alias&gt;
453
454 &lt;!--
455 Provide required aliases for standard names
456 Do these after the users configuration file so that
457 any aliases there are used preferentially
458 --&gt;
459 &lt;alias&gt;
460 &lt;family&gt;serif&lt;/family&gt;
461 &lt;prefer&gt;&lt;family&gt;Times New Roman&lt;/family&gt;&lt;/prefer&gt;
462 &lt;/alias&gt;
463 &lt;alias&gt;
464 &lt;family&gt;sans&lt;/family&gt;
465 &lt;prefer&gt;&lt;family&gt;Verdana&lt;/family&gt;&lt;/prefer&gt;
466 &lt;/alias&gt;
467 &lt;alias&gt;
468 &lt;family&gt;monospace&lt;/family&gt;
469 &lt;prefer&gt;&lt;family&gt;Andale Mono&lt;/family&gt;&lt;/prefer&gt;
470 &lt;/alias&gt;
471 &lt;/fontconfig&gt;
472 </programlisting>
473 </refsect2>
474 <refsect2><title>User configuration file</title>
475 <para>
476 This is an example of a per-user configuration file that lives in
477 ~/.fonts.conf
478 </para>
479 <programlisting>
480 &lt;?xml version="1.0"?&gt;
481 &lt;!DOCTYPE fontconfig SYSTEM "fonts.dtd"&gt;
482 &lt;!-- ~/.fonts.conf for per-user font configuration --&gt;
483 &lt;fontconfig&gt;
484
485 &lt;!--
486 Private font directory
487 --&gt;
488 &lt;dir&gt;~/misc/fonts&lt;/dir&gt;
489
490 &lt;!--
491 use rgb sub-pixel ordering to improve glyph appearance on
492 LCD screens. Changes affecting rendering, but not matching
493 should always use target="font".
494 --&gt;
495 &lt;match target="font"&gt;
496 &lt;edit name="rgba" mode="assign"&gt;&lt;const&gt;rgb&lt;/const&gt;&lt;/edit&gt;
497 &lt;/match&gt;
498 &lt;/fontconfig&gt;
499 </programlisting>
500 </refsect2>
501 </refsect1>
502 <refsect1><title>FILES</title>
503 <para>
504 <emphasis>fonts.conf</emphasis>
505 contains configuration information for the fontconfig library
506 consisting of directories to look at for font information as well as
507 instructions on editing program specified font patterns before attempting to
508 match the available fonts. It is in xml format.
509 </para>
510 <para>
511 <emphasis>fonts.dtd</emphasis>
512 is a DTD that describes the format of the configuration files.
513 </para>
514 <para>
515 <emphasis>~/.fonts.conf</emphasis>
516 is the conventional location for per-user font configuration, although the
517 actual location is specified in the global fonts.conf file.
518 </para>
519 <para>
520 <emphasis> ~/.fonts.cache-*</emphasis>
521 is the conventional repository of font information that isn't found in the
522 per-directory caches. This file is automatically maintained by fontconfig.
523 </para>
524 </refsect1>
525 </refentry>