source: x/installing/tuning-fontconfig.xml@ 1f9b99f

12.1 12.2 gimp3 ken/TL2024 ken/tuningfonts lazarus plabs/newcss python3.11 rahul/power-profiles-daemon trunk xry111/for-12.3 xry111/llvm18 xry111/spidermonkey128
Last change on this file since 1f9b99f was 1f9b99f, checked in by Ken Moffat <ken@…>, 10 months ago

tuning-fontconfig - flesh out details for free fonts.

  • Property mode set to 100644
File size: 34.0 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 non-latin 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 non-latin 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 There are many reasons why people may wish to have pages which specify a
523 particular font use a different font, or prefer specific fonts in
524 Monospace or Sans or Serif. As you will expect, there a number of
525 different ways of achieving this.
526 </para>
527
528 <bridgehead renderas="sect3" id="fontconfig-user-docs"
529 xreflabel="fontconfig-user-docs">Fontconfig user docs</bridgehead>
530
531 <para>
532 <application>Fontconfig</application> installs user documentation that
533 includes an example 'User configuration file' which among other things
534 prefers <xref linkend="wenquanyi-zenhei"/> (a Sans font) if a
535 <emphasis>Serif</emphasis> font is requested for Chinese (this part
536 might be anachronistic unless you have non-free Chinese fonts, because
537 in <filename>65-nonlatin.conf</filename> this font is already among the
538 preferred fonts when Serif is specified for Chinese) and to prefer the
539 modern <xref linkend="VLGothic"/> font if a Sans font is specified on a
540 Japanese page (otherwise a couple of other fonts would be preferred if
541 they have been installed).
542 </para>
543
544 <para>
545 If you have installed the current version, the user documentation is
546 available in HTML, PDF, and text versions at <filename
547 class="directory">/usr/share/doc/fontconfig-&fontconfig-version;/</filename>
548 : change the version if you installed a different one.
549 </para>
550
551 <bridgehead renderas="sect3" id="prefer-a-specific-font"
552 xreflabel="fontconfig-prefer-specific-font">Prefer a specific font</bridgehead>
553
554 <para>
555 As an example, if for some reason you wished to use the <ulink
556 url="https://www.fontsquirrel.com/fonts/nimbus-roman-no9-l">Nimbus Roman
557 No9 L</ulink> font wherever Times New Roman is referenced (it is
558 metrically similar, and preferred for Times Roman, but the Serif font
559 from <xref linkend="liberation-fonts"/> will be preferred for the Times
560 <emphasis>New</emphasis> Roman font if installed), as an individual user
561 you could install the font and then create the following file:
562 </para>
563
564<screen><userinput>mkdir -pv ~/.config/fontconfig/conf.d &amp;&amp;
565cat > ~/.config/fontconfig/conf.d/35-prefer-nimbus-for-timesnew.conf &lt;&lt; "EOF"
566<literal>&lt;?xml version='1.0'?&gt;
567&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
568&lt;fontconfig&gt;
569&lt;!-- prefer Nimbus Roman No9 L for Times New Roman as well as for Times,
570 without this Tinos and Liberation Serif take precedence for Times New Roman
571 before fontconfig falls back to whatever matches Times --&gt;
572 &lt;alias binding="same"&gt;
573 &lt;family&gt;Times New Roman&lt;/family&gt;
574 &lt;accept&gt;
575 &lt;family&gt;Nimbus Roman No9 L&lt;/family&gt;
576 &lt;/accept&gt;
577 &lt;/alias&gt;
578&lt;/fontconfig&gt;</literal>
579EOF</userinput></screen>
580
581 <para>
582 This is something you would normally do in an individual user's
583 settings, but the file in this case has been prefixed '35-' so that it
584 could, if desired, be used system-wide in <filename
585 class="directory">/etc/fonts/conf.d/</filename>.
586 </para>
587
588 <bridgehead renderas="sect3" id="prefer-chosen-CJK-fonts"
589 xreflabel="Prefer chosen CJK fonts">Prefer chosen CJK fonts</bridgehead>
590
591 <para>
592 The following example of a local configuration (i.e. one that applies
593 for all users of the machine) does several things. It is particularly
594 appropriate where no language is specified, or for reading CJK text
595 in a non-CJK locale, and where the Japanese forms of the codepoints
596 shared with Chinese are preferred. In particular, alternative
597 approaches would be to specify a Chinese font ahead of the Japanese
598 font, meaning that only Kana symbols will be used from the Japanese
599 font, or to not specify DejaVu so that the first font in each set
600 of preferences is preferred for text using latin alphabets.
601 </para>
602
603 <orderedlist>
604 <listitem>
605 <para>
606 If a Serif font is specified, it prefers <xref linkend="dejavu-fonts"/>.
607 If Han codepoints are found, or the Japanese language is specified,
608 the Mincho font from <xref linkend="IPAex"/> will be used. If Hangul
609 codepoints are found or the Korean language is specified, UnBatang
610 (see <xref linkend="Korean-fonts"/>) will be used: Change that line
611 If you installed a different Korean serif font. After that,
612 <xref linkend="wenquanyi-zenhei"/> (Sans, but a default for Serif
613 and monospace) is used. A previous version of this page mentioned
614 using UMing which is a traditional-style chinese font that ships
615 with an old conf file preferring it for zh-tw and zh-hk language
616 codes (and for sans-serif and monospace). But without the conf file,
617 fontconfig will only treat it as suitable for zh-hk.
618 The conf file needs to be edited to current style and will then be
619 prepended, so specifying UMing does not belong in this
620 <filename>local.conf</filename> file.
621 </para>
622 </listitem>
623 <listitem>
624 <para>
625 For Sans Serif preferences again start with <xref linkend="dejavu-fonts"/>,
626 then <xref linkend="VLGothic"/> for Japanese before falling back to
627 WenQuanYi Zen Hei which is Sans and covers both Chinese and Korean
628 Hangul.
629 </para>
630 </listitem>
631 <listitem>
632 <para>
633 The Monospace fonts are forced to the preferred Sans fonts. If the
634 text is in Chinese or Korean then <xref
635 linkend="wenquanyi-zenhei"/> will be used.
636 </para>
637 </listitem>
638 </orderedlist>
639
640 <para>
641 In a non-CJK locale, the result is that suitable fonts will be used for
642 all variants of Chinese, Japanese and Hangul Korean (but Japanese variants
643 of the glyphs shared with Chinese Han will be used). All other languages
644 should already work if a font is present. As the <systemitem
645 class="username">root</systemitem> user:
646 </para>
647
648<screen role="root"><userinput>cat > /etc/fonts/local.conf &lt;&lt; "EOF"
649<literal>&lt;?xml version='1.0'?&gt;
650&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
651&lt;fontconfig&gt;
652 &lt;alias&gt;
653 &lt;family&gt;serif&lt;/family&gt;
654 &lt;prefer&gt;
655 &lt;family&gt;DejaVu Serif&lt;/family&gt;
656 &lt;family&gt;IPAexMincho&lt;/family&gt;
657 &lt;!-- WenQuanYi is preferred as Serif in 65-nonlatin.conf,
658 override that so a real Korean font can be used for Serif --&gt;
659 &lt;family&gt;UnBatang&lt;/family&gt;
660 &lt;/prefer&gt;
661 &lt;/alias&gt;
662 &lt;alias&gt;
663 &lt;family&gt;sans-serif&lt;/family&gt;
664 &lt;prefer&gt;
665 &lt;family&gt;DejaVu Sans&lt;/family&gt;
666 &lt;family&gt;VL Gothic&lt;/family&gt;
667 &lt;!-- This assumes WenQuanYi is good enough for Korean Sans --&gt;
668 &lt;/prefer&gt;
669 &lt;/alias&gt;
670 &lt;alias&gt;
671 &lt;family&gt;monospace&lt;/family&gt;
672 &lt;prefer&gt;
673 &lt;family&gt;DejaVu Sans Mono&lt;/family&gt;
674 &lt;family&gt;VL Gothic&lt;/family&gt;
675 &lt;!-- This assumes WenQuanYi is good enough for Korean Monospace --&gt;
676 &lt;/prefer&gt;
677 &lt;/alias&gt;
678&lt;/fontconfig&gt;</literal>
679EOF</userinput></screen>
680
681 </sect2>
682
683
684 <sect2 role="configuration" id="editing-old-style-conf-files"
685 xreflabel="Editing Old-Style conf files">
686 <title>Editing Old-Style conf files</title>
687
688 <para>
689 Some fonts, particularly Chinese fonts, ship with conf files which can be
690 installed in <filename class="directory">/etc/fonts/conf.d</filename>.
691 However, if you do that and then use a terminal to run any command which
692 uses <application>fontconfig</application> you may see error messages such
693 as :
694 </para>
695
696 <para>
697 <literal>Fontconfig warning: "/etc/fonts/conf.d/69-odofonts.conf", line
698 14: Having multiple &lt;family&gt; in &lt;alias&gt; isn't supported and
699 may not work as expected</literal>.
700 </para>
701
702 <para>
703 In practice, these old rules do not work. For non-CJK users,
704 <application>fontconfig</application> will usually do a good job
705 <emphasis>without</emphasis> these rules. Their origin dates back to when
706 CJK users needed handcrafted bitmaps to be legible at small sizes, and
707 those looked ugly next to antialiased Latin glyphs - they preferred to
708 use the same CJK font for the Latin glyphs. There is a side-effect of
709 doing this : the (Serif) font is often also used for Sans, and in such a
710 situation the (English) text in <application>Gtk</application> menus will
711 use this font - compared to system fonts, as well as being serif it is
712 both faint and rather small. That can make it uncomfortable to read.
713 </para>
714
715 <para>
716 Nevertheless, these old conf files can be fixed if you wish to use them.
717 The following example is the first part of
718 <filename>64-arphic-uming.conf</filename> from <xref linkend="UMing"/> -
719 there are many more similar items which also need changing :
720 </para>
721
722 <para>
723 <literallayout>
724 &lt;match target="pattern"&gt;
725 &lt;test qual="any" name="lang" compare="contains"&gt;
726 &lt;string&gt;zh-cn&lt;/string&gt;
727 &lt;string&gt;zh-sg&lt;/string&gt;
728 &lt;/test&gt;
729 &lt;test qual="any" name="family"&gt;
730 &lt;string&gt;serif&lt;/string&gt;
731 &lt;/test&gt;
732 &lt;edit name="family" mode="prepend" binding="strong"&gt;
733 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
734 &lt;/edit&gt;
735 &lt;/match&gt;</literallayout>
736 </para>
737
738 <para>
739 The process to correct this is straightforward but tedious - for every
740 item which produces an error message, using your editor (as the &root;
741 user), edit the installed
742 file to repeat the whole block as many times as there are multiple
743 variables, then reduce each example to have only one of them. You may
744 wish to work on one error at a time, save the file after each fix, and
745 from a separate term run a command such as <command>fc-list 2>&amp;1 |
746 less</command> to see that the fix worked. For the block above, the fixed
747 version will be :
748 </para>
749
750 <para>
751 <literallayout>
752 &lt;match target="pattern"&gt;
753 &lt;test qual="any" name="lang" compare="contains"&gt;
754 &lt;string&gt;zh-cn&lt;/string&gt;
755 &lt;/test&gt;
756 &lt;test qual="any" name="family"&gt;
757 &lt;string&gt;serif&lt;/string&gt;
758 &lt;/test&gt;
759 &lt;edit name="family" mode="prepend" binding="strong"&gt;
760 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
761 &lt;/edit&gt;
762 &lt;/match&gt;
763 &lt;match target="pattern"&gt;
764 &lt;test qual="any" name="lang" compare="contains"&gt;
765 &lt;string&gt;zh-sg&lt;/string&gt;
766 &lt;/test&gt;
767 &lt;test qual="any" name="family"&gt;
768 &lt;string&gt;serif&lt;/string&gt;
769 &lt;/test&gt;
770 &lt;edit name="family" mode="prepend" binding="strong"&gt;
771 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
772 &lt;/edit&gt;
773 &lt;/match&gt;</literallayout>
774 </para>
775
776 </sect2>
777
778
779 <sect2 role="configuration" id="see-also" xreflabel="See Also">
780 <title>See Also</title>
781
782 <bridgehead renderas="sect3" id="I-stared-into-the-fontconfig"
783 xreflabel="I stared into the fontconfig">I stared into the fontconfig ...</bridgehead>
784
785 <para>
786 The blog entries by <ulink
787 url="https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/">Eevee</ulink>
788 are particularly useful if <application>fontconfig</application> does not
789 think your chosen font supports your language, and for preferring some
790 non-MS Japanese fonts when an ugly MS font is already installed.
791 </para>
792
793 <bridgehead renderas="sect3" id="arch-fontconfig"
794 xreflabel="Fontconfig in the Arch wiki">Fontconfig in the Arch wiki</bridgehead>
795
796 <para>
797 Arch has a lot of information in its wiki at <ulink
798 url="https://wiki.archlinux.org/index.php/font_configuration">font_configuration</ulink>.
799 </para>
800
801 <bridgehead renderas="sect3" id="gentoo-fontconfig"
802 xreflabel="Fontconfig in the Gentoo wiki">Fontconfig in the Gentoo wiki</bridgehead>
803
804 <para>
805 Gentoo has some information in its wiki at <ulink
806 url="https://wiki.gentoo.org/wiki/Fontconfig">Fontconfig</ulink> although
807 a lot of the details (what to enable, and Infinality) are specific to
808 Gentoo.
809 </para>
810
811 </sect2>
812
813</sect1>
Note: See TracBrowser for help on using the repository browser.