38 glps_renderer::draw (
const graphics_object& go,
const std::string print_cmd)
40 static bool in_draw =
false;
41 static std::string old_print_cmd;
47 GLint buffsize = 0,
state = GL2PS_OVERFLOW;
50 glGetIntegerv (GL_VIEWPORT, viewport);
53 if (term.find (
"eps") != std::string::npos) gl2ps_term = GL2PS_EPS;
54 else if (term.find (
"pdf") != std::string::npos) gl2ps_term = GL2PS_PDF;
55 else if (term.find (
"svg") != std::string::npos) gl2ps_term = GL2PS_SVG;
56 else if (term.find (
"ps") != std::string::npos) gl2ps_term = GL2PS_PS;
57 else if (term.find (
"pgf") != std::string::npos) gl2ps_term = GL2PS_PGF;
58 else if (term.find (
"tex") != std::string::npos) gl2ps_term = GL2PS_TEX;
61 error (
"gl2ps-renderer:: Unknown terminal");
66 if (term.find (
"notxt") != std::string::npos) gl2ps_text = GL2PS_NO_TEXT;
69 GLint gl2ps_sort = GL2PS_BSP_SORT;
70 if (term.find (
"is2D") != std::string::npos) gl2ps_sort = GL2PS_NO_SORT;
72 while (
state == GL2PS_OVERFLOW)
79 std::string include_graph;
80 std::size_t found_redirect = old_print_cmd.find (
">");
81 if (found_redirect != std::string::npos)
82 include_graph = old_print_cmd.substr (found_redirect + 1);
84 include_graph = old_print_cmd;
85 std::size_t n_begin = include_graph.find_first_not_of (
" ");
86 if (n_begin != std::string::npos)
88 std::size_t n_end = include_graph.find_last_not_of (
" ");
89 include_graph = include_graph.substr (n_begin,
93 include_graph =
"foobar-inc";
94 buffsize += 1024*1024;
95 gl2psBeginPage (
"glps_renderer figure",
"Octave", viewport,
96 gl2ps_term, gl2ps_sort,
97 (GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET
98 | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL
99 | GL2PS_BEST_ROOT | gl2ps_text
100 | GL2PS_NO_PS3_SHADING),
101 GL_RGBA, 0, NULL, 0, 0, 0,
102 buffsize, fp, include_graph.c_str ());
103 old_print_cmd = print_cmd;
105 state = gl2psEndPage ();
115 glps_renderer::alignment_to_mode (
int ha,
int va)
const
117 int gl2psa=GL2PS_TEXT_BL;
120 if (va == 0 || va == 3)
121 gl2psa=GL2PS_TEXT_BL;
123 gl2psa=GL2PS_TEXT_TL;
125 gl2psa=GL2PS_TEXT_CL;
129 if (va == 0 || va == 3)
130 gl2psa=GL2PS_TEXT_BR;
132 gl2psa=GL2PS_TEXT_TR;
134 gl2psa=GL2PS_TEXT_CR;
138 if (va == 0 || va == 3)
149 glps_renderer::render_text (
const std::string& txt,
150 double x,
double y,
double z,
151 int ha,
int va,
double rotation)
154 return Matrix (1, 4, 0.0);
156 glRasterPos3d (x, y, z);
157 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize,
158 alignment_to_mode (ha, va), rotation);
164 text_to_pixels (txt, pixels, bbox, 0, 0, rotation);
177 if (fn ==
"times" || fn ==
"times-roman")
178 fontname =
"Times-Roman";
179 else if (fn ==
"courier")
180 fontname =
"Courier";
181 else if (fn ==
"symbol")
183 else if (fn ==
"zapfdingbats")
184 fontname =
"ZapfDingbats";
186 fontname =
"Helvetica";
191 template <
typename T>
193 draw_pixels (GLsizei
w, GLsizei h, GLenum format,
const T *data)
197 for (
int i = 0; i < 3*w*h; i++)
200 gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a);
204 glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format,
205 GLenum
type,
const GLvoid *data)
207 if (type == GL_UNSIGNED_SHORT)
208 ::draw_pixels (w, h, format, static_cast<const GLushort *> (data));
209 else if (type == GL_UNSIGNED_BYTE)
210 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data));
212 gl2psDrawPixels (w, h, 0, 0, format, type, data);
225 int halign = 0, valign = 0;
241 glRasterPos3d (pos(0), pos(1), pos.numel () > 2 ? pos(2) : 0.0);
247 std::string s = sv.
join (
"\n");
249 gl2psTextOpt (s.c_str (), fontname.c_str (), fontsize,
250 alignment_to_mode (halign, valign), props.
get_rotation ());