source: x/installing/tuning-fontconfig.xml@ 3ff7901

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

tuningfonts:

Flesh out the details of preferred non-latin fonts.

Also fix a typo in a changed link.

  • Property mode set to 100644
File size: 44.3 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, why they may not always work,
38 and to identify online information which is no-longer appropriate.
39 </para>
40
41 <para>
42 Unfortunately, some of the terminology is ambiguous (e.g. 'font face' can
43 mean a name known to fontconfig, <emphasis>or</emphasis> the normal, italic
44 condensed, etc variations of a font).
45 </para>
46
47 <para>The following links are to assist navigation in this page.</para>
48 <itemizedlist>
49 <listitem>
50 <para><xref linkend="xft-font-protocol"/></para>
51 </listitem>
52 <listitem>
53 <para><xref linkend="useful-commands"/></para>
54 </listitem>
55 <listitem>
56 <para><xref linkend="the-various-files"/></para>
57 </listitem>
58 <listitem>
59 <para><xref linkend="rules-to-choose-a-font"/></para>
60 </listitem>
61 <listitem>
62 <para><xref linkend="hinting-and-antialiasing"/></para>
63 </listitem>
64 <listitem>
65 <para><xref linkend="disabling-bitmap-fonts"/></para>
66 </listitem>
67 <listitem>
68 <para><xref linkend="adding-extra-directories"/></para>
69 </listitem>
70 <listitem>
71 <para><xref linkend="preferring-certain-fonts"/></para>
72 </listitem>
73 <listitem>
74 <para><xref linkend="fontconfig-user-docs"/></para>
75 </listitem>
76 <listitem>
77 <para><xref linkend="prefer-a-specific-font"/></para>
78 </listitem>
79 <listitem>
80 <para><xref linkend="prefer-chosen-CJK-fonts"/></para>
81 </listitem>
82 <listitem>
83 <para><xref linkend="editing-old-style-conf-files"/></para>
84 </listitem>
85 <listitem>
86 <para><xref linkend="items-which-can-override-fontconfig"/></para>
87 </listitem>
88 <listitem>
89 <para><xref linkend="external-links"/></para>
90 </listitem>
91 </itemizedlist>
92
93 </sect2>
94
95 <sect2 role="configuration" id="xft-font-protocol" xreflabel="The Xft Font Protocol">
96 <title>The Xft Font Protocol</title>
97
98 <para>
99 The Xft font protocol provides antialiased font rendering through
100 <application>freetype</application>, and fonts are controlled from the
101 client side using <application>fontconfig</application> (except for
102 <xref linkend="rxvt-unicode"/> which can use fonts listed in
103 <filename>~/.Xresources</filename>, and <xref linkend="abiword"/> which
104 only uses the specified font). The default search path is <filename
105 class="directory">/usr/share/fonts</filename> and <filename
106 class="directory">~/.local/share/fonts</filename>, although for the moment
107 the old and deprecated location <filename
108 class="directory">~/.fonts</filename> still works.
109 <application>Fontconfig</application> searches directories in its path
110 recursively and maintains a cache of the font characteristics in each
111 directory. If the cache appears to be out of date, it is ignored, and
112 information is fetched from the fonts themselves (that can take a few
113 seconds if you have a lot of fonts installed).
114 </para>
115
116 <para>
117 If you've installed <application>Xorg</application> in any prefix
118 other than <filename class="directory">/usr</filename>, any
119 <application>X</application> fonts were not installed in a
120 location known to <application>Fontconfig</application>. Symlinks were
121 <!-- fonts-misc-ethiopic installs an OTF directory ! -->
122 created from the <filename class="directory">OTF</filename> and <filename
123 class="directory">TTF</filename> <application>X</application> font
124 directories to <filename
125 class="directory">/usr/share/fonts/X11-{OTF,TTF}</filename>. This allows
126 <application>Fontconfig</application> to use the OpenType and TrueType
127 fonts provided by <application>X</application>, although many people will
128 prefer to use more modern fonts.
129 </para>
130
131 <para>
132 <application>Fontconfig</application> uses names to define fonts.
133 Applications generally use generic font names such as "Monospace", "Sans"
134 and "Serif". <application>Fontconfig</application> resolves these names
135 to a font that has all characters that cover the orthography of the
136 language indicated by the locale settings.
137 </para>
138
139 </sect2>
140
141 <sect2 role="configuration" id="useful-commands" xreflabel="Useful Commands">
142 <title>Useful Commands</title>
143
144 <para>
145 The following commands may be helpful when working with fontconfig,
146 particularly if you are interested in overriding which font will be
147 chosen. 'TYPE' should be one of serif, sans-serif or monospace.
148 </para>
149
150 <para>
151 <command>fc-list | less</command> : shows a list of all available fonts
152 (/path/to/filename: Font Name:style). If you installed a font more than
153 30 seconds ago but it does not show, then it or one of its directories is
154 not readable by your user.
155 </para>
156
157 <para>
158 <command>fc-match 'Font Name'</command> : tells you which font will
159 be used if the named font is requested. Typically you would use this to
160 see what happens if a font you have not installed is requested, but you
161 can also use it if the system is giving you a different font from
162 what you expected (perhaps because <application>fontconfig</application>
163 does not think that the font supports your language).
164 </para>
165
166 <para>
167 <command>fc-match -a <replaceable>Type</replaceable> | less</command> :
168 provides a list of all fonts which can be used for that type (Monospace,
169 Sans Sasn-serif, Serif <emphasis>(capital letters optional)</emphasis>).
170 Note that in-extremis <application>fontconfig</application> will take a
171 glyph from any available font, even if it is not of the specified type,
172 and unless it knows about the font's type it will assume it is Sans.
173 </para>
174
175 <para>
176 <command>fc-match 'Serif :lang=ja:weight=bold'</command> will tell you
177 which font and weight will be chosen for Japanese text in bold weight.
178 It does not mean that the reported font will necessarily be able to show
179 Japanese ideograms, so a fallback might be used, or some glyphs may be
180 missing. For language codes use ISO-639 value such as 'fr', 'ja', 'zh-cn'.
181 Note that an unrecognized value such as just 'zh' will not return any
182 match. To illustrate the fallback, on a system wherei both Noto Sans Mono
183 and DejaVu Sans Mono are installed, <command>fc-match 'monospace
184 :lang=en</command> shows Noto Sans Mono will be used, but if the lang is
185 changed to 'ar' (arabic) DejaVu Sans will be used.
186 </para>
187
188 <para>
189 If you want to determine if a font file has hinting (many older fonts do not,
190 because it was patented) use <command>fc-query
191 <replaceable>/path/to/fontfile</replaceable> | grep 'fonthashint:'</command>:
192 which will report 'True(s)' or 'False(s)'.
193 </para>
194
195 <para>
196 If you wish to know which font will be used for a string of text
197 (i.e. one or more glyphs, preceded by a space), paste the following
198 command and replace the <literal>xyz</literal> by the text you care
199 about:
200 </para>
201
202 <para>
203 <command>FC_DEBUG=4 pango-view --font=monospace -t xyz | grep
204 family</command> : this requires <xref linkend="pango"/> and <xref
205 linkend="imagemagick"/> - it will invoke <xref linkend="display"/>
206 to show the text in a tiny window, and after closing that the last
207 line of the output will show which font was chosen. This is
208 particularly useful for CJK languages, and you can also pass a
209 language, e.g. PANGO_LANGUAGE=en;ja (English, then assume Japanese)
210 or just zh-cn (or other variants such as zh-sg or zh-tw).
211 </para>
212
213 </sect2>
214
215 <sect2 role="configuration" id="the-various-files" xreflabel="The configuration files">
216 <title>The configuration files</title>
217
218 <para>
219 The main files are in <filename class="directory">/etc/fonts/conf.d/</filename>,
220 which was intended to be a directory populated by symlinks to some of the files
221 in <filename class="directory">/usr/share/fontconfig/conf.avail/</filename>.
222 But many people, and some packages, create the files directly. Each file name
223 must be in the form of two digits, a dash, somename.conf and they are read in
224 sequence.
225 </para>
226
227 <para>
228 By convention, the numbers are assigned as follows:
229 </para>
230
231 <itemizedlist>
232 <listitem>
233 <para>
234 00-09 extra font directories
235 </para>
236 </listitem>
237 <listitem>
238 <para>
239 10-19 system rendering defaults (such as antialiasing)
240 </para>
241 </listitem>
242 <listitem>
243 <para>
244 20-29 font rendering options
245 </para>
246 </listitem>
247 <listitem>
248 <para>
249 30-39 family substitution
250 </para>
251 </listitem>
252 <listitem>
253 <para>
254 40-49 map family to generic type
255 </para>
256 </listitem>
257 <listitem>
258 <para>
259 50-59 load alternate config files
260 </para>
261 </listitem>
262 <listitem>
263 <para>
264 60-69 generic aliases, map generic to family
265 </para>
266 </listitem>
267 <listitem>
268 <para>
269 70-79 adjust which fonts are available
270 </para>
271 </listitem>
272 <listitem>
273 <para>
274 80-89 match target scan (modify scanned patterns)
275 </para>
276 </listitem>
277 <listitem>
278 <para>
279 90-99 font synthesis
280 </para>
281 </listitem>
282 </itemizedlist>
283
284 <para>
285 You can also have a personal <filename>fonts.conf</filename> in
286 $XDG_CONFIG_HOME (which is <filename
287 class="directory">~/.config/fontconfig/</filename>).
288 </para>
289
290 </sect2>
291
292 <sect2 role="configuration" id="rules-to-choose-a-font" xreflabel="The rules to choose a font">
293 <title>The rules to choose a font</title>
294
295 <para>
296 If the requested font is installed, and provided it contains the
297 codepoints <emphasis>required</emphasis> for the current language (in the
298 source, see the .orth files in the <filename
299 class="directory">fc-lang/</filename> directory), it will be used.
300 </para>
301
302 <note>
303 <para>
304 In fontconfig-2.14 the defaults were changed to Noto fonts. Some of the
305 detail here is out of date and will be revised.
306 </para>
307 </note>
308
309 <para>
310 However, if the document or page requested a font which is not installed
311 (or, occasionally, does not contain all the required codepoints) the
312 following rules come into play: First,
313 <filename>30-metric-aliases.conf</filename> is used to map aliases for
314 some fonts with the same metrics (same size, etc). Note that there are
315 both weak and strong aliases so that aliases for one form such as
316 Helvetica or Times New Roman can be stisfied by the other style, i.e.
317 anything which is an alias of Arial or Times in those examples.
318 After that, an unknown font will be searched for in
319 <filename>45-latin.conf</filename>:
320 'Latin' covers Cyrillic and Greek, and now also maps system-ui fonts which
321 are used for User Interface messages in other alphabets. If the font
322 is found it will be mapped as serif, sans-serif, monospace, fantasy,
323 cursive, or system-ui. Otherwise, 49-sansserif.conf will assume it is
324 Sans.
325 </para>
326 <para>
327 Then <filename>60-latin.conf</filename>
328 provides ordered lists of the fallbacks - <xref linkend="noto-fonts"/>
329 will be used if you installed them. Cyrillic and Greek appear to be
330 treated in the same way.All of these files prefer
331 commercial fonts if they are present, although modern libre fonts are
332 often at least equal. Finally, if a codepoint is still not found it can
333 be taken from any available system font. The following details only
334 mention freely available fonts.
335 </para>
336
337 <para>
338 Default Persion fonts are dealt with in
339 <filename>65-fonts-persian.conf</filename>. It looks as if all the listed
340 fonts are commercial. Using fonts that support Persian (which has its own
341 variant of the arabic alphabet, and its own font styles) is outside the
342 skills of the BLFS editors.
343 </para>
344
345 <para>
346 All remaining scripts for which fontconfig has preferences (CJK scripts,
347 Indic scripts) are dealt with in <filename>65-nonlatin.conf</filename>.
348 These are again nominally grouped as Serif, Sans-Serif, Monospace. Of the
349 free fonts, WenQuanYi Zen Hei (Pan-CJK Sans) comes first for both Serif
350 and for Sans. Therefore, if you install this as a fallback but want to
351 use different fonts for Japanese or Korean you will need to set up a
352 preference. Similarly, the old fireflysung Serif font is also listed for
353 Sans.
354 </para>
355
356 <para>
357 After Pan-CJK and Chinese fonts come several Japanese fonts and then
358 several Korean fonts (both split appropriately between Sans and Serif).
359 Finally come the various Lohit Indic families (one font file per script),
360 labelled as both Sans and Serif.
361 </para>
362
363 <para>
364 The Monospace fonts listed in <filename>65-nonlatin.conf</filename> do
365 not include WenQuanYi Zen Hei although that will be available as a
366 fallback if installed. Several Japanese Gothic fonts are listed, followed
367 by AR PL KaitiM GB (a zh-sc 'Brush' font), AR PL Serif fonts for zh-sc
368 (SungtiL) and zh-tw (Mingti2L), some Korean Sans fonts and the various
369 Lohit Indic families.
370 </para>
371
372 <para>
373 For UI fonts, various Noto Sans UI fonts are the only listed free fonts.
374 </para>
375
376 <para>
377 The various Noto CJK fonts are <emphasis>not</emphasis> among the listed
378 fonts, possibly the RedHat developers preferred other fonts. These now
379 come in many variations, probably anyone who uses these will not install
380 any other CJK fonts.
381 </para>
382
383 <para>
384 Before fontconfig-2.14, the first preferred Latin font family was Bitstream
385 Vera. In practice that was rarely used because it covered so little. After
386 that, DejaVu was the next preferred family, so people were recommended to
387 install that. That has now changed, Bitstream Vera has been replaced by the
388 relevant Noto fonts (Serif, Sans, Sans Mono), so these will be preferred if
389 they have been installed, followed by DejaVu.
390 </para>
391
392 <para>
393 For serif, Times New Roman could have been aliased from Liberation Serif or
394 Tinos, and Times from TeX Gyre Termes, so although the named fonts are not
395 free, the metric-compatilbe fonts can be used. Ignoring other non-free fonts,
396 the remaining order for serif is: Times New Roman, Luxi Serif, Nimbus Roman
397 No9 L, Times. In practice, that means those fonts at the end of the list
398 are unlikely to be used unless a web page asks for them.
399 </para>
400
401 <para>
402 For sans-serif, the remaining order is anything mapped to Arial, Luxi Sans,
403 Nimbus Sans L, anything mapped to Helvetica.
404 </para>
405
406 <para>
407 The remaining alternatives for monospace are Inconsolata, anything mapped
408 to Courier New, Luxi Mono, Nimbus Mono, anything mapped to Courier.
409 </para>
410
411 <para>
412 For 'fantasy' there are no free fonts, so fontconfig will fall back to
413 sans-serif.
414 </para>
415
416 <para>
417 For 'cursive', the only free font is TeX Gyre Chorus as an alias for
418 ITC Zapf chancery, otherwise fontconfig will again fall back to sans-serif.
419 </para>
420
421 <para>
422 The system-ui category is unusual. It is for interface messages, so some
423 scripts need special versions to fit in the available space. For Latin,
424 Greek and Cyrillic a normal sans font should fit without problems. However,
425 the first preferred font is Cantarell, followed by Noto Sans UI. Cantarell
426 started as a Latin sans-serif font, that has been forked in Gnome under
427 the same name but they only provide the source. The Noto Sans UI fonts are
428 for other languages.
429 </para>
430
431 <para>
432 Since fontconfig-2.12.5, there is also generic family matching for some
433 emoji and math fonts, please see {45,60}-generic.conf.
434 </para>
435
436 <para>
437 In the rare cases where a font does not contain all the expected
438 codepoints, see 'Trial the First:' at <xref
439 linkend="I-stared-into-the-fontconfig"/> for the long details.
440 </para>
441
442 </sect2>
443
444 <sect2 role="configuration" id="hinting-and-antialiasing" xreflabel="Hinting and Anti-aliasing">
445 <title>Hinting and Anti-aliasing</title>
446
447 <para>
448 It is possible to change how, or if, fonts are hinted. The following
449 example file contains the default settings, but with comments. The
450 settings are very much down to the user's preferences and to the choice
451 of fonts, so a change which improves some pages may worsen others. The
452 preferred location for this file is:
453 <filename>~/.config/fontconfig/fonts.conf</filename>
454 </para>
455
456 <para>
457 To try out different settings, you may need to exit from Xorg and then
458 run <command>startx</command> again so that all applications use the new
459 settings. Several things can override the fontconfig settings, see
460 <xref linkend="items-which-can-override-fontconfig"/> below. To explore
461 the possibilities, create a file for your user:
462 </para>
463
464<screen><userinput>mkdir -pv ~/.config/fontconfig &amp;&amp;
465cat > ~/.config/fontconfig/fonts.conf &lt;&lt; "EOF"
466<literal>&lt;?xml version='1.0'?&gt;
467&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
468&lt;fontconfig&gt;
469
470 &lt;match target="font" &gt;
471 &lt;!-- autohint was the old automatic hinter when hinting was patent
472 protected, so turn it off to ensure any hinting information in the font
473 itself is used, this is the default --&gt;
474 &lt;edit mode="assign" name="autohint"&gt; &lt;bool&gt;false&lt;/bool&gt;&lt;/edit&gt;
475
476 &lt;!-- hinting is enabled by default --&gt;
477 &lt;edit mode="assign" name="hinting"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
478
479 &lt;!-- for the lcdfilter see https://www.spasche.net/files/lcdfiltering/ --&gt;
480 &lt;edit mode="assign" name="lcdfilter"&gt; &lt;const&gt;lcddefault&lt;/const&gt;&lt;/edit&gt;
481
482 &lt;!-- options for hintstyle:
483 hintfull: is supposed to give a crisp font that aligns well to the
484 character-cell grid but at the cost of its proper shape. However, anything
485 using Pango >= 1.44 will not support full hinting, Pango now uses harfbuzz
486 for hinting. Apps which use Skia (e.g. Chromium, Firefox) should not be
487 affected by this. <!-- https://github.com/harfbuzz/harfbuzz/issues/2394 -->
488
489 hintmedium: is reported to be broken.
490 hintslight is the default: - supposed to be more fuzzy but retains shape.
491
492 hintnone: seems to turn hinting off.
493 The variations are marginal and results vary with different fonts --&gt;
494 &lt;edit mode="assign" name="hintstyle"&gt; &lt;const&gt;hintslight&lt;/const&gt;&lt;/edit&gt;
495
496 &lt;!-- antialiasing is on by default and really helps for faint characters
497 and also for 'xft:' fonts used in rxvt-unicode --&gt;
498 &lt;edit mode="assign" name="antialias"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
499
500 &lt;!-- subpixels are usually rgb, see
501 http://www.lagom.nl/lcd-test/subpixel.php --&gt;
502 &lt;edit mode="assign" name="rgba"&gt; &lt;const&gt;rgb&lt;/const&gt;&lt;/edit&gt;
503
504 &lt;!-- thanks to the Arch wiki for the lcd and subpixel links --&gt;
505 &lt;/match&gt;
506
507&lt;/fontconfig&gt;</literal>
508EOF</userinput></screen>
509
510 <para>
511 You will now need to edit the file in your preferred editor. Many of the
512 different settings give very subtle differences and the results may differ
513 for some of the fonts you use.
514 </para>
515
516 <note>
517 <para>
518 Hinting, if enabled, is done in <application>FreeType</application>.
519 Since FreeType-2.7 the default TrueType interpreter is v40. The
520 original v35 hinter could be enabled by an environment variable, but
521 is only really appropriate to original Microsoft TTF fonts (Arial, etc).
522 The v38 hinter (Infinality) is not built by default and all the options
523 to tune it have been removed. For full details see <xref
524 linkend="subpixel-hinting"/> (Spoiler: there is NO sub-pixel hinting,
525 the code simply ignores <emphasis>all</emphasis> horizontal hinting
526 instructions.
527 </para>
528
529 <para>
530 Xorg assumes screens have 96 dots per inch (DPI). Most LCD screens are
531 close to this, but some people detect colour fringing if their screen
532 diverges from that size. See <xref linkend="calc-dpi"/>.
533 </para>
534
535 <para>
536 If you have a High DPI screen (often described as '4K' or larger) you
537 will probably use larger font sizes and benefit from disabling hinting.
538 </para>
539 </note>
540
541 <para>
542 For more examples see the blfs-support thread which started at <ulink
543 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00128.html">2016-09/00128</ulink>,
544 particularly <ulink
545 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00137.html">2016-09/00137</ulink>,
546 and the original poster's preferred solution at <ulink
547 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00147.html">2016-09/00147</ulink>.
548 There are other examples in <xref linkend="arch-fontconfig"/> and <xref
549 linkend="gentoo-fontconfig"/>.
550 </para>
551
552 </sect2>
553
554 <sect2 role="configuration" id="disabling-bitmap-fonts" xreflabel="Disabling Bitmap fonts">
555 <title>Disabling Bitmap Fonts</title>
556
557 <para>
558 In previous versions of BLFS, the ugly old Xorg bitmap fonts were
559 installed. Now, many people will not need to install any of them. But if
560 for some reason you have installed one or more bitmap fonts, you can
561 prevent them from being used by <application>fontconfig</application> by
562 creating the following file as the &root; user :
563 </para>
564
565<screen role="root"><userinput>cat > /etc/fonts/conf.d/70-no-bitmaps.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;!-- Reject bitmap fonts --&gt;
570 &lt;selectfont&gt;
571 &lt;rejectfont&gt;
572 &lt;pattern&gt;
573 &lt;patelt name="scalable"&gt;&lt;bool&gt;false&lt;/bool&gt;&lt;/patelt&gt;
574 &lt;/pattern&gt;
575 &lt;/rejectfont&gt;
576 &lt;/selectfont&gt;
577&lt;/fontconfig&gt;</literal>
578EOF</userinput></screen>
579
580 </sect2>
581
582 <sect2 role="configuration" id="adding-extra-directories" xreflabel="Adding extra font directories">
583 <title>Adding extra font directories</title>
584
585 <para>
586 Normally, system fonts and user fonts are installed in directories beneath
587 the locations specified in <xref linkend="xft-font-protocol"/> and there
588 is no obvious reason to put them elsewhere. However, a full BLFS install
589 of <xref linkend="texlive"/> puts many fonts in <filename
590 class="directory">/opt/texlive/&texlive-year;/texmf-dist/fonts/</filename>
591 in the <filename class="directory">opentype/</filename> and <filename
592 class="directory">truetype/</filename> subdirectories. Although pulling in
593 all of these files may appear useful (it allows you to use them in non
594 <application>TeX</application> programs), there are several problems with
595 such an approach:
596 </para>
597
598 <orderedlist>
599 <listitem>
600 <para>
601 There are hundreds of files, which makes selecting fonts difficult.
602 </para>
603 </listitem>
604 <listitem>
605 <para>
606 Some of the files do odd things, such as displaying semaphore flags
607 instead of ASCII letters, or mapping cyrillic codepoints to character
608 forms appropriate to Old Church Slavonic instead of the expected
609 current shapes: fine if that is what you need, but painful for normal
610 use.
611 </para>
612 </listitem>
613 <listitem>
614 <para>
615 Several fonts have multiple sizes and impenetrable short names, which
616 both make selecting the correct font even more difficult.
617 </para>
618 </listitem>
619 <listitem>
620 <para>
621 When a font is added to CTAN, it is accompanied by TeX packages to use
622 it in the old engines (<application>xelatex</application> does not
623 normally need this), and then the version is often frozen whilst the
624 font is separately maintained. Some of these fonts such as <xref
625 linkend="dejavu-fonts"/> are probably already installed on your BLFS
626 system in a newer version, and if you have multiple versions of a font
627 it is unclear which one will be used by
628 <application>fontconfig</application>.
629 </para>
630 </listitem>
631 </orderedlist>
632
633 <para>
634 However, it is sometimes useful to look at these fonts in non-TeX
635 applications, if only to see whether you wish to install a current
636 version. If you have installed all of <application>texlive</application>,
637 the following example will make one of the Arkandis Open Type fonts
638 available to other applications, and all three of the ParaType TrueType
639 fonts. Adjust or repeat the lines as desired, to either make all the
640 <filename class="directory">opentype/</filename> or <filename
641 class="directory">truetype</filename>fonts available, or to select
642 different font directories. As the <systemitem
643 class="username">root</systemitem> user:
644 </para>
645
646<screen role="root"><userinput>cat > /etc/fonts/conf.d/09-texlive.conf &lt;&lt; "EOF"
647<literal>&lt;?xml version='1.0'?&gt;
648&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
649&lt;fontconfig&gt;
650 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/opentype/arkandis/berenisadf&lt;/dir&gt;
651 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/truetype/paratype&lt;/dir&gt;
652&lt;/fontconfig&gt;</literal>
653EOF</userinput></screen>
654
655 <para>
656 If you do this, remember to change all instances of the year in that file
657 when you upgrade <application>texlive</application> to a later release.
658 </para>
659
660 </sect2>
661
662 <sect2 role="configuration" id="preferring-certain-fonts" xreflabel="Preferring certain fonts">
663 <title>Preferring certain fonts</title>
664
665 <para>
666 With the exception of web pages which use WOFF fonts and either supply
667 them or link to google to download them, web pages have traditionally
668 suggested a list of preferred font family names if they cared (e.g.
669 Times New Roman, Serif). There are many reasons why people may wish to
670 have pages which specify a preferred font use a different font, or
671 prefer specific fonts in Monospace or Sans or Serif. As you will expect,
672 there a number of different ways of achieving this.
673 </para>
674
675 <bridgehead renderas="sect3" id="fontconfig-user-docs"
676 xreflabel="Fontconfig user documentation">Fontconfig user documentation</bridgehead>
677
678 <para>
679 <application>Fontconfig</application> installs user documentation that
680 includes an example 'User configuration file' which among other things
681 prefers <xref linkend="wenquanyi-zenhei"/> (a Sans font) if a
682 <emphasis>Serif</emphasis> font is requested for Chinese (this part
683 might be anachronistic unless you have non-free Chinese fonts, because
684 in <filename>65-nonlatin.conf</filename> this font is already among the
685 preferred fonts when Serif is specified for Chinese) and to prefer the
686 modern <xref linkend="VLGothic"/> font if a Sans font is specified on a
687 Japanese page (otherwise a couple of other fonts would be preferred if
688 they have been installed).
689 </para>
690
691 <para>
692 If you have installed the current version, the user documentation is
693 available in HTML, PDF, and text versions at <filename
694 class="directory">/usr/share/doc/fontconfig-&fontconfig-version;/</filename>
695 : change the version if you installed a different one.
696 </para>
697
698 <bridgehead renderas="sect3" id="prefer-a-specific-font"
699 xreflabel="Prefer a specific font">Prefer a specific font</bridgehead>
700
701 <para>
702 As an example, if for some reason you wished to use the <ulink
703 url="https://www.fontsquirrel.com/fonts/nimbus-roman-no9-l">Nimbus Roman
704 No9 L</ulink> font wherever Times New Roman is referenced (it is
705 metrically similar, and preferred for Times Roman, but the Serif font
706 from <xref linkend="liberation-fonts"/> will be preferred for the Times
707 <emphasis>New</emphasis> Roman font if installed), as an individual user
708 you could install the font and then create the following file:
709 </para>
710
711<screen><userinput>mkdir -pv ~/.config/fontconfig/conf.d &amp;&amp;
712cat > ~/.config/fontconfig/conf.d/35-prefer-nimbus-for-timesnew.conf &lt;&lt; "EOF"
713<literal>&lt;?xml version='1.0'?&gt;
714&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
715&lt;fontconfig&gt;
716&lt;!-- prefer Nimbus Roman No9 L for Times New Roman as well as for Times,
717 without this Tinos and Liberation Serif take precedence for Times New Roman
718 before fontconfig falls back to whatever matches Times --&gt;
719 &lt;alias binding="same"&gt;
720 &lt;family&gt;Times New Roman&lt;/family&gt;
721 &lt;accept&gt;
722 &lt;family&gt;Nimbus Roman No9 L&lt;/family&gt;
723 &lt;/accept&gt;
724 &lt;/alias&gt;
725&lt;/fontconfig&gt;</literal>
726EOF</userinput></screen>
727
728 <para>
729 This is something you would normally do in an individual user's
730 settings, but the file in this case has been prefixed '35-' so that it
731 could, if desired, be used system-wide in <filename
732 class="directory">/etc/fonts/conf.d/</filename>.
733 </para>
734
735 <bridgehead renderas="sect3" id="prefer-chosen-CJK-fonts"
736 xreflabel="Prefer chosen CJK fonts">Prefer chosen CJK fonts</bridgehead>
737
738 <para>
739 The following example of a local configuration (i.e. one that applies
740 for all users of the machine) does several things. It is particularly
741 appropriate where no language is specified, or for reading CJK text
742 in a non-CJK locale, and where the Japanese forms of the codepoints
743 shared with Chinese are preferred. In particular, alternative
744 approaches would be to specify a Chinese font ahead of the Japanese
745 font, meaning that only Kana symbols will be used from the Japanese
746 font, or to not specify DejaVu so that the first font in each set
747 of preferences is preferred for text using Latin alphabets.
748 </para>
749
750 <orderedlist>
751 <listitem>
752 <para>
753 If a Serif font is specified, it prefers <xref linkend="dejavu-fonts"/>.
754 If Han codepoints are found, or the Japanese language is specified,
755 the Mincho font from <xref linkend="IPAex"/> will be used. If Hangul
756 codepoints are found or the Korean language is specified, UnBatang
757 (see <xref linkend="Korean-fonts"/>) will be used: Change that line
758 If you installed a different Korean serif font. After that,
759 <xref linkend="wenquanyi-zenhei"/> (Sans, but a default for Serif
760 and monospace) is used. A previous version of this page mentioned
761 using UMing which is a traditional-style chinese font that ships
762 with an old conf file preferring it for zh-tw and zh-hk language
763 codes (and for sans-serif and monospace). But without the conf file,
764 fontconfig will only treat it as suitable for zh-hk.
765 The conf file needs to be edited to current style and will then be
766 prepended, so specifying UMing does not belong in this
767 <filename>local.conf</filename> file.
768 </para>
769 </listitem>
770 <listitem>
771 <para>
772 For Sans Serif preferences again start with <xref linkend="dejavu-fonts"/>,
773 then <xref linkend="VLGothic"/> for Japanese before falling back to
774 WenQuanYi Zen Hei which is Sans and covers both Chinese and Korean
775 Hangul.
776 </para>
777 </listitem>
778 <listitem>
779 <para>
780 The Monospace fonts are forced to the preferred Sans fonts. If the
781 text is in Chinese or Korean then <xref
782 linkend="wenquanyi-zenhei"/> will be used.
783 </para>
784 </listitem>
785 </orderedlist>
786
787 <para>
788 In a non-CJK locale, the result is that suitable fonts will be used for
789 all variants of Chinese, Japanese and Hangul Korean (but Japanese variants
790 of the glyphs shared with Chinese Han will be used). All other languages
791 should already work if a font is present. As the <systemitem
792 class="username">root</systemitem> user:
793 </para>
794
795<screen role="root"><userinput>cat > /etc/fonts/local.conf &lt;&lt; "EOF"
796<literal>&lt;?xml version='1.0'?&gt;
797&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
798&lt;fontconfig&gt;
799 &lt;alias&gt;
800 &lt;family&gt;serif&lt;/family&gt;
801 &lt;prefer&gt;
802 &lt;family&gt;DejaVu Serif&lt;/family&gt;
803 &lt;family&gt;IPAexMincho&lt;/family&gt;
804 &lt;!-- WenQuanYi is preferred as Serif in 65-nonlatin.conf,
805 override that so a real Korean font can be used for Serif --&gt;
806 &lt;family&gt;UnBatang&lt;/family&gt;
807 &lt;/prefer&gt;
808 &lt;/alias&gt;
809 &lt;alias&gt;
810 &lt;family&gt;sans-serif&lt;/family&gt;
811 &lt;prefer&gt;
812 &lt;family&gt;DejaVu Sans&lt;/family&gt;
813 &lt;family&gt;VL Gothic&lt;/family&gt;
814 &lt;!-- This assumes WenQuanYi is good enough for Korean Sans --&gt;
815 &lt;/prefer&gt;
816 &lt;/alias&gt;
817 &lt;alias&gt;
818 &lt;family&gt;monospace&lt;/family&gt;
819 &lt;prefer&gt;
820 &lt;family&gt;DejaVu Sans Mono&lt;/family&gt;
821 &lt;family&gt;VL Gothic&lt;/family&gt;
822 &lt;!-- This assumes WenQuanYi is good enough for Korean Monospace --&gt;
823 &lt;/prefer&gt;
824 &lt;/alias&gt;
825&lt;/fontconfig&gt;</literal>
826EOF</userinput></screen>
827
828 </sect2>
829
830
831 <sect2 role="configuration" id="editing-old-style-conf-files"
832 xreflabel="Editing Old-Style conf files">
833 <title>Editing Old-Style conf files</title>
834
835 <para>
836 Some fonts, particularly Chinese fonts, ship with conf files which can be
837 installed in <filename class="directory">/etc/fonts/conf.d</filename>.
838 However, if you do that and then use a terminal to run any command which
839 uses <application>fontconfig</application> you may see error messages such
840 as :
841 </para>
842
843 <para>
844 <literal>Fontconfig warning: "/etc/fonts/conf.d/69-odofonts.conf", line
845 14: Having multiple &lt;family&gt; in &lt;alias&gt; isn't supported and
846 may not work as expected</literal>.
847 </para>
848
849 <para>
850 In practice, these old rules do not work. For non-CJK users,
851 <application>fontconfig</application> will usually do a good job
852 <emphasis>without</emphasis> these rules. Their origin dates back to when
853 CJK users needed handcrafted bitmaps to be legible at small sizes, and
854 those looked ugly next to antialiased Latin glyphs - they preferred to
855 use the same CJK font for the Latin glyphs. There is a side-effect of
856 doing this : the (Serif) font is often also used for Sans, and in such a
857 situation the (English) text in <application>Gtk</application> menus will
858 use this font - compared to system fonts, as well as being serif it is
859 both faint and rather small. That can make it uncomfortable to read.
860 </para>
861
862 <para>
863 Nevertheless, these old conf files can be fixed if you wish to use them.
864 The following example is the first part of
865 <filename>64-arphic-uming.conf</filename> from <xref linkend="UMing"/> -
866 there are many more similar items which also need changing :
867 </para>
868
869 <para>
870 <literallayout>
871 &lt;match target="pattern"&gt;
872 &lt;test qual="any" name="lang" compare="contains"&gt;
873 &lt;string&gt;zh-cn&lt;/string&gt;
874 &lt;string&gt;zh-sg&lt;/string&gt;
875 &lt;/test&gt;
876 &lt;test qual="any" name="family"&gt;
877 &lt;string&gt;serif&lt;/string&gt;
878 &lt;/test&gt;
879 &lt;edit name="family" mode="prepend" binding="strong"&gt;
880 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
881 &lt;/edit&gt;
882 &lt;/match&gt;</literallayout>
883 </para>
884
885 <para>
886 The process to correct this is straightforward but tedious - for every
887 item which produces an error message, using your editor (as the &root;
888 user), edit the installed
889 file to repeat the whole block as many times as there are multiple
890 variables, then reduce each example to have only one of them. You may
891 wish to work on one error at a time, save the file after each fix, and
892 from a separate term run a command such as <command>fc-list 2>&amp;1 |
893 less</command> to see that the fix worked. For the block above, the fixed
894 version will be :
895 </para>
896
897 <para>
898 <literallayout>
899 &lt;match target="pattern"&gt;
900 &lt;test qual="any" name="lang" compare="contains"&gt;
901 &lt;string&gt;zh-cn&lt;/string&gt;
902 &lt;/test&gt;
903 &lt;test qual="any" name="family"&gt;
904 &lt;string&gt;serif&lt;/string&gt;
905 &lt;/test&gt;
906 &lt;edit name="family" mode="prepend" binding="strong"&gt;
907 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
908 &lt;/edit&gt;
909 &lt;/match&gt;
910 &lt;match target="pattern"&gt;
911 &lt;test qual="any" name="lang" compare="contains"&gt;
912 &lt;string&gt;zh-sg&lt;/string&gt;
913 &lt;/test&gt;
914 &lt;test qual="any" name="family"&gt;
915 &lt;string&gt;serif&lt;/string&gt;
916 &lt;/test&gt;
917 &lt;edit name="family" mode="prepend" binding="strong"&gt;
918 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
919 &lt;/edit&gt;
920 &lt;/match&gt;</literallayout>
921 </para>
922
923 <bridgehead renderas="sect3" id="items-which-can-override-fontconfig"
924 xreflabel="Items which can override fontconfig">Items which can override fontconfig</bridgehead>
925
926 <para>
927 Several desktop environments, as well as some programs, will use fontconfig
928 to find fonts but may override certain things.
929 </para>
930
931 <para>
932 GNOME: The settings in org.gnome.desktop.interface can be updated with
933 <application>dconf-editor</application>. You can set the fonts to your preference
934 and desired point size. To use the fonts chosen by fontconfig specify e.g.
935 'Sans 12', Serif 11', 'Mono 10' as desired. Also review the antialiasing, hinting
936 and rgba settings.
937 </para>
938
939 <para>
940 LXQt: Change font settings as necessary to match fontconfig in
941 <application>lxqt-config-appearance</application>.
942 </para>
943
944 <para>
945 KDE Plasma: The settings can be adjusted in <application>System
946 Settings</application> under Appearance -> Fonts. This will create or modify
947 <filename>~/.config/fontconfig/fonts.conf</filename> although
948 <filename>~/.config/fontconfig/fonts.conf</filename>, if installed, can
949 override that.
950 </para>
951
952 <para>
953 Xfce desktop: The settings can be adjusted in
954 <application>Settings</application> Appearance -> Fonts. Specify your
955 preferred fonts, e.g. 'Sans Regular' (to use the regular face and weight
956 rather than Bold and/or Italic) and adjust the point size in the option.
957 Review the Rendering and DPI options.
958 </para>
959
960 <para>
961 Firefox: This browser allows you to specify its default fonts. For the 115esr
962 series, use the 'Hamburger' menu to got to Preferences, General, and under Fonts
963 -> Advanced select Sans Serif, Serif, Monospace as appropriate if you wish to use
964 the fonts which match fontconfig. Set the point sizes as desired. In later
965 versions, the settings are at Preferences -> Fonts.
966 <!-- FIXME : Ken - when merging, add note in packages to update this when next ESR
967 series is used -->
968 </para>
969
970 <para>
971 Libreoffice: Tests using English text with an old Japanese font (HanaMinA)
972 which supports several European languages but had only one weight and no
973 italics or slant showed that although <application>Libreoffice</application>
974 uses fontconfig to find the font, it created its own bold or slanted text.
975 It is not clear if it will do the same where a font actually has bold weight
976 or an italic face. Also, documentation shows that Libreoffice has its own
977 substitution rules for when a codepoint is not found in the selected font,
978 but is unclear if those rules apply on Linux using fontconfig.
979 </para>
980
981 <para>
982 Pango: as noted in the example <filename>~/.config/fontconfig</filename>
983 above, anything using Pango-1.44 (from 2019) or later now uses Harfbuzz for
984 hinting, not FreeType, and <literal>hintfull</literal> is not supported.
985 </para>
986
987 </sect2>
988
989 <sect2 role="configuration" id="external-links" xreflabel="External Links">
990 <title>External Links</title>
991
992 <bridgehead renderas="sect3" id="I-stared-into-the-fontconfig"
993 xreflabel="I stared into the fontconfig">I stared into the fontconfig ...</bridgehead>
994
995 <para>
996 The blog entries by <ulink
997 url="https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/">Eevee</ulink>
998 are particularly useful if <application>fontconfig</application> does not
999 think your chosen font supports your language, and for preferring some
1000 non-MS Japanese fonts when an ugly MS font is already installed.
1001 </para>
1002
1003 <bridgehead renderas="sect3" id="subpixel-hinting"
1004 xreflabel="subpixel-hinting">subpixel-hinting</bridgehead>
1005
1006 <para>The documentation of the FreeType v40 interpreter at <ulink
1007 url="https://freetype.org/freetype2/docs/hinting/subpixel-hinting.html">freetype
1008 docs</ulink>
1009 explains how the current hinter works, and why the previous (slow) Infinality
1010 interpreter was replaced.
1011 </para>
1012
1013 <bridgehead renderas="sect3" id="calc-dpi"
1014 xreflabel="calc-dpi">Calculating DPI</bridgehead>
1015
1016 <para>An old answer at <ulink
1017 url="https://askubuntu.com/questions/197828/how-to-find-and-change-the-screen-dpi/">askubuntu</ulink>
1018 gives some detail on calculating a screen's dots per inch, but essentailly
1019 you just measure the width and height of the visible panel, convert to
1020 inches if using metric measurements, and divide by the number of pixels.
1021 You can then pass <option>-dpi <replaceable>90</replaceable></option> when
1022 you start Xorg, using your own value.
1023 </para>
1024
1025 <bridgehead renderas="sect3" id="arch-fontconfig"
1026 xreflabel="Fontconfig in the Arch wiki">Fontconfig in the Arch wiki</bridgehead>
1027
1028 <para>
1029 Arch has a lot of information in its wiki at <ulink
1030 url="https://wiki.archlinux.org/index.php/font_configuration">font_configuration</ulink>.
1031 </para>
1032
1033 <bridgehead renderas="sect3" id="gentoo-fontconfig"
1034 xreflabel="Fontconfig in the Gentoo wiki">Fontconfig in the Gentoo wiki</bridgehead>
1035
1036 <para>
1037 Gentoo has some information in its wiki at <ulink
1038 url="https://wiki.gentoo.org/wiki/Fontconfig">Fontconfig</ulink> although
1039 a lot of the details (what to enable, and Infinality) are specific to
1040 Gentoo.
1041 </para>
1042
1043 </sect2>
1044
1045</sect1>
Note: See TracBrowser for help on using the repository browser.