--- octave-4.0.0-rc4/libinterp/corefcn/gl2ps-renderer.cc 2015-04-28 12:15:42.000000000 -0400 +++ octave-3.8.2/libinterp/corefcn/gl2ps-renderer.cc 2015-05-01 19:59:00.078151283 -0400 @@ -1,6 +1,6 @@ /* -Copyright (C) 2009-2015 Shai Ayal +Copyright (C) 2009-2013 Shai Ayal This file is part of Octave. @@ -24,9 +24,6 @@ #include #endif -#include "error.h" -#include "gl2ps-renderer.h" - #ifdef HAVE_GL2PS_H #include @@ -35,6 +32,7 @@ #include "oct-locbuf.h" #include "unwind-prot.h" +#include "gl2ps-renderer.h" #include "gl2ps.h" #include "sysdep.h" @@ -46,44 +44,32 @@ if (!in_draw) { - unwind_protect frame; + in_draw = true; - frame.protect_var (in_draw); + GLint buffsize = 0, state = GL2PS_OVERFLOW; + GLint viewport[4]; - in_draw = true; + glGetIntegerv (GL_VIEWPORT, viewport); GLint gl2ps_term; - if (term.find ("eps") != std::string::npos) - gl2ps_term = GL2PS_EPS; - else if (term.find ("pdf") != std::string::npos) - gl2ps_term = GL2PS_PDF; - else if (term.find ("ps") != std::string::npos) - gl2ps_term = GL2PS_PS; - else if (term.find ("svg") != std::string::npos) - gl2ps_term = GL2PS_SVG; - else if (term.find ("pgf") != std::string::npos) - gl2ps_term = GL2PS_PGF; - else if (term.find ("tex") != std::string::npos) - gl2ps_term = GL2PS_TEX; + if (term.find ("eps") != std::string::npos) gl2ps_term = GL2PS_EPS; + else if (term.find ("pdf") != std::string::npos) gl2ps_term = GL2PS_PDF; + else if (term.find ("svg") != std::string::npos) gl2ps_term = GL2PS_SVG; + else if (term.find ("ps") != std::string::npos) gl2ps_term = GL2PS_PS; + else if (term.find ("pgf") != std::string::npos) gl2ps_term = GL2PS_PGF; + else if (term.find ("tex") != std::string::npos) gl2ps_term = GL2PS_TEX; else { - error ("gl2ps-renderer::draw: Unknown terminal %s", term.c_str ()); + error ("gl2ps-renderer:: Unknown terminal"); return; } GLint gl2ps_text = 0; - if (term.find ("notxt") != std::string::npos) - gl2ps_text = GL2PS_NO_TEXT; + if (term.find ("notxt") != std::string::npos) gl2ps_text = GL2PS_NO_TEXT; // Default sort order optimizes for 3D plots GLint gl2ps_sort = GL2PS_BSP_SORT; - - // For 2D plots we can use a simpler Z-depth sorting algorithm - if (term.find ("is2D") != std::string::npos) - gl2ps_sort = GL2PS_SIMPLE_SORT; - - GLint state = GL2PS_OVERFLOW; - GLint buffsize = 0; + if (term.find ("is2D") != std::string::npos) gl2ps_sort = GL2PS_NO_SORT; while (state == GL2PS_OVERFLOW) { @@ -92,71 +78,36 @@ // 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; - - size_t found_redirect = old_print_cmd.find (">"); - + 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; - - size_t n_begin = include_graph.find_first_not_of (" "); - + std::size_t n_begin = include_graph.find_first_not_of (" "); if (n_begin != std::string::npos) { - size_t n_end = include_graph.find_last_not_of (" "); + 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; - - // GL2PS_SILENT was removed to allow gl2ps printing errors on stderr - GLint ret = gl2psBeginPage ("glps_renderer figure", "Octave", 0, - gl2ps_term, gl2ps_sort, - (GL2PS_NO_BLENDING - | GL2PS_OCCLUSION_CULL - | GL2PS_BEST_ROOT - | gl2ps_text - | GL2PS_NO_PS3_SHADING - | GL2PS_USE_CURRENT_VIEWPORT), - GL_RGBA, 0, 0, 0, 0, 0, - buffsize, fp, include_graph.c_str ()); - if (ret == GL2PS_ERROR) - { - old_print_cmd.clear (); - error ("gl2ps-renderer::draw: gl2psBeginPage returned GL2PS_ERROR"); - return; - } - + gl2psBeginPage ("glps_renderer figure", "Octave", viewport, + gl2ps_term, gl2ps_sort, + (GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET + | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL + | GL2PS_BEST_ROOT | gl2ps_text + | GL2PS_NO_PS3_SHADING), + GL_RGBA, 0, NULL, 0, 0, 0, + buffsize, fp, include_graph.c_str ()); old_print_cmd = print_cmd; - opengl_renderer::draw (go); - - // Without glFinish () there may primitives be missing in the - // gl2ps output. - glFinish (); - state = gl2psEndPage (); + } - if (state == GL2PS_NO_FEEDBACK) - { - warning ("gl2ps-renderer::draw: empty feedback buffer and/or nothing else to print"); - } - else if (state == GL2PS_ERROR) - { - old_print_cmd.clear (); - error ("gl2ps-renderer::draw: gl2psEndPage returned GL2PS_ERROR"); - return; - } - - // Don't check state for GL2PS_UNINITIALIZED (should never happen) - // GL2PS_OVERFLOW (see while loop) or GL2PS_SUCCESS - } + in_draw = 0; } else opengl_renderer::draw (go); @@ -165,8 +116,7 @@ int glps_renderer::alignment_to_mode (int ha, int va) const { - int gl2psa = GL2PS_TEXT_BL; - + int gl2psa=GL2PS_TEXT_BL; if (ha == 0) { if (va == 0 || va == 3) @@ -194,7 +144,6 @@ else if (va == 1) gl2psa=GL2PS_TEXT_C; } - return gl2psa; } @@ -207,16 +156,14 @@ return Matrix (1, 4, 0.0); glRasterPos3d (x, y, z); - gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, alignment_to_mode (ha, va), rotation); // FIXME? - // We have no way of getting a bounding box from gl2ps, so we use FreeType. + // We have no way of getting a bounding box from gl2ps, so we use freetype. Matrix bbox; uint8NDArray pixels; text_to_pixels (txt, pixels, bbox, 0, 0, rotation); - return bbox; } @@ -225,52 +172,22 @@ { opengl_renderer::set_font (props); - fontsize = props.get ("fontsize_points").double_value (); - - caseless_str fn = props.get ("fontname").xtolower ().string_value (); - bool isbold = - (props.get ("fontweight").xtolower ().string_value () == "bold"); - bool isitalic = - (props.get ("fontangle").xtolower ().string_value () == "italic"); + fontsize = props.get ("fontsize").double_value (); + caseless_str fn = props.get ("fontname").string_value (); fontname = ""; if (fn == "times" || fn == "times-roman") - { - if (isitalic && isbold) - fontname = "Times-BoldItalic"; - else if (isitalic) - fontname = "Times-Italic"; - else if (isbold) - fontname = "Times-Bold"; - else - fontname = "Times-Roman"; - } + fontname = "Times-Roman"; else if (fn == "courier") - { - if (isitalic && isbold) - fontname = "Courier-BoldOblique"; - else if (isitalic) - fontname = "Courier-Oblique"; - else if (isbold) - fontname = "Courier-Bold"; - else - fontname = "Courier"; - } + fontname = "Courier"; else if (fn == "symbol") fontname = "Symbol"; else if (fn == "zapfdingbats") fontname = "ZapfDingbats"; else - { - if (isitalic && isbold) - fontname = "Helvetica-BoldOblique"; - else if (isitalic) - fontname = "Helvetica-Oblique"; - else if (isbold) - fontname = "Helvetica-Bold"; - else - fontname = "Helvetica"; - } + fontname = "Helvetica"; + + // FIXME: add support for bold and italic } template @@ -280,9 +197,9 @@ OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*w*h); // Convert to GL_FLOAT as it is the only type gl2ps accepts. - for (int i = 0; i < 3*w*h; i++) + for (unsigned int i = 0; i < 3*w*h; i++) a[i] = data[i] / maxval; - + gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a); } @@ -310,8 +227,7 @@ set_color (props.get_color_rgb ()); const Matrix pos = get_transform ().scale (props.get_data_position ()); - int halign = 0; - int valign = 0; + int halign = 0, valign = 0; if (props.horizontalalignment_is ("center")) halign = 1; -++ octave-4.0.0-rc4/libinterp/corefcn/gl2ps-renderer.h 2015-04-28 12:15:42.000000000 -0400 +-- octave-3.8.2/libinterp/corefcn/gl2ps-renderer.h 2014-08-06 13:54:14.000000000 -0400 @@ -1,6 +1,6 @@ /* -Copyright (C) 2009-2015 Shai Ayal +Copyright (C) 2009-2013 Shai Ayal This file is part of Octave. @@ -23,8 +23,6 @@ #if !defined (octave_gl2ps_renderer_h) #define octave_gl2ps_renderer_h 1 -#include "graphics.h" - #ifdef HAVE_GL2PS_H #include "gl-render.h" @@ -40,7 +38,7 @@ ~glps_renderer (void) { } - void draw (const graphics_object& go, const std::string& print_cmd); + void draw (const graphics_object& go, const std::string print_cmd); protected: @@ -64,18 +62,13 @@ gl2psEnable (GL2PS_LINE_STIPPLE); } - void set_polygon_offset (bool on, float offset = 0.0f) + void set_polygon_offset (bool on, double offset = 0.0) { + opengl_renderer::set_polygon_offset (on, offset); if (on) - { - opengl_renderer::set_polygon_offset (on, offset); - gl2psEnable (GL2PS_POLYGON_OFFSET_FILL); - } + gl2psEnable (GL2PS_POLYGON_OFFSET_FILL); else - { - gl2psDisable (GL2PS_POLYGON_OFFSET_FILL); - opengl_renderer::set_polygon_offset (on, offset); - } + gl2psDisable (GL2PS_POLYGON_OFFSET_FILL); } void set_linewidth (float w)