indent -bli0 -nip -npsl -npcs -l120 -lc120 -nprs

This commit is contained in:
William Kendrick 2010-02-02 23:42:06 +00:00
parent 6e6ee1f8a3
commit 68ead6a3d0

View file

@ -77,9 +77,9 @@
extern WrapperData macosx; extern WrapperData macosx;
/* system fonts that cause TTF_OpenFont to crash */ /* system fonts that cause TTF_OpenFont to crash */
static const char* problemFonts[] = { static const char *problemFonts[] = {
"/Library/Fonts//AppleMyungjo.ttf", "/Library/Fonts//AppleMyungjo.ttf",
NULL NULL
}; };
#endif #endif
@ -214,25 +214,25 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix); snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size); ret = TuxPaint_Font_OpenFont("", str, size);
#ifdef __APPLE__ #ifdef __APPLE__
if (!ret) if (!ret)
{ {
snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix); snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size); ret = TuxPaint_Font_OpenFont("", str, size);
} }
if (!ret) if (!ret)
{ {
snprintf(str, sizeof(str), "/Library/Fonts/%s.ttf", lang_prefix); snprintf(str, sizeof(str), "/Library/Fonts/%s.ttf", lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size); ret = TuxPaint_Font_OpenFont("", str, size);
} }
if (!ret) if (!ret)
{ {
snprintf(str, sizeof(str), "%s/%s.ttf", macosx.fontsPath, lang_prefix); snprintf(str, sizeof(str), "%s/%s.ttf", macosx.fontsPath, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size); ret = TuxPaint_Font_OpenFont("", str, size);
} }
#endif #endif
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
@ -241,17 +241,12 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
ret = try_alternate_font(size); ret = try_alternate_font(size);
if (!ret) if (!ret)
{ {
fprintf( fprintf(stderr,
stderr, "\nWarning: Can't load font for this locale:\n"
"\nWarning: Can't load font for this locale:\n" "%s\n"
"%s\n" "The Simple DirectMedia Layer error that occurred was:\n"
"The Simple DirectMedia Layer error that occurred was:\n" "%s\n\n" "Will use default (American English) instead.\n\n", str, SDL_GetError());
"%s\n\n" button_label_y_nudge = smash_i18n();
"Will use default (American English) instead.\n\n",
str,
SDL_GetError()
);
button_label_y_nudge = smash_i18n();
} }
} }
} }
@ -269,7 +264,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
tpf->pango_context = NULL; tpf->pango_context = NULL;
} }
#endif #endif
if (tpf->typ == FONT_TYPE_TTF) if (tpf->typ == FONT_TYPE_TTF)
{ {
TTF_CloseFont(tpf->ttf_font); TTF_CloseFont(tpf->ttf_font);
@ -278,9 +273,9 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
free(tpf); free(tpf);
} }
TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttffilename, int size) TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size)
{ {
TuxPaint_Font * tpf = NULL; TuxPaint_Font *tpf = NULL;
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
char desc[1024]; char desc[1024];
#endif #endif
@ -311,28 +306,30 @@ TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttff
tpf = NULL; tpf = NULL;
} }
else else
tpf->height = size; /* FIXME: Is this accurate!? -bjk 2007.07.12 */ tpf->height = size; /* FIXME: Is this accurate!? -bjk 2007.07.12 */
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_OpenFont() done\n"); fflush(stdout); printf("TuxPaint_Font_OpenFont() done\n");
fflush(stdout);
#endif #endif
return(tpf); return (tpf);
} }
#endif #endif
if (ttffilename != NULL && ttffilename[0] != '\0') if (ttffilename != NULL && ttffilename[0] != '\0')
{ {
#ifdef DEBUG #ifdef DEBUG
printf("Opening TTF\n"); fflush(stdout); printf("Opening TTF\n");
fflush(stdout);
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
int i = 0; int i = 0;
while (problemFonts[i] != NULL) while (problemFonts[i] != NULL)
{ {
if (!strcmp(ttffilename, problemFonts[i++])) if (!strcmp(ttffilename, problemFonts[i++]))
return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */ return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */
} }
#endif #endif
@ -357,10 +354,11 @@ TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttff
} }
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_OpenFont() done\n"); fflush(stdout); printf("TuxPaint_Font_OpenFont() done\n");
fflush(stdout);
#endif #endif
return(tpf); return (tpf);
} }
@ -545,9 +543,7 @@ static void groupfonts_range(style_info ** base, int count)
if (num_font_families == num_font_families_max) if (num_font_families == num_font_families_max)
{ {
num_font_families_max = num_font_families_max * 5 / 4 + 30; num_font_families_max = num_font_families_max * 5 / 4 + 30;
user_font_families = user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families);
realloc(user_font_families,
num_font_families_max * sizeof *user_font_families);
} }
fi = calloc(1, sizeof *fi); fi = calloc(1, sizeof *fi);
@ -563,8 +559,7 @@ static void groupfonts_range(style_info ** base, int count)
{ {
#if 0 #if 0
// THREADED_FONTS // THREADED_FONTS
printf("too many boldness levels, discarding: %s, %s\n", printf("too many boldness levels, discarding: %s, %s\n", base[i]->family, base[i]->style);
base[i]->family, base[i]->style);
#endif #endif
continue; continue;
} }
@ -574,11 +569,9 @@ static void groupfonts_range(style_info ** base, int count)
{ {
#if 0 #if 0
// THREADED_FONTS // THREADED_FONTS
printf("duplicates, discarding: %s, %s\n", base[i]->family, printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style);
base[i]->style);
printf("b %d, spot %d\n", b, spot); printf("b %d, spot %d\n", b, spot);
printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], fi->filename[2], fi->filename[3]);
fi->filename[2], fi->filename[3]);
#endif #endif
continue; continue;
} }
@ -801,8 +794,7 @@ static void parse_font_style(style_info * si)
si->boldness = 1; si->boldness = 1;
// we'll count both TrueType and OpenType // we'll count both TrueType and OpenType
si->truetype = !!strcasestr(si->filename, ".ttf") si->truetype = !!strcasestr(si->filename, ".ttf") || !!strcasestr(si->filename, ".otf");
|| !!strcasestr(si->filename, ".otf");
} }
@ -838,8 +830,7 @@ static void groupfonts(void)
while (i--) while (i--)
parse_font_style(user_font_styles[i]); parse_font_style(user_font_styles[i]);
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0], qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0], compar_fontgroup);
compar_fontgroup);
//printf("groupfonts() qsort(user_font_styles...)\n"); //printf("groupfonts() qsort(user_font_styles...)\n");
//fflush(stdout); //fflush(stdout);
@ -871,8 +862,7 @@ static void groupfonts(void)
free(user_font_styles); free(user_font_styles);
user_font_styles = NULL; // just to catch bugs user_font_styles = NULL; // just to catch bugs
qsort(user_font_families, num_font_families, sizeof user_font_families[0], qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller);
compar_fontkiller);
//printf(stderr, "groupfonts() qsort(user_font_families 1...)\n"); //printf(stderr, "groupfonts() qsort(user_font_families 1...)\n");
//fflush(stdout); //fflush(stdout);
low = 0; low = 0;
@ -885,15 +875,13 @@ static void groupfonts(void)
{ {
if (++high >= num_font_families) if (++high >= num_font_families)
break; break;
if (strcmp if (strcmp(user_font_families[low]->family, user_font_families[high]->family))
(user_font_families[low]->family, user_font_families[high]->family))
break; break;
} }
dupe_markdown_range(user_font_families + low, high - low); dupe_markdown_range(user_font_families + low, high - low);
low = high; low = high;
} }
qsort(user_font_families, num_font_families, sizeof user_font_families[0], qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontscore);
compar_fontscore);
//printf("groupfonts() qsort(user_font_families 2...)\n"); //printf("groupfonts() qsort(user_font_families 2...)\n");
//fflush(stdout); //fflush(stdout);
if (user_font_families[0]->score < 0) if (user_font_families[0]->score < 0)
@ -902,8 +890,7 @@ static void groupfonts(void)
// THREADED_FONTS // THREADED_FONTS
printf("Trim starting with %d families\n", num_font_families); printf("Trim starting with %d families\n", num_font_families);
#endif #endif
while (num_font_families > 1 while (num_font_families > 1 && user_font_families[num_font_families - 1]->score < 0)
&& user_font_families[num_font_families - 1]->score < 0)
{ {
i = --num_font_families; i = --num_font_families;
free(user_font_families[i]->directory); free(user_font_families[i]->directory);
@ -1025,8 +1012,8 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale)
#endif #endif
sched_yield(); // try to let the parent run right now sched_yield(); // try to let the parent run right now
prctl(PR_SET_PDEATHSIG, 9); // get killed if parent exits prctl(PR_SET_PDEATHSIG, 9); // get killed if parent exits
if(getppid()==1) if (getppid() == 1)
_exit(99); // parent is already init, and won't be dying :-) _exit(99); // parent is already init, and won't be dying :-)
font_socket_fd = sv[1]; font_socket_fd = sv[1];
close(sv[0]); close(sv[0]);
progress_bar_disabled = 1; progress_bar_disabled = 1;
@ -1158,8 +1145,7 @@ void receive_some_font_info(SDL_Surface * screen)
} }
rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill); rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill);
#ifdef DEBUG #ifdef DEBUG
printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, (long int) rc);
buf_fill, buf_size, (long int) rc);
#endif #endif
if (rc == -1) if (rc == -1)
@ -1199,8 +1185,8 @@ void receive_some_font_info(SDL_Surface * screen)
show_progress_bar(screen); show_progress_bar(screen);
walk = buf; walk = buf;
num_font_families = *(unsigned char *)walk++; num_font_families = *(unsigned char *) walk++;
num_font_families += *(unsigned char *)walk++ << 8u; num_font_families += *(unsigned char *) walk++ << 8u;
#ifdef DEBUG #ifdef DEBUG
printf("Got %u bytes with %u families.\n", buf_fill, num_font_families); printf("Got %u bytes with %u families.\n", buf_fill, num_font_families);
#endif #endif
@ -1260,7 +1246,8 @@ TuxPaint_Font *getfonthandle(int desire)
char description[1024]; char description[1024];
#ifdef DEBUG #ifdef DEBUG
printf("\ngetfonthandle(%d)...\n", desire); fflush(stdout); printf("\ngetfonthandle(%d)...\n", desire);
fflush(stdout);
#endif #endif
if (fi == NULL) if (fi == NULL)
@ -1275,22 +1262,22 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->filename != NULL) if (fi->filename != NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("Setting 'name' to fi->filename[%d (0x%x)]\n", printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int) text_state, (int) text_state);
(int) text_state,
(int) text_state);
fflush(stdout); fflush(stdout);
#endif #endif
name = fi->filename[text_state]; name = fi->filename[text_state];
#ifdef DEBUG #ifdef DEBUG
printf("Which is: %s\n", name); fflush(stdout); printf("Which is: %s\n", name);
fflush(stdout);
#endif #endif
} }
else else
{ {
#ifdef DBEUG #ifdef DBEUG
printf("fi->filename is NULL\n"); fflush(stdout); printf("fi->filename is NULL\n");
fflush(stdout);
#endif #endif
name = NULL; name = NULL;
@ -1299,13 +1286,15 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->handle) if (fi->handle)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("fi->handle was set (0x%x)\n", (int) fi->handle); fflush(stdout); printf("fi->handle was set (0x%x)\n", (int) fi->handle);
fflush(stdout);
#endif #endif
return fi->handle; return fi->handle;
} }
#ifdef DEBUG #ifdef DEBUG
printf("fi->handle was not yet set\n"); fflush(stdout); printf("fi->handle was not yet set\n");
fflush(stdout);
#endif #endif
@ -1350,9 +1339,10 @@ TuxPaint_Font *getfonthandle(int desire)
if (!name) if (!name)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("name is still NULL\n"); fflush(stdout); printf("name is still NULL\n");
fflush(stdout);
#endif #endif
return(NULL); return (NULL);
} }
pathname = alloca(strlen(fi->directory) + 1 + strlen(name) + 1); pathname = alloca(strlen(fi->directory) + 1 + strlen(name) + 1);
@ -1367,9 +1357,10 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->handle == NULL) if (fi->handle == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("fi->handle is NULL!\n"); fflush(stdout); printf("fi->handle is NULL!\n");
fflush(stdout);
#endif #endif
return(NULL); return (NULL);
} }
if (fi->handle->typ == FONT_TYPE_TTF) if (fi->handle->typ == FONT_TYPE_TTF)
@ -1377,13 +1368,15 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->handle->ttf_font == NULL) if (fi->handle->ttf_font == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("fi->handle->ttf_font is NULL!\n"); fflush(stdout); printf("fi->handle->ttf_font is NULL!\n");
fflush(stdout);
#endif #endif
return(NULL); return (NULL);
} }
#ifdef DEBUG #ifdef DEBUG
printf("calling TTF_SetFontStyle(0x%x)\n", missing); fflush(stdout); printf("calling TTF_SetFontStyle(0x%x)\n", missing);
fflush(stdout);
#endif #endif
TTF_SetFontStyle(fi->handle->ttf_font, missing); TTF_SetFontStyle(fi->handle->ttf_font, missing);
@ -1402,8 +1395,7 @@ TuxPaint_Font *getfonthandle(int desire)
static int was_bad_font; static int was_bad_font;
// see if two font surfaces are the same // see if two font surfaces are the same
static int do_surfcmp(const SDL_Surface * const *const v1, static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * const *const v2)
const SDL_Surface * const *const v2)
{ {
const SDL_Surface *const s1 = *v1; const SDL_Surface *const s1 = *v1;
const SDL_Surface *const s2 = *v2; const SDL_Surface *const s2 = *v2;
@ -1416,8 +1408,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1,
printf("s1==s2?\n"); printf("s1==s2?\n");
return 0; return 0;
} }
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format || !s2->format)
|| !s2->format)
{ {
was_bad_font = 1; was_bad_font = 1;
return 0; return 0;
@ -1533,31 +1524,33 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf)
if (tpf == NULL) if (tpf == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_FontHeight() received NULL\n"); fflush(stdout); printf("TuxPaint_Font_FontHeight() received NULL\n");
fflush(stdout);
#endif #endif
return(1); return (1);
} }
return(tpf->height); return (tpf->height);
} }
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf) const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
{ {
if (tpf == NULL) if (tpf == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_FontFaceFamilyName() received NULL\n"); fflush(stdout); printf("TuxPaint_Font_FontFaceFamilyName() received NULL\n");
fflush(stdout);
#endif #endif
return(""); return ("");
} }
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO) if (tpf->typ == FONT_TYPE_PANGO)
{ {
(void)(tpf); (void) (tpf);
/* FIXME */ /* FIXME */
return(""); return ("");
} }
#endif #endif
@ -1568,44 +1561,44 @@ const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
printf("TuxPaint_Font_FontFaceFamilyName() is confused\n"); printf("TuxPaint_Font_FontFaceFamilyName() is confused\n");
#endif #endif
return(""); return ("");
} }
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf) const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
{ {
if (tpf == NULL) if (tpf == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_FontFaceStyleName() received NULL\n"); fflush(stdout); printf("TuxPaint_Font_FontFaceStyleName() received NULL\n");
fflush(stdout);
#endif #endif
return(""); return ("");
} }
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO) if (tpf->typ == FONT_TYPE_PANGO)
{ {
(void)(tpf); (void) (tpf);
/* FIXME */ /* FIXME */
return(""); return ("");
} }
#endif #endif
if (tpf->typ == FONT_TYPE_TTF) if (tpf->typ == FONT_TYPE_TTF)
return (TTF_FontFaceStyleName(tpf->ttf_font)); return (TTF_FontFaceStyleName(tpf->ttf_font));
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_FontFaceStyleName() is confused\n"); printf("TuxPaint_Font_FontFaceStyleName() is confused\n");
#endif #endif
return(""); return ("");
} }
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
void sdl_color_to_pango_color(SDL_Color sdl_color, void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color)
SDLPango_Matrix * pango_color)
{ {
Uint8 pc[4][4]; Uint8 pc[4][4];
@ -1633,4 +1626,3 @@ void sdl_color_to_pango_color(SDL_Color sdl_color,
} }
#endif #endif