FLTK logo

[master] cd60ea1 - Add Fl_PostScript_File_Device::set_current() and end_current() members.

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] cd60ea1 - Add Fl_PostScript_File_Device::set_current() and end_current() members. "ManoloFLTK" Jul 24, 2022  
 
commit cd60ea17b021ce4442bc5efea8b7082463c682b8
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sun Jul 24 08:46:52 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sun Jul 24 08:46:52 2022 +0200

    Add Fl_PostScript_File_Device::set_current() and end_current() members.

 FL/Fl_PostScript.H                       |  6 +++++
 src/drivers/PostScript/Fl_PostScript.cxx | 38 ++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git FL/Fl_PostScript.H FL/Fl_PostScript.H
index 5461455..bb9b27d 100644
--- FL/Fl_PostScript.H
+++ FL/Fl_PostScript.H
@@ -71,6 +71,10 @@ class Fl_PostScript_Graphics_Driver;
 
  */
 class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
+private:
+  // memorize the display's current font to restore it when the object ceases being current
+  Fl_Font display_font_;
+  Fl_Fontsize display_size_;
 protected:
   /**
    \brief Returns the PostScript driver of this drawing surface.
@@ -139,6 +143,8 @@ public:
   FILE *file();
   /** Sets the function end_job() calls to close the file() */
   void close_command(Fl_PostScript_Close_Command cmd);
+  virtual void set_current();
+  virtual void end_current();
 };
 
 /** Encapsulated PostScript drawing surface.
diff --git src/drivers/PostScript/Fl_PostScript.cxx src/drivers/PostScript/Fl_PostScript.cxx
index e27a91f..7b69f51 100644
--- src/drivers/PostScript/Fl_PostScript.cxx
+++ src/drivers/PostScript/Fl_PostScript.cxx
@@ -91,6 +91,21 @@ Fl_PostScript_File_Device::~Fl_PostScript_File_Device() {
   if (ps) delete ps;
 }
 
+void Fl_PostScript_File_Device::set_current() {
+  Fl_Graphics_Driver& driver = Fl_Graphics_Driver::default_driver();
+  display_font_ = driver.font();
+  display_size_ = driver.size();
+  Fl_Paged_Device::set_current();
+}
+
+void Fl_PostScript_File_Device::end_current() {
+  if (display_font_ >= 0 && display_size_ > 0)  {
+    Fl_Graphics_Driver& driver = Fl_Graphics_Driver::default_driver();
+    driver.font(display_font_, display_size_);
+  }
+  Fl_Paged_Device::end_current();
+}
+
 /**
  \cond DriverDev
  \addtogroup DriverDeveloper
@@ -1451,16 +1466,14 @@ static cairo_status_t write_to_cairo_stream(FILE *output, unsigned char *data, u
   return (l == length ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR);
 }
 
-static int init_cairo_postscript(FILE* output, cairo_t* &cairo_,
-                                 Fl_Cairo_Graphics_Driver *driver,
-                                 int w, int h) {
-  cairo_surface_t* cs = cairo_ps_surface_create_for_stream((cairo_write_func_t)write_to_cairo_stream, output, w, h);
-  if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) return 1;
+static cairo_t* init_cairo_postscript(FILE* output, int w, int h) {
+  cairo_surface_t* cs = cairo_ps_surface_create_for_stream(
+                        (cairo_write_func_t)write_to_cairo_stream, output, w, h);
+  if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) return NULL;
   cairo_ps_surface_restrict_to_level(cs, CAIRO_PS_LEVEL_2);
-  cairo_ = cairo_create(cs);
+  cairo_t* cairo_ = cairo_create(cs);
   cairo_surface_destroy(cs);
-  driver->Fl_Cairo_Graphics_Driver::font(0, 0); // to create the PangoLayout
-  return 0;
+  return cairo_;
 }
 
 int Fl_PostScript_Graphics_Driver::start_postscript(int pagecount,
@@ -1483,8 +1496,9 @@ int Fl_PostScript_Graphics_Driver::start_postscript(int pagecount,
     pw_ = Fl_Paged_Device::page_formats[format].width;
     ph_ = Fl_Paged_Device::page_formats[format].height;
   }
-  if (init_cairo_postscript(output, cairo_, this,
-                            Fl_Paged_Device::page_formats[format].width, Fl_Paged_Device::page_formats[format].height)) return 1;
+  cairo_ = init_cairo_postscript(output, Fl_Paged_Device::page_formats[format].width,
+                            Fl_Paged_Device::page_formats[format].height);
+  if (!cairo_) return 1;
   nPages=0;
   char feature[250];
   sprintf(feature, "%%%%BeginFeature: *PageSize %s\n<</PageSize[%d %d]>>setpagedevice\n%%%%EndFeature",
@@ -1496,8 +1510,8 @@ int Fl_PostScript_Graphics_Driver::start_postscript(int pagecount,
 int Fl_PostScript_Graphics_Driver::start_eps(int width, int height) {
   pw_ = width;
   ph_ = height;
-  if (init_cairo_postscript(output, cairo_, this,
-                            width, height)) return 1;
+  cairo_ = init_cairo_postscript(output, width, height);
+  if (!cairo_) return 1;
   cairo_ps_surface_set_eps(cairo_get_target(cairo_), true);
   nPages=0; //useful?
   return 0;
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'.