42 glps_renderer::draw (
const graphics_object& go,
const std::string& print_cmd)
44 static bool in_draw =
false;
45 static std::string old_print_cmd;
56 if (term.find (
"eps") != std::string::npos)
57 gl2ps_term = GL2PS_EPS;
58 else if (term.find (
"pdf") != std::string::npos)
59 gl2ps_term = GL2PS_PDF;
60 else if (term.find (
"ps") != std::string::npos)
61 gl2ps_term = GL2PS_PS;
62 else if (term.find (
"svg") != std::string::npos)
63 gl2ps_term = GL2PS_SVG;
64 else if (term.find (
"pgf") != std::string::npos)
65 gl2ps_term = GL2PS_PGF;
66 else if (term.find (
"tex") != std::string::npos)
67 gl2ps_term = GL2PS_TEX;
70 error (
"gl2ps-renderer::draw: Unknown terminal %s", term.c_str ());
75 if (term.find (
"notxt") != std::string::npos)
76 gl2ps_text = GL2PS_NO_TEXT;
79 GLint gl2ps_sort = GL2PS_BSP_SORT;
82 if (term.find (
"is2D") != std::string::npos)
83 gl2ps_sort = GL2PS_SIMPLE_SORT;
85 GLint
state = GL2PS_OVERFLOW;
88 while (state == GL2PS_OVERFLOW)
96 std::string include_graph;
98 size_t found_redirect = old_print_cmd.find (
">");
100 if (found_redirect != std::string::npos)
101 include_graph = old_print_cmd.substr (found_redirect + 1);
103 include_graph = old_print_cmd;
105 size_t n_begin = include_graph.find_first_not_of (
" ");
107 if (n_begin != std::string::npos)
109 size_t n_end = include_graph.find_last_not_of (
" ");
110 include_graph = include_graph.substr (n_begin,
111 n_end - n_begin + 1);
114 include_graph =
"foobar-inc";
116 buffsize += 1024*1024;
119 GLint ret = gl2psBeginPage (
"glps_renderer figure",
"Octave", 0,
120 gl2ps_term, gl2ps_sort,
122 | GL2PS_OCCLUSION_CULL
125 | GL2PS_NO_PS3_SHADING
126 | GL2PS_USE_CURRENT_VIEWPORT),
127 GL_RGBA, 0, 0, 0, 0, 0,
128 buffsize, fp, include_graph.c_str ());
129 if (ret == GL2PS_ERROR)
131 old_print_cmd.clear ();
132 error (
"gl2ps-renderer::draw: gl2psBeginPage returned GL2PS_ERROR");
136 old_print_cmd = print_cmd;
138 opengl_renderer::draw (go);
144 state = gl2psEndPage ();
146 if (state == GL2PS_NO_FEEDBACK)
148 warning (
"gl2ps-renderer::draw: empty feedback buffer and/or nothing else to print");
150 else if (state == GL2PS_ERROR)
152 old_print_cmd.clear ();
153 error (
"gl2ps-renderer::draw: gl2psEndPage returned GL2PS_ERROR");
162 opengl_renderer::draw (go);
166 glps_renderer::alignment_to_mode (
int ha,
int va)
const
168 int gl2psa = GL2PS_TEXT_BL;
172 if (va == 0 || va == 3)
173 gl2psa=GL2PS_TEXT_BL;
175 gl2psa=GL2PS_TEXT_TL;
177 gl2psa=GL2PS_TEXT_CL;
181 if (va == 0 || va == 3)
182 gl2psa=GL2PS_TEXT_BR;
184 gl2psa=GL2PS_TEXT_TR;
186 gl2psa=GL2PS_TEXT_CR;
190 if (va == 0 || va == 3)
202 glps_renderer::render_text (
const std::string& txt,
203 double x,
double y,
double z,
204 int ha,
int va,
double rotation)
207 return Matrix (1, 4, 0.0);
209 glRasterPos3d (x, y, z);
211 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize,
212 alignment_to_mode (ha, va), rotation);
218 text_to_pixels (txt, pixels, bbox, 0, 0, rotation);
226 opengl_renderer::set_font (props);
237 if (fn ==
"times" || fn ==
"times-roman")
239 if (isitalic && isbold)
240 fontname =
"Times-BoldItalic";
242 fontname =
"Times-Italic";
244 fontname =
"Times-Bold";
246 fontname =
"Times-Roman";
248 else if (fn ==
"courier")
250 if (isitalic && isbold)
251 fontname =
"Courier-BoldOblique";
253 fontname =
"Courier-Oblique";
255 fontname =
"Courier-Bold";
257 fontname =
"Courier";
259 else if (fn ==
"symbol")
261 else if (fn ==
"zapfdingbats")
262 fontname =
"ZapfDingbats";
265 if (isitalic && isbold)
266 fontname =
"Helvetica-BoldOblique";
268 fontname =
"Helvetica-Oblique";
270 fontname =
"Helvetica-Bold";
272 fontname =
"Helvetica";
276 template <
typename T>
278 draw_pixels (GLsizei
w, GLsizei h, GLenum format,
const T *data,
float maxval)
283 for (
int i = 0; i < 3*w*h; i++)
284 a[i] = data[i] / maxval;
286 gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a);
290 glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format,
291 GLenum
type,
const GLvoid *data)
295 if (type == GL_UNSIGNED_BYTE)
296 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data), 255.0
f);
297 else if (type == GL_UNSIGNED_SHORT)
298 ::draw_pixels (w, h, format, static_cast<const GLushort *> (data), 65535.0
f);
300 gl2psDrawPixels (w, h, 0, 0, format, type, data);
330 glRasterPos3d (pos(0), pos(1), pos.numel () > 2 ? pos(2) : 0.0);
336 std::string s = sv.
join (
"\n");
338 gl2psTextOpt (s.c_str (), fontname.c_str (), fontsize,
339 alignment_to_mode (halign, valign), props.
get_rotation ());
343 safe_pclose (FILE *
f)
353 const std::string& term)
363 frame.
add_fcn (safe_pclose, fp);
365 glps_renderer rend (fp, term);
367 rend.draw (fig, cmd);
370 error (
"print: failed to open pipe for gl2ps renderer");
374 error (
"print: printing not available without gl2ps library");
FILE * octave_popen(const char *command, const char *mode)
Matrix get_data_position(void) const
int octave_pclose(FILE *f)
static uint32_t state[624]
void error(const char *fmt,...)
bool verticalalignment_is(const std::string &v) const
string_vector all_strings(bool pad=false) const
void gl2ps_print(const graphics_object &fig, const std::string &cmd, const std::string &term)
octave_value xtolower(void) const
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
std::string string_value(bool force=false) const
std::complex< double > w(std::complex< double > z, double relerr=0)
octave_value get_string(void) const
void warning(const char *fmt,...)
double get_rotation(void) const
bool is_empty(void) const
virtual octave_value get(const caseless_str &pname) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
double double_value(bool frc_str_conv=false) const
std::string join(const std::string &sep=std::string()) const
F77_RET_T const double * x
Matrix get_color_rgb(void) const
bool horizontalalignment_is(const std::string &v) const