Config font names, nothing happens

Hi. It says in the configuration comment that:

! Binding for the logical font-names. You can bind any name to any
! font here.

I tried. Been trying for about an hour and I have the swipl-devel source code, looking at the code in xpce/x11/xfont.c as well, I’ve played with pango/cairo but never Xft and I am sure that’s what was used to buld it. ldd only lists dynamic libs, those being:

╰─$ ldd /usr/bin/swipl (0x00007ffc3dbc3000) => /usr/lib/swi-prolog/lib/x86_64-linux/ (0x00007fbaa8558000) => /lib/x86_64-linux-gnu/ (0x00007fbaa8160000) => /lib/x86_64-linux-gnu/ (0x00007fbaa7f30000) => /usr/lib/x86_64-linux-gnu/ (0x00007fbaa7ca8000) => /lib/x86_64-linux-gnu/ (0x00007fbaa7a88000) => /lib/x86_64-linux-gnu/ (0x00007fbaa7868000) => /lib/x86_64-linux-gnu/ (0x00007fbaa7660000) => /lib/x86_64-linux-gnu/ (0x00007fbaa72c0000) => /lib/x86_64-linux-gnu/ (0x00007fbaa70b8000)
	/lib64/ (0x00007fbaa8ae8000)

Here is my last attempt at getting my fave editor font into XpceEmacs!!

display.system_fonts:   [ normal    := font('xft:FreeMono Regular', roman, 12), \                                                        
                          bold      := font('xft:FreeMono Regular', bold,    12), \                                                      
                          italic    := font('xft:FreeMono Regular', oblique, 12), \                                                      
                          small     := font('xft:FreeMono Regular', roman,   10), \                                                      
                          large     := font('xft:FreeMono Regular', roman,   14), \                                                      
                          boldlarge := font('xft:FreeMono Regular', bold,    14), \                                                      
                          huge      := font('xft:FreeMono Regular', roman,   18), \                                                      
                          boldhuge  := font('xft:FreeMono Regular', bold,    18), \                                                      
                          fixed     := font('xft:FreeMono Regular',    roman,   13), \                                                   
                          tt        := font('xft:FreeMono Regular',    roman,   13), \                                                   
                          boldtt    := font('xft:FreeMono Regular',    bold,    13), \                                                   
                          symbol    := font(symbol,    roman,   12)  \                                                                   

The way to use system fonts is using font() with 4 arguments. The first three describe the font as family, style and size. If the 4th is omitted we make some OS dependent sensible mapping for the predefined font families. If the 4th is present, this is used to create the font and the other three are simply recorded with the font.

The 4th argument is OS dependent. On modern non-Windows systems, the font selection is done using the Xft library, in particular using fontconfig. The relevant fragment is here:

  { const char *xname = strName(f->x_name);

    if ( strchr(xname, ':') )
      xft = XftFontOpenName(r->display_xref, r->screen, xname);
      xft = XftFontOpenXlfd(r->display_xref, r->screen, xname);
    if ( !xft )
      return replaceFont(f, d);

So, if there is a : in the name, use XftFontOpenName(), else use XftFontOpenXlfd(). Now, it is extremely hard to find good documentation for these functions :frowning: I could find some hints on, section Font names.

Instead of editing the config file and restarting Prolog, we can play around using, for example:

:- [library(pce)].
?- send(new(@p, picture), open).
?- send(@p, clear), send(@p, display, text("Hello world", font := font(times,bold,12,'Times-12:bold'))).

Once you find what you want, edit the config file and restart Prolog.

If you find sensible docs, please share!

edit Seems e.g. ‘FreeMono-17:regular’ might get what you want.


@jan superb info!

I finally got what I wanted in the end thanks to your help. I read that page, I used the FC_DEBUG variable for a while. The window sample was the clincher and then a little hacky and I now have, actually, IBM 3270 in the editor which is a really nice font for extended hours at the wheel.

Also it shows again how well thought out the windows API is…about two months ago I spent two days playing around with the Xpce stuff to see if it was what I was looking for to build the editor/ide ecosystem for my language…it’s tempting but Annes web server tutorial may have won the day in terms of making it usable over the net as well. Compared to say using Gtk or WxWidgets with Haskell, the code is much more readable!

Thank you !

1 Like

Just showing off…I didn’t think I could get any comfier with SWI but, here is my final configuration file and a screenshot…I was always a little irked by the small font sin the menus and the navigator but no more!

display.system_fonts:	[ \
	  normal    := font(helvetica, roman,   12, 'Ubuntu-12:regular'), \
	  bold      := font(helvetica, bold,    12, 'Ubuntu-12:bold'), \
	  italic    := font(helvetica, oblique, 12, 'Ubuntu-12:italic'), \
	  small     := font(helvetica, roman,   10, 'Ubuntu-10:narrow'), \
	  large     := font(helvetica, roman,   14, 'Ubuntu-14:regular'), \
	  boldlarge := font(helvetica, bold,    14, 'Ubuntu-14:bold'), \
	  huge      := font(helvetica, roman,   18, 'Ubuntu-18:regular'), \
	  boldhuge  := font(helvetica, bold,    18, 'Ubuntu-1:bold'), \
	  fixed     := font(screen,    roman,   14, 'IBM 3270-16:narrow'), \
	  tt        := font(screen,    roman,   14, 'IBM 3270-16:narrow'), \
	  boldtt    := font(screen,    bold,    14, 'IBM 3270-16:narrow,bold')  \


Small write up in case anybody wants details, Linux Mint specific.


Apologies for resurrecting an old topic. It might be worth pointing out similar font-selection help on the Windows operating system. Jan’s comments regarding the fourth-argument font term has utility on Windows also. Take this example.

:- use_module(library(pce)).

:- initialization main.

main :-
    send(new(@p, picture), open),
    send(@p, clear),
    send(@p, display,
         text("Hello World!",
              font := font('Blackadder ITC', regular, 24, ''))).

Note especially the fourth empty-atom argument for font/4.


Without that fourth argument, font selection fails to find Blackadder!

So your display.system_fonts can select Fira Mono for Powerline using the following terms.

fixed     := font('Fira Mono for Powerline',    regular,   13, ''), \
tt        := font('Fira Mono for Powerline',    regular,   13, ''), \
boldtt    := font('Fira Mono for Powerline',    bold,      13, ''), \

(Excerpt from xpce\Defaults in AppData\Roaming\SWI-Prolog)

Note also that resizing (i.e. font_magnify in Emacs) does not apply correct font selection to the scaled-up and scaled-down fonts that you specify in Defaults.