23 #if defined (HAVE_CONFIG_H)
31 #if defined (HAVE_GL2PS_H)
55 gl2ps_renderer :
public opengl_renderer
59 gl2ps_renderer (FILE *_fp,
const std::string& _term)
60 :
octave::opengl_renderer () , fp (_fp), term (_term), fontsize (),
61 fontname (), buffer_overflow (
false)
64 ~gl2ps_renderer (
void) { }
78 double x,
double y,
double z,
79 int halign,
int valign,
double rotation = 0.0);
87 glGetIntegerv (GL_VIEWPORT, vp);
88 gl2psBeginViewport (vp);
95 GLint
state = gl2psEndViewport ();
96 if (state == GL2PS_NO_FEEDBACK)
97 warning (
"gl2ps_renderer::draw_axes: empty feedback buffer and/or nothing else to print");
98 else if (state == GL2PS_ERROR)
99 error (
"gl2ps_renderer::draw_axes: gl2psEndPage returned GL2PS_ERROR");
101 buffer_overflow |= (state == GL2PS_OVERFLOW);
105 gl2psGetOptions (&opts);
106 opts &= ~GL2PS_DRAW_BACKGROUND;
107 gl2psSetOptions (opts);
112 void draw_pixels (
int w,
int h,
const float *data);
113 void draw_pixels (
int w,
int h,
const uint8_t *data);
114 void draw_pixels (
int w,
int h,
const uint16_t *data);
116 void set_linestyle (
const std::string&
s,
bool use_stipple =
false,
117 double linewidth = 0.5)
121 if (s ==
"-" && ! use_stipple)
122 gl2psDisable (GL2PS_LINE_STIPPLE);
124 gl2psEnable (GL2PS_LINE_STIPPLE);
127 void set_polygon_offset (
bool on,
float offset = 0.0
f)
132 gl2psEnable (GL2PS_POLYGON_OFFSET_FILL);
136 gl2psDisable (GL2PS_POLYGON_OFFSET_FILL);
141 void set_linewidth (
float w)
150 void fix_strlist_position (
double x,
double y,
double z,
152 std::list<octave::text_renderer::string>& lst);
154 int alignment_to_mode (
int ha,
int va)
const;
159 bool buffer_overflow;
165 static bool in_draw =
false;
176 GLint gl2ps_term = GL2PS_PS;
177 if (term.find (
"eps") != std::string::npos)
178 gl2ps_term = GL2PS_EPS;
179 else if (term.find (
"pdf") != std::string::npos)
180 gl2ps_term = GL2PS_PDF;
181 else if (term.find (
"ps") != std::string::npos)
182 gl2ps_term = GL2PS_PS;
183 else if (term.find (
"svg") != std::string::npos)
184 gl2ps_term = GL2PS_SVG;
185 else if (term.find (
"pgf") != std::string::npos)
186 gl2ps_term = GL2PS_PGF;
187 else if (term.find (
"tex") != std::string::npos)
188 gl2ps_term = GL2PS_TEX;
190 warning (
"gl2ps_renderer::draw: Unknown terminal %s, using 'ps'",
193 GLint gl2ps_text = 0;
194 if (term.find (
"notxt") != std::string::npos)
195 gl2ps_text = GL2PS_NO_TEXT;
198 GLint gl2ps_sort = GL2PS_BSP_SORT;
201 if (term.find (
"is2D") != std::string::npos)
202 gl2ps_sort = GL2PS_SIMPLE_SORT;
208 error (
"gl2ps_renderer::draw: couldn't open temporary file for printing");
210 GLint buffsize = 2*1024*1024;
211 buffer_overflow =
true;
213 while (buffer_overflow)
215 buffer_overflow =
false;
228 size_t found_redirect = old_print_cmd.find (
">");
230 if (found_redirect != std::string::npos)
231 include_graph = old_print_cmd.substr (found_redirect + 1);
233 include_graph = old_print_cmd;
235 size_t n_begin = include_graph.find_first_not_of (
" ");
237 if (n_begin != std::string::npos)
239 size_t n_end = include_graph.find_last_not_of (
" ");
240 include_graph = include_graph.substr (n_begin,
241 n_end - n_begin + 1);
244 include_graph =
"foobar-inc";
247 GLint ret = gl2psBeginPage (
"gl2ps_renderer figure",
"Octave", 0,
248 gl2ps_term, gl2ps_sort,
250 | GL2PS_OCCLUSION_CULL
253 | GL2PS_DRAW_BACKGROUND
254 | GL2PS_NO_PS3_SHADING
255 | GL2PS_USE_CURRENT_VIEWPORT),
256 GL_RGBA, 0, 0, 0, 0, 0,
257 buffsize, tmpf, include_graph.c_str ());
258 if (ret == GL2PS_ERROR)
260 old_print_cmd.clear ();
261 error (
"gl2ps_renderer::draw: gl2psBeginPage returned GL2PS_ERROR");
266 if (! buffer_overflow)
267 old_print_cmd = print_cmd;
278 size_t nread, nwrite;
280 while (! feof (tmpf) && nread)
282 nread = std::fread (str, 1, 256, tmpf);
285 nwrite = std::fwrite (str, 1, nread, fp);
289 error (
"gl2ps_renderer::draw: internal pipe error");
299 gl2ps_renderer::alignment_to_mode (
int ha,
int va)
const
301 int gl2psa = GL2PS_TEXT_BL;
305 if (va == 0 || va == 3)
306 gl2psa=GL2PS_TEXT_BL;
308 gl2psa=GL2PS_TEXT_TL;
310 gl2psa=GL2PS_TEXT_CL;
314 if (va == 0 || va == 3)
315 gl2psa=GL2PS_TEXT_BR;
317 gl2psa=GL2PS_TEXT_TR;
319 gl2psa=GL2PS_TEXT_CR;
323 if (va == 0 || va == 3)
335 gl2ps_renderer::fix_strlist_position (
double x,
double y,
double z,
337 std::list<octave::text_renderer::string>& lst)
339 for (std::list<octave::text_renderer::string>::iterator
p = lst.begin ();
340 p != lst.end ();
p++)
343 ColumnVector coord_pix = get_transform ().transform (x, y, z,
false);
346 double rot = rotation * 4.0 *
atan (1.0) / 180;
347 coord_pix(0) += ((*p).get_x () +
box(0))*cos (rot)
348 - ((*p).get_y () +
box(1))*sin (rot);
349 coord_pix(1) -= ((*p).get_y () +
box(1))*cos (rot)
350 + ((*p).get_x () +
box(0))*sin (rot);;
354 get_transform ().untransform (coord_pix(0), coord_pix(1),
355 coord_pix(2),
false);
356 (*p).set_x (coord(0));
357 (*p).set_y (coord(1));
358 (*p).set_z (coord(2));
364 code_to_symbol (uint32_t
code)
368 uint32_t idx = code - 945;
371 std::string characters(
"abgdezhqiklmnxoprVstufcyw");
372 retval = characters[idx];
379 std::string characters(
"ABGDEZHQIKLMNXOPRVSTUFCYW");
380 retval = characters[idx];
382 else if (code == 978)
384 else if (code == 215)
386 else if (code == 177)
388 else if (code == 8501)
390 else if (code == 8465)
392 else if (code == 8242)
394 else if (code == 8736)
396 else if (code == 172)
398 else if (code == 9829)
400 else if (code == 8472)
402 else if (code == 8706)
404 else if (code == 8704)
406 else if (code == 9827)
408 else if (code == 9824)
410 else if (code == 8476)
412 else if (code == 8734)
414 else if (code == 8730)
416 else if (code == 8707)
418 else if (code == 9830)
420 else if (code == 8747)
422 else if (code == 8727)
424 else if (code == 8744)
426 else if (code == 8855)
428 else if (code == 8901)
430 else if (code == 8728)
432 else if (code == 8745)
434 else if (code == 8743)
436 else if (code == 8856)
438 else if (code == 8729)
440 else if (code == 8746)
442 else if (code == 8853)
444 else if (code == 8804)
446 else if (code == 8712)
448 else if (code == 8839)
450 else if (code == 8801)
452 else if (code == 8773)
454 else if (code == 8834)
456 else if (code == 8805)
458 else if (code == 8715)
460 else if (code == 8764)
462 else if (code == 8733)
464 else if (code == 8838)
466 else if (code == 8835)
468 else if (code == 8739)
470 else if (code == 8776)
472 else if (code == 8869)
474 else if (code == 8656)
476 else if (code == 8592)
478 else if (code == 8658)
480 else if (code == 8594)
482 else if (code == 8596)
484 else if (code == 8593)
486 else if (code == 8595)
488 else if (code == 8970)
490 else if (code == 8971)
492 else if (code == 10216)
494 else if (code == 10217)
496 else if (code == 8968)
498 else if (code == 8969)
500 else if (code == 8800)
502 else if (code == 8230)
504 else if (code == 176)
506 else if (code == 8709)
508 else if (code == 169)
512 warning (
"print: unhandled symbol %d", code);
518 select_font (
caseless_str fn,
bool isbold,
bool isitalic)
522 if (fn ==
"times" || fn ==
"times-roman")
524 if (isitalic && isbold)
525 fontname =
"Times-BoldItalic";
527 fontname =
"Times-Italic";
529 fontname =
"Times-Bold";
531 fontname =
"Times-Roman";
533 else if (fn ==
"courier")
535 if (isitalic && isbold)
536 fontname =
"Courier-BoldOblique";
538 fontname =
"Courier-Oblique";
540 fontname =
"Courier-Bold";
542 fontname =
"Courier";
544 else if (fn ==
"symbol")
546 else if (fn ==
"zapfdingbats")
547 fontname =
"ZapfDingbats";
550 if (isitalic && isbold)
551 fontname =
"Helvetica-BoldOblique";
553 fontname =
"Helvetica-Oblique";
555 fontname =
"Helvetica-Bold";
557 fontname =
"Helvetica";
565 std::size_t idx = str.find (chr);
566 while (idx != std::string::npos)
568 str.insert (idx,
"\\");
569 idx = str.find (chr, idx + 2);
576 gl2ps_renderer::render_text (
const std::string& txt,
577 double x,
double y,
double z,
578 int ha,
int va,
double rotation)
583 return Matrix (1, 4, 0.0);
589 std::list<octave::text_renderer::string> lst;
591 text_to_strlist (str, lst, bbox, ha, va, rotation);
595 if (lst.empty () || term.find (
"tex") != std::string::npos
596 || (lst.size () == 1 && ! lst.front ().get_code ()))
600 if (! lst.empty () && term.find (
"tex") == std::string::npos)
610 glRasterPos3d (x, y, z);
613 if (term.find (
"svg") == std::string::npos
614 && term.find (
"tex") == std::string::npos)
616 escape_character (
"(", str);
617 escape_character (
")", str);
620 gl2psTextOpt (str.c_str (), name.c_str (),
sz,
621 alignment_to_mode (ha, va), rotation);
626 fix_strlist_position (x, y, z, bbox, rotation, lst);
628 for (std::list<octave::text_renderer::string>::iterator
p = lst.begin ();
629 p != lst.end ();
p++)
631 fontname = select_font ((*p).get_name (),
632 (*p).get_weight () ==
"bold",
633 (*p).get_angle () ==
"italic");
634 if ((*p).get_code ())
639 if (term.find (
"svg") == std::string::npos)
642 str = code_to_symbol ((*p).get_code ());
646 std::stringstream ss;
647 ss << (*p).get_code ();
648 str =
"&#" + ss.str () +
";";
653 str = (*p).get_string ();
655 if (term.find (
"svg") == std::string::npos)
657 escape_character (
"(", str);
658 escape_character (
")", str);
662 set_color ((*p).get_color ());
663 glRasterPos3d ((*p).get_x (), (*p).get_y (), (*p).get_z ());
664 gl2psTextOpt (str.c_str (), fontname.c_str (), (*p).get_size (),
665 GL2PS_TEXT_BL, rotation);
668 fontname = saved_font;
689 fontname = select_font (fn, isbold, isitalic);
693 gl2ps_renderer::draw_pixels (
int w,
int h,
const float *data)
698 for (
int i = 0;
i < 3*h*
w;
i++)
699 tmp_data[
i] = (data[
i] < 0.0
f ? 0.0
f : (data[
i] > 1.0
f ? 1.0
f : data[
i]));
701 gl2psDrawPixels (w, h, 0, 0, GL_RGB, GL_FLOAT, tmp_data);
705 gl2ps_renderer::draw_pixels (
int w,
int h,
const uint8_t *data)
713 for (
int i = 0;
i < 3*w*
h;
i++)
714 tmp_data[
i] = data[
i] / maxval;
716 draw_pixels (w, h, tmp_data);
720 gl2ps_renderer::draw_pixels (
int w,
int h,
const uint16_t *data)
728 for (
int i = 0;
i < 3*w*
h;
i++)
729 tmp_data[
i] = data[
i] / maxval;
731 draw_pixels (w, h, tmp_data);
770 render_text (str, pos(0), pos(1), pos.
numel () > 2 ? pos(2) : 0.0,
771 halign, valign, props.get_rotation ());
777 safe_pclose (FILE *
f)
802 #if defined (HAVE_GL2PS_H)
807 bool have_cmd = stream.length () > 1 && stream[0] ==
'|';
822 error (
"print: failed to open pipe \"%s\"", stream.c_str ());
824 frame.
add_fcn (safe_pclose, fp);
830 fp = std::fopen (stream.c_str (),
"w");
833 error (
"gl2ps_print: failed to create file \"%s\"", stream.c_str ());
838 gl2ps_renderer rend (fp, term);
840 rend.draw (fig, stream);
Octave interface to the compression and uncompression libraries.
Matrix get_color(void) const
FILE * octave_popen(const char *command, const char *mode)
Matrix get_data_position(void) const
int octave_pclose(FILE *f)
virtual void set_polygon_offset(bool on, float offset=0.0f)
octave_idx_type numel(void) const
Number of elements in the array.
int octave_ftruncate_wrapper(int fd, off_t sz)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
virtual void draw(const graphics_object &go, bool toplevel=true)
std::string get_weight(void) const
void error(const char *fmt,...)
std::string get_string(void) const
bool verticalalignment_is(const std::string &v) const
virtual void draw_axes(const axes::properties &props)
octave_value xtolower(void) const
Complex atan(const Complex &x)
void add_fcn(void(*fcn)(void))
std::string string_value(bool force=false) const
std::string join(const std::string &sep="") const
std::complex< double > w(std::complex< double > z, double relerr=0)
void gl2ps_print(const graphics_object &fig, const std::string &stream, const std::string &term)
void signal_handler(void)
FILE * octave_tmpfile_wrapper(void)
string_vector string_vector_value(bool pad=false) const
virtual void set_linestyle(const std::string &s, bool stipple=false, double linewidth=0.5)
static uint32_t state[624]
octave_value get_string(void) const
void warning(const char *fmt,...)
octave::unwind_protect frame
charNDArray max(char d, const charNDArray &m)
bool is_empty(void) const
virtual octave_value get(const caseless_str &pname) const
std::string get_angle(void) const
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=0)
Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value.
=val(i)}if ode{val(i)}occurs in table i
the element is set to zero In other the statement xample y
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
ColumnVector transform(const Matrix &m, double x, double y, double z)
std::string get_name(void) const
double double_value(bool frc_str_conv=false) const
double get_size(void) const
virtual bool has_property(const caseless_str &) const
virtual void set_font(const base_properties &props)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
static void safe_fclose(FILE *f)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
Matrix get_color_rgb(void) const
bool horizontalalignment_is(const std::string &v) const