Looks like SDL2_Pango can find our fonts now
Made sure to add our font dir (e.g., /usr/local/share/tuxpaint/fonts/) to FontConfig's directories before trying to load uifont! Also, update font names to match what we ship with Tux Paint. WIP -- Would like to supply some alternatives.
This commit is contained in:
parent
794ea691e8
commit
0bfc8c18c1
3 changed files with 52 additions and 84 deletions
|
|
@ -70,22 +70,14 @@ https://tuxpaint.org/
|
||||||
Closes https://sourceforge.net/p/tuxpaint/feature-requests/146/
|
Closes https://sourceforge.net/p/tuxpaint/feature-requests/146/
|
||||||
Bill Kendrick <bill@newbreedsoftware.com>
|
Bill Kendrick <bill@newbreedsoftware.com>
|
||||||
|
|
||||||
* WIP Different default fonts may be set on a per-locale basis
|
* Different default fonts once again used on a per-locale basis.
|
||||||
(hard-coded into Tux Paint). Most locales still use "DejaVu Sans",
|
|
||||||
if available. As of 0.9.31, things are configured as:
|
|
||||||
+ Arabic: Nice
|
|
||||||
+ Gujarati: Lohit Gujarati
|
|
||||||
+ Hebrew: Nachlieli CLM
|
|
||||||
+ Hindi: Lohit Devanagari
|
|
||||||
+ Japanese: TBD <<FIXME>>
|
|
||||||
+ Korean: Baekmuk Gulim
|
|
||||||
+ Thai: Garuda
|
|
||||||
+ Tibetan: Tsampa Keyboard
|
|
||||||
(This returns us to how Tux Paint behaved when we used
|
(This returns us to how Tux Paint behaved when we used
|
||||||
SDL_ttf to directly load fonts for the UI, and used TTF font files
|
SDL_ttf to directly load fonts for the UI, and used TTF font files
|
||||||
that we ship in the `fonts/locale/` directory.)
|
that we ship in the `fonts/locale/` directory. We now ask Pango,
|
||||||
|
via FontConfig, to look there for fonts.)
|
||||||
Closes https://sourceforge.net/p/tuxpaint/feature-requests/240/
|
Closes https://sourceforge.net/p/tuxpaint/feature-requests/240/
|
||||||
Bill Kendrick <bill@newbreedsoftware.com> (code)
|
Bill Kendrick <bill@newbreedsoftware.com> (code)
|
||||||
|
h/t Mark Kim & TOYAMA Shin-ichi
|
||||||
|
|
||||||
* Bug Fixes:
|
* Bug Fixes:
|
||||||
----------
|
----------
|
||||||
|
|
|
||||||
51
src/fonts.c
51
src/fonts.c
|
|
@ -175,42 +175,23 @@ static void reliable_read(int fd, void *buf, size_t count);
|
||||||
|
|
||||||
const char * PANGO_DEFAULT_FONT = "DejaVu Sans";
|
const char * PANGO_DEFAULT_FONT = "DejaVu Sans";
|
||||||
|
|
||||||
|
/* Names of the fonts we include in `fonts/locale/` */
|
||||||
|
// (Try `otfinfo --info fonts/locale/*.ttf | grep "Full name:"`)
|
||||||
default_locale_font_t default_local_fonts[] = {
|
default_locale_font_t default_local_fonts[] = {
|
||||||
// Initially based on "otfinfo --info fonts/locale/*.ttf | grep "Full name:"
|
{ LANG_AR, "ae_Nice" },
|
||||||
{
|
{ LANG_BO, "Tsampa Keyboard" }, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
|
||||||
LANG_JA,
|
{ LANG_EL, "Thryomanes" },
|
||||||
"TakaoPGothic" /* Included in Ubuntu "fonts-takao-gothic" package */
|
{ LANG_GU, "Lohit Gujarati" },
|
||||||
// FIXME: Shin-ichi recommend something, please! -bjk 2023.06.08
|
{ LANG_HE, "Nachlieli Light" },
|
||||||
},
|
{ LANG_HI, "Raghindi" },
|
||||||
{
|
{ LANG_JA, "GJGothicPNSubset" },
|
||||||
LANG_KO,
|
{ LANG_KA, "TuxPaint Georgian" },
|
||||||
"Baekmuk Gulim"
|
{ LANG_KO, "Baekmuk Gulim" },
|
||||||
},
|
{ LANG_TA, "TSCu_Comic" },
|
||||||
{
|
{ LANG_TE, "Vemana2000" },
|
||||||
LANG_BO, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
|
{ LANG_TH, "Garuda" },
|
||||||
"Tsampa Keyboard" /* FIXME: Not packaged in Ubuntu! */
|
{ LANG_ZH_TW, "SubsetForTuxPaint" },
|
||||||
},
|
{ -1, NULL },
|
||||||
{
|
|
||||||
LANG_GU,
|
|
||||||
"Lohit Gujarati" /* Included in Ubuntu "fonts-lohit-gujr" package */
|
|
||||||
},
|
|
||||||
{
|
|
||||||
LANG_TH,
|
|
||||||
"Garuda" /* Included in Ubuntu "fonts-tlwg-garuda-ttf" package */
|
|
||||||
},
|
|
||||||
{
|
|
||||||
LANG_AR,
|
|
||||||
"Nice" /* Included in Ubuntu "fonts-arabeyes" package (ae_Nice) */
|
|
||||||
},
|
|
||||||
{
|
|
||||||
LANG_HE,
|
|
||||||
"Nachlieli CLM" /* Inclued in Ubuntu "culmus" package */
|
|
||||||
},
|
|
||||||
{
|
|
||||||
LANG_HI,
|
|
||||||
"Lohit Devanagari" /* Included in Ubuntu "fonts-lohit-deva" package */
|
|
||||||
},
|
|
||||||
{-1, NULL},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
||||||
|
|
|
||||||
|
|
@ -9326,47 +9326,10 @@ static int generate_fontconfig_cache_real(void)
|
||||||
TuxPaint_Font *tmp_font;
|
TuxPaint_Font *tmp_font;
|
||||||
SDL_Surface *tmp_surf;
|
SDL_Surface *tmp_surf;
|
||||||
SDL_Color black = { 0, 0, 0, 0 };
|
SDL_Color black = { 0, 0, 0, 0 };
|
||||||
FcBool fontAddStatus;
|
|
||||||
const char * locale_fontdir;
|
|
||||||
|
|
||||||
DEBUG_PRINTF("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID());
|
DEBUG_PRINTF("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID());
|
||||||
|
|
||||||
|
|
||||||
/* Add Tux Paint's own set of fonts to FontConfig,
|
|
||||||
so SDL2_Pango can find and use them */
|
|
||||||
locale_fontdir = "/usr/local/share/tuxpaint/fonts"; // FIXME
|
|
||||||
|
|
||||||
fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *) locale_fontdir);
|
|
||||||
if (fontAddStatus == FcFalse)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ARGH: Why is '/usr/local/share/tuxpaint/fonts' not
|
|
||||||
coming back in the list of font dirs (below)?!
|
|
||||||
|
|
||||||
I tried both of these & they did not help.
|
|
||||||
Documentation out there is very vague; Google barely helping.
|
|
||||||
|
|
||||||
-bjk 2023.06.12
|
|
||||||
*/
|
|
||||||
printf("Rescanning fonts..."); fflush(stdout);
|
|
||||||
FcDirCacheRead(locale_fontdir, FcTrue /* force */, FcConfigGetCurrent());
|
|
||||||
FcDirCacheRescan(locale_fontdir, FcConfigGetCurrent());
|
|
||||||
printf("done\n");
|
|
||||||
|
|
||||||
if (SDL_TRUE) // FIXME
|
|
||||||
{
|
|
||||||
FcStrList *str_list;
|
|
||||||
FcChar8 *path;
|
|
||||||
str_list = FcConfigGetFontDirs(FcConfigGetCurrent());
|
|
||||||
printf("FontConfigGetFontDirs():\n");
|
|
||||||
while ((path = FcStrListNext(str_list)) != NULL) {
|
|
||||||
printf(" * %s\n", (const char *) path);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
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)
|
if (tmp_font != NULL)
|
||||||
|
|
@ -28152,6 +28115,8 @@ static void setup_config(char *argv[])
|
||||||
if (tmpcfg.tp_ui_font)
|
if (tmpcfg.tp_ui_font)
|
||||||
{
|
{
|
||||||
char * tmp_str;
|
char * tmp_str;
|
||||||
|
FcBool fontAddStatus;
|
||||||
|
const char locale_fontdir[MAX_PATH];
|
||||||
|
|
||||||
if (strcmp(tmpcfg.tp_ui_font, "default") == 0)
|
if (strcmp(tmpcfg.tp_ui_font, "default") == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -28164,6 +28129,36 @@ static void setup_config(char *argv[])
|
||||||
printf/*DEBUG_PRINTF*/("Requested UI font described by \"%s\"\n", tp_ui_font);
|
printf/*DEBUG_PRINTF*/("Requested UI font described by \"%s\"\n", tp_ui_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add Tux Paint's own set of fonts to FontConfig,
|
||||||
|
so SDL2_Pango can find and use them */
|
||||||
|
snprintf(locale_fontdir, sizeof(locale_fontdir), "%s/fonts", DATA_PREFIX);
|
||||||
|
|
||||||
|
fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *) locale_fontdir);
|
||||||
|
if (fontAddStatus == FcFalse)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME: Unclear whether this is necessary? -bjk 2023.06.12 */
|
||||||
|
DEBUG_PRINTF("Rescanning fonts..."); fflush(stdout);
|
||||||
|
FcDirCacheRead((const FcChar8 *) locale_fontdir, FcTrue /* force */, FcConfigGetCurrent());
|
||||||
|
FcDirCacheRescan((const FcChar8 *) locale_fontdir, FcConfigGetCurrent());
|
||||||
|
DEBUG_PRINTF("done\n");
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
{
|
||||||
|
FcStrList *str_list;
|
||||||
|
FcChar8 *path;
|
||||||
|
str_list = FcConfigGetFontDirs(FcConfigGetCurrent());
|
||||||
|
printf("FcConfigGetFontDirs():\n");
|
||||||
|
while ((path = FcStrListNext(str_list)) != NULL) {
|
||||||
|
printf(" * %s\n", (const char *) path);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
tmp_str = ask_pango_for_font(tp_ui_font);
|
tmp_str = ask_pango_for_font(tp_ui_font);
|
||||||
if (tmp_str != NULL)
|
if (tmp_str != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue