From 83c4cbc67658d753b077f4cf54fed2427f6f1151 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Mon, 29 May 2023 13:10:59 -0700 Subject: [PATCH] WIP New "--uifont" option to specify UI font If not specified, or "default" is specified (e.g., to override a higher-up config file setting), it will fallback to what we have #define'd in fonts.h as PANGO_DEFAULT_FONT, "DejaVu Sans". It appears to fallback to this (or a reasonable fascimile) if the font specified by the "uifont" option doesn't exist (e.g., "tuxpaint --uifont=ABCD1234"). For https://sourceforge.net/p/tuxpaint/feature-requests/146/ --- docs/CHANGES.txt | 5 +++++ src/fonts.h | 7 +++++-- src/parse.gperf | 1 + src/parse.h | 1 + src/tuxpaint-completion.bash | 1 + src/tuxpaint.c | 33 +++++++++++++++++++++++++++------ 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 8b99fbd1e..1e9d09613 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -49,6 +49,11 @@ https://tuxpaint.org/ Closes https://sourceforge.net/p/tuxpaint/feature-requests/236/ Bill Kendrick + * WIP Ability to specify a font for Tux Paint's UI (button labels, + dialog boxes, Tux tip text at the bottom). + Closes https://sourceforge.net/p/tuxpaint/feature-requests/146/ + Bill Kendrick + * Bug Fixes: ---------- * In some window size / button size combinations, Eraser diff --git a/src/fonts.h b/src/fonts.h index 6bfe74281..bc88c6eb0 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last updated: April 30, 2023 + Last updated: May 29, 2023 */ #ifndef FONTS_H @@ -39,8 +39,11 @@ #include "SDL_ttf.h" #include "SDL2_Pango.h" +/* UI font, which as of 0.9.31, can be overridden by "uifont" + setting (also, this will be used if "uifont=default" is specified, + e.g. to override a config. file option using a command-line option) */ + #define PANGO_DEFAULT_FONT "DejaVu Sans" -//#define PANGO_DEFAULT_FONT "OpenDyslexicAlta" #include "compiler.h" diff --git a/src/parse.gperf b/src/parse.gperf index 809897da8..4d01c8662 100644 --- a/src/parse.gperf +++ b/src/parse.gperf @@ -161,6 +161,7 @@ startblank, POSBOOL(start_blank) startlast, NEGBOOL(start_blank) sysconfig, POSBOOL(parsertmp_sysconfig) sysfonts, NEGBOOL(no_system_fonts) +uifont, MULTI(tp_ui_font) uppercase, POSBOOL(only_uppercase) usage, IMM(usage) verbose-version, IMM(verbose_version) diff --git a/src/parse.h b/src/parse.h index a555b494f..1896ef169 100644 --- a/src/parse.h +++ b/src/parse.h @@ -36,6 +36,7 @@ struct cfginfo const char *native_screensize; const char *new_colors_last; const char *no_button_distinction; + const char *tp_ui_font; const char *no_fancy_cursors; const char *no_system_fonts; const char *noshortcuts; diff --git a/src/tuxpaint-completion.bash b/src/tuxpaint-completion.bash index ad3ccc05f..efaf73b6e 100644 --- a/src/tuxpaint-completion.bash +++ b/src/tuxpaint-completion.bash @@ -53,6 +53,7 @@ _tuxpaint() --newcolorsfirst --newcolorslast \ --colorsrows=1 --colorsrows=2 \ --colorsrows=3 \ + --uifont --uifont=default \ --sysfonts --nosysfonts \ --nostampcontrols --stampcontrols \ --nostamprotation --stamprotation \ diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 381f32543..9b02deec2 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -586,6 +586,7 @@ int iswprint(wchar_t wc) #include "compiler.h" +char * tp_ui_font = NULL; /* Convert floats to fractions between (min/max) and ((max-min)/max) (anything with smaller resolution will round up or down) */ @@ -8052,6 +8053,7 @@ void show_usage(int exitcode) " Languages:\n" " [--lang LANGUAGE | --locale LOCALE | --lang help]\n" " [--mirrorstamps | --dontmirrorstamps]\n" + " [--uifont \"FONT NAME\" | --uifont default]\n" " [--sysfonts | --nosysfonts]\n" " [--currentlocalefont | --alllocalefonts]\n" "\n" @@ -9283,7 +9285,7 @@ static int generate_fontconfig_cache_real(void) DEBUG_PRINTF("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID()); - tmp_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, NULL, 12); + tmp_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, NULL, 12); /* always just using the default font for the purpose of getting FontConfig to generate its cache */ if (tmp_font != NULL) { @@ -27875,6 +27877,23 @@ static void setup_config(char *argv[]) tmpcfg.parsertmp_locale = NULL; button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale, &num_wished_langs); + if (tmpcfg.tp_ui_font) + { + if (strcmp(tmpcfg.tp_ui_font, "default") == 0) + { + printf/*DEBUG_PRINTF*/("UI font will be default: %s\n", PANGO_DEFAULT_FONT); + tp_ui_font = strdup(PANGO_DEFAULT_FONT); + } + else + { + tp_ui_font = strdup(tmpcfg.tp_ui_font); + printf/*DEBUG_PRINTF*/("UI font will be: %s\n", tp_ui_font); + } + } + else + { + tp_ui_font = strdup(PANGO_DEFAULT_FONT); + } /* FIXME: most of this is not required before starting the font scanner */ @@ -29311,8 +29330,8 @@ static void setup(void) #endif - medium_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, - DATA_PREFIX "fonts/default_font.ttf", + medium_font = TuxPaint_Font_OpenFont(tp_ui_font, + DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */ (18 - (only_uppercase * 3)) * button_scale); if (medium_font == NULL) @@ -29654,8 +29673,9 @@ static void setup(void) /* Load system fonts: */ - large_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, - DATA_PREFIX "fonts/default_font.ttf", (30 - (only_uppercase * 3)) * button_scale); + large_font = TuxPaint_Font_OpenFont(tp_ui_font, + DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */ + (30 - (only_uppercase * 3)) * button_scale); if (large_font == NULL) { @@ -29669,7 +29689,8 @@ static void setup(void) } - small_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, DATA_PREFIX "fonts/default_font.ttf", + small_font = TuxPaint_Font_OpenFont(tp_ui_font, + DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */ #ifdef __APPLE__ (12 - (only_uppercase * 2)) * button_scale #else