You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



Mozilla DPI-related Font Size Issues on Unix

Mozilla Fonts Overview

A number of factors can cause fonts in Mozilla to seem wrong. For web page text, you can choose your default sizes and styles via the UI preferences panel. Typically, web page authors override some or all of your preferences via stylesheets and/or presentational markup. Mozilla has a minimum text size preference and text zoom to help you combat author styles that override your defaults. It is also possible to override author overrides via user stylesheets.

Fonts can seem wrong in Mozilla's menus, tools and bookmarks too. Doing something about it is the topic of this page.

How UI Fonts in Mozilla are Configured

Mozilla sets UI fonts by querying the operating system's font subsystem for CSS system fonts. In most environments, these are set in points. Point sized controls only display at the intended size if the system DPI is reasonably configured.

Since some web page authors size text in points, inappropriately configured DPI also can adversely impact web page text sizes.

DPI Problem Solving

Both points and DPI either too small or too big are typically caused by a mismatch between your real display size and the display size your X server thinks you have. So, if you don't like Mozilla's UI font sizes, start to correct your problem by reconciling the two sizes. Measure your display, and change whatever settings are required to cause the X server to report and use the actual display size.

GTK1 Mozilla does not respond to DPI adjustments with corresponding changes in UI fonts. Adjustments to GTK1 UI fonts must be made via gnomecc or via userChrome.css.

To find out what your X server thinks your DPI settings are, run the program xdpyinfo:

	$ xdpyinfo | grep dimensions
	$ xdpyinfo | grep resolution

Note the dimensions in pixels and millimeters, and the resolution in DPI. Compare to what you're actually using, but don't confuse dots and pixels - a dot may or may not equal a pixel. If you have KDE, kinfocenter's X-Server section will conveniently show the same information.

For example, if you use a 17" CRT display, your viewable screen dimensions will be approximately 328 mm wide by 246 mm tall. This actual size could traditionally be forced by adding:

	DisplaySize	328	246
to
	Section "Monitor"

in /etc/X11/XF86Config or /etc/X11/xorg.conf, as applicable on your system. If you are running a 1400 X 1050 resolution with a 328 mm X 246 mm display, your system will be running at an actual 108 DPI. This change may be sufficient to correct your problem. If it fails and you are running Xorg 7.2 or newer, you may need to add:

	Option	"NoDDC"
to
	Section "Device"

for your graphics adapter in order for DisplaySize to work.

If the above change improves your system, but the result is less than 100% to your satisfaction, you can tweak sizes up or down by making the DisplaySize dimensions slightly larger or smaller than actual.

Unfortunately, variations in the implementations of X mean display size reconciliation as above won't be a solution on every system. Failure here seems to be common on newer systems using fontconfig instead of legacy xfs.

Systems using fontconfig provide an option for X and applications that understand it to set DPI via the Xft.dpi variable. To find out if Xft.dpi has already been set, check by running the program xrdb -query:

	$ xrdb -query | grep dpi

The regular file /etc/X11/Xresources is one place this might be set, where you might find it present, but commented out. On systems with the directory /etc/X11/Xresources, Xft.dpi can be set in ~/.Xresources. Another location it can be set is ~/.Xdefaults. On such systems, adding to the applicable file:

	Xft.dpi: 108

or uncommenting an existing line would produce the same result as setting DisplaySize produces for xfs. On some systems, setting DisplaySize first, and then setting Xft.dpi to match the reported DPI is required for proper results.

As above, if this works, but at less than 100% satisfaction, tweak the number lower or higher to suit your preference. If possible, use a number that is a multiple of 6, or even 12, as numbers that aren't sometimes result in annoying rounding errors that cause adjacent bitmap font sizes to not increment and decrement linearly.

All Mozilla.org builds of Firefox and SeaMonkey, some of Mozilla, and most builds of these products supplied by recent Linux distros, are built using the GTK2 toolkit. This means that gnome-control-center can be used to explicitly set DPI to a desired value that these builds will share with all other GTK2 apps.

Some users have found success in adjusting the X server's DPI by doing one of the following:

  1. Using the graphical login screen:

    In /etc/X11/xdm/Xservers, change:

    	:0 local /usr/X11R6/bin/X

    to:

    	:0 local /usr/X11R6/bin/X -dpi 100

    You need to restart xdm for this to work:

    	$ su - root
    	# telinit 3
    	# telinit 5
  2. Using Redhat and gdm:

    In /etc/X11/gdm/gdm.conf, change:

    	0=/usr/bin/X11/X

    to:

    	0=/usr/bin/X11/X -dpi 100

    You will need to restart gdm for this to work

  3. In some Debian variants:

    In /etc/init.d/xsession, or /etc/kde3/kdm/Xservers, change:

    	DPI="-dpi 75"

    to include whatever DPI you wish to use instead of 75.

    You will need to restart X for this to work

  4. Using startx from the command line:

    $ startx -- -dpi 100

If none of the above or variations thereof work, as a last resort, you can use the brute force method of forcing Mozilla to use a particular DPI directly. Edit your user.js file and add:

	user_pref("layout.css.dpi", 108);

You may change the DPI number to any resolution you like. Setting it to 0 will restore Mozilla's use of the X Server DPI. Like prefs.js, user.js is a plain text file in your profile directory. If it doesn't exist, create it with your choice of text editor.

As an alternative to editing user.js, you can change layout.css.dpi by entering

	about:config

in the urlbar, right clicking the current value, and changing it to any number you like.

A third way to change Mozilla DPI by brute force in older versions is via the preferences UI:

	Appearance	->	Fonts	->	Display resolution

Changes to layout.css.dpi by any of the three methods above require a complete Mozilla restart to take effect.

Note that for cross-platform uniformity reasons, Mozilla by default uses the greater of your system setting or 96. If you wish Mozilla to use a DPI of less than 96, you must force it to do so using layout.css.dpi, either automatically by supplying the parameter 0, or by the DPI integer value you wish used.

Choosing Your Mozilla

Not all Mozilla builds are suitable for all systems. Legacy systems use the xfs font service system exclusively. Standard builds must be used on these systems for reasonable results. Newer systems use the fontconfig font service system in addition to xfs. You can use any Mozilla build on these systems, but xft labeled builds should produce clearly better results.

To find out which type of Mozilla build you are using, enter into the urlbar:

	about:buildconfig

Only builds intended for fontconfig systems will show --enable-xft as a configure argument.

Customizing Fonts Via CSS

Finally, if you still can't get Mozilla's fonts just the way you like them by changing DPI, you can customize them directly using standard CSS 2.1, in userChrome.css for the UI, and userContent.css for web page text. How to do this is covered generally at Customizing Mozilla.

Using CSS, you can customize Mozilla fonts via methods that don't depend on DPI. A few of the many possible UI CSS selectors you might wish to try in userChrome.css include:

  • menu, menuitem (main menu items)
  • statusbar
  • .tabbrowser-tabs .tab-text
  • toolbar (urlbar)
  • .toolbarbutton-1 (nav button text in Modern theme)
  • treechildren (mailnews folder & header panes; pref trees)
  • .treecol-text (mailnews column headings)

Using DOM Inspector you can explore Mozilla's application of CSS and find other selectors you might wish to experiment with.

Help

Forums available for further help with Unix DPI and fonts include: