comparison src/gl2ps-renderer.cc @ 11455:2be9e22796d2

improvements in text-extent calculation
author Konstantinos Poulios <logari81@googlemail.com>
date Thu, 06 Jan 2011 20:46:03 +0100
parents 2786e3b7072e
children fd0a3ac60b0e
comparison
equal deleted inserted replaced
11454:d7a964a5c57c 11455:2be9e22796d2
86 } 86 }
87 else 87 else
88 opengl_renderer::draw (go); 88 opengl_renderer::draw (go);
89 } 89 }
90 90
91 Matrix 91 int
92 glps_renderer::render_text (const std::string& txt, 92 glps_renderer::alignment_to_mode (int ha, int va) const
93 double x, double y, double z, 93 {
94 int ha, int va, double rotation)
95 {
96 if (txt.empty ())
97 return Matrix (1, 4, 0.0);
98
99 int gl2psa=GL2PS_TEXT_BL; 94 int gl2psa=GL2PS_TEXT_BL;
100 if (ha == 0) 95 if (ha == 0)
101 { 96 {
102 if (va == 0 || va == 3) 97 if (va == 0 || va == 3)
103 gl2psa=GL2PS_TEXT_BL; 98 gl2psa=GL2PS_TEXT_BL;
122 else if (va == 2) 117 else if (va == 2)
123 gl2psa=GL2PS_TEXT_T; 118 gl2psa=GL2PS_TEXT_T;
124 else if (va == 1) 119 else if (va == 1)
125 gl2psa=GL2PS_TEXT_C; 120 gl2psa=GL2PS_TEXT_C;
126 } 121 }
122 return gl2psa;
123 }
124
125 Matrix
126 glps_renderer::render_text (const std::string& txt,
127 double x, double y, double z,
128 int ha, int va, double rotation)
129 {
130 if (txt.empty ())
131 return Matrix (1, 4, 0.0);
127 132
128 glRasterPos3d (x, y, z); 133 glRasterPos3d (x, y, z);
129 134 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize,
130 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, gl2psa, rotation); 135 alignment_to_mode (ha, va), rotation);
131 136
132 // FIXME? -- we have no way of getting a bounding box from gl2ps, so 137 // FIXME? -- we have no way of getting a bounding box from gl2ps, so
133 // we use freetype 138 // we use freetype
134 Matrix bbox; 139 Matrix bbox;
135 uint8NDArray pixels; 140 uint8NDArray pixels;
136 int rot_mode; 141 text_to_pixels (txt, pixels, bbox, 0, 0, rotation);
137 text_to_pixels (txt, rotation, pixels, bbox, rot_mode);
138
139 return bbox; 142 return bbox;
140 } 143 }
141 144
142 void 145 void
143 glps_renderer::set_font (const base_properties& props) 146 glps_renderer::set_font (const base_properties& props)
184 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data)); 187 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data));
185 else 188 else
186 gl2psDrawPixels (w, h, 0, 0, format, type, data); 189 gl2psDrawPixels (w, h, 0, 0, format, type, data);
187 } 190 }
188 191
192 void
193 glps_renderer::draw_text (const text::properties& props)
194 {
195 if (props.get_string ().empty ())
196 return;
197
198 set_font (props);
199 set_color (props.get_color_rgb ());
200
201 const Matrix pos = get_transform ().scale (props.get_data_position ());
202 int halign = 0, valign = 0;
203
204 if (props.horizontalalignment_is ("center"))
205 halign = 1;
206 else if (props.horizontalalignment_is ("right"))
207 halign = 2;
208
209 if (props.verticalalignment_is ("top"))
210 valign = 2;
211 else if (props.verticalalignment_is ("baseline"))
212 valign = 3;
213 else if (props.verticalalignment_is ("middle"))
214 valign = 1;
215
216 // FIXME: handle margin and surrounding box
217
218 glRasterPos3d (pos(0), pos(1), pos(2));
219 gl2psTextOpt (props.get_string ().c_str (), fontname.c_str (), fontsize,
220 alignment_to_mode (halign, valign), props.get_rotation ());
221
222 }
223
189 #endif 224 #endif