Indentation.

This commit is contained in:
Pere Pujal i Carabantes 2017-12-19 02:17:27 +01:00
commit 1e0ea6d4b3
94 changed files with 26586 additions and 26244 deletions

13
src/.indent.pro vendored Normal file
View file

@ -0,0 +1,13 @@
--blank-lines-after-declarations
--blank-lines-after-procedures
--break-before-boolean-operator
--continue-at-parentheses
--declaration-indentation1
--dont-break-function-decl-args
--dont-break-procedure-type
--line-length120
--no-blank-lines-after-commas
--no-space-after-casts
--no-space-after-function-call-names
--no-space-after-parentheses
--no-tabs

View file

@ -1,8 +1,8 @@
/* BeOS_print.h */
/* printing support for Tux Paint */
/* Marcin 'Shard' Konicki <shard@beosjournal.org> */
/* BeOS_print.h */
/* printing support for Tux Paint */
/* Marcin 'Shard' Konicki <shard@beosjournal.org> */
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -18,25 +18,25 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
*/
/* Jan. 17, 2003 */
/* $Id$ */
*/
/* Jan. 17, 2003 */
/* $Id$ */
#ifndef __BEOS_PRINT_H__
#define __BEOS_PRINT_H__
#include "SDL.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#endif /* __cplusplus */
extern int SurfacePrint(SDL_Surface * surf);
extern int IsPrinterAvailable();
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __BEOS_PRINT__ */
}
#endif /* __cplusplus */
#endif /* __BEOS_PRINT__ */

View file

@ -59,23 +59,23 @@ enum
/* Hex codes: */
const int default_color_hexes[NUM_DEFAULT_COLORS][3] = {
{0, 0, 0}, /* Black */
{128, 128, 128}, /* Dark grey */
{192, 192, 192}, /* Light grey */
{255, 255, 255}, /* White */
{255, 0, 0}, /* Red */
{255, 128, 0}, /* Orange */
{255, 255, 0}, /* Yellow */
{160, 228, 128}, /* Light green */
{33, 148, 70}, /* Dark green */
{138, 168, 205}, /* Sky blue */
{50, 100, 255}, /* Blue */
{186, 157, 255}, /* Lavender */
{128, 0, 128}, /* Purple */
{255, 165, 211}, /* Pink */
{128, 80, 0}, /* Brown */
{226, 189, 166}, /* Tan */
{247, 228, 219} /* Beige */
{0, 0, 0}, /* Black */
{128, 128, 128}, /* Dark grey */
{192, 192, 192}, /* Light grey */
{255, 255, 255}, /* White */
{255, 0, 0}, /* Red */
{255, 128, 0}, /* Orange */
{255, 255, 0}, /* Yellow */
{160, 228, 128}, /* Light green */
{33, 148, 70}, /* Dark green */
{138, 168, 205}, /* Sky blue */
{50, 100, 255}, /* Blue */
{186, 157, 255}, /* Lavender */
{128, 0, 128}, /* Purple */
{255, 165, 211}, /* Pink */
{128, 80, 0}, /* Brown */
{226, 189, 166}, /* Tan */
{247, 228, 219} /* Beige */
};

View file

@ -84,7 +84,7 @@
// since gcc-2.5
#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#else
#define NORETURN
#define FUNCTION

View file

@ -84,8 +84,8 @@ void do_setcursor(SDL_Cursor * c)
void free_cursor(SDL_Cursor ** cursor)
{
if (*cursor)
{
SDL_FreeCursor(*cursor);
*cursor = NULL;
}
{
SDL_FreeCursor(*cursor);
*cursor = NULL;
}
}

View file

@ -25,7 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#ifndef __USE_GNU
#define __USE_GNU /* for strcasestr() */
#define __USE_GNU /* for strcasestr() */
#endif
#include <string.h>
#include <locale.h>
@ -67,188 +67,189 @@
///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale)
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files, unsigned i,
const char *restrict const locale)
{
dirlen = dirlen;
while (i--)
{
int loadable = 0;
const char *restrict const cp = strchr(files[i].str, '.');
show_progress_bar_(screen, texture, renderer);
if (cp)
{
// need gcc 3.4 for the restrict in this location
const char * /*restrict */ const suffixes[] =
{ "ttc", "dfont", "pfa", "pfb", "otf", "ttf", };
int j = sizeof suffixes / sizeof suffixes[0];
while (j--)
{
// only check part, because of potential .gz or .bz2 suffix
if (!strncasecmp(cp + 1, suffixes[j], strlen(suffixes[j])))
{
loadable = 1;
break;
}
}
}
if (!loadable)
{
if (strcasestr(files[i].str, "/rsrc"))
loadable = 1;
}
// Loadable: TrueType (.ttf), OpenType (.otf), Type1 (.pfa and .pfb),
// and various useless bitmap fonts. Compressed files (with .gz or .bz2)
// should also work. A *.dfont is pretty much a Mac resource fork in a normal
// file, and may load with some library versions.
if (loadable)
{
char fname[512];
TuxPaint_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
int loadable = 0;
const char *restrict const cp = strchr(files[i].str, '.');
show_progress_bar_(screen, texture, renderer);
if (cp)
{
// need gcc 3.4 for the restrict in this location
const char * /*restrict */ const suffixes[] =
{ "ttc", "dfont", "pfa", "pfb", "otf", "ttf", };
int j = sizeof suffixes / sizeof suffixes[0];
while (j--)
{
// only check part, because of potential .gz or .bz2 suffix
if (!strncasecmp(cp + 1, suffixes[j], strlen(suffixes[j])))
{
loadable = 1;
break;
}
}
}
if (!loadable)
{
if (strcasestr(files[i].str, "/rsrc"))
loadable = 1;
}
// Loadable: TrueType (.ttf), OpenType (.otf), Type1 (.pfa and .pfb),
// and various useless bitmap fonts. Compressed files (with .gz or .bz2)
// should also work. A *.dfont is pretty much a Mac resource fork in a normal
// file, and may load with some library versions.
if (loadable)
{
char fname[512];
TuxPaint_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
#ifdef DEBUG
printf("Loading font: %s (locale is: %s)\n", fname, (locale ? locale : "NULL")); //EP
printf("Loading font: %s (locale is: %s)\n", fname, (locale ? locale : "NULL")); //EP
#endif
if (locale && strstr(fname, "locale") && !all_locale_fonts)
{
char fname_check[512];
/* We're (probably) loading from our locale fonts folder; ONLY load our locale's font */
snprintf(fname_check, sizeof fname_check, "%s/%s.ttf", dir, locale);
if (locale && strstr(fname, "locale") && !all_locale_fonts)
{
char fname_check[512];
/* We're (probably) loading from our locale fonts folder; ONLY load our locale's font */
snprintf(fname_check, sizeof fname_check, "%s/%s.ttf", dir, locale);
#ifdef DEBUG
printf("checking \"%s\" vs \"%s\"\n", fname_check, fname); //EP
printf("checking \"%s\" vs \"%s\"\n", fname_check, fname); //EP
#endif
if (strcmp(fname, fname_check) == 0)
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
else
font = NULL;
}
else
{
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
}
if (font)
{
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
const char *restrict const style = TuxPaint_Font_FontFaceStyleName(font);
if (strcmp(fname, fname_check) == 0)
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
else
font = NULL;
}
else
{
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
}
if (font)
{
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
const char *restrict const style = TuxPaint_Font_FontFaceStyleName(font);
#ifdef DEBUG
int numfaces = TTF_FontFaces(font->ttf_font);
if (numfaces != 1)
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str,
family, style);
int numfaces = TTF_FontFaces(font->ttf_font);
printf("success: tpf: 0x%x tpf->ttf_font: 0x%x\n",
(unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
if (numfaces != 1)
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str, family, style);
printf("success: tpf: 0x%x tpf->ttf_font: 0x%x\n", (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
#endif
// These fonts crash Tux Paint via a library bug.
int blacklisted = !strcmp("Zapfino", family) || !strcmp("Elvish Ring NFI", family);
// These fonts crash Tux Paint via a library bug.
int blacklisted = !strcmp("Zapfino", family) || !strcmp("Elvish Ring NFI", family);
// First, the blacklist. We list font families that can crash Tux Paint
// via bugs in the SDL_ttf library. We also test fonts to be sure that
// they have both uppercase and lowercase letters. Note that we do not
// test for "Aa", because it is OK if uppercase and lowercase are the
// same (but not nice -- such fonts get a low score later).
//
// Most locales leave the blacklist strings alone: "QX" and "qx"
// (it is less destructive to use the scoring strings instead)
//
// Locales that absolutely require all fonts to have some
// extra characters should use "QX..." and "qx...", where "..."
// are some characters you absolutely require in all fonts.
//
// Locales with absolutely NO use for ASCII may use "..." and "...",
// where "..." are some characters you absolutely require in
// all fonts. This would be the case for a locale in which it is
// impossible for a user to type ASCII letters.
//
// Most translators should use scoring instead.
if(!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
blacklisted = 1;
// First, the blacklist. We list font families that can crash Tux Paint
// via bugs in the SDL_ttf library. We also test fonts to be sure that
// they have both uppercase and lowercase letters. Note that we do not
// test for "Aa", because it is OK if uppercase and lowercase are the
// same (but not nice -- such fonts get a low score later).
//
// Most locales leave the blacklist strings alone: "QX" and "qx"
// (it is less destructive to use the scoring strings instead)
//
// Locales that absolutely require all fonts to have some
// extra characters should use "QX..." and "qx...", where "..."
// are some characters you absolutely require in all fonts.
//
// Locales with absolutely NO use for ASCII may use "..." and "...",
// where "..." are some characters you absolutely require in
// all fonts. This would be the case for a locale in which it is
// impossible for a user to type ASCII letters.
//
// Most translators should use scoring instead.
if (!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
blacklisted = 1;
if(!blacklisted){
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[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);
user_font_styles[num_font_styles]->style = strdup(style);
user_font_styles[num_font_styles]->score = 0;
if (!blacklisted)
{
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[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);
user_font_styles[num_font_styles]->style = strdup(style);
user_font_styles[num_font_styles]->score = 0;
// TODO: weight specification
// TODO: weight specification
// Now we score fonts to ensure that the best ones will be placed at
// the top of the list. The user will see them first. This sorting is
// especially important for users who have scroll buttons disabled.
// Translators should do whatever is needed to put crummy fonts last.
// distinct uppercase and lowercase (e.g., 'o' vs. 'O')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("oO"));
// Now we score fonts to ensure that the best ones will be placed at
// the top of the list. The user will see them first. This sorting is
// especially important for users who have scroll buttons disabled.
// Translators should do whatever is needed to put crummy fonts last.
// common punctuation (e.g., '?', '!', '.', ',', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext(",.?!"));
// distinct uppercase and lowercase (e.g., 'o' vs. 'O')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("oO"));
// uncommon punctuation (e.g., '@', '#', '*', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext("`\%_@$~#{<(^&*"));
// common punctuation (e.g., '?', '!', '.', ',', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext(",.?!"));
// digits (e.g., '0', '1' and '7')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("017"));
// uncommon punctuation (e.g., '@', '#', '*', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext("`\%_@$~#{<(^&*"));
// distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("O0"));
// digits (e.g., '0', '1' and '7')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("017"));
// distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("1Il|"));
// distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("O0"));
// translation spares -- design not finalized
// distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("1Il|"));
// translation spares -- design not finalized
#if 0
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1a"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1b"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9a"))*9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9b"))*9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1a"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1b"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9a")) * 9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9b")) * 9;
#endif
// this really should be dynamic, avoiding the need for a special build
#ifdef OLPC_XO
// Maybe German adds a "\xc2\xb7" (middle dot) and colon here? The key wouldn't change though.
user_font_styles[num_font_styles]->score += charset_works(font, "\xc3\x97\xc3\xb7"); // multiply and divide
// Maybe German adds a "\xc2\xb7" (middle dot) and colon here? The key wouldn't change though.
user_font_styles[num_font_styles]->score += charset_works(font, "\xc3\x97\xc3\xb7"); // multiply and divide
#endif
// FIXME: add topology tests ('A' has one hole, 'B' has two holes, etc.)
// FIXME: add topology tests ('A' has one hole, 'B' has two holes, etc.)
num_font_styles++;
num_font_styles++;
//printf("Accepted: %s, %s, %s, score(%d)\n", files[i].str, family, style, user_font_styles[num_font_styles]->score);
files[i].str = NULL; // so free() won't crash -- we stole the memory
}
else
{
files[i].str = NULL; // so free() won't crash -- we stole the memory
}
else
{
#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
}
TuxPaint_Font_CloseFont(font);
}
else
{
}
TuxPaint_Font_CloseFont(font);
}
else
{
#if 0
// THREADED_FONTS
printf("could not open %s\n", files[i].str);
printf("could not open %s\n", files[i].str);
#endif
}
}
}
free(files[i].str);
}
free(files[i].str);
}
free(files);
}
@ -258,16 +259,14 @@ 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;
return -strcmp(s1, s2); /* FIXME: Should we try strcasecmp, to group things together despite uppercase/lowercase in filenames (e.g., Jigsaw* vs jigsaw* Starters)??? -bjk 2009.10.11 */
return -strcmp(s1, s2); /* FIXME: Should we try strcasecmp, to group things together despite uppercase/lowercase in filenames (e.g., Jigsaw* vs jigsaw* Starters)??? -bjk 2009.10.11 */
}
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn) (SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
const char *restrict const locale)
{
DIR *d;
@ -289,123 +288,124 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
return;
for (;;)
{
struct dirent *f = readdir(d);
int filetype = TP_FTW_UNKNOWN;
{
struct dirent *f = readdir(d);
int filetype = TP_FTW_UNKNOWN;
if (!f)
break;
if (f->d_name[0] == '.')
continue;
if (!f)
break;
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)
{
default:
continue;
case DT_REG:
if (!rsrc) // if maybe opening resource files, need st_size
filetype = TP_FTW_NORMAL;
break;
case DT_DIR:
filetype = TP_FTW_DIRECTORY;
break;
case DT_UNKNOWN:
case DT_LNK:
;
}
switch (f->d_type)
{
default:
continue;
case DT_REG:
if (!rsrc) // if maybe opening resource files, need st_size
filetype = TP_FTW_NORMAL;
break;
case DT_DIR:
filetype = TP_FTW_DIRECTORY;
break;
case DT_UNKNOWN:
case DT_LNK:
;
}
#else
#warning Failed to see DT_UNKNOWN
#endif
#if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
d_namlen = f->d_namlen;
d_namlen = f->d_namlen;
#else
d_namlen = strlen(f->d_name);
d_namlen = strlen(f->d_name);
#endif
add_rsrc = 0;
add_rsrc = 0;
if (filetype == TP_FTW_UNKNOWN)
{
struct stat 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))
filetype = TP_FTW_DIRECTORY;
else if (S_ISREG(sbuf.st_mode))
{
filetype = TP_FTW_NORMAL;
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)
{
char *cp;
if (filetype == TP_FTW_UNKNOWN)
{
struct stat sbuf;
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);
else
cp[d_namlen] = '\0';
file_names[num_file_names].str = cp;
file_names[num_file_names].len = d_namlen;
num_file_names++;
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))
filetype = TP_FTW_DIRECTORY;
else if (S_ISREG(sbuf.st_mode))
{
filetype = TP_FTW_NORMAL;
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)
{
char *cp;
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);
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)
{
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);
}
cp = malloc(d_namlen + 1);
memcpy(cp, f->d_name, d_namlen + 1);
dir_names[num_dir_names].str = cp;
dir_names[num_dir_names].len = d_namlen;
num_dir_names++;
}
}
if (filetype == TP_FTW_DIRECTORY)
{
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);
}
cp = malloc(d_namlen + 1);
memcpy(cp, f->d_name, d_namlen + 1);
dir_names[num_dir_names].str = cp;
dir_names[num_dir_names].len = d_namlen;
num_dir_names++;
}
}
closedir(d);
show_progress_bar_(screen, texture, renderer);
dir[dirlen] = '\0'; // repair it (clobbered for stat() call above)
dir[dirlen] = '\0'; // repair it (clobbered for stat() call above)
if (1 || file_names) // Now ALWAYS calling callback function, so stamp loader can notice top-level directories (even if there are only subdirs, and no files, inside) -bjk 2007.05.16
{
if (1 || file_names) // Now ALWAYS calling callback function, so stamp loader can notice top-level directories (even if there are only subdirs, and no files, inside) -bjk 2007.05.16
{
// 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--)
{
free(file_names[num_file_names].str);
}
free(file_names);
qsort(file_names, num_file_names, sizeof *file_names, compare_ftw_str);
while (num_file_names--)
{
free(file_names[num_file_names].str);
}
free(file_names);
#else
fn(screen, texture, renderer, dir, dirlen, file_names, num_file_names, locale);
fn(screen, texture, renderer, dir, dirlen, file_names, num_file_names, locale);
#endif
}
}
if (dir_names)
{
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
while (num_dir_names--)
{
memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1);
tp_ftw(screen, texture, renderer, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str);
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
while (num_dir_names--)
{
memcpy(dir + dirlen, dir_names[num_dir_names].str, dir_names[num_dir_names].len + 1);
tp_ftw(screen, texture, renderer, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str);
}
free(dir_names);
}
free(dir_names);
}
}

View file

@ -45,16 +45,14 @@ typedef struct tp_ftw_str
} tp_ftw_str;
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale);
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files, unsigned i,
const char *restrict const locale);
int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn) (SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
const char *restrict const locale);
#endif

File diff suppressed because it is too large Load diff

View file

@ -63,10 +63,10 @@
#define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0)
#define SDL_Thread int
#define SDL_mutex int
#define SDL_CreateMutex() 0 // creates in released state
#define SDL_CreateMutex() 0 // creates in released state
#define SDL_DestroyMutex(lock)
#define SDL_mutexP(lock) // take lock
#define SDL_mutexV(lock) // release lock
#define SDL_mutexP(lock) // take lock
#define SDL_mutexV(lock) // release lock
#endif
#endif
@ -91,21 +91,23 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
/* Stuff that wraps either SDL_Pango or SDL_TTF for font rendering: */
enum {
enum
{
#ifndef NO_SDLPANGO
FONT_TYPE_PANGO,
#endif
FONT_TYPE_TTF
};
typedef struct TuxPaint_Font_s {
typedef struct TuxPaint_Font_s
{
#ifndef NO_SDLPANGO
SDLPango_Context * pango_context;
SDLPango_Context *pango_context;
#endif
int typ;
TTF_Font * ttf_font;
TTF_Font *ttf_font;
int height;
char * desc;
char *desc;
} TuxPaint_Font;
int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
@ -140,7 +142,7 @@ static int text_sizes[] = {
#endif
12, 18, 24, 36, 48,
56, 64, 96, 112, 128, 160
}; // point sizes
}; // point sizes
#define MIN_TEXT_SIZE 0u
#define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1)
@ -150,12 +152,12 @@ typedef struct style_info
{
char *filename;
char *directory;
char *family; // name like "FooCorp Thunderstruck"
char *style; // junk like "Oblique Demi-Bold"
char *family; // name like "FooCorp Thunderstruck"
char *style; // junk like "Oblique Demi-Bold"
int italic;
int boldness;
int score;
int truetype; // Is it? (TrueType gets priority)
int truetype; // Is it? (TrueType gets priority)
} style_info;
// user's notion of a font
@ -183,15 +185,15 @@ TuxPaint_Font *getfonthandle(int desire);
int charset_works(TuxPaint_Font * font, const char *s);
TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttffilename, int size);
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size);
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
#ifdef NO_SDLPANGO
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
#else
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color);
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color);
#endif
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp, const char *restrict const locale);

View file

