diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2010-03-14 18:07:24 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2010-03-14 18:07:24 +0000 |
| commit | 998cc6df521a115454727d1ecf6bc7d4fee96f68 (patch) | |
| tree | 70a1c9afffb294a75bd38484c2e6e4a042ac3426 /src/Fl_Bitmap.cxx | |
| parent | 5bc66fafc348c547870bbf51c9c4a7215ad4ff25 (diff) | |
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
Diffstat (limited to 'src/Fl_Bitmap.cxx')
| -rw-r--r-- | src/Fl_Bitmap.cxx | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx index 26019091b..513858e78 100644 --- a/src/Fl_Bitmap.cxx +++ b/src/Fl_Bitmap.cxx @@ -37,6 +37,7 @@ #include <FL/Fl_Widget.H> #include <FL/Fl_Menu_Item.H> #include <FL/Fl_Bitmap.H> +#include <FL/Fl_Printer.H> #include "flstring.h" #if defined(__APPLE_QUARTZ__) @@ -264,6 +265,10 @@ Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *array) } 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); + return; + } if (!array) { draw_empty(XP, YP); return; @@ -293,12 +298,51 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { #elif defined(WIN32) if (!id) id = fl_create_bitmap(w(), h(), array); - HDC tempdc = CreateCompatibleDC(fl_gc); - 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); + typedef BOOL (WINAPI* fl_transp_func) (HDC,int,int,int,int,HDC,int,int,int,int,UINT); + static fl_transp_func fl_TransparentBlt; + HDC tempdc; + int save; + BOOL use_print_algo = false; + if (fl_device->type() == Fl_Device::gdi_printer) { + static HMODULE hMod = NULL; + if (!hMod) { + hMod = LoadLibrary("MSIMG32.DLL"); + if (hMod) fl_TransparentBlt = (fl_transp_func)GetProcAddress(hMod, "TransparentBlt"); + } + if (hMod) use_print_algo = true; + } + if (use_print_algo) { // algorithm for bitmap output to Fl_GDI_Printer + Fl_Offscreen tmp_id = fl_create_offscreen(W, H); + fl_begin_offscreen(tmp_id); + Fl_Color save_c = fl_color(); // save bitmap's desired color + uchar r, g, b; + Fl::get_color(save_c, r, g, b); + r = 255-r; + g = 255-g; + b = 255-b; + Fl_Color background = fl_rgb_color(r, g, b); // a color very different from the bitmap's + fl_color(background); + fl_rectf(0,0,W,H); // use this color as offscreen background + fl_color(save_c); // back to bitmap's color + tempdc = CreateCompatibleDC(fl_gc); + save = SaveDC(tempdc); + SelectObject(tempdc, (HGDIOBJ)id); + SelectObject(fl_gc, fl_brush()); // use bitmap's desired color + BitBlt(fl_gc, 0, 0, W, H, tempdc, 0, 0, 0xE20746L); // draw bitmap to offscreen + fl_end_offscreen(); // offscreen data is in tmp_id + SelectObject(tempdc, (HGDIOBJ)tmp_id); // use offscreen data + // draw it to printer context with background color as transparent + fl_TransparentBlt(fl_gc, X,Y,W,H, tempdc, cx, cy, w(), h(), RGB(r, g, b) ); + fl_delete_offscreen(tmp_id); + } + else { // algorithm for bitmap output to display + tempdc = CreateCompatibleDC(fl_gc); + 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); + } RestoreDC(tempdc, save); DeleteDC(tempdc); #elif defined(__APPLE_QUARTZ__) |
