indent fonts.c fonts.h

This commit is contained in:
Bill Kendrick 2017-10-15 10:53:55 -07:00
parent b37621c2f0
commit 81ff48ccbc
2 changed files with 804 additions and 782 deletions

View file

@ -189,6 +189,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
else else
{ {
char str[128]; char str[128];
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);
@ -238,7 +239,8 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
#ifdef DEBUG #ifdef DEBUG
printf("TuxPaint_Font_CloseFont step 1 (%p)\n", tpf); //EP printf("TuxPaint_Font_CloseFont step 1 (%p)\n", tpf); //EP
#endif #endif
if (!tpf) return; //EP if (!tpf)
return; //EP
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
#ifdef DEBUG #ifdef DEBUG
@ -265,7 +267,8 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
tpf->ttf_font = NULL; tpf->ttf_font = NULL;
} }
if (tpf->desc != NULL) { if (tpf->desc != NULL)
{
free(tpf->desc); free(tpf->desc);
tpf->desc = NULL; tpf->desc = NULL;
} }
@ -277,6 +280,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
{ {
TuxPaint_Font *tpf = NULL; TuxPaint_Font *tpf = NULL;
int i; int i;
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
char desc[1024]; char desc[1024];
#endif #endif
@ -381,9 +385,11 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
void reliable_write(int fd, const void *buf, size_t count) void reliable_write(int fd, const void *buf, size_t count)
{ {
struct pollfd p; struct pollfd p;
do do
{ {
ssize_t rc = write(fd, buf, count); ssize_t rc = write(fd, buf, count);
if (rc == -1) if (rc == -1)
{ {
switch (errno) switch (errno)
@ -412,9 +418,11 @@ void reliable_write(int fd, const void *buf, size_t count)
static void reliable_read(int fd, void *buf, size_t count) static void reliable_read(int fd, void *buf, size_t count)
{ {
struct pollfd p; struct pollfd p;
do do
{ {
ssize_t rc = read(fd, buf, count); ssize_t rc = read(fd, buf, count);
if (rc == -1) if (rc == -1)
{ {
switch (errno) switch (errno)
@ -570,6 +578,7 @@ static void groupfonts_range(style_info ** base, int count)
while (i--) while (i--)
{ {
int b = boldmap[base[i]->boldness]; int b = boldmap[base[i]->boldness];
if (b == -1) if (b == -1)
{ {
#if 0 #if 0
@ -717,6 +726,7 @@ static void parse_font_style(style_info * si)
{ {
size_t len = strlen(si->family); size_t len = strlen(si->family);
char *name = malloc(len + strlen(" Condensed") + 1); char *name = malloc(len + strlen(" Condensed") + 1);
sp += strlen("Condensed"); sp += strlen("Condensed");
memcpy(name, si->family, len); memcpy(name, si->family, len);
strcpy(name + len, " Condensed"); strcpy(name + len, " Condensed");
@ -809,7 +819,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") || !!strcasestr(si->filename, ".otf"); si->truetype = ! !strcasestr(si->filename, ".ttf") || ! !strcasestr(si->filename, ".otf");
} }
@ -818,9 +828,11 @@ static void dupe_markdown_range(family_info ** base, int count)
int bestscore = -999; int bestscore = -999;
int bestslot = 0; int bestslot = 0;
int i = count; int i = count;
while (i--) while (i--)
{ {
int score = base[i]->score; int score = base[i]->score;
if (score <= bestscore) if (score <= bestscore)
continue; continue;
bestscore = score; bestscore = score;
@ -852,6 +864,7 @@ static void groupfonts(void)
for (;;) for (;;)
{ {
int high = low; int high = low;
if (low >= num_font_styles) if (low >= num_font_styles)
break; break;
for (;;) for (;;)
@ -882,6 +895,7 @@ static void groupfonts(void)
for (;;) for (;;)
{ {
int high = low; int high = low;
if (low >= num_font_families) if (low >= num_font_families)
break; break;
for (;;) for (;;)
@ -946,7 +960,7 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
{ {
char *homedirdir; char *homedirdir;
(void) vp; // junk passed by threading library (void)vp; // junk passed by threading library
loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale); loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale);
@ -962,8 +976,9 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); loadfonts(screen, "/usr/X11R6/lib/X11/fonts");
#elif defined(__HAIKU__) #elif defined(__HAIKU__)
dev_t volume = dev_for_path("/boot"); dev_t volume = dev_for_path("/boot");
char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; char buffer[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
status_t result; status_t result;
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, buffer); loadfonts(screen, buffer);
result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
@ -1051,6 +1066,7 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale)
while (i--) while (i--)
{ {
char *s; char *s;
s = user_font_families[i]->directory; s = user_font_families[i]->directory;
if (s) if (s)
size += strlen(s); size += strlen(s);
@ -1168,7 +1184,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, 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 #endif
if (rc == -1) if (rc == -1)
@ -1208,8 +1224,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
@ -1222,6 +1238,7 @@ void receive_some_font_info(SDL_Surface * screen)
while (i--) while (i--)
{ {
unsigned len; unsigned len;
user_font_families[i] = fip + i; user_font_families[i] = fip + i;
len = strlen(walk); len = strlen(walk);
@ -1285,7 +1302,7 @@ 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", (int) text_state, (int) text_state); printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int)text_state, (int)text_state);
fflush(stdout); fflush(stdout);
#endif #endif
@ -1451,8 +1468,9 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c
return s1->h - s2->h; return s1->h - s2->h;
{ {
const char *const c1 = (char *const) s1->pixels; const char *const c1 = (char *const)s1->pixels;
const char *const c2 = (char *const) s2->pixels; const char *const c2 = (char *const)s2->pixels;
width = s1->format->BytesPerPixel * s1->w; width = s1->format->BytesPerPixel * s1->w;
if (width == s1->pitch) if (width == s1->pitch)
return memcmp(c1, c2, width * s1->h); return memcmp(c1, c2, width * s1->h);
@ -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) static int surfcmp(const void *s1, const void *s2)
{ {
int diff = do_surfcmp(s1, s2); int diff = do_surfcmp(s1, s2);
if (!diff) if (!diff)
was_bad_font = 1; was_bad_font = 1;
return diff; return diff;
@ -1488,6 +1507,7 @@ int charset_works(TuxPaint_Font * font, const char *s)
SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]); SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]);
unsigned count = 0; unsigned count = 0;
int ret = 0; int ret = 0;
while (*s) while (*s)
{ {
char c[8]; char c[8];
@ -1571,7 +1591,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
#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 ("");
@ -1602,7 +1622,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
#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 ("");

View file

@ -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: */ /* Stuff that wraps either SDL_Pango or SDL_TTF for font rendering: */
enum { enum
{
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
FONT_TYPE_PANGO, FONT_TYPE_PANGO,
#endif #endif
FONT_TYPE_TTF FONT_TYPE_TTF
}; };
typedef struct TuxPaint_Font_s { typedef struct TuxPaint_Font_s
{
#ifndef NO_SDLPANGO #ifndef NO_SDLPANGO
SDLPango_Context * pango_context; SDLPango_Context *pango_context;
#endif #endif
int typ; int typ;
TTF_Font * ttf_font; TTF_Font *ttf_font;
int height; int height;
char * desc; char *desc;
} TuxPaint_Font; } TuxPaint_Font;
int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf); int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
@ -183,15 +185,15 @@ TuxPaint_Font *getfonthandle(int desire);
int charset_works(TuxPaint_Font * font, const char *s); 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); void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf); const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf); const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
#ifdef NO_SDLPANGO #ifdef NO_SDLPANGO
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size); TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
#else #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 #endif
int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale); int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale);