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/
This commit is contained in:
Bill Kendrick 2023-05-29 13:10:59 -07:00
parent b4a550a6e1
commit 83c4cbc676
6 changed files with 40 additions and 8 deletions

View file

@ -49,6 +49,11 @@ https://tuxpaint.org/
Closes https://sourceforge.net/p/tuxpaint/feature-requests/236/
Bill Kendrick <bill@newbreedsoftware.com>
* 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 <bill@newbreedsoftware.com>
* Bug Fixes:
----------
* In some window size / button size combinations, Eraser

View file

@ -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"

View file

@ -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)

View file

@ -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;

View file

@ -53,6 +53,7 @@ _tuxpaint()
--newcolorsfirst --newcolorslast \
--colorsrows=1 --colorsrows=2 \
--colorsrows=3 \
--uifont --uifont=default \
--sysfonts --nosysfonts \
--nostampcontrols --stampcontrols \
--nostamprotation --stamprotation \

View file

@ -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