Wednesday, May 17, 2006

How to configure LCD/TFT Monitor

LCD/TFT Monitor Configuration in X.Org
**DISCLAIMER**

I only have one monitor to test this with. The results back have been mixed so far from others. 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 > 3.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 I will *not* cover this.

Contents

1) Prologue
2) Introduction
3) Thanks
4) What You'll Need
5) Physical Setup
6) Settings
7) Thoughts
Non TrueType fonts
Gtk/qt
8) Appendix A
9) Bibliography

1. Prologue

The scenario: On 10th November 2004, my Sony CPD-210EST 17" CRT monitor reached the end of its life. At 11:13am (GMT) 11th November, it was declared DOA. In its place, since no one really sells decent CRT monitors any more, I replaced it with a Hyundai Q17+ 17" LCD/TFT monitor.

2. Introduction

LCD/TFTs display fonts very differently to a CRT. If you have a distribution that can deal with this all, then great. If not, with default settings on X.Org/Freetype, the results for fonts 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, no one site has put together a workable solution specifically for an LCD on a modern distribution.

This exists, therefore, to show the naysayers that they're wrong, and that you _can_ enjoy nice looking fonts in Linux.

(Please note, this is _not_ an exhaustive HOWTO, and it is _not_ a HOWTO about .fonts.conf (please see my Bibliography for a site detailing the tags available in .fonts.conf. This HOWTO is only about configuring an LCD and what works best for one))

3. Thanks

Transformer, The ? For blowing up on my last monitor and leading me to an LCD.
synaptical ? First person to report back that my .fonts.conf actually worked elsewhere!
J.W. - Suggested that I actually write this up on LQ.org

4. What You'll Need

Your favorite text editor (not vi, obviously =:-P)
X.Org (or a later edition of XFree86 >3.3? Not tested on XFree86 though)
An LCD/TFT monitor (obviously! I haven't tested this on laptops, but I'm told it does make a difference)

5. Physical Setup

?It's alive!?

(I humbly apologize in advance for this section, but better safe than sorry.)

Plug up your LCD. Where possible, use the DVI-D (i.e. The digital, not analogue VGA) connector. Then, ensure the viewing angle of your LCD is correct. Play around with it until you are happy.

6. Settings

?Treachery, faith and the X server?

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 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.

?Damned, dirty fonts?

The real problems begins with font rendering in X. If you are switching over on your machine from a CRT to an LCD, I can guarantee that 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.) Therefore, we need to throw everything that Freetype has against these fonts to cure this.

If you're using KDE or GNOME, you'll find they have tools for doing what I'm going to describe. However, I would recommend _against_ using them. I've found their attempts and 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.

If it exists: Just add these sections to it, inside the tags.
If it doesn't exist: Use my .fonts.conf from Appendix A as your .fonts.conf and edit as necessary. I have annotated the file, and you can also easily follow my instructions below (but all these sections are already in my example file)

The steps are:

1. Ensure that the sub pixel order is _not_ specified.

This goes against everything that all the other HOWTOs put together say, but there is yet method in my madness.

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[1]), 'vgbr' (as vrgb, but very rare).


none


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.


true


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.


hintfull


4. 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.


true


5. Enable the Freetype autohinter

Autohinter is not turned on automatically. Only disable this if you have recompiled Freetype with the bytecode interpreter, which is run automatically.

Although to be honest, Freetype are right, and the autohinter is actually better. 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.


true


6. Testing

Just load any application up, 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).

7. Make changes system wide

If you like your users (however ungrateful they may be), 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 local .fonts.conf will always override the system settings).

7. Thoughts

Non TrueType fonts

Non TrueType fonts don't render well on LCDs as they don't support anti aliasing. 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):


Helvetica


sans-serif


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').

Gtk/qt

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)

8. Appendix A

The following is my .fonts.conf file. Just drop it into your home directory, load up a program and compare it to your already running ones. If the results are good enough, then you can add the contents of this file to /etc/fonts/local.conf (if it doesn't exist, just create the file with the .fonts.conf. If it does, copy what you need inside the tags) to override the settings for all your users, and save them from having to figure this out.

If it doesn't work, then I have annotated the file to indicate what you might need to change.

2 comments:

Unknown said...

Here are the 3.5 QVGA 4.3 WQVGA 5.7 QVGA 7 WVGA TFT LCD modules, and always trying to stay in LCD technology in the forefront of our current technology products, including COG, COF, TAB, SMT. Believe that through our cooperation, the displayed a better world.Graphic LCD Display . click here

Unknown said...

Very informative post. Keep up the good work. I would really look forward to your other posts

Lenovo - 12.5" ThinkPad Notebook - 4 GB Memory - 320 GB Hard Drive - Black

Lenovo - 15.6" Essential Notebook - 4 GB Memory - 500 GB Hard Drive