~Win32PrinterDisplay()
{
//if(memDC) DeleteDC(memDC);
- //if(memBitmap) DeleteObject(memBitmap);
+ //if(memBitmap) DeleteObject(memBitmap);
if(palette) DeleteObject(palette);
delete logPalette;
}
static PixelFormat GetColorFormat(int depth)
{
- if(depth == 8)
+ if(depth == 8)
return pixelFormat8;
- else if(depth == 16)
+ else if(depth == 16)
return pixelFormat555;
- else
+ else
return pixelFormat888;
}
+static define dpi = 100;
+static define inchToMillimeter = 0.039370;
class Win32PrinterDisplayDriver : DisplayDriver
{
class_property(name) = "Win32Printer";
bool CreateDisplaySystem(DisplaySystem displaySystem)
{
- Win32PrinterSystem gdiSystem = displaySystem.driverData = Win32PrinterSystem { };
+ displaySystem.driverData = Win32PrinterSystem { };
return true; //false;
}
bool CreateDisplay(Display display)
{
- Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
bool result = false;
if(display)
uint16 szPrinter[160];
uint16 *szDevice, *szDriver, *szOutput;
- GetProfileString(L"windows", L"device", L"...", (char *)szPrinter, 160);
+ GetProfileString(L"windows", L"device", L"...", szPrinter, 160);
szDevice = wcstok(szPrinter, L",");
szDriver = wcstok(null, L",");
szOutput = wcstok(null, L",");
size = DocumentProperties(null, hPrinter, szDevice, null, null, 0);
devMode = (DEVMODE *)new0 byte[size];
DocumentProperties(null, hPrinter, szDevice, devMode, null, DM_OUT_BUFFER);
+ devMode->dmFields |= DM_ORIENTATION | DM_PAPERSIZE;
devMode->dmOrientation = (width > height) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
+ if(height == (int)(8.5*dpi) && width == 11*dpi)
+ devMode->dmPaperSize = DMPAPER_LETTER;
+ else if(height == (int)(8.5*dpi) && width == 14*dpi)
+ devMode->dmPaperSize = DMPAPER_LEGAL;
+ else if(height == 11*dpi && width == 17*dpi)
+ devMode->dmPaperSize = DMPAPER_11X17;
+ else
+ {
+ short w = (short)((double)width * 10 / dpi / inchToMillimeter);
+ short h = (short)((double)height * 10 / dpi / inchToMillimeter);
+ devMode->dmPaperSize = DMPAPER_USER;
+ devMode->dmFields |= DM_PAPERWIDTH | DM_PAPERLENGTH;
+ devMode->dmPaperLength = w > h ? w : h;
+ devMode->dmPaperWidth = w < h ? w : h;
+ }
DocumentProperties(null, hPrinter, szDevice, devMode, devMode, DM_IN_BUFFER|DM_OUT_BUFFER);
gdiSystem.hdc = CreateDC(szDriver, szDevice, szOutput, devMode);
delete devMode;
Win32PrinterDisplay gdiDisplay = display.driverData;
gdiDisplay.completed = false;
EndPage(gdiDisplay.hdc);
- StartPage(gdiDisplay.hdc);
+ StartPage(gdiDisplay.hdc);
}
void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
if(bitmap.transparent)
{
Bitmap mask { };
- HGDIOBJ prevDC, prevDC2;
+ HGDIOBJ prevDC;//, prevDC2;
int c;
mask.Allocate(null, bitmap.width, bitmap.height, 0, pixelFormat888, false);
for(c = 0; c<bitmap.width * bitmap.height; c++)
gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, mask.picture, info, DIB_RGB_COLORS);
gdiBitmap.mask = CreateBitmap(bitmap.width, bitmap.height, 1, 1, null);
prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
- prevDC2 = SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
+ /*prevDC2 = */SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
SetBkColor(gdiSystem.bmpDC, 0);
BitBlt(gdiSystem.tmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.bmpDC, 0, 0, SRCCOPY);
SetBkColor(gdiSystem.bmpDC, 0);
SetBkColor(gdiSystem.bmpDC, RGB(0,0,0));
BitBlt(gdiSystem.bmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.tmpDC, 0, 0, SRCAND);
SelectObject(gdiSystem.tmpDC, prevDC2);
- SelectObject(gdiSystem.bmpDC, prevDC);
+ SelectObject(gdiSystem.bmpDC, prevDC);
SetTextColor(gdiSystem.bmpDC, RGB(0,0,0));
SetBkColor(gdiSystem.bmpDC, RGB(255,255,255));
SetBkColor(gdiSystem.tmpDC, RGB(255,255,255));
{
gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
}
-
+
delete bitmap.picture;
delete info;
void ReleaseSurface(Display display, Surface surface)
{
Win32PrinterSurface gdiSurface = surface.driverData;
- Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
if(gdiSurface)
{
if(gdiSurface.rgn)
surface.height = gdiDisplay.height - y + 1;
surface.offset.x = x * gdiDisplay.width / display.width;
surface.offset.y = y * gdiDisplay.height / display.height;
- surface.unclippedBox = surface.box =
+ surface.unclippedBox = surface.box =
{
left = clip.left * gdiDisplay.width / display.width,
top = clip.top * gdiDisplay.height / display.height,
right = (clip.right+1) * gdiDisplay.width / display.width-1,
bottom = (clip.bottom+1) * gdiDisplay.height / display.height-1
};
-
+
gdiSurface.rgn = CreateRectRgn(
surface.offset.x + surface.box.left,
surface.offset.y + surface.box.top,
{
Win32PrinterDisplay gdiDisplay = display.driverData;
Win32PrinterSurface gdiSurface = surface.driverData;
- HRGN clippedRgn = null;
+ HRGN clippedRgn = null;
if(clip != null)
{
Box box = clip;
box.Clip(gdiSurface.unclippedBox);
gdiSurface.box = box;
- surface.box =
+ surface.box =
{
left = box.left * gdiDisplay.width / display.width,
top = box.top * gdiDisplay.height / display.height,
}
else
clippedRgn = CreateRectRgn(0, 0, 0, 0);
-
+
if(clippedRgn)
SelectClipRgn(gdiSurface.hdc, clippedRgn);
}
bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
{
bool result = false;
- Win32PrinterDisplay gdiDisplay = display.driverData;
// result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
return result;
}
void SetForeground(Display display, Surface surface, ColorAlpha color)
{
Win32PrinterSurface gdiSurface = surface.driverData;
- Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
COLORREF rgb = RGB(color.color.r, color.color.g, color.color.b);
// ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
SetTextColor(gdiSurface.hdc, rgb);
void SetBackground(Display display, Surface surface, ColorAlpha color)
{
Win32PrinterSurface gdiSurface = surface.driverData;
- Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
COLORREF rgb;
/*
((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
PatBlt(gdiSurface.hdc,
(int)((float)x * gdiDisplay.width / display.width) + surface.offset.x,
(int)((float)y * gdiDisplay.height / display.height) + surface.offset.y,
- (int)((float)(x+1) * gdiDisplay.width / display.width)-1 + surface.offset.x+1,
+ (int)((float)(x+1) * gdiDisplay.width / display.width)-1 + surface.offset.x+1,
(int)((float)(y+1) * gdiDisplay.height / display.height)-1 + surface.offset.y+1,
PATCOPY);
SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
{
Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
Win32PrinterSurface gdiSurface = surface.driverData;
-
+
x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
x2 = (int)(((float)(x2+1) * gdiDisplay.width / display.width) + 0.5) + surface.offset.x;
SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
-
+
SetBkColor(gdiSurface.hdc, 0xFFFFFF);
SetTextColor(gdiSurface.hdc, 0);
- StretchBlt(gdiSurface.hdc,
- dx * gdiDisplay.width / display.width + surface.offset.x,
+ StretchBlt(gdiSurface.hdc,
+ dx * gdiDisplay.width / display.width + surface.offset.x,
dy * gdiDisplay.height / display.height + surface.offset.y,
(w) * gdiDisplay.width / display.width,
(h) * gdiDisplay.height / display.height,
gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
- StretchBlt(gdiSurface.hdc,
- dx * gdiDisplay.width / display.width + surface.offset.x,
+ StretchBlt(gdiSurface.hdc,
+ dx * gdiDisplay.width / display.width + surface.offset.x,
dy * gdiDisplay.height / display.height + surface.offset.y,
(w) * gdiDisplay.width / display.width,
(h) * gdiDisplay.height / display.height,
gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
/*
- StretchBlt(gdiSurface.hdc,
- dx * gdiDisplay.width / display.width + surface.offset.x,
+ StretchBlt(gdiSurface.hdc,
+ dx * gdiDisplay.width / display.width + surface.offset.x,
dy * gdiDisplay.height / display.height + surface.offset.y,
(w+1) * gdiDisplay.width / display.width-1,
(h+1) * gdiDisplay.height / display.height-1,
gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
- StretchBlt(gdiSurface.hdc,
- dx * gdiDisplay.width / display.width + surface.offset.x,
+ StretchBlt(gdiSurface.hdc,
+ dx * gdiDisplay.width / display.width + surface.offset.x,
dy * gdiDisplay.height / display.height + surface.offset.y,
(w+1) * gdiDisplay.width / display.width-1,
(h+1) * gdiDisplay.height / display.height-1,
{
SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
- StretchBlt(gdiSurface.hdc,
- dx * gdiDisplay.width / display.width + surface.offset.x,
+ StretchBlt(gdiSurface.hdc,
+ dx * gdiDisplay.width / display.width + surface.offset.x,
dy * gdiDisplay.height / display.height + surface.offset.y,
(w+1) * gdiDisplay.width / display.width-1,
(h+1) * gdiDisplay.height / display.height-1,
Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
}
- Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
+ Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
{
Win32PrinterSystem gdiSystem = displaySystem.driverData;
HDC hdc = gdiSystem.hdc;
- int pixels, res;
+ int /*pixels, */res;
void * font;
/*
SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
*/
- pixels = GetDeviceCaps(hdc, VERTRES);
+ //pixels = GetDeviceCaps(hdc, VERTRES);
res = GetDeviceCaps(hdc, LOGPIXELSY);
{
int s;
s = -(int)(((float)size * res / 78) + 0.5);
// font = CreateFont(-(int)(((float)size * 96 / 72) + 0.5),
- font = CreateFont(s,
+ font = CreateFontA(s,
// font = CreateFont(-(int)(((float)size * pixels * RESY / res / 72) + 0.5),
0,0,0, flags.bold ? FW_BOLD : FW_NORMAL, flags.italic ? TRUE : FALSE,
flags.underline ? TRUE : FALSE, 0, DEFAULT_CHARSET,
SetBkMode(gdiSurface.hdc, opaque ? OPAQUE : TRANSPARENT);
}
- void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
+ void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
{
Win32PrinterSurface gdiSurface = surface.driverData;
Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
delete u16text;
}
- void ::_TextExtent(HDC hdc, int resX, int resY, char * text, int len, int * width, int * height)
+ void ::_TextExtent(HDC hdc, int resX, int resY, const char * text, int len, int * width, int * height)
{
SIZE space, size;
uint realLen;
uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
for(realLen = 0; realLen<wordCount && u16text[realLen]; realLen++);
- GetTextExtentPoint32(hdc, " ", 1, &space);
+ GetTextExtentPoint32(hdc, L" ", 1, &space);
GetTextExtentPoint32(hdc, u16text, realLen, &size);
delete u16text;
*width = size.cx + (wordCount - realLen) * space.cx;
*width = *width * resX / GetDeviceCaps(hdc, HORZRES);
}
- if(height)
+ if(height)
{
if(realLen)
*height = size.cy;
*height = *height * resY / GetDeviceCaps(hdc, VERTRES);
}
}
-
- void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
+
+ void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
{
- Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
Win32PrinterSystem gdiSystem = (display && display.displaySystem) ? display.displaySystem.driverData : null;
Win32PrinterSurface gdiSurface = surface.driverData;
_TextExtent(gdiSurface.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
}
- void FontExtent(DisplaySystem displaySystem, void * font, char * text, int len, int * width, int * height)
+ void FontExtent(DisplaySystem displaySystem, void * font, const char * text, int len, int * width, int * height)
{
Win32PrinterSystem gdiSystem = displaySystem.driverData;
if(gdiSystem.hdc)
void LineStipple(Display display, Surface surface, uint stipple)
{
- Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
+ //Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
// ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
}