Allow primary & fallback locale fonts to be specified

e.g., for Chinese Traditional, try to use the full font (that
we supply as an optional download), then try the 'subset' font
that we ship with Tux Paint.
This commit is contained in:
Bill Kendrick 2023-06-13 00:25:49 -07:00
parent 0bfc8c18c1
commit 0437b898ca
3 changed files with 42 additions and 16 deletions

View file

@ -174,24 +174,27 @@ static void reliable_read(int fd, void *buf, size_t count);
#endif #endif
const char * PANGO_DEFAULT_FONT = "DejaVu Sans"; const char * PANGO_DEFAULT_FONT = "DejaVu Sans";
const char * PANGO_DEFAULT_FONT_FALLBACK = NULL;
/* Names of the fonts we include in `fonts/locale/` */ /* Names of the fonts we include in `fonts/locale/`
(LANG_* codes are from `src/i18n.h`) */
// (Try `otfinfo --info fonts/locale/*.ttf | grep "Full name:"`) // (Try `otfinfo --info fonts/locale/*.ttf | grep "Full name:"`)
default_locale_font_t default_local_fonts[] = { default_locale_font_t default_local_fonts[] = {
{ LANG_AR, "ae_Nice" }, { LANG_AR, "ae_Nice", NULL },
{ LANG_BO, "Tsampa Keyboard" }, // NOTE: Our current translation is Wylie transliterated, not Unicode! */ { LANG_BO, "Tsampa Keyboard", NULL }, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
{ LANG_EL, "Thryomanes" }, { LANG_EL, "Thryomanes", NULL},
{ LANG_GU, "Lohit Gujarati" }, { LANG_GU, "Lohit Gujarati", NULL },
{ LANG_HE, "Nachlieli Light" }, { LANG_HE, "Nachlieli Light", NULL },
{ LANG_HI, "Raghindi" }, { LANG_HI, "Raghindi", NULL },
{ LANG_JA, "GJGothicPNSubset" }, { LANG_JA, "Gen Jyuu Gothic P Regular", "GJGothicPNSubset" },
{ LANG_KA, "TuxPaint Georgian" }, { LANG_KA, "TuxPaint Georgian", NULL }, /* FIXME: Upon what is this font based? Never knew -bjk 2023.06.12 */
{ LANG_KO, "Baekmuk Gulim" }, { LANG_KO, "Baekmuk Gulim", NULL },
{ LANG_TA, "TSCu_Comic" }, { LANG_TA, "TSCu_Comic", NULL },
{ LANG_TE, "Vemana2000" }, { LANG_TE, "Vemana2000", NULL },
{ LANG_TH, "Garuda" }, { LANG_TH, "Garuda", NULL },
{ LANG_ZH_TW, "SubsetForTuxPaint" }, { LANG_ZH_CN, "AR PL SungtiL GB", NULL },
{ -1, NULL }, { LANG_ZH_TW, "HanWangKaiMediumChuIn", "SubsetForTuxPaint" },
{ -1, NULL, NULL },
}; };
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf) void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)

View file

@ -52,10 +52,11 @@
typedef struct default_locale_font_s { typedef struct default_locale_font_s {
int locale_id; int locale_id;
const char * font_name; const char * font_name;
const char * font_name_fallback;
} default_locale_font_t; } default_locale_font_t;
extern default_locale_font_t default_local_fonts[]; extern default_locale_font_t default_local_fonts[];
extern const char * PANGO_DEFAULT_FONT; extern const char * PANGO_DEFAULT_FONT, * PANGO_DEFAULT_FONT_FALLBACK;
#include "compiler.h" #include "compiler.h"

View file

@ -27926,6 +27926,7 @@ static void setup_config(char *argv[])
{ {
char str[128]; char str[128];
char *picturesdir; char *picturesdir;
char *tp_ui_font_fallback;
int i; int i;
#if !defined(_WIN32) && !defined(__ANDROID__) #if !defined(_WIN32) && !defined(__ANDROID__)
@ -28104,14 +28105,18 @@ static void setup_config(char *argv[])
button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale, &num_wished_langs); button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale, &num_wished_langs);
/* Determine the referred font for the current locale */ /* Determine the referred font for the current locale */
PANGO_DEFAULT_FONT_FALLBACK = NULL;
for (i = 0; default_local_fonts[i].locale_id != -1; i++) for (i = 0; default_local_fonts[i].locale_id != -1; i++)
{ {
if (default_local_fonts[i].locale_id == get_current_language()) if (default_local_fonts[i].locale_id == get_current_language())
{ {
PANGO_DEFAULT_FONT = default_local_fonts[i].font_name; PANGO_DEFAULT_FONT = default_local_fonts[i].font_name;
PANGO_DEFAULT_FONT_FALLBACK = default_local_fonts[i].font_name_fallback;
} }
} }
tp_ui_font_fallback = NULL;
if (tmpcfg.tp_ui_font) if (tmpcfg.tp_ui_font)
{ {
char * tmp_str; char * tmp_str;
@ -28122,6 +28127,10 @@ static void setup_config(char *argv[])
{ {
printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT); printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
tp_ui_font = strdup(PANGO_DEFAULT_FONT); tp_ui_font = strdup(PANGO_DEFAULT_FONT);
if (PANGO_DEFAULT_FONT_FALLBACK != NULL)
{
tp_ui_font_fallback = strdup(PANGO_DEFAULT_FONT_FALLBACK);
}
} }
else else
{ {
@ -28160,6 +28169,19 @@ static void setup_config(char *argv[])
tmp_str = ask_pango_for_font(tp_ui_font); tmp_str = ask_pango_for_font(tp_ui_font);
if (tmp_str != NULL)
{
if (strcmp(tp_ui_font, tmp_str) != 0 && tp_ui_font_fallback != NULL)
{
free(tp_ui_font);
tp_ui_font = strdup(tp_ui_font_fallback);
tp_ui_font_fallback = NULL;
printf/*DEBUG_PRINTF*/("Requested fallback default UI font, \"%s\"\n", tp_ui_font);
tmp_str = ask_pango_for_font(tp_ui_font);
}
}
if (tmp_str != NULL) if (tmp_str != NULL)
{ {
printf("Actual UI font will be \"%s\"\n", tmp_str); printf("Actual UI font will be \"%s\"\n", tmp_str);