/* xscreensaver, Copyright (c) 2018-2020 by Jamie Zawinski <jwz@jwz.org>
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
/* Like XLoadQueryFont, but if it fails, it tries some heuristics to
extern const char *progname
;
#define countof(x) (sizeof((x))/sizeof((*x)))
load_font_retry_1 (Display
*dpy
, int screen
, const char *xlfd
, Bool xft_p
)
# define LOADFONT(F) (xft_p \
? (void *) XftFontOpenXlfd (dpy, screen, (F)) \
: (void *) XLoadQueryFont (dpy, (F)))
# define LOADFONT(F) ((void *) XLoadQueryFont (dpy, (F)))
void *f
= xlfd
? LOADFONT(xlfd
) : 0;
if (! xlfd
) xlfd
= "<null>";
fprintf (stderr
, "%s: loaded %s\n", progname
, xlfd
);
Bool bold_p
= (!!strcasestr (xlfd
, "-bold-") ||
!!strcasestr (xlfd
, "-ocr"));
Bool italic_p
= (!!strcasestr (xlfd
, "-i-") ||
!!strcasestr (xlfd
, "-o-"));
Bool fixed_p
= (!!strcasestr (xlfd
, "courier") ||
!!strcasestr (xlfd
, "-ocr") ||
!!strcasestr (xlfd
, "-m-") ||
!!strcasestr (xlfd
, "-c-"));
fprintf (stderr
, "%s: failed %s\n", progname
, xlfd
);
if (!strcmp (xlfd
, "vga")) /* BSOD uses this: it has no XLFD name. */
fixed_p
= True
, size
= 120;
/* Look for the first number in the string like "-180-" */
if (s
[0] == '-' && s
[1] >= '0' && s
[1] <= '9')
while (*s2
>= '0' && *s2
<= '9')
if (*s2
!= '-') continue; /* Number ends with dash */
if (i
< 60 || i
>= 2000) continue; /* In range 6pt - 200pt */
if (i
% 10) continue; /* Multiple of 10 */
fprintf (stderr
, "%s: unloadable, unparsable font: \"%s\"\n",
const char *variable
[] = {
"bitstream vera sans", /* sometimes foundry is in family */
"vera sans", /* sometimes not? */
"new century schoolbook",
"bitstream charter", /* sometimes foundry is in family */
"charter", /* sometimes not? */
/* Don't use a wildcard family. If none of the above worked, then
then almost none of the X11 fonts are installed, and it's not
unlikely that "-*-*-medium-r-*-*-*-140-*-*-*-10646-1" will
match an Arabic or or Japanese font that contains no Latin
glyphs at all, even in a Latin locale. So in that case, just
let "helvetica" fall back to "fixed".
/* As above, but "can't happen" because we already tried fixed? */
const char *charsets
[] = { "iso10646-1", "iso8859-1", "*-*" };
const char *weights
[] = { "bold", "medium" };
const char *slants
[] = { "o", "i", "r" };
const char *spacings
[] = { "m", "c", "p" };
for (a
= 0; a
< countof(charsets
); a
++)
for (b
= (bold_p
? 0 : 1); b
< countof(weights
); b
++)
for (c
= (italic_p
? 0 : 2); c
< countof(slants
); c
++)
d
< (fixed_p
? countof(fixed
) : countof(variable
));
for (g
= size
; g
>= 60; g
-= 10)
for (e
= (fixed_p
? 0 : 2); e
< countof(spacings
); e
++)
"-%s-%s-%s-%s-%s-%s-%s-%d-%s-%s-%s-%s-%s",
(fixed_p
? fixed
[d
] : variable
[d
]),
fprintf(stderr
, "%s: trying %s\n", progname
, buf
);
"%s: substituted \"%s\" for \"%s\"\n",
fprintf (stderr
, "%s: unable to find any alternatives to \"%s\"\n",
# endif /* !HAVE_JWXYZ */
load_font_retry (Display
*dpy
, const char *xlfd
)
return (XFontStruct
*) load_font_retry_1 (dpy
, 0, xlfd
, 0);
load_xft_font_retry (Display
*dpy
, int screen
, const char *xlfd
)
return (XftFont
*) load_font_retry_1 (dpy
, screen
, xlfd
, 1);
#elif defined(HAVE_JWXYZ)
load_xft_font_retry (Display
*dpy
, int screen
, const char *xlfd
)
return XftFontOpenXlfd (dpy
, screen
, xlfd
);