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

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

tuningfonts -

Minor text changes to expand the purpose of the page.

Change internal links to show proper text names without hyphens.

  • Property mode set to 100644
File size: 42.4 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="see-also"/></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 configuation 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. There are similar files with a 65- prefix for
331 Persian and other writing systems. All of these files prefer
332 commercial fonts if they are present, although modern libre fonts are
333 often at least equal. Finally, if a codepoint is still not found it can
334 be taken from any available system font. The following details only
335 mention freely available fonts.
336 </para>
337
338 <para>
339 Before fontconfig-2.14, the first preferred font family was Bitstream
340 Vera. In practice that was rarely used because it covered so little. After
341 that, DejaVu was the next preferred family, so people were recommended to
342 install that. That has now changed, Bitstream Vera has been replaced by the
343 relevant Noto fonts (Serif, Sans, Sans Mono), so these will be preferred if
344 they have been installed, followed by DejaVu.
345 </para>
346
347 <para>
348 For serif, Times New Roman could have been aliased from Liberation Serif or
349 Tinos, and Times from TeX Gyre Termes, so although the named fonts are not
350 free, the metric-compatilbe fonts can be used. Ignoring other non-free fonts,
351 the remaining order for serif is: Times New Roman, Luxi Serif, Nimbus Roman
352 No9 L, Times. In practice, that means those fonts at the end of the list
353 are unlikely to be used unless a web page asks for them.
354 </para>
355
356 <para>
357 For sans-serif, the remaining order is anything mapped to Arial, Luxi Sans,
358 Nimbus Sans L, anything mapped to Helvetica.
359 </para>
360
361 <para>
362 The remaining alternatives for monospace are Inconsolata, anything mapped
363 to Courier New, Luxi Mono, Nimbus Mono, anything mapped to Courier.
364 </para>
365
366 <para>
367 For 'fantasy' there are no free fonts, so fontconfig will fall back to
368 sans-serif.
369 </para>
370
371 <para>
372 For 'cursive', the only free font is TeX Gyre Chorus as an alias for
373 ITC Zapf chancery, otherwise fontconfig will again fall back to sans-serif.
374 </para>
375
376 <para>
377 The system-ui category is unusual. It is for interface messages, so some
378 scripts need special versions to fit in the available space. For Latin,
379 Greek and Cyrillic a normal sans font should fit without problems. However,
380 the first preferred font is Cantarell, followed by Noto Sans UI. Cantarell
381 started as a Latin sans-serif font, that has been forked in Gnome under
382 the same name but they only provide the source. The Noto Sans UI fonts are
383 for other languages.
384 </para>
385
386 <para>
387 Since fontconfig-2.12.5, there is also generic family matching for some
388 emoji and math fonts, please see {45,60}-generic.conf.
389 </para>
390
391 <para>
392 In the rare cases where a font does not contain all the expected
393 codepoints, see 'Trial the First:' at <xref
394 linkend="I-stared-into-the-fontconfig"/> for the long details.
395 </para>
396
397 </sect2>
398
399 <sect2 role="configuration" id="hinting-and-antialiasing" xreflabel="Hinting and Anti-aliasing">
400 <title>Hinting and Anti-aliasing</title>
401
402 <para>
403 It is possible to change how, or if, fonts are hinted. The following
404 example file contains the default settings, but with comments. The
405 settings are very much down to the user's preferences and to the choice
406 of fonts, so a change which improves some pages may worsen others. The
407 preferred location for this file is:
408 <filename>~/.config/fontconfig/fonts.conf</filename>
409 </para>
410
411 <para>
412 To try out different settings, you may need to exit from Xorg and then
413 run <command>startx</command> again so that all applications use the new
414 settings. Several things can override the fontconfig settings, see
415 <xref linkend="items-which-can-override-fontconfig"/> below. To explore
416 the possibilities, create a file for your user:
417 </para>
418
419<screen><userinput>mkdir -pv ~/.config/fontconfig &amp;&amp;
420cat > ~/.config/fontconfig/fonts.conf &lt;&lt; "EOF"
421<literal>&lt;?xml version='1.0'?&gt;
422&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
423&lt;fontconfig&gt;
424
425 &lt;match target="font" &gt;
426 &lt;!-- autohint was the old automatic hinter when hinting was patent
427 protected, so turn it off to ensure any hinting information in the font
428 itself is used, this is the default --&gt;
429 &lt;edit mode="assign" name="autohint"&gt; &lt;bool&gt;false&lt;/bool&gt;&lt;/edit&gt;
430
431 &lt;!-- hinting is enabled by default --&gt;
432 &lt;edit mode="assign" name="hinting"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
433
434 &lt;!-- for the lcdfilter see https://www.spasche.net/files/lcdfiltering/ --&gt;
435 &lt;edit mode="assign" name="lcdfilter"&gt; &lt;const&gt;lcddefault&lt;/const&gt;&lt;/edit&gt;
436
437 &lt;!-- options for hintstyle:
438 hintfull: is supposed to give a crisp font that aligns well to the
439 character-cell grid but at the cost of its proper shape. However, anything
440 using Pango >= 1.44 will not support full hinting, Pango now uses harfbuzz
441 for hinting. Apps which use Skia (e.g. Chromium, Firefox) should not be
442 affected by this. <!-- https://github.com/harfbuzz/harfbuzz/issues/2394 -->
443
444 hintmedium: is reported to be broken.
445 hintslight is the default: - supposed to be more fuzzy but retains shape.
446
447 hintnone: seems to turn hinting off.
448 The variations are marginal and results vary with different fonts --&gt;
449 &lt;edit mode="assign" name="hintstyle"&gt; &lt;const&gt;hintslight&lt;/const&gt;&lt;/edit&gt;
450
451 &lt;!-- antialiasing is on by default and really helps for faint characters
452 and also for 'xft:' fonts used in rxvt-unicode --&gt;
453 &lt;edit mode="assign" name="antialias"&gt; &lt;bool&gt;true&lt;/bool&gt;&lt;/edit&gt;
454
455 &lt;!-- subpixels are usually rgb, see
456 http://www.lagom.nl/lcd-test/subpixel.php --&gt;
457 &lt;edit mode="assign" name="rgba"&gt; &lt;const&gt;rgb&lt;/const&gt;&lt;/edit&gt;
458
459 &lt;!-- thanks to the Arch wiki for the lcd and subpixel links --&gt;
460 &lt;/match&gt;
461
462&lt;/fontconfig&gt;</literal>
463EOF</userinput></screen>
464
465 <para>
466 You will now need to edit the file in your preferred editor. Many of the
467 different settings give very subtle differences and the results may differ
468 for some of the fonts you use.
469 </para>
470
471 <note>
472 <para>
473 Hinting, if enabled, is done in <application>FreeType</application>.
474 Since FreeType-2.7 the default TrueType interpreter is v40. The
475 original v35 hinter could be enabled by an environment variable, but
476 is only really appropriate to original Microsoft TTF fonts (Arial, etc).
477 The v38 hinter (Infinality) is not built by default and all the options
478 to tune it have been removed. For full details see <xref
479 linkend="subpixel-hinting"/> (Spoiler: there is NO sub-pixel hinting,
480 the code simply ignores <emphasis>all</emphasis> horizontal hinting
481 instructions.
482 </para>
483
484 <para>
485 Xorg assumes screens have 96 dots per inch (DPI). Most LCD screens are
486 close to this, but some people detect colour fringing if their screen
487 diverges from that size. See <xref linkend="calc-dpi"/>.
488 </para>
489
490 <para>
491 If you have a High DPI screen (often described as '4K' or larger) you
492 will probably use larger font sizes and benefit from disabling hinting.
493 </para>
494 </note>
495
496 <para>
497 For more examples see the blfs-support thread which started at <ulink
498 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00128.html">2016-09/00128</ulink>,
499 particularly <ulink
500 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00137.html">2016-09/00137</ulink>,
501 and the original poster's preferred solution at <ulink
502 url="https://lists.linuxfromscratch.org/sympa/arc/blfs-support/2016-09/msg00147.html">2016-09/00147</ulink>.
503 There are other examples in <xref linkend="arch-fontconfig"/> and <xref
504 linkend="gentoo-fontconfig"/>.
505 </para>
506
507 </sect2>
508
509 <sect2 role="configuration" id="disabling-bitmap-fonts" xreflabel="Disabling Bitmap fonts">
510 <title>Disabling Bitmap Fonts</title>
511
512 <para>
513 In previous versions of BLFS, the ugly old Xorg bitmap fonts were
514 installed. Now, many people will not need to install any of them. But if
515 for some reason you have installed one or more bitmap fonts, you can
516 prevent them from being used by <application>fontconfig</application> by
517 creating the following file as the &root; user :
518 </para>
519
520<screen role="root"><userinput>cat > /etc/fonts/conf.d/70-no-bitmaps.conf &lt;&lt; "EOF"
521<literal>&lt;?xml version='1.0'?&gt;
522&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
523&lt;fontconfig&gt;
524&lt;!-- Reject bitmap fonts --&gt;
525 &lt;selectfont&gt;
526 &lt;rejectfont&gt;
527 &lt;pattern&gt;
528 &lt;patelt name="scalable"&gt;&lt;bool&gt;false&lt;/bool&gt;&lt;/patelt&gt;
529 &lt;/pattern&gt;
530 &lt;/rejectfont&gt;
531 &lt;/selectfont&gt;
532&lt;/fontconfig&gt;</literal>
533EOF</userinput></screen>
534
535 </sect2>
536
537 <sect2 role="configuration" id="adding-extra-directories" xreflabel="Adding extra font directories">
538 <title>Adding extra font directories</title>
539
540 <para>
541 Normally, system fonts and user fonts are installed in directories beneath
542 the locations specified in <xref linkend="xft-font-protocol"/> and there
543 is no obvious reason to put them elsewhere. However, a full BLFS install
544 of <xref linkend="texlive"/> puts many fonts in <filename
545 class="directory">/opt/texlive/&texlive-year;/texmf-dist/fonts/</filename>
546 in the <filename class="directory">opentype/</filename> and <filename
547 class="directory">truetype/</filename> subdirectories. Although pulling in
548 all of these files may appear useful (it allows you to use them in non
549 <application>TeX</application> programs), there are several problems with
550 such an approach:
551 </para>
552
553 <orderedlist>
554 <listitem>
555 <para>
556 There are hundreds of files, which makes selecting fonts difficult.
557 </para>
558 </listitem>
559 <listitem>
560 <para>
561 Some of the files do odd things, such as displaying semaphore flags
562 instead of ASCII letters, or mapping cyrillic codepoints to character
563 forms appropriate to Old Church Slavonic instead of the expected
564 current shapes: fine if that is what you need, but painful for normal
565 use.
566 </para>
567 </listitem>
568 <listitem>
569 <para>
570 Several fonts have multiple sizes and impenetrable short names, which
571 both make selecting the correct font even more difficult.
572 </para>
573 </listitem>
574 <listitem>
575 <para>
576 When a font is added to CTAN, it is accompanied by TeX packages to use
577 it in the old engines (<application>xelatex</application> does not
578 normally need this), and then the version is often frozen whilst the
579 font is separately maintained. Some of these fonts such as <xref
580 linkend="dejavu-fonts"/> are probably already installed on your BLFS
581 system in a newer version, and if you have multiple versions of a font
582 it is unclear which one will be used by
583 <application>fontconfig</application>.
584 </para>
585 </listitem>
586 </orderedlist>
587
588 <para>
589 However, it is sometimes useful to look at these fonts in non-TeX
590 applications, if only to see whether you wish to install a current
591 version. If you have installed all of <application>texlive</application>,
592 the following example will make one of the Arkandis Open Type fonts
593 available to other applications, and all three of the ParaType TrueType
594 fonts. Adjust or repeat the lines as desired, to either make all the
595 <filename class="directory">opentype/</filename> or <filename
596 class="directory">truetype</filename>fonts available, or to select
597 different font directories. As the <systemitem
598 class="username">root</systemitem> user:
599 </para>
600
601<screen role="root"><userinput>cat > /etc/fonts/conf.d/09-texlive.conf &lt;&lt; "EOF"
602<literal>&lt;?xml version='1.0'?&gt;
603&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
604&lt;fontconfig&gt;
605 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/opentype/arkandis/berenisadf&lt;/dir&gt;
606 &lt;dir&gt;/opt/texlive/&texlive-year;/texmf-dist/fonts/truetype/paratype&lt;/dir&gt;
607&lt;/fontconfig&gt;</literal>
608EOF</userinput></screen>
609
610 <para>
611 If you do this, remember to change all instances of the year in that file
612 when you upgrade <application>texlive</application> to a later release.
613 </para>
614
615 </sect2>
616
617 <sect2 role="configuration" id="preferring-certain-fonts" xreflabel="Preferring certain fonts">
618 <title>Preferring certain fonts</title>
619
620 <para>
621 With the exception of web pages which use WOFF fonts and either supply
622 them or link to google to download them, web pages have traditionally
623 suggested a list of preferred font family names if they cared (e.g.
624 Times New Roman, Serif). There are many reasons why people may wish to
625 have pages which specify a preferred font use a different font, or
626 prefer specific fonts in Monospace or Sans or Serif. As you will expect,
627 there a number of different ways of achieving this.
628 </para>
629
630 <bridgehead renderas="sect3" id="fontconfig-user-docs"
631 xreflabel="Fontconfig user documentation">Fontconfig user documentation</bridgehead>
632
633 <para>
634 <application>Fontconfig</application> installs user documentation that
635 includes an example 'User configuration file' which among other things
636 prefers <xref linkend="wenquanyi-zenhei"/> (a Sans font) if a
637 <emphasis>Serif</emphasis> font is requested for Chinese (this part
638 might be anachronistic unless you have non-free Chinese fonts, because
639 in <filename>65-nonlatin.conf</filename> this font is already among the
640 preferred fonts when Serif is specified for Chinese) and to prefer the
641 modern <xref linkend="VLGothic"/> font if a Sans font is specified on a
642 Japanese page (otherwise a couple of other fonts would be preferred if
643 they have been installed).
644 </para>
645
646 <para>
647 If you have installed the current version, the user documentation is
648 available in HTML, PDF, and text versions at <filename
649 class="directory">/usr/share/doc/fontconfig-&fontconfig-version;/</filename>
650 : change the version if you installed a different one.
651 </para>
652
653 <bridgehead renderas="sect3" id="prefer-a-specific-font"
654 xreflabel="Prefer a specific font">Prefer a specific font</bridgehead>
655
656 <para>
657 As an example, if for some reason you wished to use the <ulink
658 url="https://www.fontsquirrel.com/fonts/nimbus-roman-no9-l">Nimbus Roman
659 No9 L</ulink> font wherever Times New Roman is referenced (it is
660 metrically similar, and preferred for Times Roman, but the Serif font
661 from <xref linkend="liberation-fonts"/> will be preferred for the Times
662 <emphasis>New</emphasis> Roman font if installed), as an individual user
663 you could install the font and then create the following file:
664 </para>
665
666<screen><userinput>mkdir -pv ~/.config/fontconfig/conf.d &amp;&amp;
667cat > ~/.config/fontconfig/conf.d/35-prefer-nimbus-for-timesnew.conf &lt;&lt; "EOF"
668<literal>&lt;?xml version='1.0'?&gt;
669&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
670&lt;fontconfig&gt;
671&lt;!-- prefer Nimbus Roman No9 L for Times New Roman as well as for Times,
672 without this Tinos and Liberation Serif take precedence for Times New Roman
673 before fontconfig falls back to whatever matches Times --&gt;
674 &lt;alias binding="same"&gt;
675 &lt;family&gt;Times New Roman&lt;/family&gt;
676 &lt;accept&gt;
677 &lt;family&gt;Nimbus Roman No9 L&lt;/family&gt;
678 &lt;/accept&gt;
679 &lt;/alias&gt;
680&lt;/fontconfig&gt;</literal>
681EOF</userinput></screen>
682
683 <para>
684 This is something you would normally do in an individual user's
685 settings, but the file in this case has been prefixed '35-' so that it
686 could, if desired, be used system-wide in <filename
687 class="directory">/etc/fonts/conf.d/</filename>.
688 </para>
689
690 <bridgehead renderas="sect3" id="prefer-chosen-CJK-fonts"
691 xreflabel="Prefer chosen CJK fonts">Prefer chosen CJK fonts</bridgehead>
692
693 <para>
694 The following example of a local configuration (i.e. one that applies
695 for all users of the machine) does several things. It is particularly
696 appropriate where no language is specified, or for reading CJK text
697 in a non-CJK locale, and where the Japanese forms of the codepoints
698 shared with Chinese are preferred. In particular, alternative
699 approaches would be to specify a Chinese font ahead of the Japanese
700 font, meaning that only Kana symbols will be used from the Japanese
701 font, or to not specify DejaVu so that the first font in each set
702 of preferences is preferred for text using Latin alphabets.
703 </para>
704
705 <orderedlist>
706 <listitem>
707 <para>
708 If a Serif font is specified, it prefers <xref linkend="dejavu-fonts"/>.
709 If Han codepoints are found, or the Japanese language is specified,
710 the Mincho font from <xref linkend="IPAex"/> will be used. If Hangul
711 codepoints are found or the Korean language is specified, UnBatang
712 (see <xref linkend="Korean-fonts"/>) will be used: Change that line
713 If you installed a different Korean serif font. After that,
714 <xref linkend="wenquanyi-zenhei"/> (Sans, but a default for Serif
715 and monospace) is used. A previous version of this page mentioned
716 using UMing which is a traditional-style chinese font that ships
717 with an old conf file preferring it for zh-tw and zh-hk language
718 codes (and for sans-serif and monospace). But without the conf file,
719 fontconfig will only treat it as suitable for zh-hk.
720 The conf file needs to be edited to current style and will then be
721 prepended, so specifying UMing does not belong in this
722 <filename>local.conf</filename> file.
723 </para>
724 </listitem>
725 <listitem>
726 <para>
727 For Sans Serif preferences again start with <xref linkend="dejavu-fonts"/>,
728 then <xref linkend="VLGothic"/> for Japanese before falling back to
729 WenQuanYi Zen Hei which is Sans and covers both Chinese and Korean
730 Hangul.
731 </para>
732 </listitem>
733 <listitem>
734 <para>
735 The Monospace fonts are forced to the preferred Sans fonts. If the
736 text is in Chinese or Korean then <xref
737 linkend="wenquanyi-zenhei"/> will be used.
738 </para>
739 </listitem>
740 </orderedlist>
741
742 <para>
743 In a non-CJK locale, the result is that suitable fonts will be used for
744 all variants of Chinese, Japanese and Hangul Korean (but Japanese variants
745 of the glyphs shared with Chinese Han will be used). All other languages
746 should already work if a font is present. As the <systemitem
747 class="username">root</systemitem> user:
748 </para>
749
750<screen role="root"><userinput>cat > /etc/fonts/local.conf &lt;&lt; "EOF"
751<literal>&lt;?xml version='1.0'?&gt;
752&lt;!DOCTYPE fontconfig SYSTEM 'fonts.dtd'&gt;
753&lt;fontconfig&gt;
754 &lt;alias&gt;
755 &lt;family&gt;serif&lt;/family&gt;
756 &lt;prefer&gt;
757 &lt;family&gt;DejaVu Serif&lt;/family&gt;
758 &lt;family&gt;IPAexMincho&lt;/family&gt;
759 &lt;!-- WenQuanYi is preferred as Serif in 65-nonlatin.conf,
760 override that so a real Korean font can be used for Serif --&gt;
761 &lt;family&gt;UnBatang&lt;/family&gt;
762 &lt;/prefer&gt;
763 &lt;/alias&gt;
764 &lt;alias&gt;
765 &lt;family&gt;sans-serif&lt;/family&gt;
766 &lt;prefer&gt;
767 &lt;family&gt;DejaVu Sans&lt;/family&gt;
768 &lt;family&gt;VL Gothic&lt;/family&gt;
769 &lt;!-- This assumes WenQuanYi is good enough for Korean Sans --&gt;
770 &lt;/prefer&gt;
771 &lt;/alias&gt;
772 &lt;alias&gt;
773 &lt;family&gt;monospace&lt;/family&gt;
774 &lt;prefer&gt;
775 &lt;family&gt;DejaVu Sans Mono&lt;/family&gt;
776 &lt;family&gt;VL Gothic&lt;/family&gt;
777 &lt;!-- This assumes WenQuanYi is good enough for Korean Monospace --&gt;
778 &lt;/prefer&gt;
779 &lt;/alias&gt;
780&lt;/fontconfig&gt;</literal>
781EOF</userinput></screen>
782
783 </sect2>
784
785
786 <sect2 role="configuration" id="editing-old-style-conf-files"
787 xreflabel="Editing Old-Style conf files">
788 <title>Editing Old-Style conf files</title>
789
790 <para>
791 Some fonts, particularly Chinese fonts, ship with conf files which can be
792 installed in <filename class="directory">/etc/fonts/conf.d</filename>.
793 However, if you do that and then use a terminal to run any command which
794 uses <application>fontconfig</application> you may see error messages such
795 as :
796 </para>
797
798 <para>
799 <literal>Fontconfig warning: "/etc/fonts/conf.d/69-odofonts.conf", line
800 14: Having multiple &lt;family&gt; in &lt;alias&gt; isn't supported and
801 may not work as expected</literal>.
802 </para>
803
804 <para>
805 In practice, these old rules do not work. For non-CJK users,
806 <application>fontconfig</application> will usually do a good job
807 <emphasis>without</emphasis> these rules. Their origin dates back to when
808 CJK users needed handcrafted bitmaps to be legible at small sizes, and
809 those looked ugly next to antialiased Latin glyphs - they preferred to
810 use the same CJK font for the Latin glyphs. There is a side-effect of
811 doing this : the (Serif) font is often also used for Sans, and in such a
812 situation the (English) text in <application>Gtk</application> menus will
813 use this font - compared to system fonts, as well as being serif it is
814 both faint and rather small. That can make it uncomfortable to read.
815 </para>
816
817 <para>
818 Nevertheless, these old conf files can be fixed if you wish to use them.
819 The following example is the first part of
820 <filename>64-arphic-uming.conf</filename> from <xref linkend="UMing"/> -
821 there are many more similar items which also need changing :
822 </para>
823
824 <para>
825 <literallayout>
826 &lt;match target="pattern"&gt;
827 &lt;test qual="any" name="lang" compare="contains"&gt;
828 &lt;string&gt;zh-cn&lt;/string&gt;
829 &lt;string&gt;zh-sg&lt;/string&gt;
830 &lt;/test&gt;
831 &lt;test qual="any" name="family"&gt;
832 &lt;string&gt;serif&lt;/string&gt;
833 &lt;/test&gt;
834 &lt;edit name="family" mode="prepend" binding="strong"&gt;
835 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
836 &lt;/edit&gt;
837 &lt;/match&gt;</literallayout>
838 </para>
839
840 <para>
841 The process to correct this is straightforward but tedious - for every
842 item which produces an error message, using your editor (as the &root;
843 user), edit the installed
844 file to repeat the whole block as many times as there are multiple
845 variables, then reduce each example to have only one of them. You may
846 wish to work on one error at a time, save the file after each fix, and
847 from a separate term run a command such as <command>fc-list 2>&amp;1 |
848 less</command> to see that the fix worked. For the block above, the fixed
849 version will be :
850 </para>
851
852 <para>
853 <literallayout>
854 &lt;match target="pattern"&gt;
855 &lt;test qual="any" name="lang" compare="contains"&gt;
856 &lt;string&gt;zh-cn&lt;/string&gt;
857 &lt;/test&gt;
858 &lt;test qual="any" name="family"&gt;
859 &lt;string&gt;serif&lt;/string&gt;
860 &lt;/test&gt;
861 &lt;edit name="family" mode="prepend" binding="strong"&gt;
862 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
863 &lt;/edit&gt;
864 &lt;/match&gt;
865 &lt;match target="pattern"&gt;
866 &lt;test qual="any" name="lang" compare="contains"&gt;
867 &lt;string&gt;zh-sg&lt;/string&gt;
868 &lt;/test&gt;
869 &lt;test qual="any" name="family"&gt;
870 &lt;string&gt;serif&lt;/string&gt;
871 &lt;/test&gt;
872 &lt;edit name="family" mode="prepend" binding="strong"&gt;
873 &lt;string&gt;AR PL UMing CN&lt;/string&gt;
874 &lt;/edit&gt;
875 &lt;/match&gt;</literallayout>
876 </para>
877
878 <bridgehead renderas="sect3" id="items-which-can-override-fontconfig"
879 xreflabel="Items which can override fontconfig">Items which can override fontconfig</bridgehead>
880
881 <para>
882 Several desktop environments, as well as some programs, will use fontconfig
883 to find fonts but may override certain things.
884 </para>
885
886 <para>
887 GNOME: The settings in org.gnome.desktop.interface can be updated with
888 <application>dconf-editor</application>. You can set the fonts to your preference
889 and desired point size. To use the fonts chosen by fontconfig specify e.g.
890 'Sans 12', Serif 11', 'Mono 10' as desired. Also review the antialiasing, hinting
891 and rgba settings.
892 </para>
893
894 <para>
895 LXQt: Change font settings as necessary to match fontconfig in
896 <application>lxqt-config-appearance</application>.
897 </para>
898
899 <para>
900 KDE Plasma: The settings can be adjusted in <application>System
901 Settings</application> under Appearance -> Fonts. This will create or modify
902 <filename>~/.config/fontconfig/fonts.conf</filename> although
903 <filename>~/.config/fontconfig/fonts.conf</filename>, if installed, can
904 override that.
905 </para>
906
907 <para>
908 Xfce desktop: The settings can be adjusted in
909 <application>Settings</application> Appearance -> Fonts. Specify your
910 preferred fonts, e.g. 'Sans Regular' (to use the regular face and weight
911 rather than Bold and/or Italic) and adjust the point size in the option.
912 Review the Rendering and DPI options.
913 </para>
914
915 <para>
916 Firefox: This browser allows you to specify its default fonts. For the 115esr
917 series, use the 'Hamburger' menu to got to Preferences, General, and under Fonts
918 -> Advanced select Sans Serif, Serif, Monospace as appropriate if you wish to use
919 the fonts which match fontconfig. Set the point sizes as desired. In later
920 versions, the settings are at Preferences -> Fonts.
921 <!-- FIXME : Ken - when merging, add note in packages to update this when next ESR
922 series is used -->
923 </para>
924
925 <para>
926 Libreoffice: Tests using English text with an old Japanese font (HanaMinA)
927 which supports several European languages but had only one weight and no
928 italics or slant showed that although <application>Libreoffice</application>
929 uses fontconfig to find the font, it created its own bold or slanted text.
930 It is not clear if it will do the same where a font actually has bold weight
931 or an italic face. Also, documentation shows that Libreoffice has its own
932 substitution rules for when a codepoint is not found in the selected font,
933 but is unclear if those rules apply on Linux using fontconfig.
934 </para>
935
936 <para>
937 Pango: as noted in the example <filename>~/.config/fontconfig</filename>
938 above, anything using Pango-1.44 (from 2019) or later now uses Harfbuzz for
939 hinting, not FreeType, and <literal>hintfull</literal> is not supported.
940 </para>
941
942 </sect2>
943
944 <sect2 role="configuration" id="see-also" xreflabel="See Also">
945 <title>See Also</title>
946
947 <bridgehead renderas="sect3" id="I-stared-into-the-fontconfig"
948 xreflabel="I stared into the fontconfig">I stared into the fontconfig ...</bridgehead>
949
950 <para>
951 The blog entries by <ulink
952 url="https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/">Eevee</ulink>
953 are particularly useful if <application>fontconfig</application> does not
954 think your chosen font supports your language, and for preferring some
955 non-MS Japanese fonts when an ugly MS font is already installed.
956 </para>
957
958 <bridgehead renderas="sect3" id="subpixel-hinting"
959 xreflabel="subpixel-hinting">subpixel-hinting</bridgehead>
960
961 <para>The documentation of the FreeType v40 interpreter at <ulink
962 url="https://freetype.org/freetype2/docs/hinting/subpixel-hinting.html">freetype
963 docs</ulink>
964 explains how the current hinter works, and why the previous (slow) Infinality
965 interpreter was replaced.
966 </para>
967
968 <bridgehead renderas="sect3" id="calc-dpi"
969 xreflabel="calc-dpi">Calculating DPI</bridgehead>
970
971 <para>An old answer at <ulink
972 url="https://askubuntu.com/questions/197828/how-to-find-and-change-the-screen-dpi/">askubuntu</ulink>
973 gives some detail on calculating a screen's dots per inch, but essentailly
974 you just measure the width and height of the visible panel, convert to
975 inches if using metric measurements, and divide by the number of pixels.
976 You can then pass <option>-dpi <replaceable>90</replaceable></option> when
977 you start Xorg, using your own value.
978 </para>
979
980 <bridgehead renderas="sect3" id="arch-fontconfig"
981 xreflabel="Fontconfig in the Arch wiki">Fontconfig in the Arch wiki</bridgehead>
982
983 <para>
984 Arch has a lot of information in its wiki at <ulink
985 url="https://wiki.archlinux.org/index.php/font_configuration">font_configuration</ulink>.
986 </para>
987
988 <bridgehead renderas="sect3" id="gentoo-fontconfig"
989 xreflabel="Fontconfig in the Gentoo wiki">Fontconfig in the Gentoo wiki</bridgehead>
990
991 <para>
992 Gentoo has some information in its wiki at <ulink
993 url="https://wiki.gentoo.org/wiki/Fontconfig">Fontconfig</ulink> although
994 a lot of the details (what to enable, and Infinality) are specific to
995 Gentoo.
996 </para>
997
998 </sect2>
999
1000</sect1>
Note: See TracBrowser for help on using the repository browser.