diff --git a/Makefile b/Makefile index 91d2dfaab..10daa535f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ # bill@newbreedsoftware.com # http://www.tuxpaint.org/ -# June 14, 2002 - June 12, 2007 +# June 14, 2002 - June 24, 2007 # The version number, for release: @@ -110,6 +110,8 @@ SVG_CFLAGS=-I/usr/include/librsvg-2/librsvg \ -I/usr/lib/glib-2.0/include \ -I/usr/include/cairo +PAPER_LIB=-lpaper + # The entire set of CFLAGS: @@ -701,10 +703,12 @@ install-man: tuxpaint: obj/tuxpaint.o obj/i18n.o obj/im.o obj/cursor.o obj/pixels.o \ obj/floodfill.o obj/rgblinear.o obj/playsound.o obj/fonts.o \ obj/progressbar.o obj/dirwalk.o obj/get_fname.o \ + obj/postscript_print.o \ $(HQXX_O) $(ARCH_LIBS) @echo @echo "...Linking Tux Paint..." - @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ + @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(PAPER_CFLAGS) \ + $(DEFS) \ -o tuxpaint \ $^ \ $(HQXX_O) \ @@ -831,6 +835,13 @@ obj/win32_print.o: src/win32_print.c obj src/win32_print.h src/debug.h @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ -c src/win32_print.c -o obj/win32_print.o +obj/postscript_print.o: src/postscript_print.c obj \ + src/postscript_print.h src/debug.h + @echo + @echo "...Compoling PostScript print support..." + @$(CC) $(CFLGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ + -c src/postscript_print.c -o obj/postscript_print.o + obj/resource.o: visualc/resources.rc obj visualc/resource.h @echo @echo "...Compiling win32 resources..." diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 707546265..de5050740 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/ $Id$ -2007.June.21 (0.9.17) +2007.June.24 (0.9.17) * Interface Improvements: ----------------------- @@ -107,6 +107,9 @@ $Id$ resolution. Either use both "fullscreen=yes" and "native=yes" in the config file, or "--fullscreen --native" on the command-line. + * Split PostScript printing code (for Linux/Unix/etc.) into its own + source file. (Mac OS X, Windows and BeOS all had their own.) + * Documentation Improvements: --------------------------- * Discussed SVG Stamps in "Extending Tux Paint." diff --git a/src/postscript_print.c b/src/postscript_print.c new file mode 100644 index 000000000..eb8371cfc --- /dev/null +++ b/src/postscript_print.c @@ -0,0 +1,103 @@ + +#include +#include +#include +#include +#include +#include "postscript_print.h" +#include "pixels.h" + +///////////////////////////////////// PostScript printing /////////// +#ifdef PRINTMETHOD_PS + +/* Actually save the PostScript data to the file stream: */ +int do_ps_save(FILE * fi, + // const char *restrict const fname, + const char * fname, + SDL_Surface * surf) +{ + unsigned char * /* restrict const */ ps_row = malloc(surf->w * 3); + int x, y; + char buf[256]; + Uint32(*getpixel) (SDL_Surface *, int, int) = + getpixels[surf->format->BytesPerPixel]; + time_t t = time(NULL); + + fprintf(fi, "%%!PS-Adobe-3.0 EPSF-3.0\n"); // probably broken, but close enough maybe + fprintf(fi, "%%%%Title: (%s)\n", fname); + strftime(buf, sizeof buf - 1, "%a %b %e %H:%M:%S %Y", localtime(&t)); + fprintf(fi, "%%%%CreationDate: (%s)\n", buf); + fprintf(fi, "%%%%Creator: (Tux Paint " VER_VERSION ", " VER_DATE ")\n"); + fprintf(fi, "%%%%LanguageLevel: 2\n"); +// fprintf(fi, "%%%%BoundingBox: 72 214 540 578\n"); // doubt we have the needed info + fprintf(fi, "%%%%DocumentData: Binary\n"); + fprintf(fi, "%%%%EndComments\n"); + fprintf(fi, "\n"); + fprintf(fi, "gsave\n"); + fprintf(fi, "\n"); + + if (surf->w > surf->h) + fprintf(fi, "90 rotate\n"); // landscape mode + + fprintf(fi, "%% First, grab the page size.\n"); + fprintf(fi, "gsave\n"); + fprintf(fi, " clippath\n"); + fprintf(fi, " pathbbox\n"); + fprintf(fi, "grestore\n"); + fprintf(fi, "/ury exch def\n"); + fprintf(fi, "/urx exch def\n"); + fprintf(fi, "/lly exch def\n"); + fprintf(fi, "/llx exch def\n"); + fprintf(fi, "\n"); + fprintf(fi, "llx lly translate\n"); + fprintf(fi, "\n"); + fprintf(fi, "/width %u def\n", surf->w); + fprintf(fi, "/height %u def\n", surf->h); + fprintf(fi, "width height scale\n"); + fprintf(fi, "\n"); + fprintf(fi, "urx llx sub width div\n"); + fprintf(fi, "ury lly sub height div\n"); + fprintf(fi, "%% now do a 'min' operation\n"); + fprintf(fi, "2 copy gt { exch } if pop\n"); + fprintf(fi, "\n"); + fprintf(fi, "dup scale\n"); + fprintf(fi, "/DeviceRGB setcolorspace\n"); + fprintf(fi, "<<\n"); + fprintf(fi, " /ImageType 1\n"); + fprintf(fi, " /Width width /Height height\n"); + fprintf(fi, " /BitsPerComponent 8\n"); + fprintf(fi, " /ImageMatrix [width 0 0 height neg 0 height]\n"); + fprintf(fi, " /Decode [0 1 0 1 0 1]\n"); + fprintf(fi, " /DataSource currentfile\n"); + fprintf(fi, ">>\n"); + fprintf(fi, "%%%%BeginData: %u Binary Bytes\n", surf->w * surf->h * 3u); + fprintf(fi, "image\n"); + + /* Save the picture: */ + for (y = 0; y < surf->h; y++) + { + for (x = 0; x < surf->w; x++) + { + Uint8 r, g, b; + SDL_GetRGB(getpixel(surf, x, y), surf->format, &r, &g, &b); + ps_row[x * 3 + 0] = r; + ps_row[x * 3 + 1] = g; + ps_row[x * 3 + 2] = b; + } + fwrite(ps_row, surf->w, 3, fi); + } + free(ps_row); + + fprintf(fi, "\n"); + fprintf(fi, "%%%%EndData\n"); + fprintf(fi, "grestore\n"); + fprintf(fi, "showpage\n"); + fprintf(fi, "%%%%EOF\n"); + + fclose(fi); + return 1; +} + +#endif +///////////////////////////////////////////////////////////////// + diff --git a/src/postscript_print.h b/src/postscript_print.h new file mode 100644 index 000000000..b096d7e7c --- /dev/null +++ b/src/postscript_print.h @@ -0,0 +1,53 @@ +/* + postscript_print.h + +*/ + +#ifndef POSTSCRIPT_PRINT_H +#define POSTSCRIPT_PRINT_H + +#include +#include "SDL.h" + + +/* Method for printing images: */ + +#define PRINTMETHOD_PS /* Direct to PostScript */ +//#define PRINTMETHOD_PNM_PS /* Output PNM, assuming it gets printed */ +//#define PRINTMETHOD_PNG_PNM_PS /* Output PNG, assuming it gets printed */ + + + +/* Default print and alt-print command, depending on the print method: */ + +#define DEFAULT_PRINTCOMMAND "lpr" +#define DEFAULT_ALTPRINTCOMMAND "kprinter" + +#ifdef PRINTMETHOD_PNG_PNM_PS +#define PRINTCOMMAND "pngtopnm | pnmtops | " DEFAULT_PRINTCOMMAND +#elif defined(PRINTMETHOD_PNM_PS) +#define PRINTCOMMAND "pnmtops | " DEFAULT_PRINTCOMMAND +#elif defined(PRINTMETHOD_PS) +#define PRINTCOMMAND DEFAULT_PRINTCOMMAND +#else +#error No print method defined! +#endif + +#ifdef PRINTMETHOD_PNG_PNM_PS +#define ALTPRINTCOMMAND "pngtopnm | pnmtops | " DEFAULT_ALTPRINTCOMMAND +#elif defined(PRINTMETHOD_PNM_PS) +#define ALTPRINTCOMMAND "pnmtops | " DEFAULT_ALTPRINTCOMMAND +#elif defined(PRINTMETHOD_PS) +#define ALTPRINTCOMMAND DEFAULT_ALTPRINTCOMMAND +#else +#error No alt print method defined! +#endif + + +int do_ps_save(FILE * fi, + // const char *restrict const fname, + const char *fname, + SDL_Surface * surf); + +#endif /* POSTSCRIPT_PRINT_H */ + diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 64af1d4b9..9f4823c58 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 - June 21, 2007 + June 14, 2002 - June 24, 2007 $Id$ */ @@ -48,6 +48,9 @@ #endif +//#define CORNER_SHAPES /* need major work! */ + + /* Method for printing images: */ #define PRINTMETHOD_PS /* Direct to PostScript */ @@ -55,33 +58,6 @@ //#define PRINTMETHOD_PNG_PNM_PS /* Output PNG, assuming it gets printed */ -//#define CORNER_SHAPES /* need major work! */ - -/* Default print and alt-print command, depending on the print method: */ - -#define DEFAULT_PRINTCOMMAND "lpr" -#define DEFAULT_ALTPRINTCOMMAND "kprinter" - -#ifdef PRINTMETHOD_PNG_PNM_PS -#define PRINTCOMMAND "pngtopnm | pnmtops | " DEFAULT_PRINTCOMMAND -#elif defined(PRINTMETHOD_PNM_PS) -#define PRINTCOMMAND "pnmtops | " DEFAULT_PRINTCOMMAND -#elif defined(PRINTMETHOD_PS) -#define PRINTCOMMAND DEFAULT_PRINTCOMMAND -#else -#error No print method defined! -#endif - -#ifdef PRINTMETHOD_PNG_PNM_PS -#define ALTPRINTCOMMAND "pngtopnm | pnmtops | " DEFAULT_ALTPRINTCOMMAND -#elif defined(PRINTMETHOD_PNM_PS) -#define ALTPRINTCOMMAND "pnmtops | " DEFAULT_ALTPRINTCOMMAND -#elif defined(PRINTMETHOD_PS) -#define ALTPRINTCOMMAND DEFAULT_ALTPRINTCOMMAND -#else -#error No alt print method defined! -#endif - #define MAX_PATH 256 @@ -269,10 +245,17 @@ char *strcasestr(const char *haystack, const char *needle) #include #ifndef WIN32 + +/* Not Windows: */ + #include #include #include + #ifdef __BEOS__ + +/* BeOS */ + #include "BeOS_print.h" // workaround dirent handling bug in TuxPaint code typedef struct safer_dirent @@ -285,13 +268,32 @@ typedef struct safer_dirent char d_name[NAME_MAX]; } safer_dirent; #define dirent safer_dirent -#endif + +#else /* __BEOS__ */ + +/* Not BeOS */ + #ifdef __APPLE__ + +/* Apple */ + #include "macosx_print.h" #include "wrapperdata.h" extern WrapperData macosx; -#endif -#else + +#else /* __APPLE__ */ + +/* Not Windows, not BeOS, not Apple */ + +#include "postscript_print.h" + +#endif /* __APPLE__ */ + +#endif /* __BEOS__ */ + +#else /* WIN32 */ + +/* Windows */ #include #include @@ -12580,95 +12582,6 @@ static int do_png_save(FILE * fi, const char *const fname, SDL_Surface * surf) return 0; } -///////////////////////////////////// PostScript printing /////////// -#ifdef PRINTMETHOD_PS - -/* Actually save the PostScript data to the file stream: */ -static int do_ps_save(FILE * fi, const char *restrict const fname, - SDL_Surface * surf) -{ - unsigned char *restrict const ps_row = malloc(surf->w * 3); - int x, y; - char buf[256]; - Uint32(*getpixel) (SDL_Surface *, int, int) = - getpixels[surf->format->BytesPerPixel]; - time_t t = time(NULL); - - fprintf(fi, "%%!PS-Adobe-3.0 EPSF-3.0\n"); // probably broken, but close enough maybe - fprintf(fi, "%%%%Title: (%s)\n", fname); - strftime(buf, sizeof buf - 1, "%a %b %e %H:%M:%S %Y", localtime(&t)); - fprintf(fi, "%%%%CreationDate: (%s)\n", buf); - fprintf(fi, "%%%%Creator: (Tux Paint " VER_VERSION ", " VER_DATE ")\n"); - fprintf(fi, "%%%%LanguageLevel: 2\n"); -// fprintf(fi, "%%%%BoundingBox: 72 214 540 578\n"); // doubt we have the needed info - fprintf(fi, "%%%%DocumentData: Binary\n"); - fprintf(fi, "%%%%EndComments\n"); - fprintf(fi, "\n"); - fprintf(fi, "gsave\n"); - fprintf(fi, "\n"); -// fprintf(fi, "90 rotate\n"); // landscape mode - fprintf(fi, "%% First, grab the page size.\n"); - fprintf(fi, "gsave\n"); - fprintf(fi, " clippath\n"); - fprintf(fi, " pathbbox\n"); - fprintf(fi, "grestore\n"); - fprintf(fi, "/ury exch def\n"); - fprintf(fi, "/urx exch def\n"); - fprintf(fi, "/lly exch def\n"); - fprintf(fi, "/llx exch def\n"); - fprintf(fi, "\n"); - fprintf(fi, "llx lly translate\n"); - fprintf(fi, "\n"); - fprintf(fi, "/width %u def\n", surf->w); - fprintf(fi, "/height %u def\n", surf->h); - fprintf(fi, "width height scale\n"); - fprintf(fi, "\n"); - fprintf(fi, "urx llx sub width div\n"); - fprintf(fi, "ury lly sub height div\n"); - fprintf(fi, "%% now do a 'min' operation\n"); - fprintf(fi, "2 copy gt { exch } if pop\n"); - fprintf(fi, "\n"); - fprintf(fi, "dup scale\n"); - fprintf(fi, "/DeviceRGB setcolorspace\n"); - fprintf(fi, "<<\n"); - fprintf(fi, " /ImageType 1\n"); - fprintf(fi, " /Width width /Height height\n"); - fprintf(fi, " /BitsPerComponent 8\n"); - fprintf(fi, " /ImageMatrix [width 0 0 height neg 0 height]\n"); - fprintf(fi, " /Decode [0 1 0 1 0 1]\n"); - fprintf(fi, " /DataSource currentfile\n"); - fprintf(fi, ">>\n"); - fprintf(fi, "%%%%BeginData: %u Binary Bytes\n", surf->w * surf->h * 3u); - fprintf(fi, "image\n"); - - /* Save the picture: */ - for (y = 0; y < surf->h; y++) - { - for (x = 0; x < surf->w; x++) - { - Uint8 r, g, b; - SDL_GetRGB(getpixel(surf, x, y), surf->format, &r, &g, &b); - ps_row[x * 3 + 0] = r; - ps_row[x * 3 + 1] = g; - ps_row[x * 3 + 2] = b; - } - fwrite(ps_row, surf->w, 3, fi); - } - free(ps_row); - - fprintf(fi, "\n"); - fprintf(fi, "%%%%EndData\n"); - fprintf(fi, "grestore\n"); - fprintf(fi, "showpage\n"); - fprintf(fi, "%%%%EOF\n"); - - fclose(fi); - return 1; -} - -#endif -///////////////////////////////////////////////////////////////// - /* Pick a new file ID: */ static void get_new_file_id(void) {