Skipping locale-specific fonts, unless we're in that locale.

Providing option to load all locale fonts anyway (the old behavior).
Renaming zh_tw.ttf to zh_TW.ttf.
This commit is contained in:
William Kendrick 2009-06-01 04:02:40 +00:00
parent 230dac43fa
commit a219080838
7 changed files with 73 additions and 21 deletions

View file

@ -136,6 +136,12 @@ $Id$
* Updated to the latest version (2.27) of DejaVu Sans Regular for UI font. * Updated to the latest version (2.27) of DejaVu Sans Regular for UI font.
* Only loads locale-specific fonts (e.g., Tibetan's "bo.ttf", which is
unusable with any language _except_ Tibetan) when Tux Paint is running
in that locale. (Use "--alllocalefonts" command-line option
or "alllocalefonts=yes" config. file option, to load all of those fonts,
regardless of locale setting -- the old behavior.)
* New localizations: * New localizations:
------------------ ------------------
* Shuswap (Secwepemctín) translation * Shuswap (Secwepemctín) translation

View file

@ -48,7 +48,7 @@
///////////////// directory walking callers and callbacks ////////////////// ///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i) unsigned dirlen, tp_ftw_str * files, unsigned i, char * locale)
{ {
dirlen = dirlen; dirlen = dirlen;
@ -87,8 +87,22 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
char fname[512]; char fname[512];
TuxPaint_Font *font; TuxPaint_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str); snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
//printf("Loading font: %s\n", fname); /* printf("Loading font: %s (locale is: %s)\n", fname, (locale != NULL ? locale : "NULL")); */
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]); if (locale != NULL && strstr(fname, "locale") != NULL && all_locale_fonts == 0)
{
char fname_check[512];
/* We're (probably) loading from our locale fonts folder; ONLY load our locale's font */
snprintf(fname_check, sizeof fname_check, "%s/%s.ttf", dir, locale);
/* printf("checking vs \"%s\" vs \"%s\"\n", fname_check, fname); */
if (strcmp(fname, fname_check) == 0)
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
else
font = NULL;
}
else
{
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
}
if (font) if (font)
{ {
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font); const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
@ -205,7 +219,8 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen, int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,
unsigned count)) unsigned count, char * locale),
char * locale)
{ {
DIR *d; DIR *d;
unsigned num_file_names = 0; unsigned num_file_names = 0;
@ -329,7 +344,7 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
} }
free(file_names); free(file_names);
#else #else
fn(screen, dir, dirlen, file_names, num_file_names); fn(screen, dir, dirlen, file_names, num_file_names, locale);
#endif #endif
} }
@ -340,7 +355,7 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
{ {
memcpy(dir + dirlen, dir_names[num_dir_names].str, memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1); dir_names[num_dir_names].len + 1);
tp_ftw(screen, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn); tp_ftw(screen, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str); free(dir_names[num_dir_names].str);
} }
free(dir_names); free(dir_names);

View file

@ -26,12 +26,13 @@ typedef struct tp_ftw_str
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i); unsigned dirlen, tp_ftw_str * files, unsigned i, char * locale);
int compare_ftw_str(const void *v1, const void *v2); int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen, int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,
unsigned count)); unsigned count, char * locale),
char * locale);
#endif #endif

View file

