1 namespace gfx::drivers;
7 #define _WIN32_WINNT 0x0500
8 #define WIN32_LEAN_AND_MEAN
10 #define Method _Method
15 default wchar_t *wcstok(wchar_t *strToken,const wchar_t *strDelimit);
19 //static char szMessage[]= L"Printing ECERE Document...";
20 static char szMessage[]= "Printing ECERE Document...";
23 static define RESX = 850;
24 static define RESY = 1100;
27 class Win32PrinterDisplay : struct
30 LOGPALETTE * logPalette;
39 ~Win32PrinterDisplay()
41 //if(memDC) DeleteDC(memDC);
42 //if(memBitmap) DeleteObject(memBitmap);
43 if(palette) DeleteObject(palette);
48 static byte defaultRGBLookup[32768];
49 static bool rgbLookupSet = false;
51 class Win32PrinterSystem : struct
56 int resX, resY; // Save the display here, support only one display at a time
64 class Win32PrinterSurface : struct
68 COLORREF color, backColor;
71 Box box, unclippedBox;
74 class Win32PrinterBitmap : struct
80 static PixelFormat GetColorFormat(int depth)
85 return pixelFormat555;
87 return pixelFormat888;
90 class Win32PrinterDisplayDriver : DisplayDriver
92 class_property(name) = "Win32Printer";
93 class_property(printer) = bool::true;
95 bool CreateDisplaySystem(DisplaySystem displaySystem)
97 Win32PrinterSystem gdiSystem = displaySystem.driverData = Win32PrinterSystem { };
101 void DestroyDisplaySystem(DisplaySystem displaySystem)
103 Win32PrinterSystem gdiSystem = displaySystem.driverData;
104 DeleteDC(gdiSystem.tmpDC);
105 DeleteDC(gdiSystem.bmpDC);
106 DeleteDC(gdiSystem.hdc);
107 displaySystem.driverData = null;
111 void DestroyDisplay(Display display)
113 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
114 Win32PrinterDisplay gdiDisplay = display.driverData;
117 EndPage(gdiDisplay.hdc);
118 Escape(gdiDisplay.hdc, ENDDOC, 0, null, null);
121 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
123 display.driverData = null;
127 DeleteDC(gdiSystem.tmpDC);
128 DeleteDC(gdiSystem.bmpDC);
129 DeleteDC(gdiSystem.hdc);
133 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
135 Win32PrinterDisplay gdiDisplay = display.driverData;
136 if(display.displaySystem.pixelFormat == pixelFormat8)
139 ColorAlpha realPalette[256];
140 int reserved = (display.flags.fullScreen) ? 1 : 10;
141 HDC hdc = gdiDisplay.hdc;
146 GetSystemPaletteEntries(hdc,0,256,(PALETTEENTRY *)realPalette);
147 for(c = 0; c<256; c++)
148 realPalette[c] = RGB(realPalette[c].color.r, realPalette[c].color.g, realPalette[c].color.b);
150 // *** Reserved Palette Handling ***
153 palette = GetDefaultPalette();
154 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
156 for(c = 0; c<32768; c++)
157 defaultRGBLookup[c] = (byte)BestColorMatch(realPalette, 1,255, (Color555)c);
159 CopyBytes(gdiDisplay.rgbLookup, defaultRGBLookup, 32768);
163 for(i=0; i<LIGHTSTEPS; i++)
165 gdiDisplay.lightTable[c][i]=gdiDisplay.rgbLookup[(uint16)Color555 {
166 (byte)(((uint16)realPalette[c].color.r*i) >> LIGHTSHIFT),
167 (byte)(((uint16)realPalette[c].color.g*i) >> LIGHTSHIFT),
168 (byte)(((uint16)realPalette[c].color.b*i) >> LIGHTSHIFT) }];
171 CopyBytesBy4(gdiDisplay.bitmap.palette, realPalette, 256);
176 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
177 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, realPalette, colorMatch);
181 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);*/
182 // *********************************
184 gdiDisplay.logPalette->palVersion = 0x300;
185 gdiDisplay.logPalette->palNumEntries = 256;
187 for(c = 0; c < 256; c++)
189 gdiDisplay.logPalette->palPalEntry[c].peFlags = PC_NOCOLLAPSE;
190 gdiDisplay.logPalette->palPalEntry[c].peRed = realPalette[c].color.r;
191 gdiDisplay.logPalette->palPalEntry[c].peGreen = realPalette[c].color.g;
192 gdiDisplay.logPalette->palPalEntry[c].peBlue = realPalette[c].color.b;
195 if(!gdiDisplay.palette)
196 gdiDisplay.palette = CreatePalette(gdiDisplay.logPalette);
198 SetPaletteEntries(gdiDisplay.palette, 0, 256, gdiDisplay.logPalette->palPalEntry);
200 SelectPalette(hdc, gdiDisplay.palette, FALSE);
203 // SetDIBColorTable(gdiDisplay.hdc, 0, 256, (RGBQUAD *)gdiDisplay.bitmap.palette);
208 bool CreateDisplay(Display display)
210 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
215 Win32PrinterDisplay gdiDisplay = display.driverData = Win32PrinterDisplay { };
216 if((gdiDisplay.logPalette = (LOGPALETTE *)new0 byte[sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*256]) /*&&
217 ((subclass(DisplayDriver))class(LFBDisplayDriver)).CreateDisplay(display)*/)
225 bool DisplaySize(Display display, int width, int height)
227 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
228 Win32PrinterDisplay gdiDisplay = display.driverData;
230 HDC hdc = gdiSystem.hdc;
232 if(!width || !height)
238 uint16 szPrinter[160];
239 uint16 *szDevice, *szDriver, *szOutput;
241 GetProfileString(L"windows", L"device", L"...", (char *)szPrinter, 160);
242 szDevice = wcstok(szPrinter, L",");
243 szDriver = wcstok(null, L",");
244 szOutput = wcstok(null, L",");
245 if(szDevice && szDriver && szOutput)
247 DEVMODE * devMode = null;
248 HANDLE hPrinter = null;
250 OpenPrinter(szPrinter, &hPrinter, null);
251 size = DocumentProperties(null, hPrinter, szDevice, null, null, 0);
252 devMode = (DEVMODE *)new0 byte[size];
253 DocumentProperties(null, hPrinter, szDevice, devMode, null, DM_OUT_BUFFER);
254 devMode->dmOrientation = (width > height) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
255 DocumentProperties(null, hPrinter, szDevice, devMode, devMode, DM_IN_BUFFER|DM_OUT_BUFFER);
256 gdiSystem.hdc = CreateDC(szDriver, szDevice, szOutput, devMode);
258 ClosePrinter(hPrinter);
261 gdiSystem.tmpDC = CreateCompatibleDC(gdiSystem.hdc);
262 gdiSystem.bmpDC = CreateCompatibleDC(gdiSystem.hdc);
263 gdiSystem.depth = GetDeviceCaps(gdiSystem.hdc, BITSPIXEL);
264 gdiSystem.depth = 32;
265 display.displaySystem.pixelFormat = GetColorFormat(gdiSystem.depth);
268 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
269 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
270 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
272 SetMapMode(gdiSystem.hdc, MM_TEXT);
275 String docName = printingDocumentName ? printingDocumentName : szMessage;
276 char curDir[MAX_LOCATION];
277 GetWorkingDir(curDir, MAX_LOCATION);
279 if(Escape(gdiSystem.hdc, STARTDOC, strlen(docName), docName, null ) > 0)
281 StartPage(gdiSystem.hdc);
284 ChangeWorkingDir(curDir);
287 //displaySystem.flags.memBackBuffer = true;
291 gdiDisplay.hdc = gdiSystem.hdc;
292 gdiDisplay.width = GetDeviceCaps(hdc, HORZRES);
293 gdiDisplay.height = GetDeviceCaps(hdc, VERTRES);
295 gdiSystem.resX = display.width = width;
296 gdiSystem.resY = display.height = height;
298 SelectObject(gdiDisplay.hdc,GetStockObject(DC_PEN));
299 SelectObject(gdiDisplay.hdc,GetStockObject(DC_BRUSH));
300 SetBkMode(gdiDisplay.hdc, TRANSPARENT);
306 void DisplayPosition(Display display, int x, int y)
308 Win32PrinterDisplay gdiDisplay = display.driverData;
309 gdiDisplay.offset.x = x;
310 gdiDisplay.offset.y = y;
314 void RestorePalette(Display display)
316 Win32PrinterDisplay gdiDisplay = display.driverData;
317 HDC hdc = gdiDisplay.hdc;
320 if(gdiDisplay.palette)
322 SelectPalette(hdc, gdiDisplay.palette, FALSE);
328 #define MAX_EXPOSED 50
330 void StartUpdate(Display display)
332 Win32PrinterDisplay gdiDisplay = display.driverData;
333 if(gdiDisplay && !gdiDisplay.completed)
335 GdiSetBatchLimit(1000);
337 gdiDisplay.rgn = CreateRectRgn(0,0,0,0);
338 gdiDisplay.data = (RGNDATA *) new0 byte[sizeof(RGNDATAHEADER) + sizeof(RECT) * MAX_EXPOSED];
339 if(gdiDisplay.palette)
340 SelectPalette(gdiDisplay.hdc, gdiDisplay.palette, FALSE);
344 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
349 void Update(Display display, Box updateBox)
354 void EndUpdate(Display display)
356 Win32PrinterDisplay gdiDisplay = display.driverData;
357 if(gdiDisplay && !gdiDisplay.completed)
359 DeleteObject(gdiDisplay.rgn);
360 delete gdiDisplay.data;
361 gdiDisplay.data = null;
362 gdiDisplay.completed = true;
366 void NextPage(Display display)
368 Win32PrinterDisplay gdiDisplay = display.driverData;
369 gdiDisplay.completed = false;
370 EndPage(gdiDisplay.hdc);
371 StartPage(gdiDisplay.hdc);
374 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
376 // (((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
377 Win32PrinterBitmap gdiBitmap = bitmap.driverData;
380 DeleteDC(gdiBitmap.memDC);
382 DeleteObject(gdiBitmap.mask);
384 DeleteObject(gdiBitmap.bmp);
385 delete (Win32PrinterBitmap)gdiBitmap;
386 bitmap.driverData = null;
387 bitmap.driver = null;
390 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
392 // return (((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
394 if(bitmap.Convert(null, pixelFormat888, null))
396 Win32PrinterSystem gdiSystem = displaySystem.driverData;
397 Win32PrinterBitmap gdiBitmap = bitmap.driverData = Win32PrinterBitmap { };
398 BITMAPINFO * info = new0 BITMAPINFO[1];
399 if(!info) return false;
401 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
402 info->bmiHeader.biPlanes = 1;
403 info->bmiHeader.biWidth = bitmap.width;
404 info->bmiHeader.biHeight = -bitmap.height;
405 info->bmiHeader.biBitCount = 32;
406 // If transparent, we need to create a black mask for the little GDI trick
407 if(bitmap.transparent)
410 HGDIOBJ prevDC, prevDC2;
412 mask.Allocate(null, bitmap.width, bitmap.height, 0, pixelFormat888, false);
413 for(c = 0; c<bitmap.width * bitmap.height; c++)
414 ((Color *)mask.picture)[c] = ((ColorAlpha *)bitmap.picture)[c].a ? 0xFFFFFF : 0;
416 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, mask.picture, info, DIB_RGB_COLORS);
417 gdiBitmap.mask = CreateBitmap(bitmap.width, bitmap.height, 1, 1, null);
418 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
419 prevDC2 = SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
420 SetBkColor(gdiSystem.bmpDC, 0);
421 BitBlt(gdiSystem.tmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.bmpDC, 0, 0, SRCCOPY);
422 SetBkColor(gdiSystem.bmpDC, 0);
423 SetTextColor(gdiSystem.bmpDC, 0xFFFFFF);
425 SelectObject(gdiSystem.bmpDC, prevDC);
426 DeleteObject(gdiBitmap.bmp);
428 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
429 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
432 SetTextColor(gdiSystem.bmpDC, RGB(255,255,255));
433 SetBkColor(gdiSystem.bmpDC, RGB(0,0,0));
434 BitBlt(gdiSystem.bmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.tmpDC, 0, 0, SRCAND);
435 SelectObject(gdiSystem.tmpDC, prevDC2);
436 SelectObject(gdiSystem.bmpDC, prevDC);
437 SetTextColor(gdiSystem.bmpDC, RGB(0,0,0));
438 SetBkColor(gdiSystem.bmpDC, RGB(255,255,255));
439 SetBkColor(gdiSystem.tmpDC, RGB(255,255,255));
445 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
448 delete bitmap.picture;
451 bitmap.driver = ((subclass(DisplayDriver))class(Win32PrinterDisplayDriver));
457 void ReleaseSurface(Display display, Surface surface)
459 Win32PrinterSurface gdiSurface = surface.driverData;
460 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
465 SelectClipRgn(gdiSurface.hdc,null);
466 DeleteObject(gdiSurface.rgn);
467 gdiSurface.rgn = null;
469 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
471 surface.driverData = null;
475 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
480 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
483 Win32PrinterDisplay gdiDisplay = display.driverData;
484 if(gdiDisplay && !gdiDisplay.completed)
486 Win32PrinterSurface gdiSurface;
487 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
489 if((surface.driverData = gdiSurface = Win32PrinterSurface { }))
491 // if(((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip))
493 gdiSurface.hdc = gdiDisplay.hdc ? gdiDisplay.hdc : gdiSystem.tmpDC;
495 gdiSurface.offset.x = x;
496 gdiSurface.offset.y = y;
497 gdiSurface.unclippedBox = gdiSurface.box = clip;
499 surface.width = gdiDisplay.width - x + 1;
500 surface.height = gdiDisplay.height - y + 1;
501 surface.offset.x = x * gdiDisplay.width / display.width;
502 surface.offset.y = y * gdiDisplay.height / display.height;
503 surface.unclippedBox = surface.box =
505 left = clip.left * gdiDisplay.width / display.width,
506 top = clip.top * gdiDisplay.height / display.height,
507 right = (clip.right+1) * gdiDisplay.width / display.width-1,
508 bottom = (clip.bottom+1) * gdiDisplay.height / display.height-1
511 gdiSurface.rgn = CreateRectRgn(
512 surface.offset.x + surface.box.left,
513 surface.offset.y + surface.box.top,
514 surface.offset.x + surface.box.right + 1,
515 surface.offset.y + surface.box.bottom + 1);
517 // x + clip.left, y+clip.top,x+clip.right+1,y+clip.bottom+1);
520 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
522 SetDCBrushColor(gdiSurface.hdc, RGB(0,0,0));
523 SetDCPenColor(gdiSurface.hdc, RGB(255,255,255));
525 SetBkColor(gdiSystem.hdc, RGB(0,0,0));
534 void Clip(Display display, Surface surface, Box clip)
536 Win32PrinterDisplay gdiDisplay = display.driverData;
537 Win32PrinterSurface gdiSurface = surface.driverData;
538 HRGN clippedRgn = null;
543 box.Clip(gdiSurface.unclippedBox);
545 gdiSurface.box = box;
548 left = box.left * gdiDisplay.width / display.width,
549 top = box.top * gdiDisplay.height / display.height,
550 right = (box.right+1) * gdiDisplay.width / display.width-1,
551 bottom = (box.bottom+1) * gdiDisplay.height / display.height-1
554 if(box.right > box.left && box.bottom > box.top)
556 box.left += gdiSurface.offset.x;
557 box.top += gdiSurface.offset.y;
558 box.right+= gdiSurface.offset.x;
559 box.bottom += gdiSurface.offset.y;
561 gdiSurface.rgn = CreateRectRgn(
562 surface.offset.x + surface.box.left,
563 surface.offset.y + surface.box.top,
564 surface.offset.x + surface.box.right + 1,
565 surface.offset.y + surface.box.bottom + 1);
567 // clippedRgn = CreateRectRgn(box.left, box.top, box.right+1, box.bottom+1);
570 clippedRgn = CreateRectRgn(0, 0, 0, 0);
573 SelectClipRgn(gdiSurface.hdc, clippedRgn);
575 else if(gdiSurface.clippedRgn)
577 surface.box = surface.unclippedBox;
578 gdiSurface.box = gdiSurface.unclippedBox;
579 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
581 if(gdiSurface.clippedRgn)
582 DeleteObject(gdiSurface.clippedRgn);
583 gdiSurface.clippedRgn = clippedRgn;
586 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
589 Win32PrinterDisplay gdiDisplay = display.driverData;
590 // result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
594 void SetForeground(Display display, Surface surface, ColorAlpha color)
596 Win32PrinterSurface gdiSurface = surface.driverData;
597 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
598 COLORREF rgb = RGB(color.color.r, color.color.g, color.color.b);
599 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
600 SetTextColor(gdiSurface.hdc, rgb);
601 gdiSurface.color = rgb;
602 SetDCPenColor(gdiSurface.hdc, rgb);
605 void SetBackground(Display display, Surface surface, ColorAlpha color)
607 Win32PrinterSurface gdiSurface = surface.driverData;
608 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
611 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
612 if(gdiSurface.bitmap.pixelFormat == pixelFormat8 && display)
613 color = gdiSurface.bitmap.palette[gdiDisplay.rgbLookup[(uint16)(Color555) color]];
615 rgb = RGB(color.color.r, color.color.g, color.color.b);
616 gdiSurface.backColor = rgb;
617 SetBkColor(gdiSurface.hdc, rgb);
618 SetDCBrushColor(gdiSurface.hdc, rgb);
621 ColorAlpha GetPixel(Display display, Surface surface, int x, int y)
626 void PutPixel(Display display, Surface surface, int x, int y)
628 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
629 Win32PrinterSurface gdiSurface = surface.driverData;
631 SetBkMode(gdiSurface.hdc, OPAQUE);
632 SetBkColor(gdiSurface.hdc, gdiSurface.color);
633 PatBlt(gdiSurface.hdc,
634 (int)((float)x * gdiDisplay.width / display.width) + surface.offset.x,
635 (int)((float)y * gdiDisplay.height / display.height) + surface.offset.y,
636 (int)((float)(x+1) * gdiDisplay.width / display.width)-1 + surface.offset.x+1,
637 (int)((float)(y+1) * gdiDisplay.height / display.height)-1 + surface.offset.y+1,
639 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
640 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
643 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
645 Win32PrinterSurface gdiSurface = surface.driverData;
646 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
649 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
650 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
651 x2 = (int)((float)x2 * gdiDisplay.width / display.width) + surface.offset.x;
652 y2 = (int)((float)y2 * gdiDisplay.height / display.height) + surface.offset.y;
653 for(c = 0; c <= (float)gdiDisplay.width / display.width; c++)
657 MoveToEx(gdiSurface.hdc, x1, y1, null);
658 LineTo(gdiSurface.hdc, x2, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
664 MoveToEx(gdiSurface.hdc, x1, y1, null);
665 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2);
671 MoveToEx(gdiSurface.hdc, x1, y1, null);
672 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
679 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
681 Win32PrinterSurface gdiSurface = surface.driverData;
682 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
686 SelectObject(gdiSurface.hdc,GetStockObject(NULL_BRUSH));
687 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
688 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
689 x2 = (int)((float)(x2) * gdiDisplay.width / display.width) + surface.offset.x;
690 y2 = (int)((float)(y2) * gdiDisplay.height / display.height) + surface.offset.y;
691 for(c = 0; c <= (float)gdiDisplay.width / display.width + 1.5; c++)
693 ::Rectangle(gdiSurface.hdc, x1, y1, x2, y2);
697 SelectObject(gdiSurface.hdc,GetStockObject(DC_BRUSH));
700 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
702 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
703 Win32PrinterSurface gdiSurface = surface.driverData;
705 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
706 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
707 x2 = (int)(((float)(x2+1) * gdiDisplay.width / display.width) + 0.5) + surface.offset.x;
708 y2 = (int)(((float)(y2+1) * gdiDisplay.height / display.height) + 0.5) + surface.offset.y;
710 SetBkMode(gdiSurface.hdc, OPAQUE);
711 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
712 SetDCBrushColor(gdiSurface.hdc, gdiSurface.backColor);
713 PatBlt(gdiSurface.hdc,x1,y1,x2-x1+1,y2-y1+1,PATCOPY);
714 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
717 void Clear(Display display, Surface surface, ClearType type)
719 Win32PrinterSurface gdiSurface = surface.driverData;
720 if(type != depthBuffer)
721 Area(display, surface, gdiSurface.box.left, gdiSurface.box.top, gdiSurface.box.right, gdiSurface.box.bottom);
724 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
729 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
734 void Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
736 Filter(display, surface, src, dx, dy, sx, sy, w, h, w, h);
739 void Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
741 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
744 void Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
746 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
747 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
748 Win32PrinterBitmap gdiBitmap = src.driverData;
749 Win32PrinterSurface gdiSurface = surface.driverData;
753 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
754 SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
756 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
758 SetBkColor(gdiSurface.hdc, 0xFFFFFF);
759 SetTextColor(gdiSurface.hdc, 0);
760 StretchBlt(gdiSurface.hdc,
761 dx * gdiDisplay.width / display.width + surface.offset.x,
762 dy * gdiDisplay.height / display.height + surface.offset.y,
763 (w) * gdiDisplay.width / display.width,
764 (h) * gdiDisplay.height / display.height,
765 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
766 StretchBlt(gdiSurface.hdc,
767 dx * gdiDisplay.width / display.width + surface.offset.x,
768 dy * gdiDisplay.height / display.height + surface.offset.y,
769 (w) * gdiDisplay.width / display.width,
770 (h) * gdiDisplay.height / display.height,
771 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
773 StretchBlt(gdiSurface.hdc,
774 dx * gdiDisplay.width / display.width + surface.offset.x,
775 dy * gdiDisplay.height / display.height + surface.offset.y,
776 (w+1) * gdiDisplay.width / display.width-1,
777 (h+1) * gdiDisplay.height / display.height-1,
778 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
779 StretchBlt(gdiSurface.hdc,
780 dx * gdiDisplay.width / display.width + surface.offset.x,
781 dy * gdiDisplay.height / display.height + surface.offset.y,
782 (w+1) * gdiDisplay.width / display.width-1,
783 (h+1) * gdiDisplay.height / display.height-1,
784 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
786 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
790 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
791 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
792 StretchBlt(gdiSurface.hdc,
793 dx * gdiDisplay.width / display.width + surface.offset.x,
794 dy * gdiDisplay.height / display.height + surface.offset.y,
795 (w+1) * gdiDisplay.width / display.width-1,
796 (h+1) * gdiDisplay.height / display.height-1,
797 gdiSystem.bmpDC, sx, sy,sw,sh, SRCCOPY);
801 void BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
803 Blit(display,surface,src,dx,dy,sx,sy,w,h);
806 void StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
808 Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
811 void FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
813 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
816 Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
818 Win32PrinterSystem gdiSystem = displaySystem.driverData;
819 HDC hdc = gdiSystem.hdc;
823 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
824 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
825 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
828 pixels = GetDeviceCaps(hdc, VERTRES);
829 res = GetDeviceCaps(hdc, LOGPIXELSY);
832 s = -(int)(((float)size * res / 78) + 0.5);
834 // font = CreateFont(-(int)(((float)size * 96 / 72) + 0.5),
836 // font = CreateFont(-(int)(((float)size * pixels * RESY / res / 72) + 0.5),
837 0,0,0, flags.bold ? FW_BOLD : FW_NORMAL, flags.italic ? TRUE : FALSE,
838 flags.underline ? TRUE : FALSE, 0, DEFAULT_CHARSET,
839 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
840 DEFAULT_PITCH|FF_DONTCARE, faceName);
842 // SetMapMode(gdiSystem.hdc, MM_TEXT);
846 void UnloadFont(DisplaySystem displaySystem, Font font)
852 void TextFont(Display display, Surface surface, Font font)
854 Win32PrinterSurface gdiSurface = surface.driverData;
855 SelectObject(gdiSurface.hdc, font);
858 void TextOpacity(Display display, Surface surface, bool opaque)
860 Win32PrinterSurface gdiSurface = surface.driverData;
861 SetBkMode(gdiSurface.hdc, opaque ? OPAQUE : TRANSPARENT);
864 void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
866 Win32PrinterSurface gdiSurface = surface.driverData;
867 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
869 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
872 SetMapMode(gdiSurface.hdc, MM_ANISOTROPIC);
873 SetWindowExtEx(gdiSurface.hdc, RESX, RESY, null);
874 SetViewportExtEx(gdiSurface.hdc, GetDeviceCaps(gdiSurface.hdc, HORZRES), GetDeviceCaps(gdiSurface.hdc, VERTRES), null);
876 TextOut(gdiSurface.hdc, x * gdiDisplay.width / display.width + surface.offset.x, y * gdiDisplay.height / display.height + surface.offset.y, u16text, wordCount);
878 TextOut(gdiSurface.hdc, x + gdiSurface.offset.x, y + gdiSurface.offset.y, text,len);
879 SetMapMode(gdiSurface.hdc, MM_TEXT);
884 void ::_TextExtent(HDC hdc, int resX, int resY, char * text, int len, int * width, int * height)
889 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
891 for(realLen = 0; realLen<wordCount && u16text[realLen]; realLen++);
892 GetTextExtentPoint32(hdc, " ", 1, &space);
893 GetTextExtentPoint32(hdc, u16text, realLen, &size);
898 // UNICODE FIX: proper space computation
899 *width = size.cx + (wordCount - realLen) * space.cx;
900 *width = *width * resX / GetDeviceCaps(hdc, HORZRES);
907 *height = len ? space.cy : 0;
908 *height = *height * resY / GetDeviceCaps(hdc, VERTRES);
912 void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
914 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
915 Win32PrinterSystem gdiSystem = (display && display.displaySystem) ? display.displaySystem.driverData : null;
916 Win32PrinterSurface gdiSurface = surface.driverData;
918 _TextExtent(gdiSurface.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
921 void FontExtent(DisplaySystem displaySystem, void * font, char * text, int len, int * width, int * height)
923 Win32PrinterSystem gdiSystem = displaySystem.driverData;
926 SelectObject(gdiSystem.hdc, font);
927 _TextExtent(gdiSystem.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
931 if(width) *width = 0;
932 if(height) *height = 0;
936 void DrawingChar(Display display, Surface surface, byte character)
941 void LineStipple(Display display, Surface surface, uint stipple)
943 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
944 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
947 bool Lock(Display display)
952 void Unlock(Display display)