# HG changeset patch # User Rik # Date 1628021509 25200 # Node ID 4b25d83d152d78c49123b8c76bb91e46fbe06653 # Parent da7210e30f3e5fc730d6ad40038a85d37bfe7ecb Put title of plot into "Title" property of generated PDFs (bug #60992) * gl2ps-print.cc (get_title): New function to call get_title () on a figure graphics object. * gl2ps-print.cc (gl2ps_renderer::draw): New variable myhandle to hold "__myhandle__" property value. Call get_title() to get title for plot. If empty, use generic "Octave plot". Call gl2psBeginPage() with first argument being desired plot title. diff -r da7210e30f3e -r 4b25d83d152d libinterp/corefcn/gl2ps-print.cc --- a/libinterp/corefcn/gl2ps-print.cc Tue Aug 03 12:34:52 2021 -0400 +++ b/libinterp/corefcn/gl2ps-print.cc Tue Aug 03 13:11:49 2021 -0700 @@ -322,6 +322,29 @@ return retval; } + static std::string + get_title (const graphics_handle& h) + { + std::string retval; + + gh_manager& gh_mgr = __get_gh_manager__ ("gl2ps_renderer::get_title"); + + graphics_object go = gh_mgr.get_object (h); + + if (! go.valid_object ()) + return retval; + + if (go.isa ("figure")) + { + figure::properties& fp + = reinterpret_cast (go.get_properties ()); + + retval = fp.get_title (); + } + + return retval; + } + void gl2ps_renderer::draw (const graphics_object& go, const std::string& print_cmd) { @@ -358,12 +381,18 @@ if (m_term.find ("notxt") != std::string::npos) gl2ps_text = GL2PS_NO_TEXT; + // Find Title for plot + const graphics_handle& myhandle = go.get ("__myhandle__"); + std::string plot_title = get_title (myhandle); + if (plot_title.empty ()) + plot_title = "Octave plot"; + // Default sort order optimizes for 3D plots GLint gl2ps_sort = GL2PS_BSP_SORT; // FIXME: gl2ps does not provide a way to change the sorting algorithm // on a viewport basis, we thus disable sorting only if all axes are 2D - if (has_2D_axes (go.get ("__myhandle__"))) + if (has_2D_axes (myhandle)) gl2ps_sort = GL2PS_NO_SORT; // Use a temporary file in case an overflow happens @@ -431,7 +460,7 @@ set_device_pixel_ratio (fprop.get___device_pixel_ratio__ ()); // GL2PS_SILENT was removed to allow gl2ps to print errors on stderr - GLint ret = gl2psBeginPage ("gl2ps_renderer figure", "Octave", + GLint ret = gl2psBeginPage (plot_title.c_str (), "Octave", nullptr, gl2ps_term, gl2ps_sort, (GL2PS_BEST_ROOT | gl2ps_text