@ -100,6 +100,7 @@ SDL_Thread *font_thread;
int no_system_fonts; int no_system_fonts;
int all_locale_fonts;
volatile long font_thread_done = 0, font_thread_aborted = 0; volatile long font_thread_done = 0, font_thread_aborted = 0;
volatile long waiting_for_fonts = 0; volatile long waiting_for_fonts = 0;
int font_scanner_pid; int font_scanner_pid;
@ -119,6 +120,9 @@ int text_state = 0;
unsigned text_size = 4; // initial text size unsigned text_size = 4; // initial text size
void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, char * locale);
/* Unfortunately, there is a bug in SDL_ttf-2.0.6, the current version /* Unfortunately, there is a bug in SDL_ttf-2.0.6, the current version
that causes a segmentation fault if an attempt is made to call that causes a segmentation fault if an attempt is made to call
TTF_OpenFont() with the filename of a font that doesn't exist. This TTF_OpenFont() with the filename of a font that doesn't exist. This
@ -416,7 +420,7 @@ void reliable_read(int fd, void *buf, size_t count)
} }
void run_font_scanner(SDL_Surface * screen) void run_font_scanner(SDL_Surface * screen, char * locale)
{ {
int sv[2]; int sv[2];
int size, i; int size, i;
@ -442,7 +446,7 @@ void run_font_scanner(SDL_Surface * screen)
sched_yield(); // try to let the parent run right now sched_yield(); // try to let the parent run right now
SDL_Init(SDL_INIT_NOPARACHUTE); SDL_Init(SDL_INIT_NOPARACHUTE);
TTF_Init(); TTF_Init();
load_user_fonts(screen, NULL); load_user_fonts(screen, NULL, locale);
size = 0; size = 0;
i = num_font_families; i = num_font_families;
@ -657,13 +661,13 @@ void receive_some_font_info(SDL_Surface * screen)
#endif #endif
int load_user_fonts(SDL_Surface * screen, void *vp) int load_user_fonts(SDL_Surface * screen, void *vp, char * locale)
{ {
char *homedirdir; char *homedirdir;
(void) vp; // junk passed by threading library (void) vp; // junk passed by threading library
loadfonts(screen, DATA_PREFIX "fonts"); loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale);
if (!no_system_fonts) if (!no_system_fonts)
{ {
@ -1365,12 +1369,17 @@ TuxPaint_Font *getfonthandle(int desire)
void loadfonts(SDL_Surface * screen, const char *const dir) void loadfonts(SDL_Surface * screen, const char *const dir)
{
loadfonts_locale_filter(screen, dir, NULL);
}
void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, char * locale)
{ {
char buf[TP_FTW_PATHSIZE]; char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
tp_ftw(screen, buf, dirlen, 1, loadfont_callback); tp_ftw(screen, buf, dirlen, 1, loadfont_callback, locale);
} }

View file

@ -54,6 +54,7 @@ extern int font_scanner_pid;
extern int font_socket_fd; extern int font_socket_fd;
extern int no_system_fonts; extern int no_system_fonts;
extern int all_locale_fonts;
extern int was_bad_font; extern int was_bad_font;
/* FIXME: SDL_ttf is up to 2.0.8, so we can probably fully remove this; /* FIXME: SDL_ttf is up to 2.0.8, so we can probably fully remove this;
@ -87,12 +88,12 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
TuxPaint_Font *try_alternate_font(int size); TuxPaint_Font *try_alternate_font(int size);
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size); TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
int load_user_fonts(SDL_Surface * screen, void *vp); int load_user_fonts(SDL_Surface * screen, void *vp, char * locale);
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
void reliable_write(int fd, const void *buf, size_t count); void reliable_write(int fd, const void *buf, size_t count);
void reliable_read(int fd, void *buf, size_t count); void reliable_read(int fd, void *buf, size_t count);
void run_font_scanner(SDL_Surface * screen); void run_font_scanner(SDL_Surface * screen, char * locale);
void receive_some_font_info(SDL_Surface * screen); void receive_some_font_info(SDL_Surface * screen);
#endif #endif

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
June 14, 2002 - February 22, 2009 June 14, 2002 - May 31, 2009
$Id$ $Id$
*/ */
@ -5165,7 +5165,7 @@ static unsigned compute_default_scale_factor(double ratio)
static void loadbrush_callback(SDL_Surface * screen, static void loadbrush_callback(SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,
unsigned i) unsigned i, char * locale)
{ {
FILE * fi; FILE * fi;
char buf[64]; char buf[64];
@ -5258,7 +5258,7 @@ static void load_brush_dir(SDL_Surface * screen, const char *const dir)
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
tp_ftw(screen, buf, dirlen, 0, loadbrush_callback); tp_ftw(screen, buf, dirlen, 0, loadbrush_callback, NULL);
} }
SDL_Surface *mirror_surface(SDL_Surface * s) SDL_Surface *mirror_surface(SDL_Surface * s)
@ -5974,7 +5974,7 @@ static void get_stamp_thumb(stamp_type * sd)
static void loadstamp_callback(SDL_Surface * screen, static void loadstamp_callback(SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,
unsigned i) unsigned i, char * locale)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("loadstamp_callback: %s\n", dir); printf("loadstamp_callback: %s\n", dir);
@ -6099,7 +6099,7 @@ static void load_stamp_dir(SDL_Surface * screen, const char *const dir)
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
load_stamp_basedir = dir; load_stamp_basedir = dir;
tp_ftw(screen, buf, dirlen, 0, loadstamp_callback); tp_ftw(screen, buf, dirlen, 0, loadstamp_callback, NULL);
} }
@ -6242,6 +6242,7 @@ static void setup(int argc, char *argv[])
autosave_on_quit = 0; autosave_on_quit = 0;
dont_load_stamps = 0; dont_load_stamps = 0;
no_system_fonts = 1; no_system_fonts = 1;
all_locale_fonts = 0;
mirrorstamps = 0; mirrorstamps = 0;
disable_stamp_controls = 0; disable_stamp_controls = 0;
disable_magic_controls = 0; disable_magic_controls = 0;
@ -6663,6 +6664,14 @@ static void setup(int argc, char *argv[])
{ {
no_system_fonts = 0; no_system_fonts = 0;
} }
else if (strcmp(argv[i], "--alllocalefonts") == 0)
{
all_locale_fonts = 1;
}
else if (strcmp(argv[i], "--currentlocalefont") == 0)
{
all_locale_fonts = 0;
}
else if (strcmp(argv[i], "--noprint") == 0 || strcmp(argv[i], "-p") == 0) else if (strcmp(argv[i], "--noprint") == 0 || strcmp(argv[i], "-p") == 0)
{ {
disable_print = 1; disable_print = 1;
@ -6860,6 +6869,8 @@ static void setup(int argc, char *argv[])
setup_language(getfilename(argv[0]), &button_label_y_nudge); setup_language(getfilename(argv[0]), &button_label_y_nudge);
/* printf("cur locale = %d (%s)\n", get_current_language(), lang_prefixes[get_current_language()]); */
im_init(&im_data, get_current_language()); im_init(&im_data, get_current_language());
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
@ -6873,7 +6884,7 @@ static void setup(int argc, char *argv[])
-bjk 2007.06.05 */ -bjk 2007.06.05 */
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
run_font_scanner(screen); run_font_scanner(screen, lang_prefixes[get_current_language()]);
#endif #endif
@ -15884,6 +15895,15 @@ static void parse_options(FILE * fi)
{ {
disable_stamp_controls = 0; disable_stamp_controls = 0;
} }
else if (strcmp(str, "alllocalefonts=yes") == 0)
{
all_locale_fonts = 1;
}
else if (strcmp(str, "alllocalefonts=no") == 0 ||
strcmp(str, "currentlocalefont=yes") == 0)
{
all_locale_fonts = 0;
}
else if (strcmp(str, "nomagiccontrols=yes") == 0) else if (strcmp(str, "nomagiccontrols=yes") == 0)
{ {
disable_magic_controls = 1; disable_magic_controls = 1;