Thanks for the code…
Now I will merge it with the one I’ve written in these days.
Can someone help me implement printing for linux too?
Enzo.
-------------- next part --------------
#ifdef linux
#include <stdio.h>
#else
#include <windows.h>
#endif
#ifdef WIN32
HDC GetPrinterDC()
{
char szPrinter[80];
char *szDevice, *szDriver, *szOutput;
DEVMODE PrintDev;
GetProfileString(“windows”, “device”, “,” ,szPrinter, 80);
if (NULL != (szDevice = strtok (szPrinter, “,”)) &&
NULL != (szDriver = strtok (NULL, “,”)) &&
NULL != (szOutput = strtok (NULL, “,”))) {
memset (&PrintDev, 0, sizeof (PrintDev));
PrintDev.dmOrientation = DMORIENT_LANDSCAPE;
return CreateDC(szDriver, szDevice, szOutput,&PrintDev);
}
return 0;
}
#endif
void PrintSurface (char* Info, SDL_Surface* Surface, Uint32 Flags)
{
#ifdef linux
printf (“Printing request: (image %d x %d)\n”,
Surface->w, Surface->h);
#else
HDC PrinterDC;
static DOCINFO di = {sizeof (DOCINFO), Info, NULL};
PrinterDC = GetPrinterDC();
int lx = GetDeviceCaps (PrinterDC, HORZRES);
int ly = GetDeviceCaps (PrinterDC, VERTRES);
int px = (lySurface->w)/Surface->h;
int py = (lxSurface->h)/Surface->w;
if (py>ly) {
py = ly;
} else {
px = lx;
}
if (PrinterDC) {
if (StartDoc (PrinterDC, &di) > 0) {
if (StartPage (PrinterDC) > 0) {
HDC ImageDC;
BITMAPINFO BitmapInfo;
HBITMAP Bitmap;
DWORD TotalSize;
HGDIOBJ Prev;
void Pixels;
BitmapInfo = (BITMAPINFO*)
malloc (sizeof (BITMAPINFO)+255*sizeof (RGBQUAD));
memset (BitmapInfo,0,sizeof (Bitmap));
BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo->bmiHeader.biWidth = Surface->w;
BitmapInfo->bmiHeader.biHeight = -Surface->h;
BitmapInfo->bmiHeader.biPlanes = 1;
BitmapInfo->bmiHeader.biBitCount = Surface->format->BitsPerPixel;
BitmapInfo->bmiHeader.biCompression = BI_RGB;
BitmapInfo->bmiHeader.biSizeImage = Surface->h * Surface->pitch;
BitmapInfo->bmiHeader.biXPelsPerMeter = 0;
BitmapInfo->bmiHeader.biYPelsPerMeter = 0;
BitmapInfo->bmiHeader.biClrUsed = Surface->format->palette->ncolors;
BitmapInfo->bmiHeader.biClrImportant = 0;
if (Surface->format->palette) {
for (int I=0; Iformat->palette->ncolors; I++) {
BitmapInfo->bmiColors[I].rgbRed =
(Surface->format->palette->colors+I)->r;
BitmapInfo->bmiColors[I].rgbGreen =
(Surface->format->palette->colors+I)->g;
BitmapInfo->bmiColors[I].rgbBlue =
(Surface->format->palette->colors+I)->b;
}
}
ImageDC = CreateCompatibleDC(PrinterDC);
if (ImageDC) {
Bitmap = CreateDIBSection(ImageDC, BitmapInfo, DIB_RGB_COLORS,
(&Pixels), NULL, 0);
if (Bitmap) {
memcpy (Pixels, Surface->pixels,
BitmapInfo->bmiHeader.biSizeImage);
Prev = SelectObject (ImageDC, Bitmap);
StretchBlt (PrinterDC, 0, 0, px, py,
ImageDC, 0, 0, Surface->w, Surface->h, SRCCOPY);
SelectObject (ImageDC,Prev);
DeleteObject (Bitmap);
}
DeleteDC (ImageDC);
}
free (BitmapInfo);
if (EndPage(PrinterDC) > 0) {
EndDoc (PrinterDC);
}
}
}
DeleteDC (PrinterDC);
}
#endif
}