0

Can I have an additional font in my .Xresources so that if the default one doesn't have some unicode characters, the additional one can display them?

2 Answers2

1

Yes. There are seven font sizes, as can be seen with a Ctrl+MouseRightButton on XTerm. They can be set in .Xresources.

  • font = Default
  • font1 = Unreadable
  • font2 = Tiny
    ...
  • font6 = Huge

So you can set a default font that misses some unicode characters. If you miss them, change to a font that supports them, for example, Tiny. This .Xresources file does it:

XTerm*font:  -*-courier 10 pitch-medium-r-*-*-*-*-*-*-*-*-ascii-*
XTerm*font2: -*-fixed-medium-r-*-*-15-*-*-*-*-*-iso10646-*
Quasímodo
  • 18,865
  • 4
  • 36
  • 73
1

xterm has two sets of bitmap-fonts:

  • font, font2, font3, ..., font6 are the conventional fonts dating back to X11R4.
  • utf8Fonts.font, etc., are Unicode fonts.

The app-defaults files XTerm and UXTerm have both of these, but in the latter, those Unicode fonts are not inside the utf8Fonts layer. Here is the content from the XTerm app-defaults file:

*VT100.utf8Fonts.font2: -misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1
*VT100.utf8Fonts.font:  -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1
*VT100.utf8Fonts.font3: -misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1
*VT100.utf8Fonts.font4: -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso10646-1
*VT100.utf8Fonts.font5: -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
*VT100.utf8Fonts.font6: -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1

and here is the content from the UXTerm app-defaults file:

*VT100.font2:   -misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1
*VT100.font:    -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1
*VT100.font3:   -misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1
*VT100.font4:   -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso10646-1
*VT100.font5:   -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
*VT100.font6:   -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1

Just reading the XTerm app-defaults file, most users would not notice that the non-UTF-8 fonts given here look something like the UTF-8 fonts:

*VT100.font1:       nil2
*IconFont:      nil2
*fontMenu*font2*Label:  Tiny
*VT100.font2:       5x7
*fontMenu*font3*Label:  Small
*VT100.font3:       6x10
*fontMenu*font4*Label:  Medium
*VT100.font4:       7x13
*fontMenu*font5*Label:  Large
*VT100.font5:       9x15
*fontMenu*font6*Label:  Huge
*VT100.font6:       10x20

Those short names are (as detailed in xterm cannot load font) aliases for ISO-8859-1 fonts, which (unsuprisingly given the history of UTF-8) have the same appearance as the UTF-8 fonts. But they have only 192 characters (256 - 64 control characters), while the bitmap UTF-8 fonts have thousands.

There is more than one app-defaults file because that seemed a simpler solution than the utf8Fonts arrangement. The uxterm script selects the latter at startup using the -class option, but as described in the manual page, xterm will automatically select the utf8Fonts at startup based on the locale settings.

xterm has menu items for UTF-8 Encoding and UTF-8 Fonts. If your locale uses UTF-8 encoding (and if the locale resource uses the default value), then xterm pre-selects these menu items and disables them from being changed. If the locale does not use UTF-8 encoding, you are able to change these menu entries and see the resulting differences.

You can specify in your X resources which file to use by prefixing the resources with XTerm or UXTerm, respectively.

While one could make font sets using bitmap fonts, which would allow one to do what's asked in the question:

Can I have an additional font in my .Xresources so that if the default one doesn't have some unicode characters, the additional one can display them?

xterm uses only one of these bitmap-fonts at a time (along with automatically using bold- and italic-versions). There is a font-set feature in the X libraries, but it has severe performance problems and was never widely used. In xterm, it is treated as a nuisance (see menuLocale resource).

Besides bitmap-fonts, xterm also supports TrueType fonts, and will automatically lookup fonts as needed to fill in for missing glyphs from the family specified with the -fa option. Depending on your fontconfig arrangement, you can get a workable coverage from the TrueType fonts (with the caveat that some of those are sized incorrectly).

Thomas Dickey
  • 76,765
  • When I run uxterm -class 'XTerm', it launches a terminal with a really ugly font but which displays Unicode correctly. – Akshat Vats Aug 11 '20 at 03:57
  • sure - read the answer and the linked X resource-settings. (The "really ugly font" here isn't one of the many TrueType fonts which merit that description, but a bitmap font). – Thomas Dickey Aug 11 '20 at 08:42