LCD Monitor Configuration In X.Org: Difference between revisions
(Migrated from old wiki)
m (Added to Hardware Category)
|Line 1:||Line 1:|
Latest revision as of 02:29, 3 June 2009
If there is nothing wrong with your display, please don't go mucking about with your ~/.fonts.conf file (at least, back it up first). If you do have problems with your LCD display, then this is a good bet to try. If you have any success or failure, please do report this back, and changes, if any, that you made to your .fonts.conf file and any other file (perhaps /etc/X11/xorg.conf?) Comments, corrections and thoughts are always welcome.
This may well also work with XFree86 > 4.3, since they use the same font configuration files as this. Older versions have a non-XML font configuration setup (I don't know when the switch over was made though), and will not be covered.
WARNING - Parts of this article are out of date, and there are a few changes required for modular X. These will be added soon.
LCD/TFTs display fonts very differently to a CRT. Unfortunately with Slackware's default settings on X.Org/FreeType, the results for fonts on an LCD are painful to say the least. This is further compounded by the fact that all the 'helpful' HOWTOs out there are badly out of date, referring to ancient versions of the now defunct XFree86. Whilst there are a few sites out there with bits of information, putting into a workable solution is quite a challenge.
This exists, therefore, to show the naysayers that they're wrong, and that you _can_ enjoy nice looking fonts in Slackware.
(Please note, this is _not_ an exhaustive HOWTO, and it is _not_ a HOWTO about .fonts.conf (please see the Bibliography for a site detailing the tags available in .fonts.conf). This HOWTO is only about configuring an LCD monitor and what works best for one)
What You'll Need
- Your favourite text editor
- X.Org (or a later edition of XFree86 >4.3. This has only been tested on Slackware 10.1 and above).
- An LCD/TFT monitor (most of this may also apply to an LCD monitor on a laptop).
(I humbly apologise in advance for this section, but better safe than sorry.)
(Standalone Monitors only) Plug up your LCD. Where possible, use the DVI-D (i.e. The digital, not analogue VGA) connector, if both your monitor and your graphics card have one. If not, use an analogue VGA cable and connection (where possible, avoid using DVI-D to VGA adaptors.) Then, ensure the viewing angle of your LCD is correct. Play around with it until you are happy.
As far as I know, there is no special configuration of X needed for an LCD monitor. Just create the necessary entry for a monitor in /etc/X11/xorg.conf with the correct refresh rates as normal and enjoy (the monitor itself may even be able to give you these, mine does.) I won't cover this in any more detail, as it's pretty standard and covered better elsewhere.
X will also detect the correct sub-pixel alignment, so you don't need to deal with that either.
Fonts and FreeType
The real problems begins with font rendering in X. If you are switching over on your machine from a CRT to an LCD, what is facing you at first sight will be unpleasant to say the least.
Of course, this isn't down to X, as in all modern X servers from X.Org (and the later ones from XFree86) FreeType is responsible for all font rendering (any other modules loaded in your /etc/X11/xorg.conf for font rendering are anachronisms: they are no longer used, and X tells you they don't exist). Something I've seen a lot is that “fonts looked better on 9.0” or earlier versions of Slackware, and there is good reason for this. With the changeover to FreeType2, due to various Apple patents in the US and Japan, the 'bytecode interpreter' is now disabled by default. (Plus, IMHO, the Bitstream fonts that ship with Slackware aren't very good). With a CRT, this isn't much of a problem, but it does make a lot of difference on an LCD and is nearly illegible.
There are two ways round this, either:
- Make alterations to .fonts.conf to try and make the Bitstream fonts render better on an LCD.
- Rebuild FreeType with the bytecode interpreter, and use the properly hinted MS fonts (Arial, et al) to get cleaner, crisper looking fonts on the LCD.
Both of these solutions give different results (though I prefer the second).
For both alternatives, there are some common settings that must be made.
If you're using KDE or GNOME, you'll find they have tools for doing some of what I'm going to describe. However, I would recommend _against_ using them. I've found their attempts at generating and editing a .fonts.conf file to be dubious to say the least. It is much more preferable to edit the file yourself, and since it is now done through a well defined XML file, this isn't as bad as it once appeared to be (judging from some of those ancient HOWTOs).
Crank up your editor and load ~/.fonts.conf (or /etc/fonts/local.conf)
If it exists: Just add these sections to it, inside the <fontconfig></fontconfig> tags. If it doesn't exist: Use my ~/.fonts.conf skeleton from Appendix A as your .fonts.conf and edit as necessary.
1. Ensure that the sub pixel order is _not_ specified.
X knows the sub pixel order already, and if this is enabled as well, FreeType produces some very strange results. However, if you do still have problems, consider replacing 'none' with 'rgb' (the standard for LCD monitors), 'bgr' (unusual), 'vrgb' (vertical rgb, if you have a monitor that has been rotated by 90 degrees), 'vgbr' (as vrgb, but very rare).
<match target="font" > <edit mode="assign" name="rgba" > <const>none</const> </edit> </match>
2. Enable sub-pixel hinting
This is what really starts to make the difference. Visit http://grc.com/ctwhat.htm for the technical explanation of why we're doing all of this.
<match target="font" > <edit mode="assign" name="hinting" > <bool>true</bool> </edit> </match>
3. Set the hinting amount
Usually, this should be full. Valid options are 'none', 'hintslight', 'hintmedium' and 'hintfull' which should be fairly self explanatory if you've read the article at the link above.
<match target="font" > <edit mode="assign" name="hintstyle" > <const>hintfull</const> </edit> </match>
Option 1) The 'Easy' Way
Essentially, we're going to enable FreeType's non-patented autohinter and antialiasing to improve the appeareance of the default Bitstream fonts.
Add the following to ~/.fonts.conf.
- Enable anti aliasing
This makes the fonts start to look nice, but some of the shapes will be distorted, so we need the FreeType autohinter (see next part).
<match target="font" > <edit mode="assign" name="antialias" > <bool>true</bool> </edit> </match>
You may need to enable anti alias separately on Fluxbox before it takes notice of the changes:
fluxbox menu --> Configure --> AntiAlias
- Enable the FreeType autohinter
The autohinter is not turned on automatically, so we have to do this manually.
Please note that OpenOffice.org binaries from the OOo website are built against the bytecode interpreter, so even if you have compiled FreeType with the bytecode interpreter and override it with the autohinter, OOo will still use the bytecode interpreter.
<match target="pattern" > <edit mode="assign" name="autohint" > <bool>true</bool> </edit> </match>
Option 2) The 'Hard' Way
This is my (User:Cathectic) preferred solution, as I believe it gives better results. This involves rebuilding FreeType with the bytecode interpreter enabled, and then using the properly hinted fonts 'Core Fonts For the Web' from Microsoft.
For this, you will need to:
- Get a copy of FreeType that has the bytecode interpreter enabled.
- Download the Freetype sources from your local Slackware mirror (slackware-$VERSION/source/l/freetype)
- In freetype.SlackBuild, uncomment the line to apply the bytecode enabling patch
- Run the SlackBuild
- Replace your old freetype package with the new one you've just built.
32bit X Applications (Slamd64 only): To enable 32bit applications in Slamd64 to use the bytecode interpreter, you need to install a 32bit bytecode enabled FreeType.
- Download and install the 'Microsoft Core Fonts for the Web' (if you have a Windows installation, you could import the fonts from that instead. This tutorial assumes you do not) from either:
- LinuxPackages (install CabExtract, then CoreFonts)
- Or, From the 'Core Fonts for the Web' at http://prdownloads.sourceforge.net/corefonts/
- Get all the *.exe files
- Get the CabExtract source RPM, rpm2tgz it, untar, build and install
- Use CabExtract to extract the *.ttf's from the *.exe's you downloaded, and then move the fonts to /usr/X11/lib/X11/fonts/TTF (/usr/share/fonts/TTF for X.Org 7 or newer).
Now add the following to ~/.fonts.conf
1. Disable the autohinter
This isn't strictly necessary – the autohinter is not enabled by default, and if it's not enabled, the bytecode interpreter is used by default. However, it's better safe than sorry.
<match target="pattern" > <edit mode="assign" name="autohint" > <bool>false</bool> </edit> </match>
2. Set the MS fonts as defaults
<match target="pattern" name="family" > <test name="family" qual="any" > <string>sans-serif</string> </test> <edit mode="assign" name="family" > <string>Arial</string> </edit> </match>
<match target="pattern" name="family" > <test name="family" qual="any" > <string>monospace</string> </test> <edit mode="assign" name="family" > <string>Courier New</string> </edit> </match>
<match target="pattern" name="family" > <test name="family" qual="any" > <string>serif</string> </test> <edit mode="assign" name="family" > <string>Times New Roman</string> </edit> </match>
(I would also recommend using the template in Appendix B to replace all the Bitstream and Luxi fonts with the MS equivalents (or set them to use serif, sans-serif, monospace instead)).
Just load any application up (I'd recommend a Gtk one, KDE will probably need a restart for the changes to take affect everywhere), and the changes should be immediately obvious (I used Mozilla Firefox, by opening and closing it after every tweak of ~/.fonts.conf, I was able to see the changes immediately).
Apply System Wide
You can apply these changes system wide, using /etc/fonts/local.conf
If it exists, just append the sections you added above to it. If it doesn't, use your .fonts.conf as /etc/fonts/local.conf, and edit it as necessary
(The order of precedence for processing is /etc/fonts/fonts.conf (automatically generated, don't edit it), /etc/fonts/local.conf then ~/.fonts.conf - meaning your ~/.fonts.conf will always override the system settings).
Application Specific Settings
Qt and Gtk settings need to be changed.
For gtk, edit .gtkrc-2.0 and set the fonts either to the generic 'serif', 'sans-serif', etc (now aliased to the MS fonts), or specify the MS fonts outright.
For qt, edit .kde/kderc and .qt/qtrc
Non TrueType fonts
Non TrueType fonts don't render well on LCDs as they don't support hinting. For these fonts (e.g. Helvetica), it is recommended that you specify an alternative TrueType font (that is hopefully similar, but it doesn't have to be!) to use instead (in this case, whatever the default sans-serif font on the system is):
<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>
You can easily reuse this for other fonts. Just copy and paste, then replace 'Helvetica' with the font to replace, and 'sans-serif' with the font you want to replace it with (or you can use the generic descriptions 'serif', 'sans-serif' or 'monospace').
Some programs (usually older ones) using these libraries may not always use anti aliased fonts, even if you've specified them in .fonts.conf. This can fixed by:
Gtk: Add the following to /etc/profile: export GDK_USE_XFT='1'
qt: In ~/.qt/qtrc, ensure the following entry is present under [General]: enableXft=true useXft=true
Programs coded using Gtk 1.x don't appear to support anti aliasing properly – you may want to consider replacing them with ones that use Gtk 2.x (e.g. Replacing XMMS with its Gtk2 fork, Beep Media Player)
OpenOffice.org binaries are built against the bytecode interpreter. If you install a bytecode enabled FreeType, OOo will always use it, regardless of any system settings enabling the autohinter. Also, OpenOffice.org fonts have to be changed manually.
Tools > Options > OpenOffice.org > 'Use system font for user interface' (make sure this is checked).
The following is a ~/.fonts.conf / /etc/fonts/local.conf skeleton. Use this to put together a working configuration for your system.
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> </fontconfig>
This section is a recommendation only. Some fonts are not TrueType, which means they don't support anti aliasing and look dreadful on an LCD. The way round this is to tell FreeType to replace any such fonts with a properly hinted TrueType equivalent. All of the Bitstream and Luxi fonts should be aliased in this way (some sites, such as Gnome's home page, use these fonts, and they don't render correctly with the bytecode interpreter).
You can copy, paste and edit the following example for Helvetica for any other fonts you want to replace. (Just replace 'Helvetica' with the font to replace, and 'sans-serif' with the font you want it to be replaced with. Generic font descriptions serif, sans-serif and monospace are valid entries, as well as specific font names.)
<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> <alias>
 Apparently, there are some monitors where the screen can be rotated. If so, perhaps the vrgb/vbgr settings might be better for you (but only when the screen is rotated) If you can test this, please report back the results.
Man Page of fonts.conf - http://www.fontconfig.org/fontconfig-user.html
XFree86 Font Configuration - http://www.xfree86.org/current/fonts2.html
Explanation of Sub Pixel Hinting - http://grc.com/ctwhat.htm
Gentoo Xorg & Fonts (And how to fix Konsole Linux fonts problem) - http://gentoo-wiki.com/HOWTO_Xorg_and_Fonts
If you're running an old version of XFree http://www.tldp.org/HOWTO/FDU/index.html