@ -33,7 +33,7 @@
/* DIR_SAVE: Where is the user's saved directory?
This is where their saved files are stored
and where the "current_id.txt" file is saved.
Windows predefines "savedir" as:
"C:\Documents and Settings\%USERNAME%\Application Data\TuxPaint"
though it may get overridden with "--savedir" option
@ -60,10 +60,10 @@ const char *datadir;
char *get_fname(const char *const name, int kind)
{
char f[512];
const char *restrict const dir = (kind==DIR_SAVE) ? savedir : datadir;
const char *restrict const dir = (kind == DIR_SAVE) ? savedir : datadir;
// Some mkdir()'s don't like trailing slashes
snprintf(f, sizeof(f), "%s%c%s", dir, (*name)?'/':'\0', name);
snprintf(f, sizeof(f), "%s%c%s", dir, (*name) ? '/' : '\0', name);
return strdup(f);
}

View file

@ -28,7 +28,8 @@
extern const char *savedir;
extern const char *datadir;
enum {
enum
{
DIR_SAVE,
DIR_DATA
};

View file

@ -54,20 +54,21 @@
// setlocale cannot get current default locale of the device.
// Here, JNI and Java Locale class can get the default locale
// if user has not set locale and lang in the config file yet.
static char * android_locale ()
static char *android_locale()
{
static char android_locale_buf[32];
JNIEnv *mEnv = Android_JNI_GetEnv();
jclass mLocaleClass = (*mEnv)->FindClass(mEnv, "java/util/Locale");
jmethodID mGetDefaultMethod = (*mEnv)->GetStaticMethodID(mEnv, mLocaleClass, "getDefault", "()Ljava/util/Locale;");
jobject mLocaleObject = (*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod);
jmethodID mToStringMethod = (*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString", "()Ljava/lang/String;");
jstring mLocaleString = (*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod);
const char* locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0);
strcpy(android_locale_buf, locale);
(*mEnv)->ReleaseStringUTFChars(mEnv, mLocaleString, locale);
printf("android locale %s\n", android_locale_buf);
return android_locale_buf;
static char android_locale_buf[32];
JNIEnv *mEnv = Android_JNI_GetEnv();
jclass mLocaleClass = (*mEnv)->FindClass(mEnv, "java/util/Locale");
jmethodID mGetDefaultMethod = (*mEnv)->GetStaticMethodID(mEnv, mLocaleClass, "getDefault", "()Ljava/util/Locale;");
jobject mLocaleObject = (*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod);
jmethodID mToStringMethod = (*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString", "()Ljava/lang/String;");
jstring mLocaleString = (*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod);
const char *locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0);
strcpy(android_locale_buf, locale);
(*mEnv)->ReleaseStringUTFChars(mEnv, mLocaleString, locale);
printf("android locale %s\n", android_locale_buf);
return android_locale_buf;
}
#endif
@ -255,7 +256,7 @@ int need_right_to_left_word;
const char *lang_prefix, *short_lang_prefix;
int num_wished_langs = 0;
w_langs wished_langs[255];
w_langs wished_langs[255];
static const language_to_locale_struct language_to_locale_array[] = {
{"english", "C"},
@ -390,10 +391,10 @@ static const language_to_locale_struct language_to_locale_array[] = {
{"northern-sotho", "nso_ZA.UTF-8"},
{"sesotho-sa-leboa", "nso_ZA.UTF-8"},
{"occitan", "oc_FR.UTF-8"},
{"odia", "or_IN.UTF-8"}, // Proper spelling
{"oriya", "or_IN.UTF-8"}, // Alternative
{"ojibwe", "oj_CA.UTF-8"}, // Proper spelling
{"ojibway", "oj_CA.UTF-8"}, // For compatibility
{"odia", "or_IN.UTF-8"}, // Proper spelling
{"oriya", "or_IN.UTF-8"}, // Alternative
{"ojibwe", "oj_CA.UTF-8"}, // Proper spelling
{"ojibway", "oj_CA.UTF-8"}, // For compatibility
{"punjabi", "pa_IN.UTF-8"},
{"panjabi", "pa_IN.UTF-8"},
{"polish", "pl_PL.UTF-8"},
@ -409,7 +410,7 @@ static const language_to_locale_struct language_to_locale_array[] = {
{"sanskrit", "sa_IN.UTF-8"},
{"santali-devaganari", "sat_IN.UTF-8"},
{"santali-ol-chiki", "sat@olchiki"},
{"serbian", "sr_RS.UTF-8"}, /* Was sr_YU, but that's not in /usr/share/i18n/SUPPORTED, and sr_RS is -bjk 2014.08.04 */
{"serbian", "sr_RS.UTF-8"}, /* Was sr_YU, but that's not in /usr/share/i18n/SUPPORTED, and sr_RS is -bjk 2014.08.04 */
{"serbian-latin", "sr_RS@latin"},
{"shuswap", "shs_CA.UTF-8"},
{"secwepemctin", "shs_CA.UTF-8"},
@ -426,7 +427,7 @@ static const language_to_locale_struct language_to_locale_array[] = {
{"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 */
{"tibetan", "bo_CN.UTF-8"}, /* Based on: http://texinfo.org/pipermail/texinfo-pretest/2005-April/000334.html */
{"turkish", "tr_TR.UTF-8"},
{"twi", "tw_GH.UTF-8"},
{"ukrainian", "uk_UA.UTF-8"},
@ -449,13 +450,12 @@ static const language_to_locale_struct language_to_locale_array[] = {
/* Show available languages: */
static void show_lang_usage(int exitcode)
{
FILE * f = exitcode ? stderr : stdout;
FILE *f = exitcode ? stderr : stdout;
const char *const prg = "tuxpaint";
fprintf(f,
"\n"
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
/* C */ " english american-english\n"
/* ach */" acholi acoli\n"
fprintf(f, "\n" "Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
/* C */ " english american-english\n"
/* ach */ " acholi acoli\n"
/* af */ " afrikaans\n"
/* ak */ " akan twi-fante\n"
/* sq */ " albanian\n"
@ -464,7 +464,7 @@ static void show_lang_usage(int exitcode)
/* an */ " aragones\n"
/* hy */ " armenian hayeren\n"
/* as */ " assamese\n"
/* ast */" asturian\n"
/* ast */ " asturian\n"
/* en_AU */ " australian-english\n"
/* az */ " azerbaijani\n"
/* bm */ " bambara\n"
@ -498,7 +498,7 @@ static void show_lang_usage(int exitcode)
/* ka */ " georgian\n"
/* de */ " german deutsch\n"
/* el */ " greek\n"
/* gos */" gronings zudelk-veenkelonioals\n"
/* gos */ " gronings zudelk-veenkelonioals\n"
/* gu */ " gujarati\n"
/* he */ " hebrew\n"
/* hi */ " hindi\n"
@ -513,18 +513,18 @@ static void show_lang_usage(int exitcode)
/* ks@devanagari */ " kashmiri-devanagari\n"
/* ks */ " kashmiri-perso-arabic\n"
/* km */ " khmer\n"
/* cgg */" kiga chiga\n"
/* cgg */ " kiga chiga\n"
/* rw */ " kinyarwanda\n"
/* tlh */" klingon tlhIngan\n"
/* kok */" konkani-devaganari\n"
/* kok@roman */" konkani-roman\n"
/* tlh */ " klingon tlhIngan\n"
/* kok */ " konkani-devaganari\n"
/* kok@roman */ " konkani-roman\n"
/* ko */ " korean\n"
/* ku */ " kurdish\n"
/* lv */ " latvian\n"
/* lt */ " lithuanian lietuviu\n"
/* lg */ " luganda\n"
/* lb */ " luxembourgish letzebuergesch\n"
/* mai */" maithili\n"
/* mai */ " maithili\n"
/* mk */ " macedonian\n"
/* ms */ " malay\n"
/* ml */ " malayalam\n"
@ -535,7 +535,7 @@ static void show_lang_usage(int exitcode)
/* mn */ " mongolian\n"
/* nr */ " ndebele\n"
/* ne */ " nepali\n"
/* nso */" northern-sotho sesotho-sa-leboa\n"
/* nso */ " northern-sotho sesotho-sa-leboa\n"
/* nn */ " norwegian nynorsk norsk\n"
/* oc */ " occitan\n"
/* or */ " odia oriya\n"
@ -547,8 +547,8 @@ static void show_lang_usage(int exitcode)
/* ro */ " romanian\n"
/* ru */ " russian russkiy\n"
/* sa */ " sanskrit\n"
/* sat */" santali-devaganari\n"
/* sat@olchiki */" santali-ol-chiki\n"
/* sat */ " santali-devaganari\n"
/* sat@olchiki */ " santali-ol-chiki\n"
/* gd */ " scottish scottish-gaelic ghaidhlig\n"
/* sr */ " serbian\n"
/* sr@latin */ " serbian-latin\n"
@ -573,15 +573,15 @@ static void show_lang_usage(int exitcode)
/* tr */ " turkish\n"
/* uk */ " ukrainian\n"
/* ur */ " urdu\n"
/* ca@valencia */ " valencian valencia\n"
/* ca@valencia */ " valencian valencia\n"
/* ve */ " venda\n"
/* vec */" venetian veneto\n"
/* vec */ " venetian veneto\n"
/* vi */ " vietnamese\n"
/* wa */ " walloon walon\n"
/* wo */ " wolof\n"
/* cy */ " welsh cymraeg\n"
/* xh */ " xhosa\n"
/* zam */" zapotec miahuatlan-zapotec\n"
/* zam */ " zapotec miahuatlan-zapotec\n"
/* zu */ " zulu\n"
"\n", prg);
exit(exitcode);
@ -593,13 +593,13 @@ static void show_lang_usage(int exitcode)
static void show_locale_usage(FILE * f, const char *const prg)
{
fprintf(f,
"\n"
"Usage: %s [--locale LOCALE]\n"
"\n"
"LOCALE may be one of:\n"
" C (English American English)\n"
"\n"
"Usage: %s [--locale LOCALE]\n"
"\n"
"LOCALE may be one of:\n"
" C (English American English)\n"
" ach_UG (Acholi Acoli)\n"
" af_ZA (Afrikaans)\n"
" af_ZA (Afrikaans)\n"
" ak_GH (Akan Twi-Fante)\n"
" am_ET (Amharic)\n"
" ar_SA (Arabic)\n"
@ -615,44 +615,44 @@ static void show_locale_usage(FILE * f, const char *const prg)
" brx_IN (Bodo)\n"
" bs_BA (Bosnian)\n"
" nb_NO (Bokmal)\n"
" pt_BR (Brazilian Brazilian Portuguese Portugues Brazilian)\n"
" br_FR (Breton Brezhoneg)\n"
" en_AU (Australian English)\n"
" en_CA (Canadian English)\n"
" en_GB (British British English)\n"
" en_ZA (South African English)\n"
" bg_BG (Bulgarian)\n"
" ca_ES (Catalan Catala)\n"
" pt_BR (Brazilian Brazilian Portuguese Portugues Brazilian)\n"
" br_FR (Breton Brezhoneg)\n"
" en_AU (Australian English)\n"
" en_CA (Canadian English)\n"
" en_GB (British British English)\n"
" en_ZA (South African English)\n"
" bg_BG (Bulgarian)\n"
" ca_ES (Catalan Catala)\n"
" ca_ES@valencia (Valencian Valencia)n"
" zh_CN (Chinese-Simplified)\n"
" zh_TW (Chinese-Traditional)\n"
" cs_CZ (Czech Cesky)\n"
" da_DK (Danish Dansk)\n"
" doi_IN (Dogri)\n"
" nl_NL (Dutch)\n"
" zh_CN (Chinese-Simplified)\n"
" zh_TW (Chinese-Traditional)\n"
" cs_CZ (Czech Cesky)\n"
" da_DK (Danish Dansk)\n"
" doi_IN (Dogri)\n"
" nl_NL (Dutch)\n"
" fa_IR (Persian)\n"
" ff_SN (Fulah)\n"
" fi_FI (Finnish Suomi)\n"
" fo_FO (Faroese)\n"
" fr_FR (French Francais)\n"
" ga_IE (Irish Gaelic Gaidhlig)\n"
" gd_GB (Scottish Gaelic Ghaidhlig)\n"
" gl_ES (Galician Galego)\n"
" gos_NL (Gronings Zudelk Veenkelonioals)\n"
" gu_IN (Gujarati)\n"
" de_DE (German Deutsch)\n"
" fi_FI (Finnish Suomi)\n"
" fo_FO (Faroese)\n"
" fr_FR (French Francais)\n"
" ga_IE (Irish Gaelic Gaidhlig)\n"
" gd_GB (Scottish Gaelic Ghaidhlig)\n"
" gl_ES (Galician Galego)\n"
" gos_NL (Gronings Zudelk Veenkelonioals)\n"
" gu_IN (Gujarati)\n"
" de_DE (German Deutsch)\n"
" eo (Esperanto)\n"
" et_EE (Estonian)\n"
" el_GR (Greek)\n"
" he_IL (Hebrew)\n"
" hi_IN (Hindi)\n"
" hr_HR (Croatian Hrvatski)\n"
" hu_HU (Hungarian Magyar)\n"
" et_EE (Estonian)\n"
" el_GR (Greek)\n"
" he_IL (Hebrew)\n"
" hi_IN (Hindi)\n"
" hr_HR (Croatian Hrvatski)\n"
" hu_HU (Hungarian Magyar)\n"
" cgg_UG (Kiga Chiga)\n"
" tlh (Klingon tlhIngan)\n"
" is_IS (Icelandic Islenska)\n"
" id_ID (Indonesian Bahasa Indonesia)\n"
" it_IT (Italian Italiano)\n"
" tlh (Klingon tlhIngan)\n"
" is_IS (Icelandic Islenska)\n"
" id_ID (Indonesian Bahasa Indonesia)\n"
" it_IT (Italian Italiano)\n"
" iu_CA (Inuktitut)\n"
" ja_JP (Japanese)\n"
" ka_GE (Georgian)\n"
@ -679,16 +679,16 @@ static void show_locale_usage(FILE * f, const char *const prg)
" nr_ZA (Ndebele)\n"
" ne_NP (Nepali)\n"
" nso_ZA (Northern Sotho Sotho sa Leboa)\n"
" nn_NO (Norwegian Nynorsk Norsk)\n"
" oc_FR (Occitan)\n"
" oj_CA (Ojibway)\n"
" nn_NO (Norwegian Nynorsk Norsk)\n"
" oc_FR (Occitan)\n"
" oj_CA (Ojibway)\n"
" or_IN (Odia Oriya)\n"
" pa_IN (Punjabi Panjabi)\n"
" pl_PL (Polish Polski)\n"
" pt_PT (Portuguese Portugues)\n"
" ro_RO (Romanian)\n"
" ru_RU (Russian Russkiy)\n"
" rw_RW (Kinyarwanda)\n"
" pa_IN (Punjabi Panjabi)\n"
" pl_PL (Polish Polski)\n"
" pt_PT (Portuguese Portugues)\n"
" ro_RO (Romanian)\n"
" ru_RU (Russian Russkiy)\n"
" rw_RW (Kinyarwanda)\n"
" sa_IN (Sanskrit)\n"
" sat_IN (Santali)\n"
" sat@olchiki (Santali (Ol-Chiki))\n"
@ -696,10 +696,10 @@ static void show_locale_usage(FILE * f, const char *const prg)
" sd_IN (Sindhii (Perso-Arabic))\n"
" shs_CA (Shuswap Secwepemctin)\n"
" si_LK (Sinhala)\n"
" sk_SK (Slovak)\n"
" sl_SI (Slovenian)\n"
" sk_SK (Slovak)\n"
" sl_SI (Slovenian)\n"
" son (Songhay)\n"
" sq_AL (Albanian)\n"
" sq_AL (Albanian)\n"
" sr_YU (Serbian (cyrillic))\n"
" sr_RS@latin (Serbian (latin))\n"
" es_ES (Spanish Espanol)\n"
@ -707,12 +707,12 @@ static void show_locale_usage(FILE * f, const char *const prg)
" es_MX (Mexican Mexican Spanish Espanol Mejicano)\n"
" sw_TZ (Swahili)\n"
" sv_SE (Swedish Svenska)\n"
" ta_IN (Tamil)\n"
" ta_IN (Tamil)\n"
" te_IN (Telugu)\n"
" tl_PH (Tagalog)\n"
" bo_CN (Tibetan)\n"
" th_TH (Thai)\n"
" tr_TR (Turkish)\n"
" tl_PH (Tagalog)\n"
" bo_CN (Tibetan)\n"
" th_TH (Thai)\n"
" tr_TR (Turkish)\n"
" tw_GH (Twi)\n"
" uk_UA (Ukrainian)\n"
" ur_IN (Urdu)\n"
@ -722,10 +722,7 @@ static void show_locale_usage(FILE * f, const char *const prg)
" wa_BE (Walloon)\n"
" wo_SN (Wolof)\n"
" cy_GB (Welsh Cymraeg)\n"
" xh_ZA (Xhosa)\n"
" zam (Zapoteco-Miahuatlan)\n"
" zu_ZA (Zulu)\n"
"\n", prg);
" xh_ZA (Xhosa)\n" " zam (Zapoteco-Miahuatlan)\n" " zu_ZA (Zulu)\n" "\n", prg);
}
@ -740,10 +737,10 @@ static int search_int_array(int l, int *array)
int i;
for (i = 0; array[i] != -1; i++)
{
if (array[i] == l)
return 1;
}
{
if (array[i] == l)
return 1;
}
return 0;
}
@ -754,17 +751,19 @@ static void ctype_utf8(void)
{
#ifndef _WIN32
/* FIXME: should this iterate over more locales?
A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */
const char *names[] = {"en_US.UTF8","en_US.UTF-8","UTF8","UTF-8","C.UTF-8"};
int i = sizeof(names)/sizeof(names[0]);
for(;;){
if(iswprint((wchar_t)0xf7)) // division symbol -- which is in Latin-1 :-/
return;
if(--i < 0)
break;
setlocale(LC_CTYPE,names[i]);
setlocale(LC_MESSAGES,names[i]);
}
A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */
const char *names[] = { "en_US.UTF8", "en_US.UTF-8", "UTF8", "UTF-8", "C.UTF-8" };
int i = sizeof(names) / sizeof(names[0]);
for (;;)
{
if (iswprint((wchar_t) 0xf7)) // division symbol -- which is in Latin-1 :-/
return;
if (--i < 0)
break;
setlocale(LC_CTYPE, names[i]);
setlocale(LC_MESSAGES, names[i]);
}
fprintf(stderr, "Failed to find a locale with iswprint() working!\n");
#endif
}
@ -773,11 +772,12 @@ static void ctype_utf8(void)
static const char *language_to_locale(const char *langstr)
{
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
while (i--)
{
if (!strcmp(langstr, language_to_locale_array[i].language))
return language_to_locale_array[i].locale;
}
{
if (!strcmp(langstr, language_to_locale_array[i].language))
return language_to_locale_array[i].locale;
}
if (strcmp(langstr, "help") == 0 || strcmp(langstr, "list") == 0)
show_lang_usage(0);
fprintf(stderr, "%s is an invalid language\n", langstr);
@ -797,6 +797,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
size_t len_baseloc;
int found = 0;
int i;
// printf("langint %i\n", langint);
if (!loc)
@ -808,75 +809,73 @@ static void set_langint_from_locale_string(const char *restrict loc)
if it still fails, try to find language and country code without the variant,
finally scan just the lang part.
as a last resource reverse the scanning
*/
*/
if(dot)
if (dot)
*dot = '\0';
if (cntrycode)
{
ccodeaux = strdup(cntrycode);
*cntrycode = '\0';
}
{
ccodeaux = strdup(cntrycode);
*cntrycode = '\0';
}
if (at)
{
ataux = strdup(at);
*at = '\0';
if(cntrycode)
{
/* ll_CC@variant */
//if (found == 0) printf("ll_CC@variant check\n");
snprintf(straux, 255, "%s%s%s", baseloc, ccodeaux, ataux);
ataux = strdup(at);
*at = '\0';
if (cntrycode)
{
/* ll_CC@variant */
//if (found == 0) printf("ll_CC@variant check\n");
snprintf(straux, 255, "%s%s%s", baseloc, ccodeaux, ataux);
len_baseloc = strlen(straux);
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
}
}
}
/* ll@variant */
//if (found == 0) printf("ll@variant check\n");
snprintf(straux, 255, "%s%s", baseloc, ataux);
len_baseloc = strlen(straux);
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
}
}
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
}
}
}
/* ll@variant*/
//if (found == 0) printf("ll@variant check\n");
snprintf(straux, 255, "%s%s", baseloc, ataux);
len_baseloc = strlen(straux);
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
}
}
}
if(cntrycode)
if (cntrycode)
{
/* ll_CC */
//if (found == 0) printf("ll_CC check\n");
snprintf(straux, 255, "%s%s",baseloc, ccodeaux);
snprintf(straux, 255, "%s%s", baseloc, ccodeaux);
len_baseloc = strlen(straux);
/* Which, if any, of the locales is it? */
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
}
}
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
}
}
}
/* ll */
@ -885,15 +884,14 @@ static void set_langint_from_locale_string(const char *restrict loc)
/* Which, if any, of the locales is it? */
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
}
}
}
/* Last resource, we should never arrive here, this check depends
on the right order in lang_prefixes[]
@ -903,21 +901,21 @@ static void set_langint_from_locale_string(const char *restrict loc)
// printf("Language still not found: loc= %s Trying reverse check as last resource...\n", loc);
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (!strncasecmp(loc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (!strncasecmp(loc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
}
}
}
// printf("langint %i, lang_ext %s\n", langint, lang_prefixes[langint]);
free(baseloc);
if (ataux)
free(ataux);
if (ccodeaux)
free(ccodeaux);
free(ccodeaux);
}
#define HAVE_SETENV
@ -930,8 +928,9 @@ static void mysetenv(const char *name, const char *value)
#ifdef HAVE_SETENV
setenv(name, value, 1);
#else
int len = strlen(name)+1+strlen(value)+1;
int len = strlen(name) + 1 + strlen(value) + 1;
char *str = malloc(len);
sprintf(str, "%s=%s", name, value);
putenv(str);
#endif
@ -939,32 +938,32 @@ static void mysetenv(const char *name, const char *value)
static int set_current_language(const char *restrict locale_choice) MUST_CHECK;
static int set_current_language(const char *restrict loc)
static int set_current_language(const char *restrict loc)
{
int i;
int y_nudge = 0;
char * oldloc;
char *oldloc;
char *env_language;
if (strlen(loc) > 0)
{
/* Got command line or config file language */
mysetenv("LANGUAGE", loc);
}
else
{
/* Find what language to use from env vars */
if (getenv("LANGUAGE") == NULL)
{
if (getenv("LC_ALL"))
mysetenv("LANGUAGE", getenv("LC_ALL"));
else if (getenv("LC_MESSAGES"))
mysetenv("LANGUAGE", getenv("LC_MESSAGES"));
else if (getenv("LANG"))
mysetenv("LANGUAGE", getenv("LANG"));
/* Got command line or config file language */
mysetenv("LANGUAGE", loc);
}
else
{
/* Find what language to use from env vars */
if (getenv("LANGUAGE") == NULL)
{
if (getenv("LC_ALL"))
mysetenv("LANGUAGE", getenv("LC_ALL"));
else if (getenv("LC_MESSAGES"))
mysetenv("LANGUAGE", getenv("LC_MESSAGES"));
else if (getenv("LANG"))
mysetenv("LANGUAGE", getenv("LANG"));
}
}
}
oldloc = strdup(loc);
@ -972,14 +971,14 @@ static int set_current_language(const char *restrict loc)
after that, ctype_utf8() call will test the compatibility with utf8 and try to load
a different locale if the resulting one is not compatible. */
#ifdef DEBUG
printf ("Locale BEFORE is: %s\n", setlocale(LC_ALL,NULL));//EP
printf("Locale BEFORE is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif
setlocale(LC_ALL, "");
setlocale(LC_ALL, loc);
ctype_utf8();
#ifdef DEBUG
printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
#endif
printf("Locale AFTER is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif
bindtextdomain("tuxpaint", LOCALEDIR);
/* Old version of glibc does not have bind_textdomain_codeset() */
@ -997,78 +996,82 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
loc = setlocale(LC_MESSAGES, NULL);
#endif
if (oldloc && loc && strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0) {
/* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */
if (oldloc && loc && strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0)
{
/* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */
/* Albert's comments from December 2009:
gettext() won't even bother to look up messages unless it
is totally satisfied that you are using one of the locales that
it ships with! Make gettext() unhappy, and it'll switch to the
lobotomized 7-bit Linux "C" locale just to spite you.
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/localedata/SUPPORTED?content-type=text/x-cvsweb-markup&cvsroot=glibc
You can confuse gettext() into mostly behaving. For example, a
user could pick a random UTF-8 locale and change the messages.
In that case, Tux Paint thinks it's in the other locale but the
messages come out right. Like so: LANGUAGE=zam LC_ALL=fr_FR.UTF-8
It doesn't work to leave LC_ALL unset, set it to "zam", set it to "C",
or set it to random nonsense. Yeah, Tux Paint will think it's in
a French locale, but the messages will be Zapotec nonetheless.
Maybe it's time to give up on gettext().
/* Albert's comments from December 2009:
gettext() won't even bother to look up messages unless it
is totally satisfied that you are using one of the locales that
it ships with! Make gettext() unhappy, and it'll switch to the
lobotomized 7-bit Linux "C" locale just to spite you.
[see also: https://sourceforge.net/mailarchive/message.php?msg_name=787b0d920912222352i5ab22834x92686283b565016b%40mail.gmail.com ]
*/
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/localedata/SUPPORTED?content-type=text/x-cvsweb-markup&cvsroot=glibc
/* Unneeded here, this has yet been done as part of ctype_utf8() call before, iterating over a list of locales */
// setlocale(LC_ALL, "en_US.UTF-8"); /* Is it dumb to assume "en_US" is pretty close to "C" locale? */
You can confuse gettext() into mostly behaving. For example, a
user could pick a random UTF-8 locale and change the messages.
In that case, Tux Paint thinks it's in the other locale but the
messages come out right. Like so: LANGUAGE=zam LC_ALL=fr_FR.UTF-8
It doesn't work to leave LC_ALL unset, set it to "zam", set it to "C",
or set it to random nonsense. Yeah, Tux Paint will think it's in
a French locale, but the messages will be Zapotec nonetheless.
mysetenv("LANGUAGE", oldloc);
set_langint_from_locale_string(oldloc);
} else {
Maybe it's time to give up on gettext().
[see also: https://sourceforge.net/mailarchive/message.php?msg_name=787b0d920912222352i5ab22834x92686283b565016b%40mail.gmail.com ]
*/
/* Unneeded here, this has yet been done as part of ctype_utf8() call before, iterating over a list of locales */
// setlocale(LC_ALL, "en_US.UTF-8"); /* Is it dumb to assume "en_US" is pretty close to "C" locale? */
mysetenv("LANGUAGE", oldloc);
set_langint_from_locale_string(oldloc);
}
else
{
#ifdef _WIN32
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", loc);
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", loc);
#endif
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", "C");
}
env_language = strdup(getenv("LANGUAGE"));
int j = 0;
char *env_language_lang;
if (*env_language)
{
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", "C");
}
env_language = strdup(getenv("LANGUAGE"));
int j = 0;
char *env_language_lang;
if (*env_language)
{
env_language_lang = strtok(env_language, ":");
while (env_language_lang != NULL)
{
num_wished_langs++;
set_langint_from_locale_string(env_language_lang);
wished_langs[j].langint = langint;
wished_langs[j].lang_prefix = lang_prefixes[langint];
wished_langs[j].need_own_font = search_int_array(langint, lang_use_own_font);
wished_langs[j].need_right_to_left = search_int_array(langint, lang_use_right_to_left);
wished_langs[j].need_right_to_left_word = search_int_array(langint, lang_use_right_to_left_word);
for (i = 0; lang_y_nudge[i][0] != -1; i++)
{
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
if (lang_y_nudge[i][0] == langint)
{
wished_langs[j].lang_y_nudge = lang_y_nudge[i][1];
//printf("y_nudge = %d\n", y_nudge);
break;
}
}
{
num_wished_langs++;
set_langint_from_locale_string(env_language_lang);
wished_langs[j].langint = langint;
wished_langs[j].lang_prefix = lang_prefixes[langint];
wished_langs[j].need_own_font = search_int_array(langint, lang_use_own_font);
wished_langs[j].need_right_to_left = search_int_array(langint, lang_use_right_to_left);
wished_langs[j].need_right_to_left_word = search_int_array(langint, lang_use_right_to_left_word);
for (i = 0; lang_y_nudge[i][0] != -1; i++)
{
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
if (lang_y_nudge[i][0] == langint)
{
wished_langs[j].lang_y_nudge = lang_y_nudge[i][1];
//printf("y_nudge = %d\n", y_nudge);
break;
}
}
j++;
env_language_lang = strtok(NULL, ":");
}
j++;
env_language_lang = strtok(NULL, ":");
}
if (*env_language)
free(env_language);
free(env_language);
}
// set_langint_from_locale_string(loc);
// set_langint_from_locale_string(loc);
lang_prefix = lang_prefixes[wished_langs[0].langint];
@ -1084,21 +1087,19 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
#if 0
for (i = 0; lang_y_nudge[i][0] != -1; i++)
{
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
if (lang_y_nudge[i][0] == langint)
{
y_nudge = lang_y_nudge[i][1];
//printf("y_nudge = %d\n", y_nudge);
break;
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
if (lang_y_nudge[i][0] == langint)
{
y_nudge = lang_y_nudge[i][1];
//printf("y_nudge = %d\n", y_nudge);
break;
}
}
}
#endif
#ifdef DEBUG
fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n",
lang_prefix, langint,
need_right_to_left ? "(RTL)" : "",
need_right_to_left_word ? "(RTL words)" : "");
lang_prefix, langint, need_right_to_left ? "(RTL)" : "", need_right_to_left_word ? "(RTL words)" : "");
fflush(stderr);
#endif
@ -1118,29 +1119,29 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
printf("lang \"%s\", locale \"%s\"\n", lang, locale);
#endif
if(locale)
{
if(!strcmp(locale,"help"))
if (locale)
{
show_locale_usage(stdout,"tuxpaint");
exit(0);
if (!strcmp(locale, "help"))
{
show_locale_usage(stdout, "tuxpaint");
exit(0);
}
}
}
if(lang)
if (lang)
locale = language_to_locale(lang);
#ifdef __APPLE__
patch_i18n(locale); //EP
patch_i18n(locale); //EP
#endif
#ifdef __ANDROID__
if(locale == NULL)
locale = android_locale();
if (locale == NULL)
locale = android_locale();
#endif
if(locale == NULL)
locale = "";
if (locale == NULL)
locale = "";
return set_current_language(locale);
}

View file

@ -40,133 +40,133 @@
enum
{
LANG_ACH, /* Acholi */
LANG_AF, /* Afrikaans */
LANG_AF, /* Afrikaans */
LANG_AK, /* Akan */
LANG_AM, /* Amharic */
LANG_AN, /* Aragones */
LANG_AR, /* Arabic */
LANG_AR, /* Arabic */
LANG_AS, /* Assamese */
LANG_AST, /* Asturian */
LANG_AZ, /* Azerbaijani */
LANG_BE, /* Belarusian */
LANG_BG, /* Bulgarian */
LANG_BM, /* Bambara */
LANG_AST, /* Asturian */
LANG_AZ, /* Azerbaijani */
LANG_BE, /* Belarusian */
LANG_BG, /* Bulgarian */
LANG_BM, /* Bambara */
LANG_BN, /* Bengali */
LANG_BO, /* Tibetan */
LANG_BR, /* Breton */
LANG_BRX, /* Bodo */
LANG_BO, /* Tibetan */
LANG_BR, /* Breton */
LANG_BRX, /* Bodo */
LANG_BS, /* Bosnian */
LANG_CA_VALENCIA, /* Valencian */
LANG_CA, /* Catalan */
LANG_CA, /* Catalan */
LANG_CGG, /* Kiga */
LANG_CS, /* Czech */
LANG_CY, /* Welsh */
LANG_DA, /* Danish */
LANG_DE, /* German */
LANG_DOI, /* Dogri */
LANG_EL, /* Greek */
LANG_EN, /* English (American) (DEFAULT) */
LANG_EN_AU, /* English (Australian) */
LANG_EN_CA, /* English (Canadian) */
LANG_EN_GB, /* English (British) */
LANG_EN_ZA, /* English (South African) */
LANG_EO, /* Esperanto */
LANG_ES_MX, /* Spanish (Mexican) */
LANG_ES, /* Spanish */
LANG_ET, /* Estonian */
LANG_EU, /* Basque */
LANG_FA, /* Persian */
LANG_CS, /* Czech */
LANG_CY, /* Welsh */
LANG_DA, /* Danish */
LANG_DE, /* German */
LANG_DOI, /* Dogri */
LANG_EL, /* Greek */
LANG_EN, /* English (American) (DEFAULT) */
LANG_EN_AU, /* English (Australian) */
LANG_EN_CA, /* English (Canadian) */
LANG_EN_GB, /* English (British) */
LANG_EN_ZA, /* English (South African) */
LANG_EO, /* Esperanto */
LANG_ES_MX, /* Spanish (Mexican) */
LANG_ES, /* Spanish */
LANG_ET, /* Estonian */
LANG_EU, /* Basque */
LANG_FA, /* Persian */
LANG_FF, /* Fulah */
LANG_FI, /* Finnish */
LANG_FO, /* Faroese */
LANG_FR, /* French */
LANG_GA, /* Irish Gaelic */
LANG_GD, /* Scottish Gaelic */
LANG_GL, /* Galician */
LANG_GR, /* Gronings */
LANG_GU, /* Gujarati */
LANG_HE, /* Hebrew */
LANG_HI, /* Hindi */
LANG_HR, /* Croatian */
LANG_HU, /* Hungarian */
LANG_HY, /* Armenian */
LANG_I_KLINGON_ROMANIZED, /* Klingon (Romanized) */
LANG_ID, /* Indonesian */
LANG_IS, /* Icelandic */
LANG_IT, /* Italian */
LANG_FI, /* Finnish */
LANG_FO, /* Faroese */
LANG_FR, /* French */
LANG_GA, /* Irish Gaelic */
LANG_GD, /* Scottish Gaelic */
LANG_GL, /* Galician */
LANG_GR, /* Gronings */
LANG_GU, /* Gujarati */
LANG_HE, /* Hebrew */
LANG_HI, /* Hindi */
LANG_HR, /* Croatian */
LANG_HU, /* Hungarian */
LANG_HY, /* Armenian */
LANG_I_KLINGON_ROMANIZED, /* Klingon (Romanized) */
LANG_ID, /* Indonesian */
LANG_IS, /* Icelandic */
LANG_IT, /* Italian */
LANG_IU, /* Inuktitut */
LANG_JA, /* Japanese */
LANG_KA, /* Georgian */
LANG_JA, /* Japanese */
LANG_KA, /* Georgian */
LANG_KAB, /* Kabyle */
LANG_KN, /* Kannada */
LANG_KM, /* Khmer */
LANG_KM, /* Khmer */
LANG_KOK_ROMAN, /* Konkani (Roman) */
LANG_KOK, /* Konkani (Devaganari) */
LANG_KO, /* Korean */
LANG_KS_DEVANAGARI, /* Kashmiri (Devanagari script) */
LANG_KS, /* Kashmiri (Perso-Arabic script) */
LANG_KU, /* Kurdish */
LANG_KO, /* Korean */
LANG_KS_DEVANAGARI, /* Kashmiri (Devanagari script) */
LANG_KS, /* Kashmiri (Perso-Arabic script) */
LANG_KU, /* Kurdish */
LANG_LB, /* Luxembourgish */
LANG_LG, /* Luganda */
LANG_LT, /* Lithuanian */
LANG_LV, /* Latvian */
LANG_LT, /* Lithuanian */
LANG_LV, /* Latvian */
LANG_MAI, /* Maithili */
LANG_ML, /* Malayalam */
LANG_MK, /* Macedonian */
LANG_MN, /* Mongolian */
LANG_MNI_BENGALI, /* Manipuri (Bengali script)*/
LANG_MK, /* Macedonian */
LANG_MN, /* Mongolian */
LANG_MNI_BENGALI, /* Manipuri (Bengali script) */
LANG_MNI_METEI_MAYEK, /* Manipuri (Metei Mayek script) */
LANG_MR, /* Marath */
LANG_MS, /* Malay */
LANG_NB, /* Norwegian Bokmal */
LANG_MS, /* Malay */
LANG_NB, /* Norwegian Bokmal */
LANG_NE, /* Nepali */
LANG_NL, /* Dutch */
LANG_NN, /* Norwegian Nynorsk */
LANG_NL, /* Dutch */
LANG_NN, /* Norwegian Nynorsk */
LANG_NR, /* Ndebele */
LANG_NSO, /* Northern Sotho */
LANG_OC, /* Occitan */
LANG_OJ, /* Ojibway */
LANG_OC, /* Occitan */
LANG_OJ, /* Ojibway */
LANG_OR, /* Odia */
LANG_PA, /* Punjabi */
LANG_PL, /* Polish */
LANG_PT_BR, /* Portuguese (Brazilian) */
LANG_PT, /* Portuguese */
LANG_RO, /* Romanian */
LANG_RU, /* Russian */
LANG_RW, /* Kinyarwanda */
LANG_PA, /* Punjabi */
LANG_PL, /* Polish */
LANG_PT_BR, /* Portuguese (Brazilian) */
LANG_PT, /* Portuguese */
LANG_RO, /* Romanian */
LANG_RU, /* Russian */
LANG_RW, /* Kinyarwanda */
LANG_SAT_OL_CHIKI,
LANG_SAT, /* Santali */
LANG_SA, /* Sanskrit */
LANG_SD, /* Sindhi (Perso-Arabic) */
LANG_SD_DEVANAGARI, /* Sindhi (Devanagari) */
LANG_SHS, /* Shuswap */
LANG_SHS, /* Shuswap */
LANG_SI, /* Sinhala */
LANG_SK, /* Slovak */
LANG_SL, /* Slovenian */
LANG_SK, /* Slovak */
LANG_SL, /* Slovenian */
LANG_SON, /* Songhay */
LANG_SQ, /* Albanian */
LANG_SR_LATIN, /* Serbian (latin) */
LANG_SR, /* Serbian (cyrillic) */
LANG_SQ, /* Albanian */
LANG_SR_LATIN, /* Serbian (latin) */
LANG_SR, /* Serbian (cyrillic) */
LANG_SU, /* Sundanese */
LANG_SV, /* Swedish */
LANG_SW, /* Swahili */
LANG_TA, /* Tamil */
LANG_SV, /* Swedish */
LANG_SW, /* Swahili */
LANG_TA, /* Tamil */
LANG_TE, /* Telugu */
LANG_TH, /* Thai */
LANG_TL, /* Tagalog */
LANG_TR, /* Turkish */
LANG_TW, /* Twi */
LANG_UK, /* Ukrainian */
LANG_UR, /* Urdu */
LANG_VEC, /* Venetian */
LANG_VE, /* Venda */
LANG_VI, /* Vietnamese */
LANG_WA, /* Walloon */
LANG_TH, /* Thai */
LANG_TL, /* Tagalog */
LANG_TR, /* Turkish */
LANG_TW, /* Twi */
LANG_UK, /* Ukrainian */
LANG_UR, /* Urdu */
LANG_VEC, /* Venetian */
LANG_VE, /* Venda */
LANG_VI, /* Vietnamese */
LANG_WA, /* Walloon */
LANG_WO, /* Wolof */
LANG_XH, /* Xhosa */
LANG_ZAM, /* Zapotec (Miahuatlan) */
LANG_ZH_CN, /* Chinese (Simplified) */
LANG_ZH_TW, /* Chinese (Traditional) */
LANG_XH, /* Xhosa */
LANG_ZAM, /* Zapotec (Miahuatlan) */
LANG_ZH_CN, /* Chinese (Simplified) */
LANG_ZH_TW, /* Chinese (Traditional) */
LANG_ZU, /* Zulu */
NUM_LANGS
};
@ -185,8 +185,8 @@ typedef struct language_to_locale_struct
extern const char *lang_prefixes[NUM_LANGS];
extern int need_own_font;
extern int need_right_to_left; // Right-justify
extern int need_right_to_left_word; // Words need to be reversed, too! (e.g., Hebrew, but not Arabic)
extern int need_right_to_left; // Right-justify
extern int need_right_to_left_word; // Words need to be reversed, too! (e.g., Hebrew, but not Arabic)
extern const char *lang_prefix, *short_lang_prefix;
extern int num_wished_langs;
@ -207,8 +207,9 @@ extern w_langs wished_langs[255];
int get_current_language(void);
int setup_i18n(const char *restrict lang, const char *restrict locale) MUST_CHECK;
#ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK;
int smash_i18n(void) MUST_CHECK;
#endif
#endif

1766
src/im.c

File diff suppressed because it is too large Load diff

View file

@ -33,15 +33,16 @@
* TYPES
*/
typedef struct IM_DATA {
int lang; /* Language used in sequence translation */
wchar_t s[16]; /* Characters that should be displayed */
const char* tip_text; /* Tip text, read-only please */
typedef struct IM_DATA
{
int lang; /* Language used in sequence translation */
wchar_t s[16]; /* Characters that should be displayed */
const char *tip_text; /* Tip text, read-only please */
/* For use by language-specific im_event_<lang> calls. PRIVATE! */
wchar_t buf[8]; /* Buffered characters */
int redraw; /* Redraw this many characters next time */
int request; /* Event request */
wchar_t buf[8]; /* Buffered characters */
int redraw; /* Redraw this many characters next time */
int request; /* Event request */
} IM_DATA;
@ -49,9 +50,9 @@ typedef struct IM_DATA {
* FUNCTIONS
*/
void im_init(IM_DATA* im, int lang); /* Initialize IM */
void im_softreset(IM_DATA* im); /* Soft Reset IM */
int im_read(IM_DATA* im, SDL_Event event);
void im_init(IM_DATA * im, int lang); /* Initialize IM */
void im_softreset(IM_DATA * im); /* Soft Reset IM */
int im_read(IM_DATA * im, SDL_Event event);
#endif /* TUXPAINT_IM_H */

View file

@ -25,17 +25,16 @@
#include "SDL.h"
const char *SurfacePrint(SDL_Surface *surface, int showDialog);
int DisplayPageSetup(const SDL_Surface *surface);
const char *SurfacePrint(SDL_Surface * surface, int showDialog);
int DisplayPageSetup(const SDL_Surface * surface);
#ifdef OBJECTIVEC
@interface PrintSheetController : NSObject
@interface PrintSheetController:NSObject
{
bool displayPrintSetupSheet;
bool displayPrintSheet;
bool displayPrintSetupSheet;
bool displayPrintSheet;
}
-
@end
#endif OBJECTIVEC
-@end
#endif /* OBJECTIVEC */

File diff suppressed because it is too large Load diff

View file

@ -26,41 +26,41 @@ KMOD_ALT An Alt key is down
typedef struct osk_keymap
{
int keycode;
int disable_caps; /* If caps lock should affect this key */
char * plain; /* The default Xkeysym for the keycode */
char * caps; /* If CapsLock or Shift + key */
char * altgr; /* If AltGr + key */
char * shiftaltgr; /* If AltGr + Shift + key */
int keycode;
int disable_caps; /* If caps lock should affect this key */
char *plain; /* The default Xkeysym for the keycode */
char *caps; /* If CapsLock or Shift + key */
char *altgr; /* If AltGr + key */
char *shiftaltgr; /* If AltGr + Shift + key */
} osk_keymap;
typedef struct osk_key
{
int keycode; /* The code associated to this key. If 0, then it is an empty key. */
int keycode; /* The code associated to this key. If 0, then it is an empty key. */
int row;
int x;
int y;
float width; /* The width in buttons */
char *plain_label; /* The text that will show the key */
char *top_label; /* The text that will show the key above the plain label. */
char *altgr_label; /* The text that will show the key at the right of the plain label */
char *shift_altgr_label; /* The text that will show the key when shift and altgr are activated */
int shiftcaps; /* If the value of the key should be shifted when capslock is active */
int stick; /* If the key currently affects the others */
float width; /* The width in buttons */
char *plain_label; /* The text that will show the key */
char *top_label; /* The text that will show the key above the plain label. */
char *altgr_label; /* The text that will show the key at the right of the plain label */
char *shift_altgr_label; /* The text that will show the key when shift and altgr are activated */
int shiftcaps; /* If the value of the key should be shifted when capslock is active */
int stick; /* If the key currently affects the others */
} osk_key;
typedef struct osk_composenode
{
wchar_t * keysym;
wchar_t * result;
int size; /* How many childs are there. */
struct osk_composenode ** childs;
wchar_t *keysym;
wchar_t *result;
int size; /* How many childs are there. */
struct osk_composenode **childs;
// struct osk_composenode **parent;
} osk_composenode;
typedef struct keysymdefs
{
char * mnemo;
char *mnemo;
int keysym;
int unicode;
} keysymdefs;
@ -71,11 +71,11 @@ typedef struct osk_layout
int *rows;
int width;
int height;
char * fontpath;
char *fontpath;
osk_key **keys;
osk_keymap *keymap;
osk_composenode * composemap;
keysymdefs * keysymdefs;
osk_composenode *composemap;
keysymdefs *keysymdefs;
unsigned int sizeofkeysymdefs;
SDL_Color bgcolor;
SDL_Color fgcolor;
@ -91,56 +91,61 @@ typedef struct osk_keymodifiers
typedef struct osk_kmdf
{
osk_key * shift;
osk_key * altgr;
osk_key * compose;
osk_key * dead;
osk_key * dead2;
osk_key * dead3;
osk_key * dead4;
osk_key *shift;
osk_key *altgr;
osk_key *compose;
osk_key *dead;
osk_key *dead2;
osk_key *dead3;
osk_key *dead4;
} osk_kmdf;
typedef struct osk_keyboard
{
char * name; /* The name of the keyboard */
char * keyboard_list; /* The names of the keyboards allowed from this one */
SDL_Surface *surface; /* The surface containing the keyboard */
SDL_Surface *button_up; /* The surfaces containing the buttons */
char *name; /* The name of the keyboard */
char *keyboard_list; /* The names of the keyboards allowed from this one */
SDL_Surface *surface; /* The surface containing the keyboard */
SDL_Surface *button_up; /* The surfaces containing the buttons */
SDL_Surface *button_down;
SDL_Surface *button_off;
SDL_Surface *button_nav;
SDL_Surface *button_hold;
SDL_Surface *oskdel; /* The surfaces containing some symbols for the buttons, delete arrow */
SDL_Surface *osktab; /* Tab arrows */
SDL_Surface *oskenter; /* Return hook/arrow */
SDL_Surface *oskcapslock; /* CapsLock */
SDL_Surface *oskshift; /* Shift */
int changed; /* If the surface has been modified (painted) */
SDL_Rect rect; /* The rectangle that has changed */
int recreated; /* If the surface has been deleted and newly created */
int modifiers; /* The state of Alt, CTRL, Shift, CapsLock, AltGr keys */
osk_keymodifiers keymodifiers; /* A shortcurt to find the place of the pressed modifiers */
SDL_Surface *oskdel; /* The surfaces containing some symbols for the buttons, delete arrow */
SDL_Surface *osktab; /* Tab arrows */
SDL_Surface *oskenter; /* Return hook/arrow */
SDL_Surface *oskcapslock; /* CapsLock */
SDL_Surface *oskshift; /* Shift */
int changed; /* If the surface has been modified (painted) */
SDL_Rect rect; /* The rectangle that has changed */
int recreated; /* If the surface has been deleted and newly created */
int modifiers; /* The state of Alt, CTRL, Shift, CapsLock, AltGr keys */
osk_keymodifiers keymodifiers; /* A shortcurt to find the place of the pressed modifiers */
osk_kmdf kmdf;
osk_layout *layout; /* The layout struct */
char *layout_name[256]; /* The layout name */
TTF_Font * osk_fonty; /* Font */
int disable_change; /* If true, stay with the first layout found */
wchar_t * key[256]; /* The text of the key */
int keycode; /* The unicode code corresponding to the key */
wchar_t * composed; /* The unicode char found after a sequence of key presses */
int composed_type; /* 1 if the value stored in composed is yet the unicode value */
osk_composenode * composing; /* The node in the middle of a compose sequence */
osk_key * last_key_pressed; /* The last key pressed */
osk_layout *layout; /* The layout struct */
char *layout_name[256]; /* The layout name */
TTF_Font *osk_fonty; /* Font */
int disable_change; /* If true, stay with the first layout found */
wchar_t *key[256]; /* The text of the key */
int keycode; /* The unicode code corresponding to the key */
wchar_t *composed; /* The unicode char found after a sequence of key presses */
int composed_type; /* 1 if the value stored in composed is yet the unicode value */
osk_composenode *composing; /* The node in the middle of a compose sequence */
osk_key *last_key_pressed; /* The last key pressed */
} on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change);
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift,
int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char * layout_buttons, char *layout_labels, char *layout_keycodes);
void osk_reset(on_screen_keyboard *osk);
struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y);
void osk_released(on_screen_keyboard *osk);
void osk_hover(on_screen_keyboard *keyboard, int x, int y);
void osk_free(on_screen_keyboard *osk);
void osk_change_layout(on_screen_keyboard *osk);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char *layout_buttons, char *layout_labels,
char *layout_keycodes);
void osk_reset(on_screen_keyboard * osk);
struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y);
void osk_released(on_screen_keyboard * osk);
void osk_hover(on_screen_keyboard * keyboard, int x, int y);
void osk_free(on_screen_keyboard * osk);
void osk_change_layout(on_screen_keyboard * osk);

