Adding "indent.sh" to re-indent code; ran it!!!
This commit is contained in:
parent
16336cc854
commit
18f9cad6fe
98 changed files with 5798 additions and 9001 deletions
|
|
@ -32,15 +32,15 @@ char *get_nativelibdir()
|
|||
return nativelibdir;
|
||||
}
|
||||
|
||||
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
|
||||
unsigned *num_file_names)
|
||||
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames, unsigned *num_file_names)
|
||||
{
|
||||
AAssetDir *assetDir = AAssetManager_openDir(asset_manager, dirname);
|
||||
const char *filename = (const char *) NULL;
|
||||
const char *filename = (const char *)NULL;
|
||||
tp_ftw_str *filenames = NULL;
|
||||
|
||||
unsigned max_file_names = 0;
|
||||
int fulllen = 0;
|
||||
|
||||
*num_file_names = 0;
|
||||
|
||||
|
||||
|
|
@ -67,12 +67,7 @@ void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
|
|||
*ffilenames = filenames;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
|
||||
env,
|
||||
jclass
|
||||
clazz,
|
||||
jobject
|
||||
mgr)
|
||||
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv * env, jclass clazz, jobject mgr)
|
||||
{
|
||||
asset_manager = AAssetManager_fromJava(env, mgr);
|
||||
|
||||
|
|
@ -82,14 +77,10 @@ JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
|
|||
return 1;
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv *
|
||||
env,
|
||||
jclass
|
||||
clazz,
|
||||
jstring
|
||||
path)
|
||||
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv * env, jclass clazz, jstring path)
|
||||
{
|
||||
const char *cpath = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
|
||||
nativelibdir = strdup(cpath);
|
||||
(*env)->ReleaseStringUTFChars(env, path, cpath);
|
||||
}
|
||||
|
|
@ -102,8 +93,7 @@ void load_brushes_from_assets(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))
|
||||
unsigned count, const char *restrict const locale))
|
||||
{
|
||||
unsigned num_file_names = 0;
|
||||
char *dir = "data/brushes";
|
||||
|
|
@ -127,10 +117,10 @@ void load_from_assets(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))
|
||||
unsigned count, const char *restrict const locale))
|
||||
{
|
||||
unsigned num_file_names = 0;
|
||||
|
||||
// char * dir = "data/stamps/cartoon/tux";
|
||||
char buf[TP_FTW_PATHSIZE];
|
||||
unsigned dirlen = strlen(dirname);
|
||||
|
|
@ -140,6 +130,5 @@ void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
|
|||
tp_ftw_str *filenames = NULL;
|
||||
|
||||
load_assets_dir(dirname, &filenames, &num_file_names);
|
||||
fn(screen, texture, renderer, dirname, dirlen, filenames, num_file_names,
|
||||
NULL);
|
||||
fn(screen, texture, renderer, dirname, dirlen, filenames, num_file_names, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ void load_brushes_from_assets(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));
|
||||
unsigned count, const char *restrict const locale));
|
||||
|
||||
void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, const char *dirname,
|
||||
|
|
@ -47,24 +46,12 @@ void load_from_assets(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));
|
||||
unsigned count, const char *restrict const locale));
|
||||
|
||||
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
|
||||
unsigned *num_file_names);
|
||||
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames, unsigned *num_file_names);
|
||||
|
||||
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
|
||||
env,
|
||||
jclass
|
||||
clazz,
|
||||
jobject
|
||||
mgr);
|
||||
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv * env, jclass clazz, jobject mgr);
|
||||
|
||||
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv *
|
||||
env,
|
||||
jclass
|
||||
clazz,
|
||||
jstring
|
||||
path);
|
||||
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv * env, jclass clazz, jstring path);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n)
|
||||
{
|
||||
int length = strnlen(s, n);
|
||||
|
||||
// w is the index of pwcs, s is the index of s
|
||||
int w = 0, c = 0;
|
||||
|
||||
|
|
@ -41,9 +42,10 @@ size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n)
|
|||
pwcs[w] = '\0';
|
||||
char first = s[c];
|
||||
int len = 0;
|
||||
|
||||
if ((first & 0x80) == 0)
|
||||
{
|
||||
pwcs[w] = (wchar_t) s[c];
|
||||
pwcs[w] = (wchar_t)s[c];
|
||||
len = 1;
|
||||
}
|
||||
else if ((first & 0xe0) == 0xc0)
|
||||
|
|
|
|||
|
|
@ -34,17 +34,14 @@
|
|||
int IsPrinterAvailable(void)
|
||||
{
|
||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||
jclass mPrintHelperClass =
|
||||
(*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
|
||||
jclass mPrintHelperClass = (*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
|
||||
|
||||
if (mPrintHelperClass == NULL)
|
||||
return 0;
|
||||
|
||||
jmethodID mSupportMethod =
|
||||
(*mEnv)->GetStaticMethodID(mEnv, mPrintHelperClass, "systemSupportsPrint",
|
||||
"()Z");
|
||||
jboolean support =
|
||||
(*mEnv)->CallStaticBooleanMethod(mEnv, mPrintHelperClass, mSupportMethod);
|
||||
jmethodID mSupportMethod = (*mEnv)->GetStaticMethodID(mEnv, mPrintHelperClass, "systemSupportsPrint",
|
||||
"()Z");
|
||||
jboolean support = (*mEnv)->CallStaticBooleanMethod(mEnv, mPrintHelperClass, mSupportMethod);
|
||||
|
||||
return support ? 1 : 0;
|
||||
}
|
||||
|
|
@ -56,49 +53,41 @@ const char *SurfacePrint(SDL_Surface * surface)
|
|||
{
|
||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||
jclass mBitmapClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap");
|
||||
jmethodID mCreateMethod =
|
||||
(*mEnv)->GetStaticMethodID(mEnv, mBitmapClass, "createBitmap",
|
||||
"([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
|
||||
jintArray mSurfaceArray =
|
||||
(*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
|
||||
(*mEnv)->SetIntArrayRegion(mEnv, mSurfaceArray, 0, surface->w * surface->h,
|
||||
surface->pixels);
|
||||
jclass mConfigClass =
|
||||
(*mEnv)->FindClass(mEnv, "android/graphics/Bitmap$Config");
|
||||
jfieldID mConfigField =
|
||||
(*mEnv)->GetStaticFieldID(mEnv, mConfigClass, "ARGB_8888",
|
||||
"Landroid/graphics/Bitmap$Config;");
|
||||
jobject mConfig =
|
||||
(*mEnv)->GetStaticObjectField(mEnv, mConfigClass, mConfigField);
|
||||
jobject mBitMap =
|
||||
(*mEnv)->CallStaticObjectMethod(mEnv, mBitmapClass, mCreateMethod,
|
||||
mSurfaceArray, surface->w, surface->h,
|
||||
mConfig);
|
||||
jmethodID mCreateMethod = (*mEnv)->GetStaticMethodID(mEnv, mBitmapClass, "createBitmap",
|
||||
"([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
|
||||
jintArray mSurfaceArray = (*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
|
||||
|
||||
(*mEnv)->SetIntArrayRegion(mEnv, mSurfaceArray, 0, surface->w * surface->h, surface->pixels);
|
||||
jclass mConfigClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap$Config");
|
||||
jfieldID mConfigField = (*mEnv)->GetStaticFieldID(mEnv, mConfigClass, "ARGB_8888",
|
||||
"Landroid/graphics/Bitmap$Config;");
|
||||
jobject mConfig = (*mEnv)->GetStaticObjectField(mEnv, mConfigClass, mConfigField);
|
||||
jobject mBitMap = (*mEnv)->CallStaticObjectMethod(mEnv, mBitmapClass, mCreateMethod,
|
||||
mSurfaceArray, surface->w, surface->h,
|
||||
mConfig);
|
||||
|
||||
jobject mContext = (jobject) SDL_AndroidGetActivity();
|
||||
jclass mPrintClass = (*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
|
||||
|
||||
// sometimes android v4 support library may be not ready
|
||||
if (mPrintClass == NULL)
|
||||
return "There is no androidX support library.";
|
||||
jmethodID mInitMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "<init>",
|
||||
"(Landroid/content/Context;)V");
|
||||
jobject mPrint =
|
||||
(*mEnv)->NewObject(mEnv, mPrintClass, mInitMethod, mContext);
|
||||
jmethodID mPrintMethod =
|
||||
(*mEnv)->GetMethodID(mEnv, mPrintClass, "printBitmap",
|
||||
"(Ljava/lang/String;Landroid/graphics/Bitmap;)V");
|
||||
jobject mPrint = (*mEnv)->NewObject(mEnv, mPrintClass, mInitMethod, mContext);
|
||||
jmethodID mPrintMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "printBitmap",
|
||||
"(Ljava/lang/String;Landroid/graphics/Bitmap;)V");
|
||||
|
||||
/* Thanks to n.collins for the explaination on the int signature
|
||||
on https://stackoverflow.com/questions/13468041/android-how-to-call-java-method-from-jni-with-int-and-int-parameters --Pere */
|
||||
jmethodID msetScaleMode =
|
||||
(*mEnv)->GetMethodID(mEnv, mPrintClass, "setScaleMode", "(I)V");
|
||||
jfieldID mScaleModeField =
|
||||
(*mEnv)->GetStaticFieldID(mEnv, mPrintClass, "SCALE_MODE_FIT", "I");
|
||||
jint mScaleModeInt =
|
||||
(*mEnv)->GetStaticIntField(mEnv, mPrintClass, mScaleModeField);
|
||||
jmethodID msetScaleMode = (*mEnv)->GetMethodID(mEnv, mPrintClass, "setScaleMode", "(I)V");
|
||||
jfieldID mScaleModeField = (*mEnv)->GetStaticFieldID(mEnv, mPrintClass, "SCALE_MODE_FIT", "I");
|
||||
jint mScaleModeInt = (*mEnv)->GetStaticIntField(mEnv, mPrintClass, mScaleModeField);
|
||||
|
||||
(*mEnv)->CallVoidMethod(mEnv, mPrint, msetScaleMode, mScaleModeInt);
|
||||
|
||||
jstring mString = (*mEnv)->NewStringUTF(mEnv, "TuxPaint");
|
||||
|
||||
(*mEnv)->CallVoidMethod(mEnv, mPrint, mPrintMethod, mString, mBitMap);
|
||||
|
||||
// clean up
|
||||
|
|
|
|||
|
|
@ -34,8 +34,7 @@
|
|||
|
||||
SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
|
||||
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate,
|
||||
*cursor_pipette;
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate, *cursor_pipette;
|
||||
|
||||
#ifdef NOKIA_770
|
||||
int hide_cursor = 1;
|
||||
|
|
|
|||
|
|
@ -70,8 +70,7 @@
|
|||
|
||||
extern SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
|
||||
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate,
|
||||
*cursor_pipette;
|
||||
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate, *cursor_pipette;
|
||||
|
||||
extern int no_fancy_cursors, hide_cursor;
|
||||
|
||||
|
|
|
|||
|
|
@ -82,8 +82,7 @@ extern char *strcasestr(const char *haystack, const char *needle);
|
|||
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)
|
||||
tp_ftw_str * files, unsigned i, const char *restrict const locale)
|
||||
{
|
||||
dirlen = dirlen;
|
||||
|
||||
|
|
@ -153,10 +152,8 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
}
|
||||
if (font)
|
||||
{
|
||||
const char *restrict const family =
|
||||
TuxPaint_Font_FontFaceFamilyName(font);
|
||||
const char *restrict const style =
|
||||
TuxPaint_Font_FontFaceStyleName(font);
|
||||
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
|
||||
const char *restrict const style = TuxPaint_Font_FontFaceStyleName(font);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
@ -165,22 +162,19 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
int numfaces = TTF_FontFaces(font->ttf_font);
|
||||
|
||||
if (numfaces != 1)
|
||||
printf("%s:%d - Found %d faces in %s, %s, %s\n", __FILE__,
|
||||
__LINE__, numfaces, files[i].str, family, style);
|
||||
printf("%s:%d - Found %d faces in %s, %s, %s\n", __FILE__, __LINE__, numfaces, files[i].str, family, style);
|
||||
|
||||
printf("%s:%d - success: tpf: 0x%x tpf->ttf_font: 0x%x\n", __FILE__, __LINE__, (unsigned int) (intptr_t) font, (unsigned int) (intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
|
||||
printf("%s:%d - success: tpf: 0x%x tpf->ttf_font: 0x%x\n", __FILE__, __LINE__, (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
|
||||
}
|
||||
#ifndef NO_SDLPANGO
|
||||
else
|
||||
printf("%s:%d - success: tpf: 0x%x tpf->pango_context: 0x%x\n",
|
||||
__FILE__, __LINE__, (unsigned int) (intptr_t) font,
|
||||
(unsigned int) (intptr_t) font->pango_context);
|
||||
__FILE__, __LINE__, (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->pango_context);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// These fonts crash Tux Paint via a library bug.
|
||||
int blacklisted = !strcmp("Zapfino", family)
|
||||
|| !strcmp("Elvish Ring NFI", family);
|
||||
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
|
||||
|
|
@ -201,8 +195,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
// 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")))
|
||||
if (!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
|
||||
blacklisted = 1;
|
||||
|
||||
if (!blacklisted)
|
||||
|
|
@ -210,12 +203,9 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
if (num_font_styles == num_font_styles_max)
|
||||
{
|
||||
num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
|
||||
user_font_styles =
|
||||
realloc(user_font_styles,
|
||||
num_font_styles_max * sizeof *user_font_styles);
|
||||
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles);
|
||||
}
|
||||
user_font_styles[num_font_styles] =
|
||||
malloc(sizeof *user_font_styles[num_font_styles]);
|
||||
user_font_styles[num_font_styles] = malloc(sizeof *user_font_styles[num_font_styles]);
|
||||
user_font_styles[num_font_styles]->directory = strdup(dir);
|
||||
user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below)
|
||||
user_font_styles[num_font_styles]->family = strdup(family);
|
||||
|
|
@ -230,52 +220,46 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
// Translators should do whatever is needed to put crummy fonts last.
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* distinct uppercase and lowercase (e.g., 'o' vs. 'O') */ gettext("oO")
|
||||
charset_works(font, /* distinct uppercase and lowercase (e.g., 'o' vs. 'O') */ gettext("oO")
|
||||
);
|
||||
|
||||
// common punctuation (e.g., '?', '!', '.', ',', etc.)
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* common punctuation (e.g., '?', '!', '.', ',', etc.) */ gettext(",.?!")
|
||||
charset_works(font, /* common punctuation (e.g., '?', '!', '.', ',', etc.) */ gettext(",.?!")
|
||||
);
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* uncommon punctuation (e.g., '@', '#', '*', etc.) */ gettext("`\%_@$~#{<(^&*")
|
||||
charset_works(font, /* uncommon punctuation (e.g., '@', '#', '*', etc.) */ gettext("`\%_@$~#{<(^&*")
|
||||
);
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* digits (e.g., '0', '1' and '7') */ gettext("017")
|
||||
charset_works(font, /* digits (e.g., '0', '1' and '7') */ gettext("017")
|
||||
);
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */ gettext("O0")
|
||||
charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */
|
||||
gettext("O0")
|
||||
);
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
charset_works(
|
||||
font, /* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */ gettext("1Il|")
|
||||
);
|
||||
charset_works(font,
|
||||
/* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */
|
||||
gettext("1Il|")
|
||||
);
|
||||
|
||||
// Translation spares
|
||||
|
||||
|
||||
user_font_styles[num_font_styles]->score +=
|
||||
// If neccessary, translate any of following strings using at least
|
||||
// two locale specific characters required to render your language.
|
||||
// Then, the scores for those fonts having such characters will increase.
|
||||
//
|
||||
// You can use two different weight for scoring, 1 or 9, according
|
||||
// to the importance.
|
||||
// If neccessary, translate any of following strings using at least
|
||||
// two locale specific characters required to render your language.
|
||||
// Then, the scores for those fonts having such characters will increase.
|
||||
//
|
||||
// You can use two different weight for scoring, 1 or 9, according
|
||||
// to the importance.
|
||||
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-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;
|
||||
|
||||
// this really should be dynamic, avoiding the need for a special build
|
||||
#ifdef OLPC_XO
|
||||
|
|
@ -292,8 +276,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
|
|||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Font is too defective: %s, %s, %s\n", files[i].str,
|
||||
family, style);
|
||||
fprintf(stderr, "Font is too defective: %s, %s, %s\n", files[i].str, family, style);
|
||||
#endif
|
||||
}
|
||||
TuxPaint_Font_CloseFont(font);
|
||||
|
|
@ -349,9 +332,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
|
|||
dir, unsigned dirlen,
|
||||
tp_ftw_str * files,
|
||||
unsigned count,
|
||||
const char *restrict const
|
||||
locale),
|
||||
const char *restrict const locale)
|
||||
const char *restrict const locale), const char *restrict const locale)
|
||||
{
|
||||
DIR *d;
|
||||
unsigned num_file_names = 0;
|
||||
|
|
@ -362,6 +343,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
|
|||
tp_ftw_str *dir_names = NULL;
|
||||
int d_namlen;
|
||||
int add_rsrc;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
unsigned dlen;
|
||||
#endif
|
||||
|
|
@ -532,12 +514,10 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
|
|||
#else
|
||||
#ifdef __ANDROID__
|
||||
if (dlen != dirlen) /* First case only happens in Android files coming from assets */
|
||||
fn(screen, texture, renderer, di, dlen, file_names, num_file_names,
|
||||
locale);
|
||||
fn(screen, texture, renderer, di, dlen, file_names, num_file_names, locale);
|
||||
else
|
||||
#endif
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -546,10 +526,8 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
|
|||
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);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ typedef struct 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);
|
||||
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,
|
||||
|
|
@ -62,7 +61,6 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
|
|||
tp_ftw_str * files,
|
||||
unsigned count,
|
||||
const char *restrict const
|
||||
locale),
|
||||
const char *restrict const locale);
|
||||
locale), const char *restrict const locale);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
352
src/fill.c
352
src/fill.c
|
|
@ -82,7 +82,7 @@ sdf_point sdf_pt_empty = { 9999, 9999 };
|
|||
|
||||
typedef struct sdf_grid_s
|
||||
{
|
||||
sdf_point * * grid;
|
||||
sdf_point **grid;
|
||||
int w, h;
|
||||
} sdf_grid;
|
||||
|
||||
|
|
@ -96,14 +96,10 @@ int global_extent_x1, global_extent_y1, global_extent_x2, global_extent_y2;
|
|||
int global_prog_anim;
|
||||
|
||||
double colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2);
|
||||
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr,
|
||||
double pct);
|
||||
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct);
|
||||
void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
||||
SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, int x, int y,
|
||||
int y_outside);
|
||||
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
|
||||
Uint32 draw_color, Uint8 * touched);
|
||||
SDL_Texture * texture, SDL_Renderer * renderer, int x, int y, int y_outside);
|
||||
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched);
|
||||
|
||||
void init_queue(void);
|
||||
void add_to_queue(int x, int y, int y_outside);
|
||||
|
|
@ -140,9 +136,8 @@ void add_to_queue(int x, int y, int y_outside)
|
|||
if (queue_end + 1 > queue_size)
|
||||
{
|
||||
queue_t *tmp;
|
||||
tmp =
|
||||
(queue_t *) realloc(queue,
|
||||
sizeof(queue_t) * (queue_size + QUEUE_SIZE_CHUNK));
|
||||
|
||||
tmp = (queue_t *) realloc(queue, sizeof(queue_t) * (queue_size + QUEUE_SIZE_CHUNK));
|
||||
if (tmp == NULL)
|
||||
{
|
||||
fprintf(stderr, "Fill queue cannot be realloc()'d\n");
|
||||
|
|
@ -256,25 +251,22 @@ int would_flood_fill(SDL_Surface * canvas, Uint32 cur_colr, Uint32 old_colr)
|
|||
void do_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, SDL_Surface * last,
|
||||
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
|
||||
Uint8 * touched)
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched)
|
||||
{
|
||||
simulate_flood_fill(screen, texture, renderer, last, canvas, x, y, cur_colr,
|
||||
old_colr, x1, y1, x2, y2, touched);
|
||||
simulate_flood_fill(screen, texture, renderer, last, canvas, x, y, cur_colr, old_colr, x1, y1, x2, y2, touched);
|
||||
}
|
||||
|
||||
|
||||
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr,
|
||||
double pct)
|
||||
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct)
|
||||
{
|
||||
Uint8 old_r, old_g, old_b, draw_r, draw_g, draw_b, new_r, new_g, new_b;
|
||||
|
||||
SDL_GetRGB(draw_colr, canvas->format, &draw_r, &draw_g, &draw_b);
|
||||
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
|
||||
|
||||
new_r = (Uint8) (((float) old_r) * (1.00 - pct) + ((float) draw_r * pct));
|
||||
new_g = (Uint8) (((float) old_g) * (1.00 - pct) + ((float) draw_g * pct));
|
||||
new_b = (Uint8) (((float) old_b) * (1.00 - pct) + ((float) draw_b * pct));
|
||||
new_r = (Uint8) (((float)old_r) * (1.00 - pct) + ((float)draw_r * pct));
|
||||
new_g = (Uint8) (((float)old_g) * (1.00 - pct) + ((float)draw_g * pct));
|
||||
new_b = (Uint8) (((float)old_b) * (1.00 - pct) + ((float)draw_b * pct));
|
||||
|
||||
return SDL_MapRGB(canvas->format, draw_r, draw_g, draw_b);
|
||||
return SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
|
|
@ -308,8 +300,7 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
|
|||
/* Do the work (possibly queuing more, as we go) */
|
||||
while (remove_from_queue(&x, &y, &y_outside))
|
||||
{
|
||||
simulate_flood_fill_outside_check(screen, texture, renderer, x, y,
|
||||
y_outside);
|
||||
simulate_flood_fill_outside_check(screen, texture, renderer, x, y, y_outside);
|
||||
}
|
||||
cleanup_queue();
|
||||
|
||||
|
|
@ -320,9 +311,7 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
|
|||
}
|
||||
|
||||
void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
||||
SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, int x, int y,
|
||||
int y_outside)
|
||||
SDL_Texture * texture, SDL_Renderer * renderer, int x, int y, int y_outside)
|
||||
{
|
||||
int fillL, fillR, narrowFillL, narrowFillR, i, outside, just_queued;
|
||||
double in_line, closeness;
|
||||
|
|
@ -374,9 +363,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
|
||||
/* Find left side, filling along the way */
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last,
|
||||
fillL /* - 1 */ , y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL /* - 1 */ , y);
|
||||
in_line = colors_close(global_canvas, px_colr, global_old_colr);
|
||||
outside = 0;
|
||||
while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD)
|
||||
|
|
@ -399,17 +386,12 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
|
||||
}
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y,
|
||||
blend(global_canvas,
|
||||
global_cur_colr,
|
||||
px_colr,
|
||||
(1.0 - in_line)));
|
||||
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
|
||||
fillL--;
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
|
||||
if (fillL >= 0)
|
||||
{
|
||||
|
|
@ -432,13 +414,9 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
|
||||
}
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
|
||||
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y,
|
||||
blend(global_canvas,
|
||||
global_cur_colr,
|
||||
px_colr,
|
||||
(1.0 - in_line)));
|
||||
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -452,8 +430,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
|
||||
/* Find right side, filling along the way */
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillR + 1, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR + 1, y);
|
||||
in_line = colors_close(global_canvas, px_colr, global_old_colr);
|
||||
outside = 0;
|
||||
while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD)
|
||||
|
|
@ -476,17 +453,12 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
|
||||
}
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y,
|
||||
blend(global_canvas,
|
||||
global_cur_colr,
|
||||
px_colr,
|
||||
(1.0 - in_line)));
|
||||
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
|
||||
fillR++;
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
|
||||
if (fillR < global_canvas->w)
|
||||
{
|
||||
|
|
@ -509,13 +481,9 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
|
||||
}
|
||||
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
|
||||
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y,
|
||||
blend(global_canvas,
|
||||
global_cur_colr,
|
||||
px_colr,
|
||||
(1.0 - in_line)));
|
||||
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
|
||||
}
|
||||
|
||||
if (fillR > global_extent_x2)
|
||||
|
|
@ -533,15 +501,11 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
{
|
||||
for (i = narrowFillL; i <= narrowFillR; i++)
|
||||
{
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1);
|
||||
closeness = colors_close(global_canvas, px_colr, global_old_colr);
|
||||
if (closeness < COLOR_MATCH_NARROW ||
|
||||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
|
||||
if (closeness < COLOR_MATCH_NARROW || (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
|
||||
{
|
||||
if (!just_queued
|
||||
&& (global_touched == NULL
|
||||
|| !global_touched[((y - 1) * global_canvas->w) + i]))
|
||||
if (!just_queued && (global_touched == NULL || !global_touched[((y - 1) * global_canvas->w) + i]))
|
||||
{
|
||||
add_to_queue(i, y - 1, y_outside + 1);
|
||||
just_queued = 1;
|
||||
|
|
@ -566,15 +530,11 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
{
|
||||
for (i = narrowFillL; i <= narrowFillR; i++)
|
||||
{
|
||||
px_colr =
|
||||
getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1);
|
||||
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1);
|
||||
closeness = colors_close(global_canvas, px_colr, global_old_colr);
|
||||
if (closeness < COLOR_MATCH_NARROW ||
|
||||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
|
||||
if (closeness < COLOR_MATCH_NARROW || (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
|
||||
{
|
||||
if (!just_queued
|
||||
&& (global_touched == NULL
|
||||
|| !global_touched[((y + 1) * global_canvas->w) + i]))
|
||||
if (!just_queued && (global_touched == NULL || !global_touched[((y + 1) * global_canvas->w) + i]))
|
||||
{
|
||||
add_to_queue(i, y + 1, y_outside + 1);
|
||||
just_queued = 1;
|
||||
|
|
@ -595,8 +555,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
|
|||
|
||||
void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color,
|
||||
Uint8 * touched)
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched)
|
||||
{
|
||||
Uint32 old_colr, new_colr;
|
||||
int xx, yy;
|
||||
|
|
@ -643,17 +602,11 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
|||
}
|
||||
|
||||
/* Apply fuzziness at any antialiased edges we detected */
|
||||
ratio = (ratio * ((float) touched[yy * canvas->w + xx] / 255.0));
|
||||
ratio = (ratio * ((float)touched[yy * canvas->w + xx] / 255.0));
|
||||
|
||||
new_r =
|
||||
(Uint8) (((float) old_r) * ratio +
|
||||
((float) draw_r * (1.0 - ratio)));
|
||||
new_g =
|
||||
(Uint8) (((float) old_g) * ratio +
|
||||
((float) draw_g * (1.0 - ratio)));
|
||||
new_b =
|
||||
(Uint8) (((float) old_b) * ratio +
|
||||
((float) draw_b * (1.0 - ratio)));
|
||||
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.0 - ratio)));
|
||||
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.0 - ratio)));
|
||||
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.0 - ratio)));
|
||||
|
||||
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
|
||||
|
|
@ -662,8 +615,7 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
|||
}
|
||||
}
|
||||
|
||||
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
|
||||
Uint32 draw_color, Uint8 * touched)
|
||||
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched)
|
||||
{
|
||||
int xx, yy;
|
||||
int pix;
|
||||
|
|
@ -675,13 +627,12 @@ void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
|
|||
pix = ((y + yy) * canvas->w) + (x + xx);
|
||||
|
||||
if (pix >= 0 && pix < canvas->w * canvas->h)
|
||||
{
|
||||
if ((xx * xx) + (yy * yy) < (16 * 16) && touched[pix])
|
||||
{
|
||||
if ((xx * xx) + (yy * yy) < (16 * 16) && touched[pix])
|
||||
{
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy,
|
||||
draw_color);
|
||||
}
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy, draw_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -690,8 +641,7 @@ void draw_brush_fill(SDL_Surface * canvas,
|
|||
int x_left ATTRIBUTE_UNUSED, int y_top ATTRIBUTE_UNUSED,
|
||||
int x_right ATTRIBUTE_UNUSED,
|
||||
int y_bottom ATTRIBUTE_UNUSED, int x1, int y1, int x2,
|
||||
int y2, Uint32 draw_color, Uint8 * touched, int *up_x1,
|
||||
int *up_y1, int *up_x2, int *up_y2)
|
||||
int y2, Uint32 draw_color, Uint8 * touched, int *up_x1, int *up_y1, int *up_x2, int *up_y2)
|
||||
{
|
||||
int dx, dy;
|
||||
int y;
|
||||
|
|
@ -709,7 +659,7 @@ void draw_brush_fill(SDL_Surface * canvas,
|
|||
|
||||
if (dx != 0)
|
||||
{
|
||||
m = ((float) dy) / ((float) dx);
|
||||
m = ((float)dy) / ((float)dx);
|
||||
b = y1 - m * x1;
|
||||
|
||||
if (x2 >= x1)
|
||||
|
|
@ -770,8 +720,7 @@ void draw_brush_fill(SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
|
||||
int x_right, int y_bottom, int x, int y,
|
||||
Uint32 draw_color, Uint8 * touched)
|
||||
int x_right, int y_bottom, int x, int y, Uint32 draw_color, Uint8 * touched)
|
||||
{
|
||||
Uint32 old_colr, new_colr;
|
||||
int xx, yy;
|
||||
|
|
@ -800,40 +749,33 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
|
|||
pix = (yy * canvas->w) + xx;
|
||||
|
||||
if (pix >= 0 && pix < canvas->w * canvas->h)
|
||||
{
|
||||
if (touched[pix])
|
||||
{
|
||||
if (touched[pix])
|
||||
/* Determine the distance from the click point */
|
||||
xd = fabs((float)(xx - x));
|
||||
yd = fabs((float)(yy - y));
|
||||
dist = sqrt(xd * xd + yd * yd);
|
||||
if (dist < rad)
|
||||
{
|
||||
/* Determine the distance from the click point */
|
||||
xd = fabs((float) (xx - x));
|
||||
yd = fabs((float) (yy - y));
|
||||
dist = sqrt(xd * xd + yd * yd);
|
||||
if (dist < rad)
|
||||
{
|
||||
ratio = (dist / rad);
|
||||
ratio = (dist / rad);
|
||||
|
||||
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
|
||||
old_colr =
|
||||
getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
|
||||
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
|
||||
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
|
||||
old_colr = getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
|
||||
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
|
||||
|
||||
/* Apply fuzziness at any antialiased edges we detected */
|
||||
ratio = (ratio * ((float) touched[pix] / 255.0));
|
||||
/* Apply fuzziness at any antialiased edges we detected */
|
||||
ratio = (ratio * ((float)touched[pix] / 255.0));
|
||||
|
||||
new_r =
|
||||
(Uint8) (((float) old_r) * ratio +
|
||||
((float) draw_r * (1.00 - ratio)));
|
||||
new_g =
|
||||
(Uint8) (((float) old_g) * ratio +
|
||||
((float) draw_g * (1.00 - ratio)));
|
||||
new_b =
|
||||
(Uint8) (((float) old_b) * ratio +
|
||||
((float) draw_b * (1.00 - ratio)));
|
||||
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.00 - ratio)));
|
||||
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.00 - ratio)));
|
||||
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.00 - ratio)));
|
||||
|
||||
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
|
||||
}
|
||||
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -845,9 +787,12 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
|
|||
|
||||
void sdf_pt_get(sdf_grid * g, int x, int y, sdf_point * p)
|
||||
{
|
||||
if (x >= 0 && x < g->w && y >= 0 && y < g->h) {
|
||||
if (x >= 0 && x < g->w && y >= 0 && y < g->h)
|
||||
{
|
||||
memcpy(p, &(g->grid[y][x]), sizeof(sdf_point));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(p, &(sdf_pt_empty), sizeof(sdf_point));
|
||||
}
|
||||
}
|
||||
|
|
@ -870,37 +815,44 @@ void sdf_compare(sdf_grid * g, sdf_point * p, int x, int y, int offsetx, int off
|
|||
other.dx += offsetx;
|
||||
other.dy += offsety;
|
||||
|
||||
if (sdf_distsq(other) < sdf_distsq(*p)) {
|
||||
if (sdf_distsq(other) < sdf_distsq(*p))
|
||||
{
|
||||
p->dx = other.dx;
|
||||
p->dy = other.dy;
|
||||
}
|
||||
}
|
||||
|
||||
int malloc_sdf_grid(sdf_grid * g, int w, int h) {
|
||||
int malloc_sdf_grid(sdf_grid * g, int w, int h)
|
||||
{
|
||||
int i, abort;
|
||||
|
||||
g->w = w;
|
||||
g->h = h;
|
||||
g->grid = (sdf_point * *) malloc(h * sizeof(sdf_point *));
|
||||
if (g->grid == NULL) {
|
||||
g->grid = (sdf_point * *)malloc(h * sizeof(sdf_point *));
|
||||
if (g->grid == NULL)
|
||||
{
|
||||
fprintf(stderr, "malloc_sdf_grid() cannot malloc() g->grid!\n");
|
||||
free(g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < h; i++) {
|
||||
for (i = 0; i < h; i++)
|
||||
{
|
||||
g->grid[i] = NULL;
|
||||
}
|
||||
|
||||
abort = 0;
|
||||
for (i = 0; i < h && !abort; i++) {
|
||||
for (i = 0; i < h && !abort; i++)
|
||||
{
|
||||
g->grid[i] = (sdf_point *) malloc(w * sizeof(sdf_point));
|
||||
if (g->grid[i] == NULL) {
|
||||
if (g->grid[i] == NULL)
|
||||
{
|
||||
abort = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (abort) {
|
||||
if (abort)
|
||||
{
|
||||
fprintf(stderr, "malloc_sdf_grid() cannot malloc() g->grid[]!\n");
|
||||
free_sdf_grid(g);
|
||||
return 0;
|
||||
|
|
@ -909,11 +861,14 @@ int malloc_sdf_grid(sdf_grid * g, int w, int h) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void free_sdf_grid(sdf_grid * g) {
|
||||
void free_sdf_grid(sdf_grid * g)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g->h; i++) {
|
||||
if (g->grid[i] != NULL) {
|
||||
for (i = 0; i < g->h; i++)
|
||||
{
|
||||
if (g->grid[i] != NULL)
|
||||
{
|
||||
free(g->grid[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -921,15 +876,21 @@ void free_sdf_grid(sdf_grid * g) {
|
|||
}
|
||||
|
||||
|
||||
void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1, sdf_grid * g2) {
|
||||
void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1, sdf_grid * g2)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
if (bitmask[y * w + x]) {
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
if (bitmask[y * w + x])
|
||||
{
|
||||
sdf_pt_put(g1, x, y, sdf_pt_inside);
|
||||
sdf_pt_put(g2, x, y, sdf_pt_empty);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sdf_pt_put(g1, x, y, sdf_pt_empty);
|
||||
sdf_pt_put(g2, x, y, sdf_pt_inside);
|
||||
}
|
||||
|
|
@ -938,40 +899,47 @@ void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1,
|
|||
}
|
||||
|
||||
|
||||
void sdf_generate(sdf_grid * g) {
|
||||
void sdf_generate(sdf_grid * g)
|
||||
{
|
||||
int x, y;
|
||||
sdf_point p;
|
||||
|
||||
/* Pass 0 */
|
||||
for (y = 0; y < g->h; y++) {
|
||||
for (x = 0; x < g->w; x++) {
|
||||
for (y = 0; y < g->h; y++)
|
||||
{
|
||||
for (x = 0; x < g->w; x++)
|
||||
{
|
||||
sdf_pt_get(g, x, y, &p);
|
||||
sdf_compare(g, &p, x, y, -1, 0);
|
||||
sdf_compare(g, &p, x, y, 0, -1);
|
||||
sdf_compare(g, &p, x, y, -1, 0);
|
||||
sdf_compare(g, &p, x, y, 0, -1);
|
||||
sdf_compare(g, &p, x, y, -1, -1);
|
||||
sdf_compare(g, &p, x, y, 1, -1);
|
||||
sdf_compare(g, &p, x, y, 1, -1);
|
||||
sdf_pt_put(g, x, y, p);
|
||||
}
|
||||
|
||||
for (x = g->w - 1; x >= 0; x--) {
|
||||
for (x = g->w - 1; x >= 0; x--)
|
||||
{
|
||||
sdf_pt_get(g, x, y, &p);
|
||||
sdf_compare(g, &p, x, y, 1, 0);
|
||||
sdf_compare(g, &p, x, y, 1, 0);
|
||||
sdf_pt_put(g, x, y, p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Pass 1 */
|
||||
for (y = g->h - 1; y >= 0; y--) {
|
||||
for (x = g->w - 1; x >= 0; x--) {
|
||||
for (y = g->h - 1; y >= 0; y--)
|
||||
{
|
||||
for (x = g->w - 1; x >= 0; x--)
|
||||
{
|
||||
sdf_pt_get(g, x, y, &p);
|
||||
sdf_compare(g, &p, x, y, 1, 0);
|
||||
sdf_compare(g, &p, x, y, 0, 1);
|
||||
sdf_compare(g, &p, x, y, 1, 0);
|
||||
sdf_compare(g, &p, x, y, 0, 1);
|
||||
sdf_compare(g, &p, x, y, -1, 1);
|
||||
sdf_compare(g, &p, x, y, 1, 1);
|
||||
sdf_compare(g, &p, x, y, 1, 1);
|
||||
sdf_pt_put(g, x, y, p);
|
||||
}
|
||||
|
||||
for (x = 0; x < g->w; x++) {
|
||||
for (x = 0; x < g->w; x++)
|
||||
{
|
||||
sdf_pt_get(g, x, y, &p);
|
||||
sdf_compare(g, &p, x, y, -1, 0);
|
||||
sdf_pt_put(g, x, y, p);
|
||||
|
|
@ -989,21 +957,24 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
|
|||
int pix_idx;
|
||||
float ratio;
|
||||
Uint8 draw_r, draw_g, draw_b, old_r, old_g, old_b, new_r, new_g, new_b;
|
||||
Uint8 * bitmask;
|
||||
Uint8 *bitmask;
|
||||
sdf_grid g1, g2;
|
||||
|
||||
/* Create space for bitmask (based on `touched`) and SDF output
|
||||
large enough for the area being filled */
|
||||
bitmask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (bitmask == NULL) {
|
||||
if (bitmask == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!malloc_sdf_grid(&g1, canvas->w, canvas->h)) {
|
||||
if (!malloc_sdf_grid(&g1, canvas->w, canvas->h))
|
||||
{
|
||||
free(bitmask);
|
||||
return;
|
||||
}
|
||||
if (!malloc_sdf_grid(&g2, canvas->w, canvas->h)) {
|
||||
if (!malloc_sdf_grid(&g2, canvas->w, canvas->h))
|
||||
{
|
||||
free(bitmask);
|
||||
free_sdf_grid(&g1);
|
||||
return;
|
||||
|
|
@ -1011,8 +982,10 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
|
|||
|
||||
|
||||
/* Convert the `touched` values into a bitmask to feed into the SDF routines */
|
||||
for (yy = 0; yy < canvas->h; yy++) {
|
||||
for (xx = 0; xx < canvas->w; xx++) {
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
/* Converting 0-255 to 0/1 */
|
||||
bitmask[yy * canvas->w + xx] = (touched[(yy * canvas->w) + xx] >= 128);
|
||||
}
|
||||
|
|
@ -1036,49 +1009,42 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
|
|||
pix_idx = (yy * canvas->w) + xx;
|
||||
|
||||
if (pix_idx >= 0 && pix_idx < canvas->w * canvas->h)
|
||||
{
|
||||
if (touched[pix_idx])
|
||||
{
|
||||
if (touched[pix_idx])
|
||||
{
|
||||
sdf_point p;
|
||||
double dist1, dist2, dist;
|
||||
sdf_point p;
|
||||
double dist1, dist2, dist;
|
||||
|
||||
sdf_pt_get(&g1, xx, yy, &p);
|
||||
dist1 = sqrt(sdf_distsq(p));
|
||||
sdf_pt_get(&g1, xx, yy, &p);
|
||||
dist1 = sqrt(sdf_distsq(p));
|
||||
|
||||
sdf_pt_get(&g2, xx, yy, &p);
|
||||
dist2 = sqrt(sdf_distsq(p));
|
||||
sdf_pt_get(&g2, xx, yy, &p);
|
||||
dist2 = sqrt(sdf_distsq(p));
|
||||
|
||||
dist = dist1 - dist2;
|
||||
dist = dist1 - dist2;
|
||||
|
||||
/* Determine the distance from the click point */
|
||||
ratio = ((float) ((dist * 10) + 255)) / 255.0; // Magic numbers :-( -bjk 2023.02.25
|
||||
if (ratio < 0.0)
|
||||
ratio = 0.0;
|
||||
else if (ratio > 1.0)
|
||||
ratio = 1.0;
|
||||
/* Determine the distance from the click point */
|
||||
ratio = ((float)((dist * 10) + 255)) / 255.0; // Magic numbers :-( -bjk 2023.02.25
|
||||
if (ratio < 0.0)
|
||||
ratio = 0.0;
|
||||
else if (ratio > 1.0)
|
||||
ratio = 1.0;
|
||||
|
||||
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
|
||||
old_colr =
|
||||
getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
|
||||
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
|
||||
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
|
||||
old_colr = getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
|
||||
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
|
||||
|
||||
/* Apply fuzziness at any antialiased edges we detected */
|
||||
ratio = (ratio * ((float) touched[pix_idx] / 255.0));
|
||||
/* Apply fuzziness at any antialiased edges we detected */
|
||||
ratio = (ratio * ((float)touched[pix_idx] / 255.0));
|
||||
|
||||
new_r =
|
||||
(Uint8) (((float) old_r) * ratio +
|
||||
((float) draw_r * (1.00 - ratio)));
|
||||
new_g =
|
||||
(Uint8) (((float) old_g) * ratio +
|
||||
((float) draw_g * (1.00 - ratio)));
|
||||
new_b =
|
||||
(Uint8) (((float) old_b) * ratio +
|
||||
((float) draw_b * (1.00 - ratio)));
|
||||
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.00 - ratio)));
|
||||
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.00 - ratio)));
|
||||
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.00 - ratio)));
|
||||
|
||||
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
|
||||
}
|
||||
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
|
||||
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
15
src/fill.h
15
src/fill.h
|
|
@ -40,24 +40,19 @@ int would_flood_fill(SDL_Surface * canvas, Uint32 cur_colr, Uint32 old_colr);
|
|||
void do_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, SDL_Surface * last,
|
||||
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
|
||||
Uint8 * touched);
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched);
|
||||
void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, SDL_Surface * last,
|
||||
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
|
||||
Uint8 * touched);
|
||||
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched);
|
||||
void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x_left, int y_top, int x_right, int y_bottom,
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color,
|
||||
Uint8 * touched);
|
||||
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched);
|
||||
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
|
||||
int x_right, int y_bottom, int x, int y,
|
||||
Uint32 draw_color, Uint8 * touched);
|
||||
int x_right, int y_bottom, int x, int y, Uint32 draw_color, Uint8 * touched);
|
||||
void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touched);
|
||||
void draw_brush_fill(SDL_Surface * canvas, int x_left, int y_top, int x_right,
|
||||
int y_bottom, int x1, int y1, int x2, int y2,
|
||||
Uint32 draw_color, Uint8 * touched, int *up_x1,
|
||||
int *up_y1, int *up_x2, int *up_y2);
|
||||
Uint32 draw_color, Uint8 * touched, int *up_x1, int *up_y1, int *up_x2, int *up_y2);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -59,12 +59,9 @@ const char *const fill_names[NUM_FILLS] = {
|
|||
const char *const fill_tips[NUM_FILLS] = {
|
||||
gettext_noop("Click to fill an area with a solid color."),
|
||||
gettext_noop("Click and drag to fill an area by hand, using a brush."),
|
||||
gettext_noop
|
||||
("Click and drag to fill an area with a linear gradient (from the chosen color to transparent)."),
|
||||
gettext_noop
|
||||
("Click to fill an area with a radial gradient (from the chosen color to transparent)."),
|
||||
gettext_noop
|
||||
("Click to fill an area with a shaped gradient (from the chosen color to transparent).")
|
||||
gettext_noop("Click and drag to fill an area with a linear gradient (from the chosen color to transparent)."),
|
||||
gettext_noop("Click to fill an area with a radial gradient (from the chosen color to transparent)."),
|
||||
gettext_noop("Click to fill an area with a shaped gradient (from the chosen color to transparent).")
|
||||
};
|
||||
|
||||
const char *const fill_img_fnames[NUM_FILLS] = {
|
||||
|
|
|
|||
190
src/fonts.c
190
src/fonts.c
|
|
@ -142,6 +142,7 @@ int all_locale_fonts;
|
|||
volatile long font_thread_done;
|
||||
volatile long font_thread_aborted;
|
||||
volatile long waiting_for_fonts;
|
||||
|
||||
#ifdef FORKED_FONTS
|
||||
static int font_scanner_pid;
|
||||
#endif
|
||||
|
|
@ -180,8 +181,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
|
|||
{
|
||||
char str[128];
|
||||
|
||||
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX,
|
||||
lang_prefix);
|
||||
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
|
||||
|
||||
ret = TuxPaint_Font_OpenFont("", str, size);
|
||||
|
||||
|
|
@ -214,16 +214,14 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
|
|||
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 1 (%p)\n", __FILE__, __LINE__,
|
||||
tpf);
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 1 (%p)\n", __FILE__, __LINE__, tpf);
|
||||
#endif
|
||||
if (!tpf)
|
||||
return;
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 2 (%p, %d)\n", __FILE__,
|
||||
__LINE__, tpf->pango_context, tpf->typ);
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 2 (%p, %d)\n", __FILE__, __LINE__, tpf->pango_context, tpf->typ);
|
||||
#endif
|
||||
if (tpf->typ == FONT_TYPE_PANGO)
|
||||
if (tpf->pango_context)
|
||||
|
|
@ -236,8 +234,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 3 (%p, %d)\n", __FILE__,
|
||||
__LINE__, tpf->ttf_font, tpf->typ);
|
||||
printf("%s:%d - TuxPaint_Font_CloseFont step 3 (%p, %d)\n", __FILE__, __LINE__, tpf->ttf_font, tpf->typ);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
if (tpf->typ == FONT_TYPE_TTF)
|
||||
|
|
@ -256,8 +253,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
|||
free(tpf);
|
||||
}
|
||||
|
||||
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
||||
const char *ttffilename, int size)
|
||||
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size)
|
||||
{
|
||||
TTF_Font *ttf_font;
|
||||
TuxPaint_Font *tpf = NULL;
|
||||
|
|
@ -269,8 +265,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - OpenFont(pango:\"%s\", ttf:\"%s\")\n", __FILE__, __LINE__,
|
||||
pangodesc, ttffilename);
|
||||
printf("%s:%d - OpenFont(pango:\"%s\", ttf:\"%s\")\n", __FILE__, __LINE__, pangodesc, ttffilename);
|
||||
#endif
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
|
|
@ -282,16 +277,15 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
tpf->desc = strdup(desc);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Creating Pango context: \"%s\"\n", __FILE__, __LINE__,
|
||||
desc);
|
||||
printf("%s:%d - Creating Pango context: \"%s\"\n", __FILE__, __LINE__, desc);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
/*
|
||||
* SDLPango_CreateContext_GivenFontDesc() defaults to ASCII character set
|
||||
* (at least on the macOS) unless the CHARSET environment varaible is set.
|
||||
* May also want to set on non-macOS platforms, also.
|
||||
*/
|
||||
* SDLPango_CreateContext_GivenFontDesc() defaults to ASCII character set
|
||||
* (at least on the macOS) unless the CHARSET environment varaible is set.
|
||||
* May also want to set on non-macOS platforms, also.
|
||||
*/
|
||||
|
||||
mysetenv("CHARSET", "UTF-8");
|
||||
#endif
|
||||
|
|
@ -325,8 +319,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
if (ttffilename != NULL && ttffilename[0] != '\0')
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Considering loading TTF \"%s\"\n", __FILE__, __LINE__,
|
||||
ttffilename);
|
||||
printf("%s:%d - Considering loading TTF \"%s\"\n", __FILE__, __LINE__, ttffilename);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
|
|
@ -336,8 +329,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
if (!strcmp(ttffilename, problemFonts[i++]))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Notice: Skipping problematic font: \"%s\"\n",
|
||||
ttffilename);
|
||||
fprintf(stderr, "Notice: Skipping problematic font: \"%s\"\n", ttffilename);
|
||||
#endif
|
||||
return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */
|
||||
}
|
||||
|
|
@ -349,9 +341,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
if (strstr(ttffilename, problemFontExtensions[i++]))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"Notice: Skipping font with problematic extension: \"%s\"\n",
|
||||
ttffilename);
|
||||
fprintf(stderr, "Notice: Skipping font with problematic extension: \"%s\"\n", ttffilename);
|
||||
#endif
|
||||
return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */
|
||||
}
|
||||
|
|
@ -361,13 +351,12 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
|
||||
if (ttf_font == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename,
|
||||
size);
|
||||
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
familyname = TTF_FontFaceFamilyName(ttf_font); /* N.B.: I don't believe we're supposed to free() this... -bjk 2021.10.26 */
|
||||
(void) familyname; // avoid compiler complaints if NO_SDLPANGO is set, or ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set
|
||||
(void)familyname; // avoid compiler complaints if NO_SDLPANGO is set, or ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Loaded %s (\"%s\")\n", __FILE__, __LINE__, ttffilename,
|
||||
|
|
@ -406,8 +395,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
|
|||
tpf->desc = strdup(ttffilename);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Succeeded loading %s via SDL_ttf\n", __FILE__, __LINE__,
|
||||
ttffilename);
|
||||
printf("%s:%d - Succeeded loading %s via SDL_ttf\n", __FILE__, __LINE__, ttffilename);
|
||||
#endif
|
||||
tpf->height = TTF_FontHeight(tpf->ttf_font);
|
||||
|
||||
|
|
@ -614,9 +602,7 @@ static void groupfonts_range(style_info ** base, int count)
|
|||
if (num_font_families == num_font_families_max)
|
||||
{
|
||||
num_font_families_max = num_font_families_max * 5 / 4 + 30;
|
||||
user_font_families =
|
||||
realloc(user_font_families,
|
||||
num_font_families_max * sizeof *user_font_families);
|
||||
user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families);
|
||||
}
|
||||
|
||||
fi = calloc(1, sizeof *fi);
|
||||
|
|
@ -633,8 +619,7 @@ static void groupfonts_range(style_info ** base, int count)
|
|||
{
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
printf("too many boldness levels, discarding: %s, %s\n",
|
||||
base[i]->family, base[i]->style);
|
||||
printf("too many boldness levels, discarding: %s, %s\n", base[i]->family, base[i]->style);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
|
@ -644,11 +629,9 @@ static void groupfonts_range(style_info ** base, int count)
|
|||
{
|
||||
#if 0
|
||||
// THREADED_FONTS
|
||||
printf("duplicates, discarding: %s, %s\n", base[i]->family,
|
||||
base[i]->style);
|
||||
printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style);
|
||||
printf("b %d, spot %d\n", b, spot);
|
||||
printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1],
|
||||
fi->filename[2], fi->filename[3]);
|
||||
printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], fi->filename[2], fi->filename[3]);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
|
@ -872,8 +855,7 @@ static void parse_font_style(style_info * si)
|
|||
si->boldness = 1;
|
||||
|
||||
// we'll count both TrueType and OpenType
|
||||
si->truetype = !!strcasestr(si->filename, ".ttf")
|
||||
|| !!strcasestr(si->filename, ".otf");
|
||||
si->truetype = !!strcasestr(si->filename, ".ttf") || !!strcasestr(si->filename, ".otf");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -911,8 +893,7 @@ static void groupfonts(void)
|
|||
while (i--)
|
||||
parse_font_style(user_font_styles[i]);
|
||||
|
||||
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0],
|
||||
compar_fontgroup);
|
||||
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0], compar_fontgroup);
|
||||
//printf("groupfonts() qsort(user_font_styles...)\n");
|
||||
//fflush(stdout);
|
||||
|
||||
|
|
@ -945,8 +926,7 @@ static void groupfonts(void)
|
|||
free(user_font_styles);
|
||||
user_font_styles = NULL; // just to catch bugs
|
||||
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
|
||||
compar_fontkiller);
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller);
|
||||
low = 0;
|
||||
for (;;)
|
||||
{
|
||||
|
|
@ -958,15 +938,13 @@ static void groupfonts(void)
|
|||
{
|
||||
if (++high >= num_font_families)
|
||||
break;
|
||||
if (strcmp
|
||||
(user_font_families[low]->family, user_font_families[high]->family))
|
||||
if (strcmp(user_font_families[low]->family, user_font_families[high]->family))
|
||||
break;
|
||||
}
|
||||
dupe_markdown_range(user_font_families + low, high - low);
|
||||
low = high;
|
||||
}
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
|
||||
compar_fontscore);
|
||||
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontscore);
|
||||
//printf("groupfonts() qsort(user_font_families 2...)\n");
|
||||
//fflush(stdout);
|
||||
if (num_font_families > 0 && user_font_families[0]->score < 0)
|
||||
|
|
@ -975,8 +953,7 @@ static void groupfonts(void)
|
|||
// THREADED_FONTS
|
||||
printf("Trim starting with %d families\n", num_font_families);
|
||||
#endif
|
||||
while (num_font_families > 1
|
||||
&& user_font_families[num_font_families - 1]->score < 0)
|
||||
while (num_font_families > 1 && user_font_families[num_font_families - 1]->score < 0)
|
||||
{
|
||||
i = --num_font_families;
|
||||
free(user_font_families[i]->directory);
|
||||
|
|
@ -1002,9 +979,7 @@ static void groupfonts(void)
|
|||
|
||||
static void loadfonts_locale_filter(SDL_Surface * screen,
|
||||
SDL_Texture * texture,
|
||||
SDL_Renderer * renderer,
|
||||
const char *const dir,
|
||||
const char *restrict const locale)
|
||||
SDL_Renderer * renderer, const char *const dir, const char *restrict const locale)
|
||||
{
|
||||
char buf[TP_FTW_PATHSIZE];
|
||||
unsigned dirlen = strlen(dir);
|
||||
|
|
@ -1012,27 +987,23 @@ static void loadfonts_locale_filter(SDL_Surface * screen,
|
|||
DEBUG_PRINTF("Loading fonts from [%s]\n", dir);
|
||||
|
||||
memcpy(buf, dir, dirlen);
|
||||
tp_ftw(screen, texture, renderer, buf, dirlen, 1, loadfont_callback,
|
||||
locale);
|
||||
tp_ftw(screen, texture, renderer, buf, dirlen, 1, loadfont_callback, locale);
|
||||
}
|
||||
|
||||
static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, const char *const dir)
|
||||
static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *const dir)
|
||||
{
|
||||
loadfonts_locale_filter(screen, texture, renderer, dir, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer, void *vp,
|
||||
const char *restrict const locale)
|
||||
SDL_Renderer * renderer, void *vp, const char *restrict const locale)
|
||||
{
|
||||
char *homedirdir;
|
||||
|
||||
(void) vp; // junk passed by threading library
|
||||
(void)vp; // junk passed by threading library
|
||||
|
||||
loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts",
|
||||
locale);
|
||||
loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts", locale);
|
||||
|
||||
if (!no_system_fonts)
|
||||
{
|
||||
|
|
@ -1049,21 +1020,13 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
|
|||
char buffer[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
|
||||
status_t result;
|
||||
|
||||
result =
|
||||
find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer,
|
||||
sizeof(buffer));
|
||||
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
|
||||
loadfonts(screen, texture, renderer, buffer);
|
||||
result =
|
||||
find_directory(B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY, volume, false,
|
||||
buffer, sizeof(buffer));
|
||||
result = find_directory(B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
|
||||
loadfonts(screen, texture, renderer, buffer);
|
||||
result =
|
||||
find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer,
|
||||
sizeof(buffer));
|
||||
result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
|
||||
loadfonts(screen, texture, renderer, buffer);
|
||||
result =
|
||||
find_directory(B_USER_NONPACKAGED_FONTS_DIRECTORY, volume, false,
|
||||
buffer, sizeof(buffer));
|
||||
result = find_directory(B_USER_NONPACKAGED_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
|
||||
loadfonts(screen, texture, renderer, buffer);
|
||||
#elif defined(__APPLE__)
|
||||
loadfonts(screen, texture, renderer, "/System/Library/Fonts");
|
||||
|
|
@ -1102,8 +1065,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
|
|||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
homedirdir =
|
||||
malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
|
||||
homedirdir = malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
|
||||
if (homedirdir)
|
||||
{
|
||||
sprintf(homedirdir, "%s/fonts", apple_globalPreferencesPath());
|
||||
|
|
@ -1113,8 +1075,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Grouping %d fonts...\n", __FILE__, __LINE__,
|
||||
num_font_styles);
|
||||
printf("%s:%d - Grouping %d fonts...\n", __FILE__, __LINE__, num_font_styles);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
|
|
@ -1135,8 +1096,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
|
|||
#ifdef FORKED_FONTS
|
||||
|
||||
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer,
|
||||
const char *restrict const locale)
|
||||
SDL_Renderer * renderer, const char *restrict const locale)
|
||||
{
|
||||
int sv[2];
|
||||
int size, i;
|
||||
|
|
@ -1202,8 +1162,7 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
|
|||
buf = malloc(size);
|
||||
walk = buf;
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Sending %u bytes with %u families.\n", __FILE__, __LINE__,
|
||||
size, num_font_families);
|
||||
printf("%s:%d - Sending %u bytes with %u families.\n", __FILE__, __LINE__, size, num_font_families);
|
||||
#endif
|
||||
*walk++ = num_font_families & 0xffu;
|
||||
*walk++ = num_font_families >> 8u;
|
||||
|
|
@ -1272,8 +1231,7 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
|
|||
}
|
||||
|
||||
|
||||
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer)
|
||||
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
|
||||
{
|
||||
char *buf = NULL;
|
||||
unsigned buf_size = 0;
|
||||
|
|
@ -1298,7 +1256,7 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
|
|||
rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill);
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", __FILE__,
|
||||
__LINE__, font_socket_fd, buf_fill, buf_size, (long int) rc);
|
||||
__LINE__, font_socket_fd, buf_fill, buf_size, (long int)rc);
|
||||
#endif
|
||||
|
||||
if (rc == -1)
|
||||
|
|
@ -1339,11 +1297,10 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
|
|||
|
||||
show_progress_bar_(screen, texture, renderer);
|
||||
walk = buf;
|
||||
num_font_families = *(unsigned char *) walk++;
|
||||
num_font_families += *(unsigned char *) walk++ << 8u;
|
||||
num_font_families = *(unsigned char *)walk++;
|
||||
num_font_families += *(unsigned char *)walk++ << 8u;
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Got %u bytes with %u families.\n", __FILE__, __LINE__,
|
||||
buf_fill, num_font_families);
|
||||
printf("%s:%d - Got %u bytes with %u families.\n", __FILE__, __LINE__, buf_fill, num_font_families);
|
||||
#endif
|
||||
user_font_families = malloc(num_font_families * sizeof *user_font_families);
|
||||
|
||||
|
|
@ -1409,8 +1366,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
if (fi == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - getfonthandle(%d) points to a NULL family\n", __FILE__,
|
||||
__LINE__, desire);
|
||||
printf("%s:%d - getfonthandle(%d) points to a NULL family\n", __FILE__, __LINE__, desire);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return NULL;
|
||||
|
|
@ -1419,8 +1375,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
if (fi->filename != NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - Setting 'name' to fi->filename[%d (0x%x)]\n", __FILE__,
|
||||
__LINE__, (int) text_state, (int) text_state);
|
||||
printf("%s:%d - Setting 'name' to fi->filename[%d (0x%x)]\n", __FILE__, __LINE__, (int)text_state, (int)text_state);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
|
|
@ -1444,8 +1399,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
if (fi->handle)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - fi->handle was set (0x%x)\n", __FILE__, __LINE__,
|
||||
(int) (intptr_t) fi->handle);
|
||||
printf("%s:%d - fi->handle was set (0x%x)\n", __FILE__, __LINE__, (int)(intptr_t) fi->handle);
|
||||
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
|
@ -1511,8 +1465,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
strcpy(description, "");
|
||||
}
|
||||
|
||||
fi->handle =
|
||||
TuxPaint_Font_OpenFont(description, pathname, text_sizes[text_size]);
|
||||
fi->handle = TuxPaint_Font_OpenFont(description, pathname, text_sizes[text_size]);
|
||||
// if the font doesn't load, we die -- it did load OK before though
|
||||
|
||||
if (fi->handle == NULL)
|
||||
|
|
@ -1536,8 +1489,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - calling TTF_SetFontStyle(0x%x)\n", __FILE__, __LINE__,
|
||||
missing);
|
||||
printf("%s:%d - calling TTF_SetFontStyle(0x%x)\n", __FILE__, __LINE__, missing);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
|
|
@ -1557,8 +1509,7 @@ TuxPaint_Font *getfonthandle(int desire)
|
|||
static int was_bad_font;
|
||||
|
||||
// see if two font surfaces are the same
|
||||
static int do_surfcmp(const SDL_Surface * const *const v1,
|
||||
const SDL_Surface * const *const v2)
|
||||
static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * const *const v2)
|
||||
{
|
||||
const SDL_Surface *const s1 = *v1;
|
||||
const SDL_Surface *const s2 = *v2;
|
||||
|
|
@ -1572,8 +1523,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1,
|
|||
fprintf(stderr, "s1==s2?\n");
|
||||
return 0;
|
||||
}
|
||||
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format
|
||||
|| !s2->format)
|
||||
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format || !s2->format)
|
||||
{
|
||||
/* One or the other or both SDL_Surfaces were invalid!? */
|
||||
was_bad_font = 1;
|
||||
|
|
@ -1596,11 +1546,12 @@ static int do_surfcmp(const SDL_Surface * const *const v1,
|
|||
/* Otherwise, compare the pixels in the surfaces
|
||||
(using `memcmp()`) */
|
||||
{
|
||||
const char *const c1 = (char *const) s1->pixels;
|
||||
const char *const c2 = (char *const) s2->pixels;
|
||||
const char *const c1 = (char *const)s1->pixels;
|
||||
const char *const c2 = (char *const)s2->pixels;
|
||||
|
||||
width = s1->format->BytesPerPixel * s1->w;
|
||||
if (width == s1->pitch) {
|
||||
if (width == s1->pitch)
|
||||
{
|
||||
/* Same width, just compare scanline */
|
||||
return memcmp(c1, c2, width * s1->h);
|
||||
}
|
||||
|
|
@ -1625,7 +1576,8 @@ static int surfcmp(const void *s1, const void *s2)
|
|||
{
|
||||
int diff = do_surfcmp(s1, s2);
|
||||
|
||||
if (!diff) {
|
||||
if (!diff)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("surfcmp found two identical renders!\n");
|
||||
#endif
|
||||
|
|
@ -1708,8 +1660,7 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf)
|
|||
if (tpf == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_FontHeight() received NULL\n", __FILE__,
|
||||
__LINE__);
|
||||
printf("%s:%d - TuxPaint_Font_FontHeight() received NULL\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return (1);
|
||||
|
|
@ -1723,8 +1674,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
|
|||
if (tpf == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() received NULL\n",
|
||||
__FILE__, __LINE__);
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() received NULL\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return ("");
|
||||
|
|
@ -1733,7 +1683,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
|
|||
#ifndef NO_SDLPANGO
|
||||
if (tpf->typ == FONT_TYPE_PANGO)
|
||||
{
|
||||
(void) (tpf);
|
||||
(void)(tpf);
|
||||
/* FIXME */
|
||||
|
||||
return ("");
|
||||
|
|
@ -1744,8 +1694,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
|
|||
return (TTF_FontFaceFamilyName(tpf->ttf_font));
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() is confused\n", __FILE__,
|
||||
__LINE__);
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() is confused\n", __FILE__, __LINE__);
|
||||
#endif
|
||||
|
||||
return ("");
|
||||
|
|
@ -1756,8 +1705,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
|
|||
if (tpf == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() received NULL\n",
|
||||
__FILE__, __LINE__);
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() received NULL\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return ("");
|
||||
|
|
@ -1766,7 +1714,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
|
|||
#ifndef NO_SDLPANGO
|
||||
if (tpf->typ == FONT_TYPE_PANGO)
|
||||
{
|
||||
(void) (tpf);
|
||||
(void)(tpf);
|
||||
/* FIXME */
|
||||
|
||||
return ("");
|
||||
|
|
@ -1777,8 +1725,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
|
|||
return (TTF_FontFaceStyleName(tpf->ttf_font));
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() is confused\n", __FILE__,
|
||||
__LINE__);
|
||||
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() is confused\n", __FILE__, __LINE__);
|
||||
#endif
|
||||
|
||||
return ("");
|
||||
|
|
@ -1787,8 +1734,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
|
|||
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
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)
|
||||
{
|
||||
Uint8 pc[4][4];
|
||||
|
||||
|
|
|
|||
15
src/fonts.h
15
src/fonts.h
|
|
@ -121,10 +121,8 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
|
|||
#ifdef FORKED_FONTS
|
||||
void reliable_write(int fd, const void *buf, size_t count);
|
||||
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer,
|
||||
const char *restrict const locale);
|
||||
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
|
||||
SDL_Renderer * renderer);
|
||||
SDL_Renderer * renderer, const char *restrict const locale);
|
||||
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -192,8 +190,7 @@ 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);
|
||||
|
|
@ -201,12 +198,10 @@ 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);
|
||||
SDL_Renderer * renderer, void *vp, const char *restrict const locale);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ const char *exportdir;
|
|||
char *get_fname(const char *const name, int kind)
|
||||
{
|
||||
char f[512];
|
||||
|
||||
// const char *restrict const dir;
|
||||
const char *dir;
|
||||
|
||||
|
|
|
|||
14
src/gifenc.c
14
src/gifenc.c
|
|
@ -44,6 +44,7 @@ typedef struct Node Node;
|
|||
static Node *new_node(uint16_t key, int degree)
|
||||
{
|
||||
Node *node = calloc(1, sizeof(*node) + degree * sizeof(Node *));
|
||||
|
||||
if (node)
|
||||
node->key = key;
|
||||
return node;
|
||||
|
|
@ -52,6 +53,7 @@ static Node *new_node(uint16_t key, int degree)
|
|||
static Node *new_trie(int degree, int *nkeys)
|
||||
{
|
||||
Node *root = new_node(0, degree);
|
||||
|
||||
/* Create nodes for single pixels. */
|
||||
for (*nkeys = 0; *nkeys < degree; (*nkeys)++)
|
||||
root->children[*nkeys] = new_node(*nkeys, degree);
|
||||
|
|
@ -75,12 +77,12 @@ static void put_loop(ge_GIF * gif, uint16_t loop);
|
|||
#define OR_ABORT if (res == -1) { fprintf(stderr, "Cannot write to GIF\n"); return(NULL); }
|
||||
#define OR_ABORT2 if (res == -1) { fprintf(stderr, "Cannot write to GIF\n"); return; }
|
||||
|
||||
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height,
|
||||
uint8_t * palette, int depth, int loop)
|
||||
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, uint8_t * palette, int depth, int loop)
|
||||
{
|
||||
int i, r, g, b, v;
|
||||
ssize_t res;
|
||||
ge_GIF *gif = calloc(1, sizeof(*gif) + 2 * width * height);
|
||||
|
||||
if (!gif)
|
||||
goto no_gif;
|
||||
gif->w = width;
|
||||
|
|
@ -225,8 +227,7 @@ static void end_key(ge_GIF * gif)
|
|||
gif->offset = gif->partial = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
|
||||
static void put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
|
||||
{
|
||||
int nkeys, key_size, i, j;
|
||||
Node *node, *child, *root;
|
||||
|
|
@ -255,6 +256,7 @@ put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
|
|||
for (j = x; j < x + w; j++)
|
||||
{
|
||||
uint8_t pixel = gif->frame[i * gif->w + j] & (degree - 1);
|
||||
|
||||
child = node->children[pixel];
|
||||
if (child)
|
||||
{
|
||||
|
|
@ -286,11 +288,11 @@ put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
|
|||
del_trie(root, degree);
|
||||
}
|
||||
|
||||
static int
|
||||
get_bbox(ge_GIF * gif, uint16_t * w, uint16_t * h, uint16_t * x, uint16_t * y)
|
||||
static int get_bbox(ge_GIF * gif, uint16_t * w, uint16_t * h, uint16_t * x, uint16_t * y)
|
||||
{
|
||||
int i, j, k;
|
||||
int left, right, top, bottom;
|
||||
|
||||
left = gif->w;
|
||||
right = 0;
|
||||
top = gif->h;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ typedef struct ge_GIF
|
|||
uint8_t buffer[0xFF];
|
||||
} ge_GIF;
|
||||
|
||||
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height,
|
||||
uint8_t * palette, int depth, int loop);
|
||||
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, uint8_t * palette, int depth, int loop);
|
||||
void ge_add_frame(ge_GIF * gif, uint16_t delay);
|
||||
void ge_close_gif(ge_GIF * gif);
|
||||
|
||||
|
|
|
|||
75
src/i18n.c
75
src/i18n.c
|
|
@ -64,16 +64,12 @@ 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);
|
||||
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);
|
||||
|
|
@ -494,9 +490,7 @@ static void show_lang_usage(int exitcode)
|
|||
const char *const prg = "tuxpaint";
|
||||
|
||||
/* FIXME: All this should REALLY be array-based!!! */
|
||||
fprintf(f,
|
||||
"\n" "Usage: %s [--lang LANGUAGE]\n" "\n"
|
||||
"LANGUAGE may be one of:\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"
|
||||
|
|
@ -774,8 +768,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -819,13 +812,12 @@ 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" };
|
||||
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 :-/
|
||||
if (iswprint((wchar_t)0xf7)) // division symbol -- which is in Latin-1 :-/
|
||||
return;
|
||||
if (--i < 0)
|
||||
break;
|
||||
|
|
@ -844,8 +836,7 @@ 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];
|
||||
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
|
||||
|
||||
while (i--)
|
||||
{
|
||||
|
|
@ -871,8 +862,7 @@ static const char *language_to_locale(const char *langstr)
|
|||
*/
|
||||
static const char *locale_to_closest_locale(const char *inlocale)
|
||||
{
|
||||
const int numlocale =
|
||||
sizeof(language_to_locale_array) / sizeof(language_to_locale_array[0]);
|
||||
const int numlocale = sizeof(language_to_locale_array) / sizeof(language_to_locale_array[0]);
|
||||
const char *outlocale = NULL;
|
||||
int outlocale_score = 0;
|
||||
int i = 0;
|
||||
|
|
@ -883,8 +873,7 @@ static const char *locale_to_closest_locale(const char *inlocale)
|
|||
{
|
||||
const char *candidate = language_to_locale_array[i].locale;
|
||||
|
||||
for (j = 0; j < (int) strlen(inlocale) && j < (int) strlen(candidate);
|
||||
j++)
|
||||
for (j = 0; j < (int)strlen(inlocale) && j < (int)strlen(candidate); j++)
|
||||
{
|
||||
if (inlocale[j] != candidate[j])
|
||||
break;
|
||||
|
|
@ -964,8 +953,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
|
|||
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))
|
||||
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
|
||||
{
|
||||
langint = i;
|
||||
found = 1;
|
||||
|
|
@ -980,8 +968,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
|
|||
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))
|
||||
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
|
||||
{
|
||||
langint = i;
|
||||
found = 1;
|
||||
|
|
@ -1001,8 +988,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
|
|||
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])))
|
||||
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], strlen(lang_prefixes[i])))
|
||||
{
|
||||
langint = i;
|
||||
found = 1;
|
||||
|
|
@ -1018,8 +1004,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
|
|||
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])))
|
||||
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
|
||||
{
|
||||
langint = i;
|
||||
found = 1;
|
||||
|
|
@ -1099,8 +1084,7 @@ void mysetenv(const char *name, const char *value)
|
|||
* @return The Y-nudge value for font rendering in the language.
|
||||
*/
|
||||
|
||||
static int set_current_language(const char *restrict loc,
|
||||
int *ptr_num_wished_langs)
|
||||
static int set_current_language(const char *restrict loc, int *ptr_num_wished_langs)
|
||||
{
|
||||
int i;
|
||||
int j = 0;
|
||||
|
|
@ -1137,8 +1121,7 @@ static int set_current_language(const char *restrict loc,
|
|||
env = getenv("LC_MESSAGES");
|
||||
if (env != NULL && env[0] != '\0')
|
||||
{
|
||||
DEBUG_PRINTF("Language via LC_MESSAGES: %s\n",
|
||||
getenv("LC_MESSAGES"));
|
||||
DEBUG_PRINTF("Language via LC_MESSAGES: %s\n", getenv("LC_MESSAGES"));
|
||||
mysetenv("LANGUAGE", getenv("LC_MESSAGES"));
|
||||
}
|
||||
else
|
||||
|
|
@ -1182,6 +1165,7 @@ static int set_current_language(const char *restrict loc,
|
|||
// -- 2022/02/02: Shin-ichi TOYAMA & Pere Pujal i Carabantes
|
||||
char curdir[256];
|
||||
char f[512];
|
||||
|
||||
getcwd(curdir, sizeof(curdir));
|
||||
snprintf(f, sizeof(f), "%s%s", curdir, "\\locale");
|
||||
#ifdef DEBUG
|
||||
|
|
@ -1255,12 +1239,9 @@ static int set_current_language(const char *restrict loc,
|
|||
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);
|
||||
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]);
|
||||
|
|
@ -1294,15 +1275,13 @@ static int set_current_language(const char *restrict loc,
|
|||
|
||||
#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
|
||||
|
||||
free(oldloc);
|
||||
|
||||
DEBUG_PRINTF("lang_prefixes[%d] is \"%s\"\n", get_current_language(),
|
||||
lang_prefixes[get_current_language()]);
|
||||
DEBUG_PRINTF("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
|
||||
|
||||
*ptr_num_wished_langs = num_wished_langs;
|
||||
|
||||
|
|
@ -1321,8 +1300,7 @@ static int set_current_language(const char *restrict loc,
|
|||
* @param int * a place to return the number of languages we want to use, when scanning stamp descriptions
|
||||
* @return Y-nudge
|
||||
*/
|
||||
int setup_i18n(const char *restrict lang, const char *restrict locale,
|
||||
int *num_wished_langs)
|
||||
int setup_i18n(const char *restrict lang, const char *restrict locale, int *num_wished_langs)
|
||||
{
|
||||
DEBUG_PRINTF("lang %p, locale %p\n", lang, locale);
|
||||
DEBUG_PRINTF("lang \"%s\", locale \"%s\"\n", lang, locale);
|
||||
|
|
@ -1364,6 +1342,7 @@ int setup_i18n(const char *restrict lang, const char *restrict locale,
|
|||
int smash_i18n(void)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
return set_current_language("C", &tmp);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -206,9 +206,8 @@ extern w_langs wished_langs[255];
|
|||
/* Function prototypes: */
|
||||
|
||||
int get_current_language(void);
|
||||
int setup_i18n(const char *restrict lang, const char *restrict locale,
|
||||
int *ptr_num_wished_languages) MUST_CHECK;
|
||||
void mysetenv(const char *name, const char *value);
|
||||
int setup_i18n(const char *restrict lang, const char *restrict locale, int *ptr_num_wished_languages) MUST_CHECK;
|
||||
void mysetenv(const char *name, const char *value);
|
||||
|
||||
#ifdef NO_SDLPANGO
|
||||
int smash_i18n(void) MUST_CHECK;
|
||||
|
|
|
|||
97
src/im.c
97
src/im.c
|
|
@ -258,7 +258,7 @@ static void wcs_lshift(wchar_t *s, size_t count)
|
|||
*/
|
||||
static void wcs_pull(wchar_t *s, size_t count)
|
||||
{
|
||||
int peg = (int) wcslen(s) - (int) count;
|
||||
int peg = (int)wcslen(s) - (int)count;
|
||||
|
||||
if (peg < 0)
|
||||
peg = 0;
|
||||
|
|
@ -311,7 +311,7 @@ static void sm_free(STATE_MACHINE * sm)
|
|||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < (int) sm->next_maxsize; i++)
|
||||
for (i = 0; i < (int)sm->next_maxsize; i++)
|
||||
{
|
||||
STATE_MACHINE *next_state = sm->next[i].state;
|
||||
|
||||
|
|
@ -358,8 +358,7 @@ static STATE_MACHINE *sm_search_shallow(STATE_MACHINE * sm, char key)
|
|||
SM_WITH_KEY smk = { key, NULL };
|
||||
SM_WITH_KEY *smk_found;
|
||||
|
||||
smk_found =
|
||||
bsearch(&smk, sm->next, sm->next_size, sizeof(SM_WITH_KEY), swk_compare);
|
||||
smk_found = bsearch(&smk, sm->next, sm->next_size, sizeof(SM_WITH_KEY), swk_compare);
|
||||
|
||||
if (!smk_found)
|
||||
return NULL;
|
||||
|
|
@ -381,10 +380,9 @@ static STATE_MACHINE *sm_search_shallow(STATE_MACHINE * sm, char key)
|
|||
* @return Found unicode character sequence output of the last state.
|
||||
*/
|
||||
static const wchar_t *sm_search(STATE_MACHINE * start, wchar_t *key,
|
||||
int *matched, STATE_MACHINE ** penult,
|
||||
STATE_MACHINE ** end)
|
||||
int *matched, STATE_MACHINE ** penult, STATE_MACHINE ** end)
|
||||
{
|
||||
STATE_MACHINE *sm = sm_search_shallow(start, (char) *key);
|
||||
STATE_MACHINE *sm = sm_search_shallow(start, (char)*key);
|
||||
const wchar_t *unicode;
|
||||
|
||||
/* No match - stop recursion */
|
||||
|
|
@ -418,8 +416,7 @@ static void sm_sort_shallow(STATE_MACHINE * sm)
|
|||
/**
|
||||
* Add a single sequence-to-unicode path to the state machine.
|
||||
*/
|
||||
static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
|
||||
char flag)
|
||||
static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode, char flag)
|
||||
{
|
||||
STATE_MACHINE *sm_found = sm_search_shallow(sm, seq[0]);
|
||||
|
||||
|
|
@ -432,10 +429,10 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
|
|||
|
||||
fprintf(stderr, "Unicode sequence ");
|
||||
for (i = 0; i < wcslen(sm->output); i++)
|
||||
fprintf(stderr, "%04X ", (int) sm->output[i]);
|
||||
fprintf(stderr, "%04X ", (int)sm->output[i]);
|
||||
fprintf(stderr, " already defined, overriding with ");
|
||||
for (i = 0; i < wcslen(unicode); i++)
|
||||
fprintf(stderr, "%04X ", (int) unicode[i]);
|
||||
fprintf(stderr, "%04X ", (int)unicode[i]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
wcscpy(sm->output, unicode);
|
||||
|
|
@ -446,7 +443,7 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
|
|||
/* The key doesn't exist yet */
|
||||
if (!sm_found)
|
||||
{
|
||||
int index = (int) sm->next_size;
|
||||
int index = (int)sm->next_size;
|
||||
SM_WITH_KEY *next = &sm->next[index];
|
||||
|
||||
/* Add the key */
|
||||
|
|
@ -516,8 +513,7 @@ static int charmap_init(CHARMAP * cm)
|
|||
*
|
||||
* @return 0 if no error, 1 if error.
|
||||
*/
|
||||
static int charmap_add(CHARMAP * cm, int section, char *seq,
|
||||
const wchar_t *unicode, char *flag)
|
||||
static int charmap_add(CHARMAP * cm, int section, char *seq, const wchar_t *unicode, char *flag)
|
||||
{
|
||||
if (section >= MAX_SECTIONS)
|
||||
{
|
||||
|
|
@ -528,7 +524,7 @@ static int charmap_add(CHARMAP * cm, int section, char *seq,
|
|||
/* For now, we only utilize one-character flags */
|
||||
if (strlen(flag) > 1)
|
||||
{
|
||||
fprintf(stderr, "%04X: Multi-character flag, truncated.\n", (int) (intptr_t) unicode); //EP added (intptr_t) to avoid warning on x64
|
||||
fprintf(stderr, "%04X: Multi-character flag, truncated.\n", (int)(intptr_t) unicode); //EP added (intptr_t) to avoid warning on x64
|
||||
}
|
||||
|
||||
return sm_add(&cm->sections[section], seq, unicode, flag[0]);
|
||||
|
|
@ -635,7 +631,7 @@ static int charmap_load(CHARMAP * cm, const char *path)
|
|||
|
||||
fwprintf(stderr, L"Unable to add sequence '%ls', unicode ", buf);
|
||||
for (i = 0; i < wcslen(unicode); i++)
|
||||
fwprintf(stderr, L"%04X ", (int) unicode[i]);
|
||||
fwprintf(stderr, L"%04X ", (int)unicode[i]);
|
||||
fwprintf(stderr, L"in section %d\n", section);
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -679,15 +675,13 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
|
|||
|
||||
/* Determine the starting state based on the charmap's active section */
|
||||
section = cm->section;
|
||||
if (!IN_RANGE(0, section, (int) ARRAYLEN(cm->sections)))
|
||||
if (!IN_RANGE(0, section, (int)ARRAYLEN(cm->sections)))
|
||||
section = 0;
|
||||
start = &cm->sections[section];
|
||||
|
||||
cm->match_state = NULL;
|
||||
cm->match_state_prev = NULL;
|
||||
unicode =
|
||||
sm_search(start, s, &cm->match_count, &cm->match_state_prev,
|
||||
&cm->match_state);
|
||||
unicode = sm_search(start, s, &cm->match_count, &cm->match_state_prev, &cm->match_state);
|
||||
|
||||
/**
|
||||
* Determine whether the match is final. A match is considered to be final
|
||||
|
|
@ -701,7 +695,7 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
|
|||
* final state we possibly can.
|
||||
*/
|
||||
cm->match_is_final = 0;
|
||||
if (cm->match_count < (int) wcslen(s))
|
||||
if (cm->match_count < (int)wcslen(s))
|
||||
{
|
||||
cm->match_is_final = 1;
|
||||
}
|
||||
|
|
@ -713,7 +707,7 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
|
|||
cm->match_is_final = 1;
|
||||
cm->match_stats |= MATCH_STAT_NOMOSTATES;
|
||||
}
|
||||
if (cm->match_count == (int) wcslen(s))
|
||||
if (cm->match_count == (int)wcslen(s))
|
||||
{
|
||||
cm->match_stats |= MATCH_STAT_NOMOBUF;
|
||||
}
|
||||
|
|
@ -830,8 +824,7 @@ int im_read(IM_DATA * im, SDL_Event event)
|
|||
redraw = im_event_c(im, event);
|
||||
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s),
|
||||
wcslen(im->buf), im->redraw);
|
||||
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf), im->redraw);
|
||||
#endif
|
||||
|
||||
return redraw;
|
||||
|
|
@ -983,8 +976,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
|
|||
|
||||
if (charmap_load(&cm, lang_file))
|
||||
{
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
|
||||
lang_file);
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
|
||||
im->lang = LANG_DEFAULT;
|
||||
return im_event_c(im, event);
|
||||
}
|
||||
|
|
@ -1001,7 +993,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
|
|||
|
||||
|
||||
/* Discard redraw characters, so they can be redrawn */
|
||||
if ((int) wcslen(im->s) < im->redraw)
|
||||
if ((int)wcslen(im->s) < im->redraw)
|
||||
im->redraw = wcslen(im->s);
|
||||
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
|
||||
|
||||
|
|
@ -1055,8 +1047,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
|
|||
|
||||
/* Actual character processing */
|
||||
default:
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|
||||
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
{
|
||||
/* English mode */
|
||||
if (cm.section == SEC_ENGLISH)
|
||||
|
|
@ -1081,8 +1072,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
|
|||
const wchar_t *us = charmap_search(&cm, im->buf);
|
||||
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
|
||||
wcslen(im->buf));
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
|
||||
#endif
|
||||
|
||||
/* Match was found? */
|
||||
|
|
@ -1122,7 +1112,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
|
|||
cm.match_is_final = 0;
|
||||
}
|
||||
/* If the matched characters didn't consume all, it's own state */
|
||||
else if ((size_t) cm.match_count != wcslen(im->buf))
|
||||
else if ((size_t)cm.match_count != wcslen(im->buf))
|
||||
{
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" 2b (%2d)\n", cm.match_count);
|
||||
|
|
@ -1209,8 +1199,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
|
|||
|
||||
if (charmap_load(&cm, lang_file))
|
||||
{
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
|
||||
lang_file);
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
|
||||
im->lang = LANG_DEFAULT;
|
||||
return im_event_c(im, event);
|
||||
}
|
||||
|
|
@ -1227,7 +1216,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
|
|||
|
||||
|
||||
/* Discard redraw characters, so they can be redrawn */
|
||||
if ((int) wcslen(im->s) < im->redraw)
|
||||
if ((int)wcslen(im->s) < im->redraw)
|
||||
im->redraw = wcslen(im->s);
|
||||
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
|
||||
|
||||
|
|
@ -1304,8 +1293,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
|
|||
const wchar_t *us = charmap_search(&cm, im->buf);
|
||||
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
|
||||
wcslen(im->buf));
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
|
||||
#endif
|
||||
|
||||
/* Match was found? */
|
||||
|
|
@ -1345,7 +1333,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
|
|||
cm.match_is_final = 0;
|
||||
}
|
||||
/* If the matched characters didn't consume all, it's own state */
|
||||
else if ((size_t) cm.match_count != wcslen(im->buf))
|
||||
else if ((size_t)cm.match_count != wcslen(im->buf))
|
||||
{
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" 2b (%2d)\n", cm.match_count);
|
||||
|
|
@ -1431,8 +1419,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
|
|||
|
||||
if (charmap_load(&cm, lang_file))
|
||||
{
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
|
||||
lang_file);
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
|
||||
im->lang = LANG_DEFAULT;
|
||||
return im_event_c(im, event);
|
||||
}
|
||||
|
|
@ -1449,7 +1436,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
|
|||
|
||||
|
||||
/* Discard redraw characters, so they can be redrawn */
|
||||
if ((int) wcslen(im->s) < im->redraw)
|
||||
if ((int)wcslen(im->s) < im->redraw)
|
||||
im->redraw = wcslen(im->s);
|
||||
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
|
||||
|
||||
|
|
@ -1506,8 +1493,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
|
|||
|
||||
/* Actual character processing */
|
||||
default:
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|
||||
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
{
|
||||
/* English mode */
|
||||
if (cm.section == SEC_ENGLISH)
|
||||
|
|
@ -1532,8 +1518,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
|
|||
const wchar_t *us = charmap_search(&cm, im->buf);
|
||||
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
|
||||
wcslen(im->buf));
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
|
||||
#endif
|
||||
|
||||
/* Match was found? */
|
||||
|
|
@ -1573,7 +1558,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
|
|||
cm.match_is_final = 0;
|
||||
}
|
||||
/* If the matched characters didn't consume all, it's own state */
|
||||
else if ((size_t) cm.match_count != wcslen(im->buf))
|
||||
else if ((size_t)cm.match_count != wcslen(im->buf))
|
||||
{
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" 2b (%2d)\n", cm.match_count);
|
||||
|
|
@ -1628,15 +1613,14 @@ static int im_event_ko_isvowel(CHARMAP * cm, wchar_t c)
|
|||
|
||||
/* Determine the starting state based on the charmap's active section */
|
||||
section = cm->section;
|
||||
if (!IN_RANGE(0, section, (int) ARRAYLEN(cm->sections)))
|
||||
if (!IN_RANGE(0, section, (int)ARRAYLEN(cm->sections)))
|
||||
section = 0;
|
||||
start = &cm->sections[section];
|
||||
|
||||
next = sm_search_shallow(start, (char) c);
|
||||
next = sm_search_shallow(start, (char)c);
|
||||
unicode = next ? next->output : NULL;
|
||||
|
||||
return (unicode && wcslen(unicode) == 1 && 0x314F <= unicode[0]
|
||||
&& unicode[0] <= 0x3163);
|
||||
return (unicode && wcslen(unicode) == 1 && 0x314F <= unicode[0] && unicode[0] <= 0x3163);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1685,8 +1669,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
|
|||
|
||||
if (charmap_load(&cm, lang_file))
|
||||
{
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
|
||||
lang_file);
|
||||
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
|
||||
im->lang = LANG_DEFAULT;
|
||||
return im_event_c(im, event);
|
||||
}
|
||||
|
|
@ -1703,7 +1686,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
|
|||
|
||||
|
||||
/* Discard redraw characters, so they can be redrawn */
|
||||
if ((int) wcslen(im->s) < im->redraw)
|
||||
if ((int)wcslen(im->s) < im->redraw)
|
||||
im->redraw = wcslen(im->s);
|
||||
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
|
||||
|
||||
|
|
@ -1758,8 +1741,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
|
|||
|
||||
/* Actual character processing */
|
||||
default:
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|
||||
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
|
||||
{
|
||||
/* English mode */
|
||||
if (cm.section == SEC_ENGLISH)
|
||||
|
|
@ -1783,8 +1765,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
|
|||
const wchar_t *us = charmap_search(&cm, bp);
|
||||
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
|
||||
wcslen(im->buf));
|
||||
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
|
||||
#endif
|
||||
|
||||
/* Match was found? */
|
||||
|
|
@ -1876,7 +1857,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
|
|||
cm.match_is_final = 0;
|
||||
}
|
||||
/* If the matched characters didn't consume all, it's own state */
|
||||
else if ((size_t) cm.match_count != wcslen(bp))
|
||||
else if ((size_t)cm.match_count != wcslen(bp))
|
||||
{
|
||||
#ifdef IM_DEBUG
|
||||
wprintf(L" 2b (%2d)\n", cm.match_count);
|
||||
|
|
|
|||
16
src/indent.sh
Executable file
16
src/indent.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Indent Tux Paint source files
|
||||
|
||||
echo "Indenting src/*.c"
|
||||
find . -name "*.c" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
|
||||
|
||||
echo "Indenting src/*.h"
|
||||
find . -name "*.h" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
|
||||
|
||||
echo "Indenting magic/src/*.c"
|
||||
find ../magic/src/ -name "*.c" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
|
||||
|
||||
echo "Indenting magic/src/*.h"
|
||||
find ../magic/src/ -name "*.h" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
|
||||
|
||||
|
|
@ -61,8 +61,7 @@ static void draw_keyboard(on_screen_keyboard * keyboard);
|
|||
static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y);
|
||||
static void set_key(osk_key * orig, osk_key * dest, int firsttime);
|
||||
static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name);
|
||||
static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
|
||||
char *layout_name);
|
||||
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name);
|
||||
|
||||
#ifdef DEBUG_OSK_COMPOSEMAP
|
||||
static void print_composemap(osk_composenode * composemap, char *sp);
|
||||
|
|
@ -91,9 +90,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
SDL_Surface * BLANK_oskdel,
|
||||
SDL_Surface * BLANK_osktab,
|
||||
SDL_Surface * BLANK_oskenter,
|
||||
SDL_Surface * BLANK_oskcapslock,
|
||||
SDL_Surface * BLANK_oskshift,
|
||||
int disable_change)
|
||||
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift, int disable_change)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
SDL_Surface *button_up, *button_down;
|
||||
|
|
@ -113,8 +110,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
layout = load_layout(keyboard, layout_name);
|
||||
if (!layout)
|
||||
{
|
||||
fprintf(stderr, "Error trying to load the required layout %s\n",
|
||||
layout_name);
|
||||
fprintf(stderr, "Error trying to load the required layout %s\n", layout_name);
|
||||
layout = load_layout(keyboard, strdup("default.layout"));
|
||||
if (!layout)
|
||||
{
|
||||
|
|
@ -142,17 +138,15 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
#ifdef OSK_DEBUG
|
||||
printf
|
||||
("%d x %d layout of %d x %d buttons won't fit within %d x %d pixel area...\n",
|
||||
layout->width, layout->height, BLANK_button_up->w, BLANK_button_up->h,
|
||||
layout_avail_width, layout_avail_height);
|
||||
layout->width, layout->height, BLANK_button_up->w, BLANK_button_up->h, layout_avail_width, layout_avail_height);
|
||||
#endif
|
||||
|
||||
max_w = (float) layout_avail_width / (float) layout->width;
|
||||
max_h = (float) layout_avail_height / (float) layout->height;
|
||||
max_w = (float)layout_avail_width / (float)layout->width;
|
||||
max_h = (float)layout_avail_height / (float)layout->height;
|
||||
|
||||
#ifdef OSK_DEBUG
|
||||
printf("...want (%d / %d) x (%d x %d) = %.2f x %.2f buttons...\n",
|
||||
layout_avail_width, layout->width,
|
||||
layout_avail_height, layout->height, max_w, max_h);
|
||||
layout_avail_width, layout->width, layout_avail_height, layout->height, max_w, max_h);
|
||||
#endif
|
||||
|
||||
if (max_w > max_h)
|
||||
|
|
@ -160,8 +154,8 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
if (max_h > max_w)
|
||||
max_h = max_w;
|
||||
|
||||
scale_w = (float) max_w / (float) BLANK_button_up->w;
|
||||
scale_h = (float) max_h / (float) BLANK_button_up->h;
|
||||
scale_w = (float)max_w / (float)BLANK_button_up->w;
|
||||
scale_h = (float)max_h / (float)BLANK_button_up->h;
|
||||
|
||||
#ifdef OSK_DEBUG
|
||||
printf("...so scaling by w=%.2f & h=%.2f\n", scale_w, scale_h);
|
||||
|
|
@ -196,8 +190,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
layout->width * button_up->w,
|
||||
layout->height * button_up->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask,
|
||||
canvas->format->Bmask, 0);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
|
||||
if (!surface)
|
||||
{
|
||||
fprintf(stderr, "Error creating the onscreen keyboard surface\n");
|
||||
|
|
@ -251,8 +244,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
|
||||
SDL_FillRect(surface, NULL,
|
||||
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r,
|
||||
keyboard->layout->bgcolor.g,
|
||||
keyboard->layout->bgcolor.b));
|
||||
keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b));
|
||||
|
||||
keybd_prepare(keyboard);
|
||||
|
||||
|
|
@ -260,8 +252,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
return keyboard;
|
||||
}
|
||||
|
||||
static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
|
||||
char *layout_name)
|
||||
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name)
|
||||
{
|
||||
FILE *fi;
|
||||
int hlayout_loaded;
|
||||
|
|
@ -303,8 +294,7 @@ static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
|
|||
fi = fopen(filename, "r");
|
||||
if (fi == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", layout_name,
|
||||
filename);
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", layout_name, filename);
|
||||
/* Fallback to default */
|
||||
snprintf(filename, 255, "%sosk/default.layout", DATA_PREFIX);
|
||||
fi = fopen(filename, "r");
|
||||
|
|
@ -424,8 +414,7 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
|
|||
fi = fopen(filename, "r");
|
||||
if (fi == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", hlayout_name,
|
||||
filename);
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", hlayout_name, filename);
|
||||
layout->keys = NULL;
|
||||
free(filename);
|
||||
return;
|
||||
|
|
@ -534,8 +523,7 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
|
|||
layout->keys[line_number][i].shift_altgr_label = NULL;
|
||||
}
|
||||
}
|
||||
else if (width && height && allocated && strncmp(line, "KEY ", 4) == 0
|
||||
&& key_number < width)
|
||||
else if (width && height && allocated && strncmp(line, "KEY ", 4) == 0 && key_number < width)
|
||||
{
|
||||
plain_label = malloc(sizeof(char) * 64);
|
||||
top_label = malloc(sizeof(char) * 64);
|
||||
|
|
@ -546,17 +534,14 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
|
|||
"%s %i %i.%i %s %s %s %s %i",
|
||||
key,
|
||||
&keycode,
|
||||
&key_width, &key_width_decimal, plain_label, top_label,
|
||||
altgr_label, shift_altgr_label, &shiftcaps);
|
||||
&key_width, &key_width_decimal, plain_label, top_label, altgr_label, shift_altgr_label, &shiftcaps);
|
||||
layout->keys[line_number][key_number].keycode = keycode;
|
||||
layout->keys[line_number][key_number].width =
|
||||
(float) 0.1 *key_width_decimal + key_width;
|
||||
layout->keys[line_number][key_number].width = (float)0.1 *key_width_decimal + key_width;
|
||||
|
||||
layout->keys[line_number][key_number].plain_label = plain_label;
|
||||
layout->keys[line_number][key_number].top_label = top_label;
|
||||
layout->keys[line_number][key_number].altgr_label = altgr_label;
|
||||
layout->keys[line_number][key_number].shift_altgr_label =
|
||||
shift_altgr_label;
|
||||
layout->keys[line_number][key_number].shift_altgr_label = shift_altgr_label;
|
||||
layout->keys[line_number][key_number].shiftcaps = shiftcaps;
|
||||
layout->keys[line_number][key_number].stick = 0;
|
||||
key_number++;
|
||||
|
|
@ -653,9 +638,7 @@ void load_keymap(osk_layout * layout, char *keymap_name)
|
|||
|
||||
/* FIXME: Why is the us-intl keymap duplicating the two first entries of every keycode? */
|
||||
/* And why is the arabic keymap using the 5th and 6th entries as plain/shifted keys? */
|
||||
readed =
|
||||
sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2,
|
||||
ksname3, ksname4);
|
||||
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2, ksname3, ksname4);
|
||||
|
||||
if (readed == 5 && keycode > 8 && keycode < 256)
|
||||
{
|
||||
|
|
@ -695,8 +678,7 @@ void load_keymap(osk_layout * layout, char *keymap_name)
|
|||
}
|
||||
|
||||
/* Scans a line of keysyms and result and classifies them. */
|
||||
static void gettokens(char *line, char *delim, char **pointer,
|
||||
osk_composenode * composenode, osk_layout * layout)
|
||||
static void gettokens(char *line, char *delim, char **pointer, osk_composenode * composenode, osk_layout * layout)
|
||||
{
|
||||
int i;
|
||||
char *tok;
|
||||
|
|
@ -763,9 +745,7 @@ static void gettokens(char *line, char *delim, char **pointer,
|
|||
}
|
||||
|
||||
composenode->size = composenode->size + 1;
|
||||
composenode->childs =
|
||||
realloc(composenode->childs,
|
||||
composenode->size * sizeof(osk_composenode *));
|
||||
composenode->childs = realloc(composenode->childs, composenode->size * sizeof(osk_composenode *));
|
||||
|
||||
mbstowcs(wtok, tok, 255);
|
||||
auxnode = malloc(sizeof(osk_composenode));
|
||||
|
|
@ -776,8 +756,7 @@ static void gettokens(char *line, char *delim, char **pointer,
|
|||
|
||||
/* printf("size %d, keysym %ls =>", composenode->size, composenode->childs[composenode->size - 1]->keysym); */
|
||||
|
||||
gettokens(NULL, delim, pointer,
|
||||
composenode->childs[composenode->size - 1], layout);
|
||||
gettokens(NULL, delim, pointer, composenode->childs[composenode->size - 1], layout);
|
||||
free(tok);
|
||||
return;
|
||||
}
|
||||
|
|
@ -808,8 +787,7 @@ static void load_composemap(osk_layout * layout, char *composemap_name)
|
|||
fi = fopen(filename, "r");
|
||||
if (fi == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", composemap_name,
|
||||
filename);
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", composemap_name, filename);
|
||||
layout->keys = NULL;
|
||||
free(filename);
|
||||
return;
|
||||
|
|
@ -832,7 +810,7 @@ static void load_composemap(osk_layout * layout, char *composemap_name)
|
|||
if (is_blank_or_comment(line))
|
||||
continue;
|
||||
|
||||
gettokens(line, (char *) ">< \t", pointer, layout->composemap, layout);
|
||||
gettokens(line, (char *)">< \t", pointer, layout->composemap, layout);
|
||||
}
|
||||
|
||||
fclose(fi);
|
||||
|
|
@ -917,8 +895,7 @@ static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name)
|
|||
fi = fopen(filename, "r");
|
||||
if (fi == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", keysymdefs_name,
|
||||
filename);
|
||||
fprintf(stderr, "Can't open either %s nor %s\n", keysymdefs_name, filename);
|
||||
layout->keysymdefs = NULL;
|
||||
free(filename);
|
||||
return;
|
||||
|
|
@ -939,15 +916,13 @@ static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name)
|
|||
continue;
|
||||
|
||||
layout->sizeofkeysymdefs = i;
|
||||
layout->keysymdefs =
|
||||
realloc(layout->keysymdefs, sizeof(keysymdefs) * (i + 1));
|
||||
layout->keysymdefs = realloc(layout->keysymdefs, sizeof(keysymdefs) * (i + 1));
|
||||
|
||||
/* Some keysyms doesn't correspond to any unicode value, ej. BackSpace */
|
||||
layout->keysymdefs[i].unicode = 0;
|
||||
layout->keysymdefs[i].mnemo = malloc(sizeof(char) * 128);
|
||||
sscanf(line, "#define XK_%s %x /* U+%x",
|
||||
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym,
|
||||
&layout->keysymdefs[i].unicode);
|
||||
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym, &layout->keysymdefs[i].unicode);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
@ -1004,8 +979,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
|
|||
* This software is in the public domain. Share and enjoy!
|
||||
*/
|
||||
/* first check for Latin-1 characters (1:1 mapping) */
|
||||
if ((keysym >= 0x0020 && keysym <= 0x007e)
|
||||
|| (keysym >= 0x00a0 && keysym <= 0x00ff))
|
||||
if ((keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff))
|
||||
return keysym;
|
||||
|
||||
/* also check for directly encoded 24-bit UCS characters */
|
||||
|
|
@ -1023,9 +997,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
|
|||
|
||||
|
||||
/* Searches in the tree for composing stuff */
|
||||
static void get_composed_keysym(on_screen_keyboard * keyboard,
|
||||
osk_composenode * composenode,
|
||||
wchar_t *keysym)
|
||||
static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode * composenode, wchar_t *keysym)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -1145,43 +1117,37 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
|
|||
if (keyboard->layout->fontpath)
|
||||
{
|
||||
/* First try if it is an absolute path */
|
||||
keyboard->osk_fonty =
|
||||
TTF_OpenFont(keyboard->layout->fontpath, font_height);
|
||||
keyboard->osk_fonty = TTF_OpenFont(keyboard->layout->fontpath, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Now trying if it is relative to DATA_PREFIX/fonts/ */
|
||||
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX,
|
||||
keyboard->layout->fontpath);
|
||||
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX, keyboard->layout->fontpath);
|
||||
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Perhaps it is relative to DATA_PREFIX only? */
|
||||
snprintf(fontname, 255, "%s/%s", DATA_PREFIX,
|
||||
keyboard->layout->fontpath);
|
||||
snprintf(fontname, 255, "%s/%s", DATA_PREFIX, keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Or to DATA_PREFIX/fonts/locale/ ? */
|
||||
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX,
|
||||
keyboard->layout->fontpath);
|
||||
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX, keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Fonts are in assets "data" dir in Android builds */
|
||||
snprintf(fontname, 255, "data/fonts/%s",
|
||||
keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Fonts are in assets "data" dir in Android builds, checking locale dir */
|
||||
snprintf(fontname, 255, "data/fonts/locale/%s",
|
||||
keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Fonts are in assets "data" dir in Android builds */
|
||||
snprintf(fontname, 255, "data/fonts/%s", keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Fonts are in assets "data" dir in Android builds, checking locale dir */
|
||||
snprintf(fontname, 255, "data/fonts/locale/%s", keyboard->layout->fontpath);
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1193,17 +1159,16 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
|
|||
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
/* Also for Android */
|
||||
sprintf(fontname, "data/fonts/FreeSansBold.ttf");
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
/* Also for Android */
|
||||
sprintf(fontname, "data/fonts/FreeSansBold.ttf");
|
||||
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
|
||||
}
|
||||
}
|
||||
|
||||
if (keyboard->osk_fonty == NULL)
|
||||
{
|
||||
fprintf(stderr, "\nError: Can't open the font!\n"
|
||||
"The Simple DirectMedia Layer error that occurred was:\n"
|
||||
"%s\n\n", SDL_GetError());
|
||||
"The Simple DirectMedia Layer error that occurred was:\n" "%s\n\n", SDL_GetError());
|
||||
free(fontname);
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1213,8 +1178,7 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
|
|||
}
|
||||
|
||||
|
||||
static void apply_surface(int x, int y, SDL_Surface * source,
|
||||
SDL_Surface * destination, SDL_Rect * clip)
|
||||
static void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip)
|
||||
{
|
||||
SDL_Rect offset;
|
||||
|
||||
|
|
@ -1266,8 +1230,7 @@ static SDL_Surface *stretch_surface(SDL_Surface * orig, int width)
|
|||
width,
|
||||
orig->h,
|
||||
orig->format->BitsPerPixel,
|
||||
orig->format->Rmask, orig->format->Gmask,
|
||||
orig->format->Bmask, 0);
|
||||
orig->format->Rmask, orig->format->Gmask, orig->format->Bmask, 0);
|
||||
|
||||
SDL_BlitSurface(orig, NULL, dest, NULL);
|
||||
rect.y = 0;
|
||||
|
|
@ -1359,38 +1322,26 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
|
|||
if (strncmp("NULL", text, 4) != 0 && key.keycode != 0)
|
||||
{
|
||||
if (hot)
|
||||
skey =
|
||||
stretch_surface(keyboard->button_down,
|
||||
key.width * keyboard->button_down->w);
|
||||
skey = stretch_surface(keyboard->button_down, key.width * keyboard->button_down->w);
|
||||
|
||||
else if (key.stick)
|
||||
skey =
|
||||
stretch_surface(keyboard->button_hold,
|
||||
key.width * keyboard->button_hold->w);
|
||||
skey = stretch_surface(keyboard->button_hold, key.width * keyboard->button_hold->w);
|
||||
|
||||
else
|
||||
{
|
||||
if (key.keycode == 1 || key.keycode == 2)
|
||||
{
|
||||
if (keyboard->disable_change)
|
||||
skey =
|
||||
stretch_surface(keyboard->button_off,
|
||||
key.width * keyboard->button_off->w);
|
||||
skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w);
|
||||
else
|
||||
skey =
|
||||
stretch_surface(keyboard->button_nav,
|
||||
key.width * keyboard->button_nav->w);
|
||||
skey = stretch_surface(keyboard->button_nav, key.width * keyboard->button_nav->w);
|
||||
}
|
||||
else
|
||||
skey =
|
||||
stretch_surface(keyboard->button_up,
|
||||
key.width * keyboard->button_up->w);
|
||||
skey = stretch_surface(keyboard->button_up, key.width * keyboard->button_up->w);
|
||||
}
|
||||
}
|
||||
else
|
||||
skey =
|
||||
stretch_surface(keyboard->button_off,
|
||||
key.width * keyboard->button_off->w);
|
||||
skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w);
|
||||
|
||||
apply_surface(key.x, key.y, skey, keyboard->surface, NULL);
|
||||
|
||||
|
|
@ -1452,8 +1403,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
|
|||
}
|
||||
}
|
||||
|
||||
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS
|
||||
&& !(modstate & KMOD_SHIFT))
|
||||
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS && !(modstate & KMOD_SHIFT))
|
||||
{
|
||||
if (key.shiftcaps)
|
||||
text = strdup(key.shift_altgr_label);
|
||||
|
|
@ -1486,8 +1436,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
|
|||
|
||||
else if (strncmp("CAPSLOCK", text, 8) == 0)
|
||||
{
|
||||
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface,
|
||||
NULL);
|
||||
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface, NULL);
|
||||
}
|
||||
|
||||
else if (strncmp("SHIFT", text, 5) == 0)
|
||||
|
|
@ -1497,9 +1446,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
|
|||
|
||||
else if (strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
|
||||
{
|
||||
messager =
|
||||
TTF_RenderUTF8_Blended(keyboard->osk_fonty, text,
|
||||
keyboard->layout->fgcolor);
|
||||
messager = TTF_RenderUTF8_Blended(keyboard->osk_fonty, text, keyboard->layout->fgcolor);
|
||||
|
||||
apply_surface(key.x + 5, key.y, messager, keyboard->surface, NULL);
|
||||
SDL_FreeSurface(messager);
|
||||
|
|
@ -1516,12 +1463,10 @@ static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y)
|
|||
key = NULL;
|
||||
for (j = 0; j < keyboard->layout->height; j++)
|
||||
{
|
||||
if (keyboard->layout->keys[j][0].y < y
|
||||
&& keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
|
||||
if (keyboard->layout->keys[j][0].y < y && keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
|
||||
for (i = 0; i < keyboard->layout->width; i++)
|
||||
if (keyboard->layout->keys[j][i].x < x &&
|
||||
keyboard->layout->keys[j][i].x +
|
||||
keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
|
||||
keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
|
||||
{
|
||||
key = &keyboard->layout->keys[j][i];
|
||||
return key;
|
||||
|
|
@ -1629,8 +1574,7 @@ static char *find_keysym(osk_key key, on_screen_keyboard * keyboard)
|
|||
}
|
||||
}
|
||||
|
||||
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS
|
||||
&& !(modstate & KMOD_SHIFT))
|
||||
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS && !(modstate & KMOD_SHIFT))
|
||||
{
|
||||
if (key.shiftcaps)
|
||||
keysym = keysyms.shiftaltgr;
|
||||
|
|
@ -1650,8 +1594,7 @@ static char *find_keysym(osk_key key, on_screen_keyboard * keyboard)
|
|||
}
|
||||
|
||||
/* We lose the SDL ModState by leaving and entering the tuxpaint window, so using a custom state */
|
||||
static int handle_keymods(char *keysym, osk_key * key,
|
||||
on_screen_keyboard * keyboard)
|
||||
static int handle_keymods(char *keysym, osk_key * key, on_screen_keyboard * keyboard)
|
||||
{
|
||||
SDL_Keymod mod;
|
||||
SDL_Event ev;
|
||||
|
|
@ -1688,8 +1631,7 @@ static int handle_keymods(char *keysym, osk_key * key,
|
|||
|
||||
/* Seems ISO_Level3_Shift and ISO_Next_Group are used too for right Alt */
|
||||
else if (strncmp("ISO_Level3_Shift", keysym, 16) == 0 ||
|
||||
strncmp("ISO_Next_Group", keysym, 14) == 0
|
||||
|| strncmp("ALT_R", keysym, 5) == 0)
|
||||
strncmp("ISO_Next_Group", keysym, 14) == 0 || strncmp("ALT_R", keysym, 5) == 0)
|
||||
{
|
||||
if (mod & KMOD_RALT)
|
||||
{
|
||||
|
|
@ -1904,10 +1846,10 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
|
|||
|
||||
wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1));
|
||||
|
||||
mbsrtowcs(wkeysym, (const char **) &keysym, strlen(keysym) + 1, NULL);
|
||||
mbsrtowcs(wkeysym, (const char **)&keysym, strlen(keysym) + 1, NULL);
|
||||
|
||||
#ifdef OSK_DEBUG
|
||||
printf("wkeysym %ls %i\n\n", wkeysym, (int) wcslen(wkeysym));
|
||||
printf("wkeysym %ls %i\n\n", wkeysym, (int)wcslen(wkeysym));
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -1932,8 +1874,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
|
|||
event.text.text[0] = '\r';
|
||||
event.text.text[1] = '\0';
|
||||
}
|
||||
else if (wcsncmp(L"Tab", ks, 3) == 0
|
||||
|| wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
|
||||
else if (wcsncmp(L"Tab", ks, 3) == 0 || wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
|
||||
{
|
||||
event.key.keysym.sym = SDLK_TAB;
|
||||
event.text.text[0] = '\t';
|
||||
|
|
@ -1966,7 +1907,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
|
|||
wchar_t buf[2];
|
||||
|
||||
iwc = keysym2unicode(mnemo2keysym(mnemo, keyboard), keyboard);
|
||||
buf[0] = (wchar_t) iwc;
|
||||
buf[0] = (wchar_t)iwc;
|
||||
buf[1] = L'\0';
|
||||
|
||||
#ifdef OSK_DEBUG
|
||||
|
|
@ -1979,7 +1920,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
|
|||
printf("len = %d\n", len);
|
||||
printf("event.text.text = \"%s\"\n", event.text.text);
|
||||
#else
|
||||
len = len; /* Avoid 'set but not used' warning */
|
||||
len = len; /* Avoid 'set but not used' warning */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,15 +156,12 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
|
|||
SDL_Surface * BLANK_oskdel,
|
||||
SDL_Surface * BLANK_osktab,
|
||||
SDL_Surface * BLANK_oskenter,
|
||||
SDL_Surface * BLANK_oskcapslock,
|
||||
SDL_Surface * BLANK_oskshift,
|
||||
int disable_change);
|
||||
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_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);
|
||||
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);
|
||||
|
|
|
|||
32
src/pixels.c
32
src/pixels.c
|
|
@ -37,9 +37,7 @@ 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)))
|
||||
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 */
|
||||
|
|
@ -60,9 +58,7 @@ 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)))
|
||||
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 */
|
||||
|
|
@ -83,9 +79,7 @@ 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)))
|
||||
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 */
|
||||
|
|
@ -118,9 +112,7 @@ 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)))
|
||||
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 */
|
||||
|
|
@ -141,9 +133,9 @@ 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
|
||||
|
|
@ -167,9 +159,9 @@ 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
|
||||
|
|
@ -194,9 +186,9 @@ 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
|
||||
|
|
@ -227,9 +219,9 @@ 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
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ static int old_sound[4] = { -1, -1, -1, -1 };
|
|||
* (low values, near the top of the window, are quieter), or
|
||||
* SNDDIST_NEAR for full volume
|
||||
*/
|
||||
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;
|
||||
|
|
@ -109,8 +108,7 @@ void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
|
|||
left = (255 - dist) / 2;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("Panning of sound #%d in channel %d, left=%d, right=%d\n", s,
|
||||
chan, left, (255 - dist) - left);
|
||||
printf("Panning of sound #%d in channel %d, left=%d, right=%d\n", s, chan, left, (255 - dist) - left);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
Mix_SetPanning(chan, left, (255 - dist) - left);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
extern Mix_Chunk *sounds[NUM_SOUNDS];
|
||||
extern int mute, use_sound, use_stereo;
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -68,18 +68,17 @@
|
|||
|
||||
static int f2int(float f)
|
||||
{
|
||||
return ((int) f);
|
||||
return ((int)f);
|
||||
}
|
||||
|
||||
static int f2dec(float f)
|
||||
{
|
||||
return (int) ((f - f2int(f)) * 100);
|
||||
return (int)((f - f2int(f)) * 100);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
int img_w = surf->w;
|
||||
|
|
@ -93,8 +92,7 @@ int do_ps_save(FILE * fi,
|
|||
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;
|
||||
|
|
@ -148,8 +146,7 @@ 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
|
||||
|
|
@ -157,8 +154,7 @@ int do_ps_save(FILE * fi,
|
|||
|
||||
/* 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))
|
||||
if ((ppr_w >= ppr_h && img_w >= img_h) || (ppr_w <= ppr_h && img_w <= img_h))
|
||||
{
|
||||
rotate = 0;
|
||||
r_img_w = img_w;
|
||||
|
|
@ -180,16 +176,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
|
||||
|
||||
|
||||
|
|
@ -215,8 +208,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");
|
||||
|
||||
|
|
@ -235,23 +227,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));
|
||||
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. */
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@
|
|||
#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
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ int progress_bar_disabled, prog_bar_ctr;
|
|||
*
|
||||
* @param screen Screen surface
|
||||
*/
|
||||
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;
|
||||
|
|
@ -73,9 +72,7 @@ void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture,
|
|||
r.w = screen->w;
|
||||
r.h = 24;
|
||||
|
||||
SDL_UpdateTexture(texture, &r,
|
||||
screen->pixels + ((screen->h - 24) * screen->pitch),
|
||||
screen->pitch);
|
||||
SDL_UpdateTexture(texture, &r, screen->pixels + ((screen->h - 24) * screen->pitch), screen->pitch);
|
||||
|
||||
/* Docs says one should clear the renderer, even if this means a refresh of the whole thing. */
|
||||
SDL_RenderClear(renderer);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@
|
|||
extern SDL_Surface *img_progress;
|
||||
extern 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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
17
src/shapes.h
17
src/shapes.h
|
|
@ -327,10 +327,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."),
|
||||
|
|
@ -357,11 +355,9 @@ const char *const shape_tips[NUM_SHAPES] = {
|
|||
gettext_noop("An octagon has eight equal 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 triangle star (3 points star)
|
||||
gettext_noop("A star with 3 points."),
|
||||
gettext_noop("A star with 3 points."),
|
||||
|
|
@ -435,8 +431,7 @@ enum
|
|||
const char *const shape_tool_tips[NUM_SHAPE_COMPLEXITIES] = {
|
||||
gettext_noop
|
||||
("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want. Move around to rotate it, and click again to draw it."),
|
||||
gettext_noop
|
||||
("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want.")
|
||||
gettext_noop("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want.")
|
||||
};
|
||||
|
||||
/* Strings shown when switching between "from center"
|
||||
|
|
|
|||
|
|
@ -57,9 +57,7 @@ int main(int argc, char *argv[])
|
|||
/* Open each PNG image!... */
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
printf
|
||||
("%5d ------------------------------------------------------------------\n",
|
||||
i);
|
||||
printf("%5d ------------------------------------------------------------------\n", i);
|
||||
printf("%s\n", argv[i]);
|
||||
fflush(stdout);
|
||||
|
||||
|
|
@ -134,8 +132,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Fill alpha channel if there is none */
|
||||
if (ctype == PNG_COLOR_TYPE_RGB ||
|
||||
ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_PALETTE)
|
||||
if (ctype == PNG_COLOR_TYPE_RGB || ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
|
||||
}
|
||||
|
|
@ -163,8 +160,7 @@ int main(int argc, char *argv[])
|
|||
rows[y] = (png_byte *) malloc(png_get_rowbytes(png, info));
|
||||
if (!rows[y])
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Failed to malloc() space for image data row #%d!\n", y);
|
||||
fprintf(stderr, "Failed to malloc() space for image data row #%d!\n", y);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6195
src/tuxpaint.c
6195
src/tuxpaint.c
File diff suppressed because it is too large
Load diff
|
|
@ -84,7 +84,7 @@ struct dirent *readdir(struct DIR *pDir)
|
|||
if (pDir->hFind)
|
||||
|
||||
{
|
||||
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
|
||||
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
|
||||
if (!FindNextFile(pDir->hFind, &pDir->wfd))
|
||||
|
||||
{
|
||||
|
|
@ -107,9 +107,7 @@ struct dirent *readdir(struct DIR *pDir)
|
|||
*/
|
||||
int alphasort(const void *a, const void *b)
|
||||
{
|
||||
return (strcmp
|
||||
((*(const struct dirent **) a)->d_name,
|
||||
(*(const struct dirent **) b)->d_name));
|
||||
return (strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,15 +124,11 @@ 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 *)));
|
||||
*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);
|
||||
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;
|
||||
|
|
@ -151,8 +145,7 @@ static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
|
|||
* @param compar Callback for sorting items in the list (via qsort()).
|
||||
* @return Count of items, or -1 on error.
|
||||
*/
|
||||
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
|
||||
comparCB compar)
|
||||
int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
|
||||
{
|
||||
DIR *pDir;
|
||||
int count;
|
||||
|
|
@ -173,7 +166,6 @@ int scandir(const char *dir, struct dirent ***namelist, selectCB select,
|
|||
if (count <= 0)
|
||||
return -1;
|
||||
if (compar != NULL)
|
||||
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
|
||||
compar);
|
||||
qsort((void *)(*namelist), (size_t)count, sizeof(struct dirent *), compar);
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,5 +71,4 @@ extern struct dirent *readdir(struct DIR *pDir);
|
|||
typedef int (*selectCB)(const struct dirent *);
|
||||
typedef int (*comparCB)(const void *, const void *);
|
||||
extern int alphasort(const void *a, const void *b);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist,
|
||||
selectCB select, comparCB compar);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ static SDL_Surface *make24bitDIB(SDL_Surface * surf)
|
|||
|
||||
surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE);
|
||||
surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24,
|
||||
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask,
|
||||
pixfmt.Amask);
|
||||
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask);
|
||||
|
||||
linesize = surf24->w * 3; // Flip top2bottom
|
||||
dst = surfDIB->pixels;
|
||||
|
|
@ -105,8 +104,7 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
|
|||
return 0;
|
||||
|
||||
if (((dev = strtok(buff, ",")) != NULL) &&
|
||||
((drv = strtok(NULL, ", ")) != NULL)
|
||||
&& ((out = strtok(NULL, ", ")) != NULL))
|
||||
((drv = strtok(NULL, ", ")) != NULL) && ((out = strtok(NULL, ", ")) != NULL))
|
||||
{
|
||||
if (device)
|
||||
strcpy(device, dev);
|
||||
|
|
@ -145,8 +143,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;
|
||||
|
|
@ -159,8 +156,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;
|
||||
|
||||
|
|
@ -170,9 +166,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;
|
||||
|
||||
|
|
@ -195,8 +189,7 @@ err_exit:
|
|||
/**
|
||||
* FIXME
|
||||
*/
|
||||
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
|
||||
HANDLE hDevMode)
|
||||
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
|
||||
|
|
@ -208,7 +201,7 @@ static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
|
|||
int block_written;
|
||||
char devname[dmDeviceNameSize];
|
||||
|
||||
strcpy(devname, (const char *) devmode->dmDeviceName);
|
||||
strcpy(devname, (const char *)devmode->dmDeviceName);
|
||||
fwrite(devname, 1, sizeof(devname), fp);
|
||||
block_written = fwrite(devmode, 1, block_size, fp);
|
||||
GlobalUnlock(hDevMode);
|
||||
|
|
@ -272,8 +265,7 @@ static int GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
|
@ -326,8 +318,7 @@ int IsPrinterAvailable(void)
|
|||
/**
|
||||
* FIXME
|
||||
*/
|
||||
const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
|
||||
const char *printcfg, int showdialog)
|
||||
const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf, const char *printcfg, int showdialog)
|
||||
{
|
||||
const char *res = NULL;
|
||||
HWND hWnd;
|
||||
|
|
@ -424,17 +415,17 @@ const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
|
|||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -476,9 +467,8 @@ const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
|
|||
nError = StretchDIBits(hDCprinter, rcDst.left, rcDst.top,
|
||||
rcDst.right - rcDst.left,
|
||||
rcDst.bottom - rcDst.top,
|
||||
0, 0, bmih.biWidth, bmih.biHeight,
|
||||
surf24->pixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
if (nError == (int) GDI_ERROR)
|
||||
0, 0, bmih.biWidth, bmih.biHeight, surf24->pixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
if (nError == (int)GDI_ERROR)
|
||||
{
|
||||
res = "win32_print: StretchDIBits() failed.";
|
||||
goto error;
|
||||
|
|
@ -523,8 +513,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;
|
||||
|
|
@ -573,8 +562,7 @@ 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;
|
||||
|
||||
|
|
@ -598,8 +586,7 @@ 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;
|
||||
|
||||
|
|
@ -621,8 +608,7 @@ char *GetUserImageDir(void);
|
|||
char *GetUserImageDir(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 = "My Pictures";
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
|
|
@ -675,8 +661,7 @@ static int g_bWindowActive = 0;
|
|||
/**
|
||||
* FIXME
|
||||
*/
|
||||
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
|
||||
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int bEatKeystroke = 0;
|
||||
|
|
@ -690,8 +675,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|||
case WM_KEYDOWN:
|
||||
case WM_KEYUP:
|
||||
{
|
||||
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN)
|
||||
|| (p->vkCode == VK_RWIN));
|
||||
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -708,9 +692,7 @@ int InstallKeyboardHook(void)
|
|||
{
|
||||
if (g_hKeyboardHook)
|
||||
return -1;
|
||||
g_hKeyboardHook =
|
||||
SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
|
||||
GetModuleHandle(NULL), 0);
|
||||
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0);
|
||||
return g_hKeyboardHook ? 0 : -2;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@
|
|||
#endif
|
||||
|
||||
/* if printcfg is NULL, uses the default printer */
|
||||
extern const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
|
||||
const char *printcfg, int showdialog);
|
||||
extern const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf, const char *printcfg, int showdialog);
|
||||
extern int IsPrinterAvailable(void);
|
||||
|
||||
/* additional windows functions requiring <windows.h> */
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ int MoveFileToRecycleBin(const TCHAR * fullPathName)
|
|||
fileOp.hwnd = NULL;
|
||||
fileOp.wFunc = FO_DELETE;
|
||||
fileOp.pTo = NULL;
|
||||
fileOp.fFlags =
|
||||
FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
|
||||
fileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
|
||||
return SHFileOperation(&fileOp);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue