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

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

tuningfonts:

Explain about font weights, and how installing only one or two may
let you slightly darken (or lighten) the text.

Comment about static fonts in files which also include variable
fotns - variable fonts are mentioned on the TTF-and-OTF page but
the data fits better in tuning-fontconfig.

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