From 998cc6df521a115454727d1ecf6bc7d4fee96f68 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 14 Mar 2010 18:07:24 +0000 Subject: Merge of branch-1.3-Fl_Printer, with the following main changes: (1) adding Fl_Device class (and more) for device abstraction (2) adding Fl_Pinter class (and more) for printing support. Todo: Code cleanup, update dependencies, remove/replace test print window. I'm looking into converting the test window popup in a global shortcut that would pop up the print dialog now... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7263 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Pixmap.cxx | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/Fl_Pixmap.cxx') diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index 42ab0bb0a..ecf45915b 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include #include "flstring.h" @@ -74,6 +75,10 @@ void Fl_Pixmap::measure() { } 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); + return; + } // ignore empty or bad pixmap data: if (!data()) { draw_empty(XP, YP); @@ -139,7 +144,54 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { fl_restore_clip(); } #elif defined(WIN32) - if (mask) { + if (fl_device->type() == Fl_Device::gdi_printer) { + typedef BOOL (WINAPI* fl_transp_func) (HDC,int,int,int,int,HDC,int,int,int,int,UINT); + static HMODULE hMod = NULL; + static fl_transp_func fl_TransparentBlt = NULL; + if (!hMod) { + hMod = LoadLibrary("MSIMG32.DLL"); + if(hMod) fl_TransparentBlt = (fl_transp_func)GetProcAddress(hMod, "TransparentBlt"); + } + if (hMod) { +# define UNLIKELY_RGB_COLOR 2,3,4 // a nearly black color unlikely to occur in pixmaps +# 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; + // draw pixmap to offscreen using the unlikely color for background + fl_draw_pixmap(data(), 0, 0, fl_rgb_color(UNLIKELY_RGB_COLOR) ); + fl_end_offscreen(); + HDC new_gc = CreateCompatibleDC(fl_gc); + int save = SaveDC(new_gc); + SelectObject(new_gc, (void*)tmp_id); + // print all of offscreen but its parts using unlikely color + fl_TransparentBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, w(), h(), WIN_COLOR ); + RestoreDC(new_gc,save); + // This is an approximate algorithm that fails to print pixmap pixels that would use the unlikely color. + // It can be transformed into an exact algorithm by adding the following commented out statements + // that print pixmap one more time hiding another color (any color would fit) + /* +# define UNLIKELY_RGB_COLOR2 4,3,2 +# define WIN_COLOR2 RGB(4,3,2) + { + fl_begin_offscreen(tmp_id); + fl_draw_pixmap(data(), 0, 0, fl_rgb_color(UNLIKELY_RGB_COLOR2) ); + fl_end_offscreen(); + } + save = SaveDC(new_gc); + SelectObject(new_gc, (void*)tmp_id); + fl_TransparentBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, w(), h(), WIN_COLOR2 ); + 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); int save = SaveDC(new_gc); SelectObject(new_gc, (void*)mask); -- cgit v1.2.3