1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-27 10:12:24 +00:00

GTK: hard-code some last-ditch fallback fonts.

If the user's choice of fonts can't be instantiated during initial
terminal-window setup, then we now automatically try two fallback
options, "client:Monospace 10" and "server:fixed", and only give a
fatal error if _no_ option allows us to open a terminal window.

Previously, on Wayland, PuTTY and pterm with default configuration
would completely fail to open a terminal window at all, because our
default font configuration is still the trad X11 "server:fixed", and
on Wayland, X11-style server-side bitmap fonts don't exist at all.

Conversely, in the GTK1 build of PuTTY which we're still supporting,
_client-side_ fonts aren't supported, so if a user had configured one
in their normal PuTTY configuration, then the GTK1 version would
similarly fail to launch.

Now both of those cases should work, because the fallbacks include a
client-side font _and_ a server-side one, and I hope that any usable
Pango system will make "Monospace" map to _some_ locally available
font, and that any remotely sensible X server has 'fixed'

I think it would be even better if there was a mechanism for the Conf
to specify a fallback list of fonts. For example, this might be
specified via a new multifont prefix along the lines of

  choices:client:Monospace 10:server:fixed

with the semantics that the "choices:" prefix means that the rest of
the string is split up at every other colon to find a list of fonts to
try to make. Then we could not only set PuTTY's default to a list of
possibilities likely to find a usable font everywhere, but also, users
could configure their own list of preferred fallbacks.

But I haven't thought of a good answer to the design question of what
should happen if a Conf font setting looks like that and the user
triggers the GUI font selector! (Also, you'd need to figure out what
happened if a 'choices:' string had another 'choices' in it...)
This commit is contained in:
Simon Tatham 2025-01-09 13:01:22 +00:00
parent 6ec424059c
commit b088d77d58

View File

@ -4368,22 +4368,22 @@ static bool gtk_seat_get_windowid(Seat *seat, long *id)
}
#endif
char *setup_fonts_ucs(GtkFrontend *inst)
char *setup_fonts_ucs(GtkFrontend *inst, Conf *conf)
{
bool shadowbold = conf_get_bool(inst->conf, CONF_shadowbold);
int shadowboldoffset = conf_get_int(inst->conf, CONF_shadowboldoffset);
bool shadowbold = conf_get_bool(conf, CONF_shadowbold);
int shadowboldoffset = conf_get_int(conf, CONF_shadowboldoffset);
FontSpec *fs;
unifont *fonts[4];
int i;
fs = conf_get_fontspec(inst->conf, CONF_font);
fs = conf_get_fontspec(conf, CONF_font);
fonts[0] = multifont_create(inst->area, fs->name, false, false,
shadowboldoffset, shadowbold);
if (!fonts[0]) {
return dupprintf("unable to load font \"%s\"", fs->name);
}
fs = conf_get_fontspec(inst->conf, CONF_boldfont);
fs = conf_get_fontspec(conf, CONF_boldfont);
if (shadowbold || !fs->name[0]) {
fonts[1] = NULL;
} else {
@ -4396,7 +4396,7 @@ char *setup_fonts_ucs(GtkFrontend *inst)
}
}
fs = conf_get_fontspec(inst->conf, CONF_widefont);
fs = conf_get_fontspec(conf, CONF_widefont);
if (fs->name[0]) {
fonts[2] = multifont_create(inst->area, fs->name, true, false,
shadowboldoffset, shadowbold);
@ -4410,7 +4410,7 @@ char *setup_fonts_ucs(GtkFrontend *inst)
fonts[2] = NULL;
}
fs = conf_get_fontspec(inst->conf, CONF_wideboldfont);
fs = conf_get_fontspec(conf, CONF_wideboldfont);
if (shadowbold || !fs->name[0]) {
fonts[3] = NULL;
} else {
@ -4861,7 +4861,7 @@ static void after_change_settings_dialog(void *vctx, int retval)
conf_get_bool(newconf, CONF_shadowbold) ||
conf_get_int(oldconf, CONF_shadowboldoffset) !=
conf_get_int(newconf, CONF_shadowboldoffset)) {
char *errmsg = setup_fonts_ucs(inst);
char *errmsg = setup_fonts_ucs(inst, inst->conf);
if (errmsg) {
char *msgboxtext =
dupprintf("Could not change fonts in terminal window: %s\n",
@ -4950,7 +4950,7 @@ static void change_font_size(GtkFrontend *inst, int increment)
}
}
errmsg = setup_fonts_ucs(inst);
errmsg = setup_fonts_ucs(inst, inst->conf);
if (errmsg)
goto cleanup;
@ -5350,15 +5350,48 @@ void new_session_window(Conf *conf, const char *geometry_string)
inst->area = gtk_drawing_area_new();
gtk_widget_set_name(GTK_WIDGET(inst->area), "drawing-area");
/*
* Try to create the fonts for use in the window. If this fails,
* we'll try again with some fallback settings, and only abort
* completely if we can't find any fonts at all.
*/
{
char *errmsg = setup_fonts_ucs(inst);
if (errmsg) {
window_setup_error(errmsg);
sfree(errmsg);
gtk_widget_destroy(inst->area);
sfree(inst);
return;
char *errmsg_main = setup_fonts_ucs(inst, inst->conf);
if (!errmsg_main)
goto fonts_ok;
static const char *const fallbacks[] = {
"client:Monospace 10",
"server:fixed",
};
for (size_t i = 0; i < lenof(fallbacks); i++) {
Conf *fallback_conf = conf_new();
do_defaults(NULL, fallback_conf);
FontSpec *fs = fontspec_new(fallbacks[i]);
conf_set_fontspec(fallback_conf, CONF_font, fs);
fontspec_free(fs);
char *errmsg_fallback = setup_fonts_ucs(inst, fallback_conf);
conf_free(fallback_conf);
if (!errmsg_fallback) {
fprintf(stderr, "%s; falling back to default font '%s'\n",
errmsg_main, fallbacks[i]);
sfree(errmsg_main);
goto fonts_ok;
}
sfree(errmsg_fallback);
}
window_setup_error(errmsg_main);
sfree(errmsg_main);
gtk_widget_destroy(inst->area);
sfree(inst);
return;
fonts_ok:;
}
#if GTK_CHECK_VERSION(2,0,0)