source: x/installing/tuning-fontconfig.xml@ d1d1e5d

12.1 ken/TL2024 ken/tuningfonts lazarus plabs/newcss python3.11 rahul/power-profiles-daemon trunk xry111/llvm18
Last change on this file since d1d1e5d was d1d1e5d, checked in by Ken Moffat <ken@…>, 6 months ago

Capitalize proper nouns within the page.

As a consequence, simplify 'other non-latin alphabets' to
'other alphabets' rather than 'other non-Latin alphabets'.

Correct the link to my own 'Substitute latin fonts' item, which
remains lowercase, to go directly to it and therefore make a
separate link for the font pages of that site as a whole.

  • Property mode set to 100644
File size: 34.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="tuning-fontconfig">
9 <?dbhtml filename="tuning-fontconfig.html"?>
10
11
12 <title>Tuning Fontconfig</title>
13
14 <indexterm zone="tuning-fontconfig">
15 <primary sortas="g-tuning-fontconfig">Tuning Fontconfig</primary>
16 </indexterm>
17
18 <sect2 id='fontconfig-overview' xreflabel="Overview of Fontconfig">
19 <title>Overview of Fontconfig</title>
20
21<!-- do not add individual indexterm entries for items within this page, they
22 all belong in section G (others) and not only do they add noise in longindex,
23 the links all point to the top of the page. -->
24
25 <para>
26 If you only read text in English, and are happy with the common libre
27 fonts listed on the next page, you may never need to worry about the
28 details of how <application>fontconfig</application> works. But there are
29 many things which can be altered if they do not suit your needs.
30 </para>
31
32 <para>
33 Although this page is long, it barely scratches the surface and you will
34 be able to find many alternative views on the web (but please remember
35 that some things have changed over the years, for example the autohinter
36 is no longer the default). The aim here is to give you enough information
37 to understand the changes you are making.
38 </para>
39
40 </sect2>
41
42 <sect2 role="configuration" id="xft-font-protocol" xreflabel="The Xft Font Protocol">
43 <title>The Xft Font Protocol</title>
44
45 <para>
46 The Xft font protocol provides antialiased font rendering through
47 <application>freetype</application>, and fonts are controlled from the
48 client side using <application>fontconfig</application> (except for
49 <xref linkend="rxvt-unicode"/> which can use fonts listed in
50 <filename>~/.Xresources</filename>, and <xref linkend="abiword"/> which
51 only uses the specified font). The default search path is <filename
52 class="directory">/usr/share/fonts</filename> and <filename
53 class="directory">~/.local/share/fonts</filename>, although for the moment
54 the old and deprecated location <filename
55 class="directory">~/.fonts</filename> still works.
56 <application>Fontconfig</application> searches directories in its path
57 recursively and maintains a cache of the font characteristics in each
58 directory. If the cache appears to be out of date, it is ignored, and
59 information is fetched from the fonts themselves (that can take a few
60 seconds if you have a lot of fonts installed).
61 </para>
62
63 <para>
64 If you've installed <application>Xorg</application> in any prefix
65 other than <filename class="directory">/usr</filename>, any
66 <application>X</application> fonts were not installed in a
67 location known to <application>Fontconfig</application>. Symlinks were
68 <!-- fonts-misc-ethiopic installs an OTF directory ! -->
69 created from the <filename class="directory">OTF</filename> and <filename
70 class="directory">TTF</filename> <application>X</application> font
71 directories to <filename
72 class="directory">/usr/share/fonts/X11-{OTF,TTF}</filename>. This allows
73 <application>Fontconfig</application> to use the OpenType and TrueType
74 fonts provided by <application>X</application>, although many people will
75 prefer to use more modern fonts.
76 </para>
77
78 <para>
79 <application>Fontconfig</application> uses names to define fonts.
80 Applications generally use generic font names such as "Monospace", "Sans"
81 and "Serif". <application>Fontconfig</application> resolves these names
82 to a font that has all characters that cover the orthography of the
83 language indicated by the locale settings.
84 </para>
85
86 </sect2>
87
88 <sect2 role="configuration" id="useful-commands" xreflabel="Useful Commands">
89 <title>Useful Commands</title>
90
91 <para>
92 The following commands may be helpful when working with fontconfig:
93 </para>
94
95 <para>
96 <command>fc-list | less</command> : shows a list of all available fonts
97 (/path/to/filename: Font Name:style). If you installed a font more than
98 30 seconds ago but it does not show, then it or one of its directories is
99 not readable by your user.
100 </para>
101
102 <para>
103 <command>fc-match 'Font Name'</command> : tells you which font will
104 be used if the named font is requested. Typically you would use this to
105 see what happens if a font you have not installed is requested, but you
106 can also use it if the system is giving you a different font from
107 what you expected (perhaps because <application>fontconfig</application>
108 does not think that the font supports your language).
109 </para>
110
111 <para>
112 <command>fc-match -a 'Type' | less</command> : provides a list of all
113 fonts which can be used for that type (Monospace, Sans, Serif). Note that
114 in-extremis <application>fontconfig</application> will take a glyph from
115 any available font, even if it is not of the specified type, and unless it
116 knows about the font's type it will assume it is Sans.
117 </para>
118
119 <para>
120 <command>fc-match 'Serif :lang=ja:weight=bold'</command> will tell you
121 which font and weight will be chosen for Japanese text in bold weight.
122 It does not mean that the reported font will necessarily be able to show
123 Japanese ideograms, so a fallback might be used, or some glyphs may be
124 missing.
125 </para>
126
127 <para>
128 If you wish to know which font will be used for a string of text
129 (i.e. one or more glyphs, preceded by a space), paste the following
130 command and replace the <literal>xyz</literal> by the text you care
131 about:
132 </para>
133
134 <para>
135 <command>FC_DEBUG=4 pango-view --font=monospace -t xyz | grep
136 family</command> : this requires <xref linkend="pango"/> and <xref
137 linkend="imagemagick"/> - it will invoke <xref linkend="display"/>
138 to show the text in a tiny window, and after closing that the last
139 line of the output will show which font was chosen. This is
140 particularly useful for CJK languages, and you can also pass a
141 language, e.g. PANGO_LANGUAGE=en;ja (English, then assume Japanese)
142 or just zh-cn (or other variants - 'zh' on its own is not valid).
143 </para>
144
145 </sect2>
146
147 <sect2 role="configuration" id="the-various-files" xreflabel="The various files">
148 <title>The various files</title>
149
150 <para>
151 The main files are in <filename class="directory">/etc/fonts/conf.d/</filename>,
152 which was intended to be a directory populated by symlinks to some of the files
153 in <filename class="directory">/usr/share/fontconfig/conf.avail/</filename>.
154 But many people, and some packages, create the files directly. Each file name
155 must be in the form of two digits, a dash, somename.conf and they are read in
156 sequence.
157 </para>
158
159 <para>
160 By convention, the numbers are assigned as follows:
161 </para>
162
163 <itemizedlist>
164 <listitem>
165 <para>
166 00-09 extra font directories
167 </para>
168 </listitem>
169 <listitem>
170 <para>
171 10-19 system rendering defaults (such as antialiasing)
172 </para>
173 </listitem>
174 <listitem>
175 <para>
176 20-29 font rendering options
177 </para>
178 </listitem>
179 <listitem>
180 <para>
181 30-39 family substitution
182 </para>
183 </listitem>
184 <listitem>
185 <para>
186 40-49 map family to generic type
187 </para>
188 </listitem>
189 <listitem>
190 <para>
191 50-59 load alternate config files
192 </para>
193 </listitem>
194 <listitem>
195 <para>
196 60-69 generic aliases, map generic to family
197 </para>
198 </listitem>
199 <listitem>
200 <para>
201 70-79 adjust which fonts are available
202 </para>
203 </listitem>
204 <listitem>
205 <para>
206 80-89 match target scan (modify scanned patterns)
207 </para>
208 </listitem>
209 <listitem>
210 <para>
211 90-99 font synthesis
212 </para>
213 </listitem>
214 </itemizedlist>
215
216 <para>
217 You can also have a personal <filename>fonts.conf</filename> in
218 $XDG_CONFIG_HOME (which is <filename
219 class="directory">~/.config/fontconfig/</filename>).
220 </para>
221
222 </sect2>
223
224 <sect2 role="configuration" id="rules-to-choose-a-font" xreflabel="The rules to choose a font">
225 <title>The rules to choose a font</title>
226
227 <para>
228 If the requested font is installed, and provided it contains the
229 codepoints <emphasis>required</emphasis> for the current language (in the
230 source, see the .orth files in the <filename
231 class="directory">fc-lang/</filename> directory), it will be used.
232 </para>
233
234 <note>
235 <para>
236 In fontconfig-2.14 the defaults were changed to Noto fonts. Some of the
237 detail here is out of date and will be revised.
238 </para>
239 </note>
240
241 <para>
242 However, if the document or page requested a font which is not installed
243 (or, occasionally, does not contain all the required codepoints) the
244 following rules come into play: First,
245 <filename>30-metric-aliases.conf</filename> is used to map aliases for
246 some fonts with the same metrics (same size, etc). Note that there are
247 both weak and strong aliases so that aliases for one form such as
248 Helvetica or Times New Roman can be stisfied by the other style, i.e.
249 anything which is an alias of Arial or Times in those examples.
250 After that, an unknown font will be searched for in
251 <filename>45-latin.conf</filename>:
252 'Latin' covers Cyrillic and Greek, and now also maps system-ui fonts which
253 are used for User Interface messages in other alphabets. If the font
254 is found it will be mapped as serif, sans-serif, monospace, fantasy,
255 cursive, or system-ui. Otherwise, 49-sansserif.conf will assume it is
256 Sans.
257 </para>
258 <para>
259 Then <filename>60-latin.conf</filename>
260 provides ordered lists of the fallbacks - <xref linkend="noto-fonts"/>
261 will be used if you installed them. Cyrillic and Greek appear to be
262 treated in the same way. There are similar files with a 65- prefix for
263 Persian and other writing systems. All of these files prefer
264 commercial fonts if they are present, although modern libre fonts are
265 often at least equal. Finally, if a codepoint is still not found it can
266 be taken from any available system font. The following details only
267 mention freely available fonts.
268 </para>
269
270 <para>
271 Before fontconfig-2.14, the first preferred font family was Bitstream
272 Vera. In practice that was rarely used because it covered so little. After
273 that, DejaVu was the next preferred family, so people were recommended to
274 install that. That has now changed, Bitstream Vera has been replaced by the
275 relevant Noto fonts (Serif, Sans, Sans Mono), so these will be preferred if
276 they have been installed, followed by DejaVu.
277 </para>
278
279 <para>
280 For serif, Times New Roman could have been aliased from Liberation Serif or
281 Tinos, and Times from TeX Gyre Termes, so although the named fonts are not
282 free, the metric-compatilbe fonts can be used. Ignoring other non-free fonts,
283 the remaining order for serif is: Times New Roman, Luxi Serif, Nimbus Roman
284 No9 L, Times. In practice, that means those fonts at the end of the list
285 are unlikely to be used unless a web page asks for them.
286 </para>
287
288 <para>
289 For sans-serif, the remaining order is anything mapped to Arial, Luxi Sans,
290 Nimbus Sans L, anything mapped to Helvetica.
291 </para>
292
293 <para>
294 The remaining alternatives for monospace are Inconsolata, anything mapped
295 to Courier New, Luxi Mono, Nimbus Mono, anything mapped to Courier.
296 </para>
297
298 <para>
299 For 'fantasy' there are no free fonts, so fontconfig will fall back to
300 sans-serif.
301 </para>
302
303 <para>
304 For 'cursive', the only free font is TeX Gyre Chorus as an alias for
305 ITC Zapf chancery, otherwise fontconfig will again fall back to sans-serif.
306 </para>
307
308 <para>
309 The system-ui category is unusual. It is for interface messages, so some
310 scripts need special versions to fit in the available space. For Latin,
311 Greek and Cyrillic a normal sans font should fit without problems. However,
312 the first preferred font is Cantarell, followed by Noto Sans UI. Cantarell
313 started as a Latin sans-serif font, that has been forked in Gnome under
314 the same name but they only provide the source. The Noto Sans UI fonts are
315 for other languages.
316 </para>
317
318 <para>
319 Since fontconfig-2.12.5, there is also generic family matching for some
320 emoji and math fonts, please see {45,60}-generic.conf.
321 </para>
322
323 <para>
324 In the rare cases where a font does not contain all the expected
325 codepoints, see 'Trial the First:' at <xref
326 linkend="I-stared-into-the-fontconfig"/> for the long details.
327 </para>
328
329 </sect2>
330
331 <sect2 role="configuration" id="hinting-and-antialiasing" xreflabel="Hinting and Anti-aliasing">
332 <title>Hinting and Anti-aliasing</title>
333
334 <para>
335 It is possible to change how, or if, fonts are hinted. The following
336 example file contains the default settings, but with comments. The
337 settings are very much down to the user's preferences and to the choice
338 of fonts, so a change which improves some pages may worsen others. The
339 preferred location for this file is:
340 <filename>~/.config/fontconfig/fonts.conf</filename>
341 </para>
342
343 <para>
344 To try out different settings, you may need to exit from Xorg and then
345 run <command>startx</command> again so that all applications use the new
346 settings. If you use GNOME, KDE, or LXQt, their desktops can override
347 these changes. To explore the possibilities, create a file for your user:
348 </para>
349
350<screen><userinput>mkdir -pv ~/.config/fontconfig &amp;&amp;
351cat > ~/.config/fontconfig/fonts.conf &lt;&lt; "EOF"
352<literal>&lt;?xml version='1.0'?&gt;
353&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
354&lt;fontconfig&gt;
355
356 &lt;match target="font" &gt;
357 &lt;!-- autohint was the old automatic hinter when hinting was patent
358 protected, so turn it off to ensure any hinting information in the font
359 itself is used, this is the default --&gt;
360 &lt;edit mode="assign" name="autohint"&gt; &lt;bool&gt;false&lt;/bool&gt;&lt;/edit&gt;
361
362 &lt;!-- hinting is enabled by default --&gt;
363 &lt;edit mode="assign" name="hinting"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
364
365 &lt;!-- for the lcdfilter see https://www.spasche.net/files/lcdfiltering/ --&gt;
366 &lt;edit mode="assign" name="lcdfilter"&gt; &lt;const&gt;lcddefault&lt;/const&gt;&lt;/edit&gt;
367
368 &lt;!-- options for hintstyle:
369 hintfull: is supposed to give a crisp font that aligns well to the
370 character-cell grid but at the cost of its proper shape.
371
372 hintmedium: poorly documented, maybe a synonym for hintfull.
373 hintslight is the default: - supposed to be more fuzzy but retains shape.
374
375 hintnone: seems to turn hinting off.
376 The variations are marginal and results vary with different fonts --&gt;
377 &lt;edit mode="assign" name="hintstyle"&gt; &lt;const&gt;hintslight&lt;/const&gt;&lt;/edit&gt;
378
379 &lt;!-- antialiasing is on by default and really helps for faint characters
380 and also for 'xft:' fonts used in rxvt-unicode --&gt;
381 &lt;edit mode="assign" name="antialias"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
382
383 &lt;!-- subpixels are usually rgb, see
384 http://www.lagom.nl/lcd-test/subpixel.php --&gt;
385 &lt;edit mode="assign" name="rgba"&gt; &lt;const&gt;rgb&lt;/const&gt;&lt;/edit&gt;
386
387 &lt;!-- thanks to the Arch wiki for the lcd and subpixel links --&gt;
388 &lt;/match&gt;
389
390&lt;/fontconfig&gt;</literal>
391EOF</userinput></screen>
392
393 <para>
394 You will now need to edit the file in your preferred editor.
395 </para>
396
397 <para>
398 For more examples see the blfs-support thread which started at <ulink
399 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00128.html">2016-09/00128</ulink>,
400 particularly <ulink
401 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00137.html">2016-09/00137</ulink>,
402 and the original poster's preferred solution at <ulink
403 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00147.html">2016-09/00147</ulink>.
404 There are other examples in <xref linkend="arch-fontconfig"/> and <xref
405 linkend="gentoo-fontconfig"/>.
406 </para>
407
408 </sect2>
409
410 <sect2 role="configuration" id="disabling-bitmap-fonts" xreflabel="Disabling Bitmap fonts">
411 <title>Disabling Bitmap Fonts</title>
412
413 <para>
414 In previous versions of BLFS, the ugly old Xorg bitmap fonts were
415 installed. Now, many people will not need to install any of them. But if
416 for some reason you have installed one or more bitmap fonts, you can
417 prevent them from being used by <application>fontconfig</application> by
418 creating the following file as the &root; user :
419 </para>
420
421<screen role="root"><userinput>cat > /etc/fonts/conf.d/70-no-bitmaps.conf &lt;&lt; "EOF"
422<literal>&lt;?xml version='1.0'?&gt;
423&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
424&lt;fontconfig&gt;
425&lt;!-- Reject bitmap fonts --&gt;
426 &lt;selectfont&gt;
427 &lt;rejectfont&gt;
428 &lt;pattern&gt;
429 &lt;patelt name="scalable"&gt;&lt;bool&gt;false&lt;/bool&gt;&lt;/patelt&gt;
430 &lt;/pattern&gt;
431 &lt;/rejectfont&gt;
432 &lt;/selectfont&gt;
433&lt;/fontconfig&gt;</literal>
434EOF</userinput></screen>
435
436 </sect2>
437
438 <sect2 role="configuration" id="adding-extra-directories" xreflabel="Adding extra font directories">
439 <title>Adding extra font directories</title>
440
441 <para>
442 Normally, system fonts and user fonts are installed in directories beneath
443 the locations specified in <xref linkend="xft-font-protocol"/> and there
444 is no obvious reason to put them elsewhere. However, a full BLFS install
445 of <xref linkend="texlive"/> puts many fonts in <filename
446 class="directory">/opt/texlive/&texlive-year;/texmf-dist/fonts/</filename>
447 in the <filename class="directory">opentype/</filename> and <filename
448 class="directory">truetype/</filename> subdirectories. Although pulling in
449 all of these files may appear useful (it allows you to use them in non
450 <application>TeX</application> programs), there are several problems with
451 such an approach:
452 </para>
453
454 <orderedlist>
455 <listitem>
456 <para>
457 There are hundreds of files, which makes selecting fonts difficult.
458 </para>
459 </listitem>
460 <listitem>
461 <para>
462 Some of the files do odd things, such as displaying semaphore flags
463 instead of ASCII letters, or mapping cyrillic codepoints to character
464 forms appropriate to Old Church Slavonic instead of the expected
465 current shapes: fine if that is what you need, but painful for normal
466 use.
467 </para>
468 </listitem>
469 <listitem>
470 <para>
471 Several fonts have multiple sizes and impenetrable short names, which
472 both make selecting the correct font even more difficult.
473 </para>
474 </listitem>
475 <listitem>
476 <para>
477 When a font is added to CTAN, it is accompanied by TeX packages to use
478 it in the old engines (<application>xelatex</application> does not
479 normally need this), and then the version is often frozen whilst the
480 font is separately maintained. Some of these fonts such as <xref
481 linkend="dejavu-fonts"/> are probably already installed on your BLFS
482 system in a newer version, and if you have multiple versions of a font
483 it is unclear which one will be used by
484 <application>fontconfig</application>.
485 </para>
486 </listitem>
487 </orderedlist>
488
489 <para>
490 However, it is sometimes useful to look at these fonts in non-TeX
491 applications, if only to see whether you wish to install a current
492 version. If you have installed all of <application>texlive</application>,
493 the following example will make one of the Arkandis Open Type fonts
494 available to other applications, and all three of the ParaType TrueType
495 fonts. Adjust or repeat the lines as desired, to either make all the
496 <filename class="directory">opentype/</filename> or <filename
497 class="directory">truetype</filename>fonts available, or to select
498 different font directories. As the <systemitem
499 class="username">root</systemitem> user:
500 </para>
501
502<screen role="root"><userinput>cat > /etc/fonts/conf.d/09-texlive.conf &lt;&lt; "EOF"
503<literal>&lt;?xml version='1.0'?&gt;
504&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
505&lt;fontconfig&gt;
506 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/opentype/arkandis/berenisadf&lt;/dir&gt;
507 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/truetype/paratype&lt;/dir&gt;
508&lt;/fontconfig&gt;</literal>
509EOF</userinput></screen>
510
511 <para>
512 If you do this, remember to change all instances of the year in that file
513 when you upgrade <application>texlive</application> to a later release.
514 </para>
515
516 </sect2>
517
518 <sect2 role="configuration" id="preferring-certain-fonts" xreflabel="Preferring certain fonts">
519 <title>Preferring certain fonts</title>
520
521 <para>
522 With the exception of web pages which use WOFF fonts and either supply
523 them or link to google to download them, web pages have traditionally
524 suggested a list of preferred font family names if they cared (e.g.
525 Times New Roman, Serif). There are many reasons why people may wish to
526 have pages which specify a preferred font use a different font, or
527 prefer specific fonts in Monospace or Sans or Serif. As you will expect,
528 there a number of different ways of achieving this.
529 </para>
530
531 <bridgehead renderas="sect3" id="fontconfig-user-docs"
532 xreflabel="fontconfig-user-docs">Fontconfig user docs</bridgehead>
533
534 <para>
535 <application>Fontconfig</application> installs user documentation that
536 includes an example 'User configuration file' which among other things
537 prefers <xref linkend="wenquanyi-zenhei"/> (a Sans font) if a
538 <emphasis>Serif</emphasis> font is requested for Chinese (this part
539 might be anachronistic unless you have non-free Chinese fonts, because
540 in <filename>65-nonlatin.conf</filename> this font is already among the
541 preferred fonts when Serif is specified for Chinese) and to prefer the
542 modern <xref linkend="VLGothic"/> font if a Sans font is specified on a
543 Japanese page (otherwise a couple of other fonts would be preferred if
544 they have been installed).
545 </para>
546
547 <para>
548 If you have installed the current version, the user documentation is
549 available in HTML, PDF, and text versions at <filename
550 class="directory">/usr/share/doc/fontconfig-&fontconfig-version;/</filename>
551 : change the version if you installed a different one.
552 </para>
553
554 <bridgehead renderas="sect3" id="prefer-a-specific-font"
555 xreflabel="fontconfig-prefer-specific-font">Prefer a specific font</bridgehead>
556
557 <para>
558 As an example, if for some reason you wished to use the <ulink
559 url="https://www.fontsquirrel.com/fonts/nimbus-roman-no9-l">Nimbus Roman
560 No9 L</ulink> font wherever Times New Roman is referenced (it is
561 metrically similar, and preferred for Times Roman, but the Serif font
562 from <xref linkend="liberation-fonts"/> will be preferred for the Times
563 <emphasis>New</emphasis> Roman font if installed), as an individual user
564 you could install the font and then create the following file:
565 </para>
566
567<screen><userinput>mkdir -pv ~/.config/fontconfig/conf.d &amp;&amp;
568cat > ~/.config/fontconfig/conf.d/35-prefer-nimbus-for-timesnew.conf &lt;&lt; "EOF"
569<literal>&lt;?xml version='1.0'?&gt;
570&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
571&lt;fontconfig&gt;
572&lt;!-- prefer Nimbus Roman No9 L for Times New Roman as well as for Times,
573 without this Tinos and Liberation Serif take precedence for Times New Roman
574 before fontconfig falls back to whatever matches Times --&gt;
575 &lt;alias binding="same"&gt;
576 &lt;family&gt;Times New Roman&lt;/family&gt;
577 &lt;accept&gt;
578 &lt;family&gt;Nimbus Roman No9 L&lt;/family&gt;
579 &lt;/accept&gt;
580 &lt;/alias&gt;
581&lt;/fontconfig&gt;</literal>
582EOF</userinput></screen>
583
584 <para>
585 This is something you would normally do in an individual user's
586 settings, but the file in this case has been prefixed '35-' so that it
587 could, if desired, be used system-wide in <filename
588 class="directory">/etc/fonts/conf.d/</filename>.
589 </para>
590
591 <bridgehead renderas="sect3" id="prefer-chosen-CJK-fonts"
592 xreflabel="Prefer chosen CJK fonts">Prefer chosen CJK fonts</bridgehead>
593
594 <para>
595 The following example of a local configuration (i.e. one that applies
596 for all users of the machine) does several things. It is particularly
597 appropriate where no language is specified, or for reading CJK text
598 in a non-CJK locale, and where the Japanese forms of the codepoints
599 shared with Chinese are preferred. In particular, alternative
600 approaches would be to specify a Chinese font ahead of the Japanese
601 font, meaning that only Kana symbols will be used from the Japanese
602 font, or to not specify DejaVu so that the first font in each set
603 of preferences is preferred for text using Latin alphabets.
604 </para>
605
606 <orderedlist>
607 <listitem>
608 <para>
609 If a Serif font is specified, it prefers <xref linkend="dejavu-fonts"/>.
610 If Han codepoints are found, or the Japanese language is specified,
611 the Mincho font from <xref linkend="IPAex"/> will be used. If Hangul
612 codepoints are found or the Korean language is specified, UnBatang
613 (see <xref linkend="Korean-fonts"/>) will be used: Change that line
614 If you installed a different Korean serif font. After that,
615 <xref linkend="wenquanyi-zenhei"/> (Sans, but a default for Serif
616 and monospace) is used. A previous version of this page mentioned
617 using UMing which is a traditional-style chinese font that ships
618 with an old conf file preferring it for zh-tw and zh-hk language
619 codes (and for sans-serif and monospace). But without the conf file,
620 fontconfig will only treat it as suitable for zh-hk.
621 The conf file needs to be edited to current style and will then be
622 prepended, so specifying UMing does not belong in this
623 <filename>local.conf</filename> file.
624 </para>
625 </listitem>
626 <listitem>
627 <para>
628 For Sans Serif preferences again start with <xref linkend="dejavu-fonts"/>,
629 then <xref linkend="VLGothic"/> for Japanese before falling back to
630 WenQuanYi Zen Hei which is Sans and covers both Chinese and Korean
631 Hangul.
632 </para>
633 </listitem>
634 <listitem>
635 <para>
636 The Monospace fonts are forced to the preferred Sans fonts. If the
637 text is in Chinese or Korean then <xref
638 linkend="wenquanyi-zenhei"/> will be used.
639 </para>
640 </listitem>
641 </orderedlist>
642
643 <para>
644 In a non-CJK locale, the result is that suitable fonts will be used for
645 all variants of Chinese, Japanese and Hangul Korean (but Japanese variants
646 of the glyphs shared with Chinese Han will be used). All other languages
647 should already work if a font is present. As the <systemitem
648 class="username">root</systemitem> user:
649 </para>
650
651<screen role="root"><userinput>cat > /etc/fonts/local.conf &lt;&lt; "EOF"
652<literal>&lt;?xml version='1.0'?&gt;
653&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
654&lt;fontconfig&gt;
655 &lt;alias&gt;
656 &lt;family&gt;serif&lt;/family&gt;
657 &lt;prefer&gt;
658 &lt;family&gt;DejaVu Serif&lt;/family&gt;
659 &lt;family&gt;IPAexMincho&lt;/family&gt;
660 &lt;!-- WenQuanYi is preferred as Serif in 65-nonlatin.conf,
661 override that so a real Korean font can be used for Serif --&gt;
662 &lt;family&gt;UnBatang&lt;/family&gt;
663 &lt;/prefer&gt;
664 &lt;/alias&gt;
665 &lt;alias&gt;
666 &lt;family&gt;sans-serif&lt;/family&gt;
667 &lt;prefer&gt;
668 &lt;family&gt;DejaVu Sans&lt;/family&gt;
669 &lt;family&gt;VL Gothic&lt;/family&gt;
670 &lt;!-- This assumes WenQuanYi is good enough for Korean Sans --&gt;
671 &lt;/prefer&gt;
672 &lt;/alias&gt;
673 &lt;alias&gt;
674 &lt;family&gt;monospace&lt;/family&gt;
675 &lt;prefer&gt;
676 &lt;family&gt;DejaVu Sans Mono&lt;/family&gt;
677 &lt;family&gt;VL Gothic&lt;/family&gt;
678 &lt;!-- This assumes WenQuanYi is good enough for Korean Monospace --&gt;
679 &lt;/prefer&gt;
680 &lt;/alias&gt;
681&lt;/fontconfig&gt;</literal>
682EOF</userinput></screen>
683
684 </sect2>
685
686
687 <sect2 role="configuration" id="editing-old-style-conf-files"
688 xreflabel="Editing Old-Style conf files">
689 <title>Editing Old-Style conf files</title>
690
691 <para>
692 Some fonts, particularly Chinese fonts, ship with conf files which can be
693 installed in <filename class="directory">/etc/fonts/conf.d</filename>.
694 However, if you do that and then use a terminal to run any command which
695 uses <application>fontconfig</application> you may see error messages such
696 as :
697 </para>
698
699 <para>
700 <literal>Fontconfig warning: "/etc/fonts/conf.d/69-odofonts.conf", line
701 14: Having multiple &lt;family&gt; in &lt;alias&gt; isn't supported and
702 may not work as expected</literal>.
703 </para>
704
705 <para>
706 In practice, these old rules do not work. For non-CJK users,
707 <application>fontconfig</application> will usually do a good job
708 <emphasis>without</emphasis> these rules. Their origin dates back to when
709 CJK users needed handcrafted bitmaps to be legible at small sizes, and
710 those looked ugly next to antialiased Latin glyphs - they preferred to
711 use the same CJK font for the Latin glyphs. There is a side-effect of
712 doing this : the (Serif) font is often also used for Sans, and in such a
713 situation the (English) text in <application>Gtk</application> menus will
714 use this font - compared to system fonts, as well as being serif it is
715 both faint and rather small. That can make it uncomfortable to read.
716 </para>
717
718 <para>
719 Nevertheless, these old conf files can be fixed if you wish to use them.
720 The following example is the first part of
721 <filename>64-arphic-uming.conf</filename> from <xref linkend="UMing"/> -
722 there are many more similar items which also need changing :
723 </para>
724
725 <para>
726 <literallayout>
727 &lt;match target="pattern"&gt;
728 &lt;test qual="any" name="lang" compare="contains"&gt;
729 &lt;string&gt;zh-cn&lt;/string&gt;
730 &lt;string&gt;zh-sg&lt;/string&gt;
731 &lt;/test&gt;
732 &lt;test qual="any" name="family"&gt;
733 &lt;string&gt;serif&lt;/string&gt;
734 &lt;/test&gt;
735 &lt;edit name="family" mode="prepend" binding="strong"&gt;
736 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
737 &lt;/edit&gt;
738 &lt;/match&gt;</literallayout>
739 </para>
740
741 <para>
742 The process to correct this is straightforward but tedious - for every
743 item which produces an error message, using your editor (as the &root;
744 user), edit the installed
745 file to repeat the whole block as many times as there are multiple
746 variables, then reduce each example to have only one of them. You may
747 wish to work on one error at a time, save the file after each fix, and
748 from a separate term run a command such as <command>fc-list 2>&amp;1 |
749 less</command> to see that the fix worked. For the block above, the fixed
750 version will be :
751 </para>
752
753 <para>
754 <literallayout>
755 &lt;match target="pattern"&gt;
756 &lt;test qual="any" name="lang" compare="contains"&gt;
757 &lt;string&gt;zh-cn&lt;/string&gt;
758 &lt;/test&gt;
759 &lt;test qual="any" name="family"&gt;
760 &lt;string&gt;serif&lt;/string&gt;
761 &lt;/test&gt;
762 &lt;edit name="family" mode="prepend" binding="strong"&gt;
763 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
764 &lt;/edit&gt;
765 &lt;/match&gt;
766 &lt;match target="pattern"&gt;
767 &lt;test qual="any" name="lang" compare="contains"&gt;
768 &lt;string&gt;zh-sg&lt;/string&gt;
769 &lt;/test&gt;
770 &lt;test qual="any" name="family"&gt;
771 &lt;string&gt;serif&lt;/string&gt;
772 &lt;/test&gt;
773 &lt;edit name="family" mode="prepend" binding="strong"&gt;
774 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
775 &lt;/edit&gt;
776 &lt;/match&gt;</literallayout>
777 </para>
778
779 </sect2>
780
781
782 <sect2 role="configuration" id="see-also" xreflabel="See Also">
783 <title>See Also</title>
784
785 <bridgehead renderas="sect3" id="I-stared-into-the-fontconfig"
786 xreflabel="I stared into the fontconfig">I stared into the fontconfig ...</bridgehead>
787
788 <para>
789 The blog entries by <ulink
790 url="https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/">Eevee</ulink>
791 are particularly useful if <application>fontconfig</application> does not
792 think your chosen font supports your language, and for preferring some
793 non-MS Japanese fonts when an ugly MS font is already installed.
794 </para>
795
796 <bridgehead renderas="sect3" id="arch-fontconfig"
797 xreflabel="Fontconfig in the Arch wiki">Fontconfig in the Arch wiki</bridgehead>
798
799 <para>
800 Arch has a lot of information in its wiki at <ulink
801 url="https://wiki.archlinux.org/index.php/font_configuration">font_configuration</ulink>.
802 </para>
803
804 <bridgehead renderas="sect3" id="gentoo-fontconfig"
805 xreflabel="Fontconfig in the Gentoo wiki">Fontconfig in the Gentoo wiki</bridgehead>
806
807 <para>
808 Gentoo has some information in its wiki at <ulink
809 url="https://wiki.gentoo.org/wiki/Fontconfig">Fontconfig</ulink> although
810 a lot of the details (what to enable, and Infinality) are specific to
811 Gentoo.
812 </para>
813
814 </sect2>
815
816</sect1>
Note: See TracBrowser for help on using the repository browser.