# HG changeset patch # User John W. Eaton # Date 1422569229 18000 # Node ID 61cc00ebac60024d32a6bc7b38f27e7ddad98b9f # Parent 3da4b083e0b8df8c27191ecbf06ba87503ca8b51 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc * gl2ps-renderer.h, gl2ps-renderer.cc (gl2ps_print): New function. * __init_fltk__.cc (OpenGL_fltk::print): Use it. diff -r 3da4b083e0b8 -r 61cc00ebac60 libinterp/corefcn/gl2ps-renderer.cc --- a/libinterp/corefcn/gl2ps-renderer.cc Tue Jan 27 18:55:25 2015 +0100 +++ b/libinterp/corefcn/gl2ps-renderer.cc Thu Jan 29 17:07:09 2015 -0500 @@ -30,9 +30,11 @@ #include "lo-mappers.h" #include "oct-locbuf.h" +#include "unwind-prot.h" #include "gl2ps-renderer.h" #include "gl2ps.h" +#include "sysdep.h" void glps_renderer::draw (const graphics_object& go, const std::string print_cmd) @@ -266,4 +268,34 @@ alignment_to_mode (halign, valign), props.get_rotation ()); } +static void +safe_pclose (FILE *f) +{ + if (f) + octave_pclose (f); +} + #endif + +void +gl2ps_print (const graphics_object& fig, const std::string& cmd, + const std::string& term) +{ +#ifdef HAVE_GL2PS_H + + unwind_protect frame; + + FILE *fp = octave_popen (cmd.c_str (), "w"); + + frame.add_fcn (safe_pclose, fp); + + glps_renderer rend (fp, term); + + rend.draw (fig, cmd); + +#else + + error ("print: printing not available without gl2ps library"); + +#endif +} diff -r 3da4b083e0b8 -r 61cc00ebac60 libinterp/corefcn/gl2ps-renderer.h --- a/libinterp/corefcn/gl2ps-renderer.h Tue Jan 27 18:55:25 2015 +0100 +++ b/libinterp/corefcn/gl2ps-renderer.h Thu Jan 29 17:07:09 2015 -0500 @@ -86,4 +86,8 @@ #endif // HAVE_GL2PS_H +extern OCTINTERP_API void +gl2ps_print (const graphics_object& fig, const std::string& cmd, + const std::string& term); + #endif diff -r 3da4b083e0b8 -r 61cc00ebac60 libinterp/dldfcn/__init_fltk__.cc --- a/libinterp/dldfcn/__init_fltk__.cc Tue Jan 27 18:55:25 2015 +0100 +++ b/libinterp/dldfcn/__init_fltk__.cc Thu Jan 29 17:07:09 2015 -0500 @@ -83,11 +83,9 @@ #include "display.h" #include "file-ops.h" -#include "gl-render.h" #include "gl2ps-renderer.h" #include "graphics.h" #include "parse.h" -#include "sysdep.h" #include "toplev.h" #include "variables.h" @@ -133,15 +131,8 @@ void print (const std::string& cmd, const std::string& term) { //std::cout << "OpenGL_fltk::print(cmd=" << cmd << ", term=" << term << ") canvas size = " << w () << "x" << h () << std::endl; -#ifdef HAVE_GL2PS_H - FILE *fp; - fp = octave_popen (cmd.c_str (), "w"); - glps_renderer rend (fp, term); - rend.draw (gh_manager::get_object (number), cmd); - octave_pclose (fp); -#else - error ("fltk: printing not available without gl2ps library"); -#endif + + gl2ps_print (gh_manager::get_object (number), cmd, term); } void resize (int xx, int yy, int ww, int hh)