View file

@ -86,4 +86,5 @@ struct cfginfo
#define CFGINFO_MAXOFFSET (sizeof(struct cfginfo))
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt, const char *restrict src);
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt,
const char *restrict src);

View file

@ -37,21 +37,19 @@ static void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
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)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
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 */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
*p = pixel;
}
*p = pixel;
}
}
/* Draw a single pixel into the surface: */
@ -60,21 +58,19 @@ static void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
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)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
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 */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
/* 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: */
@ -83,33 +79,31 @@ static void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
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)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
}
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
}
/* Draw a single pixel into the surface: */
@ -118,21 +112,19 @@ static void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
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)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
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 */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
/* 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: */
@ -141,17 +133,17 @@ static Uint32 getpixel8(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
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 */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the
@ -167,17 +159,17 @@ static Uint32 getpixel16(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
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 */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the
@ -194,17 +186,17 @@ static Uint32 getpixel24(SDL_Surface * surface, int x, int y)
Uint32 pixel;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
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 */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the
@ -227,24 +219,24 @@ static Uint32 getpixel32(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
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 */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the
* 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) =

View file

@ -33,55 +33,54 @@ int mute;
int use_sound = 1;
static 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;
if (!mute && use_sound && s != SND_NONE)
{
if (override || !Mix_Playing(chan))
{
Mix_PlayChannel(chan, sounds[s], 0);
if (override || !Mix_Playing(chan))
{
Mix_PlayChannel(chan, sounds[s], 0);
old_sound[chan] = s;
old_sound[chan] = s;
}
if (old_sound[chan] == s)
{
if (y == SNDDIST_NEAR)
dist = 0;
else
{
if (y < 0)
y = 0;
else if (y >= screen->h - 1)
y = screen->h - 1;
dist = (255 * ((screen->h - 1) - y)) / (screen->h - 1);
}
if (x == SNDPOS_LEFT)
left = 255 - dist;
else if (x == SNDPOS_CENTER)
left = (255 - dist) / 2;
else if (x == SNDPOS_RIGHT)
left = 0;
else
{
if (x < 0)
x = 0;
else if (x >= screen->w)
x = screen->w - 1;
left = ((255 - dist) * ((screen->w - 1) - x)) / (screen->w - 1);
}
Mix_SetPanning(chan, left, (255 - dist) - left);
}
}
if (old_sound[chan] == s)
{
if (y == SNDDIST_NEAR)
dist = 0;
else
{
if (y < 0)
y = 0;
else if (y >= screen->h - 1)
y = screen->h - 1;
dist = (255 * ((screen->h - 1) - y)) / (screen->h - 1);
}
if (x == SNDPOS_LEFT)
left = 255 - dist;
else if (x == SNDPOS_CENTER)
left = (255 - dist) / 2;
else if (x == SNDPOS_RIGHT)
left = 0;
else
{
if (x < 0)
x = 0;
else if (x >= screen->w)
x = screen->w - 1;
left = ((255 - dist) * ((screen->w - 1) - x)) / (screen->w - 1);
}
Mix_SetPanning(chan, left, (255 - dist) - left);
}
}
#endif
}

View file

@ -37,7 +37,6 @@
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

View file

@ -62,7 +62,7 @@
#include "pixels.h"
#define MARGIN 36 /* Margin to put around image, in points (inch/72) (36pt = 0.5") */
#define MARGIN 36 /* Margin to put around image, in points (inch/72) (36pt = 0.5") */
#define my_min(x,y) ((x < y) ? (x) : (y))
@ -78,12 +78,9 @@ static int f2dec(float f)
/* Actually save the PostScript data to the file stream: */
int do_ps_save(FILE * fi,
const char *restrict const fname,
SDL_Surface * surf,
const char *restrict pprsize,
int is_pipe)
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe)
{
const struct paper * ppr;
const struct paper *ppr;
int img_w = surf->w;
int img_h = surf->h;
int r_img_w, r_img_h;
@ -94,8 +91,8 @@ int do_ps_save(FILE * fi,
int plane;
Uint8 r, g, b;
char buf[256];
Uint32(*getpixel) (SDL_Surface *, int, int) =
getpixels[surf->format->BytesPerPixel];
Uint32(*getpixel) (SDL_Surface *, int, int) = getpixels[surf->format->BytesPerPixel];
int printed_img_w, printed_img_h;
time_t t = time(NULL);
int rotate;
@ -104,40 +101,40 @@ int do_ps_save(FILE * fi,
/* Determine paper size: */
paperinit(); // FIXME: Should we do this at startup? -bjk 2007.06.25
paperinit(); // FIXME: Should we do this at startup? -bjk 2007.06.25
if (pprsize == NULL)
{
/* User did not request a specific paper size (on command-line or
in config file), ask the system. It will return either their
$PAPER env. var., the value from /etc/papersize, or NULL: */
pprsize = systempapername();
if (pprsize == NULL)
{
/* No setting, env. var. or /etc/ file; use the default! */
/* User did not request a specific paper size (on command-line or
in config file), ask the system. It will return either their
$PAPER env. var., the value from /etc/papersize, or NULL: */
pprsize = defaultpapername();
pprsize = systempapername();
if (pprsize == NULL)
{
/* No setting, env. var. or /etc/ file; use the default! */
pprsize = defaultpapername();
#ifdef DEBUG
printf("Using default paper\n");
printf("Using default paper\n");
#endif
}
}
#ifdef DEBUG
else
{
printf("Using system paper\n");
}
else
{
printf("Using system paper\n");
}
#endif
}
}
#ifdef DEBUG
else
{
printf("Using user paper\n");
}
{
printf("Using user paper\n");
}
#endif
#ifdef DEBUG
printf("Using paper size: %s\n", pprsize);
#endif
@ -151,28 +148,26 @@ int do_ps_save(FILE * fi,
ppr_h = paperpsheight(ppr);
#ifdef DEBUG
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h,
(float) ppr_w / 72.0, (float) ppr_h / 72.0);
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h, (float)ppr_w / 72.0, (float)ppr_h / 72.0);
#endif
paperdone(); // FIXME: Should we do this at quit? -bjk 2007.06.25
paperdone(); // FIXME: Should we do this at quit? -bjk 2007.06.25
/* Determine whether it's best to rotate the image: */
if ((ppr_w >= ppr_h && img_w >= img_h) ||
(ppr_w <= ppr_h && img_w <= img_h))
{
rotate = 0;
r_img_w = img_w;
r_img_h = img_h;
}
if ((ppr_w >= ppr_h && img_w >= img_h) || (ppr_w <= ppr_h && img_w <= img_h))
{
rotate = 0;
r_img_w = img_w;
r_img_h = img_h;
}
else
{
rotate = 1;
r_img_w = img_h;
r_img_h = img_w;
}
{
rotate = 1;
r_img_w = img_h;
r_img_h = img_w;
}
#ifdef DEBUG
printf("Image is %d x %d\n", img_w, img_h);
@ -183,15 +178,13 @@ int do_ps_save(FILE * fi,
/* Determine scale: */
scale = my_min(((float) (ppr_w - (MARGIN * 2)) / (float) r_img_w),
((float) (ppr_h - (MARGIN * 2)) / (float) r_img_h));
scale = my_min(((float)(ppr_w - (MARGIN * 2)) / (float)r_img_w), ((float)(ppr_h - (MARGIN * 2)) / (float)r_img_h));
printed_img_w = r_img_w * scale;
printed_img_h = r_img_h * scale;
#ifdef DEBUG
printf("Scaling image by %.2f (to %d x %d)\n", scale,
printed_img_w, printed_img_h);
printf("Scaling image by %.2f (to %d x %d)\n", scale, printed_img_w, printed_img_h);
#endif
@ -206,7 +199,7 @@ int do_ps_save(FILE * fi,
/* Begin PostScript output with some useful meta info in comments: */
fprintf(fi, "%%!PS-Adobe-2.0 EPSF-2.0\n"); // we need LanguageLevel2 for color
fprintf(fi, "%%!PS-Adobe-2.0 EPSF-2.0\n"); // we need LanguageLevel2 for color
fprintf(fi, "%%%%Title: (%s)\n", fname);
@ -217,8 +210,7 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Pages: 1\n");
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int) (ppr_w + 0.5), (int)
(ppr_h + 0.5));
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int)(ppr_w + 0.5), (int)(ppr_h + 0.5));
fprintf(fi, "%%%%EndComments\n");
@ -237,24 +229,20 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Page: 1 1\n");
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n",
ppr_w, ppr_h);
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n", ppr_w, ppr_h);
fprintf(fi, "gsave\n");
/* 'translate' moves the user space origin to a new position with
respect to the current page, leaving the orientation of the axes and
the unit lengths unchanged. */
fprintf(fi, "%d.%02d %d.%02d translate\n",
f2int(tlate_x), f2dec(tlate_x),
f2int(tlate_y), f2dec(tlate_y));
respect to the current page, leaving the orientation of the axes and
the unit lengths unchanged. */
fprintf(fi, "%d.%02d %d.%02d translate\n", f2int(tlate_x), f2dec(tlate_x), f2int(tlate_y), f2dec(tlate_y));
/* 'scale' modifies the unit lengths independently along the current
x and y axes, leaving the origin location and the orientation of the
axes unchanged. */
x and y axes, leaving the origin location and the orientation of the
axes unchanged. */
fprintf(fi, "%d.%02d %d.%02d scale\n",
f2int(printed_img_w), f2dec(printed_img_w),
f2int(printed_img_h), f2dec(printed_img_h));
f2int(printed_img_w), f2dec(printed_img_w), f2int(printed_img_h), f2dec(printed_img_h));
/* Rotate the image */
if (rotate)
@ -274,23 +262,23 @@ int do_ps_save(FILE * fi,
cur_line_len = 0;
for (y = 0; y < img_h; y++)
{
for (plane = 0; plane < 3; plane++)
{
for (x = 0; x < img_w; x++)
{
SDL_GetRGB(getpixel(surf, x, y), surf->format, &r, &g, &b);
fprintf(fi, "%02x", (plane == 0 ? r : (plane == 1 ? g : b)));
cur_line_len++;
if (cur_line_len >= 30)
for (plane = 0; plane < 3; plane++)
{
fprintf(fi, "\n");
cur_line_len = 0;
for (x = 0; x < img_w; x++)
{
SDL_GetRGB(getpixel(surf, x, y), surf->format, &r, &g, &b);
fprintf(fi, "%02x", (plane == 0 ? r : (plane == 1 ? g : b)));
cur_line_len++;
if (cur_line_len >= 30)
{
fprintf(fi, "\n");
cur_line_len = 0;
}
}
}
}
}
}
fprintf(fi, "\n");
fprintf(fi, "grestore\n");
@ -299,16 +287,16 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%EOF\n");
if (!is_pipe)
{
fclose(fi);
return 1;
}
{
fclose(fi);
return 1;
}
else
{
pid_t child_pid, w;
int status;
{
pid_t child_pid, w;
int status;
child_pid = pclose(fi);
child_pid = pclose(fi);
/* debug */
/*
@ -316,15 +304,18 @@ int do_ps_save(FILE * fi,
printf("errno = %d\n", errno); fflush(stdout);
*/
if (child_pid < 0 || (errno != 0 && errno != EAGAIN)) { /* FIXME: This right? */
return 0;
} else if (child_pid == 0) {
return 1;
}
if (child_pid < 0 || (errno != 0 && errno != EAGAIN))
{ /* FIXME: This right? */
return 0;
}
else if (child_pid == 0)
{
return 1;
}
do
{
w = waitpid(child_pid, &status, 0);
do
{
w = waitpid(child_pid, &status, 0);
/* debug */
/*
@ -339,15 +330,14 @@ int do_ps_save(FILE * fi,
printf("continued\n");
}
*/
}
while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status));
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) /* Not happy exit */
return 0;
return 1;
}
while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status));
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) /* Not happy exit */
return 0;
return 1;
}
}
#endif

