comparison src/gl2ps-renderer.cc @ 9798:2d6a5af744b6

printing for fltk backend using gl2ps
author Shai Ayal <shaiay@users.sourceforge.net>
date Tue, 10 Nov 2009 19:48:02 -0500
parents
children 92d8f35ff217
comparison
equal deleted inserted replaced
9797:f569f46a1c34 9798:2d6a5af744b6
1 /*
2
3 Copyright (C) 2009 Shai Ayal
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #if defined (HAVE_OPENGL)
28
29 #include <cstdio>
30
31 #include "lo-mappers.h"
32 #include "oct-locbuf.h"
33
34 #include "gl2ps-renderer.h"
35 #include "gl2ps.h"
36
37 void
38 glps_renderer::draw (const graphics_object& go)
39 {
40 static bool in_draw = false;
41
42 if (!in_draw)
43 {
44 in_draw = true;
45
46 FILE *fp = fopen (filename.c_str (), "wb");
47 GLint buffsize = 0, state = GL2PS_OVERFLOW;
48 GLint viewport[4];
49
50 glGetIntegerv (GL_VIEWPORT, viewport);
51
52 while (state == GL2PS_OVERFLOW)
53 {
54 buffsize += 1024*1024;
55 gl2psBeginPage ("glps_renderer figure", "Octave", viewport,
56 GL2PS_EPS, GL2PS_BSP_SORT,
57 (GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET
58 | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL
59 | GL2PS_BEST_ROOT), GL_RGBA, 0, NULL, 0, 0, 0,
60 buffsize, fp, filename.c_str () );
61
62 opengl_renderer::draw (go);
63 state = gl2psEndPage ();
64 }
65
66 fclose (fp);
67
68 in_draw = 0;
69 }
70 else
71 opengl_renderer::draw (go);
72 }
73
74 Matrix
75 glps_renderer::render_text (const std::string& txt,
76 double x, double y, double z,
77 int ha, int va, double rotation)
78 {
79 Matrix retval = Matrix (1, 4, 0.0);
80
81 if (txt.empty ())
82 return retval;
83
84 int gl2psa=GL2PS_TEXT_BL;
85 if (ha == 0)
86 {
87 if (va == 0 || va == 3)
88 gl2psa=GL2PS_TEXT_BL;
89 else if (va == 2)
90 gl2psa=GL2PS_TEXT_TL;
91 else if (va == 1)
92 gl2psa=GL2PS_TEXT_CL;
93 }
94 else if (ha == 2)
95 {
96 if (va == 0 || va == 3)
97 gl2psa=GL2PS_TEXT_BR;
98 else if (va == 2)
99 gl2psa=GL2PS_TEXT_TR;
100 else if (va == 1)
101 gl2psa=GL2PS_TEXT_CR;
102 }
103 else if (ha == 1)
104 {
105 if (va == 0 || va == 3)
106 gl2psa=GL2PS_TEXT_B;
107 else if (va == 2)
108 gl2psa=GL2PS_TEXT_T;
109 else if (va == 1)
110 gl2psa=GL2PS_TEXT_C;
111 }
112
113 glRasterPos3d (x, y, z);
114
115 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, gl2psa, rotation);
116
117 // FIXME -- we have no way of getting a bounding box from gl2ps
118 return retval;
119 }
120
121 void
122 glps_renderer::set_font (const base_properties& props)
123 {
124 fontsize = props.get ("fontsize").double_value ();
125
126 caseless_str fn = props.get ("fontname").string_value ();
127 fontname = "";
128 if (fn == "times" || fn == "times-roman")
129 fontname = "Times-Roman";
130 else if (fn == "courier")
131 fontname = "Courier";
132 else if (fn == "symbol")
133 fontname = "Symbol";
134 else if (fn == "zapfdingbats")
135 fontname = "ZapfDingbats";
136 else
137 fontname = "Helvetica";
138
139 // FIXME -- add support for bold and italic
140 }
141
142 #endif
143
144 /*
145 ;;; Local Variables: ***
146 ;;; mode: C++ ***
147 ;;; End: ***
148 */