Author: manolo
Date: 2012-03-14 01:49:36 -0700 (Wed, 14 Mar 2012)
New Revision: 9282
Log:
Simplified Fl_Paged_Device::print_window() under Mac OS
Modified:
branches/branch-1.3/src/Fl_Image.cxx
branches/branch-1.3/src/Fl_cocoa.mm
Modified: branches/branch-1.3/src/Fl_Image.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Image.cxx 2012-03-12 14:20:18 UTC (rev
9281)
+++ branches/branch-1.3/src/Fl_Image.cxx 2012-03-14 08:49:36 UTC (rev
9282)
@@ -446,6 +446,11 @@
}
#ifdef __APPLE__
+static void imgProviderReleaseData (void *info, const void *data, size_t size)
+{
+ delete[] (unsigned char *)data;
+}
+
void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int
WP, int HP, int cx, int cy) {
int X, Y, W, H;
// Don't draw an empty image...
@@ -456,14 +461,26 @@
if (start(img, XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
return;
}
+ CGDataProviderReleaseDataCallback release_cb = NULL;
+ const uchar* img_bytes = img->array;
+ int ld = img->ld();
if (!img->id_) {
CGColorSpaceRef lut = 0;
+ if (Fl_Surface_Device::surface() != Fl_Display_Device::display_device()) {
+ // when printing, duplicate the image data so it can be deleted later,
at page end
+ release_cb = imgProviderReleaseData;
+ Fl_RGB_Image* img2 = (Fl_RGB_Image*)img->copy();
+ img2->alloc_array = 0;
+ img_bytes = img2->array;
+ ld = 0;
+ delete img2;
+ }
if (img->d()<=2)
lut = CGColorSpaceCreateDeviceGray();
else
lut = CGColorSpaceCreateDeviceRGB();
- CGDataProviderRef src = CGDataProviderCreateWithData( 0L, img->array,
img->w()*img->h()*img->d(), 0L);
- img->id_ = CGImageCreate( img->w(), img->h(), 8, img->d()*8,
img->ld()?img->ld():img->w()*img->d(),
+ CGDataProviderRef src = CGDataProviderCreateWithData( NULL, img_bytes,
img->w()*img->h()*img->d(), release_cb);
+ img->id_ = CGImageCreate( img->w(), img->h(), 8, img->d()*8,
ld?ld:img->w()*img->d(),
lut, (img->d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,
src, 0L, false, kCGRenderingIntentDefault);
CGColorSpaceRelease(lut);
Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2012-03-12 14:20:18 UTC (rev 9281)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2012-03-14 08:49:36 UTC (rev 9282)
@@ -3244,7 +3244,7 @@
}
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int
w, int h, int *bytesPerPixel)
-// delete the returned pointer after use
+// delete[] the returned pointer after use
{
while(win->window()) {
x += win->x();
@@ -3346,23 +3346,14 @@
Fl::check();
win->make_current();
this->set_current(); // back to the Fl_Paged_Device
- if (driver()->class_name() == Fl_Quartz_Graphics_Driver::class_id) {
- // capture as transparent image the window title bar from screen
- CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt);
- CGRect rect = { { x_offset, y_offset }, { win->w(), bt } }; // print the
title bar
- Fl_X::q_begin_image(rect, 0, 0, win->w(), bt);
- CGContextDrawImage(fl_gc, rect, img);
- Fl_X::q_end_image();
- CGImageRelease(img);
- }
- else {
- // capture the window title bar from screen
- uchar *top_image = fl_read_image(NULL, 0, -bt, win->w(), bt);
- if (top_image) { // print the title bar
- fl_draw_image(top_image, x_offset, y_offset, win->w(), bt, 3);
- delete[] top_image;
- }
- }
+ int bpp;
+ // capture the window title bar as an RGBA image
+ unsigned char *top_image = Fl_X::bitmap_from_window_rect(win, 0, -bt,
win->w(), bt, &bpp);
+ Fl_RGB_Image* rgba = new Fl_RGB_Image(top_image, win->w(), bt, bpp);
+ // and print it
+ rgba->draw(x_offset, y_offset);
+ delete rgba;
+ delete[] top_image;
this->print_widget(win, x_offset, y_offset + bt); // print the window inner
part
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit