Howto specify X scalable fonts from the command line

Let's say you want to display a message in the middle of the screen with an X program such as xmessage, and you want to do it with a big bad-ass font. Not times 40, not times 100, but, say 400 pixels high, or may be 2000 (printing) points high.

The basics

xmessage 'My message'

will do it. You can specify the fonts with -fn. Now, you have to find the scalable fonts. This is done (as with non-scalable, that is bitmap ones) with xlsfonts.

The name of the font

The name of an X font is fndry-fmly-wght-slant-swid-adstyle--pxlsz-ptsz-resx-resy-spc-avgwdth-reg-encod
(note the double -- in the middle).

The meaning of each field is as following:

fndry The foundry that digitized the font
fmly The typeface family that the font belongs to
wght The weight of the font; i.e., the degree of blackness
slant The slant of the font
swid The width of the font proportional to its horizontal size (the setwidth)
adstyle Additional style information; e.g., whether the font is serif or sans serif
pxlsz Pixel size; 0 for a scalable font
ptsz Point size, in tenths of a point; 0 for a scalable font
resx Horizontal resolution; 0 for a scalable font
resy Vertical resolution; 0 for a scalable font
spc Spacing; possible values are p (proportional), m (monospaced), or c (character cell)
avgwdth The arithmetic mean width of all glyphs in the font, in tenths of a pixel
reg The registration authority that owns the font's encoding
encod The name of the encoded character set


You can find the available fonts in your X server using xlsfonts. "*" can be used as a wildcard. As the above table shows, scalable fonts have 0 as their pixel size, point size, and horizontal and vertical resolution. So you find scalable fonts by passing 0 there, for example:

xlsfonts '*--0-*'

Making it work

Now, you can pass the name of the font you like, or wildcard everything, you just have to put the value you want in the place of pixel size or point size. So let's say you want your text to be 200 pixels high, you'll do it by using '--200-' in your font name. But there's a small captcha here: unlike the bitmap font case, if you want the scaling machinery to kick in, the font name must be "well formed", meaning in this context it has all the necessary dashes. Don't count them, I'll tell you: 14.

So you can for example display your message with 200 pixels

xmessage -fn '-*-*-*-r-*--200-0-0-0-p-*-*-*' 'My message'

If you want it to be 200 points high instead, you'll use:

xmessage -fn '-*-*-*-r-*--0-200-0-0-p-*-*-*' 'My message'

If you messed with the font name, you'll know it by the message (likely on the console):

Warning: Cannot convert string "your-font-name" to type FontStruct

Still not working

If you've no error message, but no text appears (like there was no font), most likely the font description isn't specific enough, and that led to select a font that is not able to display the string you've passed. Try to specifiy the character set, like in:

xmessage -fn '-*-*-*-r-*--0-200-0-0-p-*-iso8859-1' 'My message'

or the foundry, if you know one that can represent your string (and is installed), like in:

xmessage -fn '-adobe-*-*-r-*--0-200-0-0-p-*-*-*' 'My message'

assuming Adobe fonts are installed and apt to represent your string.

(This is a general answer to "I've specified an X font, but nothing appears").

A last word

There are very good scalable fonts from urw coming with many distributions, so

xmessage -fn '-urw-*-*-r-*--0-200-0-0-p-*-*-*' 'My message'

may be a good choice.