diff --git a/src/fonts.c b/src/fonts.c index 7f0dbcae9..94ca44588 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -24,7 +24,7 @@ #include #ifndef __USE_GNU -#define __USE_GNU /* for strcasestr() */ +#define __USE_GNU /* for strcasestr() */ #endif #include #include @@ -85,7 +85,7 @@ static const char *problemFonts[] = { /* font types that cause TTF_OpenFont to crash */ static const char *problemFontExtensions[] = { - ".pfb", /* Ubuntu 14.04 (libsdl-ttf2.0-0 2.0.11-3, libfreetype6 2.5.2-1ubuntu2) -bjk 2014.04.19 */ + ".pfb", /* Ubuntu 14.04 (libsdl-ttf2.0-0 2.0.11-3, libfreetype6 2.5.2-1ubuntu2) -bjk 2014.04.19 */ NULL }; @@ -153,7 +153,7 @@ int num_font_styles; int num_font_styles_max; int text_state; -unsigned text_size = 4; // initial text size +unsigned text_size = 4; // initial text size int button_label_y_nudge; @@ -167,12 +167,12 @@ static TuxPaint_Font *try_alternate_font(int size) strcpy(prefix, lang_prefix); if ((p = strrchr(prefix, '_')) != NULL) - { - *p = 0; - snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, prefix); + { + *p = 0; + snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, prefix); - return TuxPaint_Font_OpenFont("", str, size); - } + return TuxPaint_Font_OpenFont("", str, size); + } return NULL; } #endif @@ -183,53 +183,54 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size) TuxPaint_Font *ret = NULL; if (!need_own_font) - { - return fallback; - } + { + return fallback; + } else - { - char str[128]; - snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix); + { + char str[128]; - ret = TuxPaint_Font_OpenFont("", str, size); + snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix); + + ret = TuxPaint_Font_OpenFont("", str, size); #ifdef __APPLE__ - if (!ret) - { - snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix); - ret = TuxPaint_Font_OpenFont("", str, size); - } + if (!ret) + { + snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix); + ret = TuxPaint_Font_OpenFont("", str, size); + } - if (!ret) - { - snprintf(str, sizeof(str), "/Library/Fonts/%s.ttf", lang_prefix); - ret = TuxPaint_Font_OpenFont("", str, size); - } + if (!ret) + { + snprintf(str, sizeof(str), "/Library/Fonts/%s.ttf", lang_prefix); + ret = TuxPaint_Font_OpenFont("", str, size); + } - if (!ret) - { - snprintf(str, sizeof(str), "%s/%s.ttf", macosx.fontsPath, lang_prefix); - ret = TuxPaint_Font_OpenFont("", str, size); - } + if (!ret) + { + snprintf(str, sizeof(str), "%s/%s.ttf", macosx.fontsPath, lang_prefix); + ret = TuxPaint_Font_OpenFont("", str, size); + } #endif #ifndef NO_SDLPANGO - if (!ret) - { - ret = try_alternate_font(size); if (!ret) - { - fprintf(stderr, - "\nWarning: Can't load font for this locale:\n" - "%s\n" - "The Simple DirectMedia Layer error that occurred was:\n" - "%s\n\n" "Will use default (American English) instead.\n\n", str, SDL_GetError()); - button_label_y_nudge = smash_i18n(); - } - } + { + ret = try_alternate_font(size); + if (!ret) + { + fprintf(stderr, + "\nWarning: Can't load font for this locale:\n" + "%s\n" + "The Simple DirectMedia Layer error that occurred was:\n" + "%s\n\n" "Will use default (American English) instead.\n\n", str, SDL_GetError()); + button_label_y_nudge = smash_i18n(); + } + } #endif - return ret ? ret : fallback; - } + return ret ? ret : fallback; + } } #endif @@ -238,20 +239,21 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf) #ifdef DEBUG printf("TuxPaint_Font_CloseFont step 1 (%p)\n", tpf); //EP #endif - if (!tpf) return; //EP - + if (!tpf) + return; //EP + #ifndef NO_SDLPANGO #ifdef DEBUG printf("TuxPaint_Font_CloseFont step 2 (%p, %d)\n", tpf->pango_context, tpf->typ); //EP #endif if (tpf->typ == FONT_TYPE_PANGO) - if (tpf->pango_context) //EP - { -#ifndef __APPLE__ //EP added ifdef because SDLPango_FreeContext sometimes crashed with "pointer being freed was not allocated" + if (tpf->pango_context) //EP + { +#ifndef __APPLE__ //EP added ifdef because SDLPango_FreeContext sometimes crashed with "pointer being freed was not allocated" SDLPango_FreeContext(tpf->pango_context); #endif tpf->pango_context = NULL; - } + } #endif #ifdef DEBUG @@ -259,16 +261,17 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf) fflush(stdout); #endif if (tpf->typ == FONT_TYPE_TTF) - if (tpf->ttf_font) //EP - { - TTF_CloseFont(tpf->ttf_font); - tpf->ttf_font = NULL; - } + if (tpf->ttf_font) //EP + { + TTF_CloseFont(tpf->ttf_font); + tpf->ttf_font = NULL; + } - if (tpf->desc != NULL) { - free(tpf->desc); - tpf->desc = NULL; - } + if (tpf->desc != NULL) + { + free(tpf->desc); + tpf->desc = NULL; + } free(tpf); } @@ -277,6 +280,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile { TuxPaint_Font *tpf = NULL; int i; + #ifndef NO_SDLPANGO char desc[1024]; #endif @@ -288,84 +292,84 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile #ifndef NO_SDLPANGO if (pangodesc != NULL && pangodesc[0] != '\0') - { - tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font)); - tpf->typ = FONT_TYPE_PANGO; - snprintf(desc, sizeof(desc), "%s %d", pangodesc, (size * 3) / 4); - tpf->desc = strdup(desc); - -#ifdef DEBUG - printf("Creating context: \"%s\"\n", desc); -#endif - - tpf->pango_context = SDLPango_CreateContext_GivenFontDesc(desc); - if (tpf->pango_context == NULL) { + tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font)); + tpf->typ = FONT_TYPE_PANGO; + snprintf(desc, sizeof(desc), "%s %d", pangodesc, (size * 3) / 4); + tpf->desc = strdup(desc); + #ifdef DEBUG - printf("Failed to load %s\n", desc); + printf("Creating context: \"%s\"\n", desc); #endif - free(tpf); - tpf = NULL; + + tpf->pango_context = SDLPango_CreateContext_GivenFontDesc(desc); + if (tpf->pango_context == NULL) + { +#ifdef DEBUG + printf("Failed to load %s\n", desc); +#endif + free(tpf); + tpf = NULL; + } + else + tpf->height = size; /* FIXME: Is this accurate!? -bjk 2007.07.12 */ + +#ifdef DEBUG + printf("TuxPaint_Font_OpenFont() done\n"); + fflush(stdout); +#endif + + return (tpf); } - else - tpf->height = size; /* FIXME: Is this accurate!? -bjk 2007.07.12 */ - -#ifdef DEBUG - printf("TuxPaint_Font_OpenFont() done\n"); - fflush(stdout); -#endif - - return (tpf); - } #endif if (ttffilename != NULL && ttffilename[0] != '\0') - { -#ifdef DEBUG - printf("Opening TTF\n"); - fflush(stdout); -#endif - - i = 0; - while (problemFonts[i] != NULL) - { - if (!strcmp(ttffilename, problemFonts[i++])) - return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */ - } - - i = 0; - while (problemFontExtensions[i] != NULL) - { - if (strstr(ttffilename, problemFontExtensions[i++])) - return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */ - } - - tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font)); - tpf->typ = FONT_TYPE_TTF; - tpf->ttf_font = TTF_OpenFont(ttffilename, size); - tpf->desc = strdup(ttffilename); - -#ifdef DEBUG - printf("Loaded %s: %d->%d\n", ttffilename, tpf, tpf->ttf_font); - fflush(stdout); -#endif - - if (tpf->ttf_font == NULL) { #ifdef DEBUG - printf("Failed to load %s: %s\n", ttffilename, SDL_GetError()); + printf("Opening TTF\n"); + fflush(stdout); #endif - free(tpf); - tpf = NULL; - } - else - { + + i = 0; + while (problemFonts[i] != NULL) + { + if (!strcmp(ttffilename, problemFonts[i++])) + return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */ + } + + i = 0; + while (problemFontExtensions[i] != NULL) + { + if (strstr(ttffilename, problemFontExtensions[i++])) + return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */ + } + + tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font)); + tpf->typ = FONT_TYPE_TTF; + tpf->ttf_font = TTF_OpenFont(ttffilename, size); + tpf->desc = strdup(ttffilename); + #ifdef DEBUG - printf("Succeeded loading %s\n", ttffilename); + printf("Loaded %s: %d->%d\n", ttffilename, tpf, tpf->ttf_font); + fflush(stdout); #endif - tpf->height = TTF_FontHeight(tpf->ttf_font); + + if (tpf->ttf_font == NULL) + { +#ifdef DEBUG + printf("Failed to load %s: %s\n", ttffilename, SDL_GetError()); +#endif + free(tpf); + tpf = NULL; + } + else + { +#ifdef DEBUG + printf("Succeeded loading %s\n", ttffilename); +#endif + tpf->height = TTF_FontHeight(tpf->ttf_font); + } } - } #ifdef DEBUG printf("TuxPaint_Font_OpenFont() done\n"); @@ -381,30 +385,32 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile void reliable_write(int fd, const void *buf, size_t count) { struct pollfd p; + do - { - ssize_t rc = write(fd, buf, count); - if (rc == -1) { - switch (errno) - { - default: - return; - case EAGAIN: - case ENOSPC: - ; // satisfy a C syntax abomination - p = (struct pollfd) - { - fd, POLLOUT, 0}; - poll(&p, 1, -1); // try not to burn CPU time - // FALL THROUGH - case EINTR: - continue; - } + ssize_t rc = write(fd, buf, count); + + if (rc == -1) + { + switch (errno) + { + default: + return; + case EAGAIN: + case ENOSPC: + ; // satisfy a C syntax abomination + p = (struct pollfd) + { + fd, POLLOUT, 0}; + poll(&p, 1, -1); // try not to burn CPU time + // FALL THROUGH + case EINTR: + continue; + } + } + buf += rc; + count -= rc; } - buf += rc; - count -= rc; - } while (count); } @@ -412,31 +418,33 @@ void reliable_write(int fd, const void *buf, size_t count) static void reliable_read(int fd, void *buf, size_t count) { struct pollfd p; + do - { - ssize_t rc = read(fd, buf, count); - if (rc == -1) { - switch (errno) - { - default: - return; - case EAGAIN: - ; // satisfy a C syntax abomination - p = (struct pollfd) - { - fd, POLLIN, 0}; - poll(&p, 1, -1); // try not to burn CPU time - // FALL THROUGH - case EINTR: - continue; - } + ssize_t rc = read(fd, buf, count); + + if (rc == -1) + { + switch (errno) + { + default: + return; + case EAGAIN: + ; // satisfy a C syntax abomination + p = (struct pollfd) + { + fd, POLLIN, 0}; + poll(&p, 1, -1); // try not to burn CPU time + // FALL THROUGH + case EINTR: + continue; + } + } + if (rc == 0) + break; // EOF. Better not happen before the end! + buf += rc; + count -= rc; } - if (rc == 0) - break; // EOF. Better not happen before the end! - buf += rc; - count -= rc; - } while (count); } @@ -456,14 +464,14 @@ static void groupfonts_range(style_info ** base, int count) #if 0 // THREADED_FONTS if (count < 1 || count > 4) - { - printf("\n::::::: %d styles in %s:\n", count, base[0]->family); - i = count; - while (i--) { - printf(" %s\n", base[i]->style); + printf("\n::::::: %d styles in %s:\n", count, base[0]->family); + i = count; + while (i--) + { + printf(" %s\n", base[i]->style); + } } - } #endif i = count; @@ -476,90 +484,90 @@ static void groupfonts_range(style_info ** base, int count) i = 4; while (i--) - { - if (!boldcounts[i]) - continue; - if (i > boldmax) - boldmax = i; - if (i < boldmin) - boldmin = i; - bolduse++; - } + { + if (!boldcounts[i]) + continue; + if (i > boldmax) + boldmax = i; + if (i < boldmin) + boldmin = i; + bolduse++; + } if (likely(bolduse <= 2)) - { - // in case they are same, we want non-bold, - // so that setting goes second - boldmap[boldmax] = 1; - boldmap[boldmin] = 0; - } + { + // in case they are same, we want non-bold, + // so that setting goes second + boldmap[boldmax] = 1; + boldmap[boldmin] = 0; + } else if (count == 3) - { - int boldmid; - int zmin = 0, zmid = 0, zmax = 0; - - boldmap[boldmax] = 1; - boldmap[boldmin] = 0; - boldmid = boldcounts[boldmin + 1] ? boldmin + 1 : boldmin + 2; - - i = 3; - while (i--) { - if (base[i]->boldness == boldmin) - zmin = base[i]->italic; - if (base[i]->boldness == boldmid) - zmid = base[i]->italic; - if (base[i]->boldness == boldmax) - zmax = base[i]->italic; + int boldmid; + int zmin = 0, zmid = 0, zmax = 0; + + boldmap[boldmax] = 1; + boldmap[boldmin] = 0; + boldmid = boldcounts[boldmin + 1] ? boldmin + 1 : boldmin + 2; + + i = 3; + while (i--) + { + if (base[i]->boldness == boldmin) + zmin = base[i]->italic; + if (base[i]->boldness == boldmid) + zmid = base[i]->italic; + if (base[i]->boldness == boldmax) + zmax = base[i]->italic; + } + if (zmin != zmid) + boldmap[boldmid] = 0; + else if (zmid != zmax) + boldmap[boldmid] = 1; + else if (boldmin == 0 && boldmid == 1) + { + boldmap[0] = -1; + boldmap[1] = 0; + } } - if (zmin != zmid) - boldmap[boldmid] = 0; - else if (zmid != zmax) - boldmap[boldmid] = 1; - else if (boldmin == 0 && boldmid == 1) - { - boldmap[0] = -1; - boldmap[1] = 0; - } - } else - { - int claimed_bold = boldcounts[3]; - int claimed_norm = boldcounts[1]; - - // 3 or 4 boldness levels, 4 or more styles! - // This is going to be random hacks and hopes. - - // bold is bold - boldmap[3] = 1; - - // norm is norm - boldmap[1] = 0; - - // classify demi-bold or medium - if (claimed_bold < 2) { - boldmap[2] = 1; - claimed_bold += boldcounts[2]; - } - else if (claimed_norm < 2) - { - boldmap[2] = 0; - claimed_norm += boldcounts[2]; - } + int claimed_bold = boldcounts[3]; + int claimed_norm = boldcounts[1]; - // classify lightface - if (claimed_norm < 2) - { - boldmap[0] = 0; - //claimed_norm += boldcounts[0]; + // 3 or 4 boldness levels, 4 or more styles! + // This is going to be random hacks and hopes. + + // bold is bold + boldmap[3] = 1; + + // norm is norm + boldmap[1] = 0; + + // classify demi-bold or medium + if (claimed_bold < 2) + { + boldmap[2] = 1; + claimed_bold += boldcounts[2]; + } + else if (claimed_norm < 2) + { + boldmap[2] = 0; + claimed_norm += boldcounts[2]; + } + + // classify lightface + if (claimed_norm < 2) + { + boldmap[0] = 0; + //claimed_norm += boldcounts[0]; + } } - } if (num_font_families == num_font_families_max) - { - num_font_families_max = num_font_families_max * 5 / 4 + 30; - user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families); - } + { + num_font_families_max = num_font_families_max * 5 / 4 + 30; + user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families); + } fi = calloc(1, sizeof *fi); user_font_families[num_font_families++] = fi; @@ -568,49 +576,50 @@ static void groupfonts_range(style_info ** base, int count) fi->score = base[0]->truetype + base[0]->score; i = count; while (i--) - { - int b = boldmap[base[i]->boldness]; - if (b == -1) { + int b = boldmap[base[i]->boldness]; + + if (b == -1) + { #if 0 // THREADED_FONTS - printf("too many boldness levels, discarding: %s, %s\n", base[i]->family, base[i]->style); + printf("too many boldness levels, discarding: %s, %s\n", base[i]->family, base[i]->style); #endif - continue; - } - spot = b ? TTF_STYLE_BOLD : 0; - spot += base[i]->italic ? TTF_STYLE_ITALIC : 0; - if (fi->filename[spot]) - { + continue; + } + spot = b ? TTF_STYLE_BOLD : 0; + spot += base[i]->italic ? TTF_STYLE_ITALIC : 0; + if (fi->filename[spot]) + { #if 0 // THREADED_FONTS - printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style); - printf("b %d, spot %d\n", b, spot); - printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], fi->filename[2], fi->filename[3]); + printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style); + printf("b %d, spot %d\n", b, spot); + printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], fi->filename[2], fi->filename[3]); #endif - continue; + continue; + } + fi->filename[spot] = strdup(base[i]->filename); + fi->score += 2; } - fi->filename[spot] = strdup(base[i]->filename); - fi->score += 2; - } if (!fi->filename[0] && !fi->filename[1]) - { - fi->filename[0] = fi->filename[2]; - fi->filename[2] = NULL; - fi->filename[1] = fi->filename[3]; - fi->filename[3] = NULL; - } + { + fi->filename[0] = fi->filename[2]; + fi->filename[2] = NULL; + fi->filename[1] = fi->filename[3]; + fi->filename[3] = NULL; + } if (!fi->filename[0] && !fi->filename[2]) - { - fi->filename[0] = fi->filename[1]; - fi->filename[1] = NULL; - fi->filename[2] = fi->filename[3]; - fi->filename[3] = NULL; - } + { + fi->filename[0] = fi->filename[1]; + fi->filename[1] = NULL; + fi->filename[2] = fi->filename[3]; + fi->filename[3] = NULL; + } if (!fi->filename[0]) - { - fi->filename[0] = strdup(fi->filename[TTF_STYLE_BOLD]); - } + { + fi->filename[0] = strdup(fi->filename[TTF_STYLE_BOLD]); + } } @@ -683,125 +692,126 @@ static void parse_font_style(style_info * si) while (*sp) - { - if (*sp == ' ') { - sp++; - continue; - } - if (!strncasecmp(sp, "Bold", strlen("Bold"))) - { - sp += strlen("Bold"); - have_bold = 1; - continue; - } - if (!strncasecmp(sp, "Regular", strlen("Regular"))) - { - sp += strlen("Regular"); - continue; - } - if (!strncasecmp(sp, "Italic", strlen("Italic"))) - { - sp += strlen("Italic"); - si->italic = 1; - continue; - } - if (!strncasecmp(sp, "Oblique", strlen("Oblique"))) - { - sp += strlen("Oblique"); - si->italic = 1; - continue; - } - // move " Condensed" from style to family - if (!strncasecmp(sp, "Condensed", strlen("Condensed"))) - { - size_t len = strlen(si->family); - char *name = malloc(len + strlen(" Condensed") + 1); - sp += strlen("Condensed"); - memcpy(name, si->family, len); - strcpy(name + len, " Condensed"); - free(si->family); - si->family = name; - continue; - } - if (!strncasecmp(sp, "Light", strlen("Light"))) - { - sp += strlen("Light"); - have_light = 1; - continue; - } - if (!strncasecmp(sp, "Medium", strlen("Medium"))) - { - sp += strlen("Medium"); - have_medium = 1; - continue; - } - if (!strncasecmp(sp, "Demi", strlen("Demi"))) - { - sp += strlen("Demi"); - have_demi = 1; - continue; - } - if (!strncasecmp(sp, "Heavy", strlen("Heavy"))) - { - sp += strlen("Heavy"); - have_heavy = 1; - continue; - } - if (!strncasecmp(sp, "Normal", strlen("Normal"))) - { - sp += strlen("Normal"); - continue; - } - if (!strncasecmp(sp, "Black", strlen("Black"))) - { - sp += strlen("Black"); - have_black = 1; - continue; - } - if (!strncasecmp(sp, "Roman", strlen("Roman"))) - { - sp += strlen("Roman"); - continue; - } - if (!strncasecmp(sp, "Book", strlen("Book"))) - { - sp += strlen("Book"); - continue; - } - if (!strncasecmp(sp, "Chancery", strlen("Chancery"))) - { - sp += strlen("Chancery"); - si->italic = 1; - continue; - } - if (!strncasecmp(sp, "Thin", strlen("Thin"))) - { - sp += strlen("Thin"); - have_light = 1; - continue; - } - if (!strncmp(sp, "LR", strlen("LR"))) - { - sp += strlen("LR"); - continue; - } + if (*sp == ' ') + { + sp++; + continue; + } + if (!strncasecmp(sp, "Bold", strlen("Bold"))) + { + sp += strlen("Bold"); + have_bold = 1; + continue; + } + if (!strncasecmp(sp, "Regular", strlen("Regular"))) + { + sp += strlen("Regular"); + continue; + } + if (!strncasecmp(sp, "Italic", strlen("Italic"))) + { + sp += strlen("Italic"); + si->italic = 1; + continue; + } + if (!strncasecmp(sp, "Oblique", strlen("Oblique"))) + { + sp += strlen("Oblique"); + si->italic = 1; + continue; + } + // move " Condensed" from style to family + if (!strncasecmp(sp, "Condensed", strlen("Condensed"))) + { + size_t len = strlen(si->family); + char *name = malloc(len + strlen(" Condensed") + 1); - if (!stumped) - { - stumped = 1; + sp += strlen("Condensed"); + memcpy(name, si->family, len); + strcpy(name + len, " Condensed"); + free(si->family); + si->family = name; + continue; + } + if (!strncasecmp(sp, "Light", strlen("Light"))) + { + sp += strlen("Light"); + have_light = 1; + continue; + } + if (!strncasecmp(sp, "Medium", strlen("Medium"))) + { + sp += strlen("Medium"); + have_medium = 1; + continue; + } + if (!strncasecmp(sp, "Demi", strlen("Demi"))) + { + sp += strlen("Demi"); + have_demi = 1; + continue; + } + if (!strncasecmp(sp, "Heavy", strlen("Heavy"))) + { + sp += strlen("Heavy"); + have_heavy = 1; + continue; + } + if (!strncasecmp(sp, "Normal", strlen("Normal"))) + { + sp += strlen("Normal"); + continue; + } + if (!strncasecmp(sp, "Black", strlen("Black"))) + { + sp += strlen("Black"); + have_black = 1; + continue; + } + if (!strncasecmp(sp, "Roman", strlen("Roman"))) + { + sp += strlen("Roman"); + continue; + } + if (!strncasecmp(sp, "Book", strlen("Book"))) + { + sp += strlen("Book"); + continue; + } + if (!strncasecmp(sp, "Chancery", strlen("Chancery"))) + { + sp += strlen("Chancery"); + si->italic = 1; + continue; + } + if (!strncasecmp(sp, "Thin", strlen("Thin"))) + { + sp += strlen("Thin"); + have_light = 1; + continue; + } + if (!strncmp(sp, "LR", strlen("LR"))) + { + sp += strlen("LR"); + continue; + } + + if (!stumped) + { + stumped = 1; #if 0 // THREADED_FONTS - printf("Font style parser stumped by \"%s\".\n", si->style); + printf("Font style parser stumped by \"%s\".\n", si->style); #endif + } + sp++; // bad: an unknown character } - sp++; // bad: an unknown character - } if (have_demi || have_medium) si->boldness = 2; - else if (have_bold || have_black || have_heavy) // TODO: split these + else if (have_bold || have_black || have_heavy) // TODO: split these si->boldness = 3; else if (have_light) si->boldness = 0; @@ -809,7 +819,7 @@ static void parse_font_style(style_info * si) si->boldness = 1; // we'll count both TrueType and OpenType - si->truetype = !!strcasestr(si->filename, ".ttf") || !!strcasestr(si->filename, ".otf"); + si->truetype = ! !strcasestr(si->filename, ".ttf") || ! !strcasestr(si->filename, ".otf"); } @@ -818,21 +828,23 @@ static void dupe_markdown_range(family_info ** base, int count) int bestscore = -999; int bestslot = 0; int i = count; + while (i--) - { - int score = base[i]->score; - if (score <= bestscore) - continue; - bestscore = score; - bestslot = i; - } + { + int score = base[i]->score; + + if (score <= bestscore) + continue; + bestscore = score; + bestslot = i; + } i = count; while (i--) - { - if (i == bestslot) - continue; - base[i]->score = -999; - } + { + if (i == bestslot) + continue; + base[i]->score = -999; + } } @@ -850,50 +862,52 @@ static void groupfonts(void) //fflush(stdout); for (;;) - { - int high = low; - if (low >= num_font_styles) - break; - for (;;) { - if (++high >= num_font_styles) - break; - if (compar_fontgroup(user_font_styles + low, user_font_styles + high)) - break; + int high = low; + + if (low >= num_font_styles) + break; + for (;;) + { + if (++high >= num_font_styles) + break; + if (compar_fontgroup(user_font_styles + low, user_font_styles + high)) + break; + } + groupfonts_range(user_font_styles + low, high - low); + low = high; } - groupfonts_range(user_font_styles + low, high - low); - low = high; - } i = num_font_styles; while (i--) - { - free(user_font_styles[i]->filename); - free(user_font_styles[i]->directory); - free(user_font_styles[i]->family); - free(user_font_styles[i]->style); - free(user_font_styles[i]); - } + { + free(user_font_styles[i]->filename); + free(user_font_styles[i]->directory); + free(user_font_styles[i]->family); + free(user_font_styles[i]->style); + free(user_font_styles[i]); + } 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], compar_fontkiller); low = 0; for (;;) - { - int high = low; - if (low >= num_font_families) - break; - for (;;) { - if (++high >= num_font_families) - break; - if (strcmp(user_font_families[low]->family, user_font_families[high]->family)) - break; + int high = low; + + if (low >= num_font_families) + break; + for (;;) + { + if (++high >= num_font_families) + break; + if (strcmp(user_font_families[low]->family, user_font_families[high]->family)) + break; + } + dupe_markdown_range(user_font_families + low, high - low); + low = high; } - dupe_markdown_range(user_font_families + low, high - low); - low = high; - } qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontscore); //printf("groupfonts() qsort(user_font_families 2...)\n"); //fflush(stdout); @@ -904,22 +918,22 @@ static void groupfonts(void) printf("Trim starting with %d families\n", num_font_families); #endif while (num_font_families > 1 && user_font_families[num_font_families - 1]->score < 0) - { - i = --num_font_families; - free(user_font_families[i]->directory); - free(user_font_families[i]->family); - cpp = user_font_families[i]->filename; - if (cpp[0]) - free(cpp[0]); - if (cpp[1]) - free(cpp[1]); - if (cpp[2]) - free(cpp[2]); - if (cpp[3]) - free(cpp[3]); - free(user_font_families[i]); - user_font_families[i] = NULL; - } + { + i = --num_font_families; + free(user_font_families[i]->directory); + free(user_font_families[i]->family); + cpp = user_font_families[i]->filename; + if (cpp[0]) + free(cpp[0]); + if (cpp[1]) + free(cpp[1]); + if (cpp[2]) + free(cpp[2]); + if (cpp[3]) + free(cpp[3]); + free(user_font_families[i]); + user_font_families[i] = NULL; + } #if 0 // THREADED_FONTS printf("Trim ending with %d families\n", num_font_families); @@ -946,52 +960,53 @@ static void loadfonts(SDL_Surface * screen, const char *const dir) { char *homedirdir; - (void) vp; // junk passed by threading library + (void)vp; // junk passed by threading library loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale); if (!no_system_fonts) - { + { #ifdef WIN32 - homedirdir = GetSystemFontDir(); - loadfonts(screen, homedirdir); - free(homedirdir); + homedirdir = GetSystemFontDir(); + loadfonts(screen, homedirdir); + free(homedirdir); #elif defined(__BEOS__) - loadfonts(screen, "/boot/home/config/font/ttffonts"); - loadfonts(screen, "/usr/share/fonts"); - loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); + loadfonts(screen, "/boot/home/config/font/ttffonts"); + loadfonts(screen, "/usr/share/fonts"); + loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); #elif defined(__HAIKU__) - dev_t volume = dev_for_path("/boot"); - char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; - status_t result; - result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); - loadfonts(screen, buffer); - result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); - loadfonts(screen, buffer); - result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); - loadfonts(screen, buffer); + dev_t volume = dev_for_path("/boot"); + char buffer[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH]; + status_t result; + + result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); + loadfonts(screen, buffer); + result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); + loadfonts(screen, buffer); + result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); + loadfonts(screen, buffer); #elif defined(__APPLE__) - loadfonts(screen, "/System/Library/Fonts"); - loadfonts(screen, "/Library/Fonts"); - loadfonts(screen, macosx.fontsPath); - loadfonts(screen, "/usr/share/fonts"); - loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); + loadfonts(screen, "/System/Library/Fonts"); + loadfonts(screen, "/Library/Fonts"); + loadfonts(screen, macosx.fontsPath); + loadfonts(screen, "/usr/share/fonts"); + loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); #elif defined(__sun__) - loadfonts(screen, "/usr/openwin/lib/X11/fonts"); - loadfonts(screen, "/usr/share/fonts"); - loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); + loadfonts(screen, "/usr/openwin/lib/X11/fonts"); + loadfonts(screen, "/usr/share/fonts"); + loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); #else - loadfonts(screen, "/usr/share/feh/fonts"); - loadfonts(screen, "/usr/share/fonts"); - loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); - loadfonts(screen, "/usr/share/texmf/fonts"); - loadfonts(screen, "/usr/share/grace/fonts/type1"); - loadfonts(screen, "/usr/share/hatman/fonts"); - loadfonts(screen, "/usr/share/icewm/themes/jim-mac"); - loadfonts(screen, "/usr/share/vlc/skins2/fonts"); - loadfonts(screen, "/usr/share/xplanet/fonts"); + loadfonts(screen, "/usr/share/feh/fonts"); + loadfonts(screen, "/usr/share/fonts"); + loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); + loadfonts(screen, "/usr/share/texmf/fonts"); + loadfonts(screen, "/usr/share/grace/fonts/type1"); + loadfonts(screen, "/usr/share/hatman/fonts"); + loadfonts(screen, "/usr/share/icewm/themes/jim-mac"); + loadfonts(screen, "/usr/share/vlc/skins2/fonts"); + loadfonts(screen, "/usr/share/xplanet/fonts"); #endif - } + } homedirdir = get_fname("fonts", DIR_DATA); loadfonts(screen, homedirdir); @@ -1008,7 +1023,7 @@ static void loadfonts(SDL_Surface * screen, const char *const dir) font_thread_done = 1; waiting_for_fonts = 0; // FIXME: need a memory barrier here - return 0; // useless, wanted by threading library + return 0; // useless, wanted by threading library } @@ -1024,24 +1039,24 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale) exit(42); font_scanner_pid = fork(); if (font_scanner_pid) - { - // parent (or error -- but we're screwed in that case) - font_socket_fd = sv[0]; - close(sv[1]); - return; - } + { + // parent (or error -- but we're screwed in that case) + font_socket_fd = sv[0]; + close(sv[1]); + return; + } #ifndef __HAIKU__ - nice(42); // be nice, letting the main thread get the CPU + nice(42); // be nice, letting the main thread get the CPU #endif - sched_yield(); // try to let the parent run right now - prctl(PR_SET_PDEATHSIG, 9); // get killed if parent exits + sched_yield(); // try to let the parent run right now + prctl(PR_SET_PDEATHSIG, 9); // get killed if parent exits 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]; close(sv[0]); progress_bar_disabled = 1; reliable_read(font_socket_fd, &no_system_fonts, sizeof no_system_fonts); - 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); TTF_Init(); load_user_fonts(screen, NULL, locale); @@ -1049,29 +1064,30 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale) size = 0; i = num_font_families; while (i--) - { - char *s; - s = user_font_families[i]->directory; - if (s) - size += strlen(s); - s = user_font_families[i]->family; - if (s) - size += strlen(s); - s = user_font_families[i]->filename[0]; - if (s) - size += strlen(s); - s = user_font_families[i]->filename[1]; - if (s) - size += strlen(s); - s = user_font_families[i]->filename[2]; - if (s) - size += strlen(s); - s = user_font_families[i]->filename[3]; - if (s) - size += strlen(s); - size += 6; // for '\0' on each of the above - } - size += 2; // for 2-byte font count + { + char *s; + + s = user_font_families[i]->directory; + if (s) + size += strlen(s); + s = user_font_families[i]->family; + if (s) + size += strlen(s); + s = user_font_families[i]->filename[0]; + if (s) + size += strlen(s); + s = user_font_families[i]->filename[1]; + if (s) + size += strlen(s); + s = user_font_families[i]->filename[2]; + if (s) + size += strlen(s); + s = user_font_families[i]->filename[3]; + if (s) + size += strlen(s); + size += 6; // for '\0' on each of the above + } + size += 2; // for 2-byte font count buf = malloc(size); walk = buf; #ifdef DEBUG @@ -1081,64 +1097,64 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale) *walk++ = num_font_families >> 8u; i = num_font_families; while (i--) - { - int len; - char *s; - - s = user_font_families[i]->directory; - if (s) { - len = strlen(s); - memcpy(walk, s, len); - walk += len; - } - *walk++ = '\0'; + int len; + char *s; - s = user_font_families[i]->family; - if (s) - { - len = strlen(s); - memcpy(walk, s, len); - walk += len; - } - *walk++ = '\0'; + s = user_font_families[i]->directory; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; - s = user_font_families[i]->filename[0]; - if (s) - { - len = strlen(s); - memcpy(walk, s, len); - walk += len; - } - *walk++ = '\0'; + s = user_font_families[i]->family; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; - s = user_font_families[i]->filename[1]; - if (s) - { - len = strlen(s); - memcpy(walk, s, len); - walk += len; - } - *walk++ = '\0'; + s = user_font_families[i]->filename[0]; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; - s = user_font_families[i]->filename[2]; - if (s) - { - len = strlen(s); - memcpy(walk, s, len); - walk += len; - } - *walk++ = '\0'; + s = user_font_families[i]->filename[1]; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; - s = user_font_families[i]->filename[3]; - if (s) - { - len = strlen(s); - memcpy(walk, s, len); - walk += len; + s = user_font_families[i]->filename[2]; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; + + s = user_font_families[i]->filename[3]; + if (s) + { + len = strlen(s); + memcpy(walk, s, len); + walk += len; + } + *walk++ = '\0'; } - *walk++ = '\0'; - } reliable_write(font_socket_fd, buf, size); exit(0); } @@ -1158,58 +1174,58 @@ void receive_some_font_info(SDL_Surface * screen) fcntl(font_socket_fd, F_SETFL, O_NONBLOCK); for (;;) - { - if (buf_size <= buf_fill * 9 / 8 + 128) { - buf_size = buf_size * 5 / 4 + 256; + if (buf_size <= buf_fill * 9 / 8 + 128) + { + buf_size = buf_size * 5 / 4 + 256; - // FIXME: Valgrind says this leaks -bjk 2007.07.19 - buf = realloc(buf, buf_size); - } - rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill); + // FIXME: Valgrind says this leaks -bjk 2007.07.19 + buf = realloc(buf, buf_size); + } + rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill); #ifdef DEBUG - printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, (long int) rc); + printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, (long int)rc); #endif - if (rc == -1) - { - switch (errno) - { - default: - return; - case EAGAIN: - ; // satisfy a C syntax abomination - p = (struct pollfd) - { - font_socket_fd, POLLIN, 0}; - show_progress_bar(screen); - poll(&p, 1, 29); // try not to burn CPU time - continue; - case EINTR: - continue; - } + if (rc == -1) + { + switch (errno) + { + default: + return; + case EAGAIN: + ; // satisfy a C syntax abomination + p = (struct pollfd) + { + font_socket_fd, POLLIN, 0}; + show_progress_bar(screen); + poll(&p, 1, 29); // try not to burn CPU time + continue; + case EINTR: + continue; + } + } + buf_fill += rc; + if (!rc || font_thread_aborted) + break; } - buf_fill += rc; - if (!rc || font_thread_aborted) - break; - } close(font_socket_fd); waitpid(font_scanner_pid, &status, 0); if (WIFSIGNALED(status) || font_thread_aborted) - { - printf("child killed by signal %u\n", WTERMSIG(status)); - user_font_families = NULL; - num_font_families = 0; - font_thread_done = 1; + { + printf("child killed by signal %u\n", WTERMSIG(status)); + user_font_families = NULL; + num_font_families = 0; + font_thread_done = 1; - return; - } + return; + } show_progress_bar(screen); walk = buf; - num_font_families = *(unsigned char *) walk++; - num_font_families += *(unsigned char *) walk++ << 8u; + num_font_families = *(unsigned char *)walk++; + num_font_families += *(unsigned char *)walk++ << 8u; #ifdef DEBUG printf("Got %u bytes with %u families.\n", buf_fill, num_font_families); #endif @@ -1220,38 +1236,39 @@ void receive_some_font_info(SDL_Surface * screen) i = num_font_families; while (i--) - { - unsigned len; - user_font_families[i] = fip + i; + { + unsigned len; - len = strlen(walk); - user_font_families[i]->directory = len ? walk : NULL; - walk += len + 1; + user_font_families[i] = fip + i; - len = strlen(walk); - user_font_families[i]->family = len ? walk : NULL; - walk += len + 1; + len = strlen(walk); + user_font_families[i]->directory = len ? walk : NULL; + walk += len + 1; - len = strlen(walk); - user_font_families[i]->filename[0] = len ? walk : NULL; - walk += len + 1; + len = strlen(walk); + user_font_families[i]->family = len ? walk : NULL; + walk += len + 1; - len = strlen(walk); - user_font_families[i]->filename[1] = len ? walk : NULL; - walk += len + 1; + len = strlen(walk); + user_font_families[i]->filename[0] = len ? walk : NULL; + walk += len + 1; - len = strlen(walk); - user_font_families[i]->filename[2] = len ? walk : NULL; - walk += len + 1; + len = strlen(walk); + user_font_families[i]->filename[1] = len ? walk : NULL; + walk += len + 1; - len = strlen(walk); - user_font_families[i]->filename[3] = len ? walk : NULL; - walk += len + 1; + len = strlen(walk); + user_font_families[i]->filename[2] = len ? walk : NULL; + walk += len + 1; - user_font_families[i]->handle = NULL; + len = strlen(walk); + user_font_families[i]->filename[3] = len ? walk : NULL; + walk += len + 1; - // score left uninitialized - } + user_font_families[i]->handle = NULL; + + // score left uninitialized + } font_thread_done = 1; } @@ -1274,47 +1291,47 @@ TuxPaint_Font *getfonthandle(int desire) #endif if (fi == NULL) - { + { #ifdef DEBUG - printf("getfonthandle(%d) points to a NULL family\n", desire); - fflush(stdout); + printf("getfonthandle(%d) points to a NULL family\n", desire); + fflush(stdout); #endif - return NULL; - } + return NULL; + } if (fi->filename != NULL) - { + { #ifdef DEBUG - printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int) text_state, (int) text_state); - fflush(stdout); + printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int)text_state, (int)text_state); + fflush(stdout); #endif - name = fi->filename[text_state]; + name = fi->filename[text_state]; #ifdef DEBUG - printf("Which is: %s\n", name); - fflush(stdout); + printf("Which is: %s\n", name); + fflush(stdout); #endif - } + } else - { -#ifdef DEBUG //EP fixed typo: replaced DBEUG with DEBUG - printf("fi->filename is NULL\n"); - fflush(stdout); + { +#ifdef DEBUG //EP fixed typo: replaced DBEUG with DEBUG + printf("fi->filename is NULL\n"); + fflush(stdout); #endif - name = NULL; - } + name = NULL; + } if (fi->handle) - { + { #ifdef DEBUG - printf("fi->handle was set (0x%x)\n", (int)(intptr_t) fi->handle); //EP added (intptr_t) to avoid warning on x64 + printf("fi->handle was set (0x%x)\n", (int)(intptr_t) fi->handle); //EP added (intptr_t) to avoid warning on x64 - fflush(stdout); + fflush(stdout); #endif - return fi->handle; - } + return fi->handle; + } #ifdef DEBUG printf("fi->handle was not yet set\n"); @@ -1346,28 +1363,28 @@ TuxPaint_Font *getfonthandle(int desire) */ { if (!name) - { - name = fi->filename[text_state ^ TTF_STYLE_ITALIC]; - missing = text_state & TTF_STYLE_ITALIC; - } + { + name = fi->filename[text_state ^ TTF_STYLE_ITALIC]; + missing = text_state & TTF_STYLE_ITALIC; + } if (!name) - { - name = fi->filename[text_state ^ TTF_STYLE_BOLD]; - missing = text_state & TTF_STYLE_BOLD; - } + { + name = fi->filename[text_state ^ TTF_STYLE_BOLD]; + missing = text_state & TTF_STYLE_BOLD; + } if (!name) - { - name = fi->filename[text_state ^ (TTF_STYLE_ITALIC | TTF_STYLE_BOLD)]; - missing = text_state & (TTF_STYLE_ITALIC | TTF_STYLE_BOLD); - } + { + name = fi->filename[text_state ^ (TTF_STYLE_ITALIC | TTF_STYLE_BOLD)]; + missing = text_state & (TTF_STYLE_ITALIC | TTF_STYLE_BOLD); + } if (!name) - { + { #ifdef DEBUG - printf("name is still NULL\n"); - fflush(stdout); + printf("name is still NULL\n"); + fflush(stdout); #endif - return (NULL); - } + return (NULL); + } pathname = alloca(strlen(fi->directory) + 1 + strlen(name) + 1); sprintf(pathname, "%s/%s", fi->directory, name); @@ -1379,32 +1396,32 @@ TuxPaint_Font *getfonthandle(int desire) // if the font doesn't load, we die -- it did load OK before though if (fi->handle == NULL) - { -#ifdef DEBUG - printf("fi->handle is NULL!\n"); - fflush(stdout); -#endif - return (NULL); - } - - if (fi->handle->typ == FONT_TYPE_TTF) - { - if (fi->handle->ttf_font == NULL) { #ifdef DEBUG - printf("fi->handle->ttf_font is NULL!\n"); + printf("fi->handle is NULL!\n"); fflush(stdout); #endif return (NULL); } + if (fi->handle->typ == FONT_TYPE_TTF) + { + if (fi->handle->ttf_font == NULL) + { #ifdef DEBUG - printf("calling TTF_SetFontStyle(0x%x)\n", missing); - fflush(stdout); + printf("fi->handle->ttf_font is NULL!\n"); + fflush(stdout); +#endif + return (NULL); + } + +#ifdef DEBUG + printf("calling TTF_SetFontStyle(0x%x)\n", missing); + fflush(stdout); #endif - TTF_SetFontStyle(fi->handle->ttf_font, missing); - } + TTF_SetFontStyle(fi->handle->ttf_font, missing); + } #ifndef NO_SDLPANGO if (fi->handle->typ == FONT_TYPE_PANGO) @@ -1428,21 +1445,21 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c int i; if (s1 == s2) - { - printf("s1==s2?\n"); - return 0; - } + { + printf("s1==s2?\n"); + return 0; + } if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format || !s2->format) - { - was_bad_font = 1; - return 0; - } + { + was_bad_font = 1; + return 0; + } if (s1->format->BytesPerPixel != s2->format->BytesPerPixel) - { - // something really strange and bad happened - was_bad_font = 1; - return s1->format->BytesPerPixel - s2->format->BytesPerPixel; - } + { + // something really strange and bad happened + was_bad_font = 1; + return s1->format->BytesPerPixel - s2->format->BytesPerPixel; + } if (s1->w != s2->w) @@ -1451,19 +1468,20 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c return s1->h - s2->h; { - const char *const c1 = (char *const) s1->pixels; - const char *const c2 = (char *const) s2->pixels; + const char *const c1 = (char *const)s1->pixels; + const char *const c2 = (char *const)s2->pixels; + width = s1->format->BytesPerPixel * s1->w; if (width == s1->pitch) return memcmp(c1, c2, width * s1->h); cmp = 0; i = s1->h; while (i--) - { - cmp = memcmp(c1 + i * s1->pitch, c2 + i * s2->pitch, width); - if (cmp) - break; - } + { + cmp = memcmp(c1 + i * s1->pitch, c2 + i * s2->pitch, width); + if (cmp) + break; + } } return cmp; @@ -1473,6 +1491,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c static int surfcmp(const void *s1, const void *s2) { int diff = do_surfcmp(s1, s2); + if (!diff) was_bad_font = 1; return diff; @@ -1488,57 +1507,58 @@ int charset_works(TuxPaint_Font * font, const char *s) SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]); unsigned count = 0; int ret = 0; - while (*s) - { - char c[8]; - unsigned offset = 0; - SDL_Surface *tmp_surf = NULL; - do - c[offset++] = *s++; - while ((*s & 0xc0u) == 0x80u); // assume safe input - c[offset++] = '\0'; + while (*s) + { + char c[8]; + unsigned offset = 0; + SDL_Surface *tmp_surf = NULL; + + do + c[offset++] = *s++; + while ((*s & 0xc0u) == 0x80u); // assume safe input + c[offset++] = '\0'; #ifndef NO_SDLPANGO - if (font->typ == FONT_TYPE_PANGO) - { - sdl_color_to_pango_color(black, &pango_color); - SDLPango_SetDefaultColor(font->pango_context, &pango_color); - SDLPango_SetText(font->pango_context, c, -1); - tmp_surf = SDLPango_CreateSurfaceDraw(font->pango_context); - } + if (font->typ == FONT_TYPE_PANGO) + { + sdl_color_to_pango_color(black, &pango_color); + SDLPango_SetDefaultColor(font->pango_context, &pango_color); + SDLPango_SetText(font->pango_context, c, -1); + tmp_surf = SDLPango_CreateSurfaceDraw(font->pango_context); + } #endif /* FIXME: Should the following be in an "#else" block!? -bjk 2009.06.01 */ - if (font->typ == FONT_TYPE_TTF) - { - tmp_surf = TTF_RenderUTF8_Blended(font->ttf_font, c, black); - } + if (font->typ == FONT_TYPE_TTF) + { + tmp_surf = TTF_RenderUTF8_Blended(font->ttf_font, c, black); + } - if (!tmp_surf) - { + if (!tmp_surf) + { #if 0 // THREADED_FONTS - printf("could not render \"%s\" font\n", TTF_FontFaceFamilyName(font)); + printf("could not render \"%s\" font\n", TTF_FontFaceFamilyName(font)); #endif - goto out; + goto out; + } + surfs[count++] = tmp_surf; } - surfs[count++] = tmp_surf; - } was_bad_font = 0; qsort(surfs, count, sizeof surfs[0], surfcmp); ret = !was_bad_font; out: while (count--) - { - if (surfs[count] == NULL) - printf("TRYING TO RE-FREE!"); - else { - SDL_FreeSurface(surfs[count]); - surfs[count] = NULL; + if (surfs[count] == NULL) + printf("TRYING TO RE-FREE!"); + else + { + SDL_FreeSurface(surfs[count]); + surfs[count] = NULL; + } } - } free(surfs); return ret; } @@ -1546,13 +1566,13 @@ out: int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf) { if (tpf == NULL) - { + { #ifdef DEBUG - printf("TuxPaint_Font_FontHeight() received NULL\n"); - fflush(stdout); + printf("TuxPaint_Font_FontHeight() received NULL\n"); + fflush(stdout); #endif - return (1); - } + return (1); + } return (tpf->height); } @@ -1560,22 +1580,22 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf) const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf) { if (tpf == NULL) - { + { #ifdef DEBUG - printf("TuxPaint_Font_FontFaceFamilyName() received NULL\n"); - fflush(stdout); + printf("TuxPaint_Font_FontFaceFamilyName() received NULL\n"); + fflush(stdout); #endif - return (""); - } + return (""); + } #ifndef NO_SDLPANGO if (tpf->typ == FONT_TYPE_PANGO) - { - (void) (tpf); - /* FIXME */ + { + (void)(tpf); + /* FIXME */ - return (""); - } + return (""); + } #endif if (tpf->typ == FONT_TYPE_TTF) @@ -1591,22 +1611,22 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf) const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf) { if (tpf == NULL) - { + { #ifdef DEBUG - printf("TuxPaint_Font_FontFaceStyleName() received NULL\n"); - fflush(stdout); + printf("TuxPaint_Font_FontFaceStyleName() received NULL\n"); + fflush(stdout); #endif - return (""); - } + return (""); + } #ifndef NO_SDLPANGO if (tpf->typ == FONT_TYPE_PANGO) - { - (void) (tpf); - /* FIXME */ + { + (void)(tpf); + /* FIXME */ - return (""); - } + return (""); + } #endif if (tpf->typ == FONT_TYPE_TTF) diff --git a/src/fonts.h b/src/fonts.h index 5228724d7..617601a78 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -63,10 +63,10 @@ #define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0) #define SDL_Thread int #define SDL_mutex int -#define SDL_CreateMutex() 0 // creates in released state +#define SDL_CreateMutex() 0 // creates in released state #define SDL_DestroyMutex(lock) -#define SDL_mutexP(lock) // take lock -#define SDL_mutexV(lock) // release lock +#define SDL_mutexP(lock) // take lock +#define SDL_mutexV(lock) // release lock #endif #endif @@ -91,21 +91,23 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize); /* Stuff that wraps either SDL_Pango or SDL_TTF for font rendering: */ -enum { +enum +{ #ifndef NO_SDLPANGO FONT_TYPE_PANGO, #endif FONT_TYPE_TTF }; -typedef struct TuxPaint_Font_s { +typedef struct TuxPaint_Font_s +{ #ifndef NO_SDLPANGO - SDLPango_Context * pango_context; + SDLPango_Context *pango_context; #endif int typ; - TTF_Font * ttf_font; + TTF_Font *ttf_font; int height; - char * desc; + char *desc; } TuxPaint_Font; int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf); @@ -140,7 +142,7 @@ static int text_sizes[] = { #endif 12, 18, 24, 36, 48, 56, 64, 96, 112, 128, 160 -}; // point sizes +}; // point sizes #define MIN_TEXT_SIZE 0u #define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1) @@ -150,12 +152,12 @@ typedef struct style_info { char *filename; char *directory; - char *family; // name like "FooCorp Thunderstruck" - char *style; // junk like "Oblique Demi-Bold" + char *family; // name like "FooCorp Thunderstruck" + char *style; // junk like "Oblique Demi-Bold" int italic; int boldness; int score; - int truetype; // Is it? (TrueType gets priority) + int truetype; // Is it? (TrueType gets priority) } style_info; // user's notion of a font @@ -183,15 +185,15 @@ TuxPaint_Font *getfonthandle(int desire); int charset_works(TuxPaint_Font * font, const char *s); -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); void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf); -const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf); -const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf); +const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf); +const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf); #ifdef NO_SDLPANGO TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size); #else -void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color); +void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color); #endif int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale);