Ran source code through "indent -nbfda -npcs -npsl -bli0".
This commit is contained in:
parent
51355bce43
commit
7716a05281
38 changed files with 10816 additions and 10710 deletions
|
|
@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/
|
|||
$Id$
|
||||
|
||||
|
||||
2006.August.26 (0.9.16)
|
||||
2006.August.27 (0.9.16)
|
||||
* Interface improvements:
|
||||
-----------------------
|
||||
* Modified "Text" tool so that it correctly handles the 16-bit unicode
|
||||
|
|
@ -143,6 +143,8 @@ $Id$
|
|||
|
||||
* Compiling, porting and packaging updates:
|
||||
-----------------------------------------
|
||||
* Ran source code through "indent -nbfda -npcs -npsl -bli0".
|
||||
|
||||
* "DESTDIR" patch is no longer needed.
|
||||
TOYAMA Shin-ichi <shin1@wmail.plala.or.jp>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,21 +23,21 @@
|
|||
/* Jan. 17, 2003 */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef __BEOS_PRINT_H__
|
||||
#define __BEOS_PRINT_H__
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern "C"
|
||||
{
|
||||
|
||||
extern int SurfacePrint( SDL_Surface *surf );
|
||||
extern int IsPrinterAvailable();
|
||||
#endif /*
*/
|
||||
extern int SurfacePrint(SDL_Surface * surf);
|
||||
extern int IsPrinterAvailable();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*
*/
|
||||
|
||||
#endif
|
||||
#endif /*
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
/* What colors are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
COLOR_BLACK,
|
||||
COLOR_DARKGREY,
|
||||
COLOR_LIGHTGREY,
|
||||
|
|
@ -64,9 +65,9 @@ const int color_hexes[NUM_COLORS][3] = {
|
|||
{255, 128, 0}, /* Orange */
|
||||
{255, 255, 0}, /* Yellow */
|
||||
{160, 228, 128}, /* Light green */
|
||||
{ 33, 148, 70}, /* Dark green */
|
||||
{33, 148, 70}, /* Dark green */
|
||||
{138, 168, 205}, /* Sky blue */
|
||||
{ 50, 100, 255}, /* Blue */
|
||||
{50, 100, 255}, /* Blue */
|
||||
{186, 157, 255}, /* Lavender */
|
||||
{128, 0, 128}, /* Purple */
|
||||
{255, 165, 211}, /* Pink */
|
||||
|
|
@ -78,7 +79,7 @@ const int color_hexes[NUM_COLORS][3] = {
|
|||
|
||||
/* Color names: */
|
||||
|
||||
const char * const color_names[NUM_COLORS] = {
|
||||
const char *const color_names[NUM_COLORS] = {
|
||||
gettext_noop("Black!"),
|
||||
gettext_noop("Dark grey! Some people spell it “dark gray”."),
|
||||
gettext_noop("Light grey! Some people spell it “light gray”."),
|
||||
|
|
|
|||
|
|
@ -150,4 +150,3 @@
|
|||
#undef CLOCK_ASM
|
||||
#define CLOCK_ASM(x) x=42
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@
|
|||
|
||||
#define UNUSED(arg) ((void)(arg))
|
||||
|
||||
SDL_Cursor * cursor_hand, * cursor_arrow, * cursor_watch,
|
||||
* cursor_up, * cursor_down, * cursor_tiny, * cursor_crosshair,
|
||||
* cursor_brush, * cursor_wand, * cursor_insertion, * cursor_rotate;
|
||||
SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
|
||||
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate;
|
||||
|
||||
int no_fancy_cursors;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@
|
|||
#include "arrow.xbm"
|
||||
#include "arrow-mask.xbm"
|
||||
|
||||
extern SDL_Cursor * cursor_hand, * cursor_arrow, * cursor_watch,
|
||||
* cursor_up, * cursor_down, * cursor_tiny, * cursor_crosshair,
|
||||
* cursor_brush, * cursor_wand, * cursor_insertion, * cursor_rotate;
|
||||
extern SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
|
||||
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate;
|
||||
|
||||
extern int no_fancy_cursors;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
#define DEBUG
|
||||
|
||||
//#define DEBUG
|
||||
|
|
|
|||
112
src/dirwalk.c
112
src/dirwalk.c
|
|
@ -25,33 +25,35 @@
|
|||
|
||||
///////////////// directory walking callers and callbacks //////////////////
|
||||
|
||||
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned i)
|
||||
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
|
||||
unsigned dirlen, tp_ftw_str * files, unsigned i)
|
||||
{
|
||||
dirlen = dirlen;
|
||||
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
int loadable = 0;
|
||||
const char *restrict const cp = strchr(files[i].str, '.');
|
||||
show_progress_bar(screen);
|
||||
if(cp)
|
||||
if (cp)
|
||||
{
|
||||
// need gcc 3.4 for the restrict in this location
|
||||
const char * /*restrict*/ const suffixes[] = {"ttc", "dfont", "pfa", "pfb", "otf", "ttf",};
|
||||
const char * /*restrict */ const suffixes[] =
|
||||
{ "ttc", "dfont", "pfa", "pfb", "otf", "ttf", };
|
||||
int j = sizeof suffixes / sizeof suffixes[0];
|
||||
while(j--)
|
||||
while (j--)
|
||||
{
|
||||
// only check part, because of potential .gz or .bz2 suffix
|
||||
if(!strncasecmp(cp+1,suffixes[j],strlen(suffixes[j])))
|
||||
if (!strncasecmp(cp + 1, suffixes[j], strlen(suffixes[j])))
|
||||
{
|
||||
loadable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!loadable)
|
||||
if (!loadable)
|
||||
{
|
||||
if(strcasestr(files[i].str, "/rsrc"))
|
||||
if (strcasestr(files[i].str, "/rsrc"))
|
||||
loadable = 1;
|
||||
}
|
||||
// Loadable: TrueType (.ttf), OpenType (.otf), Type1 (.pfa and .pfb),
|
||||
|
|
@ -65,7 +67,7 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
|
|||
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
|
||||
//printf("Loading font: %s\n", fname);
|
||||
font = TTF_OpenFont(fname, text_sizes[text_size]);
|
||||
if(font)
|
||||
if (font)
|
||||
{
|
||||
const char *restrict const family = TTF_FontFaceFamilyName(font);
|
||||
const char *restrict const style = TTF_FontFaceStyleName(font);
|
||||
|
|
@ -74,7 +76,8 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
|
|||
#ifdef DEBUG
|
||||
int numfaces = TTF_FontFaces(font);
|
||||
if (numfaces != 1)
|
||||
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str, family, style);
|
||||
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str,
|
||||
family, style);
|
||||
#endif
|
||||
|
||||
// First, the blacklist. We list font families that can crash Tux Paint
|
||||
|
|
@ -88,23 +91,19 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
|
|||
// translated. Otherwise, only Line X should be translated and the
|
||||
// ASCII-only fonts should be given bad scores in the scoring code below.
|
||||
// (the best scores going to fonts that support both)
|
||||
if
|
||||
(
|
||||
strcmp("Zapfino",family) && strcmp("Elvish Ring NFI",family)
|
||||
&&
|
||||
(
|
||||
(charset_works(font, gettext("qx")) && charset_works(font, gettext("QX"))) // Line X
|
||||
||
|
||||
(charset_works(font, gettext("qy")) && charset_works(font, gettext("QY"))) // Line Y
|
||||
)
|
||||
)
|
||||
if (strcmp("Zapfino", family) && strcmp("Elvish Ring NFI", family) && ((charset_works(font, gettext("qx")) && charset_works(font, gettext("QX"))) // Line X
|
||||
|| (charset_works(font, gettext("qy")) && charset_works(font, gettext("QY"))) // Line Y
|
||||
))
|
||||
{
|
||||
if (num_font_styles==num_font_styles_max)
|
||||
if (num_font_styles == num_font_styles_max)
|
||||
{
|
||||
num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
|
||||
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles);
|
||||
user_font_styles =
|
||||
realloc(user_font_styles,
|
||||
num_font_styles_max * sizeof *user_font_styles);
|
||||
}
|
||||
user_font_styles[num_font_styles] = malloc(sizeof *user_font_styles[num_font_styles]);
|
||||
user_font_styles[num_font_styles] =
|
||||
malloc(sizeof *user_font_styles[num_font_styles]);
|
||||
user_font_styles[num_font_styles]->directory = strdup(dir);
|
||||
user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below)
|
||||
user_font_styles[num_font_styles]->family = strdup(family);
|
||||
|
|
@ -127,7 +126,8 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
|
|||
{
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
printf("Font is too defective: %s, %s, %s\n", files[i].str, family, style);
|
||||
printf("Font is too defective: %s, %s, %s\n", files[i].str, family,
|
||||
style);
|
||||
#endif
|
||||
}
|
||||
TTF_CloseFont(font);
|
||||
|
|
@ -149,14 +149,16 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
|
|||
// For qsort()
|
||||
int compare_ftw_str(const void *v1, const void *v2)
|
||||
{
|
||||
const char *restrict const s1 = ((tp_ftw_str*)v1)->str;
|
||||
const char *restrict const s2 = ((tp_ftw_str*)v2)->str;
|
||||
const char *restrict const s1 = ((tp_ftw_str *) v1)->str;
|
||||
const char *restrict const s2 = ((tp_ftw_str *) v2)->str;
|
||||
return -strcmp(s1, s2);
|
||||
}
|
||||
|
||||
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int rsrc,
|
||||
void (*fn)(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned count)
|
||||
)
|
||||
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
|
||||
int rsrc, void (*fn) (SDL_Surface * screen,
|
||||
const char *restrict const dir,
|
||||
unsigned dirlen, tp_ftw_str * files,
|
||||
unsigned count))
|
||||
{
|
||||
DIR *d;
|
||||
unsigned num_file_names = 0;
|
||||
|
|
@ -176,23 +178,23 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int
|
|||
if (!d)
|
||||
return;
|
||||
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
struct dirent * f = readdir(d);
|
||||
struct dirent *f = readdir(d);
|
||||
int filetype = TP_FTW_UNKNOWN;
|
||||
|
||||
if(!f)
|
||||
if (!f)
|
||||
break;
|
||||
if(f->d_name[0]=='.')
|
||||
if (f->d_name[0] == '.')
|
||||
continue;
|
||||
// Linux and BSD can often provide file type info w/o the stat() call
|
||||
#ifdef DT_UNKNOWN
|
||||
switch(f->d_type)
|
||||
switch (f->d_type)
|
||||
{
|
||||
default:
|
||||
continue;
|
||||
case DT_REG:
|
||||
if(!rsrc) // if maybe opening resource files, need st_size
|
||||
if (!rsrc) // if maybe opening resource files, need st_size
|
||||
filetype = TP_FTW_NORMAL;
|
||||
break;
|
||||
case DT_DIR:
|
||||
|
|
@ -213,46 +215,46 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int
|
|||
#endif
|
||||
add_rsrc = 0;
|
||||
|
||||
if(filetype == TP_FTW_UNKNOWN)
|
||||
if (filetype == TP_FTW_UNKNOWN)
|
||||
{
|
||||
struct stat sbuf;
|
||||
memcpy(dir+dirlen, f->d_name, d_namlen+1);
|
||||
if(stat(dir, &sbuf))
|
||||
memcpy(dir + dirlen, f->d_name, d_namlen + 1);
|
||||
if (stat(dir, &sbuf))
|
||||
continue; // oh well... try the next one
|
||||
if(S_ISDIR(sbuf.st_mode))
|
||||
if (S_ISDIR(sbuf.st_mode))
|
||||
filetype = TP_FTW_DIRECTORY;
|
||||
else if(S_ISREG(sbuf.st_mode))
|
||||
else if (S_ISREG(sbuf.st_mode))
|
||||
{
|
||||
filetype = TP_FTW_NORMAL;
|
||||
if(rsrc && !sbuf.st_size)
|
||||
if (rsrc && !sbuf.st_size)
|
||||
add_rsrc = 5; // 5 is length of "/rsrc"
|
||||
}
|
||||
else
|
||||
continue; // was a device file or somesuch
|
||||
}
|
||||
if(filetype==TP_FTW_NORMAL)
|
||||
if (filetype == TP_FTW_NORMAL)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
if(num_file_names==max_file_names)
|
||||
if (num_file_names == max_file_names)
|
||||
{
|
||||
max_file_names = max_file_names * 5 / 4 + 30;
|
||||
file_names = realloc(file_names, max_file_names * sizeof *file_names);
|
||||
}
|
||||
cp = malloc(d_namlen + add_rsrc + 1);
|
||||
memcpy(cp, f->d_name, d_namlen);
|
||||
if(add_rsrc)
|
||||
memcpy(cp+d_namlen, "/rsrc", 6);
|
||||
if (add_rsrc)
|
||||
memcpy(cp + d_namlen, "/rsrc", 6);
|
||||
else
|
||||
cp[d_namlen] = '\0';
|
||||
file_names[num_file_names].str = cp;
|
||||
file_names[num_file_names].len = d_namlen;
|
||||
num_file_names++;
|
||||
}
|
||||
if(filetype==TP_FTW_DIRECTORY)
|
||||
if (filetype == TP_FTW_DIRECTORY)
|
||||
{
|
||||
char * cp;
|
||||
if(num_dir_names==max_dir_names)
|
||||
char *cp;
|
||||
if (num_dir_names == max_dir_names)
|
||||
{
|
||||
max_dir_names = max_dir_names * 5 / 4 + 3;
|
||||
dir_names = realloc(dir_names, max_dir_names * sizeof *dir_names);
|
||||
|
|
@ -269,12 +271,12 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int
|
|||
show_progress_bar(screen);
|
||||
dir[dirlen] = '\0'; // repair it (clobbered for stat() call above)
|
||||
|
||||
if(file_names)
|
||||
if (file_names)
|
||||
{
|
||||
// let callee sort and keep the string
|
||||
#if 0
|
||||
qsort(file_names, num_file_names, sizeof *file_names, compare_ftw_str);
|
||||
while(num_file_names--)
|
||||
while (num_file_names--)
|
||||
{
|
||||
free(file_names[num_file_names].str);
|
||||
}
|
||||
|
|
@ -284,16 +286,16 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int
|
|||
#endif
|
||||
}
|
||||
|
||||
if(dir_names)
|
||||
if (dir_names)
|
||||
{
|
||||
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
|
||||
while(num_dir_names--)
|
||||
while (num_dir_names--)
|
||||
{
|
||||
memcpy(dir+dirlen, dir_names[num_dir_names].str, dir_names[num_dir_names].len+1);
|
||||
tp_ftw(screen, dir, dirlen+dir_names[num_dir_names].len, rsrc, fn);
|
||||
memcpy(dir + dirlen, dir_names[num_dir_names].str,
|
||||
dir_names[num_dir_names].len + 1);
|
||||
tp_ftw(screen, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn);
|
||||
free(dir_names[num_dir_names].str);
|
||||
}
|
||||
free(dir_names);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,17 +17,21 @@
|
|||
|
||||
#define TP_FTW_PATHSIZE 400
|
||||
|
||||
typedef struct tp_ftw_str {
|
||||
typedef struct tp_ftw_str
|
||||
{
|
||||
char *str;
|
||||
unsigned char len;
|
||||
// unsigned char is_rsrc;
|
||||
} tp_ftw_str;
|
||||
|
||||
|
||||
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned i);
|
||||
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
|
||||
unsigned dirlen, tp_ftw_str * files, unsigned i);
|
||||
int compare_ftw_str(const void *v1, const void *v2);
|
||||
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int rsrc,
|
||||
void (*fn)(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned count));
|
||||
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
|
||||
int rsrc, void (*fn) (SDL_Surface * screen,
|
||||
const char *restrict const dir,
|
||||
unsigned dirlen, tp_ftw_str * files,
|
||||
unsigned count));
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ static int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
|
|||
#ifdef LOW_QUALITY_FLOOD_FILL
|
||||
return (c1 == c2);
|
||||
#else
|
||||
Uint8 r1, g1, b1,
|
||||
r2, g2, b2;
|
||||
Uint8 r1, g1, b1, r2, g2, b2;
|
||||
|
||||
if (c1 == c2)
|
||||
{
|
||||
|
|
@ -72,7 +71,7 @@ static int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
|
|||
// dark grey, brown, purple
|
||||
// light grey, tan
|
||||
// red, orange
|
||||
return r+g+b < 0.04;
|
||||
return r + g + b < 0.04;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -80,16 +79,18 @@ static int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
|
|||
|
||||
/* Flood fill! */
|
||||
|
||||
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr)
|
||||
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
|
||||
Uint32 cur_colr, Uint32 old_colr)
|
||||
{
|
||||
int fillL, fillR, i, in_line;
|
||||
static unsigned char prog_anim;
|
||||
Uint32 (*getpixel)(SDL_Surface *, int, int) = getpixels[canvas->format->BytesPerPixel];
|
||||
void (*putpixel)(SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel];
|
||||
Uint32(*getpixel) (SDL_Surface *, int, int) =
|
||||
getpixels[canvas->format->BytesPerPixel];
|
||||
void (*putpixel) (SDL_Surface *, int, int, Uint32) =
|
||||
putpixels[canvas->format->BytesPerPixel];
|
||||
|
||||
|
||||
if (cur_colr == old_colr ||
|
||||
colors_close(canvas, cur_colr, old_colr))
|
||||
if (cur_colr == old_colr || colors_close(canvas, cur_colr, old_colr))
|
||||
return;
|
||||
|
||||
|
||||
|
|
@ -113,7 +114,8 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
|
|||
putpixel(canvas, fillL, y, cur_colr);
|
||||
fillL--;
|
||||
|
||||
in_line = (fillL < 0) ? 0 : colors_close(canvas, getpixel(canvas, fillL, y),
|
||||
in_line =
|
||||
(fillL < 0) ? 0 : colors_close(canvas, getpixel(canvas, fillL, y),
|
||||
old_colr);
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +131,8 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
|
|||
fillR++;
|
||||
|
||||
in_line = (fillR >= canvas->w) ? 0 : colors_close(canvas, getpixel(canvas,
|
||||
fillR, y),
|
||||
fillR,
|
||||
y),
|
||||
old_colr);
|
||||
}
|
||||
|
||||
|
|
@ -143,8 +146,8 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
|
|||
if (y > 0 && colors_close(canvas, getpixel(canvas, i, y - 1), old_colr))
|
||||
do_flood_fill(screen, canvas, i, y - 1, cur_colr, old_colr);
|
||||
|
||||
if (y < canvas->h && colors_close(canvas, getpixel(canvas, i, y + 1), old_colr))
|
||||
if (y < canvas->h
|
||||
&& colors_close(canvas, getpixel(canvas, i, y + 1), old_colr))
|
||||
do_flood_fill(screen, canvas, i, y + 1, cur_colr, old_colr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr);
|
||||
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
|
||||
Uint32 cur_colr, Uint32 old_colr);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
397
src/fonts.c
397
src/fonts.c
|
|
@ -58,7 +58,7 @@ volatile long waiting_for_fonts = 0;
|
|||
int font_scanner_pid;
|
||||
int font_socket_fd;
|
||||
|
||||
TTF_Font * medium_font, * small_font, * large_font, * locale_font;
|
||||
TTF_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
|
||||
family_info **user_font_families;
|
||||
int num_font_families = 0;
|
||||
|
|
@ -76,7 +76,7 @@ unsigned text_size = 4; // initial text size
|
|||
TTF_OpenFont() with the filename of a font that doesn't exist. This
|
||||
is an old and well documented bug that is fixed in CVS.
|
||||
*/
|
||||
TTF_Font *BUGFIX_TTF_OpenFont206(const char * const file, int ptsize)
|
||||
TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
|
|
@ -84,7 +84,8 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char * const file, int ptsize)
|
|||
printf("Loading font: %s\n", file);
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(file, "rb")) == NULL) return NULL;
|
||||
if ((fp = fopen(file, "rb")) == NULL)
|
||||
return NULL;
|
||||
fclose(fp);
|
||||
|
||||
#undef TTF_OpenFont
|
||||
|
|
@ -105,15 +106,14 @@ TTF_Font *try_alternate_font(int size)
|
|||
if ((p = strrchr(prefix, '_')) != NULL)
|
||||
{
|
||||
*p = 0;
|
||||
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf",
|
||||
DATA_PREFIX, prefix);
|
||||
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, prefix);
|
||||
|
||||
return TTF_OpenFont(str, size);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TTF_Font *load_locale_font(TTF_Font *fallback, int size)
|
||||
TTF_Font *load_locale_font(TTF_Font * fallback, int size)
|
||||
{
|
||||
TTF_Font *ret = NULL;
|
||||
if (need_own_font)
|
||||
|
|
@ -159,17 +159,19 @@ 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)
|
||||
ssize_t rc = write(fd, buf, count);
|
||||
if (rc == -1)
|
||||
{
|
||||
switch(errno)
|
||||
switch (errno)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case EAGAIN:
|
||||
case ENOSPC:
|
||||
; // satisfy a C syntax abomination
|
||||
p = (struct pollfd){fd, POLLOUT, 0};
|
||||
p = (struct pollfd)
|
||||
{
|
||||
fd, POLLOUT, 0};
|
||||
poll(&p, 1, -1); // try not to burn CPU time
|
||||
// FALL THROUGH
|
||||
case EINTR:
|
||||
|
|
@ -178,7 +180,8 @@ void reliable_write(int fd, const void *buf, size_t count)
|
|||
}
|
||||
buf += rc;
|
||||
count -= rc;
|
||||
} while(count);
|
||||
}
|
||||
while (count);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -187,27 +190,30 @@ void reliable_read(int fd, void *buf, size_t count)
|
|||
struct pollfd p;
|
||||
do
|
||||
{
|
||||
ssize_t rc = read(fd,buf,count);
|
||||
if(rc==-1)
|
||||
ssize_t rc = read(fd, buf, count);
|
||||
if (rc == -1)
|
||||
{
|
||||
switch(errno)
|
||||
switch (errno)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case EAGAIN:
|
||||
; // satisfy a C syntax abomination
|
||||
p = (struct pollfd){fd, POLLIN, 0};
|
||||
p = (struct pollfd)
|
||||
{
|
||||
fd, POLLIN, 0};
|
||||
poll(&p, 1, -1); // try not to burn CPU time
|
||||
// FALL THROUGH
|
||||
case EINTR:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(rc==0)
|
||||
if (rc == 0)
|
||||
break; // EOF. Better not happen before the end!
|
||||
buf += rc;
|
||||
count -= rc;
|
||||
} while(count);
|
||||
}
|
||||
while (count);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -215,12 +221,12 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
{
|
||||
int sv[2];
|
||||
int size, i;
|
||||
char * buf, * walk;
|
||||
char *buf, *walk;
|
||||
|
||||
if(socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
|
||||
exit(42);
|
||||
font_scanner_pid = fork();
|
||||
if(font_scanner_pid)
|
||||
if (font_scanner_pid)
|
||||
{
|
||||
// parent (or error -- but we're screwed in that case)
|
||||
font_socket_fd = sv[0];
|
||||
|
|
@ -241,21 +247,27 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
|
||||
size = 0;
|
||||
i = num_font_families;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
char *s;
|
||||
s = user_font_families[i]->directory;
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
s = user_font_families[i]->family;
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
s = user_font_families[i]->filename[0];
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
s = user_font_families[i]->filename[1];
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
s = user_font_families[i]->filename[2];
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
s = user_font_families[i]->filename[3];
|
||||
if(s) size += strlen(s);
|
||||
if (s)
|
||||
size += strlen(s);
|
||||
size += 6; // for '\0' on each of the above
|
||||
}
|
||||
size += 2; // for 2-byte font count
|
||||
|
|
@ -267,13 +279,13 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = num_font_families & 0xffu;
|
||||
*walk++ = num_font_families >> 8u;
|
||||
i = num_font_families;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
int len;
|
||||
char *s;
|
||||
|
||||
s = user_font_families[i]->directory;
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -282,7 +294,7 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = '\0';
|
||||
|
||||
s = user_font_families[i]->family;
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -291,7 +303,7 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = '\0';
|
||||
|
||||
s = user_font_families[i]->filename[0];
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -300,7 +312,7 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = '\0';
|
||||
|
||||
s = user_font_families[i]->filename[1];
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -309,7 +321,7 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = '\0';
|
||||
|
||||
s = user_font_families[i]->filename[2];
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -318,7 +330,7 @@ void run_font_scanner(SDL_Surface * screen)
|
|||
*walk++ = '\0';
|
||||
|
||||
s = user_font_families[i]->filename[3];
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
len = strlen(s);
|
||||
memcpy(walk, s, len);
|
||||
|
|
@ -344,27 +356,30 @@ void receive_some_font_info(SDL_Surface * screen)
|
|||
family_info *fip;
|
||||
|
||||
fcntl(font_socket_fd, F_SETFL, O_NONBLOCK);
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
if(buf_size <= buf_fill*9/8+128)
|
||||
if (buf_size <= buf_fill * 9 / 8 + 128)
|
||||
{
|
||||
buf_size = buf_size*5/4+256;
|
||||
buf_size = buf_size * 5 / 4 + 256;
|
||||
buf = realloc(buf, buf_size);
|
||||
}
|
||||
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
|
||||
printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, rc);
|
||||
printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd,
|
||||
buf_fill, buf_size, rc);
|
||||
#endif
|
||||
|
||||
if(rc==-1)
|
||||
if (rc == -1)
|
||||
{
|
||||
switch(errno)
|
||||
switch (errno)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case EAGAIN:
|
||||
; // satisfy a C syntax abomination
|
||||
p = (struct pollfd){font_socket_fd, POLLIN, 0};
|
||||
p = (struct pollfd)
|
||||
{
|
||||
font_socket_fd, POLLIN, 0};
|
||||
show_progress_bar(screen);
|
||||
poll(&p, 1, 29); // try not to burn CPU time
|
||||
continue;
|
||||
|
|
@ -373,13 +388,13 @@ printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill,
|
|||
}
|
||||
}
|
||||
buf_fill += rc;
|
||||
if(!rc || font_thread_aborted)
|
||||
if (!rc || font_thread_aborted)
|
||||
break;
|
||||
}
|
||||
close(font_socket_fd);
|
||||
|
||||
waitpid(font_scanner_pid,&status,0);
|
||||
if(WIFSIGNALED(status) || font_thread_aborted)
|
||||
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;
|
||||
|
|
@ -399,10 +414,10 @@ printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill,
|
|||
user_font_families = malloc(num_font_families * sizeof *user_font_families);
|
||||
fip = malloc(num_font_families * sizeof **user_font_families);
|
||||
i = num_font_families;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
unsigned len;
|
||||
user_font_families[i] = fip+i;
|
||||
user_font_families[i] = fip + i;
|
||||
|
||||
len = strlen(walk);
|
||||
user_font_families[i]->directory = len ? walk : NULL;
|
||||
|
|
@ -442,7 +457,7 @@ int load_user_fonts(SDL_Surface * screen, void *vp)
|
|||
{
|
||||
char *homedirdir;
|
||||
|
||||
(void)vp; // junk passed by threading library
|
||||
(void) vp; // junk passed by threading library
|
||||
|
||||
loadfonts(screen, DATA_PREFIX "fonts");
|
||||
|
||||
|
|
@ -504,31 +519,31 @@ int load_user_fonts(SDL_Surface * screen, void *vp)
|
|||
// For qsort() and other use, to see if font files are groupable
|
||||
int compar_fontgroup(const void *v1, const void *v2)
|
||||
{
|
||||
const style_info *s1 = *(style_info**)v1;
|
||||
const style_info *s2 = *(style_info**)v2;
|
||||
const style_info *s1 = *(style_info **) v1;
|
||||
const style_info *s2 = *(style_info **) v2;
|
||||
int rc;
|
||||
|
||||
rc = strcmp(s1->directory,s2->directory);
|
||||
if(rc)
|
||||
rc = strcmp(s1->directory, s2->directory);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = s1->truetype - s2->truetype;
|
||||
if(rc)
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return strcmp(s1->family,s2->family);
|
||||
return strcmp(s1->family, s2->family);
|
||||
}
|
||||
|
||||
|
||||
// For qsort() and other use, to see if font files are duplicates
|
||||
int compar_fontkiller(const void *v1, const void *v2)
|
||||
{
|
||||
const family_info *f1 = *(family_info**)v1;
|
||||
const family_info *f2 = *(family_info**)v2;
|
||||
const family_info *f1 = *(family_info **) v1;
|
||||
const family_info *f2 = *(family_info **) v2;
|
||||
int rc;
|
||||
|
||||
rc = strcmp(f1->family,f2->family);
|
||||
if(rc)
|
||||
rc = strcmp(f1->family, f2->family);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return f1->score - f2->score;
|
||||
|
|
@ -538,8 +553,8 @@ int compar_fontkiller(const void *v1, const void *v2)
|
|||
// For qsort() and other use, to order the worst ones last
|
||||
int compar_fontscore(const void *v1, const void *v2)
|
||||
{
|
||||
const family_info *f1 = *(family_info**)v1;
|
||||
const family_info *f2 = *(family_info**)v2;
|
||||
const family_info *f1 = *(family_info **) v1;
|
||||
const family_info *f2 = *(family_info **) v2;
|
||||
|
||||
return f2->score - f1->score;
|
||||
}
|
||||
|
|
@ -550,7 +565,7 @@ int compar_fontscore(const void *v1, const void *v2)
|
|||
//
|
||||
// Cooper: Light, Medium, Light Bold, Black
|
||||
// HoeflerText: (nil), Black
|
||||
void parse_font_style(style_info *si)
|
||||
void parse_font_style(style_info * si)
|
||||
{
|
||||
int have_light = 0;
|
||||
int have_demi = 0;
|
||||
|
|
@ -565,114 +580,114 @@ void parse_font_style(style_info *si)
|
|||
si->italic = 0;
|
||||
|
||||
|
||||
while(*sp)
|
||||
while (*sp)
|
||||
{
|
||||
if(*sp==' ')
|
||||
if (*sp == ' ')
|
||||
{
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Bold",strlen("Bold")))
|
||||
if (!strncasecmp(sp, "Bold", strlen("Bold")))
|
||||
{
|
||||
sp += strlen("Bold");
|
||||
have_bold = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Regular",strlen("Regular")))
|
||||
if (!strncasecmp(sp, "Regular", strlen("Regular")))
|
||||
{
|
||||
sp += strlen("Regular");
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Italic",strlen("Italic")))
|
||||
if (!strncasecmp(sp, "Italic", strlen("Italic")))
|
||||
{
|
||||
sp += strlen("Italic");
|
||||
si->italic = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Oblique",strlen("Oblique")))
|
||||
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")))
|
||||
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");
|
||||
memcpy(name, si->family, len);
|
||||
strcpy(name + len, " Condensed");
|
||||
free(si->family);
|
||||
si->family = name;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Light",strlen("Light")))
|
||||
if (!strncasecmp(sp, "Light", strlen("Light")))
|
||||
{
|
||||
sp += strlen("Light");
|
||||
have_light = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Medium",strlen("Medium")))
|
||||
if (!strncasecmp(sp, "Medium", strlen("Medium")))
|
||||
{
|
||||
sp += strlen("Medium");
|
||||
have_medium = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Demi",strlen("Demi")))
|
||||
if (!strncasecmp(sp, "Demi", strlen("Demi")))
|
||||
{
|
||||
sp += strlen("Demi");
|
||||
have_demi = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Heavy",strlen("Heavy")))
|
||||
if (!strncasecmp(sp, "Heavy", strlen("Heavy")))
|
||||
{
|
||||
sp += strlen("Heavy");
|
||||
have_heavy = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Normal",strlen("Normal")))
|
||||
if (!strncasecmp(sp, "Normal", strlen("Normal")))
|
||||
{
|
||||
sp += strlen("Normal");
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Black",strlen("Black")))
|
||||
if (!strncasecmp(sp, "Black", strlen("Black")))
|
||||
{
|
||||
sp += strlen("Black");
|
||||
have_black = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Roman",strlen("Roman")))
|
||||
if (!strncasecmp(sp, "Roman", strlen("Roman")))
|
||||
{
|
||||
sp += strlen("Roman");
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Book",strlen("Book")))
|
||||
if (!strncasecmp(sp, "Book", strlen("Book")))
|
||||
{
|
||||
sp += strlen("Book");
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Chancery",strlen("Chancery")))
|
||||
if (!strncasecmp(sp, "Chancery", strlen("Chancery")))
|
||||
{
|
||||
sp += strlen("Chancery");
|
||||
si->italic = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp(sp,"Thin",strlen("Thin")))
|
||||
if (!strncasecmp(sp, "Thin", strlen("Thin")))
|
||||
{
|
||||
sp += strlen("Thin");
|
||||
have_light = 1;
|
||||
continue;
|
||||
}
|
||||
if(!strncmp(sp,"LR",strlen("LR")))
|
||||
if (!strncmp(sp, "LR", strlen("LR")))
|
||||
{
|
||||
sp += strlen("LR");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!stumped)
|
||||
if (!stumped)
|
||||
{
|
||||
stumped=1;
|
||||
stumped = 1;
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
printf("Font style parser stumped by \"%s\".\n", si->style);
|
||||
|
|
@ -692,16 +707,17 @@ 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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void groupfonts_range(style_info **base, int count)
|
||||
void groupfonts_range(style_info ** base, int count)
|
||||
{
|
||||
int boldcounts[4] = {0,0,0,0};
|
||||
int boldmap[4] = {-1,-1,-1,-1};
|
||||
int boldcounts[4] = { 0, 0, 0, 0 };
|
||||
int boldmap[4] = { -1, -1, -1, -1 };
|
||||
int i;
|
||||
int boldmax;
|
||||
int boldmin;
|
||||
|
|
@ -711,19 +727,19 @@ 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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
i = count;
|
||||
while(i--)
|
||||
while (i--)
|
||||
boldcounts[base[i]->boldness]++;
|
||||
|
||||
boldmax = base[0]->boldness;
|
||||
|
|
@ -731,46 +747,47 @@ printf(" %s\n", base[i]->style);
|
|||
bolduse = 0;
|
||||
|
||||
i = 4;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
if(!boldcounts[i])
|
||||
if (!boldcounts[i])
|
||||
continue;
|
||||
if(i>boldmax)
|
||||
if (i > boldmax)
|
||||
boldmax = i;
|
||||
if(i<boldmin)
|
||||
if (i < boldmin)
|
||||
boldmin = i;
|
||||
bolduse++;
|
||||
}
|
||||
if(likely(bolduse<=2))
|
||||
if (likely(bolduse <= 2))
|
||||
{
|
||||
// in case they are same, we want non-bold,
|
||||
// so that setting goes second
|
||||
boldmap[boldmax] = 1;
|
||||
boldmap[boldmin] = 0;
|
||||
}
|
||||
else if(count==3)
|
||||
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;
|
||||
boldmid = boldcounts[boldmin + 1] ? boldmin + 1 : boldmin + 2;
|
||||
|
||||
i = 3;
|
||||
while(i--){
|
||||
if(base[i]->boldness==boldmin)
|
||||
while (i--)
|
||||
{
|
||||
if (base[i]->boldness == boldmin)
|
||||
zmin = base[i]->italic;
|
||||
if(base[i]->boldness==boldmid)
|
||||
if (base[i]->boldness == boldmid)
|
||||
zmid = base[i]->italic;
|
||||
if(base[i]->boldness==boldmax)
|
||||
if (base[i]->boldness == boldmax)
|
||||
zmax = base[i]->italic;
|
||||
}
|
||||
if(zmin!=zmid)
|
||||
if (zmin != zmid)
|
||||
boldmap[boldmid] = 0;
|
||||
else if(zmid!=zmax)
|
||||
else if (zmid != zmax)
|
||||
boldmap[boldmid] = 1;
|
||||
else if(boldmin==0 && boldmid==1)
|
||||
else if (boldmin == 0 && boldmid == 1)
|
||||
{
|
||||
boldmap[0] = -1;
|
||||
boldmap[1] = 0;
|
||||
|
|
@ -791,29 +808,31 @@ printf(" %s\n", base[i]->style);
|
|||
boldmap[1] = 0;
|
||||
|
||||
// classify demi-bold or medium
|
||||
if(claimed_bold<2)
|
||||
if (claimed_bold < 2)
|
||||
{
|
||||
boldmap[2] = 1;
|
||||
claimed_bold += boldcounts[2];
|
||||
}
|
||||
else if(claimed_norm<2)
|
||||
else if (claimed_norm < 2)
|
||||
{
|
||||
boldmap[2] = 0;
|
||||
claimed_norm += boldcounts[2];
|
||||
}
|
||||
|
||||
// classify lightface
|
||||
if(claimed_norm<2)
|
||||
if (claimed_norm < 2)
|
||||
{
|
||||
boldmap[0] = 0;
|
||||
//claimed_norm += boldcounts[0];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families);
|
||||
user_font_families =
|
||||
realloc(user_font_families,
|
||||
num_font_families_max * sizeof *user_font_families);
|
||||
}
|
||||
|
||||
fi = calloc(1, sizeof *fi);
|
||||
|
|
@ -822,70 +841,73 @@ printf(" %s\n", base[i]->style);
|
|||
fi->family = strdup(base[0]->family);
|
||||
fi->score = base[0]->truetype + base[0]->score;
|
||||
i = count;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
int b = boldmap[base[i]->boldness];
|
||||
if(b==-1)
|
||||
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])
|
||||
if (fi->filename[spot])
|
||||
{
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style);
|
||||
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("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1],
|
||||
fi->filename[2], fi->filename[3]);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
fi->filename[spot] = strdup(base[i]->filename);
|
||||
fi->score += 2;
|
||||
}
|
||||
if(!fi->filename[0] && !fi->filename[1])
|
||||
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;
|
||||
}
|
||||
if(!fi->filename[0] && !fi->filename[2])
|
||||
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;
|
||||
}
|
||||
if(!fi->filename[0])
|
||||
if (!fi->filename[0])
|
||||
{
|
||||
fi->filename[0] = strdup(fi->filename[TTF_STYLE_BOLD]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dupe_markdown_range(family_info **base, int count)
|
||||
void dupe_markdown_range(family_info ** base, int count)
|
||||
{
|
||||
int bestscore = -999;
|
||||
int bestslot = 0;
|
||||
int i = count;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
int score = base[i]->score;
|
||||
if(score<=bestscore)
|
||||
if (score <= bestscore)
|
||||
continue;
|
||||
bestscore = score;
|
||||
bestslot = i;
|
||||
}
|
||||
i = count;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
if (i==bestslot)
|
||||
if (i == bestslot)
|
||||
continue;
|
||||
base[i]->score = -999;
|
||||
}
|
||||
|
|
@ -894,35 +916,36 @@ void dupe_markdown_range(family_info **base, int count)
|
|||
|
||||
void groupfonts(void)
|
||||
{
|
||||
char * * cpp;
|
||||
char **cpp;
|
||||
int i = num_font_styles;
|
||||
int low = 0;
|
||||
|
||||
while(i--)
|
||||
while (i--)
|
||||
parse_font_style(user_font_styles[i]);
|
||||
|
||||
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0], compar_fontgroup);
|
||||
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0],
|
||||
compar_fontgroup);
|
||||
//printf("groupfonts() qsort(user_font_styles...)\n");
|
||||
//fflush(stdout);
|
||||
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
int high = low;
|
||||
if(low >= num_font_styles)
|
||||
if (low >= num_font_styles)
|
||||
break;
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
if(++high >= num_font_styles)
|
||||
if (++high >= num_font_styles)
|
||||
break;
|
||||
if(compar_fontgroup(user_font_styles+low, user_font_styles+high))
|
||||
if (compar_fontgroup(user_font_styles + low, user_font_styles + high))
|
||||
break;
|
||||
}
|
||||
groupfonts_range(user_font_styles+low, high-low);
|
||||
groupfonts_range(user_font_styles + low, high - low);
|
||||
low = high;
|
||||
}
|
||||
|
||||
i = num_font_styles;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
free(user_font_styles[i]->filename);
|
||||
free(user_font_styles[i]->directory);
|
||||
|
|
@ -933,47 +956,51 @@ void groupfonts(void)
|
|||
free(user_font_styles);
|
||||
user_font_styles = NULL; // just to catch bugs
|
||||
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller);
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
|
||||
compar_fontkiller);
|
||||
//printf(stderr, "groupfonts() qsort(user_font_families 1...)\n");
|
||||
//fflush(stdout);
|
||||
low = 0;
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
int high = low;
|
||||
if(low >= num_font_families)
|
||||
if (low >= num_font_families)
|
||||
break;
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
if(++high >= num_font_families)
|
||||
if (++high >= num_font_families)
|
||||
break;
|
||||
if(strcmp(user_font_families[low]->family,user_font_families[high]->family))
|
||||
if (strcmp
|
||||
(user_font_families[low]->family, user_font_families[high]->family))
|
||||
break;
|
||||
}
|
||||
dupe_markdown_range(user_font_families+low,high-low);
|
||||
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);
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
|
||||
compar_fontscore);
|
||||
//printf("groupfonts() qsort(user_font_families 2...)\n");
|
||||
//fflush(stdout);
|
||||
if(user_font_families[0]->score < 0)
|
||||
if (user_font_families[0]->score < 0)
|
||||
printf("sorted the wrong way, or all fonts were unusable\n");
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
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)
|
||||
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])
|
||||
if (cpp[0])
|
||||
free(cpp[0]);
|
||||
if(cpp[1])
|
||||
if (cpp[1])
|
||||
free(cpp[1]);
|
||||
if(cpp[2])
|
||||
if (cpp[2])
|
||||
free(cpp[2]);
|
||||
if(cpp[3])
|
||||
if (cpp[3])
|
||||
free(cpp[3]);
|
||||
free(user_font_families[i]);
|
||||
user_font_families[i] = NULL;
|
||||
|
|
@ -992,40 +1019,40 @@ TTF_Font *getfonthandle(int desire)
|
|||
char *name = fi->filename[text_state];
|
||||
char *pathname;
|
||||
|
||||
if(fi->handle)
|
||||
if (fi->handle)
|
||||
return fi->handle;
|
||||
|
||||
if(!name)
|
||||
if (!name)
|
||||
{
|
||||
name = fi->filename[text_state ^ TTF_STYLE_ITALIC];
|
||||
missing = text_state & TTF_STYLE_ITALIC;
|
||||
}
|
||||
if(!name)
|
||||
if (!name)
|
||||
{
|
||||
name = fi->filename[text_state ^ TTF_STYLE_BOLD];
|
||||
missing = text_state & TTF_STYLE_BOLD;
|
||||
}
|
||||
if(!name)
|
||||
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);
|
||||
}
|
||||
pathname = alloca(strlen(fi->directory) + 1 + strlen(name) + 1);
|
||||
sprintf(pathname, "%s/%s", fi->directory, name);
|
||||
|
||||
fi->handle = TTF_OpenFont(pathname,text_sizes[text_size]);
|
||||
fi->handle = TTF_OpenFont(pathname, text_sizes[text_size]);
|
||||
// if the font doesn't load, we die -- it did load OK before though
|
||||
TTF_SetFontStyle(fi->handle,missing);
|
||||
TTF_SetFontStyle(fi->handle, missing);
|
||||
return fi->handle;
|
||||
}
|
||||
|
||||
|
||||
void loadfonts(SDL_Surface * screen, const char * const dir)
|
||||
void loadfonts(SDL_Surface * screen, const char *const dir)
|
||||
{
|
||||
char buf[TP_FTW_PATHSIZE];
|
||||
unsigned dirlen = strlen(dir);
|
||||
|
||||
memcpy(buf,dir,dirlen);
|
||||
memcpy(buf, dir, dirlen);
|
||||
tp_ftw(screen, buf, dirlen, 1, loadfont_callback);
|
||||
}
|
||||
|
||||
|
|
@ -1034,7 +1061,8 @@ void loadfonts(SDL_Surface * screen, const char * const dir)
|
|||
int was_bad_font;
|
||||
|
||||
// see if two font surfaces are the same
|
||||
int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *const v2)
|
||||
int do_surfcmp(const SDL_Surface * const *const v1,
|
||||
const SDL_Surface * const *const v2)
|
||||
{
|
||||
const SDL_Surface *const s1 = *v1;
|
||||
const SDL_Surface *const s2 = *v2;
|
||||
|
|
@ -1042,17 +1070,18 @@ int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *con
|
|||
int cmp;
|
||||
int i;
|
||||
|
||||
if(s1==s2)
|
||||
if (s1 == s2)
|
||||
{
|
||||
printf("s1==s2?\n");
|
||||
return 0;
|
||||
}
|
||||
if(!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format || !s2->format)
|
||||
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format
|
||||
|| !s2->format)
|
||||
{
|
||||
was_bad_font = 1;
|
||||
return 0;
|
||||
}
|
||||
if(s1->format->BytesPerPixel != s2->format->BytesPerPixel)
|
||||
if (s1->format->BytesPerPixel != s2->format->BytesPerPixel)
|
||||
{
|
||||
// something really strange and bad happened
|
||||
was_bad_font = 1;
|
||||
|
|
@ -1060,23 +1089,23 @@ int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *con
|
|||
}
|
||||
|
||||
|
||||
if(s1->w != s2->w)
|
||||
if (s1->w != s2->w)
|
||||
return s1->w - s2->w;
|
||||
if(s1->h != s2->h)
|
||||
if (s1->h != s2->h)
|
||||
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);
|
||||
if (width == s1->pitch)
|
||||
return memcmp(c1, c2, width * s1->h);
|
||||
cmp = 0;
|
||||
i = s1->h;
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
cmp = memcmp(c1 + i*s1->pitch, c2 + i*s2->pitch, width);
|
||||
if(cmp)
|
||||
cmp = memcmp(c1 + i * s1->pitch, c2 + i * s2->pitch, width);
|
||||
if (cmp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1088,29 +1117,29 @@ int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *con
|
|||
int surfcmp(const void *s1, const void *s2)
|
||||
{
|
||||
int diff = do_surfcmp(s1, s2);
|
||||
if(!diff)
|
||||
if (!diff)
|
||||
was_bad_font = 1;
|
||||
return diff;
|
||||
}
|
||||
|
||||
// check if the characters will render distinctly
|
||||
int charset_works(TTF_Font *font, const char *s)
|
||||
int charset_works(TTF_Font * font, const char *s)
|
||||
{
|
||||
SDL_Color black = {0, 0, 0, 0};
|
||||
SDL_Color black = { 0, 0, 0, 0 };
|
||||
SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]);
|
||||
unsigned count = 0;
|
||||
int ret = 0;
|
||||
while(*s)
|
||||
while (*s)
|
||||
{
|
||||
char c[8];
|
||||
unsigned offset = 0;
|
||||
SDL_Surface *tmp_surf;
|
||||
do
|
||||
c[offset++] = *s++;
|
||||
while((*s & 0xc0u) == 0x80u); // assume safe input
|
||||
while ((*s & 0xc0u) == 0x80u); // assume safe input
|
||||
c[offset++] = '\0';
|
||||
tmp_surf = TTF_RenderUTF8_Blended(font, c, black);
|
||||
if(!tmp_surf)
|
||||
if (!tmp_surf)
|
||||
{
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
|
|
@ -1124,7 +1153,7 @@ int charset_works(TTF_Font *font, const char *s)
|
|||
qsort(surfs, count, sizeof surfs[0], surfcmp);
|
||||
ret = !was_bad_font;
|
||||
out:
|
||||
while(count--)
|
||||
while (count--)
|
||||
{
|
||||
if (surfs[count] == NULL)
|
||||
printf("TRYING TO RE-FREE!");
|
||||
|
|
|
|||
33
src/fonts.h
33
src/fonts.h
|
|
@ -48,11 +48,11 @@ extern int no_system_fonts;
|
|||
extern int was_bad_font;
|
||||
|
||||
|
||||
TTF_Font *BUGFIX_TTF_OpenFont206(const char * const file, int ptsize);
|
||||
TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
|
||||
#define TTF_OpenFont BUGFIX_TTF_OpenFont206
|
||||
|
||||
TTF_Font *try_alternate_font(int size);
|
||||
TTF_Font *load_locale_font(TTF_Font *fallback, int size);
|
||||
TTF_Font *load_locale_font(TTF_Font * fallback, int size);
|
||||
int load_user_fonts(SDL_Surface * screen, void *vp);
|
||||
|
||||
#ifdef FORKED_FONTS
|
||||
|
|
@ -78,13 +78,16 @@ extern unsigned text_size;
|
|||
// nice progression (alternating 33% and 25%) 9 12 18 24 36 48 72 96 144 192
|
||||
// commonly hinted sizes seem to be: 9, 10, 12, 14, 18, 20 (less so), 24
|
||||
// reasonable: 9,12,18... and 10,14,18...
|
||||
static int text_sizes[] = {9, 12, 18, 24, 36, 48,
|
||||
56, 64, 96, 112, 128, 160}; // point sizes
|
||||
static int text_sizes[] = { 9, 12, 18, 24, 36, 48,
|
||||
56, 64, 96, 112, 128, 160
|
||||
}; // point sizes
|
||||
|
||||
#define MIN_TEXT_SIZE 0u
|
||||
#define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1)
|
||||
|
||||
// for sorting through the font files at startup
|
||||
typedef struct style_info {
|
||||
typedef struct style_info
|
||||
{
|
||||
char *filename;
|
||||
char *directory;
|
||||
char *family; // name like "FooCorp Thunderstruck"
|
||||
|
|
@ -96,7 +99,8 @@ typedef struct style_info {
|
|||
} style_info;
|
||||
|
||||
// user's notion of a font
|
||||
typedef struct family_info {
|
||||
typedef struct family_info
|
||||
{
|
||||
char *directory;
|
||||
char *family;
|
||||
char *filename[4];
|
||||
|
|
@ -104,7 +108,7 @@ typedef struct family_info {
|
|||
int score;
|
||||
} family_info;
|
||||
|
||||
extern TTF_Font * medium_font, * small_font, * large_font, * locale_font;
|
||||
extern TTF_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
|
||||
extern family_info **user_font_families;
|
||||
extern int num_font_families;
|
||||
|
|
@ -118,17 +122,16 @@ extern int num_font_styles_max;
|
|||
int compar_fontgroup(const void *v1, const void *v2);
|
||||
int compar_fontkiller(const void *v1, const void *v2);
|
||||
int compar_fontscore(const void *v1, const void *v2);
|
||||
void parse_font_style(style_info *si);
|
||||
void groupfonts_range(style_info **base, int count);
|
||||
void dupe_markdown_range(family_info **base, int count);
|
||||
void parse_font_style(style_info * si);
|
||||
void groupfonts_range(style_info ** base, int count);
|
||||
void dupe_markdown_range(family_info ** base, int count);
|
||||
void groupfonts(void);
|
||||
TTF_Font *getfonthandle(int desire);
|
||||
void loadfonts(SDL_Surface * screen, const char * const dir);
|
||||
void loadfonts(SDL_Surface * screen, const char *const dir);
|
||||
|
||||
int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *const v2);
|
||||
int do_surfcmp(const SDL_Surface * const *const v1,
|
||||
const SDL_Surface * const *const v2);
|
||||
int surfcmp(const void *s1, const void *s2);
|
||||
int charset_works(TTF_Font *font, const char *s);
|
||||
int charset_works(TTF_Font * font, const char *s);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
#include "get_fname.h"
|
||||
#include "debug.h"
|
||||
|
||||
char * savedir;
|
||||
char *savedir;
|
||||
|
||||
|
||||
/* The filename for the current image: */
|
||||
|
||||
char * get_fname(const char * const name)
|
||||
char *get_fname(const char *const name)
|
||||
{
|
||||
char f[512];
|
||||
const char * tux_settings_dir;
|
||||
const char *tux_settings_dir;
|
||||
|
||||
|
||||
/* Where is the user's data directory?
|
||||
|
|
@ -96,4 +96,3 @@ char * get_fname(const char * const name)
|
|||
|
||||
return strdup(f);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#ifndef GET_FNAME_H
|
||||
#define GET_FNAME_H
|
||||
|
||||
extern char * savedir;
|
||||
extern char *savedir;
|
||||
|
||||
char * get_fname(const char * const name);
|
||||
char *get_fname(const char *const name);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#define GREAT_H
|
||||
|
||||
|
||||
const char * const great_strs[] = {
|
||||
const char *const great_strs[] = {
|
||||
gettext_noop("Great!"),
|
||||
gettext_noop("Cool!"),
|
||||
gettext_noop("Keep it up!"),
|
||||
|
|
|
|||
264
src/i18n.c
264
src/i18n.c
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
/* Globals: */
|
||||
|
||||
const char * lang_prefixes[NUM_LANGS] = {
|
||||
const char *lang_prefixes[NUM_LANGS] = {
|
||||
"af",
|
||||
"ar",
|
||||
"be",
|
||||
|
|
@ -132,117 +132,117 @@ int lang_use_right_to_left[] = {
|
|||
};
|
||||
|
||||
|
||||
char * langstr;
|
||||
char *langstr;
|
||||
int need_own_font;
|
||||
int need_right_to_left;
|
||||
const char * lang_prefix;
|
||||
const char *lang_prefix;
|
||||
|
||||
const language_to_locale_struct language_to_locale_array[] = {
|
||||
{"english", "C"},
|
||||
{"american-english", "C"},
|
||||
{"arabic", "ar_SA.UTF-8"},
|
||||
{"croatian", "hr_HR.UTF-8"},
|
||||
{"hrvatski", "hr_HR.UTF-8"},
|
||||
{"catalan", "ca_ES.UTF-8"},
|
||||
{"catala", "ca_ES.UTF-8"},
|
||||
{"belarusian", "be_BY.UTF-8"},
|
||||
{"bielaruskaja", "be_BY.UTF-8"},
|
||||
{"czech", "cs_CZ.UTF-8"},
|
||||
{"cesky", "cs_CZ.UTF-8"},
|
||||
{"danish", "da_DK.UTF-8"},
|
||||
{"dansk", "da_DK.UTF-8"},
|
||||
{"german", "de_DE.UTF-8"},
|
||||
{"deutsch", "de_DE.UTF-8"},
|
||||
{"estonian", "et_EE.UTF-8"},
|
||||
{"greek", "el_GR.UTF-8"},
|
||||
{"gronings", "gos_NL.UTF-8"},
|
||||
{"zudelk-veenkelonioals","gos_NL.UTF-8"},
|
||||
{"gujarati", "gu_IN.UTF-8"},
|
||||
{"british-english", "en_GB.UTF-8"},
|
||||
{"british", "en_GB.UTF-8"},
|
||||
{"spanish", "es_ES.UTF-8"},
|
||||
{"mexican", "es_MX.UTF-8"},
|
||||
{"mexican-spanish", "es_MX.UTF-8"},
|
||||
{"espanol-mejicano", "es_MX.UTF-8"},
|
||||
{"espanol", "es_ES.UTF-8"},
|
||||
{"finnish", "fi_FI.UTF-8"},
|
||||
{"suomi", "fi_FI.UTF-8"},
|
||||
{"faroese", "fo_FO.UTF-8"},
|
||||
{"french", "fr_FR.UTF-8"},
|
||||
{"francais", "fr_FR.UTF-8"},
|
||||
{"gaelic", "ga_IE.UTF-8"},
|
||||
{"irish-gaelic", "ga_IE.UTF-8"},
|
||||
{"gaidhlig", "ga_IE.UTF-8"},
|
||||
{"scottish", "gd_GB.UTF-8"},
|
||||
{"ghaidhlig", "gd_GB.UTF-8"},
|
||||
{"scottish-gaelic", "gd_GB.UTF-8"},
|
||||
{"galician", "gl_ES.UTF-8"},
|
||||
{"galego", "gl_ES.UTF-8"},
|
||||
{"hebrew", "he_IL.UTF-8"},
|
||||
{"hindi", "hi_IN.UTF-8"},
|
||||
{"hungarian", "hu_HU.UTF-8"},
|
||||
{"magyar", "hu_HU.UTF-8"},
|
||||
{"indonesian", "id_ID.UTF-8"},
|
||||
{"bahasa-indonesia", "id_ID.UTF-8"},
|
||||
{"icelandic", "is_IS.UTF-8"},
|
||||
{"islenska", "is_IS.UTF-8"},
|
||||
{"italian", "it_IT.UTF-8"},
|
||||
{"italiano", "it_IT.UTF-8"},
|
||||
{"japanese", "ja_JP.UTF-8"},
|
||||
{"vietnamese", "vi_VN.UTF-8"},
|
||||
{"afrikaans", "af_ZA.UTF-8"},
|
||||
{"albanian", "sq_AL.UTF-8"},
|
||||
{"breton", "br_FR.UTF-8"},
|
||||
{"brezhoneg", "br_FR.UTF-8"},
|
||||
{"bulgarian", "bg_BG.UTF-8"},
|
||||
{"welsh", "cy_GB.UTF-8"},
|
||||
{"cymraeg", "cy_GB.UTF-8"},
|
||||
{"bokmal", "nb_NO.UTF-8"},
|
||||
{"basque", "eu_ES.UTF-8"},
|
||||
{"euskara", "eu_ES.UTF-8"},
|
||||
{"georgian", "ka_GE"},
|
||||
{"kinyarwanda", "rw_RW.UTF-8"},
|
||||
{"klingon", "tlh.UTF-8"},
|
||||
{"tlhIngan", "tlh.UTF-8"},
|
||||
{"tlhingan", "tlh.UTF-8"},
|
||||
{"korean", "ko_KR.UTF-8"},
|
||||
{"kurdish", "ku_TR.UTF-8"},
|
||||
{"tamil", "ta_IN.UTF-8"},
|
||||
{"lithuanian", "lt_LT.UTF-8"},
|
||||
{"lietuviu", "lt_LT.UTF-8"},
|
||||
{"malay", "ms_MY.UTF-8"},
|
||||
{"dutch", "nl_NL.UTF-8"},
|
||||
{"nederlands", "nl_NL.UTF-8"},
|
||||
{"norwegian", "nn_NO.UTF-8"},
|
||||
{"nynorsk", "nn_NO.UTF-8"},
|
||||
{"norsk", "nn_NO.UTF-8"},
|
||||
{"polish", "pl_PL.UTF-8"},
|
||||
{"polski", "pl_PL.UTF-8"},
|
||||
{"brazilian-portuguese", "pt_BR.UTF-8"},
|
||||
{"portugues-brazilian", "pt_BR.UTF-8"},
|
||||
{"brazilian", "pt_BR.UTF-8"},
|
||||
{"portuguese", "pt_PT.UTF-8"},
|
||||
{"portugues", "pt_PT.UTF-8"},
|
||||
{"romanian", "ro_RO.UTF-8"},
|
||||
{"russian", "ru_RU.UTF-8"},
|
||||
{"russkiy", "ru_RU.UTF-8"},
|
||||
{"slovak", "sk_SK.UTF-8"},
|
||||
{"slovenian", "sl_SI.UTF-8"},
|
||||
{"slovensko", "sl_SI.UTF-8"},
|
||||
{"serbian", "sr_YU.UTF-8"},
|
||||
{"swedish", "sv_SE.UTF-8"},
|
||||
{"svenska", "sv_SE.UTF-8"},
|
||||
{"swahili", "sw_TZ.UTF-8"},
|
||||
{"tagalog", "tl_PH.UTF-8"},
|
||||
{"thai", "th_TH.UTF-8"},
|
||||
{"tibetan", "bo_CN.UTF-8"}, /* Based on: http://texinfo.org/pipermail/texinfo-pretest/2005-April/000334.html */
|
||||
{"turkish", "tr_TR.UTF-8"},
|
||||
{"ukrainian", "uk_UA.UTF-8"},
|
||||
{"walloon", "wa_BE.UTF-8"},
|
||||
{"walon", "wa_BE.UTF-8"},
|
||||
{"chinese", "zh_CN.UTF-8"},
|
||||
{"simplified-chinese", "zh_CN.UTF-8"},
|
||||
{"traditional-chinese", "zh_TW.UTF-8"},
|
||||
{"english", "C"},
|
||||
{"american-english", "C"},
|
||||
{"arabic", "ar_SA.UTF-8"},
|
||||
{"croatian", "hr_HR.UTF-8"},
|
||||
{"hrvatski", "hr_HR.UTF-8"},
|
||||
{"catalan", "ca_ES.UTF-8"},
|
||||
{"catala", "ca_ES.UTF-8"},
|
||||
{"belarusian", "be_BY.UTF-8"},
|
||||
{"bielaruskaja", "be_BY.UTF-8"},
|
||||
{"czech", "cs_CZ.UTF-8"},
|
||||
{"cesky", "cs_CZ.UTF-8"},
|
||||
{"danish", "da_DK.UTF-8"},
|
||||
{"dansk", "da_DK.UTF-8"},
|
||||
{"german", "de_DE.UTF-8"},
|
||||
{"deutsch", "de_DE.UTF-8"},
|
||||
{"estonian", "et_EE.UTF-8"},
|
||||
{"greek", "el_GR.UTF-8"},
|
||||
{"gronings", "gos_NL.UTF-8"},
|
||||
{"zudelk-veenkelonioals", "gos_NL.UTF-8"},
|
||||
{"gujarati", "gu_IN.UTF-8"},
|
||||
{"british-english", "en_GB.UTF-8"},
|
||||
{"british", "en_GB.UTF-8"},
|
||||
{"spanish", "es_ES.UTF-8"},
|
||||
{"mexican", "es_MX.UTF-8"},
|
||||
{"mexican-spanish", "es_MX.UTF-8"},
|
||||
{"espanol-mejicano", "es_MX.UTF-8"},
|
||||
{"espanol", "es_ES.UTF-8"},
|
||||
{"finnish", "fi_FI.UTF-8"},
|
||||
{"suomi", "fi_FI.UTF-8"},
|
||||
{"faroese", "fo_FO.UTF-8"},
|
||||
{"french", "fr_FR.UTF-8"},
|
||||
{"francais", "fr_FR.UTF-8"},
|
||||
{"gaelic", "ga_IE.UTF-8"},
|
||||
{"irish-gaelic", "ga_IE.UTF-8"},
|
||||
{"gaidhlig", "ga_IE.UTF-8"},
|
||||
{"scottish", "gd_GB.UTF-8"},
|
||||
{"ghaidhlig", "gd_GB.UTF-8"},
|
||||
{"scottish-gaelic", "gd_GB.UTF-8"},
|
||||
{"galician", "gl_ES.UTF-8"},
|
||||
{"galego", "gl_ES.UTF-8"},
|
||||
{"hebrew", "he_IL.UTF-8"},
|
||||
{"hindi", "hi_IN.UTF-8"},
|
||||
{"hungarian", "hu_HU.UTF-8"},
|
||||
{"magyar", "hu_HU.UTF-8"},
|
||||
{"indonesian", "id_ID.UTF-8"},
|
||||
{"bahasa-indonesia", "id_ID.UTF-8"},
|
||||
{"icelandic", "is_IS.UTF-8"},
|
||||
{"islenska", "is_IS.UTF-8"},
|
||||
{"italian", "it_IT.UTF-8"},
|
||||
{"italiano", "it_IT.UTF-8"},
|
||||
{"japanese", "ja_JP.UTF-8"},
|
||||
{"vietnamese", "vi_VN.UTF-8"},
|
||||
{"afrikaans", "af_ZA.UTF-8"},
|
||||
{"albanian", "sq_AL.UTF-8"},
|
||||
{"breton", "br_FR.UTF-8"},
|
||||
{"brezhoneg", "br_FR.UTF-8"},
|
||||
{"bulgarian", "bg_BG.UTF-8"},
|
||||
{"welsh", "cy_GB.UTF-8"},
|
||||
{"cymraeg", "cy_GB.UTF-8"},
|
||||
{"bokmal", "nb_NO.UTF-8"},
|
||||
{"basque", "eu_ES.UTF-8"},
|
||||
{"euskara", "eu_ES.UTF-8"},
|
||||
{"georgian", "ka_GE"},
|
||||
{"kinyarwanda", "rw_RW.UTF-8"},
|
||||
{"klingon", "tlh.UTF-8"},
|
||||
{"tlhIngan", "tlh.UTF-8"},
|
||||
{"tlhingan", "tlh.UTF-8"},
|
||||
{"korean", "ko_KR.UTF-8"},
|
||||
{"kurdish", "ku_TR.UTF-8"},
|
||||
{"tamil", "ta_IN.UTF-8"},
|
||||
{"lithuanian", "lt_LT.UTF-8"},
|
||||
{"lietuviu", "lt_LT.UTF-8"},
|
||||
{"malay", "ms_MY.UTF-8"},
|
||||
{"dutch", "nl_NL.UTF-8"},
|
||||
{"nederlands", "nl_NL.UTF-8"},
|
||||
{"norwegian", "nn_NO.UTF-8"},
|
||||
{"nynorsk", "nn_NO.UTF-8"},
|
||||
{"norsk", "nn_NO.UTF-8"},
|
||||
{"polish", "pl_PL.UTF-8"},
|
||||
{"polski", "pl_PL.UTF-8"},
|
||||
{"brazilian-portuguese", "pt_BR.UTF-8"},
|
||||
{"portugues-brazilian", "pt_BR.UTF-8"},
|
||||
{"brazilian", "pt_BR.UTF-8"},
|
||||
{"portuguese", "pt_PT.UTF-8"},
|
||||
{"portugues", "pt_PT.UTF-8"},
|
||||
{"romanian", "ro_RO.UTF-8"},
|
||||
{"russian", "ru_RU.UTF-8"},
|
||||
{"russkiy", "ru_RU.UTF-8"},
|
||||
{"slovak", "sk_SK.UTF-8"},
|
||||
{"slovenian", "sl_SI.UTF-8"},
|
||||
{"slovensko", "sl_SI.UTF-8"},
|
||||
{"serbian", "sr_YU.UTF-8"},
|
||||
{"swedish", "sv_SE.UTF-8"},
|
||||
{"svenska", "sv_SE.UTF-8"},
|
||||
{"swahili", "sw_TZ.UTF-8"},
|
||||
{"tagalog", "tl_PH.UTF-8"},
|
||||
{"thai", "th_TH.UTF-8"},
|
||||
{"tibetan", "bo_CN.UTF-8"}, /* Based on: http://texinfo.org/pipermail/texinfo-pretest/2005-April/000334.html */
|
||||
{"turkish", "tr_TR.UTF-8"},
|
||||
{"ukrainian", "uk_UA.UTF-8"},
|
||||
{"walloon", "wa_BE.UTF-8"},
|
||||
{"walon", "wa_BE.UTF-8"},
|
||||
{"chinese", "zh_CN.UTF-8"},
|
||||
{"simplified-chinese", "zh_CN.UTF-8"},
|
||||
{"traditional-chinese", "zh_TW.UTF-8"},
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ void set_langstr(const char *s)
|
|||
|
||||
void set_current_language(void)
|
||||
{
|
||||
char * loc;
|
||||
char *loc;
|
||||
int lang, i, found;
|
||||
|
||||
bindtextdomain("tuxpaint", LOCALEDIR);
|
||||
|
|
@ -302,7 +302,7 @@ void set_current_language(void)
|
|||
{
|
||||
char *s;
|
||||
int len;
|
||||
len = strlen("LANGUAGE=")+strlen(loc)+1;
|
||||
len = strlen("LANGUAGE=") + strlen(loc) + 1;
|
||||
s = malloc(len);
|
||||
snprintf(s, len, "LANGUAGE=%s", loc);
|
||||
putenv(s);
|
||||
|
|
@ -330,11 +330,11 @@ void set_current_language(void)
|
|||
}
|
||||
|
||||
lang_prefix = lang_prefixes[lang];
|
||||
need_own_font = search_int_array(lang,lang_use_own_font);
|
||||
need_right_to_left = search_int_array(lang,lang_use_right_to_left);
|
||||
need_own_font = search_int_array(lang, lang_use_own_font);
|
||||
need_right_to_left = search_int_array(lang, lang_use_right_to_left);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"DEBUG: Language is %s (%d)\n", lang_prefix, lang);
|
||||
fprintf(stderr, "DEBUG: Language is %s (%d)\n", lang_prefix, lang);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
|
|
@ -343,13 +343,11 @@ void set_current_language(void)
|
|||
|
||||
/* FIXME: All this should REALLY be array-based!!! */
|
||||
/* Show available languages: */
|
||||
void show_lang_usage(FILE * f, const char * const prg)
|
||||
void show_lang_usage(FILE * f, const char *const prg)
|
||||
{
|
||||
fprintf(f,
|
||||
"\n"
|
||||
"Usage: %s [--lang LANGUAGE]\n"
|
||||
"\n"
|
||||
"LANGUAGE may be one of:\n"
|
||||
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
|
||||
/* C */ " english american-english\n"
|
||||
/* af */ " afrikaans\n"
|
||||
/* sq */ " albanian\n"
|
||||
|
|
@ -357,7 +355,8 @@ void show_lang_usage(FILE * f, const char * const prg)
|
|||
/* eu */ " basque euskara\n"
|
||||
/* be */ " belarusian bielaruskaja\n"
|
||||
/* nb */ " bokmal\n"
|
||||
/* pt_BR */ " brazilian brazilian-portuguese portugues-brazilian\n"
|
||||
/* pt_BR */
|
||||
" brazilian brazilian-portuguese portugues-brazilian\n"
|
||||
/* br */ " breton brezhoneg\n"
|
||||
/* en_GB */ " british british-english\n"
|
||||
/* bg_BG */ " bulgarian\n"
|
||||
|
|
@ -392,7 +391,8 @@ void show_lang_usage(FILE * f, const char * const prg)
|
|||
/* ku */ " kurdish\n"
|
||||
/* lt */ " lithuanian lietuviu\n"
|
||||
/* ms */ " malay\n"
|
||||
/* es_MX */ " mexican mexican-spanish espanol-mejicano\n"
|
||||
/* es_MX */
|
||||
" mexican mexican-spanish espanol-mejicano\n"
|
||||
/* nn */ " norwegian nynorsk norsk\n"
|
||||
/* pl */ " polish polski\n"
|
||||
/* pt_PT */ " portuguese portugues\n"
|
||||
|
|
@ -414,14 +414,13 @@ void show_lang_usage(FILE * f, const char * const prg)
|
|||
/* vi */ " vietnamese\n"
|
||||
/* wa */ " walloon walon\n"
|
||||
/* cy */ " welsh cymraeg\n"
|
||||
"\n",
|
||||
prg);
|
||||
"\n", prg);
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: Add accented characters to the descriptions */
|
||||
/* Show available locales: */
|
||||
void show_locale_usage(FILE * f, const char * const prg)
|
||||
void show_locale_usage(FILE * f, const char *const prg)
|
||||
{
|
||||
fprintf(f,
|
||||
"\n"
|
||||
|
|
@ -490,12 +489,10 @@ void show_locale_usage(FILE * f, const char * const prg)
|
|||
" uk_UA (Ukrainian)\n"
|
||||
" vi_VN (Vietnamese)\n"
|
||||
" wa_BE (Walloon)\n"
|
||||
" cy_GB (Welsh Cymraeg)\n"
|
||||
"\n",
|
||||
prg);
|
||||
" cy_GB (Welsh Cymraeg)\n" "\n", prg);
|
||||
}
|
||||
|
||||
void setup_language(const char * const prg)
|
||||
void setup_language(const char *const prg)
|
||||
{
|
||||
|
||||
// Justify this or delete it. It seems to make Tux Paint
|
||||
|
|
@ -503,19 +500,20 @@ void setup_language(const char * const prg)
|
|||
#if 0
|
||||
if (langstr == NULL && getenv("LANG"))
|
||||
{
|
||||
if(!strncasecmp(getenv("LANG"), "lt_LT", 5))
|
||||
if (!strncasecmp(getenv("LANG"), "lt_LT", 5))
|
||||
set_langstr("lithuanian");
|
||||
if(!strncasecmp(getenv("LANG"), "pl_PL", 5))
|
||||
if (!strncasecmp(getenv("LANG"), "pl_PL", 5))
|
||||
set_langstr("polish");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (langstr != NULL)
|
||||
{
|
||||
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
|
||||
int i =
|
||||
sizeof language_to_locale_array / sizeof language_to_locale_array[0];
|
||||
const char *locale = NULL;
|
||||
|
||||
while(i--)
|
||||
while (i--)
|
||||
{
|
||||
if (strcmp(langstr, language_to_locale_array[i].language))
|
||||
continue;
|
||||
|
|
@ -544,12 +542,12 @@ void setup_language(const char * const prg)
|
|||
char *s;
|
||||
ssize_t len;
|
||||
|
||||
len = strlen("LANGUAGE=")+strlen(locale)+1;
|
||||
len = strlen("LANGUAGE=") + strlen(locale) + 1;
|
||||
s = malloc(len);
|
||||
snprintf(s, len, "LANGUAGE=%s", locale);
|
||||
putenv(s);
|
||||
|
||||
len = strlen("LC_ALL=")+strlen(locale)+1;
|
||||
len = strlen("LC_ALL=") + strlen(locale) + 1;
|
||||
s = malloc(len);
|
||||
snprintf(s, len, "LC_ALL=%s", locale);
|
||||
putenv(s);
|
||||
|
|
@ -564,7 +562,7 @@ void setup_language(const char * const prg)
|
|||
|
||||
|
||||
// handle --locale arg
|
||||
void do_locale_option(const char * const arg)
|
||||
void do_locale_option(const char *const arg)
|
||||
{
|
||||
int len = strlen(arg) + 6;
|
||||
char *str = malloc(len);
|
||||
|
|
|
|||
21
src/i18n.h
21
src/i18n.h
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
/* Possible languages: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
LANG_AF, /* Afrikaans */
|
||||
LANG_AR, /* Arabic */
|
||||
LANG_BE, /* Belarusian */
|
||||
|
|
@ -89,7 +90,8 @@ enum {
|
|||
|
||||
/* Types: */
|
||||
|
||||
typedef struct language_to_locale_struct {
|
||||
typedef struct language_to_locale_struct
|
||||
{
|
||||
const char *language;
|
||||
const char *locale;
|
||||
} language_to_locale_struct;
|
||||
|
|
@ -97,13 +99,13 @@ typedef struct language_to_locale_struct {
|
|||
|
||||
/* Globals: */
|
||||
|
||||
extern const char * lang_prefixes[NUM_LANGS];
|
||||
extern const char *lang_prefixes[NUM_LANGS];
|
||||
extern int lang_use_own_font[];
|
||||
extern int lang_use_right_to_left[];
|
||||
extern char * langstr;
|
||||
extern char *langstr;
|
||||
extern int need_own_font;
|
||||
extern int need_right_to_left;
|
||||
extern const char * lang_prefix;
|
||||
extern const char *lang_prefix;
|
||||
extern const language_to_locale_struct language_to_locale_array[];
|
||||
|
||||
|
||||
|
|
@ -112,11 +114,10 @@ extern const language_to_locale_struct language_to_locale_array[];
|
|||
|
||||
void set_langstr(const char *s);
|
||||
void set_current_language(void);
|
||||
void show_lang_usage(FILE * f, const char * const prg);
|
||||
void show_locale_usage(FILE * f, const char * const prg);
|
||||
void setup_language(const char * const prg);
|
||||
void do_locale_option(const char * const arg);
|
||||
void show_lang_usage(FILE * f, const char *const prg);
|
||||
void show_locale_usage(FILE * f, const char *const prg);
|
||||
void setup_language(const char *const prg);
|
||||
void do_locale_option(const char *const arg);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,4 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
const char* SurfacePrint (SDL_Surface *surface, int showDialog);
|
||||
|
||||
|
||||
const char *SurfacePrint(SDL_Surface * surface, int showDialog);
|
||||
|
|
|
|||
19
src/magic.h
19
src/magic.h
|
|
@ -30,7 +30,8 @@
|
|||
|
||||
/* What tools are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
MAGIC_FILL,
|
||||
MAGIC_GRASS,
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ const int magic_colors[] = {
|
|||
|
||||
/* Magic tool names: */
|
||||
|
||||
const char * const magic_names[NUM_MAGICS] = {
|
||||
const char *const magic_names[NUM_MAGICS] = {
|
||||
gettext_noop("Fill"),
|
||||
gettext_noop("Grass"),
|
||||
|
||||
|
|
@ -127,7 +128,7 @@ const char * const magic_names[NUM_MAGICS] = {
|
|||
|
||||
/* Some text to write when each tool is selected: */
|
||||
|
||||
const char * const magic_tips[NUM_MAGICS] = {
|
||||
const char *const magic_tips[NUM_MAGICS] = {
|
||||
gettext_noop("Click in the picture to fill that area with color."),
|
||||
gettext_noop("Click and move to draw grass. Don’t forget the dirt!"),
|
||||
|
||||
|
|
@ -143,14 +144,17 @@ const char * const magic_tips[NUM_MAGICS] = {
|
|||
gettext_noop("Click and move to fade the colors."),
|
||||
gettext_noop("Click and move to darken the colors."),
|
||||
|
||||
gettext_noop("Click and move the mouse around to turn the picture into a chalk drawing."),
|
||||
gettext_noop
|
||||
("Click and move the mouse around to turn the picture into a chalk drawing."),
|
||||
gettext_noop("Click and move the mouse around to make the picture blocky."),
|
||||
|
||||
gettext_noop("Click and move the mouse around to draw a negative."),
|
||||
gettext_noop("Click and move the mouse around to change the picture’s color."),
|
||||
gettext_noop
|
||||
("Click and move the mouse around to change the picture’s color."),
|
||||
|
||||
gettext_noop("Click and move the mouse around to make the picture drip."),
|
||||
gettext_noop("Click and move the mouse around to turn the picture into a cartoon."),
|
||||
gettext_noop
|
||||
("Click and move the mouse around to turn the picture into a cartoon."),
|
||||
|
||||
gettext_noop("Click to make a mirror image."),
|
||||
gettext_noop("Click to flip the picture upside-down."),
|
||||
|
|
@ -159,7 +163,7 @@ const char * const magic_tips[NUM_MAGICS] = {
|
|||
|
||||
/* Tool icon filenames: */
|
||||
|
||||
const char * const magic_img_fnames[NUM_MAGICS] = {
|
||||
const char *const magic_img_fnames[NUM_MAGICS] = {
|
||||
DATA_PREFIX "images/magic/fill.png",
|
||||
DATA_PREFIX "images/magic/grass.png",
|
||||
|
||||
|
|
@ -222,4 +226,3 @@ const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
|
|||
{255, 0, 128},
|
||||
{255, 0, 64}
|
||||
};
|
||||
|
||||
|
|
|
|||
101
src/pixels.c
101
src/pixels.c
|
|
@ -34,13 +34,15 @@
|
|||
/* Draw a single pixel into the surface: */
|
||||
void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) ))
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
x); /* Go in X pixels */
|
||||
|
||||
|
|
@ -55,13 +57,15 @@ void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|||
/* Draw a single pixel into the surface: */
|
||||
void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) ))
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 2)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -69,20 +73,22 @@ void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
*(Uint16 *)p = pixel;
|
||||
*(Uint16 *) p = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) ))
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 3)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -109,13 +115,15 @@ void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|||
/* Draw a single pixel into the surface: */
|
||||
void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) ))
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 4)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -123,25 +131,25 @@ void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
*(Uint32 *)p = pixel; // 32-bit display
|
||||
*(Uint32 *) p = pixel; // 32-bit display
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 getpixel8(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u ))
|
||||
x = (x<0) ? 0 : surface->w - 1;
|
||||
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u ))
|
||||
y = (y<0) ? 0 : surface->h - 1;
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
x); /* Go in X pixels */
|
||||
|
||||
|
|
@ -150,24 +158,24 @@ Uint32 getpixel8(SDL_Surface * surface, int x, int y)
|
|||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return(*p);
|
||||
return (*p);
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 getpixel16(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u ))
|
||||
x = (x<0) ? 0 : surface->w - 1;
|
||||
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u ))
|
||||
y = (y<0) ? 0 : surface->h - 1;
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 2)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -176,25 +184,25 @@ Uint32 getpixel16(SDL_Surface * surface, int x, int y)
|
|||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return(*(Uint16 *)p);
|
||||
return (*(Uint16 *) p);
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 getpixel24(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
Uint32 pixel;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u ))
|
||||
x = (x<0) ? 0 : surface->w - 1;
|
||||
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u ))
|
||||
y = (y<0) ? 0 : surface->h - 1;
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 3)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -216,18 +224,18 @@ Uint32 getpixel24(SDL_Surface * surface, int x, int y)
|
|||
/* Get a pixel: */
|
||||
Uint32 getpixel32(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 * p;
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u ))
|
||||
x = (x<0) ? 0 : surface->w - 1;
|
||||
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u ))
|
||||
y = (y<0) ? 0 : surface->h - 1;
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 4)); /* Go in X pixels */
|
||||
|
||||
|
|
@ -236,13 +244,14 @@ Uint32 getpixel32(SDL_Surface * surface, int x, int y)
|
|||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return *(Uint32 *)p; // 32-bit display
|
||||
return *(Uint32 *) p; // 32-bit display
|
||||
}
|
||||
|
||||
void (*putpixels[])(SDL_Surface *, int, int, Uint32) = {
|
||||
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32 };
|
||||
void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
|
||||
{
|
||||
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
|
||||
|
||||
|
||||
Uint32 (*getpixels[])(SDL_Surface *, int, int) = {
|
||||
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32 };
|
||||
|
||||
Uint32(*getpixels[])(SDL_Surface *, int, int) =
|
||||
{
|
||||
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};
|
||||
|
|
|
|||
|
|
@ -37,14 +37,13 @@ void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
|||
void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
|
||||
extern void (*putpixels[])(SDL_Surface *, int, int, Uint32);
|
||||
extern void (*putpixels[]) (SDL_Surface *, int, int, Uint32);
|
||||
|
||||
Uint32 getpixel8(SDL_Surface * surface, int x, int y);
|
||||
Uint32 getpixel16(SDL_Surface * surface, int x, int y);
|
||||
Uint32 getpixel24(SDL_Surface * surface, int x, int y);
|
||||
Uint32 getpixel32(SDL_Surface * surface, int x, int y);
|
||||
|
||||
extern Uint32 (*getpixels[])(SDL_Surface *, int, int);
|
||||
extern Uint32(*getpixels[]) (SDL_Surface *, int, int);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
#include "debug.h"
|
||||
|
||||
#ifndef NOSOUND
|
||||
Mix_Chunk * sounds[NUM_SOUNDS];
|
||||
Mix_Chunk *sounds[NUM_SOUNDS];
|
||||
#endif
|
||||
|
||||
int mute, use_sound;
|
||||
int old_sound[4] = {-1, -1, -1, -1};
|
||||
int old_sound[4] = { -1, -1, -1, -1 };
|
||||
|
||||
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y)
|
||||
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
|
||||
int y)
|
||||
{
|
||||
#ifndef NOSOUND
|
||||
int left, dist;
|
||||
|
|
@ -59,4 +60,3 @@ void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
#define SNDDIST_NEAR -999
|
||||
|
||||
extern Mix_Chunk * sounds[NUM_SOUNDS];
|
||||
extern Mix_Chunk *sounds[NUM_SOUNDS];
|
||||
extern int mute, use_sound;
|
||||
|
||||
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y);
|
||||
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
|
||||
int y);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include "progressbar.h"
|
||||
#include "debug.h"
|
||||
|
||||
SDL_Surface * img_progress;
|
||||
SDL_Surface *img_progress;
|
||||
int progress_bar_disabled, prog_bar_ctr;
|
||||
|
||||
void show_progress_bar(SDL_Surface * screen)
|
||||
|
|
@ -41,11 +41,11 @@ void show_progress_bar(SDL_Surface * screen)
|
|||
static Uint32 oldtime;
|
||||
Uint32 newtime;
|
||||
|
||||
if(progress_bar_disabled)
|
||||
if (progress_bar_disabled)
|
||||
return;
|
||||
|
||||
newtime = SDL_GetTicks();
|
||||
if(newtime > oldtime+15) // trying not to eat some serious CPU time!
|
||||
if (newtime > oldtime + 15) // trying not to eat some serious CPU time!
|
||||
{
|
||||
for (x = 0; x < screen->w; x = x + 65)
|
||||
{
|
||||
|
|
@ -70,4 +70,3 @@ void show_progress_bar(SDL_Surface * screen)
|
|||
/* FIXME: RESURRECT THIS (bjk 2006.02.18) */
|
||||
//eat_sdl_events();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
extern SDL_Surface * img_progress;
|
||||
extern SDL_Surface *img_progress;
|
||||
extern int progress_bar_disabled, prog_bar_ctr;
|
||||
|
||||
void show_progress_bar(SDL_Surface * screen);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -30,18 +30,16 @@
|
|||
#include "rgblinear.h"
|
||||
#include "debug.h"
|
||||
|
||||
unsigned char linear_to_sRGB (float linear)
|
||||
unsigned char linear_to_sRGB(float linear)
|
||||
{
|
||||
unsigned slot;
|
||||
slot = linear*4096.0 + 0.5;
|
||||
if(slot>4095)
|
||||
slot = linear * 4096.0 + 0.5;
|
||||
if (slot > 4095)
|
||||
{
|
||||
if(linear>0.5)
|
||||
if (linear > 0.5)
|
||||
slot = 4095;
|
||||
else
|
||||
slot = 0;
|
||||
}
|
||||
return linear_to_sRGB_table[slot];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -306,10 +306,8 @@ static const unsigned char linear_to_sRGB_table[4096] =
|
|||
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
|
||||
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
|
||||
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
|
||||
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
||||
;
|
||||
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
||||
|
||||
unsigned char linear_to_sRGB (float linear) FUNCTION;
|
||||
unsigned char linear_to_sRGB(float linear) FUNCTION;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
22
src/shapes.h
22
src/shapes.h
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
/* What shapes are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
SHAPE_SQUARE,
|
||||
SHAPE_SQUARE_FILL,
|
||||
SHAPE_RECTANGLE,
|
||||
|
|
@ -153,7 +154,7 @@ const int shape_no_rotate[NUM_SHAPES] = {
|
|||
|
||||
/* Shape names: */
|
||||
|
||||
const char * const shape_names[NUM_SHAPES] = {
|
||||
const char *const shape_names[NUM_SHAPES] = {
|
||||
gettext_noop("Square"),
|
||||
gettext_noop("Square"),
|
||||
gettext_noop("Rectangle"),
|
||||
|
|
@ -173,27 +174,31 @@ const char * const shape_names[NUM_SHAPES] = {
|
|||
|
||||
/* Some text to write when each shape is selected: */
|
||||
|
||||
const char * const shape_tips[NUM_SHAPES] = {
|
||||
const char *const shape_tips[NUM_SHAPES] = {
|
||||
gettext_noop("A square is a rectangle with four equal sides."),
|
||||
gettext_noop("A square is a rectangle with four equal sides."),
|
||||
gettext_noop("A rectangle has four sides and four right angles."),
|
||||
gettext_noop("A rectangle has four sides and four right angles."),
|
||||
gettext_noop("A circle is a curve where all points have the same distance from the centre."),
|
||||
gettext_noop("A circle is a curve where all points have the same distance from the centre."),
|
||||
gettext_noop
|
||||
("A circle is a curve where all points have the same distance from the centre."),
|
||||
gettext_noop
|
||||
("A circle is a curve where all points have the same distance from the centre."),
|
||||
gettext_noop("An ellipse is a stretched circle."),
|
||||
gettext_noop("An ellipse is a stretched circle."),
|
||||
gettext_noop("A triangle has three sides."),
|
||||
gettext_noop("A triangle has three sides."),
|
||||
gettext_noop("A pentagon has five sides."),
|
||||
gettext_noop("A pentagon has five sides."),
|
||||
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."),
|
||||
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel.")
|
||||
gettext_noop
|
||||
("A rhombus has four equal sides, and opposite sides are parallel."),
|
||||
gettext_noop
|
||||
("A rhombus has four equal sides, and opposite sides are parallel.")
|
||||
};
|
||||
|
||||
|
||||
/* Shape icon filenames: */
|
||||
|
||||
const char * const shape_img_fnames[NUM_SHAPES] = {
|
||||
const char *const shape_img_fnames[NUM_SHAPES] = {
|
||||
DATA_PREFIX "images/shapes/square.png",
|
||||
DATA_PREFIX "images/shapes/square_f.png",
|
||||
DATA_PREFIX "images/shapes/rectangle.png",
|
||||
|
|
@ -209,4 +214,3 @@ const char * const shape_img_fnames[NUM_SHAPES] = {
|
|||
DATA_PREFIX "images/shapes/diamond.png",
|
||||
DATA_PREFIX "images/shapes/diamond_f.png"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
|
||||
#define SND_NONE -1
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
SND_HARP, /* Begin / New */
|
||||
SND_CLICK, /* Tool selections */
|
||||
SND_BLEEP, /* Selector selection */
|
||||
|
|
@ -87,7 +88,7 @@ enum {
|
|||
|
||||
/* Sound file filenames: */
|
||||
|
||||
static const char * sound_fnames[NUM_SOUNDS] = {
|
||||
static const char *sound_fnames[NUM_SOUNDS] = {
|
||||
DATA_PREFIX "sounds/harp.wav",
|
||||
DATA_PREFIX "sounds/click.wav",
|
||||
DATA_PREFIX "sounds/bleep.wav",
|
||||
|
|
@ -136,4 +137,3 @@ static const char * sound_fnames[NUM_SOUNDS] = {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
/* What tuxes are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TUX_DEFAULT,
|
||||
TUX_KISS,
|
||||
TUX_BORED,
|
||||
|
|
@ -31,7 +32,7 @@ enum {
|
|||
|
||||
/* Tux filenames: */
|
||||
|
||||
const char * const tux_img_fnames[NUM_TIP_TUX] = {
|
||||
const char *const tux_img_fnames[NUM_TIP_TUX] = {
|
||||
DATA_PREFIX "images/tux/default.png",
|
||||
DATA_PREFIX "images/tux/kiss.png",
|
||||
DATA_PREFIX "images/tux/bored.png",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
/* What titles are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TITLE_NONE,
|
||||
TITLE_NOCOLORS,
|
||||
TITLE_TOOLS,
|
||||
|
|
@ -33,7 +34,7 @@ enum {
|
|||
|
||||
/* Title names: */
|
||||
|
||||
const char * const title_names[NUM_TITLES] = {
|
||||
const char *const title_names[NUM_TITLES] = {
|
||||
"",
|
||||
"",
|
||||
gettext_noop("Tools"),
|
||||
|
|
@ -45,4 +46,3 @@ const char * const title_names[NUM_TITLES] = {
|
|||
gettext_noop("Letters"),
|
||||
gettext_noop("Magic")
|
||||
};
|
||||
|
||||
|
|
|
|||
16
src/tools.h
16
src/tools.h
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
/* What tools are available: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_BRUSH,
|
||||
TOOL_STAMP,
|
||||
TOOL_LINES,
|
||||
|
|
@ -39,7 +40,7 @@ enum {
|
|||
|
||||
/* Tool names: */
|
||||
|
||||
const char * const tool_names[NUM_TOOLS] = {
|
||||
const char *const tool_names[NUM_TOOLS] = {
|
||||
gettext_noop("Paint"),
|
||||
gettext_noop("Stamp"),
|
||||
gettext_noop("Lines"),
|
||||
|
|
@ -59,12 +60,14 @@ const char * const tool_names[NUM_TOOLS] = {
|
|||
|
||||
/* Some text to write when each tool is selected: */
|
||||
|
||||
const char * const tool_tips[NUM_TOOLS] = {
|
||||
const char *const tool_tips[NUM_TOOLS] = {
|
||||
gettext_noop("Pick a color and a brush shape to draw with."),
|
||||
gettext_noop("Pick a picture to stamp around your drawing."),
|
||||
gettext_noop("Click to start drawing a line. Let go to complete it."),
|
||||
gettext_noop("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."),
|
||||
gettext_noop("Choose a style of text. Click on your drawing and you can start typing."),
|
||||
gettext_noop
|
||||
("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."),
|
||||
gettext_noop
|
||||
("Choose a style of text. Click on your drawing and you can start typing."),
|
||||
gettext_noop("Pick a magical effect to use on your drawing!"),
|
||||
/* Undo */ gettext_noop("Undo!"),
|
||||
/* Redo */ gettext_noop("Redo!"),
|
||||
|
|
@ -84,7 +87,7 @@ const char * const tool_tips[NUM_TOOLS] = {
|
|||
|
||||
/* Tool icon filenames: */
|
||||
|
||||
const char * const tool_img_fnames[NUM_TOOLS] = {
|
||||
const char *const tool_img_fnames[NUM_TOOLS] = {
|
||||
DATA_PREFIX "images/tools/brush.png",
|
||||
DATA_PREFIX "images/tools/stamp.png",
|
||||
DATA_PREFIX "images/tools/lines.png",
|
||||
|
|
@ -120,4 +123,3 @@ const int tool_tux[NUM_TOOLS] = {
|
|||
TUX_GREAT,
|
||||
TUX_DEFAULT
|
||||
};
|
||||
|
||||
|
|
|
|||
2882
src/tuxpaint.c
2882
src/tuxpaint.c
File diff suppressed because it is too large
Load diff
|
|
@ -29,46 +29,42 @@
|
|||
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "win32_dirent.h"
|
||||
#include "debug.h"
|
||||
|
||||
DIR *opendir( const char *pSpec )
|
||||
DIR * opendir(const char *pSpec)
|
||||
{
|
||||
char pathname[MAX_PATH+2];
|
||||
DIR *pDir = calloc( 1, sizeof(DIR) );
|
||||
|
||||
if ( !pDir ) return NULL;
|
||||
strcpy( pathname, pSpec );
|
||||
strcat( pathname, "/*" );
|
||||
char pathname[MAX_PATH + 2];
|
||||
DIR * pDir = calloc(1, sizeof(DIR));
|
||||
if (!pDir)
|
||||
return NULL;
|
||||
strcpy(pathname, pSpec);
|
||||
strcat(pathname, "/*");
|
||||
pDir->hFind = FindFirstFile(pathname, &pDir->wfd);
|
||||
if ( pDir->hFind == INVALID_HANDLE_VALUE )
|
||||
if (pDir->hFind == INVALID_HANDLE_VALUE)
|
||||
|
||||
{
|
||||
free(pDir);
|
||||
pDir = NULL;
|
||||
}
|
||||
return pDir;
|
||||
}
|
||||
|
||||
|
||||
void closedir( DIR *pDir )
|
||||
}
|
||||
void closedir(DIR * pDir)
|
||||
{
|
||||
assert(pDir != NULL);
|
||||
free(pDir);
|
||||
}
|
||||
|
||||
|
||||
struct dirent *readdir(struct DIR *pDir)
|
||||
}
struct dirent *readdir(struct DIR *pDir)
|
||||
{
|
||||
assert(pDir != NULL);
|
||||
if (pDir->hFind)
|
||||
|
||||
{
|
||||
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
|
||||
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
|
||||
if (!FindNextFile(pDir->hFind, &pDir->wfd))
|
||||
|
||||
{
|
||||
FindClose(pDir->hFind);
|
||||
pDir->hFind = NULL;
|
||||
|
|
@ -76,60 +72,57 @@ struct dirent *readdir(struct DIR *pDir)
|
|||
return &pDir->de;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int alphasort(const void *a, const void *b)
|
||||
}
|
||||
int alphasort(const void *a, const void *b)
|
||||
{
|
||||
return(strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
|
||||
}
|
||||
|
||||
|
||||
static int addToList( int i, struct dirent ***namelist, struct dirent *entry )
|
||||
return (strcmp
|
||||
((*(const struct dirent **) a)->d_name,
|
||||
(*(const struct dirent **) b)->d_name));
|
||||
}
static int addToList(int i, struct dirent ***namelist,
|
||||
struct dirent *entry)
|
||||
{
|
||||
int size;
|
||||
struct dirent *block;
|
||||
|
||||
*namelist = (struct dirent**)realloc( (void*)(*namelist), (size_t)((i+1)*sizeof(struct dirent*)) );
|
||||
if ( *namelist == NULL ) return -1;
|
||||
|
||||
size = (((char*)&entry->d_name)-((char*)entry))+strlen(entry->d_name)+1;
|
||||
block = (struct dirent*)malloc( size );
|
||||
|
||||
if ( block == NULL ) return -1;
|
||||
|
||||
*namelist =
|
||||
(struct dirent **) realloc((void *) (*namelist),
|
||||
(size_t) ((i + 1) * sizeof(struct dirent *)));
|
||||
if (*namelist == NULL)
|
||||
return -1;
|
||||
size =
|
||||
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
|
||||
1;
|
||||
block = (struct dirent *) malloc(size);
|
||||
if (block == NULL)
|
||||
return -1;
|
||||
(*namelist)[i] = block;
|
||||
memcpy( block, entry, size );
|
||||
|
||||
memcpy(block, entry, size);
|
||||
return ++i;
|
||||
}
|
||||
|
||||
|
||||
int scandir( const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
|
||||
}
|
||||
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
|
||||
comparCB compar)
|
||||
{
|
||||
DIR *pDir;
|
||||
DIR * pDir;
|
||||
int count;
|
||||
struct dirent *entry;
|
||||
|
||||
assert( (dir != NULL) && (namelist != NULL) );
|
||||
|
||||
assert((dir != NULL) && (namelist != NULL));
|
||||
pDir = opendir(dir);
|
||||
|
||||
if ( !pDir ) return -1;
|
||||
|
||||
if (!pDir)
|
||||
return -1;
|
||||
count = 0;
|
||||
while( (entry = readdir(pDir)) != NULL )
|
||||
while ((entry = readdir(pDir)) != NULL)
|
||||
|
||||
{
|
||||
if ( select == NULL || (select != NULL && select( entry )) )
|
||||
if ( (count = addToList( count, namelist, entry )) < 0 )
|
||||
if (select == NULL || (select != NULL && select(entry)))
|
||||
if ((count = addToList(count, namelist, entry)) < 0)
|
||||
break;
|
||||
}
|
||||
closedir( pDir );
|
||||
if ( count <= 0 ) return -1;
|
||||
|
||||
if ( compar != NULL )
|
||||
qsort( (void *)(*namelist), (size_t)count, sizeof(struct dirent *), compar );
|
||||
|
||||
closedir(pDir);
|
||||
if (count <= 0)
|
||||
return -1;
|
||||
if (compar != NULL)
|
||||
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
|
||||
compar);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,23 +8,20 @@
|
|||
/* */
|
||||
/****************************************************/
|
||||
/* $Id$ */
|
||||
|
||||
typedef long BOOL;
|
||||
typedef unsigned int DWORD;
|
||||
typedef wchar_t TCHAR;
|
||||
typedef void* HANDLE;
|
||||
typedef long BOOL;
|
||||
typedef unsigned int DWORD;
|
||||
typedef wchar_t TCHAR;
|
||||
typedef void *HANDLE;
|
||||
|
||||
#define MAX_PATH 256
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)(-1))
|
||||
#define WINAPI __stdcall
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME;
|
||||
|
||||
typedef struct
|
||||
} FILETIME;
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwFileAttributes;
|
||||
FILETIME ftCreationTime;
|
||||
|
|
@ -34,49 +31,43 @@ typedef struct
|
|||
DWORD nFileSizeLow;
|
||||
DWORD dwReserved0;
|
||||
DWORD dwReserved1;
|
||||
TCHAR cFileName[ MAX_PATH ];
|
||||
TCHAR cAlternateFileName[ 14 ];
|
||||
} WIN32_FIND_DATA;
|
||||
|
||||
TCHAR cFileName[MAX_PATH];
|
||||
TCHAR cAlternateFileName[14];
|
||||
} WIN32_FIND_DATA;
|
||||
|
||||
#define FindFirstFile FindFirstFileA
|
||||
#define FindNextFile FindNextFileA
|
||||
#define FindClose FindClose
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern "C"
|
||||
{
|
||||
|
||||
extern HANDLE WINAPI FindFirstFile( const char*, WIN32_FIND_DATA* );
|
||||
extern BOOL WINAPI FindNextFile( HANDLE, WIN32_FIND_DATA* );
|
||||
extern BOOL WINAPI FindClose( HANDLE );
|
||||
#endif /*
*/
|
||||
extern HANDLE WINAPI FindFirstFile(const char *, WIN32_FIND_DATA *);
|
||||
extern BOOL WINAPI FindNextFile(HANDLE, WIN32_FIND_DATA *);
|
||||
extern BOOL WINAPI FindClose(HANDLE);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
struct dirent
|
||||
#endif /*
*/
|
||||
struct dirent
|
||||
{
|
||||
char d_name[MAX_PATH];
|
||||
};
|
||||
|
||||
|
||||
typedef struct
|
||||
};
|
||||
typedef struct
|
||||
{
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE hFind;
|
||||
struct dirent de;
|
||||
} DIR;
|
||||
} DIR;
|
||||
extern DIR *opendir(const char *pSpec);
|
||||
extern void closedir(DIR * pDir);
|
||||
extern struct dirent *readdir(struct DIR *pDir);
|
||||
typedef int (*selectCB) (const struct dirent *);
|
||||
typedef int (*comparCB) (const void *, const void *);
|
||||
extern int alphasort(const void *a, const void *b);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist,
|
||||
selectCB select, comparCB compar);
|
||||
|
||||
|
||||
extern DIR *opendir(const char *pSpec);
|
||||
extern void closedir(DIR *pDir);
|
||||
extern struct dirent *readdir(struct DIR *pDir);
|
||||
|
||||
typedef int (*selectCB)(const struct dirent *);
|
||||
typedef int (*comparCB)(const void*, const void*);
|
||||
|
||||
extern int alphasort( const void *a, const void *b );
|
||||
extern int scandir( const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);
|
||||
|
|
|
|||
|
|
@ -49,19 +49,19 @@ static PRINTDLG global_pd = {
|
|||
};
|
||||
|
||||
|
||||
static SDL_Surface *make24bitDIB(SDL_Surface *surf)
|
||||
static SDL_Surface *make24bitDIB(SDL_Surface * surf)
|
||||
{
|
||||
SDL_PixelFormat pixfmt;
|
||||
SDL_Surface *surf24;
|
||||
SDL_Surface *surfDIB;
|
||||
Uint8 *src,*dst;
|
||||
Uint8 *src, *dst;
|
||||
Uint32 linesize;
|
||||
int i;
|
||||
|
||||
memset(&pixfmt, 0, sizeof(pixfmt));
|
||||
pixfmt.palette = NULL;
|
||||
pixfmt.BitsPerPixel = 24;
|
||||
pixfmt.BytesPerPixel= 3;
|
||||
pixfmt.BytesPerPixel = 3;
|
||||
pixfmt.Rmask = 0x00FF0000;
|
||||
pixfmt.Gmask = 0x0000FF00;
|
||||
pixfmt.Bmask = 0x000000FF;
|
||||
|
|
@ -79,11 +79,12 @@ static SDL_Surface *make24bitDIB(SDL_Surface *surf)
|
|||
|
||||
surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE);
|
||||
surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24,
|
||||
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask);
|
||||
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask,
|
||||
pixfmt.Amask);
|
||||
|
||||
linesize = surf24->w * 3; // Flip top2bottom
|
||||
dst = surfDIB->pixels;
|
||||
src = ((Uint8*)surf24->pixels)+((surf24->h-1)*surf24->pitch);
|
||||
src = ((Uint8 *) surf24->pixels) + ((surf24->h - 1) * surf24->pitch);
|
||||
for (i = 0; i < surf24->h; ++i)
|
||||
{
|
||||
memcpy(dst, src, linesize);
|
||||
|
|
@ -103,7 +104,7 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
|
|||
const char *key = "device";
|
||||
const char *def = "NODEFAULTPRINTER";
|
||||
char buff[MAX_PATH];
|
||||
char *dev,*drv,*out;
|
||||
char *dev, *drv, *out;
|
||||
|
||||
if (!GetProfileString(section, key, def, buff, sizeof(buff)))
|
||||
return 0;
|
||||
|
|
@ -111,13 +112,16 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
|
|||
if (strcmp(buff, def) == 0)
|
||||
return 0;
|
||||
|
||||
if (((dev = strtok(buff, "," )) != NULL) &&
|
||||
if (((dev = strtok(buff, ",")) != NULL) &&
|
||||
((drv = strtok(NULL, ", ")) != NULL) &&
|
||||
((out = strtok(NULL, ", ")) != NULL))
|
||||
{
|
||||
if (device) strcpy(device, dev);
|
||||
if (driver) strcpy(driver, drv);
|
||||
if (output) strcpy(output, out);
|
||||
if (device)
|
||||
strcpy(device, dev);
|
||||
if (driver)
|
||||
strcpy(driver, drv);
|
||||
if (output)
|
||||
strcpy(output, out);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -146,7 +150,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
|
|||
if (!OpenPrinter(device, &hPrinter, NULL))
|
||||
return NULL;
|
||||
|
||||
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device,
|
||||
sizeof_devmode = (int) DocumentProperties(hWnd, hPrinter, device,
|
||||
NULL, NULL, 0);
|
||||
|
||||
if (!sizeof_devmode)
|
||||
|
|
@ -156,7 +160,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
|
|||
if (!hDevMode)
|
||||
goto err_exit;
|
||||
|
||||
devmode = (DEVMODE*)GlobalLock(hDevMode);
|
||||
devmode = (DEVMODE *) GlobalLock(hDevMode);
|
||||
if (!devmode)
|
||||
goto err_exit;
|
||||
|
||||
|
|
@ -172,7 +176,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
|
|||
fclose(fp);
|
||||
|
||||
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
|
||||
DM_IN_BUFFER|DM_OUT_BUFFER);
|
||||
DM_IN_BUFFER | DM_OUT_BUFFER);
|
||||
if (res != IDOK)
|
||||
goto err_exit;
|
||||
|
||||
|
|
@ -181,27 +185,32 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
|
|||
return hDevMode;
|
||||
|
||||
err_exit:
|
||||
if (fp) fclose(fp);
|
||||
if (devmode) GlobalUnlock(hDevMode);
|
||||
if (hDevMode) GlobalFree(hDevMode);
|
||||
if (hPrinter) ClosePrinter(hPrinter);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (devmode)
|
||||
GlobalUnlock(hDevMode);
|
||||
if (hDevMode)
|
||||
GlobalFree(hDevMode);
|
||||
if (hPrinter)
|
||||
ClosePrinter(hPrinter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode)
|
||||
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
|
||||
HANDLE hDevMode)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
|
||||
NOREF(hWnd);
|
||||
if ((fp = fopen(filepath, "wb")) != NULL)
|
||||
{
|
||||
DEVMODE *devmode = (DEVMODE*)GlobalLock(hDevMode);
|
||||
DEVMODE *devmode = (DEVMODE *) GlobalLock(hDevMode);
|
||||
int block_size = devmode->dmSize + devmode->dmDriverExtra;
|
||||
int block_written;
|
||||
char devname[dmDeviceNameSize];
|
||||
|
||||
strcpy(devname, (const char*)devmode->dmDeviceName);
|
||||
strcpy(devname, (const char *) devmode->dmDeviceName);
|
||||
fwrite(devname, 1, sizeof(devname), fp);
|
||||
block_written = fwrite(devmode, 1, block_size, fp);
|
||||
GlobalUnlock(hDevMode);
|
||||
|
|
@ -234,9 +243,10 @@ static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
|
|||
}
|
||||
|
||||
{
|
||||
DEVMODE *devmode = (DEVMODE*)GlobalLock(global_pd.hDevMode);
|
||||
DEVMODE *devmode = (DEVMODE *) GlobalLock(global_pd.hDevMode);
|
||||
|
||||
global_pd.hDC = CreateDC(NULL, (const char*)devmode->dmDeviceName, NULL, devmode);
|
||||
global_pd.hDC =
|
||||
CreateDC(NULL, (const char *) devmode->dmDeviceName, NULL, devmode);
|
||||
GlobalUnlock(global_pd.hDevMode);
|
||||
}
|
||||
return global_pd.hDC;
|
||||
|
|
@ -245,7 +255,7 @@ static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
|
|||
|
||||
static HDC GetDefaultPrinterDC(void)
|
||||
{
|
||||
char device[MAX_PATH],driver[MAX_PATH],output[MAX_PATH];
|
||||
char device[MAX_PATH], driver[MAX_PATH], output[MAX_PATH];
|
||||
|
||||
if (GetDefaultPrinterStrings(device, driver, output))
|
||||
return CreateDC(driver, device, output, NULL);
|
||||
|
|
@ -256,7 +266,8 @@ static HDC GetDefaultPrinterDC(void)
|
|||
|
||||
static HDC GetPrinterDC(HWND hWnd, const char *printcfg, int show)
|
||||
{
|
||||
if (!printcfg) return GetDefaultPrinterDC();
|
||||
if (!printcfg)
|
||||
return GetDefaultPrinterDC();
|
||||
return GetCustomPrinterDC(hWnd, printcfg, show);
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +279,8 @@ static int IsBandingRequired(HDC hPrinter)
|
|||
|
||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if (GetVersionEx(&osvi) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT))
|
||||
return Escape(hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL);
|
||||
return Escape(hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR) & indata,
|
||||
NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +291,8 @@ int IsPrinterAvailable(void)
|
|||
}
|
||||
|
||||
|
||||
const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog)
|
||||
const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
|
||||
int showdialog)
|
||||
{
|
||||
const char *res = NULL;
|
||||
HWND hWnd;
|
||||
|
|
@ -294,7 +307,7 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
float fLogPelsX1, fLogPelsY1, fLogPelsX2, fLogPelsY2;
|
||||
float fScaleX, fScaleY;
|
||||
int cWidthPels, xLeft, yTop;
|
||||
float subscaler,subscalerx,subscalery;
|
||||
float subscaler, subscalerx, subscalery;
|
||||
int hDCCaps;
|
||||
HBITMAP hbm = NULL;
|
||||
HDC hdcMem = NULL;
|
||||
|
|
@ -312,8 +325,8 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
|
||||
di.cbSize = sizeof(DOCINFO);
|
||||
di.lpszDocName = "Tux Paint";
|
||||
di.lpszOutput = (LPTSTR)NULL;
|
||||
di.lpszDatatype = (LPTSTR)NULL;
|
||||
di.lpszOutput = (LPTSTR) NULL;
|
||||
di.lpszDatatype = (LPTSTR) NULL;
|
||||
di.fwType = 0;
|
||||
|
||||
nError = StartDoc(hDCprinter, &di);
|
||||
|
|
@ -348,8 +361,8 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
bmih.biHeight = surf24->h;
|
||||
|
||||
GetClientRect(hWnd, &rc);
|
||||
subscalerx = (float)rc.right/surf24->w;
|
||||
subscalery = (float)rc.bottom/surf24->h;
|
||||
subscalerx = (float) rc.right / surf24->w;
|
||||
subscalery = (float) rc.bottom / surf24->h;
|
||||
subscaler = subscalery;
|
||||
if (subscalerx < subscalery)
|
||||
subscaler = subscalerx;
|
||||
|
|
@ -368,21 +381,21 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
fLogPelsY2 = GetDeviceCaps(hDCprinter, LOGPIXELSY);
|
||||
|
||||
if (fLogPelsX1 > fLogPelsX2)
|
||||
fScaleX = (fLogPelsX1/fLogPelsX2);
|
||||
fScaleX = (fLogPelsX1 / fLogPelsX2);
|
||||
else
|
||||
fScaleX = (fLogPelsX2/fLogPelsX1);
|
||||
fScaleX = (fLogPelsX2 / fLogPelsX1);
|
||||
|
||||
if (fLogPelsY1 > fLogPelsY2)
|
||||
fScaleY = (fLogPelsY1/fLogPelsY2);
|
||||
fScaleY = (fLogPelsY1 / fLogPelsY2);
|
||||
else
|
||||
fScaleY = (fLogPelsY2/fLogPelsY1);
|
||||
fScaleY = (fLogPelsY2 / fLogPelsY1);
|
||||
|
||||
fScaleX *= subscaler;
|
||||
fScaleY *= subscaler;
|
||||
|
||||
yTop = 0;
|
||||
cWidthPels = GetDeviceCaps(hDCprinter, PHYSICALWIDTH);
|
||||
xLeft = ((cWidthPels - ((int)(fScaleX*bmih.biWidth)))/2)-
|
||||
xLeft = ((cWidthPels - ((int) (fScaleX * bmih.biWidth))) / 2) -
|
||||
GetDeviceCaps(hDCprinter, PHYSICALOFFSETX);
|
||||
|
||||
hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS);
|
||||
|
|
@ -399,16 +412,18 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
RECT rcPrinter;
|
||||
RECT rcImage;
|
||||
|
||||
SetRect(&rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight));
|
||||
SetRect(&rcPrinter, xLeft, yTop, (int) (fScaleX * bmih.biWidth),
|
||||
(int) (fScaleY * bmih.biHeight));
|
||||
SetRect(&rcImage, 0, 0, bmih.biWidth, bmih.biHeight);
|
||||
|
||||
while (Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand))
|
||||
{
|
||||
if (IsRectEmpty(&rcBand)) break;
|
||||
if (IsRectEmpty(&rcBand))
|
||||
break;
|
||||
if (IntersectRect(&rcBand, &rcBand, &rcPrinter))
|
||||
{
|
||||
rcImage.top = (int)(0.5f+(float)rcBand.top/fScaleX);
|
||||
rcImage.bottom = (int)(0.5f+(float)rcBand.bottom/fScaleX);
|
||||
rcImage.top = (int) (0.5f + (float) rcBand.top / fScaleX);
|
||||
rcImage.bottom = (int) (0.5f + (float) rcBand.bottom / fScaleX);
|
||||
|
||||
SetStretchBltMode(hDCprinter, COLORONCOLOR);
|
||||
nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top,
|
||||
|
|
@ -417,7 +432,7 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
rcImage.left, rcImage.top,
|
||||
rcImage.right - rcImage.left,
|
||||
rcImage.bottom - rcImage.top,
|
||||
surf24->pixels, (BITMAPINFO*)&bmih,
|
||||
surf24->pixels, (BITMAPINFO *) & bmih,
|
||||
DIB_RGB_COLORS, SRCCOPY);
|
||||
if (nError == GDI_ERROR)
|
||||
{
|
||||
|
|
@ -434,10 +449,10 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
SetStretchBltMode(hDCprinter, COLORONCOLOR);
|
||||
|
||||
nError = StretchDIBits(hDCprinter, xLeft, yTop,
|
||||
(int)(fScaleX*bmih.biWidth),
|
||||
(int)(fScaleY*bmih.biHeight),
|
||||
(int) (fScaleX * bmih.biWidth),
|
||||
(int) (fScaleY * bmih.biHeight),
|
||||
0, 0, bmih.biWidth, bmih.biHeight,
|
||||
surf24->pixels, (BITMAPINFO*)&bmih,
|
||||
surf24->pixels, (BITMAPINFO *) & bmih,
|
||||
DIB_RGB_COLORS, SRCCOPY);
|
||||
if (nError == GDI_ERROR)
|
||||
{
|
||||
|
|
@ -464,9 +479,12 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
|
|||
EndDoc(hDCprinter);
|
||||
|
||||
error:
|
||||
if (hdcMem) DeleteDC(hdcMem);
|
||||
if (hbm) DeleteObject(hbm);
|
||||
if (surf24) SDL_FreeSurface(surf24);
|
||||
if (hdcMem)
|
||||
DeleteDC(hdcMem);
|
||||
if (hbm)
|
||||
DeleteObject(hbm);
|
||||
if (surf24)
|
||||
SDL_FreeSurface(surf24);
|
||||
|
||||
EnableWindow(hWnd, TRUE);
|
||||
DeleteDC(hDCprinter);
|
||||
|
|
@ -477,7 +495,8 @@ error:
|
|||
/*
|
||||
Read access to Windows Registry
|
||||
*/
|
||||
static HRESULT ReadRegistry(const char *key, const char *option, char *value, int size)
|
||||
static HRESULT ReadRegistry(const char *key, const char *option, char *value,
|
||||
int size)
|
||||
{
|
||||
LONG res;
|
||||
HKEY hKey = NULL;
|
||||
|
|
@ -485,13 +504,16 @@ static HRESULT ReadRegistry(const char *key, const char *option, char *value, in
|
|||
res = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
|
||||
if (res != ERROR_SUCCESS)
|
||||
goto err_exit;
|
||||
res = RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE)value, (LPDWORD)&size);
|
||||
res =
|
||||
RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE) value,
|
||||
(LPDWORD) & size);
|
||||
if (res != ERROR_SUCCESS)
|
||||
goto err_exit;
|
||||
res = ERROR_SUCCESS;
|
||||
|
||||
err_exit:
|
||||
if (hKey) RegCloseKey(hKey);
|
||||
if (hKey)
|
||||
RegCloseKey(hKey);
|
||||
return HRESULT_FROM_WIN32(res);
|
||||
}
|
||||
|
||||
|
|
@ -505,8 +527,8 @@ static char *remove_slash(char *path)
|
|||
if (!len)
|
||||
return path;
|
||||
|
||||
if (path[len-1] == '/' || path[len-1] == '\\')
|
||||
path[len-1] = 0;
|
||||
if (path[len - 1] == '/' || path[len - 1] == '\\')
|
||||
path[len - 1] = 0;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
@ -519,8 +541,9 @@ static char *remove_slash(char *path)
|
|||
char *GetDefaultSaveDir(const char *suffix)
|
||||
{
|
||||
char prefix[MAX_PATH];
|
||||
char path[2*MAX_PATH];
|
||||
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
|
||||
char path[2 * MAX_PATH];
|
||||
const char *key =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
|
||||
const char *option = "AppData";
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
|
|
@ -541,7 +564,8 @@ char *GetDefaultSaveDir(const char *suffix)
|
|||
char *GetSystemFontDir(void)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
|
||||
const char *key =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
|
||||
const char *option = "Fonts";
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
|
|
@ -552,5 +576,3 @@ char *GetSystemFontDir(void)
|
|||
}
|
||||
return strdup("C:\\WINDOWS\\FONTS");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,9 @@
|
|||
#endif
|
||||
|
||||
/* if printcfg is NULL, uses the default printer */
|
||||
extern const char *SurfacePrint( SDL_Surface *surf,
|
||||
const char *printcfg,
|
||||
int showdialog );
|
||||
extern int IsPrinterAvailable( void );
|
||||
extern const char *SurfacePrint(SDL_Surface * surf,
|
||||
const char *printcfg, int showdialog);
|
||||
extern int IsPrinterAvailable(void);
|
||||
|
||||
/* additional windows functions requiring <windows.h> */
|
||||
extern char *GetDefaultSaveDir(const char *suffix);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue