changeset 16732:3806afcf974a

Include graphics image file name in latex file for {eps,pdf,ps}latex output. * libinterp/dldfcn/__init_fltk__.cc: Add print_cmd to gl2ps_renderer.draw. * libinterp/interp-core/gl2ps-renderer.h: Add print_cmd to declaration of draw. * libinterp/interp-core/gl2ps-renderer.cc: Extract the graphics filename to be included in the LaTeX document.
author Ben Abbott <bpabbott@mac.com>
date Sat, 08 Jun 2013 11:22:10 +0800
parents 01d523d5f796
children 2723d1144f11
files libinterp/dldfcn/__init_fltk__.cc libinterp/interp-core/gl2ps-renderer.cc libinterp/interp-core/gl2ps-renderer.h
diffstat 3 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__init_fltk__.cc	Fri Jun 07 23:13:48 2013 +0200
+++ b/libinterp/dldfcn/__init_fltk__.cc	Sat Jun 08 11:22:10 2013 +0800
@@ -183,7 +183,7 @@
         FILE *fp = octave_popen (print_cmd.c_str (), "w");
         glps_renderer rend (fp, print_term);
 
-        rend.draw (gh_manager::get_object (number));
+        rend.draw (gh_manager::get_object (number), print_cmd);
 
         octave_pclose (fp);
         print_mode = false;
--- a/libinterp/interp-core/gl2ps-renderer.cc	Fri Jun 07 23:13:48 2013 +0200
+++ b/libinterp/interp-core/gl2ps-renderer.cc	Sat Jun 08 11:22:10 2013 +0800
@@ -35,9 +35,10 @@
 #include "gl2ps.h"
 
 void
-glps_renderer::draw (const graphics_object& go)
+glps_renderer::draw (const graphics_object& go, const std::string print_cmd)
 {
   static bool in_draw = false;
+  static std::string old_print_cmd;
 
   if (!in_draw)
     {
@@ -70,6 +71,24 @@
 
       while (state == GL2PS_OVERFLOW)
         {
+          // For LaTeX output the fltk print process uses two drawnow() commands.
+          // The first one is for the pdf/ps/eps graph to be included.  The print_cmd
+          // is saved as old_print_cmd.  Then the second drawnow() outputs the tex-file
+          // and the graphic filename to be included is extracted from old_print_cmd.
+          std::string include_graph;
+          std::size_t found_redirect = old_print_cmd.find (">");
+          if (found_redirect != std::string::npos)
+            include_graph = old_print_cmd.substr (found_redirect + 1);
+          else
+            include_graph = old_print_cmd;
+          std::size_t n_begin = include_graph.find_first_not_of (" ");
+          if (n_begin != std::string::npos)
+            {
+              std::size_t n_end = include_graph.find_last_not_of (" ");
+              include_graph = include_graph.substr (n_begin, n_end - n_begin + 1);
+            }
+          else
+            include_graph = "foobar-inc";
           buffsize += 1024*1024;
           gl2psBeginPage ("glps_renderer figure", "Octave", viewport,
                           gl2ps_term, gl2ps_sort,
@@ -78,8 +97,8 @@
                            | GL2PS_BEST_ROOT | gl2ps_text
                            | GL2PS_NO_PS3_SHADING),
                           GL_RGBA, 0, NULL, 0, 0, 0,
-                          buffsize, fp, "" );
-
+                          buffsize, fp, include_graph.c_str ());
+          old_print_cmd = print_cmd;
           opengl_renderer::draw (go);
           state = gl2psEndPage ();
         }
--- a/libinterp/interp-core/gl2ps-renderer.h	Fri Jun 07 23:13:48 2013 +0200
+++ b/libinterp/interp-core/gl2ps-renderer.h	Sat Jun 08 11:22:10 2013 +0800
@@ -37,7 +37,7 @@
 
   ~glps_renderer (void) { }
 
-  void draw (const graphics_object& go);
+  void draw (const graphics_object& go, const std::string print_cmd);
 
 protected: