fontconfig-user.txt revision a6844aab
1fonts-conf
2
3Name
4
5fonts.conf -- Font configuration files
6
7Synopsis
8
9   /etc/fonts/fonts.conf
10   /etc/fonts/fonts.dtd
11   /etc/fonts/conf.d
12   ~/.fonts.conf.d
13   ~/.fonts.conf
14
15Description
16
17Fontconfig is a library designed to provide system-wide font configuration,
18customization and application access.
19
20Functional Overview
21
22Fontconfig contains two essential modules, the configuration module which
23builds an internal configuration from XML files and the matching module which
24accepts font patterns and returns the nearest matching font.
25
26Font Configuration
27
28The configuration module consists of the FcConfig datatype, libexpat and
29FcConfigParse which walks over an XML tree and amends a configuration with data
30found within. From an external perspective, configuration of the library
31consists of generating a valid XML tree and feeding that to FcConfigParse. The
32only other mechanism provided to applications for changing the running
33configuration is to add fonts and directories to the list of
34application-provided font files.
35
36The intent is to make font configurations relatively static, and shared by as
37many applications as possible. It is hoped that this will lead to more stable
38font selection when passing names from one application to another. XML was
39chosen as a configuration file format because it provides a format which is
40easy for external agents to edit while retaining the correct structure and
41syntax.
42
43Font configuration is separate from font matching; applications needing to do
44their own matching can access the available fonts from the library and perform
45private matching. The intent is to permit applications to pick and choose
46appropriate functionality from the library instead of forcing them to choose
47between this library and a private configuration mechanism. The hope is that
48this will ensure that configuration of fonts for all applications can be
49centralized in one place. Centralizing font configuration will simplify and
50regularize font installation and customization.
51
52Font Properties
53
54While font patterns may contain essentially any properties, there are some well
55known properties with associated types. Fontconfig uses some of these
56properties for font matching and font completion. Others are provided as a
57convenience for the applications' rendering mechanism.
58
59  Property        Type    Description
60  --------------------------------------------------------------
61  family          String  Font family names
62  familylang      String  Languages corresponding to each family
63  style           String  Font style. Overrides weight and slant
64  stylelang       String  Languages corresponding to each style
65  fullname        String  Font full names (often includes style)
66  fullnamelang    String  Languages corresponding to each fullname
67  slant           Int     Italic, oblique or roman
68  weight          Int     Light, medium, demibold, bold or black
69  size            Double  Point size
70  width           Int     Condensed, normal or expanded
71  aspect          Double  Stretches glyphs horizontally before hinting
72  pixelsize       Double  Pixel size
73  spacing         Int     Proportional, dual-width, monospace or charcell
74  foundry         String  Font foundry name
75  antialias       Bool    Whether glyphs can be antialiased
76  hinting         Bool    Whether the rasterizer should use hinting
77  hintstyle       Int     Automatic hinting style
78  verticallayout  Bool    Use vertical layout
79  autohint        Bool    Use autohinter instead of normal hinter
80  globaladvance   Bool    Use font global advance data
81  file            String  The filename holding the font
82  index           Int     The index of the font within the file
83  ftface          FT_Face Use the specified FreeType face object
84  rasterizer      String  Which rasterizer is in use
85  outline         Bool    Whether the glyphs are outlines
86  scalable        Bool    Whether glyphs can be scaled
87  scale           Double  Scale factor for point->pixel conversions
88  dpi             Double  Target dots per inch
89  rgba            Int     unknown, rgb, bgr, vrgb, vbgr,
90                          none - subpixel geometry
91  lcdfilter       Int     Type of LCD filter
92  minspace        Bool    Eliminate leading from line spacing
93  charset         CharSet Unicode chars encoded by the font
94  lang            String  List of RFC-3066-style languages this
95                          font supports
96  fontversion     Int     Version number of the font
97  capability      String  List of layout capabilities in the font
98  embolden        Bool    Rasterizer should synthetically embolden the font
99
100
101Font Matching
102
103Fontconfig performs matching by measuring the distance from a provided pattern
104to all of the available fonts in the system. The closest matching font is
105selected. This ensures that a font will always be returned, but doesn't ensure
106that it is anything like the requested pattern.
107
108Font matching starts with an application constructed pattern. The desired
109attributes of the resulting font are collected together in a pattern. Each
110property of the pattern can contain one or more values; these are listed in
111priority order; matches earlier in the list are considered "closer" than
112matches later in the list.
113
114The initial pattern is modified by applying the list of editing instructions
115specific to patterns found in the configuration; each consists of a match
116predicate and a set of editing operations. They are executed in the order they
117appeared in the configuration. Each match causes the associated sequence of
118editing operations to be applied.
119
120After the pattern has been edited, a sequence of default substitutions are
121performed to canonicalize the set of available properties; this avoids the need
122for the lower layers to constantly provide default values for various font
123properties during rendering.
124
125The canonical font pattern is finally matched against all available fonts. The
126distance from the pattern to the font is measured for each of several
127properties: foundry, charset, family, lang, spacing, pixelsize, style, slant,
128weight, antialias, rasterizer and outline. This list is in priority order --
129results of comparing earlier elements of this list weigh more heavily than
130later elements.
131
132There is one special case to this rule; family names are split into two
133bindings; strong and weak. Strong family names are given greater precedence in
134the match than lang elements while weak family names are given lower precedence
135than lang elements. This permits the document language to drive font selection
136when any document specified font is unavailable.
137
138The pattern representing that font is augmented to include any properties found
139in the pattern but not found in the font itself; this permits the application
140to pass rendering instructions or any other data through the matching system.
141Finally, the list of editing instructions specific to fonts found in the
142configuration are applied to the pattern. This modified pattern is returned to
143the application.
144
145The return value contains sufficient information to locate and rasterize the
146font, including the file name, pixel size and other rendering data. As none of
147the information involved pertains to the FreeType library, applications are
148free to use any rasterization engine or even to take the identified font file
149and access it directly.
150
151The match/edit sequences in the configuration are performed in two passes
152because there are essentially two different operations necessary -- the first
153is to modify how fonts are selected; aliasing families and adding suitable
154defaults. The second is to modify how the selected fonts are rasterized. Those
155must apply to the selected font, not the original pattern as false matches will
156often occur.
157
158Font Names
159
160Fontconfig provides a textual representation for patterns that the library can
161both accept and generate. The representation is in three parts, first a list of
162family names, second a list of point sizes and finally a list of additional
163properties:
164
165        <families>-<point sizes>:<name1>=<values1>:<name2>=<values2>...
166
167
168Values in a list are separated with commas. The name needn't include either
169families or point sizes; they can be elided. In addition, there are symbolic
170constants that simultaneously indicate both a name and a value. Here are some
171examples:
172
173  Name                            Meaning
174  ----------------------------------------------------------
175  Times-12                        12 point Times Roman
176  Times-12:bold                   12 point Times Bold
177  Courier:italic                  Courier Italic in the default size
178  Monospace:matrix=1 .1 0 1       The users preferred monospace font
179                                  with artificial obliquing
180
181
182The '\', '-', ':' and ',' characters in family names must be preceeded by a '\'
183character to avoid having them misinterpreted. Similarly, values containing '\
184', '=', '_', ':' and ',' must also have them preceeded by a '\' character. The
185'\' characters are stripped out of the family name and values as the font name
186is read.
187
188Debugging Applications
189
190To help diagnose font and applications problems, fontconfig is built with a
191large amount of internal debugging left enabled. It is controlled by means of
192the FC_DEBUG environment variable. The value of this variable is interpreted as
193a number, and each bit within that value controls different debugging messages.
194
195  Name         Value    Meaning
196  ---------------------------------------------------------
197  MATCH            1    Brief information about font matching
198  MATCHV           2    Extensive font matching information
199  EDIT             4    Monitor match/test/edit execution
200  FONTSET          8    Track loading of font information at startup
201  CACHE           16    Watch cache files being written
202  CACHEV          32    Extensive cache file writing information
203  PARSE           64    (no longer in use)
204  SCAN           128    Watch font files being scanned to build caches
205  SCANV          256    Verbose font file scanning information
206  MEMORY         512    Monitor fontconfig memory usage
207  CONFIG        1024    Monitor which config files are loaded
208  LANGSET       2048    Dump char sets used to construct lang values
209  OBJTYPES      4096    Display message when value typechecks fail
210
211
212Add the value of the desired debug levels together and assign that (in base 10)
213to the FC_DEBUG environment variable before running the application. Output
214from these statements is sent to stdout.
215
216Lang Tags
217
218Each font in the database contains a list of languages it supports. This is
219computed by comparing the Unicode coverage of the font with the orthography of
220each language. Languages are tagged using an RFC-3066 compatible naming and
221occur in two parts -- the ISO 639 language tag followed a hyphen and then by
222the ISO 3166 country code. The hyphen and country code may be elided.
223
224Fontconfig has orthographies for several languages built into the library. No
225provision has been made for adding new ones aside from rebuilding the library.
226It currently supports 122 of the 139 languages named in ISO 639-1, 141 of the
227languages with two-letter codes from ISO 639-2 and another 30 languages with
228only three-letter codes. Languages with both two and three letter codes are
229provided with only the two letter code.
230
231For languages used in multiple territories with radically different character
232sets, fontconfig includes per-territory orthographies. This includes
233Azerbaijani, Kurdish, Pashto, Tigrinya and Chinese.
234
235Configuration File Format
236
237Configuration files for fontconfig are stored in XML format; this format makes
238external configuration tools easier to write and ensures that they will
239generate syntactically correct configuration files. As XML files are plain
240text, they can also be manipulated by the expert user using a text editor.
241
242The fontconfig document type definition resides in the external entity
243"fonts.dtd"; this is normally stored in the default font configuration
244directory (/etc/fonts). Each configuration file should contain the following
245structure:
246
247        <?xml version="1.0"?>
248        <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
249        <fontconfig>
250        ...
251        </fontconfig>
252
253
254<fontconfig>
255
256This is the top level element for a font configuration and can contain <dir>,
257<cache>, <include>, <match> and <alias> elements in any order.
258
259<dir>
260
261This element contains a directory name which will be scanned for font files to
262include in the set of available fonts.
263
264<cache>
265
266This element contains a file name for the per-user cache of font information.
267If it starts with '~', it refers to a file in the users home directory. This
268file is used to hold information about fonts that isn't present in the
269per-directory cache files. It is automatically maintained by the fontconfig
270library. The default for this file is ``~/.fonts.cache-<version>'', where
271<version> is the font configuration file version number (currently 2).
272
273<include ignore_missing="no">
274
275This element contains the name of an additional configuration file or
276directory. If a directory, every file within that directory starting with an
277ASCII digit (U+0030 - U+0039) and ending with the string ``.conf'' will be
278processed in sorted order. When the XML datatype is traversed by FcConfigParse,
279the contents of the file(s) will also be incorporated into the configuration by
280passing the filename(s) to FcConfigLoadAndParse. If 'ignore_missing' is set to
281"yes" instead of the default "no", a missing file or directory will elicit no
282warning message from the library.
283
284<config>
285
286This element provides a place to consolidate additional configuration
287information. <config> can contain <blank> and <rescan> elements in any order.
288
289<blank>
290
291Fonts often include "broken" glyphs which appear in the encoding but are drawn
292as blanks on the screen. Within the <blank> element, place each Unicode
293characters which is supposed to be blank in an <int> element. Characters
294outside of this set which are drawn as blank will be elided from the set of
295characters supported by the font.
296
297<rescan>
298
299The <rescan> element holds an <int> element which indicates the default
300interval between automatic checks for font configuration changes. Fontconfig
301will validate all of the configuration files and directories and automatically
302rebuild the internal datastructures when this interval passes.
303
304<selectfont>
305
306This element is used to black/white list fonts from being listed or matched
307against. It holds acceptfont and rejectfont elements.
308
309<acceptfont>
310
311Fonts matched by an acceptfont element are "whitelisted"; such fonts are
312explicitly included in the set of fonts used to resolve list and match
313requests; including them in this list protects them from being "blacklisted" by
314a rejectfont element. Acceptfont elements include glob and pattern elements
315which are used to match fonts.
316
317<rejectfont>
318
319Fonts matched by an rejectfont element are "blacklisted"; such fonts are
320excluded from the set of fonts used to resolve list and match requests as if
321they didn't exist in the system. Rejectfont elements include glob and pattern
322elements which are used to match fonts.
323
324<glob>
325
326Glob elements hold shell-style filename matching patterns (including ? and *)
327which match fonts based on their complete pathnames. This can be used to
328exclude a set of directories (/usr/share/fonts/uglyfont*), or particular font
329file types (*.pcf.gz), but the latter mechanism relies rather heavily on
330filenaming conventions which can't be relied upon. Note that globs only apply
331to directories, not to individual fonts.
332
333<pattern>
334
335Pattern elements perform list-style matching on incoming fonts; that is, they
336hold a list of elements and associated values. If all of those elements have a
337matching value, then the pattern matches the font. This can be used to select
338fonts based on attributes of the font (scalable, bold, etc), which is a more
339reliable mechanism than using file extensions. Pattern elements include patelt
340elements.
341
342<patelt name="property">
343
344Patelt elements hold a single pattern element and list of values. They must
345have a 'name' attribute which indicates the pattern element name. Patelt
346elements include int, double, string, matrix, bool, charset and const elements.
347
348<match target="pattern">
349
350This element holds first a (possibly empty) list of <test> elements and then a
351(possibly empty) list of <edit> elements. Patterns which match all of the tests
352are subjected to all the edits. If 'target' is set to "font" instead of the
353default "pattern", then this element applies to the font name resulting from a
354match rather than a font pattern to be matched. If 'target' is set to "scan",
355then this element applies when the font is scanned to build the fontconfig
356database.
357
358<test qual="any" name="property" target="default" compare="eq">
359
360This element contains a single value which is compared with the target
361('pattern', 'font', 'scan' or 'default') property "property" (substitute any of
362the property names seen above). 'compare' can be one of "eq", "not_eq", "less",
363"less_eq", "more", or "more_eq". 'qual' may either be the default, "any", in
364which case the match succeeds if any value associated with the property matches
365the test value, or "all", in which case all of the values associated with the
366property must match the test value. When used in a <match target="font">
367element, the target= attribute in the <test> element selects between matching
368the original pattern or the font. "default" selects whichever target the outer
369<match> element has selected.
370
371<edit name="property" mode="assign" binding="weak">
372
373This element contains a list of expression elements (any of the value or
374operator elements). The expression elements are evaluated at run-time and
375modify the property "property". The modification depends on whether "property"
376was matched by one of the associated <test> elements, if so, the modification
377may affect the first matched value. Any values inserted into the property are
378given the indicated binding ("strong", "weak" or "same") with "same" binding
379using the value from the matched pattern element. 'mode' is one of:
380
381  Mode                    With Match              Without Match
382  ---------------------------------------------------------------------
383  "assign"                Replace matching value  Replace all values
384  "assign_replace"        Replace all values      Replace all values
385  "prepend"               Insert before matching  Insert at head of list
386  "prepend_first"         Insert at head of list  Insert at head of list
387  "append"                Append after matching   Append at end of list
388  "append_last"           Append at end of list   Append at end of list
389
390
391<int>, <double>, <string>, <bool>
392
393These elements hold a single value of the indicated type. <bool> elements hold
394either true or false. An important limitation exists in the parsing of floating
395point numbers -- fontconfig requires that the mantissa start with a digit, not
396a decimal point, so insert a leading zero for purely fractional values (e.g.
397use 0.5 instead of .5 and -0.5 instead of -.5).
398
399<matrix>
400
401This element holds the four <double> elements of an affine transformation.
402
403<name>
404
405Holds a property name. Evaluates to the first value from the property of the
406font, not the pattern.
407
408<const>
409
410Holds the name of a constant; these are always integers and serve as symbolic
411names for common font values:
412
413  Constant        Property        Value
414  -------------------------------------
415  thin            weight          0
416  extralight      weight          40
417  ultralight      weight          40
418  light           weight          50
419  book            weight          75
420  regular         weight          80
421  normal          weight          80
422  medium          weight          100
423  demibold        weight          180
424  semibold        weight          180
425  bold            weight          200
426  extrabold       weight          205
427  black           weight          210
428  heavy           weight          210
429  roman           slant           0
430  italic          slant           100
431  oblique         slant           110
432  ultracondensed  width           50
433  extracondensed  width           63
434  condensed       width           75
435  semicondensed   width           87
436  normal          width           100
437  semiexpanded    width           113
438  expanded        width           125
439  extraexpanded   width           150
440  ultraexpanded   width           200
441  proportional    spacing         0
442  dual            spacing         90
443  mono            spacing         100
444  charcell        spacing         110
445  unknown         rgba            0
446  rgb             rgba            1
447  bgr             rgba            2
448  vrgb            rgba            3
449  vbgr            rgba            4
450  none            rgba            5
451  lcdnone         lcdfilter       0
452  lcddefault      lcdfilter       1
453  lcdlight        lcdfilter       2
454  lcdlegacy       lcdfilter       3
455  hintnone        hintstyle       0
456  hintslight      hintstyle       1
457  hintmedium      hintstyle       2
458  hintfull        hintstyle       3
459
460
461<or>, <and>, <plus>, <minus>, <times>, <divide>
462
463These elements perform the specified operation on a list of expression
464elements. <or> and <and> are boolean, not bitwise.
465
466<eq>, <not_eq>, <less>, <less_eq>, <more>, <more_eq>
467
468These elements compare two values, producing a boolean result.
469
470<not>
471
472Inverts the boolean sense of its one expression element
473
474<if>
475
476This element takes three expression elements; if the value of the first is
477true, it produces the value of the second, otherwise it produces the value of
478the third.
479
480<alias>
481
482Alias elements provide a shorthand notation for the set of common match
483operations needed to substitute one font family for another. They contain a
484<family> element followed by optional <prefer>, <accept> and <default>
485elements. Fonts matching the <family> element are edited to prepend the list of
486<prefer>ed families before the matching <family>, append the <accept>able
487families after the matching <family> and append the <default> families to the
488end of the family list.
489
490<family>
491
492Holds a single font family name
493
494<prefer>, <accept>, <default>
495
496These hold a list of <family> elements to be used by the <alias> element.
497
498EXAMPLE CONFIGURATION FILE
499
500System configuration file
501
502This is an example of a system-wide configuration file
503
504<?xml version="1.0"?>
505<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
506<!-- /etc/fonts/fonts.conf file to configure system font access -->
507<fontconfig>
508<!--
509        Find fonts in these directories
510-->
511<dir>/usr/share/fonts</dir>
512<dir>/usr/X11R6/lib/X11/fonts</dir>
513
514<!--
515        Accept deprecated 'mono' alias, replacing it with 'monospace'
516-->
517<match target="pattern">
518        <test qual="any" name="family"><string>mono</string></test>
519        <edit name="family" mode="assign"><string>monospace</string></edit>
520</match>
521
522<!--
523        Names not including any well known alias are given 'sans'
524-->
525<match target="pattern">
526        <test qual="all" name="family" mode="not_eq">sans</test>
527        <test qual="all" name="family" mode="not_eq">serif</test>
528        <test qual="all" name="family" mode="not_eq">monospace</test>
529        <edit name="family" mode="append_last"><string>sans</string></edit>
530</match>
531
532<!--
533        Load per-user customization file, but don't complain
534        if it doesn't exist
535-->
536<include ignore_missing="yes">~/.fonts.conf</include>
537
538<!--
539        Load local customization files, but don't complain
540        if there aren't any
541-->
542<include ignore_missing="yes">conf.d</include>
543<include ignore_missing="yes">local.conf</include>
544
545<!--
546        Alias well known font names to available TrueType fonts.
547        These substitute TrueType faces for similar Type1
548        faces to improve screen appearance.
549-->
550<alias>
551        <family>Times</family>
552        <prefer><family>Times New Roman</family></prefer>
553        <default><family>serif</family></default>
554</alias>
555<alias>
556        <family>Helvetica</family>
557        <prefer><family>Arial</family></prefer>
558        <default><family>sans</family></default>
559</alias>
560<alias>
561        <family>Courier</family>
562        <prefer><family>Courier New</family></prefer>
563        <default><family>monospace</family></default>
564</alias>
565
566<!--
567        Provide required aliases for standard names
568        Do these after the users configuration file so that
569        any aliases there are used preferentially
570-->
571<alias>
572        <family>serif</family>
573        <prefer><family>Times New Roman</family></prefer>
574</alias>
575<alias>
576        <family>sans</family>
577        <prefer><family>Arial</family></prefer>
578</alias>
579<alias>
580        <family>monospace</family>
581        <prefer><family>Andale Mono</family></prefer>
582</alias>
583</fontconfig>
584
585
586User configuration file
587
588This is an example of a per-user configuration file that lives in ~/.fonts.conf
589
590<?xml version="1.0"?>
591<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
592<!-- ~/.fonts.conf for per-user font configuration -->
593<fontconfig>
594
595<!--
596        Private font directory
597-->
598<dir>~/.fonts</dir>
599
600<!--
601        use rgb sub-pixel ordering to improve glyph appearance on
602        LCD screens.  Changes affecting rendering, but not matching
603        should always use target="font".
604-->
605<match target="font">
606        <edit name="rgba" mode="assign"><const>rgb</const></edit>
607</match>
608</fontconfig>
609
610
611Files
612
613fonts.conf contains configuration information for the fontconfig library
614consisting of directories to look at for font information as well as
615instructions on editing program specified font patterns before attempting to
616match the available fonts. It is in xml format.
617
618conf.d is the conventional name for a directory of additional configuration
619files managed by external applications or the local administrator. The
620filenames starting with decimal digits are sorted in lexicographic order and
621used as additional configuration files. All of these files are in xml format.
622The master fonts.conf file references this directory in an <include> directive.
623
624fonts.dtd is a DTD that describes the format of the configuration files.
625
626~/.fonts.conf.d is the conventional name for a per-user directory of (typically
627auto-generated) configuration files, although the actual location is specified
628in the global fonts.conf file.
629
630~/.fonts.conf is the conventional location for per-user font configuration,
631although the actual location is specified in the global fonts.conf file.
632
633~/.fonts.cache-* is the conventional repository of font information that isn't
634found in the per-directory caches. This file is automatically maintained by
635fontconfig.
636
637See Also
638
639fc-cat(1), fc-cache(1), fc-list(1), fc-match(1), fc-query(1)
640
641Version
642
643Fontconfig version 2.8.0
644
645