summaryrefslogtreecommitdiff
path: root/src/Fl_Bitmap.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fl_Bitmap.cxx')
-rw-r--r--src/Fl_Bitmap.cxx56
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__)