Added support for building on a Windows system using MinGW/MSYS.

After building and installing all the dependencies I used these commands,
in MSYS, to build, install and run:

    export set CPATH=/usr/local/include
    export set LIBRARY_PATH=/usr/local/bin:/usr/local/lib
    make win32
    make install-win32
    tuxpaint
This commit is contained in:
John Popplewell 2005-02-26 02:26:40 +00:00
parent e1ce8e1ddb
commit 778bd2f897
4 changed files with 264 additions and 252 deletions

167
Makefile
View file

@ -22,6 +22,7 @@ PKG_ROOT=
# Program:
BIN_PREFIX=$(PKG_ROOT)/$(PREFIX)/bin
EXE_EXT=
# Data:
@ -144,6 +145,22 @@ beos:
ARCH_HEADERS="src/BeOS_Print.h" \
ARCH_LIBS="obj/BeOS_print.o"
# "make win32" builds the program for Windows using MinGW/MSYS
win32:
make \
PREFIX=/usr/local \
BIN_PREFIX=$(PREFIX)/bin \
EXE_EXT=.exe \
DATA_PREFIX=$(PREFIX)/share/tuxpaint/ \
DOC_PREFIX=$(PREFIX)/share/doc/tuxpaint/ \
MAN_PREFIX=$(PREFIX)/share/man/ \
ICON_PREFIX=./ \
X11_ICON_PREFIX=./ \
LOCALE_PREFIX=$(PREFIX)/share/locale/ \
CONFDIR=$(PREFIX)/etc/tuxpaint \
ARCH_LINKS="-lintl-3 -lpng12 -lwinspool" \
ARCH_HEADERS="src/win32_print.h" \
ARCH_LIBS="obj/win32_print.o"
# "make install" installs all of the various parts
# (depending on the *PREFIX variables at the top, you probably need
@ -172,6 +189,30 @@ install: install-bin install-data install-man install-doc \
@echo
# "make private-win32" installs all of the various parts for MinGW
install-private-win32: install-bin install-data install-man install-doc \
install-icon install-gettext install-importscript \
install-default-config install-example-stamps \
install-example-starters
@echo
@echo "--------------------------------------------------------------"
@echo
@echo "All done!"
@echo "Now you can type the command 'tuxpaint' to run the program!!!"
@echo
@echo "For more information, see the 'tuxpaint' man page,"
@echo "run 'tuxpaint --usage' or see $(DOC_PREFIX)README.txt"
@echo
@echo "Visit Tux Paint's home page for more information, updates"
@echo "and to learn how you can help out!"
@echo
@echo " http://www.newbreedsoftware.com/tuxpaint/"
@echo
@echo "Enjoy!"
@echo
# "make install-beos" installs Tux Paint, but using BeOS settings
install-beos:
@ -182,7 +223,7 @@ install-beos:
DOC_PREFIX=./docs/ \
MAN_PREFIX=./src/ \
CONFDIR=./src/ \
ICON_PREFIX=./
ICON_PREFIX=./ \
X11_ICON_PREFIX=./ \
LOCALE_PREFIX=/boot/home/config/share/locale/ \
CFLAGS="-O1 -funroll-loops -fomit-frame-pointer -pipe -Wall" \
@ -192,6 +233,22 @@ install-beos:
ARCH_HEADERS="src/BeOS_Print.h" \
ARCH_LIBS="obj/BeOS_print.o"
# "make install-win32" installs Tux Paint, but using MinGW/MSYS settings
install-win32:
make install-private-win32 \
PREFIX=/usr/local \
BIN_PREFIX=$(PREFIX)/bin \
EXE_EXT=.exe \
DATA_PREFIX=$(PREFIX)/share/tuxpaint/ \
DOC_PREFIX=$(PREFIX)/share/doc/tuxpaint/ \
MAN_PREFIX=$(PREFIX)/share/man/ \
ICON_PREFIX=./ \
X11_ICON_PREFIX=./ \
LOCALE_PREFIX=$(PREFIX)/share/locale/ \
CONFDIR=$(PREFIX)/etc/tuxpaint \
ARCH_LINKS="-lintl-3 -lpng12 -lwinspool" \
ARCH_HEADERS="src/win32_print.h" \
ARCH_LIBS="obj/win32_print.o"
# "make clean" deletes the program, the compiled objects and the
# built man page (returns to factory archive, pretty much...)
@ -421,7 +478,7 @@ install-bin:
@echo "...Installing program itself..."
@install -d $(BIN_PREFIX)
@cp tuxpaint $(BIN_PREFIX)
@chmod a+rx,g-w,o-w $(BIN_PREFIX)/tuxpaint
@chmod a+rx,g-w,o-w $(BIN_PREFIX)/tuxpaint$(EXE_EXT)
# Install the import script:
@ -779,6 +836,12 @@ obj/BeOS_Print.o: src/BeOS_Print.cpp obj src/BeOS_print.h
@$(CC) $(CFLAGS) $(SDL_CFLAGS) $(DEFS) \
-c src/BeOS_print.cpp -o obj/BeOS_print.o
obj/win32_print.o: src/win32_print.c obj src/win32_print.h
@echo
@echo "...Compiling win32 print support..."
@$(CC) $(CFLAGS) $(SDL_CFLAGS) $(DEFS) \
-c src/win32_print.c -o obj/win32_print.o
# Build the translation files for gettext
@ -841,203 +904,203 @@ trans:
trans/af.mo: src/po/af.po
@echo " af_ZA ...Afrikaans..."
@msgfmt src/po/af.po -o trans/af.mo
@msgfmt -o trans/af.mo src/po/af.po
trans/be.mo: src/po/be.po
@echo " be_BY ...Belarusian..."
@msgfmt src/po/be.po -o trans/be.mo
@msgfmt -o trans/be.mo src/po/be.po
trans/bg.mo: src/po/bg.po
@echo " bg_BG ...Bulgarian..."
@msgfmt src/po/bg.po -o trans/bg.mo
@msgfmt -o trans/bg.mo src/po/bg.po
trans/br.mo: src/po/br.po
@echo " br_FR ...Breton..."
@msgfmt src/po/br.po -o trans/br.mo
@msgfmt -o trans/br.mo src/po/br.po
trans/ca.mo: src/po/ca.po
@echo " ca_ES ...Catalan..."
@msgfmt src/po/ca.po -o trans/ca.mo
@msgfmt -o trans/ca.mo src/po/ca.po
trans/cy.mo: src/po/cy.po
@echo " cy_GB ...Welsh..."
@msgfmt src/po/cy.po -o trans/cy.mo
@msgfmt -o trans/cy.mo src/po/cy.po
trans/cs.mo: src/po/cs.po
@echo " cs_CZ ...Czech..."
@msgfmt src/po/cs.po -o trans/cs.mo
@msgfmt -o trans/cs.mo src/po/cs.po
trans/da.mo: src/po/da.po
@echo " da_DK ...Danish..."
@msgfmt src/po/da.po -o trans/da.mo
@msgfmt -o trans/da.mo src/po/da.po
trans/de.mo: src/po/de.po
@echo " de_DE ...German..."
@msgfmt src/po/de.po -o trans/de.mo
@msgfmt -o trans/de.mo src/po/de.po
trans/et.mo: src/po/et.po
@echo " et_EE ...Estonian..."
@msgfmt src/po/et.po -o trans/et.mo
@msgfmt -o trans/et.mo src/po/et.po
trans/el.mo: src/po/el.po
@echo " el_GR ...Greek..."
@msgfmt src/po/el.po -o trans/el.mo
@msgfmt -o trans/el.mo src/po/el.po
trans/en_gb.mo: src/po/en_gb.po
@echo " en_GB ...British English..."
@msgfmt src/po/en_gb.po -o trans/en_gb.mo
@msgfmt -o trans/en_gb.mo src/po/en_gb.po
trans/es.mo: src/po/es.po
@echo " es_ES ...Spanish..."
@msgfmt src/po/es.po -o trans/es.mo
@msgfmt -o trans/es.mo src/po/es.po
trans/eu.mo: src/po/eu.po
@echo " eu_ES ...Basque..."
@msgfmt src/po/eu.po -o trans/eu.mo
@msgfmt -o trans/eu.mo src/po/eu.po
trans/fi.mo: src/po/fi.po
@echo " fi_FI ...Finnish..."
@msgfmt src/po/fi.po -o trans/fi.mo
@msgfmt -o trans/fi.mo src/po/fi.po
trans/fr.mo: src/po/fr.po
@echo " fr_FR ...French..."
@msgfmt src/po/fr.po -o trans/fr.mo
@msgfmt -o trans/fr.mo src/po/fr.po
trans/ga.mo: src/po/ga.po
@echo " ga_IE ...Gaelic..."
@msgfmt src/po/ga.po -o trans/ga.mo
@msgfmt -o trans/ga.mo src/po/ga.po
trans/gl.mo: src/po/gl.po
@echo " gl_ES ...Galician..."
@msgfmt src/po/gl.po -o trans/gl.mo
@msgfmt -o trans/gl.mo src/po/gl.po
trans/he.mo: src/po/he.po
@echo " he_IL ...Hebrew..."
@msgfmt src/po/he.po -o trans/he.mo
@msgfmt -o trans/he.mo src/po/he.po
trans/hi.mo: src/po/hi.po
@echo " hi_IN ...Hindi..."
@msgfmt src/po/hi.po -o trans/hi.mo
@msgfmt -o trans/hi.mo src/po/hi.po
trans/hr.mo: src/po/hr.po
@echo " hr_HR ...Croatian..."
@msgfmt src/po/hr.po -o trans/hr.mo
@msgfmt -o trans/hr.mo src/po/hr.po
trans/hu.mo: src/po/hu.po
@echo " hu_HU ...Hungarian..."
@msgfmt src/po/hu.po -o trans/hu.mo
@msgfmt -o trans/hu.mo src/po/hu.po
trans/tlh.mo: src/po/tlh.po
@echo " tlh ...Klingon (Romanized)..."
@msgfmt src/po/tlh.po -o trans/tlh.mo
@msgfmt -o trans/tlh.mo src/po/tlh.po
trans/id.mo: src/po/id.po
@echo " id_ID ...Indonesian..."
@msgfmt src/po/id.po -o trans/id.mo
@msgfmt -o trans/id.mo src/po/id.po
trans/is.mo: src/po/is.po
@echo " is_IS ...Icelandic..."
@msgfmt src/po/is.po -o trans/is.mo
@msgfmt -o trans/is.mo src/po/is.po
trans/it.mo: src/po/it.po
@echo " it_IT ...Italian..."
@msgfmt src/po/it.po -o trans/it.mo
@msgfmt -o trans/it.mo src/po/it.po
trans/ja.mo: src/po/ja.po
@echo " ja_JP ...Japanese..."
@msgfmt src/po/ja.po -o trans/ja.mo
@msgfmt -o trans/ja.mo src/po/ja.po
trans/ko.mo: src/po/ko.po
@echo " ko_KR ...Korean..."
@msgfmt src/po/ko.po -o trans/ko.mo
@msgfmt -o trans/ko.mo src/po/ko.po
trans/lt.mo: src/po/lt.po
@echo " lt_LT ...Lithuanian..."
@msgfmt src/po/lt.po -o trans/lt.mo
@msgfmt -o trans/lt.mo src/po/lt.po
trans/ms.mo: src/po/ms.po
@echo " ms_MY ...Malay..."
@msgfmt src/po/ms.po -o trans/ms.mo
@msgfmt -o trans/ms.mo src/po/ms.po
trans/nl.mo: src/po/nl.po
@echo " nl_NL ...Dutch..."
@msgfmt src/po/nl.po -o trans/nl.mo
@msgfmt -o trans/nl.mo src/po/nl.po
trans/nb.mo: src/po/nb.po
@echo " nb_NO ...Norwegian Bokmal..."
@msgfmt src/po/nb.po -o trans/nb.mo
@msgfmt -o trans/nb.mo src/po/nb.po
trans/nn.mo: src/po/nn.po
@echo " nn_NO ...Norwegian Nynorsk..."
@msgfmt src/po/nn.po -o trans/nn.mo
@msgfmt -o trans/nn.mo src/po/nn.po
trans/pl.mo: src/po/pl.po
@echo " pl_PL ...Polish..."
@msgfmt src/po/pl.po -o trans/pl.mo
@msgfmt -o trans/pl.mo src/po/pl.po
trans/pt_pt.mo: src/po/pt_pt.po
@echo " pt_PT ...Portuguese..."
@msgfmt src/po/pt_pt.po -o trans/pt_pt.mo
@msgfmt -o trans/pt_pt.mo src/po/pt_pt.po
trans/pt_br.mo: src/po/pt_br.po
@echo " pt_BR ...Brazilian Portuguese..."
@msgfmt src/po/pt_br.po -o trans/pt_br.mo
@msgfmt -o trans/pt_br.mo src/po/pt_br.po
trans/ro.mo: src/po/ro.po
@echo " ro_RO ...Romanian..."
@msgfmt src/po/ro.po -o trans/ro.mo
@msgfmt -o trans/ro.mo src/po/ro.po
trans/ru.mo: src/po/ru.po
@echo " ru_RU ...Russian..."
@msgfmt src/po/ru.po -o trans/ru.mo
@msgfmt -o trans/ru.mo src/po/ru.po
trans/sk.mo: src/po/sk.po
@echo " sk_SK ...Slovak..."
@msgfmt src/po/sk.po -o trans/sk.mo
@msgfmt -o trans/sk.mo src/po/sk.po
trans/sl.mo: src/po/sl.po
@echo " sl_SI ...Slovenian..."
@msgfmt src/po/sl.po -o trans/sl.mo
@msgfmt -o trans/sl.mo src/po/sl.po
trans/sq.mo: src/po/sq.po
@echo " sq_AL ...Albanian..."
@msgfmt src/po/sq.po -o trans/sq.mo
@msgfmt -o trans/sq.mo src/po/sq.po
trans/sr.mo: src/po/sr.po
@echo " sr_YU ...Serbian..."
@msgfmt src/po/sr.po -o trans/sr.mo
@msgfmt -o trans/sr.mo src/po/sr.po
trans/sv.mo: src/po/sv.po
@echo " sv_SE ...Swedish..."
@msgfmt src/po/sv.po -o trans/sv.mo
@msgfmt -o trans/sv.mo src/po/sv.po
trans/sw.mo: src/po/sw.po
@echo " sw_TZ ...Swahili..."
@msgfmt src/po/sw.po -o trans/sw.mo
@msgfmt -o trans/sw.mo src/po/sw.po
trans/ta.mo: src/po/ta.po
@echo " ta_IN ...Tamil..."
@msgfmt src/po/ta.po -o trans/ta.mo
@msgfmt -o trans/ta.mo src/po/ta.po
trans/tr.mo: src/po/tr.po
@echo " tr_TR ...Turkish..."
@msgfmt src/po/tr.po -o trans/tr.mo
@msgfmt -o trans/tr.mo src/po/tr.po
trans/vi.mo: src/po/vi.po
@echo " vi_VN ...Vietnamese..."
@msgfmt src/po/vi.po -o trans/vi.mo
@msgfmt -o trans/vi.mo src/po/vi.po
trans/wa.mo: src/po/wa.po
@echo " wa_BE ...Walloon..."
@msgfmt src/po/wa.po -o trans/wa.mo
@msgfmt -o trans/wa.mo src/po/wa.po
trans/zh_cn.mo: src/po/zh_cn.po
@echo " zh_CN ...Chinese..."
@msgfmt src/po/zh_cn.po -o trans/zh_cn.mo
@msgfmt -o trans/zh_cn.mo src/po/zh_cn.po
trans/zh_tw.mo: src/po/zh_tw.po
@echo " zh_TW ...Chinese..."
@msgfmt src/po/zh_tw.po -o trans/zh_tw.mo
@msgfmt -o trans/zh_tw.mo src/po/zh_tw.po

