FLTK logo

[master] 995a48d - Consistently make Fl_Paged_Device::begin_page call Fl_Surface_Device::push_current.

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.commit  ]
 
Previous Message ]Next Message ]

[master] 995a48d - Consistently make Fl_Paged_Device::begin_page call Fl_Surface_Device::push_current. "ManoloFLTK" Oct 31, 2021  
 
commit 995a48dd003b51291bb1f2c5513c529a1ad8dfed
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sun Oct 31 14:20:04 2021 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sun Oct 31 14:20:04 2021 +0100

    Consistently make Fl_Paged_Device::begin_page call Fl_Surface_Device::push_current.

 FL/Fl_Device.H                                  | 7 ++++---
 src/Fl_Paged_Device.cxx                         | 2 ++
 src/drivers/PostScript/Fl_PostScript.cxx        | 5 ++---
 src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx | 4 ++--
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git FL/Fl_Device.H FL/Fl_Device.H
index 6bf7cb6..890d4f7 100644
--- FL/Fl_Device.H
+++ FL/Fl_Device.H
@@ -38,14 +38,15 @@ class Fl_Widget;
 
  A drawing surface other than the computer's display, is typically used as follows:
  <ol><li> Create \c surface, an object from a particular Fl_Surface_Device derived class (e.g., Fl_Copy_Surface, Fl_Printer).
- <li> Call \c Fl_Surface_Device::push_current(surface); to redirect all graphics requests to \c surface which becomes the new
- current drawing surface (not necessary with class Fl_Printer because it is done by Fl_Printer::begin_job()).
+ <li> Call \c Fl_Surface_Device::push_current(surface); to redirect all graphics requests to
+ \c surface which becomes the new current drawing surface (not necessary with classes Fl_Printer / Fl_PostScript_File_Device
+ because it is done by Fl_Paged_Device::begin_page()).
  <li> At this point all of the \ref fl_drawings (e.g., fl_rect()) or the \ref fl_attributes or \ref drawing_images functions
  (e.g., fl_draw_image(), Fl_Image::draw()) operate on the new current drawing surface.
  Drawing surfaces from Fl_Widget_Surface derived classes allow additional ways
  to draw to them (e.g., Fl_Printer::print_widget(), Fl_Image_Surface::draw()).
  <li> After all drawing requests have been performed, redirect graphics requests back to their previous destination
- with \c Fl_Surface_Device::pop_current();.
+ with \c Fl_Surface_Device::pop_current(); (not necessary with classes Fl_Printer / Fl_PostScript_File_Device).
  <li> Delete \c surface.
  </ol>
  For back-compatibility, it is also possible to use the Fl_Surface_Device::set_current() member function
diff --git src/Fl_Paged_Device.cxx src/Fl_Paged_Device.cxx
index 368e098..3eb250a 100644
--- src/Fl_Paged_Device.cxx
+++ src/Fl_Paged_Device.cxx
@@ -40,6 +40,7 @@ int Fl_Paged_Device::begin_job(int pagecount, int *frompage, int *topage, char *
 
  The page coordinates are initially in points, i.e., 1/72 inch,
  and with origin at the top left of the printable page area.
+ This function also makes this surface the current drawing surface with Fl_Surface_Device::push_current().
  \return 0 if OK, non-zero if any error
  */
 int Fl_Paged_Device::begin_page (void) {return 1;}
@@ -82,6 +83,7 @@ void Fl_Paged_Device::rotate(float angle) {}
 
 /**
  \brief To be called at the end of each page.
+ This function also stops this surface from being the current drawing surface with Fl_Surface_Device::pop_current().
 
  \return 0 if OK, non-zero if any error.
  */
diff --git src/drivers/PostScript/Fl_PostScript.cxx src/drivers/PostScript/Fl_PostScript.cxx
index 470f6df..515450c 100644
--- src/drivers/PostScript/Fl_PostScript.cxx
+++ src/drivers/PostScript/Fl_PostScript.cxx
@@ -60,7 +60,6 @@ int Fl_PostScript_File_Device::begin_job (int pagecount, enum Fl_Paged_Device::P
   if(ps->output == NULL) return 2;
   ps->ps_filename_ = fl_strdup(fnfc.filename());
   ps->start_postscript(pagecount, format, layout);
-  Fl_Surface_Device::push_current(this);
   return 0;
 }
 
@@ -79,7 +78,6 @@ int Fl_PostScript_File_Device::begin_job (FILE *ps_output, int pagecount,
   ps->ps_filename_ = NULL;
   ps->start_postscript(pagecount, format, layout);
   ps->close_command(dont_close); // so that end_job() doesn't close the file
-  Fl_Surface_Device::push_current(this);
   return 0;
 }
 
@@ -1592,6 +1590,7 @@ void Fl_PostScript_File_Device::untranslate(void)
 int Fl_PostScript_File_Device::begin_page (void)
 {
   Fl_PostScript_Graphics_Driver *ps = driver();
+  Fl_Surface_Device::push_current(this);
 #if USE_PANGO
   cairo_ps_surface_dsc_begin_page_setup(cairo_get_target(ps->cr()));
   char feature[200];
@@ -1631,6 +1630,7 @@ int Fl_PostScript_File_Device::end_page (void)
   cairo_show_page(ps->cr());
   ps->check_status();
 #endif
+  Fl_Surface_Device::pop_current();
   return 0;
 }
 
@@ -1670,7 +1670,6 @@ void Fl_PostScript_File_Device::end_job (void)
     ps->clip_= ps->clip_->prev;
     delete c;
   }
-  Fl_Surface_Device::pop_current();
   int err2 = (ps->close_cmd_ ? (ps->close_cmd_)(ps->output) : fclose(ps->output) );
   if (!error) error = err2;
   if (error && ps->close_cmd_ == NULL) {
diff --git src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx
index 2e808f1..a92600d 100644
--- src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx
+++ src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx
@@ -152,14 +152,12 @@ int Fl_WinAPI_Printer_Driver::begin_job (int pagecount, int *frompage, int *topa
     y_offset = 0;
     WIN_SetupPrinterDeviceContext (hPr);
     driver()->gc(hPr);
-    this->set_current();
   }
   return err;
 }
 
 void Fl_WinAPI_Printer_Driver::end_job (void)
 {
-  Fl_Display_Device::display_device()->set_current();
   if (hPr != NULL) {
     if (! abortPrint) {
       prerr = EndDoc (hPr);
@@ -232,6 +230,7 @@ int Fl_WinAPI_Printer_Driver::begin_page (void)
 
   rsult = 0;
   if (hPr != NULL) {
+    Fl_Surface_Device::push_current(this);
     WIN_SetupPrinterDeviceContext (hPr);
     prerr = StartPage (hPr);
     if (prerr < 0) {
@@ -280,6 +279,7 @@ int Fl_WinAPI_Printer_Driver::end_page (void)
 
   rsult = 0;
   if (hPr != NULL) {
+    Fl_Surface_Device::pop_current();
     prerr = EndPage (hPr);
     if (prerr < 0) {
       abortPrint = TRUE;
Direct Link to Message ]
 
     
Previous Message ]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'.