I'm trying to load an OTF font into sflock. sflock uses XLoadQueryFont() to load the font, but for some reason the font I'm trying to load doesn't work.
I wrote a small test program which just tries to load a font and then exits. Program is shown below. It loads the font successfully for any TTF font (I tried so far) on my machine, but the OTFs I've tried don't work at all. The OTF fonts are shown by XListFonts(), so X does find them, but can't load them. Is there a way to load OTF fonts into X11, or do I have to use pango or similar?
#include <X11/Xlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
if (argc != 2) {
fprintf(stderr,"Missing argument.\n");
return 1;
}
Display *dsp = XOpenDisplay(0);
XFontStruct *font = XLoadQueryFont(dsp, argv[1]);
if (font == NULL) {
printf("font not found.\n");
} else {
printf("font found.\n");
XFreeFont(dsp, font);
}
XCloseDisplay(dsp);
return 0;
}
I've just run into similar issues trying to use the new CommitMono OpenType font. I run my X11 server via XQuartz on my macos desktop and I run X11 clients from various other servers, etc., including Emacs. With the OTF files installed on macos, but not on the client machines, I see the same effect, e.g. in Emacs where the font can be "listed", but not "opened" or loaded. When Emacs is run on the X11 server system, i.e. directly on my macos desktop within XQuartz, then it can properly display text in CommitMono.
I was able to use the converted TTF files from CommitMono, installed on my desktop to get Emacs running from another system and to display text in CommitMono, but it was ugly with excessive line spacing (as the CommitMono TTF files are currently auto-converted without fine tuning).
I think the bug here is that Xft (the X FreeType library) does not fully/properly support remote server-only OpenType fonts. Only TrueType (TTF) fonts (and maybe "Type 1" scalable fonts) can be installed only on the X11 server as "core X11 fonts". FontConfig code, which is used under the hood, also ends up running in the X11 client application, and so in the case of OpenType fonts it seems to require OTF files to be installed on the client systems! Even the latest X11 "Fonts in X11" documentation (see the "Troubleshooting" section) doesn't document this bug but instead actually claims OpenType font support should already be built into all X11 servers via the standard freetype module just as TureType support is.
The work-around solution is to also install the OTF files on the X11 client systems, e.g. in $HOME/.fonts/ (and to then run fc-cache). Now an Emacs running on a remote client system with the OTF files installed on it is able to display text in CommitMono using the OTF variant on the X11 server system.
N.B.: Since first writing this I've encountered a situation where even on a single system, i.e. with both XQuartz and all its X11 client applications are running on the same host, the CommitMono OTF files are unusable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With