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

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

tuningfonts: How to find if a font has hinting.

Many older fonts, and even some currently-developed fonts such as
Junicode, lack hints. Before exploring hinting options it makes
sens to check that the font being used does indeed have hints.

Placed in 'Useful Commands' ahead of the Pango example, because
it is a plain fontconfig command.

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