View file

@ -41,6 +41,9 @@
// plan to rip this out as soon as it is considered stable
//#define THREADED_FONTS
#define FORKED_FONTS
#ifdef WIN32
#undef FORKED_FONTS
#endif
/* Method for printing images: */
@ -159,16 +162,6 @@ static scaleparams scaletable[] = {
#include <wctype.h>
#endif
#ifdef WIN32_OLD
/* The following are required by libintl.h, so must be defined first: */
#define LC_MESSAGES 1729
#define HAVE_LC_MESSAGES 1
#define ENABLE_NLS 1
#define HAVE_LOCALE_H 1
#define HAVE_GETTEXT 1
#define HAVE_DCGETTEXT 1
#endif
#include <libintl.h>
#ifndef gettext_noop
#define gettext_noop(String) String
@ -187,8 +180,6 @@ static scaleparams scaletable[] = {
#include <sys/types.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
@ -211,38 +202,15 @@ typedef struct safer_dirent {
extern WrapperData macosx;
#endif
#else
#include "win32_dirent.h"
#include <unistd.h>
#include <dirent.h>
#include <malloc.h>
#include "win32_print.h"
#include <io.h>
#include <direct.h>
/* Enables win32 apps to get a GNU compatible locale string */
extern char* g_win32_getlocale(void);
/* Set this to 0 during developement and testing in Visual-Studio
Set this to 1 to make the final executable */
#if 1
#define DOC_PREFIX "docs/"
#define DATA_PREFIX "data/"
#define LOCALEDIR "locale"
#else
#define DOC_PREFIX "../../docs/"
#define DATA_PREFIX "../../data/"
#define LOCALEDIR "../../locale"
#endif /* 1/0 */
#define mkdir(path,access) _mkdir(path)
#define strcasecmp stricmp
#define strncasecmp strnicmp
#define snprintf _snprintf
#define S_ISDIR(i) ((i&_S_IFDIR)!=0)
#define alloca _alloca
#endif /* WIN32 */
@ -250,7 +218,7 @@ extern char* g_win32_getlocale(void);
#include <sys/stat.h>
#include "SDL.h"
#ifndef _SDL_H
#if !defined(_SDL_H)
#error "---------------------------------------------------"
#error "If you installed SDL from a package, be sure to get"
#error "the development package, as well!"
@ -259,30 +227,26 @@ extern char* g_win32_getlocale(void);
#endif
#include "SDL_image.h"
#ifndef _SDL_IMAGE_H
#ifndef _IMG_h
#if !defined(_SDL_IMAGE_H) && !defined(_IMG_h)
#error "---------------------------------------------------"
#error "If you installed SDL_image from a package, be sure"
#error "to get the development package, as well!"
#error "(e.g., 'libsdl-image1.2-devel.rpm')"
#error "---------------------------------------------------"
#endif
#endif
#include "SDL_ttf.h"
#ifndef _SDL_TTF_h
#ifndef _SDLttf_h
#if !defined(_SDL_TTF_H) && !defined(_SDLttf_h)
#error "---------------------------------------------------"
#error "If you installed SDL_ttf from a package, be sure"
#error "to get the development package, as well!"
#error "(e.g., 'libsdl-ttf1.2-devel.rpm')"
#error "---------------------------------------------------"
#endif
#endif
#ifndef NOSOUND
#include "SDL_mixer.h"
#ifndef _MIXER_H_
#if !defined(_SDL_MIXER_H) && !defined(_MIXER_H_)
#error "---------------------------------------------------"
#error "If you installed SDL_mixer from a package, be sure"
#error "to get the development package, as well!"
@ -389,7 +353,6 @@ static void win32_perror(const char * const str)
#endif
#ifndef WIN32
#ifdef __GNUC__
// This version has strict type checking for safety.
// See the "unnecessary" pointer comparison. (from Linux)
@ -407,7 +370,6 @@ static void win32_perror(const char * const str)
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#endif
#define clamp(lo,value,hi) (min(max(value,lo),hi))
@ -718,25 +680,12 @@ static void set_current_language(void)
lang = LANG_EN;
#ifndef WIN32
loc = setlocale(LC_MESSAGES, NULL);
if (loc != NULL)
{
if (strstr(loc, "LC_MESSAGES") != NULL)
loc = getenv("LANG");
}
#else
loc = getenv("LANGUAGE");
if (!loc)
{
loc = g_win32_getlocale();
if (loc)
{
snprintf(str, sizeof(str), "LANGUAGE=%s", loc);
putenv(strdup(str));
}
}
#endif
debug(loc);
@ -15123,7 +15072,7 @@ static int charsize(char c)
str[0] = c;
str[1] = '\0';
TTF_SizeUNICODE(fonts[cur_font], str, &w, &h);
TTF_SizeUNICODE(getfonthandle(cur_font), str, &w, &h);
return w;
}

View file

@ -23,14 +23,14 @@
/* Oct. 07, 2003 - added banding support */
/* - prints using 24-bit (not 32-bit) bitmap */
#include <windows.h>
#include "SDL_syswm.h"
#include "win32_print.h"
#include "resource.h"
#define NOREF(x) ((x)=(x))
#define GETHINST(hWnd) ((HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE ))
#define MIR( id ) (MAKEINTRESOURCE( id ))
#define GETHINST(hWnd) ((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE))
#define MIR(id) (MAKEINTRESOURCE(id))
static PRINTDLG global_pd = {
@ -42,11 +42,11 @@ static PRINTDLG global_pd = {
0xFFFF,
0xFFFF,
1,
NULL,
0, 0, 0, 0, 0, 0, 0, 0,
};
static SDL_Surface *make24bitDIB( SDL_Surface *surf )
static SDL_Surface *make24bitDIB(SDL_Surface *surf)
{
SDL_PixelFormat pixfmt;
SDL_Surface *surf24;
@ -55,7 +55,7 @@ static SDL_Surface *make24bitDIB( SDL_Surface *surf )
Uint32 linesize;
int i;
memset( &pixfmt, 0, sizeof(pixfmt) );
memset(&pixfmt, 0, sizeof(pixfmt));
pixfmt.palette = NULL;
pixfmt.BitsPerPixel = 24;
pixfmt.BytesPerPixel= 3;
@ -74,47 +74,47 @@ static SDL_Surface *make24bitDIB( SDL_Surface *surf )
pixfmt.colorkey = 0;
pixfmt.alpha = 0;
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 );
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);
linesize = surf24->w * 3; // Flip top2bottom
dst = surfDIB->pixels;
src = ((Uint8*)surf24->pixels)+((surf24->h-1)*surf24->pitch);
for ( i = 0; i < surf24->h; ++i )
for (i = 0; i < surf24->h; ++i)
{
memcpy( dst, src, linesize );
memcpy(dst, src, linesize);
src -= surf24->pitch;
dst += surfDIB->pitch;
}
SDL_FreeSurface( surf24 ); // Free temp surface
SDL_FreeSurface(surf24); // Free temp surface
return surfDIB;
}
/* returns 0 if failed */
static int GetDefaultPrinterStrings( char *device, char *driver, char *output )
static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
{
const char *section = "windows";
const char *key = "device";
const char *def = "NODEFAULTPRINTER";
char buff[MAX_PATH];
char *section = "windows";
char *key = "device";
char *def = "NODEFAULTPRINTER";
char *dev,*drv,*out;
if ( !GetProfileString( section, key, def, buff, sizeof(buff) ) )
if (!GetProfileString(section, key, def, buff, sizeof(buff)))
return 0;
if ( strcmp( buff, def ) == 0 )
if (strcmp(buff, def) == 0)
return 0;
if ( ((dev = strtok( buff, "," )) != NULL) &&
((drv = strtok( NULL, ", ")) != NULL) &&
((out = strtok( NULL, ", ")) != NULL) )
if (((dev = strtok(buff, "," )) != NULL) &&
((drv = strtok(NULL, ", ")) != NULL) &&
((out = strtok(NULL, ", ")) != NULL))
{
if ( device ) strcpy( device, dev );
if ( driver ) strcpy( driver, drv );
if ( output ) strcpy( output, out );
if (device) strcpy(device, dev);
if (driver) strcpy(driver, drv);
if (output) strcpy(output, out);
return 1;
}
return 0;
@ -122,7 +122,7 @@ static int GetDefaultPrinterStrings( char *device, char *driver, char *output )
#define dmDeviceNameSize 32
static HANDLE LoadCustomPrinterHDEVMODE( HWND hWnd, const char *filepath )
static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
{
char device[MAX_PATH];
HANDLE hPrinter = NULL;
@ -134,151 +134,151 @@ static HANDLE LoadCustomPrinterHDEVMODE( HWND hWnd, const char *filepath )
int block_size;
int block_read;
if ( (fp = fopen( filepath, "rb" )) == NULL )
if ((fp = fopen(filepath, "rb")) == NULL)
return NULL;
if ( fread( device, 1, dmDeviceNameSize, fp ) != dmDeviceNameSize )
if (fread(device, 1, dmDeviceNameSize, fp) != dmDeviceNameSize)
goto err_exit;
if (!OpenPrinter( device, &hPrinter, NULL ))
if (!OpenPrinter(device, &hPrinter, NULL))
return NULL;
sizeof_devmode = (int)DocumentProperties( hWnd, hPrinter, device,
NULL, NULL, 0 );
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device,
NULL, NULL, 0);
if ( !sizeof_devmode )
if (!sizeof_devmode)
goto err_exit;
hDevMode = GlobalAlloc( GHND, sizeof_devmode );
if ( !hDevMode )
hDevMode = GlobalAlloc(GHND, sizeof_devmode);
if (!hDevMode)
goto err_exit;
devmode = (DEVMODE*)GlobalLock( hDevMode );
if ( !devmode )
devmode = (DEVMODE*)GlobalLock(hDevMode);
if (!devmode)
goto err_exit;
res = DocumentProperties( hWnd, hPrinter, device, devmode, NULL,
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL,
DM_OUT_BUFFER);
if ( res != IDOK )
if (res != IDOK)
goto err_exit;
block_size = devmode->dmSize + devmode->dmDriverExtra;
block_read = fread( devmode, 1, block_size, fp );
if ( block_size != block_read )
block_read = fread(devmode, 1, block_size, fp);
if (block_size != block_read)
goto err_exit;
fclose(fp);
res = DocumentProperties( hWnd, hPrinter, device, devmode, devmode,
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
DM_IN_BUFFER|DM_OUT_BUFFER);
if ( res != IDOK )
if (res != IDOK)
goto err_exit;
GlobalUnlock( hDevMode );
ClosePrinter( hPrinter );
GlobalUnlock(hDevMode);
ClosePrinter(hPrinter);
return hDevMode;
err_exit:
if ( fp ) fclose( fp );
if ( devmode ) GlobalUnlock( hDevMode );
if ( hDevMode ) GlobalFree( hDevMode );
if ( hPrinter ) ClosePrinter( hPrinter );
if (fp) fclose(fp);
if (devmode) GlobalUnlock(hDevMode);
if (hDevMode) GlobalFree(hDevMode);
if (hPrinter) ClosePrinter(hPrinter);
return NULL;
}
static int SaveCustomPrinterHDEVMODE( HWND hWnd, const char *filepath, HANDLE hDevMode )
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode)
{
FILE *fp = NULL;
NOREF(hWnd);
if ( (fp = fopen( filepath, "wb" )) != NULL )
if ((fp = fopen(filepath, "wb")) != NULL)
{
DEVMODE *devmode = (DEVMODE*)GlobalLock( hDevMode );
DEVMODE *devmode = (DEVMODE*)GlobalLock(hDevMode);
int block_size = devmode->dmSize + devmode->dmDriverExtra;
int block_written;
char devname[dmDeviceNameSize];
strcpy( devname, (const char*)devmode->dmDeviceName );
fwrite( devname, 1, sizeof(devname), fp );
block_written = fwrite( devmode, 1, block_size, fp );
GlobalUnlock( hDevMode );
fclose( fp );
strcpy(devname, (const char*)devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode);
fclose(fp);
return block_size == block_written;
}
return 0;
}
static HDC GetCustomPrinterDC( HWND hWnd, const char *printcfg, int show )
static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
{
global_pd.hwndOwner = hWnd;
global_pd.hDC = NULL;
global_pd.hDevNames = NULL;
if ( global_pd.hDevMode == NULL )
if (global_pd.hDevMode == NULL)
{
global_pd.hDevMode = LoadCustomPrinterHDEVMODE( hWnd, printcfg );
global_pd.hDevMode = LoadCustomPrinterHDEVMODE(hWnd, printcfg);
}
if ( show )
if (show)
{
if ( PrintDlg( &global_pd ) )
if (PrintDlg(&global_pd))
{
SaveCustomPrinterHDEVMODE( hWnd, printcfg, global_pd.hDevMode );
SaveCustomPrinterHDEVMODE(hWnd, printcfg, global_pd.hDevMode);
return global_pd.hDC;
}
return NULL;
}
{
DEVMODE *devmode = (DEVMODE*)GlobalLock( global_pd.hDevMode );
DEVMODE *devmode = (DEVMODE*)GlobalLock(global_pd.hDevMode);
global_pd.hDC = CreateDC( NULL, (const char*)devmode->dmDeviceName, NULL, devmode );
GlobalUnlock( global_pd.hDevMode );
global_pd.hDC = CreateDC(NULL, (const char*)devmode->dmDeviceName, NULL, devmode);
GlobalUnlock(global_pd.hDevMode);
}
return global_pd.hDC;
}
static HDC GetDefaultPrinterDC( void )
static HDC GetDefaultPrinterDC(void)
{
char device[MAX_PATH],driver[MAX_PATH],output[MAX_PATH];
if ( GetDefaultPrinterStrings( device, driver, output ) )
return CreateDC( driver, device, output, NULL );
if (GetDefaultPrinterStrings(device, driver, output))
return CreateDC(driver, device, output, NULL);
return NULL;
}
static HDC GetPrinterDC( HWND hWnd, const char *printcfg, int show )
static HDC GetPrinterDC(HWND hWnd, const char *printcfg, int show)
{
if ( !printcfg ) return GetDefaultPrinterDC();
return GetCustomPrinterDC( hWnd, printcfg, show );
if (!printcfg) return GetDefaultPrinterDC();
return GetCustomPrinterDC(hWnd, printcfg, show);
}
static int IsBandingRequired( HDC hPrinter )
static int IsBandingRequired(HDC hPrinter)
{
OSVERSIONINFO osvi;
int indata = NEXTBAND;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if ( GetVersionEx( &osvi ) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) )
return Escape( hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL );
if (GetVersionEx(&osvi) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT))
return Escape(hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL);
return 0;
}
int IsPrinterAvailable( void )
int IsPrinterAvailable(void)
{
return (GetDefaultPrinterStrings( NULL, NULL, NULL ) != 0);
return (GetDefaultPrinterStrings(NULL, NULL, NULL) != 0);
}
const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialog )
const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog)
{
char *res = NULL;
const char *res = NULL;
HWND hWnd;
DOCINFO di;
int nError;
@ -297,15 +297,15 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
HDC hdcMem = NULL;
SDL_VERSION(&wminfo.version);
if ( !SDL_GetWMInfo( &wminfo ) )
if (!SDL_GetWMInfo(&wminfo))
return "win32_print: SDL_GetWMInfo() failed.";
hWnd = wminfo.window;
hDCprinter = GetPrinterDC( hWnd, printcfg, showdialog );
if ( !hDCprinter )
hDCprinter = GetPrinterDC(hWnd, printcfg, showdialog);
if (!hDCprinter)
return "win32_print: GetPrinterDC() failed.";
EnableWindow( hWnd, FALSE );
EnableWindow(hWnd, FALSE);
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Tux Paint";
@ -313,14 +313,14 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
di.lpszDatatype = (LPTSTR)NULL;
di.fwType = 0;
nError = StartDoc( hDCprinter, &di );
if ( nError == SP_ERROR )
nError = StartDoc(hDCprinter, &di);
if (nError == SP_ERROR)
{
res = "win32_print: StartDoc() failed.";
goto error;
}
nError = StartPage( hDCprinter );
nError = StartPage(hDCprinter);
if (nError <= 0)
{
res = "win32_print: StartPage() failed.";
@ -329,14 +329,14 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
//////////////////////////////////////////////////////////////////////////////////////
surf24 = make24bitDIB( surf );
if ( !surf24 )
surf24 = make24bitDIB(surf);
if (!surf24)
{
res = "win32_print: make24bitDIB() failed.";
goto error;
}
memset( &bmih,0, sizeof(bmih) );
memset(&bmih, 0, sizeof(bmih));
bmih.biSize = sizeof(bmih);
bmih.biPlanes = 1;
bmih.biCompression = BI_RGB;
@ -344,25 +344,25 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
bmih.biWidth = surf24->w;
bmih.biHeight = surf24->h;
GetClientRect( hWnd, &rc );
GetClientRect(hWnd, &rc);
subscalerx = (float)rc.right/surf24->w;
subscalery = (float)rc.bottom/surf24->h;
subscaler = subscalery;
if ( subscalerx < subscalery )
if (subscalerx < subscalery)
subscaler = subscalerx;
hDCwindow = GetDC( hWnd );
if ( !hDCwindow )
hDCwindow = GetDC(hWnd);
if (!hDCwindow)
{
res = "win32_print: failed to get window DC.";
goto error;
}
fLogPelsX1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSX);
fLogPelsY1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSY);
ReleaseDC( hWnd, hDCwindow );
fLogPelsX1 = GetDeviceCaps(hDCwindow, LOGPIXELSX);
fLogPelsY1 = GetDeviceCaps(hDCwindow, LOGPIXELSY);
ReleaseDC(hWnd, hDCwindow);
fLogPelsX2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSX);
fLogPelsY2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSY);
fLogPelsX2 = GetDeviceCaps(hDCprinter, LOGPIXELSX);
fLogPelsY2 = GetDeviceCaps(hDCprinter, LOGPIXELSY);
if (fLogPelsX1 > fLogPelsX2)
fScaleX = (fLogPelsX1/fLogPelsX2);
@ -390,24 +390,24 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
goto error;
}
if ( IsBandingRequired( hDCprinter ) )
if (IsBandingRequired(hDCprinter))
{
RECT rcBand = { 0 };
RECT rcBand = { 0, 0, 0, 0 };
RECT rcPrinter;
RECT rcImage;
SetRect( &rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight) );
SetRect( &rcImage, 0, 0, bmih.biWidth, bmih.biHeight );
SetRect(&rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight));
SetRect(&rcImage, 0, 0, bmih.biWidth, bmih.biHeight);
while ( Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand) )
while (Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand))
{
if ( IsRectEmpty( &rcBand) ) break;
if ( IntersectRect( &rcBand, &rcBand, &rcPrinter ) )
if (IsRectEmpty(&rcBand)) break;
if (IntersectRect(&rcBand, &rcBand, &rcPrinter))
{
rcImage.top = (int)(0.5f+(float)rcBand.top/fScaleX);
rcImage.bottom = (int)(0.5f+(float)rcBand.bottom/fScaleX);
SetStretchBltMode( hDCprinter, COLORONCOLOR );
SetStretchBltMode(hDCprinter, COLORONCOLOR);
nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top,
rcBand.right - rcBand.left,
rcBand.bottom - rcBand.top,
@ -416,7 +416,7 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
rcImage.bottom - rcImage.top,
surf24->pixels, (BITMAPINFO*)&bmih,
DIB_RGB_COLORS, SRCCOPY);
if ( nError == GDI_ERROR )
if (nError == GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
goto error;
@ -426,7 +426,7 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
}
else
{
if ( hDCCaps & RC_STRETCHDIB )
if (hDCCaps & RC_STRETCHDIB)
{
SetStretchBltMode(hDCprinter, COLORONCOLOR);
@ -436,7 +436,7 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, (BITMAPINFO*)&bmih,
DIB_RGB_COLORS, SRCCOPY);
if ( nError == GDI_ERROR )
if (nError == GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
goto error;
@ -451,22 +451,22 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
//////////////////////////////////////////////////////////////////////////////////////
nError = EndPage( hDCprinter );
if ( nError <= 0 )
nError = EndPage(hDCprinter);
if (nError <= 0)
{
res = "win32_print: EndPage() failed.";
goto error;
}
EndDoc( hDCprinter );
EndDoc(hDCprinter);
error:
if ( hdcMem ) DeleteDC( hdcMem );
if ( hbm ) DeleteObject( hbm );
if ( surf24 ) SDL_FreeSurface( surf24 );
if (hdcMem) DeleteDC(hdcMem);
if (hbm) DeleteObject(hbm);
if (surf24) SDL_FreeSurface(surf24);
EnableWindow( hWnd, TRUE );
DeleteDC( hDCprinter );
EnableWindow(hWnd, TRUE);
DeleteDC(hDCprinter);
return res;
}

View file

@ -1,22 +1,22 @@
/* win32_print.h */
/* printing support for Tux Paint */
/* John Popplewell <john@johnnypops.demon.co.uk> */
/* Sept. 30, 2002 - Oct. 1, 2002 */
#ifndef __WIN32_PRINT_H__
#define __WIN32_PRINT_H__
#ifndef _SDL_H
#include "SDL.h"
#endif
/* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint( SDL_Surface *surf,
const char *printcfg,
int showdialog );
extern int IsPrinterAvailable( void );
#endif
/* win32_print.h */
/* printing support for Tux Paint */
/* John Popplewell <john@johnnypops.demon.co.uk> */
/* Sept. 30, 2002 - Oct. 1, 2002 */
#ifndef __WIN32_PRINT_H__
#define __WIN32_PRINT_H__
#ifndef _SDL_H
#include "SDL.h"
#endif
/* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint( SDL_Surface *surf,
const char *printcfg,
int showdialog );
extern int IsPrinterAvailable( void );
#endif