Author: manolo
Date: 2010-03-04 09:06:43 -0800 (Thu, 04 Mar 2010)
New Revision: 7212
Log:
Pixmaps and Bitmaps now print with correct transparency on MSWindows.

Modified:
   branches/branch-1.3-Fl_Printer/src/Fl_Bitmap.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Pixmap.cxx

Modified: branches/branch-1.3-Fl_Printer/src/Fl_Bitmap.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Bitmap.cxx    2010-03-04 15:14:36 UTC 
(rev 7211)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Bitmap.cxx    2010-03-04 17:06:43 UTC 
(rev 7212)
@@ -264,6 +264,7 @@
   return (mask);
 }
 
+typedef BOOL (WINAPI* fl_transp_func)  
(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
 void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
   if(fl_device->type() == Fl_Device::postscript_device) {
     ((Fl_Virtual_Printer*)fl_device)->draw(this, XP, YP, WP, HP, cx, cy);
@@ -302,8 +303,19 @@
   int save = SaveDC(tempdc);
   SelectObject(tempdc, (HGDIOBJ)id);
   SelectObject(fl_gc, fl_brush());
-  // secret bitblt code found in old MSWindows reference manual:
-  BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, 0xE20746L);
+  if(fl_device->type() == Fl_Device::gdi_printer) {
+    static HMODULE hMod = NULL;
+    if (!hMod) hMod = LoadLibrary("MSIMG32.DLL");
+    if(hMod) {
+      fl_transp_func fl_TransparentBlt = (fl_transp_func)GetProcAddress(hMod, 
"TransparentBlt");
+      fl_TransparentBlt(fl_gc, X,Y,W,H, tempdc, cx, cy, w(), h(), RGB(0,0,0) );
+      }
+    else BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, SRCCOPY);
+    }
+  else {
+    // secret bitblt code found in old MSWindows reference manual:
+    BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, 0xE20746L);
+    }
   RestoreDC(tempdc, save);
   DeleteDC(tempdc);
 #elif defined(__APPLE_QUARTZ__)

Modified: branches/branch-1.3-Fl_Printer/src/Fl_Pixmap.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Pixmap.cxx    2010-03-04 15:14:36 UTC 
(rev 7211)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Pixmap.cxx    2010-03-04 17:06:43 UTC 
(rev 7212)
@@ -74,6 +74,7 @@
   }
 }
 
+typedef BOOL (WINAPI* fl_transp_func)  
(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
 void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
   if(fl_device->type() == Fl_Device::postscript_device) {
     ((Fl_Virtual_Printer*)fl_device)->draw(this, XP, YP, WP, HP, cx, cy);
@@ -144,15 +145,33 @@
     fl_restore_clip();
   }
 #elif defined(WIN32)
-  if (fl_device->type() == Fl_Device::gdi_printer) { // print with white 
instead of transparent background
-    Fl_Offscreen tmp_id = fl_create_offscreen(w(), h());
-    fl_begin_offscreen(tmp_id);
-    uchar *bitmap = 0;
-    fl_mask_bitmap = &bitmap;
-    fl_draw_pixmap(data(), 0, 0, FL_WHITE );
-    fl_end_offscreen();
-    fl_copy_offscreen(X, Y, W, H, tmp_id, cx, cy);
-    fl_delete_offscreen(tmp_id);
+  if (fl_device->type() == Fl_Device::gdi_printer) {
+    static HMODULE hMod = NULL;
+    if (!hMod) hMod = LoadLibrary("MSIMG32.DLL");
+    if (hMod) {
+#     define UNLIKELY_RGB_COLOR 2,3,4
+#     define WIN_COLOR RGB(2,3,4)
+      Fl_Offscreen tmp_id = fl_create_offscreen(w(), h());
+      fl_begin_offscreen(tmp_id);
+      uchar *bitmap = 0;
+      fl_mask_bitmap = &bitmap;
+      Fl_Color save_c = fl_color();
+      fl_color(UNLIKELY_RGB_COLOR);
+      fl_draw_pixmap(data(), 0, 0, fl_color() );
+      fl_color( save_c );
+      fl_end_offscreen();
+      HDC new_gc = CreateCompatibleDC(fl_gc);
+      int save = SaveDC(new_gc);
+      SelectObject(new_gc, (void*)tmp_id);
+      fl_transp_func fl_TransparentBlt = (fl_transp_func)GetProcAddress(hMod, 
"TransparentBlt");
+      fl_TransparentBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, w(), h(), 
WIN_COLOR);
+      RestoreDC(new_gc,save);
+      DeleteDC(new_gc);
+      fl_delete_offscreen(tmp_id);
+    }
+    else {
+      fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
+    }
   }
   else if (mask) {
     HDC new_gc = CreateCompatibleDC(fl_gc);

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to