1 namespace gfx::drivers;
7 #define _WIN32_WINNT 0x0500
8 #define WIN32_LEAN_AND_MEAN
10 #define Method _Method
11 #define String _String
17 default wchar_t *wcstok(wchar_t *strToken,const wchar_t *strDelimit);
21 //static char szMessage[]= L"Printing ECERE Document...";
22 static char szMessage[]= "Printing ECERE Document...";
25 static define RESX = 850;
26 static define RESY = 1100;
29 class Win32PrinterDisplay : struct
32 LOGPALETTE * logPalette;
41 ~Win32PrinterDisplay()
43 //if(memDC) DeleteDC(memDC);
44 //if(memBitmap) DeleteObject(memBitmap);
45 if(palette) DeleteObject(palette);
50 static byte defaultRGBLookup[32768];
51 static bool rgbLookupSet = false;
53 class Win32PrinterSystem : struct
58 int resX, resY; // Save the display here, support only one display at a time
66 class Win32PrinterSurface : struct
70 COLORREF color, backColor;
73 Box box, unclippedBox;
76 class Win32PrinterBitmap : struct
82 static PixelFormat GetColorFormat(int depth)
87 return pixelFormat555;
89 return pixelFormat888;
92 class Win32PrinterDisplayDriver : DisplayDriver
94 class_property(name) = "Win32Printer";
95 class_property(printer) = bool::true;
97 bool CreateDisplaySystem(DisplaySystem displaySystem)
99 Win32PrinterSystem gdiSystem = displaySystem.driverData = Win32PrinterSystem { };
100 return true; //false;
103 void DestroyDisplaySystem(DisplaySystem displaySystem)
105 Win32PrinterSystem gdiSystem = displaySystem.driverData;
106 DeleteDC(gdiSystem.tmpDC);
107 DeleteDC(gdiSystem.bmpDC);
108 DeleteDC(gdiSystem.hdc);
109 displaySystem.driverData = null;
113 void DestroyDisplay(Display display)
115 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
116 Win32PrinterDisplay gdiDisplay = display.driverData;
119 EndPage(gdiDisplay.hdc);
120 Escape(gdiDisplay.hdc, ENDDOC, 0, null, null);
123 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
125 display.driverData = null;
129 DeleteDC(gdiSystem.tmpDC);
130 DeleteDC(gdiSystem.bmpDC);
131 DeleteDC(gdiSystem.hdc);
135 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
137 Win32PrinterDisplay gdiDisplay = display.driverData;
138 if(display.displaySystem.pixelFormat == pixelFormat8)
141 ColorAlpha realPalette[256];
142 int reserved = (display.flags.fullScreen) ? 1 : 10;
143 HDC hdc = gdiDisplay.hdc;
148 GetSystemPaletteEntries(hdc,0,256,(PALETTEENTRY *)realPalette);
149 for(c = 0; c<256; c++)
150 realPalette[c] = RGB(realPalette[c].color.r, realPalette[c].color.g, realPalette[c].color.b);
152 // *** Reserved Palette Handling ***
155 palette = GetDefaultPalette();
156 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
158 for(c = 0; c<32768; c++)
159 defaultRGBLookup[c] = (byte)BestColorMatch(realPalette, 1,255, (Color555)c);
161 CopyBytes(gdiDisplay.rgbLookup, defaultRGBLookup, 32768);
165 for(i=0; i<LIGHTSTEPS; i++)
167 gdiDisplay.lightTable[c][i]=gdiDisplay.rgbLookup[(uint16)Color555 {
168 (byte)(((uint16)realPalette[c].color.r*i) >> LIGHTSHIFT),
169 (byte)(((uint16)realPalette[c].color.g*i) >> LIGHTSHIFT),
170 (byte)(((uint16)realPalette[c].color.b*i) >> LIGHTSHIFT) }];
173 CopyBytesBy4(gdiDisplay.bitmap.palette, realPalette, 256);
178 CopyBytesBy4(realPalette+reserved,palette+reserved,256-2*reserved);
179 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, realPalette, colorMatch);
183 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);*/
184 // *********************************
186 gdiDisplay.logPalette->palVersion = 0x300;
187 gdiDisplay.logPalette->palNumEntries = 256;
189 for(c = 0; c < 256; c++)
191 gdiDisplay.logPalette->palPalEntry[c].peFlags = PC_NOCOLLAPSE;
192 gdiDisplay.logPalette->palPalEntry[c].peRed = realPalette[c].color.r;
193 gdiDisplay.logPalette->palPalEntry[c].peGreen = realPalette[c].color.g;
194 gdiDisplay.logPalette->palPalEntry[c].peBlue = realPalette[c].color.b;
197 if(!gdiDisplay.palette)
198 gdiDisplay.palette = CreatePalette(gdiDisplay.logPalette);
200 SetPaletteEntries(gdiDisplay.palette, 0, 256, gdiDisplay.logPalette->palPalEntry);
202 SelectPalette(hdc, gdiDisplay.palette, FALSE);
205 // SetDIBColorTable(gdiDisplay.hdc, 0, 256, (RGBQUAD *)gdiDisplay.bitmap.palette);
210 bool CreateDisplay(Display display)
212 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
217 Win32PrinterDisplay gdiDisplay = display.driverData = Win32PrinterDisplay { };
218 if((gdiDisplay.logPalette = (LOGPALETTE *)new0 byte[sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*256]) /*&&
219 ((subclass(DisplayDriver))class(LFBDisplayDriver)).CreateDisplay(display)*/)
227 bool DisplaySize(Display display, int width, int height)
229 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
230 Win32PrinterDisplay gdiDisplay = display.driverData;
232 HDC hdc = gdiSystem.hdc;
234 if(!width || !height)
240 uint16 szPrinter[160];
241 uint16 *szDevice, *szDriver, *szOutput;
243 GetProfileString(L"windows", L"device", L"...", (char *)szPrinter, 160);
244 szDevice = wcstok(szPrinter, L",");
245 szDriver = wcstok(null, L",");
246 szOutput = wcstok(null, L",");
247 if(szDevice && szDriver && szOutput)
249 DEVMODE * devMode = null;
250 HANDLE hPrinter = null;
252 OpenPrinter(szPrinter, &hPrinter, null);
253 size = DocumentProperties(null, hPrinter, szDevice, null, null, 0);
254 devMode = (DEVMODE *)new0 byte[size];
255 DocumentProperties(null, hPrinter, szDevice, devMode, null, DM_OUT_BUFFER);
256 devMode->dmOrientation = (width > height) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
257 DocumentProperties(null, hPrinter, szDevice, devMode, devMode, DM_IN_BUFFER|DM_OUT_BUFFER);
258 gdiSystem.hdc = CreateDC(szDriver, szDevice, szOutput, devMode);
260 ClosePrinter(hPrinter);
263 gdiSystem.tmpDC = CreateCompatibleDC(gdiSystem.hdc);
264 gdiSystem.bmpDC = CreateCompatibleDC(gdiSystem.hdc);
265 gdiSystem.depth = GetDeviceCaps(gdiSystem.hdc, BITSPIXEL);
266 gdiSystem.depth = 32;
267 display.displaySystem.pixelFormat = GetColorFormat(gdiSystem.depth);
270 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
271 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
272 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
274 SetMapMode(gdiSystem.hdc, MM_TEXT);
277 String docName = printingDocumentName ? printingDocumentName : szMessage;
278 char curDir[MAX_LOCATION];
279 GetWorkingDir(curDir, MAX_LOCATION);
281 if(Escape(gdiSystem.hdc, STARTDOC, strlen(docName), docName, null ) > 0)
283 StartPage(gdiSystem.hdc);
286 ChangeWorkingDir(curDir);
289 //displaySystem.flags.memBackBuffer = true;
293 gdiDisplay.hdc = gdiSystem.hdc;
294 gdiDisplay.width = GetDeviceCaps(hdc, HORZRES);
295 gdiDisplay.height = GetDeviceCaps(hdc, VERTRES);
297 gdiSystem.resX = display.width = width;
298 gdiSystem.resY = display.height = height;
300 SelectObject(gdiDisplay.hdc,GetStockObject(DC_PEN));
301 SelectObject(gdiDisplay.hdc,GetStockObject(DC_BRUSH));
302 SetBkMode(gdiDisplay.hdc, TRANSPARENT);
308 void DisplayPosition(Display display, int x, int y)
310 Win32PrinterDisplay gdiDisplay = display.driverData;
311 gdiDisplay.offset.x = x;
312 gdiDisplay.offset.y = y;
316 void RestorePalette(Display display)
318 Win32PrinterDisplay gdiDisplay = display.driverData;
319 HDC hdc = gdiDisplay.hdc;
322 if(gdiDisplay.palette)
324 SelectPalette(hdc, gdiDisplay.palette, FALSE);
330 #define MAX_EXPOSED 50
332 void StartUpdate(Display display)
334 Win32PrinterDisplay gdiDisplay = display.driverData;
335 if(gdiDisplay && !gdiDisplay.completed)
337 GdiSetBatchLimit(1000);
339 gdiDisplay.rgn = CreateRectRgn(0,0,0,0);
340 gdiDisplay.data = (RGNDATA *) new0 byte[sizeof(RGNDATAHEADER) + sizeof(RECT) * MAX_EXPOSED];
341 if(gdiDisplay.palette)
342 SelectPalette(gdiDisplay.hdc, gdiDisplay.palette, FALSE);
346 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
351 void Update(Display display, Box updateBox)
356 void EndUpdate(Display display)
358 Win32PrinterDisplay gdiDisplay = display.driverData;
359 if(gdiDisplay && !gdiDisplay.completed)
361 DeleteObject(gdiDisplay.rgn);
362 delete gdiDisplay.data;
363 gdiDisplay.data = null;
364 gdiDisplay.completed = true;
368 void NextPage(Display display)
370 Win32PrinterDisplay gdiDisplay = display.driverData;
371 gdiDisplay.completed = false;
372 EndPage(gdiDisplay.hdc);
373 StartPage(gdiDisplay.hdc);
376 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
378 // (((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
379 Win32PrinterBitmap gdiBitmap = bitmap.driverData;
382 DeleteDC(gdiBitmap.memDC);
384 DeleteObject(gdiBitmap.mask);
386 DeleteObject(gdiBitmap.bmp);
387 delete (Win32PrinterBitmap)gdiBitmap;
388 bitmap.driverData = null;
389 bitmap.driver = null;
392 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
394 // return (((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
396 if(bitmap.Convert(null, pixelFormat888, null))
398 Win32PrinterSystem gdiSystem = displaySystem.driverData;
399 Win32PrinterBitmap gdiBitmap = bitmap.driverData = Win32PrinterBitmap { };
400 BITMAPINFO * info = new0 BITMAPINFO[1];
401 if(!info) return false;
403 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
404 info->bmiHeader.biPlanes = 1;
405 info->bmiHeader.biWidth = bitmap.width;
406 info->bmiHeader.biHeight = -bitmap.height;
407 info->bmiHeader.biBitCount = 32;
408 // If transparent, we need to create a black mask for the little GDI trick
409 if(bitmap.transparent)
412 HGDIOBJ prevDC, prevDC2;
414 mask.Allocate(null, bitmap.width, bitmap.height, 0, pixelFormat888, false);
415 for(c = 0; c<bitmap.width * bitmap.height; c++)
416 ((Color *)mask.picture)[c] = ((ColorAlpha *)bitmap.picture)[c].a ? 0xFFFFFF : 0;
418 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, mask.picture, info, DIB_RGB_COLORS);
419 gdiBitmap.mask = CreateBitmap(bitmap.width, bitmap.height, 1, 1, null);
420 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
421 prevDC2 = SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
422 SetBkColor(gdiSystem.bmpDC, 0);
423 BitBlt(gdiSystem.tmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.bmpDC, 0, 0, SRCCOPY);
424 SetBkColor(gdiSystem.bmpDC, 0);
425 SetTextColor(gdiSystem.bmpDC, 0xFFFFFF);
427 SelectObject(gdiSystem.bmpDC, prevDC);
428 DeleteObject(gdiBitmap.bmp);
430 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
431 prevDC = SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
434 SetTextColor(gdiSystem.bmpDC, RGB(255,255,255));
435 SetBkColor(gdiSystem.bmpDC, RGB(0,0,0));
436 BitBlt(gdiSystem.bmpDC, 0, 0, bitmap.width, bitmap.height, gdiSystem.tmpDC, 0, 0, SRCAND);
437 SelectObject(gdiSystem.tmpDC, prevDC2);
438 SelectObject(gdiSystem.bmpDC, prevDC);
439 SetTextColor(gdiSystem.bmpDC, RGB(0,0,0));
440 SetBkColor(gdiSystem.bmpDC, RGB(255,255,255));
441 SetBkColor(gdiSystem.tmpDC, RGB(255,255,255));
447 gdiBitmap.bmp = CreateDIBitmap(gdiSystem.hdc, (LPBITMAPINFOHEADER)info, CBM_INIT, bitmap.picture, info, DIB_RGB_COLORS);
450 delete bitmap.picture;
453 bitmap.driver = ((subclass(DisplayDriver))class(Win32PrinterDisplayDriver));
459 void ReleaseSurface(Display display, Surface surface)
461 Win32PrinterSurface gdiSurface = surface.driverData;
462 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
467 SelectClipRgn(gdiSurface.hdc,null);
468 DeleteObject(gdiSurface.rgn);
469 gdiSurface.rgn = null;
471 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
473 surface.driverData = null;
477 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
482 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
485 Win32PrinterDisplay gdiDisplay = display.driverData;
486 if(gdiDisplay && !gdiDisplay.completed)
488 Win32PrinterSurface gdiSurface;
489 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
491 if((surface.driverData = gdiSurface = Win32PrinterSurface { }))
493 // if(((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip))
495 gdiSurface.hdc = gdiDisplay.hdc ? gdiDisplay.hdc : gdiSystem.tmpDC;
497 gdiSurface.offset.x = x;
498 gdiSurface.offset.y = y;
499 gdiSurface.unclippedBox = gdiSurface.box = clip;
501 surface.width = gdiDisplay.width - x + 1;
502 surface.height = gdiDisplay.height - y + 1;
503 surface.offset.x = x * gdiDisplay.width / display.width;
504 surface.offset.y = y * gdiDisplay.height / display.height;
505 surface.unclippedBox = surface.box =
507 left = clip.left * gdiDisplay.width / display.width,
508 top = clip.top * gdiDisplay.height / display.height,
509 right = (clip.right+1) * gdiDisplay.width / display.width-1,
510 bottom = (clip.bottom+1) * gdiDisplay.height / display.height-1
513 gdiSurface.rgn = CreateRectRgn(
514 surface.offset.x + surface.box.left,
515 surface.offset.y + surface.box.top,
516 surface.offset.x + surface.box.right + 1,
517 surface.offset.y + surface.box.bottom + 1);
519 // x + clip.left, y+clip.top,x+clip.right+1,y+clip.bottom+1);
522 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
524 SetDCBrushColor(gdiSurface.hdc, RGB(0,0,0));
525 SetDCPenColor(gdiSurface.hdc, RGB(255,255,255));
527 SetBkColor(gdiSystem.hdc, RGB(0,0,0));
536 void Clip(Display display, Surface surface, Box clip)
538 Win32PrinterDisplay gdiDisplay = display.driverData;
539 Win32PrinterSurface gdiSurface = surface.driverData;
540 HRGN clippedRgn = null;
545 box.Clip(gdiSurface.unclippedBox);
547 gdiSurface.box = box;
550 left = box.left * gdiDisplay.width / display.width,
551 top = box.top * gdiDisplay.height / display.height,
552 right = (box.right+1) * gdiDisplay.width / display.width-1,
553 bottom = (box.bottom+1) * gdiDisplay.height / display.height-1
556 if(box.right > box.left && box.bottom > box.top)
558 box.left += gdiSurface.offset.x;
559 box.top += gdiSurface.offset.y;
560 box.right+= gdiSurface.offset.x;
561 box.bottom += gdiSurface.offset.y;
563 gdiSurface.rgn = CreateRectRgn(
564 surface.offset.x + surface.box.left,
565 surface.offset.y + surface.box.top,
566 surface.offset.x + surface.box.right + 1,
567 surface.offset.y + surface.box.bottom + 1);
569 // clippedRgn = CreateRectRgn(box.left, box.top, box.right+1, box.bottom+1);
572 clippedRgn = CreateRectRgn(0, 0, 0, 0);
575 SelectClipRgn(gdiSurface.hdc, clippedRgn);
577 else if(gdiSurface.clippedRgn)
579 surface.box = surface.unclippedBox;
580 gdiSurface.box = gdiSurface.unclippedBox;
581 SelectClipRgn(gdiSurface.hdc,gdiSurface.rgn);
583 if(gdiSurface.clippedRgn)
584 DeleteObject(gdiSurface.clippedRgn);
585 gdiSurface.clippedRgn = clippedRgn;
588 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
591 Win32PrinterDisplay gdiDisplay = display.driverData;
592 // result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
596 void SetForeground(Display display, Surface surface, ColorAlpha color)
598 Win32PrinterSurface gdiSurface = surface.driverData;
599 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
600 COLORREF rgb = RGB(color.color.r, color.color.g, color.color.b);
601 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
602 SetTextColor(gdiSurface.hdc, rgb);
603 gdiSurface.color = rgb;
604 SetDCPenColor(gdiSurface.hdc, rgb);
607 void SetBackground(Display display, Surface surface, ColorAlpha color)
609 Win32PrinterSurface gdiSurface = surface.driverData;
610 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
613 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
614 if(gdiSurface.bitmap.pixelFormat == pixelFormat8 && display)
615 color = gdiSurface.bitmap.palette[gdiDisplay.rgbLookup[(uint16)(Color555) color]];
617 rgb = RGB(color.color.r, color.color.g, color.color.b);
618 gdiSurface.backColor = rgb;
619 SetBkColor(gdiSurface.hdc, rgb);
620 SetDCBrushColor(gdiSurface.hdc, rgb);
623 ColorAlpha GetPixel(Display display, Surface surface, int x, int y)
628 void PutPixel(Display display, Surface surface, int x, int y)
630 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
631 Win32PrinterSurface gdiSurface = surface.driverData;
633 SetBkMode(gdiSurface.hdc, OPAQUE);
634 SetBkColor(gdiSurface.hdc, gdiSurface.color);
635 PatBlt(gdiSurface.hdc,
636 (int)((float)x * gdiDisplay.width / display.width) + surface.offset.x,
637 (int)((float)y * gdiDisplay.height / display.height) + surface.offset.y,
638 (int)((float)(x+1) * gdiDisplay.width / display.width)-1 + surface.offset.x+1,
639 (int)((float)(y+1) * gdiDisplay.height / display.height)-1 + surface.offset.y+1,
641 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
642 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
645 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
647 Win32PrinterSurface gdiSurface = surface.driverData;
648 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
651 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
652 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
653 x2 = (int)((float)x2 * gdiDisplay.width / display.width) + surface.offset.x;
654 y2 = (int)((float)y2 * gdiDisplay.height / display.height) + surface.offset.y;
655 for(c = 0; c <= (float)gdiDisplay.width / display.width; c++)
659 MoveToEx(gdiSurface.hdc, x1, y1, null);
660 LineTo(gdiSurface.hdc, x2, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
666 MoveToEx(gdiSurface.hdc, x1, y1, null);
667 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2);
673 MoveToEx(gdiSurface.hdc, x1, y1, null);
674 LineTo(gdiSurface.hdc, x2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1, y2 + (int)((float)gdiDisplay.width / display.width + 0.5)+1);
681 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
683 Win32PrinterSurface gdiSurface = surface.driverData;
684 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
688 SelectObject(gdiSurface.hdc,GetStockObject(NULL_BRUSH));
689 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
690 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
691 x2 = (int)((float)(x2) * gdiDisplay.width / display.width) + surface.offset.x;
692 y2 = (int)((float)(y2) * gdiDisplay.height / display.height) + surface.offset.y;
693 for(c = 0; c <= (float)gdiDisplay.width / display.width + 1.5; c++)
695 ::Rectangle(gdiSurface.hdc, x1, y1, x2, y2);
699 SelectObject(gdiSurface.hdc,GetStockObject(DC_BRUSH));
702 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
704 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
705 Win32PrinterSurface gdiSurface = surface.driverData;
707 x1 = (int)((float)x1 * gdiDisplay.width / display.width) + surface.offset.x;
708 y1 = (int)((float)y1 * gdiDisplay.height / display.height) + surface.offset.y;
709 x2 = (int)(((float)(x2+1) * gdiDisplay.width / display.width) + 0.5) + surface.offset.x;
710 y2 = (int)(((float)(y2+1) * gdiDisplay.height / display.height) + 0.5) + surface.offset.y;
712 SetBkMode(gdiSurface.hdc, OPAQUE);
713 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
714 SetDCBrushColor(gdiSurface.hdc, gdiSurface.backColor);
715 PatBlt(gdiSurface.hdc,x1,y1,x2-x1+1,y2-y1+1,PATCOPY);
716 SetBkMode(gdiSurface.hdc, surface.textOpacity ? OPAQUE : TRANSPARENT);
719 void Clear(Display display, Surface surface, ClearType type)
721 Win32PrinterSurface gdiSurface = surface.driverData;
722 if(type != depthBuffer)
723 Area(display, surface, gdiSurface.box.left, gdiSurface.box.top, gdiSurface.box.right, gdiSurface.box.bottom);
726 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
731 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
736 void Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
738 Filter(display, surface, src, dx, dy, sx, sy, w, h, w, h);
741 void Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
743 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
746 void Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
748 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
749 Win32PrinterSystem gdiSystem = display.displaySystem.driverData;
750 Win32PrinterBitmap gdiBitmap = src.driverData;
751 Win32PrinterSurface gdiSurface = surface.driverData;
755 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
756 SelectObject(gdiSystem.tmpDC, gdiBitmap.mask);
758 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
760 SetBkColor(gdiSurface.hdc, 0xFFFFFF);
761 SetTextColor(gdiSurface.hdc, 0);
762 StretchBlt(gdiSurface.hdc,
763 dx * gdiDisplay.width / display.width + surface.offset.x,
764 dy * gdiDisplay.height / display.height + surface.offset.y,
765 (w) * gdiDisplay.width / display.width,
766 (h) * gdiDisplay.height / display.height,
767 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
768 StretchBlt(gdiSurface.hdc,
769 dx * gdiDisplay.width / display.width + surface.offset.x,
770 dy * gdiDisplay.height / display.height + surface.offset.y,
771 (w) * gdiDisplay.width / display.width,
772 (h) * gdiDisplay.height / display.height,
773 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
775 StretchBlt(gdiSurface.hdc,
776 dx * gdiDisplay.width / display.width + surface.offset.x,
777 dy * gdiDisplay.height / display.height + surface.offset.y,
778 (w+1) * gdiDisplay.width / display.width-1,
779 (h+1) * gdiDisplay.height / display.height-1,
780 gdiSystem.tmpDC, sx, sy,sw,sh, SRCAND);
781 StretchBlt(gdiSurface.hdc,
782 dx * gdiDisplay.width / display.width + surface.offset.x,
783 dy * gdiDisplay.height / display.height + surface.offset.y,
784 (w+1) * gdiDisplay.width / display.width-1,
785 (h+1) * gdiDisplay.height / display.height-1,
786 gdiSystem.bmpDC, sx, sy,sw,sh, SRCPAINT);
788 SetBkColor(gdiSurface.hdc, gdiSurface.backColor);
792 SetStretchBltMode(gdiSurface.hdc, HALFTONE); //COLORONCOLOR);
793 SelectObject(gdiSystem.bmpDC, gdiBitmap.bmp);
794 StretchBlt(gdiSurface.hdc,
795 dx * gdiDisplay.width / display.width + surface.offset.x,
796 dy * gdiDisplay.height / display.height + surface.offset.y,
797 (w+1) * gdiDisplay.width / display.width-1,
798 (h+1) * gdiDisplay.height / display.height-1,
799 gdiSystem.bmpDC, sx, sy,sw,sh, SRCCOPY);
803 void BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
805 Blit(display,surface,src,dx,dy,sx,sy,w,h);
808 void StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
810 Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
813 void FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
815 Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
818 Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
820 Win32PrinterSystem gdiSystem = displaySystem.driverData;
821 HDC hdc = gdiSystem.hdc;
825 SetMapMode(gdiSystem.hdc, MM_ANISOTROPIC);
826 SetWindowExtEx(gdiSystem.hdc, RESX, RESY, null);
827 SetViewportExtEx(gdiSystem.hdc, GetDeviceCaps(gdiSystem.hdc, HORZRES), GetDeviceCaps(gdiSystem.hdc, VERTRES), null);
830 pixels = GetDeviceCaps(hdc, VERTRES);
831 res = GetDeviceCaps(hdc, LOGPIXELSY);
834 s = -(int)(((float)size * res / 78) + 0.5);
836 // font = CreateFont(-(int)(((float)size * 96 / 72) + 0.5),
838 // font = CreateFont(-(int)(((float)size * pixels * RESY / res / 72) + 0.5),
839 0,0,0, flags.bold ? FW_BOLD : FW_NORMAL, flags.italic ? TRUE : FALSE,
840 flags.underline ? TRUE : FALSE, 0, DEFAULT_CHARSET,
841 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
842 DEFAULT_PITCH|FF_DONTCARE, faceName);
844 // SetMapMode(gdiSystem.hdc, MM_TEXT);
848 void UnloadFont(DisplaySystem displaySystem, Font font)
854 void TextFont(Display display, Surface surface, Font font)
856 Win32PrinterSurface gdiSurface = surface.driverData;
857 SelectObject(gdiSurface.hdc, font);
860 void TextOpacity(Display display, Surface surface, bool opaque)
862 Win32PrinterSurface gdiSurface = surface.driverData;
863 SetBkMode(gdiSurface.hdc, opaque ? OPAQUE : TRANSPARENT);
866 void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
868 Win32PrinterSurface gdiSurface = surface.driverData;
869 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
871 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
874 SetMapMode(gdiSurface.hdc, MM_ANISOTROPIC);
875 SetWindowExtEx(gdiSurface.hdc, RESX, RESY, null);
876 SetViewportExtEx(gdiSurface.hdc, GetDeviceCaps(gdiSurface.hdc, HORZRES), GetDeviceCaps(gdiSurface.hdc, VERTRES), null);
878 TextOut(gdiSurface.hdc, x * gdiDisplay.width / display.width + surface.offset.x, y * gdiDisplay.height / display.height + surface.offset.y, u16text, wordCount);
880 TextOut(gdiSurface.hdc, x + gdiSurface.offset.x, y + gdiSurface.offset.y, text,len);
881 SetMapMode(gdiSurface.hdc, MM_TEXT);
886 void ::_TextExtent(HDC hdc, int resX, int resY, char * text, int len, int * width, int * height)
891 uint16 * u16text = UTF8toUTF16Len(text, len, &wordCount);
893 for(realLen = 0; realLen<wordCount && u16text[realLen]; realLen++);
894 GetTextExtentPoint32(hdc, " ", 1, &space);
895 GetTextExtentPoint32(hdc, u16text, realLen, &size);
900 // UNICODE FIX: proper space computation
901 *width = size.cx + (wordCount - realLen) * space.cx;
902 *width = *width * resX / GetDeviceCaps(hdc, HORZRES);
909 *height = len ? space.cy : 0;
910 *height = *height * resY / GetDeviceCaps(hdc, VERTRES);
914 void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
916 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
917 Win32PrinterSystem gdiSystem = (display && display.displaySystem) ? display.displaySystem.driverData : null;
918 Win32PrinterSurface gdiSurface = surface.driverData;
920 _TextExtent(gdiSurface.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
923 void FontExtent(DisplaySystem displaySystem, void * font, char * text, int len, int * width, int * height)
925 Win32PrinterSystem gdiSystem = displaySystem.driverData;
928 SelectObject(gdiSystem.hdc, font);
929 _TextExtent(gdiSystem.hdc, gdiSystem.resX, gdiSystem.resY, text, len, width, height);
933 if(width) *width = 0;
934 if(height) *height = 0;
938 void DrawingChar(Display display, Surface surface, byte character)
943 void LineStipple(Display display, Surface surface, uint stipple)
945 Win32PrinterDisplay gdiDisplay = display ? display.driverData : null;
946 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
949 bool Lock(Display display)
954 void Unlock(Display display)