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