Font configuration

From ArchWiki
Revision as of 15:46, 28 August 2009 by Markg85 (talk | contribs) (Goodies)
Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Merge-arrows-2.pngThis article or section is a candidate for merging with Fonts.Merge-arrows-2.png

Notes: Talk:Xorg Font Configuration (Discuss in Talk:Font configuration#)

Contents

X.org Font Configuration and beautification

See the Xorg Font Documentation for full details.
See the FreeType2 Project Page for details on the freetype X.org Module.
See Optimal Use of Fonts on Linux for more information about fonts in Linux.

xorg.conf modules

  • freetype - support for True Type (ttf, ttc), Type1 (pfa, pfb), CID (cid), CFF, Open Type, bitmap (bdf, pcf, snf), Windows (fnt), PFR, and Type42 fonts
  • speedo - support for Bitstream Speedo (spd) fonts
  • xtt - support for True Type (ttf, ttc) fonts (conflicts with freetype)
  • bitmap - support for bitmap (bdf, pcf, snf) fonts

As you can see, freetype provides everything provided by these other modules already. In addition, xtt will conflict with freetype.

X.org Font Path and /etc/fonts/

xorg.conf font path

The font path described in the xorg.conf file is used for non-Xft fonts. It is worthwhile to specify a majority of fonts here. Applications which do not support Xft will fall back to the X Server's font path. Personally, I keep a minimum of fonts here - for use with xterm and its ilk.

/etc/fonts/ font directories

The conf files in /etc/fonts (fonts.conf and local.conf) are used for fontconfig (Xft fonts). fonts.conf should never be changed, and all changes should be done in local.conf (for system wide changes) or ~/.fonts.conf (for user based changes). Files in /etc/fonts/conf.d are sourced when they start with a number and end with .conf.

The directories listed in fonts.conf are scanned by fc-cache for use with fontconfig (/usr/share/fonts and ~/.fonts). All fonts should be placed in these directories. If installing new fonts, running fc-cache -fv will detect the changes.

Adding new fonts

When new fonts are added, they are just files on your system. A handful of utilities need to be run in order to tell the system that new fonts have been added.

/usr/bin/fc-cache

This will update the fontconfig cache, assuming the new fonts can be searched by fontconfig (see the above section about /etc/fonts)

/usr/bin/mkfontscale
/usr/bin/mkfontdir
ln -s /usr/share/fonts/encodings/encodings.dir encodings.dir

These utilities need to be run from inside the directory of the new fonts. mkfontscale creates a fonts.scale file and mkfontdir creates a fonts.dir file. These files are used by the X Server, and only need to be done if the fonts are to be served through the FontPath of X.org. The encodings soft link allows the X Server to use these new fonts under all supported encodings. After all this, you should have 3 new files in the font dir : fonts.scale, fonts.dir, and encodings.dir.

fc-list and xlsfont utilities

These utilities will list, from the command line, all fonts available to each font subsystem. fc-list will list all fontconfig fonts, while xlsfont will list all X fonts. This is useful in combination with grep, i.e. "xlsfonts || grep -i bitstream" to see all bitstream fonts available.

Some Font Downloads

Goodies

LCD filter Patches

-lcd

-cleartype

My fonts look like crap - I've configured everything right but it appears I just have no good fonts.

I would suggest the following packages from pacman to fix this:

pacman -S ttf-ms-fonts ttf-cheapskate artwiz-fonts

An alternative minimalist approach is to remove the 75/100dpi packages and install the Bitstream Vera package which offers nice terminal fonts and can make web browsing (in Firefox at least) look better:

pacman -Rns xorg-fonts-75dpi xorg-fonts-100dpi
pacman -S ttf-bitstream-vera

Something that can works ::

cd /etc/fonts/conf.d
cp ../conf.avail/70-no-bitmaps.conf .

I have some apps compiled against Gtk+ 2.2 and under and fonts still look like garbage.

Yeah, this happens. Modern GTK apps enable Xft by default, however, before 2.2 this was not the case. Maybe these apps should be updated to the newer GTK. If that is not an option, then adding the line export GDK_USE_XFT=1 to a global settings file (/etc/profile, /etc/profile.d/gnome.sh, ~/.xinitrc, etc) will enable Xft for older apps

I have a similar problem as above with older Qt based apps.

Similar solution, add export QT_XFT=true somewhere.

Fonts in Gtk apps are too small when using KDE

Install gtk-qt-engine:

pacman -Sy gtk-qt-engine
  • Change the font size for Gtk apps in the 'KDE Control Center' (kcontrol, in package kdebase) -> `Appearance & Themes' -> `GTK Styles and Fonts'.

The bytecode interpreter makes my fonts look crappy, and it's compiled in, do I need to recompile?

Nope, not at all. Freetype's internal auto-hinting is just shut off. In some distros, the bytecode interpreter is compiled in and enabled by default. As a result, the bytecode interpreter overrides the freetype autohinter (which the developers are very proud of). To force the autohinter to be on, add the following to /etc/fonts/local.conf or ~/.fonts.conf

     <match target="pattern">
        <edit name="autohint" mode="assign">
           <bool>true</bool>
        </edit>
     </match>

Or change to the /etc/fonts/conf.d directory, and link the 10-autohint.conf file from the conf.avail directory into the conf.d directory. The following commands should work (the second command must be run with superuser privileges).

cd /etc/fonts/conf.d
ln -s ../conf.avail/10-autohint.conf

Question: I don't understand this... The bytecode interpreter is supposed to beat the autohinter by a long shot so i don't see why anyone would want the autohinter.
Reply: It appears that the bytecode interpreter in the 2.3 branch is quite poor. There's a forum post about it here: http://bbs.archlinux.org/viewtopic.php?id=29976. The above code made fonts much better for me. Although they didn't come into effect until after I rebooted - no idea why.

Autohint works great but not for my bold fonts. How can I turn it off only for bold fonts?

Autohinter can give you nice fonts but often makes fonts too wide. This is especially annoying with bold fonts. Fortunately you can turn off autohinter for bold fonts while leaving it on for the rest.

  • First turn on autohinter (see above) and add the following to ~/.fonts.conf
     <match target="font">
         <test name="weight" compare="more">
             <const>medium</const>
         </test>
         <edit name="autohint" mode="assign">
             <bool>false</bool>
         </edit>
     </match>

I have a TFT/DFP/LCD display uses a DVI cable and fonts look odd and fuzzy

This is due to rendering differences between CRTs and non-CRTs. To fix this problem, you need to enable sub-pixel rendering. Edit the ~/.fonts.conf file. Add the following section to enable this feature. NOTE that this will do nothing but a minor amount of extra work on CRTs and does not improve the display quality. Possible values for the const section include - rgb, bgr, vrgb, bgrv, and none.

< !-- Enable sub-pixel rendering -->
<match target="font" >
 <edit mode="assign" name="rgba" >
  <const>rgb</const>
 </edit>
</match>

I don't want my fonts Antialiased under a certain point size.

A sample of this is in the /etc/fonts/local.conf file. It is commented, just like the subpixel rendering section. Changes, if anything, should be made to the compare="less_eq" portion, and the <int>12</int> portion - these are the comparison operation and point size to compare, respectively.

     <match target="pattern">
        <test qual="any" name="size" compare="less_eq">
           <int>12</int>
        </test>
        <edit name="antialias" mode="assign"><bool>false</bool></edit>
     </match>

I'm using MS TrueType fonts (verdana) and want to enable anti-aliasing but only for bigger fonts that look too jagged.

     <?xml version="1.0"?>
     <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
     <fontconfig>
     <match target="font" >
     <test compare"more" name"size" qual="any" >
     <double>12</double>
     </test>
     <edit mode"assign" name"antialias" >
     <bool>true</bool>
     </edit>
     </match>
     <match target="font" >
     <test compare"more" name"pixelsize" qual="any" >
     <double>17</double>
     </test>
     <edit mode"assign" name"antialias" >
     <bool>true</bool>
     </edit>
     </match>
     </fontconfig>

I want to add more fonts.

Save your fonts in a directory and add it to ~/.fonts.conf

    < !-- Additional font directories -->
    <dir>/path/to/dir</dir>

I want my font sizes to match my DPI settings

Edit ~/.fonts.conf with the following. This setting should match your dpi settings in either xorg.conf or your startx command. Use xdpyinfo to get your current dpi setting. Most people recommend/use a value of 96 or 100. Changing and setting the dpi of X is beyond the scope of this document (see Xorg DisplaySize/DPI).

     <match target="pattern">
        <edit name="dpi" mode="assign"><double>100</double></edit>
     </match>

I don't like font <enter name here> and want to use <another font name> instead

The most reliable way to do this is to add an XML fragment similar to the one below to ~/.fonts.conf. This will cause Bitstream Vera Sans to be used in place of Helvetica:

<match target="pattern" name="family" >
 <test name="family" qual="any" >
  <string>Helvetica</string>
 </test>
 <edit mode="assign" name="family" >
  <string>Bitstream Vera Sans</string>
 </edit>
</match>


An alternate approach is to set the "preferred" font, but this only works if the original font is not on your system, in which case the one you specify will be substituted:


     < !-- Replace Helvetica with Bitstream Vera Sans Mono -->
     < !-- Note, an alias for Helvetica should already exist in default conf files -->
     <alias>
        <family>Helvetica</family>
        <prefer><family>Bitstream Vera Sans Mono</family></prefer>
        <default><family>fixed</family></default>
     </alias>

I have tons of disgusting pixel fonts that I don't want

The only two fonts that you absolutely have to have in order to start X are 'cursor' and 'fixed', both of which are in the fonts/misc directory. If you want to get rid of all the pixel fonts besides these two, you can delete all the files in the misc directory besides cursor.pcf.gz and all the fonts that are similar to either 9x18.pcf.gz or 9x18-ISO8859-1.pcf.gz. When I deleted all the fonts besides those from the misc directory, I had about 337 files still in it, so if you have a lot less than that you should probably put them back before restarting X.

Something or someone disabled all my non-scalable (bitmap) fonts, I want them back

By default, fontconfig 2.3.2-4 and higher will disable the use of bitmap fonts. This setting is managed in /etc/fonts/conf.d/10-no-bitmaps.conf, or in higher versions, /etc/fonts/conf.d/10-bitmaps.conf. To enable bitmap fonts and keep them enabled after upgrades of fontconfig, place a symlink from yes-bitmaps.conf to 10-bitmaps.conf, overwriting the symlink to no-bitmaps.conf.

Fake bold & italic styles for incomplete fonts

Freetype already has had this capability for some time, but only if app asks so (which never happens) - it's not going to add Bold or Italic style for those regular-only fonts anyway. To make up them, you need to edit /usr/share/fonts/fonts.cache-1 manually (and keep your modification somewhere because font update (fc-cache) overrides it). Assume you have a font Dupree:

     "dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:....

Duplicate the line, change style=Regular to style=Bold or other styles you want. Also change slant=0 to slant=100 for italic, weight=80 to weight=200 for bold (combine for bold italic):

     "dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:....

Now add necessary modification to ~/.fonts.conf:

     <match target="font">
        <test name="family" qual="any">
           <string>Dupree</string>
           <!-- other fonts here .... -->
        </test>
        <test compare="more_eq" name="weight"><int>140</int></test>
        <edit mode="assign" name="embolden"><bool>true</bool></edit>
     </match>
     <match target="font">
        <test name="family" qual="any">
           <string>Dupree</string>
           <!-- other fonts here .... -->
        </test>
        <test compare="more_eq" name="slant"><int>80</int></test>
        <edit mode="assign" name="matrix">
           <times>
              <name>matrix</name>
              <matrix>
                 <double>1</double><double>0.2</double>
                 <double>0</double><double>1</double>
              </matrix>
           </times>
        </edit>
     </match>

(Note that you can use embolden for bold fonts as well - to make them even bolder)

Example ~/.fonts.conf

A web developer's ~/.fonts.conf taken from the forums. Back up your current config and give this one a try.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">

<!-- the cathectic LCD tweaks, from linuxquestions.org,
 http://www.linuxquestions.org/questions/showthread.php?postid=1361098#post1361098 -->

<fontconfig>

<!-- Disable sub-pixel rendering.
 X detects it anyway, and if you set this as well, it just looks really horrible  -->
<match target="font" >
	<edit mode="assign" name="rgba" >
	 <const>none</const>
	</edit>
 </match>
 <match target="font" >
	<edit mode="assign" name="hinting">
	 <bool>true</bool>
	</edit>
 </match>
 <match target="font" >
	<edit mode="assign" name="hintstyle">
	 <const>hintfull</const>
	</edit>
 </match>

<!-- The first part of the 'magic.'
 This makes the fonts start to look nice,
 but some of the shapes will be distorted, so hinting is needed still -->
 <match target="font" >
	<edit mode="assign" name="antialias">
	 <bool>true</bool>
	</edit>
 </match>

<!-- Autohinter is not turned on automatically.
 Only disable this if you have recompiled Freetype with the bytecode interpreter,
 which is run automatically.<br />  -->
 <match target="pattern" >
	<edit mode="assign" name="autohint">
	 <bool>true</bool>
	</edit>
 </match>
 <match target="font">
		 <test name="weight" compare="more">
				 <const>medium</const>
		 </test>
		 <edit name="autohint" mode="assign">
				 <bool>false</bool>
		 </edit>
 </match>
<!-- Helvetica is a non true type font, and will look bad.
 This replaces it with whatever is the default sans-serif font -->
 <match target="pattern" name="family" >
	<test name="family" qual="any" >
	 <string>Helvetica</string>
	</test>
	<edit mode="assign" name="family" >
	 <string>sans-serif</string>
	</edit>
 </match>
 <dir>~/.fonts</dir>
</fontconfig>

fonts.conf from the forum - looking very good

This font config is taken from this thread: http://bbs.archlinux.org/viewtopic.php?id=78631 from the user: brebs. His font.conf:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>


	<!-- Info:
	xeffects thread:  http://forums.gentoo.org/viewtopic-t-511382.html
	http://wiki.archlinux.org/index.php/XOrg_Font_Configuration
	http://antigrain.com/research/font_rasterization/index.html
	http://fontconfig.org/fontconfig-user.html
	-->


	<!-- http://bugs.gentoo.org/show_bug.cgi?id=130466 -->
    <alias>
        <family>serif</family>
        <prefer>
            <family>DejaVu Serif</family>
            <family>Bitstream Vera Serif</family>
        </prefer>
    </alias>

    <alias>
        <family>sans-serif</family>
        <prefer>
            <family>DejaVu Sans</family>
            <family>Bitstream Vera Sans</family>
            <family>Verdana</family>
            <family>Arial</family>
        </prefer>
    </alias>

    <alias>
        <family>monospace</family>
        <prefer>
            <family>DejaVu Sans Mono</family>
            <family>Bitstream Vera Sans Mono</family>
        </prefer>
    </alias>




	<!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
	<selectfont>
		<rejectfont>
			<pattern>
				<patelt name="scalable">
					<bool>false</bool>
				</patelt>
			</pattern>
		</rejectfont>
	</selectfont>


	<!-- Replace Luxi Sans with a better-looking font - looks terrible at e.g. http://market-ticker.org/ -->
	<match name="family" target="pattern">
		<test name="family" qual="any">
			<string>Luxi Sans</string>
		</test>
		<edit name="family" mode="assign">
			<string>Liberation Sans</string>
		</edit>
	</match>



	<!-- To fix Calibri font - http://forums.fedoraforum.org/showthread.php?p=1045807#post1045807 -->
	<match target="font">
		<edit name="embeddedbitmap" mode="assign">
			<bool>false</bool>
		</edit>
	</match>


	<!-- Replace Calibri font - http://www.funtoo.org/css/article.css
	<match name="family" target="pattern">
		<test name="family" qual="any">
			<string>Calibri</string>
		</test>
		<edit name="family" mode="assign">
			<string>Trebuchet MS</string>
		</edit>
	</match>
	 -->

    <match target="pattern" name="family">
        <test qual="any" name="family"><string>fixed</string></test>
        <edit name="family" mode="assign"><string>monospace</string></edit>
    </match>

	<!-- Ubuntu options:  lcdnone, lcddefault, lcdlight, lcdlegacy -->
	<!-- hintnone, hintslight, hintmedium, hintfull -->
	<!-- Keep autohint off -->
	<!-- Blurry fonts:  Try rgb, bgr, vrgb, vbgr for "rgba" -->
	<!-- Blurry:  http://forums.gentoo.org/viewtopic-p-5060979.html#5060979 -->
	<match target="font">
		<edit name="rgba" mode="assign"><const>rgb</const></edit>
		<edit name="autohint" mode="assign"><bool>false</bool></edit>
		<edit name="antialias" mode="assign"><bool>true</bool></edit>
		<edit name="hinting" mode="assign"><bool>true</bool></edit>
		<edit name="hintstyle" mode="assign"><const>hintmedium</const></edit>
		<edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
	</match>



	<!-- http://bbs.archlinux.org/viewtopic.php?id=46480  Rubbish font anyway -->
	<!--
	<match target="pattern">
		<test name="family" compare="eq"><string>ProggyCleanTTSZ</string></test>
		<edit name="pixelsize" mode="assign"><double>16</double></edit>
		<edit name="autohint" mode="assign"><bool>false</bool></edit>
		<edit name="antialias" mode="assign"><bool>false</bool></edit>
		<edit name="hinting" mode="assign"><bool>false</bool></edit>
		<edit name="hintstyle" mode="assign"><const>hintnone</const></edit>
	</match>
	-->
	<!-- The bold variant is ugly, so replace it
	<match target="pattern">
		<test name="family" qual="any" compare="eq"><string>ProggyCleanTTSZ</string></test>
		<test name="weight" compare="more"><const>medium</const></test>
		<edit name="family" mode="assign"><string>Bitstream Vera Sans Mono</string></edit>
		<edit name="pixelsize" mode="assign"><double>10</double></edit>
	</match>
	-->


	<!-- Reduce hinting for bold fonts -->
	<match target="font">
		<test name="weight" compare="more"><const>medium</const></test>
		<edit name="autohint" mode="assign"><bool>false</bool></edit>
	</match>


	<!-- Greyscale for small fonts
	<match target="font">
		<test name="size" compare="less_eq"><double>7</double></test>
		<edit name="rgba"><const>none</const></edit>
	</match>
	-->





    <!-- Tweak Courier -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Courier</string>
        </test>
		<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
    </match>

    <!-- Tweak Courier New -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Courier New</string>
        </test>
		<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
    </match>





	<!-- From http://forums.gentoo.org/viewtopic-t-511382-start-650.html
	To create difference between small Candara and small Candara bold -->
	<match name="family" target="pattern">
		<test name="family" qual="any">
			<string>Candara</string>
		</test>
		<test compare="less_eq" name="size">
			<double>10</double>
		</test>
		<test name="weight" compare="more">
			<const>medium</const>
		</test>
		<edit name="embolden" mode="assign">
			<bool>true</bool>
		</edit>
	</match>


	<!-- From http://www.fedoraforum.org/forum/showthread.php?t=186789&page=7 -->
	<match target="font">
		<test compare="eq" name="family">
			<string>Consolas</string>
		</test>
		<edit mode="assign" name="hintstyle">
			<const>hintslight</const>
		</edit>
	</match>

	<match target="font">
		<test compare="eq" name="family">
			<string>Inconsolata</string>
		</test>
		<edit mode="assign" name="hintstyle">
			<const>hintslight</const>
		</edit>
	</match>


  <!-- From http://bugs.gentoo.org/show_bug.cgi?id=233729 -->
  <match target="font">
    <test compare="eq" name="family">
      <string>Andale Mono</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Arial</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Comic Sans MS</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Georgia</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Impact</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Times New Roman</string>
    </test>
    <!-- Looks better with lcdlegacy, e.g. http://www.billiardworld.com/glossary.html -->
	<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Trebuchet MS</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Verdana</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
    <test compare="less" name="weight">
      <const>medium</const>
    </test>
    <test compare="less_eq" name="pixelsize">
      <double>7</double>
    </test>
    <edit mode="assign" name="antialias">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font">
    <test compare="eq" name="family">
      <string>Webdings</string>
    </test>
    <edit mode="assign" name="hintstyle">
      <const>hintfull</const>
    </edit>
  </match>

</fontconfig>

Personal experience with this config. This is the very first config i found that makes everything look nice. Firefox looks good. All of gnome looks good. Even gmail looks good with this font configuration. I also kinda hate the user only font config way by saving it in ~/.fonts.conf so i saved it globally in /etc/fonts/local.conf if the file doesn't exist you can make it.