KDE and Xorg, Fonts and DPI

Today, I’d like to share a tip I found out while working with a beta release for a distirbution of Linux with KDE’s 3.5.7 version. As many readers of this blog know, I use PCLinuxOS 2007 as my main desktop and have done so since about 2005. The font configuration in PCLinuxOS is quite nice. I have a 19 inch LCD Monitor at home with 1280×1024 resolution. I notice no problems with the font on that monitor.

Working on a separate 20 inch monitor with a distribution in development however is another story. The fonts didn’t look beautiful at all. After some installation of custom fonts, things looked better, but the resolution is a bit higher on this LCD at 1400×1050. Easy to fix right? Just increase the DPI in the KDE Control Center to 120 right? Not so fast…even when it’s set to 96×96 there, it isn’t always set to 96×96. So let’s take a look at how you can force KDE to run at the correct DPI for your monitor which will, in turn, make your fonts look MUCH better. For those of you who are satisfied with your fonts, you might want to check out the commands below to see if you’re running at the DPI you think you are.

Open Konsole and let’s check your resolution:

xdpyinfo | grep dimension

This will tell you what the actual resolution of X is on your desktop. Next, look at the DPI setting.

xdpyinfo | grep resolution

Surprised? I was. I found that at the high resolution I was running at, the DPI was set to 86×86 despite my attempts to force it to 96×96 in the KDE Control Center.

So how does one combat this? It takes a bit of calculation with a formula followed by a one line entry into your xorg.conf. Easy enough? Almost too easy…couldn’t the KDE programmers, say, employ a control center menu for this? It’s possible…let’s hope it’s in KDE 4.0.


First, the formula. Using the dimensions you found above, you’ll have to calculate 2 numbers…one for horizontal and one for vertical. As my resolution is 1400×1050, I will use this as the example. The formula is as follows:

displaysize = (<pixelsize>/DPI-Desired)*25.4

In my case, displaysize = (1400/100)*25.4. This equals 355. I wrote this down for later. Now I need to use 1050 (my vertical setting for resolution 1400×1050) in the same formula (displaysize =(1050/100)*25.4) which comes out to 266. Keep these two numbers handy…remember, if you want 96 or 120 DPI for your monitor…sub in those numbers for the DPI-Desired and divide your resolution by them as shown in the formula above.


Open up xorg.conf in your favorite text editor..for example, my favorite is kate so I issue the following command: Alt-F2 (a run dialog pops up) >> kdesu kate /etc/X11/xorg.conf. You’ll be prompted for your root password to access this file. After it opens, find the “Monitor” section. Just before “EndSection” place a line like the following (substitute the values you found using the formula above):

DisplaySize 355 266 # 1400×1050 100dpi

Your display size may be different…just remember to place horizontal first, followed by vertical. Now you’ll need to restart X. Close all your applications and hit Control-Alt-Backspace. Log back in and issue the command we used previously for DPI:

xdpyinfo | grep resolution

If you followed the directions above correctly, your altered DPI settings should display. Gnome does this through a handy menu that’s very easy to use. It’s head and shoulders above what KDE does with fonts and setting DPI. Using Gnome at work for the past 4 months has shown me the many areas that KDE falls behind…but it also shows me the many areas where Gnome just doesn’t get the job done. In this case, KDE fails horribly on configuring DPI for nice looking fonts. Luckily, I was able to assemble information from various places on the web to get the job done. The page that helped me the most was Matt Parnell’s Brain, a weblog that had an entry with this formula. I wanted to reproduce the information here with a bit more hand holding so new users would be able to use the tip without getting confused. Hopefully, this helps!

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

  • Kanwar

    I have a laptop with 1400×1050 optimal resolution. xdpyinfo | grep resolution shows 124 x 125 dots per inch.

    I tried to use the above method to set 96 dpi but did not work. I have set 96 dpi in KDE control center and modified Monitor section in xorg.conf.

  • http://linux-blog.org devnet

    I’m not sure why you would want to *drop* the DPI as this results in lower quality fonts…and I’m not sure why this isn’t working for you.

    It works fine when going UP for DPI but I’ve not tried going DOWN. I’m at a loss for why this wouldn’t work.

  • http://forwardlateral.com/ Michael Birk

    I have a high-DPI screen and enjoy large, nicely anti-aliased fonts. If you use KDE, then another tip is to install the [b]GTK Styles and Fonts[/b] module (gtk-qt-engine in debian/ubuntu) and configure it via [b]System Settings / Appearance / GTK Styles and Fonts[/b]. I set it to “Use my KDE style in GTK applications”, which makes Firefox and Thunderbird (among other GTK apps) match the system’s look and feel:


  • http://www.patheyman.com Pat Heyman

    And while you’re installing the gtk-qt-engine, you may as well install kgtk. Then you can get rid of those stupid, useless gtk save and open dialogs and use kde’s. Just change your k menu’s icon commands to run through kgtk: gimp –> /usr/bin/kgtk-wrapper gimp

  • http://forwardlateral.com/ Michael Birk

    Thanks for the tip, I checked it out. Unfortunately it didn’t work too well for me. In particular Firefox, Thunderbird — it had no apparent effect. The symlink technique wasn’t working either. Maybe I’ll try trunk …

  • http://www.hackitlinux.com/ linux tip

    Very interesting, I have to try this tips. I enjoy reading this articles, thanks for sharing.

  • ristik

    By the way, this advanced secret formula finds out Your display size in millimeters (if DPI is correct). I’d recommend to measure it out directly.

  • Alexandra

    A really helpful article, thanks!
    Adding the DisplaySite line to the monitor section of xorg.conf however didn’t work for me. Having an nvidia card I set the DPI in the “device” section instead like so:

    Option “DPI” “96 x 96″

    This did the trick. After restarting X xdpyinfo now shows the desired 96×96 dots per inch.

    • Nishiyama

      Thanks Alexandra, your tip with the additional parameter to the device section worked perfect for me.

  • Marvin Renich

    In addition to putting DisplaySize in the Monitor section, you should also put Option “UseEdidDpi” “false” in the same monitor section (for some driver/monitor combinations, e.g. Nvidia on many laptops). I believe that drivers that don’t use “UseEdidDpi” will ignore it, possibly with a warning in Xorg.*.log.

  • Pingback: Setting the uifont in Firefox 3.04? | keyongtech

  • Pingback: Running on Gnome : Caramboo Dot Com