1 namespace gfx::drivers;
8 #define _WIN32_WINNT 0x0500
9 #define WIN32_LEAN_AND_MEAN
11 #define Method _Method
12 #define String _String
13 #define strlen _strlen
20 default wchar_t *wcstok(wchar_t *strToken,const wchar_t *strDelimit);
24 //static char szMessage[]= L"Printing ECERE Document...";
25 static char szMessage[]= "Printing ECERE Document...";
28 static define RESX = 850;
29 static define RESY = 1100;
32 class Win32PrinterDisplay : struct
35 LOGPALETTE * logPalette;
44 ~Win32PrinterDisplay()
46 //if(memDC) DeleteDC(memDC);
47 //if(memBitmap) DeleteObject(memBitmap);
48 if(palette) DeleteObject(palette);
53 static byte defaultRGBLookup[32768];
54 static bool rgbLookupSet = false;
56 class Win32PrinterSystem : struct
61 int resX, resY; // Save the display here, support only one display at a time
69 class Win32PrinterSurface : struct
73 COLORREF color, backColor;
76 Box box, unclippedBox;
79 class Win32PrinterBitmap : struct
85 static PixelFormat GetColorFormat(int depth)
90 return pixelFormat555;
92 return pixelFormat888;
95 class Win32PrinterDisplayDriver : DisplayDriver
97 class_property(name) = "Win32Printer";
98 class_property(printer) = bool::true;
100 bool CreateDisplaySystem(DisplaySystem displaySystem)
102 Win32PrinterSystem gdiSystem = displaySystem.driverData = Win32PrinterSystem { };
103 return true; //false;
106 void DestroyDisplaySystem(DisplaySystem displaySystem)
108 Win32PrinterSystem gdiSystem = displaySystem.driverData;
109 DeleteDC(gdiSystem.tmpDC);
110 DeleteDC(gdiSystem.bmpDC);
111 DeleteDC(gdiSystem.hdc);
112 displaySystem.driverData = null;
116 void DestroyDisplay(Display display)
118 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
119 Win32PrinterDisplay gdiDisplay = display.driverData;
122 EndPage(gdiDisplay.hdc);
123 Escape(gdiDisplay.hdc, ENDDOC, 0, null, null);
126 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
128 display.driverData = null;
132 DeleteDC(gdiSystem.tmpDC);
133 DeleteDC(gdiSystem.bmpDC);
134 DeleteDC(gdiSystem.hdc);
138 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
140 Win32PrinterDisplay gdiDisplay = display.driverData;
141 if(display.displaySystem.pixelFormat == pixelFormat8)
144 ColorAlpha realPalette[256];
145 int reserved = (display.flags.fullScreen) ? 1 : 10;
146 HDC hdc = gdiDisplay.hdc;
151 GetSystemPaletteEntries(hdc,0,256,(PALETTEENTRY *)realPalette);
152 for(c = 0; c<256; c++)
153 realPalette[c] = RGB(realPalette[c].color.r, realPalette[c].color.g, realPalette[c].color.b);
155 // *** Reserved Palette Handling ***
158 palette = GetDefaultPalette();
159 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
161 for(c = 0; c<32768; c++)
162 defaultRGBLookup[c] = (byte)BestColorMatch(realPalette, 1,255, (Color555)c);
164 CopyBytes(gdiDisplay.rgbLookup, defaultRGBLookup, 32768);
168 for(i=0; i<LIGHTSTEPS; i++)
170 gdiDisplay.lightTable[c][i]=gdiDisplay.rgbLookup[(uint16)Color555 {
171 (byte)(((uint16)realPalette[c].color.r*i) >> LIGHTSHIFT),
172 (byte)(((uint16)realPalette[c].color.g*i) >> LIGHTSHIFT),
173 (byte)(((uint16)realPalette[c].color.b*i) >> LIGHTSHIFT) }];
176 CopyBytesBy4(gdiDisplay.bitmap.palette, realPalette, 256);
181 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
182 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, realPalette, colorMatch);
186 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);*/
187 // *********************************
189 gdiDisplay.logPalette->palVersion = 0x300;
190 gdiDisplay.logPalette->palNumEntries = 256;
192 for(c = 0; c < 256; c++)
194 gdiDisplay.logPalette->palPalEntry[c].peFlags = PC_NOCOLLAPSE;
195 gdiDisplay.logPalette->palPalEntry[c].peRed = realPalette[c].color.r;
196 gdiDisplay.logPalette->palPalEntry[c].peGreen = realPalette[c].color.g;
197 gdiDisplay.logPalette->palPalEntry[c].peBlue = realPalette[c].color.b;
200 if(!gdiDisplay.palette)
201 gdiDisplay.palette = CreatePalette(gdiDisplay.logPalette);
203 SetPaletteEntries(gdiDisplay.palette, 0, 256, gdiDisplay.logPalette->palPalEntry);
205 SelectPalette(hdc, gdiDisplay.palette, FALSE);
208 // SetDIBColorTable(gdiDisplay.hdc, 0, 256, (RGBQUAD *)gdiDisplay.bitmap.palette);
213 bool CreateDisplay(Display display)
215 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
220 Win32PrinterDisplay gdiDisplay = display.driverData = Win32PrinterDisplay { };
221 if((gdiDisplay.logPalette = (LOGPALETTE *)new0 byte[sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*256]) /*&&
222 ((subclass(DisplayDriver))class(LFBDisplayDriver)).CreateDisplay(display)*/)
230 bool DisplaySize(Display display, int width, int height)
232 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
233 Win32PrinterDisplay gdiDisplay = display.driverData;
235 HDC hdc = gdiSystem.hdc;
237 if(!width || !height)
243 uint16 szPrinter[160];
244 uint16 *szDevice, *szDriver, *szOutput;
246 GetProfileString(L"windows", L"device", L"...", (char *)szPrinter, 160);
247 szDevice = wcstok(szPrinter, L",");
248 szDriver = wcstok(null, L",");
249 szOutput = wcstok(null, L",");
250 if(szDevice && szDriver && szOutput)
252 DEVMODE * devMode = null;
253 HANDLE hPrinter = null;
255 OpenPrinter(szPrinter, &hPrinter, null);
256 size = DocumentProperties(null, hPrinter, szDevice, null, null, 0);
257 devMode = (DEVMODE *)new0 byte[size];
258 DocumentProperties(null, hPrinter, szDevice, devMode, null, DM_OUT_BUFFER);
259 devMode->dmOrientation = (width > height) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
260 DocumentProperties(null, hPrinter, szDevice, devMode, devMode, DM_IN_BUFFER|DM_OUT_BUFFER);
261 gdiSystem.hdc = CreateDC(szDriver, szDevice, szOutput, devMode);
263 ClosePrinter(hPrinter);
266 gdiSystem.tmpDC = CreateCompatibleDC(gdiSystem.hdc);
267 gdiSystem.bmpDC = CreateCompatibleDC(gdiSystem.hdc);
268 gdiSystem.depth = GetDeviceCaps(gdiSystem.hdc, BITSPIXEL);
269 gdiSystem.depth = 32;
270 display.displaySystem.pixelFormat = GetColorFormat(gdiSystem.depth);
273 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
274 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
275 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
277 SetMapMode(gdiSystem.hdc, MM_TEXT);
280 String docName = printingDocumentName ? printingDocumentName : szMessage;
281 char curDir[MAX_LOCATION];
282 GetWorkingDir(curDir, MAX_LOCATION);
284 if(Escape(gdiSystem.hdc, STARTDOC, strlen(docName), docName, null ) > 0)
286 StartPage(gdiSystem.hdc);
289 ChangeWorkingDir(curDir);
292 //displaySystem.flags.memBackBuffer = true;
296 gdiDisplay.hdc = gdiSystem.hdc;
297 gdiDisplay.width = GetDeviceCaps(hdc, HORZRES);
298 gdiDisplay.height = GetDeviceCaps(hdc, VERTRES);
300 gdiSystem.resX = display.width = width;
301 gdiSystem.resY = display.height = height;
303 SelectObject(gdiDisplay.hdc,GetStockObject(DC_PEN));
304 SelectObject(gdiDisplay.hdc,GetStockObject(DC_BRUSH));
305 SetBkMode(gdiDisplay.hdc, TRANSPARENT);
311 void DisplayPosition(Display display, int x, int y)
313 Win32PrinterDisplay gdiDisplay = display.driverData;
314 gdiDisplay.offset.x = x;
315 gdiDisplay.offset.y = y;
319 void RestorePalette(Display display)
321 Win32PrinterDisplay gdiDisplay = display.driverData;
322 HDC hdc = gdiDisplay.hdc;
325 if(gdiDisplay.palette)
327 SelectPalette(hdc, gdiDisplay.palette, FALSE);
333 #define MAX_EXPOSED 50
335 void StartUpdate(Display display)
337 Win32PrinterDisplay gdiDisplay = display.driverData;
338 if(gdiDisplay && !gdiDisplay.completed)
340 GdiSetBatchLimit(1000);
342 gdiDisplay.rgn = CreateRectRgn(0,0,0,0);
343 gdiDisplay.data = (RGNDATA *) new0 byte[sizeof(RGNDATAHEADER) + sizeof(RECT) * MAX_EXPOSED];
344 if(gdiDisplay.palette)
345 SelectPalette(gdiDisplay.hdc, gdiDisplay.palette, FALSE);
349 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
354 void Update(Display display, Box updateBox)
359 void EndUpdate(Display display)
361 Win32PrinterDisplay gdiDisplay = display.driverData;
362 if(gdiDisplay && !gdiDisplay.completed)
364 DeleteObject(gdiDisplay.rgn);
365 delete gdiDisplay.data;
366 gdiDisplay.data = null;
367 gdiDisplay.completed = true;
371 void NextPage(Display display)
373 Win32PrinterDisplay gdiDisplay = display.driverData;
374 gdiDisplay.completed = false;
375 EndPage(gdiDisplay.hdc);
376 StartPage(gdiDisplay.hdc);
379 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
381 // (((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
382 Win32PrinterBitmap gdiBitmap = bitmap.driverData;
385 DeleteDC(gdiBitmap.memDC);
387 DeleteObject(gdiBitmap.mask);
389 DeleteObject(gdiBitmap.bmp);
390 delete (Win32PrinterBitmap)gdiBitmap;
391 bitmap.driverData = null;
392 bitmap.driver = null;
395 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
397 // return (((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
399 if(bitmap.Convert(null, pixelFormat888, null))
401 Win32PrinterSystem gdiSystem = displaySystem.driverData;
402 Win32PrinterBitmap gdiBitmap = bitmap.driverData = Win32PrinterBitmap { };
403 BITMAPINFO * info = new0 BITMAPINFO[1];
404 if(!info) return false;
406 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
407 info->bmiHeader.biPlanes = 1;
408 info->bmiHeader.biWidth = bitmap.width;
409 info->bmiHeader.biHeight = -bitmap.height;
410 info->bmiHeader.biBitCount = 32;
411 // If transparent, we need to create a black mask for the little GDI trick
412 if(bitmap.transparent)
415 HGDIOBJ prevDC, prevDC2;
417 mask.Allocate(null, bitmap.width, bitmap.height, 0, pixelFormat888, false);
418 for(c = 0; c<bitmap.width * bitmap.height; c++)
419 ((Color *)mask.picture)[c] = ((ColorAlpha *)bitmap.picture)[c].a ? 0xFFFFFF : 0;
421 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, mask.picture, info, DIB_RGB_COLORS);
422 gdiBitmap.mask = CreateBitmap(bitmap.width, bitmap.height, 1, 1, null);
423 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
424 prevDC2 = SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
425 SetBkColor(gdiSystem.bmpDC, 0);
426 BitBlt(gdiSystem.tmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.bmpDC, 0, 0, SRCCOPY);
427 SetBkColor(gdiSystem.bmpDC, 0);
428 SetTextColor(gdiSystem.bmpDC, 0xFFFFFF);
430 SelectObject(gdiSystem.bmpDC, prevDC);
431 DeleteObject(gdiBitmap.bmp);
433 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
434 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
437 SetTextColor(gdiSystem.bmpDC, RGB(255,255,255));
438 SetBkColor(gdiSystem.bmpDC, RGB(0,0,0));
439 BitBlt(gdiSystem.bmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.tmpDC, 0, 0, SRCAND);
440 SelectObject(gdiSystem.tmpDC, prevDC2);
441 SelectObject(gdiSystem.bmpDC, prevDC);
442 SetTextColor(gdiSystem.bmpDC, RGB(0,0,0));
443 SetBkColor(gdiSystem.bmpDC, RGB(255,255,255));
444 SetBkColor(gdiSystem.tmpDC, RGB(255,255,255));
450 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
453 delete bitmap.picture;
456 bitmap.driver = ((subclass(DisplayDriver))class(Win32PrinterDisplayDriver));
462 void ReleaseSurface(Display display, Surface surface)
464 Win32PrinterSurface gdiSurface = surface.driverData;
465 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
470 SelectClipRgn(gdiSurface.hdc,null);
471 DeleteObject(gdiSurface.rgn);
472 gdiSurface.rgn = null;
474 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
476 surface.driverData = null;
480 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
485 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
488 Win32PrinterDisplay gdiDisplay = display.driverData;
489 if(gdiDisplay && !gdiDisplay.completed)
491 Win32PrinterSurface gdiSurface;
492 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
494 if((surface.driverData = gdiSurface = Win32PrinterSurface { }))
496 // if(((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip))
498 gdiSurface.hdc = gdiDisplay.hdc ? gdiDisplay.hdc : gdiSystem.tmpDC;
500 gdiSurface.offset.x = x;
501 gdiSurface.offset.y = y;
502 gdiSurface.unclippedBox = gdiSurface.box = clip;
504 surface.width = gdiDisplay.width - x + 1;
505 surface.height = gdiDisplay.height - y + 1;
506 surface.offset.x = x * gdiDisplay.width / display.width;
507 surface.offset.y = y * gdiDisplay.height / display.height;
508 surface.unclippedBox = surface.box =
510 left = clip.left * gdiDisplay.width / display.width,
511 top = clip.top * gdiDisplay.height / display.height,
512 right = (clip.right+1) * gdiDisplay.width / display.width-1,
513 bottom = (clip.bottom+1) * gdiDisplay.height / display.height-1
516 gdiSurface.rgn = CreateRectRgn(
517 surface.offset.x + surface.box.left,
518 surface.offset.y + surface.box.top,
519 surface.offset.x + surface.box.right + 1,
520 surface.offset.y + surface.box.bottom + 1);
522 // x + clip.left, y+clip.top,x+clip.right+1,y+clip.bottom+1);
525 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
527 SetDCBrushColor(gdiSurface.hdc, RGB(0,0,0));
528 SetDCPenColor(gdiSurface.hdc, RGB(255,255,255));
530 SetBkColor(gdiSystem.hdc, RGB(0,0,0));
539 void Clip(Display display, Surface surface, Box clip)
541 Win32PrinterDisplay gdiDisplay = display.driverData;
542 Win32PrinterSurface gdiSurface = surface.driverData;
543 HRGN clippedRgn = null;
548 box.Clip(gdiSurface.unclippedBox);
550 gdiSurface.box = box;
553 left = box.left * gdiDisplay.width / display.width,
554 top = box.top * gdiDisplay.height / display.height,
555 right = (box.right+1) * gdiDisplay.width / display.width-1,
556 bottom = (box.bottom+1) * gdiDisplay.height / display.height-1
559 if(box.right > box.left && box.bottom > box.top)
561 box.left += gdiSurface.offset.x;
562 box.top += gdiSurface.offset.y;
563 box.right+= gdiSurface.offset.x;
564 box.bottom += gdiSurface.offset.y;
566 gdiSurface.rgn = CreateRectRgn(
567 surface.offset.x + surface.box.left,
568 surface.offset.y + surface.box.top,
569 surface.offset.x + surface.box.right + 1,
570 surface.offset.y + surface.box.bottom + 1);
572 // clippedRgn = CreateRectRgn(box.left, box.top, box.right+1, box.bottom+1);
575 clippedRgn = CreateRectRgn(0, 0, 0, 0);
578 SelectClipRgn(gdiSurface.hdc, clippedRgn);
580 else if(gdiSurface.clippedRgn)
582 surface.box = surface.unclippedBox;
583 gdiSurface.box = gdiSurface.unclippedBox;
584 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
586 if(gdiSurface.clippedRgn)
587 DeleteObject(gdiSurface.clippedRgn);
588 gdiSurface.clippedRgn = clippedRgn;
591 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
594 Win32PrinterDisplay gdiDisplay = display.driverData;
595 // result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
599 void SetForeground(Display display, Surface surface, ColorAlpha color)
601 Win32PrinterSurface gdiSurface = surface.driverData;
602 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
603 COLORREF rgb = RGB(color.color.r, color.color.g, color.color.b);
604 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
605 SetTextColor(gdiSurface.hdc, rgb);
606 gdiSurface.color = rgb;
607 SetDCPenColor(gdiSurface.hdc, rgb);
610 void SetBackground(Display display, Surface surface, ColorAlpha color)
612 Win32PrinterSurface gdiSurface = surface.driverData;
613 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
616 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
617 if(gdiSurface.bitmap.pixelFormat == pixelFormat8 && display)
618 color = gdiSurface.bitmap.palette[gdiDisplay.rgbLookup[(uint16)(Color555) color]];
620 rgb = RGB(color.color.r, color.color.g, color.color.b);
621 gdiSurface.backColor = rgb;
622 SetBkColor(gdiSurface.hdc, rgb);
623 SetDCBrushColor(gdiSurface.hdc, rgb);
626 ColorAlpha GetPixel(Display display, Surface surface, int x, int y)
631 void PutPixel(Display display, Surface surface, int x, int y)
633 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
634 Win32PrinterSurface gdiSurface = surface.driverData;
636 SetBkMode(gdiSurface.hdc, OPAQUE);
637 SetBkColor(gdiSurface.hdc, gdiSurface.color);
638 PatBlt(gdiSurface.hdc,
639 (int)((float)x * gdiDisplay.width / display.width) + surface.offset.x,
640 (int)((float)y * gdiDisplay.height / display.height) + surface.offset.y,
641 (int)((float)(x+1) * gdiDisplay.width / display.width)-1 + surface.offset.x+1,
642 (int)((float)(y+1) * gdiDisplay.height / display.height)-1 + surface.offset.y+1,
644 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
645 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
648 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
650 Win32PrinterSurface gdiSurface = surface.driverData;
651 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
654 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
655 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
656 x2 = (int)((float)x2 * gdiDisplay.width / display.width) + surface.offset.x;
657 y2 = (int)((float)y2 * gdiDisplay.height / display.height) + surface.offset.y;
658 for(c = 0; c <= (float)gdiDisplay.width / display.width; c++)
662 MoveToEx(gdiSurface.hdc, x1, y1, null);
663 LineTo(gdiSurface.hdc, x2, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
669 MoveToEx(gdiSurface.hdc, x1, y1, null);
670 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2);
676 MoveToEx(gdiSurface.hdc, x1, y1, null);
677 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
684 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
686 Win32PrinterSurface gdiSurface = surface.driverData;
687 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
691 SelectObject(gdiSurface.hdc,GetStockObject(NULL_BRUSH));
692 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
693 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
694 x2 = (int)((float)(x2) * gdiDisplay.width / display.width) + surface.offset.x;
695 y2 = (int)((float)(y2) * gdiDisplay.height / display.height) + surface.offset.y;
696 for(c = 0; c <= (float)gdiDisplay.width / display.width + 1.5; c++)
698 ::Rectangle(gdiSurface.hdc, x1, y1, x2, y2);
702 SelectObject(gdiSurface.hdc,GetStockObject(DC_BRUSH));
705 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
707 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
708 Win32PrinterSurface gdiSurface = surface.driverData;
710 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
711 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
712 x2 = (int)(((float)(x2+1) * gdiDisplay.width / display.width) + 0.5) + surface.offset.x;
713 y2 = (int)(((float)(y2+1) * gdiDisplay.height / display.height) + 0.5) + surface.offset.y;
715 SetBkMode(gdiSurface.hdc, OPAQUE);
716 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
717 SetDCBrushColor(gdiSurface.hdc, gdiSurface.backColor);
718 PatBlt(gdiSurface.hdc,x1,y1,x2-x1+1,y2-y1+1,PATCOPY);
719 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
722 void Clear(Display display, Surface surface, ClearType type)
724 Win32PrinterSurface gdiSurface = surface.driverData;
725 if(type != depthBuffer)
726 Area(display, surface, gdiSurface.box.left, gdiSurface.box.top, gdiSurface.box.right, gdiSurface.box.bottom);
729 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
734 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
739 void Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
741 Filter(display, surface, src, dx, dy, sx, sy, w, h, w, h);
744 void Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
746 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
749 void Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
751 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
752 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
753 Win32PrinterBitmap gdiBitmap = src.driverData;
754 Win32PrinterSurface gdiSurface = surface.driverData;
758 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
759 SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
761 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
763 SetBkColor(gdiSurface.hdc, 0xFFFFFF);
764 SetTextColor(gdiSurface.hdc, 0);
765 StretchBlt(gdiSurface.hdc,
766 dx * gdiDisplay.width / display.width + surface.offset.x,
767 dy * gdiDisplay.height / display.height + surface.offset.y,
768 (w) * gdiDisplay.width / display.width,
769 (h) * gdiDisplay.height / display.height,
770 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
771 StretchBlt(gdiSurface.hdc,
772 dx * gdiDisplay.width / display.width + surface.offset.x,
773 dy * gdiDisplay.height / display.height + surface.offset.y,
774 (w) * gdiDisplay.width / display.width,
775 (h) * gdiDisplay.height / display.height,
776 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
778 StretchBlt(gdiSurface.hdc,
779 dx * gdiDisplay.width / display.width + surface.offset.x,
780 dy * gdiDisplay.height / display.height + surface.offset.y,
781 (w+1) * gdiDisplay.width / display.width-1,
782 (h+1) * gdiDisplay.height / display.height-1,
783 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
784 StretchBlt(gdiSurface.hdc,
785 dx * gdiDisplay.width / display.width + surface.offset.x,
786 dy * gdiDisplay.height / display.height + surface.offset.y,
787 (w+1) * gdiDisplay.width / display.width-1,
788 (h+1) * gdiDisplay.height / display.height-1,
789 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
791 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
795 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
796 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
797 StretchBlt(gdiSurface.hdc,
798 dx * gdiDisplay.width / display.width + surface.offset.x,
799 dy * gdiDisplay.height / display.height + surface.offset.y,
800 (w+1) * gdiDisplay.width / display.width-1,
801 (h+1) * gdiDisplay.height / display.height-1,
802 gdiSystem.bmpDC, sx, sy,sw,sh, SRCCOPY);
806 void BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
808 Blit(display,surface,src,dx,dy,sx,sy,w,h);
811 void StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
813 Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
816 void FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
818 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
821 Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
823 Win32PrinterSystem gdiSystem = displaySystem.driverData;
824 HDC hdc = gdiSystem.hdc;
828 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
829 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
830 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
833 pixels = GetDeviceCaps(hdc, VERTRES);
834 res = GetDeviceCaps(hdc, LOGPIXELSY);
837 s = -(int)(((float)size * res / 78) + 0.5);
839 // font = CreateFont(-(int)(((float)size * 96 / 72) + 0.5),
841 // font = CreateFont(-(int)(((float)size * pixels * RESY / res / 72) + 0.5),
842 0,0,0, flags.bold ? FW_BOLD : FW_NORMAL, flags.italic ? TRUE : FALSE,
843 flags.underline ? TRUE : FALSE, 0, DEFAULT_CHARSET,
844 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
845 DEFAULT_PITCH|FF_DONTCARE, faceName);
847 // SetMapMode(gdiSystem.hdc, MM_TEXT);
851 void UnloadFont(DisplaySystem displaySystem, Font font)
857 void TextFont(Display display, Surface surface, Font font)
859 Win32PrinterSurface gdiSurface = surface.driverData;
860 SelectObject(gdiSurface.hdc, font);
863 void TextOpacity(Display display, Surface surface, bool opaque)
865 Win32PrinterSurface gdiSurface = surface.driverData;
866 SetBkMode(gdiSurface.hdc, opaque ? OPAQUE : TRANSPARENT);
869 void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
871 Win32PrinterSurface gdiSurface = surface.driverData;
872 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
874 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
877 SetMapMode(gdiSurface.hdc, MM_ANISOTROPIC);
878 SetWindowExtEx(gdiSurface.hdc, RESX, RESY, null);
879 SetViewportExtEx(gdiSurface.hdc, GetDeviceCaps(gdiSurface.hdc, HORZRES), GetDeviceCaps(gdiSurface.hdc, VERTRES), null);
881 TextOut(gdiSurface.hdc, x * gdiDisplay.width / display.width + surface.offset.x, y * gdiDisplay.height / display.height + surface.offset.y, u16text, wordCount);
883 TextOut(gdiSurface.hdc, x + gdiSurface.offset.x, y + gdiSurface.offset.y, text,len);
884 SetMapMode(gdiSurface.hdc, MM_TEXT);
889 void ::_TextExtent(HDC hdc, int resX, int resY, char * text, int len, int * width, int * height)
894 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
896 for(realLen = 0; realLen<wordCount && u16text[realLen]; realLen++);
897 GetTextExtentPoint32(hdc, " ", 1, &space);
898 GetTextExtentPoint32(hdc, u16text, realLen, &size);
903 // UNICODE FIX: proper space computation
904 *width = size.cx + (wordCount - realLen) * space.cx;
905 *width = *width * resX / GetDeviceCaps(hdc, HORZRES);
912 *height = len ? space.cy : 0;
913 *height = *height * resY / GetDeviceCaps(hdc, VERTRES);
917 void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
919 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
920 Win32PrinterSystem gdiSystem = (display && display.displaySystem) ? display.displaySystem.driverData : null;
921 Win32PrinterSurface gdiSurface = surface.driverData;
923 _TextExtent(gdiSurface.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
926 void FontExtent(DisplaySystem displaySystem, void * font, char * text, int len, int * width, int * height)
928 Win32PrinterSystem gdiSystem = displaySystem.driverData;
931 SelectObject(gdiSystem.hdc, font);
932 _TextExtent(gdiSystem.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
936 if(width) *width = 0;
937 if(height) *height = 0;
941 void DrawingChar(Display display, Surface surface, byte character)
946 void LineStipple(Display display, Surface surface, uint stipple)
948 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
949 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
952 bool Lock(Display display)
957 void Unlock(Display display)