FLTK logo

[MOD] STR #3534: Printing a window may be incorrect with the plastic scheme

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.bugs  ]
 
Previous Message ]New Message | Reply ]Next Message ]

[MOD] STR #3534: Printing a window may be incorrect with the plastic scheme Manolo Gouy Feb 17, 2020  
 
DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: https://www.fltk.org/str.php?L3534
Version: 1.4-current


To reproduce the problem:

Uncomment the first statement in main() of test/device.cxx to get
  Fl::scheme("plastic");

Run test/device
Click "Fl_Printer"
Click "GO"
Then print to a .ps or .pdf file to save paper.

The plastic background of the main window does not appear in the
"printed" file.

The cause is that Fl_Tiled_Image::draw() calls Fl_Window::current()
to identify which window contains the Fl_Tiled_Image being drawn.
This works well when the draw operation goes to the display
because Fl_Window::make_current() has necessarily been applied
to that window before any drawing is done.

But this fails when the draw operation is to another drawing surface,
such as the printer, because Fl_Window::current() is set to the 
last window drawn on the display, not to the window being printed.

The attached patch should fix that problem, by making
Fl_Window::draw() temporarily set Fl_Window::current_
when the drawing surface is not the display.

The patch would hopefully also satisfy the comment
  // This should be fixed! (AlbrechtS, 01 Mar 2015)
waiting at line 172 of src/Fl_Tiled_Image.cxx

Comments?


Link: https://www.fltk.org/str.php?L3534
Version: 1.4-current
diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx
index 0b4961062..fb77cf01d 100644
--- a/src/Fl_Window.cxx
+++ b/src/Fl_Window.cxx
@@ -482,6 +482,9 @@ void Fl_Window::flush()
 
 void Fl_Window::draw()
 {
+  Fl_Window *save_current = current_;
+  bool to_display = Fl_Display_Device::display_device()->is_current();
+  if (!to_display) current_ = this; // so drawing of background Fl_Tiled_Image is correct
   pWindowDriver->draw_begin();
 
   // The following is similar to Fl_Group::draw(), but ...
@@ -510,6 +513,7 @@ void Fl_Window::draw()
   draw_children();
 
   pWindowDriver->draw_end();
+  if (!to_display) current_ = save_current;
 # if defined(FLTK_USE_CAIRO)
   Fl::cairo_make_current(this); // checkout if an update is necessary
 # endif
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.