From be2b5537b3de150fd7fb4a9187ae0259c0d9f689 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Tue, 27 Apr 2010 22:04:43 +0000 Subject: [PATCH] * Exposing load_user_fonts() and some other font.c functions, even when FORKED_FONTS is not set. * No longer undef'ing SDL_thread stuff when FORKED_FONTS is used if we're ALSO not using SDL_Pango, since that now uses a thread to let fontconfig generate its cache, and still let Tux Paint be responsive to the OS and user. (SF.net bug #2944951) * Spawning a thread and rendering a dummy string with SDL_Pango, to allow fontconfig to generate its cache. (SF.net bug #2944951) * Setting up 'busy' mouse cursor (watch-shaped) earlier (so it can happen while fontconfig cache thread runs). * Not spawning forked font scanner (FORKED_FONTS) as early, so fontconfig can generate its cache first. (I wasn't sure if calling an SDL_thread after a fork() occured was safe or not; admittedly, I discovered that SDL_thread spawning wasn't working due to the re-#defines of those functions when FORKED_FONTS was set; see above.) All of this only tested on Ubuntu 9.04. Forced disabling of FORKED_FONTS by editing fonts.h, and Tux Paint still worked (it just took longer at the splash screen while the fonts were loaded). Needs testing on various Windows, Mac OS X and BeOS. --- Makefile | 6 +- docs/CHANGES.txt | 67 ++++++++++-------- src/fonts.c | 5 +- src/fonts.h | 7 ++ src/tuxpaint.c | 177 ++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 196 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index 17db6a180..96075007e 100644 --- a/Makefile +++ b/Makefile @@ -244,7 +244,8 @@ MOUSE_CFLAGS:=-Isrc/$(MOUSEDIR) -D$(CURSOR_SHAPES)_CURSOR_SHAPES # "make" with no arguments builds the program and man page from sources: # .PHONY: all -all: tuxpaint translations magic-plugins tp-magic-config thumb-starters +all: tuxpaint translations magic-plugins tp-magic-config +# thumb-starters @echo @echo "--------------------------------------------------------------" @echo @@ -416,9 +417,10 @@ install: install-bin install-data install-man install-doc \ install-magic-plugin-dev \ install-icon install-gettext install-im install-importscript \ install-default-config install-example-stamps \ - install-example-starters install-thumb-starters\ + install-example-starters \ install-bash-completion \ $(ARCH_INSTALL) +#install-thumb-starters @echo @echo "--------------------------------------------------------------" @echo diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index a8fe943ad..617afa9ae 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2009.April.24 (0.9.22) +2009.April.27 (0.9.22) * New Tools: ---------- * Label - A tool to add text to a drawing, which can be modified or @@ -21,7 +21,7 @@ $Id$ ---------------- * Blinds - Close window blinds over your picture. Perspective - Change the image's perspective. - Mosaic Hexagon, Mosaic irregular, Mosaic square - Glass mosaic effects. + Moasic Hexagon, Mosaic irregular, Mosaic square - Glass mosaic effects. Zoom - Zoom the image in or out. By Pere Pujal i Carabantes @@ -45,6 +45,19 @@ $Id$ * Other Improvements: ------------------- + * Creating thumbnails for the starters we provide. + Pere Pujal i Carabantes + + * On systems where Pango is used for UI text rendering, Tux Paint now + spawns a temporary thread during start-up (at the splash screen) to + allow "fontconfig" to generate its font cache in the background, + while showing the "please wait" animation, and responding to the US. + (Fontconfig takes a long time to generate its cache the first time + you run a Pango- and hence fontconfig-enabled application + (Tux Paint, Gimp, Inkscape, etc.), or after adding lots of new fonts + to your system). + SF.net Bug #2944951 + * Thumbnailing (of UI elements, stamps, saved images, etc.) is now gamma-corrected. See: http://www.4p8.com/eric.brasseur/gamma.html @@ -106,8 +119,6 @@ $Id$ * Creation of thumbnails for personal starters and templates. - * Creating thumbnails for the starters we provide. - * New Starters: ------------- * Elephant @@ -147,7 +158,7 @@ $Id$ * New Locales: ------------ * Luxembourgish translation - René Brandenburger + Ren� Brandenburger * Malayalam translation TBD @@ -156,7 +167,7 @@ $Id$ Farinaz Hedayat * Venetian language - Fabio Lazarin, El Galepìn + Fabio Lazarin, El Galep�n * Localization Updates: --------------------- @@ -375,7 +386,7 @@ $Id$ * New localizations: ------------------ - * Shuswap (Secwepemctín) translation + * Shuswap (Secwepemct�n) translation Neskie Manuel * Songhay translation @@ -444,7 +455,7 @@ $Id$ Simona Riva * Kurdish translation - Amed Çeko Jiyan + Amed �eko Jiyan * Portuguese translation Sergio Marques @@ -525,7 +536,7 @@ $Id$ ----------------- * Asturian Xandru Armesto - Mikel González + Mikel Gonz�lez * Localization Updates: --------------------- @@ -533,7 +544,7 @@ $Id$ Samuel Murray (Groenkloof) * German translation - Burkhard Lück + Burkhard L�ck * Greek translation: Yannis Papatzikos @@ -546,7 +557,7 @@ $Id$ Alesis Novik * Slovakian translation - Peter Tuhársky + Peter Tuh�rsky * Spanish translation Gabriel Gazzan @@ -721,7 +732,7 @@ $Id$ Edmund GRIMLEY EVANS * Faroese translation - Lis Gøthe í Jákupsstovu + Lis G�the � J�kupsstovu * Finnish translation Jorma Karvonen @@ -1022,7 +1033,7 @@ $Id$ Jacques Chion * German translation - Burkhard Lück + Burkhard L�ck * Gujarati translation Kartik Mistry @@ -1042,7 +1053,7 @@ $Id$ * Norwegian Nynorsk translation Karl Ove Hufthammer - * Norwegian Bokmål translation + * Norwegian Bokm�l translation Karl Ove Hufthammer * Polish translation @@ -1368,7 +1379,7 @@ $Id$ Freek de Kruijf * Faroese - Lis Gøthe í Jákupsstovu + Lis G�the � J�kupsstovu * Gujarati Kartik Mistry @@ -1524,7 +1535,7 @@ $Id$ Khalid Al Holan * Faroese - Lis Gøthe í Jákupsstovu + Lis G�the � J�kupsstovu * Gujarati -- includes "gu.ttf" font Kartik Mistry @@ -1578,7 +1589,7 @@ $Id$ Leandro Regueiro * German - Burkhard Lück + Burkhard L�ck * Greek Sokratis Sofianopoulos @@ -1612,7 +1623,7 @@ $Id$ * Spanish Pablo Pita - Gabriel Gazzán + Gabriel Gazz�n * Thai Ouychai Chaita @@ -2097,7 +2108,7 @@ $Id$ * Mentioned Tux Paint Config. tool in FAQ. * French documentation created. - Jérôme Chantreau + J�r�me Chantreau * New translations: ----------------- @@ -2133,7 +2144,7 @@ $Id$ * Mexican Spanish Ignacio Tike Daniel Illingworth - Luis C. Suárez M. + Luis C. Su�rez M. * Swahili Martin Benjamin @@ -2171,7 +2182,7 @@ $Id$ * German Patrick - Burkhard Lück + Burkhard L�ck * Greek The Greek Linux i18n Team @@ -2206,11 +2217,11 @@ $Id$ Eugene Zelenko * Spanish and Spanish documentation. - Gabriel Gazzán + Gabriel Gazz�n * Swedish Magnus Dahl - Tomas Skäre + Tomas Sk�re * Vietnamese Clytie Siddall @@ -2352,7 +2363,7 @@ $Id$ Pere Pujal Carabantes * Updated Danish translation. - Mogens Jæger + Mogens J�ger * Updated Dutch translation. Geert Stams @@ -2367,7 +2378,7 @@ $Id$ Roland Illig * Updated Hungarian translation. - Török Gábor + T�r�k G�bor * Updated Icelandic translation. Pjetur G. Hjaltason @@ -2403,7 +2414,7 @@ $Id$ Andrej Kacian * Updated Spanish translation. - Gabriel Gazzán + Gabriel Gazz�n * Updated Tamil translation. Muguntharaj @@ -2809,7 +2820,7 @@ $Id$ TOYAMA Shin-ichi * Added support for some useful HTML escape sequences in stamp descriptions - (e.g., "´" for "á" ("a" with "'" over it)) + (e.g., "´" for "�" ("a" with "'" over it)) Append ".esc" to the locale code (e.g., "fr.esc=...") in the ".txt" description files. @@ -3011,7 +3022,7 @@ $Id$ Karl Ove Hufthammer * Translated to Hungarian. - Török Gábor + T�r�k G�bor * Partly translated to Korean. PO file in an unusable charset, though... Mark K. Kim diff --git a/src/fonts.c b/src/fonts.c index c65e622ae..e1e155088 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -428,6 +428,7 @@ static void reliable_read(int fd, void *buf, size_t count) while (count); } +#endif static void groupfonts_range(style_info ** base, int count) { @@ -931,7 +932,7 @@ static void loadfonts(SDL_Surface * screen, const char *const dir) } -static int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale) +/* static */ int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale) { char *homedirdir; @@ -991,7 +992,7 @@ static int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict } - +#ifdef FORKED_FONTS void run_font_scanner(SDL_Surface * screen, const char *restrict const locale) { diff --git a/src/fonts.h b/src/fonts.h index 54db77140..5fa9c6816 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -56,6 +56,9 @@ * Move into 'fonts.c' and the code in 'tuxpaint.c' * that uses this lot should be put into 'fonts.c' as well. */ + +#ifdef NO_SDLPANGO +/* Only kill SDL_thread stuff when we're not using Pango, because we need it to let fontconfig make its cache (takes a long time the first time) -bjk 2010.04.27 */ #define SDL_CreateThread(fn,vp) (void*)(long)(fn(vp)) #define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0) #define SDL_Thread int @@ -66,6 +69,8 @@ #define SDL_mutexV(lock) // release lock #endif +#endif + extern SDL_Thread *font_thread; extern volatile long font_thread_done; @@ -188,4 +193,6 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size); void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color); #endif +int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale); + #endif diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 669a85a2d..3c960b72b 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - March 22, 2010 + June 14, 2002 - April 27, 2010 */ @@ -95,6 +95,7 @@ #define COLORSEL_CLOBBER_WIPE 8 /* draw the (greyed out) colors, but don't disable */ #define COLORSEL_FORCE_REDRAW 16 /* enable, and force redraw (to make color picker work) */ +/* FIXME: Why are we checking this BEFORE the #include "SDL.h"!? Does this even work? -bjk 2010.04.24 */ /* Setting the amask value based on endianness*/ #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define TPAINT_AMASK 0xff000000 @@ -318,6 +319,7 @@ extern WrapperData macosx; #include #include "SDL.h" +#include "SDL_thread.h" #if !defined(_SDL_H) #error "---------------------------------------------------" #error "If you installed SDL from a package, be sure to get" @@ -6749,6 +6751,65 @@ static int load_user_fonts_stub(void *vp) } #endif +#ifndef NO_SDLPANGO +volatile long fontconfig_thread_done = 0; + +int generate_fontconfig_cache_spinner(SDL_Surface * screen) +{ + SDL_Event event; + + while (fontconfig_thread_done == 0) { + show_progress_bar(screen); + SDL_Flip(screen); + SDL_Delay(20); + + while (SDL_PollEvent(&event) > 0) { + if (event.type == SDL_QUIT || + (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) { + printf("Aborting!\n"); fflush(stdout); + return(1); + } + } + } + return(0); +} + +static int generate_fontconfig_cache_real(void) +{ + TuxPaint_Font * tmp_font; + SDL_Surface * tmp_surf; + SDL_Color black = { 0, 0, 0, 0 }; + + printf("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID()); fflush(stdout); + + tmp_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, NULL, 12); + + if (tmp_font != NULL) + { + printf("-- Generated a font.\n"); fflush(stdout); + tmp_surf = render_text(tmp_font, "Test", black); + if (tmp_surf != NULL) { + printf("-- Generated a surface\n"); fflush(stdout); + SDL_FreeSurface(tmp_surf); + } else { + printf("-- Failed to make a surface!\n"); fflush(stdout); + } + TuxPaint_Font_CloseFont(tmp_font); + } else { + printf("-- Failed to generate a font!\n"); fflush(stdout); + } + + fontconfig_thread_done = 1; + + printf("-- generate_fontconfig_cache() is done\n"); fflush(stdout); + return(0); +} + +static int generate_fontconfig_cache(void *vp) +{ + return generate_fontconfig_cache_real(); +} +#endif #define hex2dec(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \ ((c) >= 'A' && (c) <= 'F') ? ((c) - 'A' + 10) : \ @@ -20612,6 +20673,7 @@ static void do_lock_file(void) free(lock_fname); } + ///////////////////////////////////////////////////////////////////////////// static void setup(void) { @@ -20636,7 +20698,9 @@ static void setup(void) Uint32(*getpixel_tmp_btn_down) (SDL_Surface *, int, int); Uint32(*getpixel_img_paintwell) (SDL_Surface *, int, int); int big_title; - +#ifndef NO_SDLPANGO + SDL_Thread * fontconfig_thread; +#endif @@ -20911,6 +20975,74 @@ static void setup(void) SDL_Flip(screen); + +#if defined(WIN32) && defined(LARGE_CURSOR_FULLSCREEN_BUG) + if (fullscreen && no_fancy_cursors == 0) + { + fprintf(stderr, "Warning: An SDL bug causes the fancy cursors to leave\n" + "trails in fullscreen mode. Disabling fancy cursors.\n" + "(You can do this yourself with 'nofancycursors' option,\n" + "to avoid this warning in the future.)\n"); + no_fancy_cursors = 1; + } +#endif + + + /* Create cursors: */ + + scale = 1; + +#ifdef SMALL_CURSOR_SHAPES + scale = 2; +#endif + +#ifdef __APPLE__ + cursor_arrow = SDL_GetCursor(); /* use standard system cursor */ +#endif + + /* this one first, because we need it yesterday */ + cursor_watch = get_cursor(watch_bits, watch_mask_bits, + watch_width, watch_height, + 14 / scale, 14 / scale); + + do_setcursor(cursor_watch); + show_progress_bar(screen); + + + + +#ifndef NO_SDLPANGO + /* Let Pango & fontcache do their work without locking up */ + + fontconfig_thread_done = 0; + + printf("Spawning Pango thread\n"); fflush(stdout); + + fontconfig_thread = SDL_CreateThread(generate_fontconfig_cache, NULL); + if (fontconfig_thread == NULL) { + fprintf(stderr, "Failed to create Pango setup thread: %s\n", SDL_GetError()); + } else { + printf("Thread spawned\n"); fflush(stdout); + if (generate_fontconfig_cache_spinner(screen)) /* returns 1 if aborted */ + { + printf("Aborted!\n"); fflush(stdout); + SDL_KillThread(fontconfig_thread); + SDL_Quit(); + exit(0); + /* FIXME: Let's be more graceful about exiting (e.g., clean up lockfile!) -bjk 2010.04.27 */ + } + printf("Done generating cache\n"); fflush(stdout); + } + + +#ifdef FORKED_FONTS + /* NOW we can fork our own font scanner stuff, and let it run in the bgkd -bjk 2010.04.27 */ + printf("Now running font scanner\n"); fflush(stdout); + run_font_scanner(screen, lang_prefixes[get_current_language()]); +#endif + +#endif + medium_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, DATA_PREFIX "fonts/default_font.ttf", 18 - (only_uppercase * 3)); @@ -20950,38 +21082,6 @@ static void setup(void) SDL_Flip(screen); -#if defined(WIN32) && defined(LARGE_CURSOR_FULLSCREEN_BUG) - if (fullscreen && no_fancy_cursors == 0) - { - fprintf(stderr, "Warning: An SDL bug causes the fancy cursors to leave\n" - "trails in fullscreen mode. Disabling fancy cursors.\n" - "(You can do this yourself with 'nofancycursors' option,\n" - "to avoid this warning in the future.)\n"); - no_fancy_cursors = 1; - } -#endif - - - /* Create cursors: */ - - scale = 1; - -#ifdef SMALL_CURSOR_SHAPES - scale = 2; -#endif - -#ifdef __APPLE__ - cursor_arrow = SDL_GetCursor(); /* use standard system cursor */ -#endif - - /* this one first, because we need it yesterday */ - cursor_watch = get_cursor(watch_bits, watch_mask_bits, - watch_width, watch_height, - 14 / scale, 14 / scale); - - do_setcursor(cursor_watch); - show_progress_bar(screen); - #ifdef FORKED_FONTS reliable_write(font_socket_fd, &no_system_fonts, sizeof no_system_fonts); #else @@ -21631,10 +21731,19 @@ int main(int argc, char *argv[]) chdir_to_binary(argv[0]); setup_config(argv); + + + CLOCK_ASM(time2); #ifdef FORKED_FONTS // must start ASAP, but depends on locale which in turn needs the config +#ifdef NO_SDLPANGO + /* Only fork it now if we're not planning on creating a thread to handle fontconfig stuff -bjk 2010.04.27 */ + printf("Running font scanner\n"); fflush(stdout); run_font_scanner(screen, lang_prefixes[get_current_language()]); +#else + printf("NOT running font scanner\n"); fflush(stdout); +#endif #endif /* Set up! */