View file

@ -79,12 +79,8 @@
#ifdef PRINTMETHOD_PS
int do_ps_save(FILE * fi,
const char *restrict const fname,
SDL_Surface * surf,
const char *restrict pprsize,
int is_pipe);
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe);
#endif
#endif /* POSTSCRIPT_PRINT_H */

View file

@ -34,7 +34,7 @@
SDL_Surface *img_progress;
int progress_bar_disabled, prog_bar_ctr;
void show_progress_bar_(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer)
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
{
SDL_Rect dest, src, r;
int x;
@ -45,39 +45,39 @@ void show_progress_bar_(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer
return;
newtime = SDL_GetTicks();
if (newtime > oldtime + 15) // trying not to eat some serious CPU time!
{
for (x = 0; x < screen->w; x = x + 65)
if (newtime > oldtime + 15) // trying not to eat some serious CPU time!
{
src.x = 65 - (prog_bar_ctr % 65);
src.y = 0;
src.w = 65;
src.h = 24;
for (x = 0; x < screen->w; x = x + 65)
{
src.x = 65 - (prog_bar_ctr % 65);
src.y = 0;
src.w = 65;
src.h = 24;
dest.x = x;
dest.y = screen->h - 24;
dest.x = x;
dest.y = screen->h - 24;
SDL_BlitSurface(img_progress, &src, screen, &dest);
SDL_BlitSurface(img_progress, &src, screen, &dest);
}
prog_bar_ctr++;
// FIXME SDL2
// SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24);
r.x = 0;
r.y = screen->h - 24;
r.w = screen->w;
r.h = 24;
SDL_UpdateTexture(texture, &r, screen->pixels + ((screen->h - 24) * screen->pitch), screen->pitch);
// NOTE docs says one should clear the renderer, however this means a refresh of the whole thing.
// SDL_RenderClear(renderer);
// SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderCopy(renderer, texture, &r, &r);
SDL_RenderPresent(renderer);
}
prog_bar_ctr++;
// FIXME SDL2
// SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24);
r.x = 0;
r.y = screen->h - 24;
r.w = screen->w;
r.h = 24;
SDL_UpdateTexture(texture, &r, screen->pixels + ((screen->h - 24) * screen->pitch), screen->pitch);
// NOTE docs says one should clear the renderer, however this means a refresh of the whole thing.
// SDL_RenderClear(renderer);
// SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderCopy(renderer, texture, &r, &r);
SDL_RenderPresent(renderer);
}
oldtime = newtime;

View file

@ -33,13 +33,14 @@
unsigned char linear_to_sRGB(float linear)
{
unsigned slot;
slot = linear * 4096.0 + 0.5;
if (slot > 4095)
{
if (linear > 0.5)
slot = 4095;
else
slot = 0;
}
{
if (linear > 0.5)
slot = 4095;
else
slot = 0;
}
return linear_to_sRGB_table[slot];
}

View file

@ -305,8 +305,7 @@ static const unsigned char linear_to_sRGB_table[4096] =
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd"
"\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";
"\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";
unsigned char linear_to_sRGB(float linear) FUNCTION;

View file

@ -62,84 +62,84 @@ enum
/* How many sides do they have? */
const int shape_sides[NUM_SHAPES] = {
4, /* Square */
4, /* Square */
4, /* Rectangle */
4, /* Rectangle */
72, /* Circle */
72, /* Circle */
72, /* Ellipse */
72, /* Ellipse */
3, /* Triangle */
3, /* Triangle */
5, /* Pentagon */
5, /* Pentagon */
4, /* Rhombus */
4, /* Rhombus */
8, /* Octagon */
8, /* Octagon */
3, /* 3 points star*/
3, /* 3 points star*/
4, /* 4 points star*/
4, /* 4 points star*/
5, /* 5 points star*/
5 /* 5 points star*/
4, /* Square */
4, /* Square */
4, /* Rectangle */
4, /* Rectangle */
72, /* Circle */
72, /* Circle */
72, /* Ellipse */
72, /* Ellipse */
3, /* Triangle */
3, /* Triangle */
5, /* Pentagon */
5, /* Pentagon */
4, /* Rhombus */
4, /* Rhombus */
8, /* Octagon */
8, /* Octagon */
3, /* 3 points star */
3, /* 3 points star */
4, /* 4 points star */
4, /* 4 points star */
5, /* 5 points star */
5 /* 5 points star */
};
/* Which shapes are 1:1 aspect? */
const int shape_locked[NUM_SHAPES] = {
1, /* Square */
1, /* Square */
0, /* Rectangle */
0, /* Rectangle */
1, /* Circle */
1, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
0, /* Triangle */
0, /* Triangle */
0, /* Pentagon */
0, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
1, /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
0, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
0, /* 5 points star*/
0 /* 5 points star*/
1, /* Square */
1, /* Square */
0, /* Rectangle */
0, /* Rectangle */
1, /* Circle */
1, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
0, /* Triangle */
0, /* Triangle */
0, /* Pentagon */
0, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
1, /* Octagon */
1, /* Octagon */
0, /* 3 points star */
0, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
0, /* 5 points star */
0 /* 5 points star */
};
/* Which shapes are filled? */
const int shape_filled[NUM_SHAPES] = {
0, /* Square */
1, /* Square */
0, /* Rectangle */
1, /* Rectangle */
0, /* Circle */
1, /* Circle */
0, /* Ellipse */
1, /* Ellipse */
0, /* Triangle */
1, /* Triangle */
0, /* Pentagon */
1, /* Pentagon */
0, /* Rhombus */
1, /* Rhombus */
0, /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
1, /* 3 points star*/
0, /* 4 points star*/
1, /* 4 points star*/
0, /* 5 points star*/
1 /* 5 points star*/
0, /* Square */
1, /* Square */
0, /* Rectangle */
1, /* Rectangle */
0, /* Circle */
1, /* Circle */
0, /* Ellipse */
1, /* Ellipse */
0, /* Triangle */
1, /* Triangle */
0, /* Pentagon */
1, /* Pentagon */
0, /* Rhombus */
1, /* Rhombus */
0, /* Octagon */
1, /* Octagon */
0, /* 3 points star */
1, /* 3 points star */
0, /* 4 points star */
1, /* 4 points star */
0, /* 5 points star */
1 /* 5 points star */
};
@ -147,83 +147,83 @@ const int shape_filled[NUM_SHAPES] = {
/* Initial angles for shapes: */
const int shape_init_ang[NUM_SHAPES] = {
45, /* Square */
45, /* Square */
45, /* Rectangle */
45, /* Rectangle */
0, /* Circle */
0, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
210, /* Triangle */
210, /* Triangle */
162, /* Pentagon */
162, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
22, /* Octagon */
22, /* Octagon */
210, /* 3 points star*/
210, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
162, /* 5 points star */
162 /* 5 points star */
45, /* Square */
45, /* Square */
45, /* Rectangle */
45, /* Rectangle */
0, /* Circle */
0, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
210, /* Triangle */
210, /* Triangle */
162, /* Pentagon */
162, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
22, /* Octagon */
22, /* Octagon */
210, /* 3 points star */
210, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
162, /* 5 points star */
162 /* 5 points star */
};
/* Shapes that don't make sense rotating (e.g., circles): */
const int shape_no_rotate[NUM_SHAPES] = {
0, /* Square */
0, /* Square */
0, /* Rectangle */
0, /* Rectangle */
1, /* Circle */
1, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
0, /* Triangle */
0, /* Triangle */
0, /* Pentagon */
0, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
0, /* Octagon */
0, /* Octagon */
0, /* 3 points star */
0, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
0, /* 5 points star */
0 /* 5 points star */
0, /* Square */
0, /* Square */
0, /* Rectangle */
0, /* Rectangle */
1, /* Circle */
1, /* Circle */
0, /* Ellipse */
0, /* Ellipse */
0, /* Triangle */
0, /* Triangle */
0, /* Pentagon */
0, /* Pentagon */
0, /* Rhombus */
0, /* Rhombus */
0, /* Octagon */
0, /* Octagon */
0, /* 3 points star */
0, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
0, /* 5 points star */
0 /* 5 points star */
};
/* Valley of stars in percent of size */
const int shape_valley[NUM_SHAPES] = {
100, /* Square */
100, /* Square */
100, /* Rectangle */
100, /* Rectangle */
100, /* Circle */
100, /* Circle */
100, /* Ellipse */
100, /* Ellipse */
100, /* Triangle */
100, /* Triangle */
100, /* Pentagon */
100, /* Pentagon */
100, /* Rhombus */
100, /* Rhombus */
100, /* Octagon */
100, /* Octagon */
20, /* 3 points star */
20, /* 3 points star */
30, /* 4 points star */
30, /* 4 points star */
35, /* 5 points star */
35 /* 5 points star */
100, /* Square */
100, /* Square */
100, /* Rectangle */
100, /* Rectangle */
100, /* Circle */
100, /* Circle */
100, /* Ellipse */
100, /* Ellipse */
100, /* Triangle */
100, /* Triangle */
100, /* Pentagon */
100, /* Pentagon */
100, /* Rhombus */
100, /* Rhombus */
100, /* Octagon */
100, /* Octagon */
20, /* 3 points star */
20, /* 3 points star */
30, /* 4 points star */
30, /* 4 points star */
35, /* 5 points star */
35 /* 5 points star */
};
@ -279,7 +279,6 @@ const char *const shape_names[NUM_SHAPES] = {
// Pentagone star (5 points star)
gettext_noop("Star")
};
@ -295,10 +294,8 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A rectangle has four sides and four right angles."),
// Description of a circle
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
// Description of an ellipse
gettext_noop("An ellipse is a stretched circle."),
@ -313,16 +310,12 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A pentagon has five sides."),
// Description of a rhombus
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."),
// Description of an octagon
gettext_noop
("An octagon has eight equal sides."),
gettext_noop
("An octagon has eight equal sides."),
gettext_noop("An octagon has eight equal sides."),
gettext_noop("An octagon has eight equal sides."),
gettext_noop("A star with 3 points."),
gettext_noop("A star with 3 points."),
@ -330,7 +323,6 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A star with 4 points."),
gettext_noop("A star with 5 points."),
gettext_noop("A star with 5 points.")
};
@ -359,5 +351,4 @@ const char *const shape_img_fnames[NUM_SHAPES] = {
DATA_PREFIX "images/shapes/star4p_f.png",
DATA_PREFIX "images/shapes/star5p.png",
DATA_PREFIX "images/shapes/star5p_f.png"
};

View file

@ -37,34 +37,34 @@
enum
{
SND_HARP, /* Begin / New */
SND_CLICK, /* Tool selections */
SND_BLEEP, /* Selector selection */
SND_BUBBLE, /* Color selection */
SND_STAMP, /* Using stamp tool */
SND_LINE_START, /* Using line tool */
SND_HARP, /* Begin / New */
SND_CLICK, /* Tool selections */
SND_BLEEP, /* Selector selection */
SND_BUBBLE, /* Color selection */
SND_STAMP, /* Using stamp tool */
SND_LINE_START, /* Using line tool */
SND_LINE_END,
SND_SCROLL, /* Selector scroll buttons */
SND_PAINT1, /* Sound while painting */
SND_SCROLL, /* Selector scroll buttons */
SND_PAINT1, /* Sound while painting */
SND_PAINT2,
SND_PAINT3,
SND_PAINT4,
SND_ERASER1, /* Sound while erasing */
SND_ERASER1, /* Sound while erasing */
SND_ERASER2,
SND_SAVE, /* Save sound effect */
SND_PROMPT, /* Prompt animation sound effect */
SND_FLIP, /* Magic flip */
SND_MIRROR, /* Magic mirror */
SND_KEYCLICK, /* Text tool keyboard click feedback */
SND_KEYCLICKRING, /* Text tool keyboard click feedback with bell ring */
SND_RETURN, /* Text tool carriage return sound */
SND_SHRINK, /* Stamp shrink */
SND_GROW, /* Stamp grow */
SND_ITALIC_ON, /* Italic on */
SND_ITALIC_OFF, /* Italic off */
SND_AREYOUSURE, /* "Are you sure?" */
SND_YOUCANNOT, /* "No no no!" */
SND_TUXOK, /* "Ok" */
SND_SAVE, /* Save sound effect */
SND_PROMPT, /* Prompt animation sound effect */
SND_FLIP, /* Magic flip */
SND_MIRROR, /* Magic mirror */
SND_KEYCLICK, /* Text tool keyboard click feedback */
SND_KEYCLICKRING, /* Text tool keyboard click feedback with bell ring */
SND_RETURN, /* Text tool carriage return sound */
SND_SHRINK, /* Stamp shrink */
SND_GROW, /* Stamp grow */
SND_ITALIC_ON, /* Italic on */
SND_ITALIC_OFF, /* Italic off */
SND_AREYOUSURE, /* "Are you sure?" */
SND_YOUCANNOT, /* "No no no!" */
SND_TUXOK, /* "Ok" */
SND_THICK,
SND_THIN,
NUM_SOUNDS

View file

@ -121,13 +121,16 @@ const char *const tool_tips[NUM_TOOLS] = {
gettext_noop("Click to start drawing a line. Let go to complete it."),
// Shape tool instructions
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
("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."),
// Text tool instructions
gettext_noop("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text."),
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text."),
// Label tool instructions
gettext_noop("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text. By using the selector button and clicking an existing label, you can move it, edit it and change its text style."),
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text. By using the selector button and clicking an existing label, you can move it, edit it and change its text style."),
// Reserved...
" ",

File diff suppressed because it is too large Load diff

View file

@ -1,128 +1,125 @@
/****************************************************/
/* */
/* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */
/* */
/* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */
/* */
/* Version 1.0.1 - fixed bug in opendir() */
/* Version 1.0.0 - initial version */
/* */
/****************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id$ */
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "win32_dirent.h"
#include "debug.h"
DIR * opendir(const char *pSpec)
/****************************************************/
/* */
/* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */
/* */
/* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */
/* */
/* Version 1.0.1 - fixed bug in opendir() */
/* Version 1.0.0 - initial version */
/* */
/****************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id$ */
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "win32_dirent.h"
#include "debug.h"
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, "/*");
pDir->hFind = FindFirstFile(pathname, &pDir->wfd);
if (pDir->hFind == INVALID_HANDLE_VALUE)
{
free(pDir);
pDir = NULL;
}
return pDir;
}
void closedir(DIR * pDir)
{
assert(pDir != NULL);
free(pDir);
} struct dirent *readdir(struct DIR *pDir)
{
assert(pDir != NULL);
if (pDir->hFind)
{
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
if (!FindNextFile(pDir->hFind, &pDir->wfd))
{
FindClose(pDir->hFind);
pDir->hFind = NULL;
}
return &pDir->de;
}
return NULL;
}
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)
{
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)[i] = block;
memcpy(block, entry, size);
return ++i;
}
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
comparCB compar)
{
DIR * pDir;
int count;
struct dirent *entry;
assert((dir != NULL) && (namelist != NULL));
pDir = opendir(dir);
if (!pDir)
return -1;
count = 0;
while ((entry = readdir(pDir)) != NULL)
{
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);
return count;
}
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)
{
free(pDir);
pDir = NULL;
}
return pDir;
}
void closedir(DIR * pDir)
{
assert(pDir != NULL);
free(pDir);
} struct dirent *readdir(struct DIR *pDir)
{
assert(pDir != NULL);
if (pDir->hFind)
{
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
if (!FindNextFile(pDir->hFind, &pDir->wfd))
{
FindClose(pDir->hFind);
pDir->hFind = NULL;
}
return &pDir->de;
}
return NULL;
}
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)
{
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)[i] = block;
memcpy(block, entry, size);
return ++i;
}
int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
{
DIR * pDir;
int count;
struct dirent *entry;
assert((dir != NULL) && (namelist != NULL));
pDir = opendir(dir);
if (!pDir)
return -1;
count = 0;
while ((entry = readdir(pDir)) != NULL)
{
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);
return count;
}

View file

@ -1,73 +1,76 @@
/****************************************************/
/* */
/* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */
/* */
/* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */
/* */
/****************************************************/
/* $Id$ */
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
/****************************************************/
/* */
/* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */
/* */
/* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */
/* */
/****************************************************/
/* $Id$ */
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
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
typedef struct
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
typedef struct
{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[MAX_PATH];
TCHAR cAlternateFileName[14];
} WIN32_FIND_DATA;
#define FindFirstFile FindFirstFileA
#define FindNextFile FindNextFileA
#define FindClose FindClose
#ifdef __cplusplus
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
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 HANDLE WINAPI FindFirstFile(const char *, WIN32_FIND_DATA *);
extern BOOL WINAPI FindNextFile(HANDLE, WIN32_FIND_DATA *);
extern BOOL WINAPI FindClose(HANDLE);
#ifdef __cplusplus
#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
char d_name[MAX_PATH];
};
typedef struct
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
struct dirent de;
} 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);
WIN32_FIND_DATA wfd;
HANDLE hFind;
struct dirent de;
} 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);

View file

@ -67,20 +67,19 @@ 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
linesize = surf24->w * 3; // Flip top2bottom
dst = surfDIB->pixels;
src = ((Uint8 *) surf24->pixels) + ((surf24->h - 1) * surf24->pitch);
for (i = 0; i < surf24->h; ++i)
{
memcpy(dst, src, linesize);
src -= surf24->pitch;
dst += surfDIB->pitch;
}
{
memcpy(dst, src, linesize);
src -= surf24->pitch;
dst += surfDIB->pitch;
}
SDL_FreeSurface(surf24); // Free temp surface
SDL_FreeSurface(surf24); // Free temp surface
return surfDIB;
}
@ -101,17 +100,16 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
return 0;
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);
return 1;
}
((drv = strtok(NULL, ", ")) != NULL) && ((out = strtok(NULL, ", ")) != NULL))
{
if (device)
strcpy(device, dev);
if (driver)
strcpy(driver, drv);
if (output)
strcpy(output, out);
return 1;
}
return 0;
}
@ -138,8 +136,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!OpenPrinter(device, &hPrinter, NULL))
goto err_exit;
sizeof_devmode = (int) DocumentProperties(hWnd, hPrinter, device,
NULL, NULL, 0);
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device, NULL, NULL, 0);
if (!sizeof_devmode)
goto err_exit;
@ -152,8 +149,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!devmode)
goto err_exit;
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL,
DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL, DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -163,8 +159,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
goto err_exit;
fclose(fp);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
DM_IN_BUFFER | DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -185,39 +180,38 @@ err_exit:
}
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);
int block_size = devmode->dmSize + devmode->dmDriverExtra;
int block_written;
char devname[dmDeviceNameSize];
{
DEVMODE *devmode = (DEVMODE *) GlobalLock(hDevMode);
int block_size = devmode->dmSize + devmode->dmDriverExtra;
int block_written;
char devname[dmDeviceNameSize];
strcpy(devname, (const char *) devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode);
fclose(fp);
return block_size == block_written;
}
strcpy(devname, (const char *)devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode);
fclose(fp);
return block_size == block_written;
}
return 0;
}
static int FileExists(const char *filepath)
{
FILE *fp;
FILE *fp;
if ((fp = fopen(filepath, "rb")) != NULL)
if ((fp = fopen(filepath, "rb")) != NULL)
{
fclose(fp);
return 1;
}
return 0;
return 0;
}
static int GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
@ -237,23 +231,22 @@ static int GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
pd.hDevMode = LoadCustomPrinterHDEVMODE(hWnd, printcfg);
if (show || !FileExists(printcfg))
{
if (PrintDlg(&pd))
{
hDCprinter = pd.hDC;
SaveCustomPrinterHDEVMODE(hWnd, printcfg, pd.hDevMode);
if (PrintDlg(&pd))
{
hDCprinter = pd.hDC;
SaveCustomPrinterHDEVMODE(hWnd, printcfg, pd.hDevMode);
GlobalFree(pd.hDevMode);
return 1;
}
GlobalFree(pd.hDevMode);
return 1;
return 0;
}
GlobalFree(pd.hDevMode);
return 0;
}
{
DEVMODE *devmode = (DEVMODE *) GlobalLock(pd.hDevMode);
hDCprinter =
CreateDC(NULL, (const char *) devmode->dmDeviceName, NULL, devmode);
hDCprinter = CreateDC(NULL, (const char *)devmode->dmDeviceName, NULL, devmode);
GlobalUnlock(pd.hDevMode);
GlobalFree(pd.hDevMode);
}
@ -276,9 +269,9 @@ static int GetPrinterDC(HWND hWnd, const char *printcfg, int show)
hDCprinter = NULL;
if (printcfg)
{
return GetCustomPrinterDC(hWnd, printcfg, show);
}
{
return GetCustomPrinterDC(hWnd, printcfg, show);
}
hDCprinter = GetDefaultPrinterDC();
return 1;
}
@ -292,8 +285,7 @@ int IsPrinterAvailable(void)
#define STRETCH_TO_FIT 0
#define SCALE_TO_FIT 1
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;
@ -316,10 +308,10 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
hWnd = wminfo.window;
if (!GetPrinterDC(hWnd, printcfg, showdialog))
{
ShowWindow(hWnd, SW_SHOWNORMAL);
return NULL;
}
{
ShowWindow(hWnd, SW_SHOWNORMAL);
return NULL;
}
if (!hDCprinter)
return "win32_print: GetPrinterDC() failed.";
@ -334,26 +326,26 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
nError = StartDoc(hDCprinter, &di);
if (nError == SP_ERROR)
{
res = "win32_print: StartDoc() failed.";
goto error;
}
{
res = "win32_print: StartDoc() failed.";
goto error;
}
nError = StartPage(hDCprinter);
if (nError <= 0)
{
res = "win32_print: StartPage() failed.";
goto error;
}
{
res = "win32_print: StartPage() failed.";
goto error;
}
//////////////////////////////////////////////////////////////////////////////////////
surf24 = make24bitDIB(surf);
if (!surf24)
{
res = "win32_print: make24bitDIB() failed.";
goto error;
}
{
res = "win32_print: make24bitDIB() failed.";
goto error;
}
memset(&bmih, 0, sizeof(bmih));
bmih.biSize = sizeof(bmih);
@ -363,104 +355,105 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
bmih.biWidth = surf24->w;
bmih.biHeight = surf24->h;
pageWidth = GetDeviceCaps(hDCprinter, HORZRES);
pageWidth = GetDeviceCaps(hDCprinter, HORZRES);
pageHeight = GetDeviceCaps(hDCprinter, VERTRES);
sX = GetDeviceCaps(hDCprinter, LOGPIXELSX);
sY = GetDeviceCaps(hDCprinter, LOGPIXELSY);
sX = GetDeviceCaps(hDCprinter, LOGPIXELSX);
sY = GetDeviceCaps(hDCprinter, LOGPIXELSY);
switch (scaling)
{
case STRETCH_TO_FIT:
{
case STRETCH_TO_FIT:
{
/* stretches x and y dimensions independently to fit the page */
/* doesn't preserve image aspect-ratio */
rcDst.top = 0; rcDst.left = 0;
rcDst.bottom = pageHeight; rcDst.right = pageWidth;
rcDst.top = 0;
rcDst.left = 0;
rcDst.bottom = pageHeight;
rcDst.right = pageWidth;
break;
}
}
case SCALE_TO_FIT:
{
{
/* maximises image size on the page */
/* preserves aspect-ratio, alignment is top and center */
int width = bmih.biWidth;
int width = bmih.biWidth;
int height = bmih.biHeight;
if (width < pageWidth && height < pageHeight)
{
float dW = (float)pageWidth / width;
float dH = (float)pageHeight / height;
{
float dW = (float)pageWidth / width;
float dH = (float)pageHeight / height;
if (dW < dH)
{
width = pageWidth;
height = (int)((height * dW * (sY/sX)) + 0.5f);
}
{
width = pageWidth;
height = (int)((height * dW * (sY / sX)) + 0.5f);
}
else
{
width = (int)((width * dH * (sX/sY)) + 0.5f);
{
width = (int)((width * dH * (sX / sY)) + 0.5f);
height = pageHeight;
}
}
}
}
if (width > pageWidth)
{
height= height*width/pageWidth;
{
height = height * width / pageWidth;
width = pageWidth;
}
}
if (height > pageHeight)
{
width= width*height/pageHeight;
{
width = width * height / pageHeight;
height = pageHeight;
}
}
rcDst.top = 0;
rcDst.left = (pageWidth-width)/2;
rcDst.bottom = rcDst.top+height;
rcDst.right = rcDst.left+width;
rcDst.left = (pageWidth - width) / 2;
rcDst.bottom = rcDst.top + height;
rcDst.right = rcDst.left + width;
break;
}
}
default:
res = "win32_print: invalid scaling option.";
goto error;
}
res = "win32_print: invalid scaling option.";
goto error;
}
hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS);
if (hDCCaps & RC_PALETTE)
{
res = "win32_print: printer context requires palette.";
goto error;
}
if (hDCCaps & RC_STRETCHDIB)
{
SetStretchBltMode(hDCprinter, COLORONCOLOR);
nError = StretchDIBits(hDCprinter, rcDst.left, rcDst.top,
rcDst.right - rcDst.left,
rcDst.bottom - rcDst.top,
0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, (BITMAPINFO *) & bmih,
DIB_RGB_COLORS, SRCCOPY);
if (nError == GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
res = "win32_print: printer context requires palette.";
goto error;
}
}
if (hDCCaps & RC_STRETCHDIB)
{
SetStretchBltMode(hDCprinter, COLORONCOLOR);
nError = StretchDIBits(hDCprinter, rcDst.left, rcDst.top,
rcDst.right - rcDst.left,
rcDst.bottom - rcDst.top,
0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, (BITMAPINFO *) & bmih, DIB_RGB_COLORS, SRCCOPY);
if (nError == GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
goto error;
}
}
else
{
res = "win32_print: StretchDIBits() not available.";
goto error;
}
{
res = "win32_print: StretchDIBits() not available.";
goto error;
}
//////////////////////////////////////////////////////////////////////////////////////
nError = EndPage(hDCprinter);
if (nError <= 0)
{
res = "win32_print: EndPage() failed.";
goto error;
}
{
res = "win32_print: EndPage() failed.";
goto error;
}
EndDoc(hDCprinter);
@ -482,8 +475,7 @@ 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;
@ -491,9 +483,7 @@ static HRESULT ReadRegistry(const char *key, const char *option, char *value,
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;
@ -529,18 +519,17 @@ char *GetDefaultSaveDir(const char *suffix)
{
char prefix[MAX_PATH];
char path[2 * 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 = "AppData";
HRESULT hr = S_OK;
if (SUCCEEDED(hr = ReadRegistry(key, option, prefix, sizeof(prefix))))
{
remove_slash(prefix);
snprintf(path, sizeof(path), "%s/%s", prefix, suffix);
_mkdir(path);
return strdup(path);
}
{
remove_slash(prefix);
snprintf(path, sizeof(path), "%s/%s", prefix, suffix);
_mkdir(path);
return strdup(path);
}
return strdup("userdata");
}
@ -551,16 +540,15 @@ 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;
if (SUCCEEDED(hr = ReadRegistry(key, option, path, sizeof(path))))
{
remove_slash(path);
return strdup(path);
}
{
remove_slash(path);
return strdup(path);
}
return strdup("C:\\WINDOWS\\FONTS");
}
@ -573,9 +561,9 @@ static char *GetUserTempDir(void)
char *temp = getenv("TEMP");
if (!temp)
{
temp = "userdata";
}
{
temp = "userdata";
}
return strdup(temp);
}
@ -594,27 +582,27 @@ char *get_temp_fname(const char *const name)
*/
static HHOOK g_hKeyboardHook = NULL;
static int g_bWindowActive = 0;
static int g_bWindowActive = 0;
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
int bEatKeystroke = 0;
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT*)lParam;
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *) lParam;
if (nCode < 0 || nCode != HC_ACTION)
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
switch (wParam)
{
case WM_KEYDOWN:
case WM_KEYUP:
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
switch (wParam)
{
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN));
break;
case WM_KEYDOWN:
case WM_KEYUP:
{
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN));
break;
}
}
}
if(bEatKeystroke)
if (bEatKeystroke)
return 1;
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
}
@ -640,5 +628,3 @@ void SetActivationState(int state)
{
g_bWindowActive = state;
}

View file

@ -15,8 +15,7 @@
#endif
/* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint(SDL_Surface * surf,
const char *printcfg, int showdialog);
extern const char *SurfacePrint(SDL_Surface * surf, const char *printcfg, int showdialog);
extern int IsPrinterAvailable(void);
/* additional windows functions requiring <windows.h> */
@ -25,8 +24,8 @@ extern char *GetSystemFontDir(void);
extern char *get_temp_fname(const char *const name);
/* keyboard hooking functions */
extern int InstallKeyboardHook(void);
extern int RemoveKeyboardHook(void);
extern int InstallKeyboardHook(void);
extern int RemoveKeyboardHook(void);
extern void SetActivationState(int state);
#endif