Mercurial > hg > octave-nkf
comparison src/gl-render.cc @ 9834:92d8f35ff217
compute bounding boxes for text in opengl graphics backend
author | Shai Ayal <shaiay@users.sourceforge.net> |
---|---|
date | Wed, 18 Nov 2009 23:14:09 -0500 |
parents | 2d6a5af744b6 |
children | fed4aad2cdca |
comparison
equal
deleted
inserted
replaced
9833:637fa784d102 | 9834:92d8f35ff217 |
---|---|
3138 glEndList (); | 3138 glEndList (); |
3139 | 3139 |
3140 return ID; | 3140 return ID; |
3141 } | 3141 } |
3142 | 3142 |
3143 void | |
3144 opengl_renderer::text_to_pixels (const std::string& txt, | |
3145 double rotation, | |
3146 uint8NDArray& pixels, | |
3147 Matrix& bbox, | |
3148 int& rot_mode) | |
3149 { | |
3150 // FIXME: clip "rotation" between 0 and 360 | |
3151 | |
3152 rot_mode = ft_render::ROTATION_0; | |
3153 | |
3154 if (rotation == 90.0) | |
3155 rot_mode = ft_render::ROTATION_90; | |
3156 else if (rotation == 180.0) | |
3157 rot_mode = ft_render::ROTATION_180; | |
3158 else if (rotation == 270.0) | |
3159 rot_mode = ft_render::ROTATION_270; | |
3160 | |
3161 text_element *elt = text_parser_none ().parse (txt); | |
3162 pixels = text_renderer.render (elt, bbox, rot_mode); | |
3163 delete elt; | |
3164 } | |
3165 | |
3143 Matrix | 3166 Matrix |
3144 opengl_renderer::render_text (const std::string& txt, | 3167 opengl_renderer::render_text (const std::string& txt, |
3145 double x, double y, double z, | 3168 double x, double y, double z, |
3146 int halign, int valign, double rotation) | 3169 int halign, int valign, double rotation) |
3147 { | 3170 { |
3148 #if HAVE_FREETYPE | 3171 #if HAVE_FREETYPE |
3149 if (txt.empty ()) | 3172 if (txt.empty ()) |
3150 return Matrix (1, 4, 0.0); | 3173 return Matrix (1, 4, 0.0); |
3151 | 3174 |
3152 // FIXME: clip "rotation" between 0 and 360 | |
3153 | |
3154 int rot_mode = ft_render::ROTATION_0; | |
3155 | |
3156 if (rotation == 90.0) | |
3157 rot_mode = ft_render::ROTATION_90; | |
3158 else if (rotation == 180.0) | |
3159 rot_mode = ft_render::ROTATION_180; | |
3160 else if (rotation == 270.0) | |
3161 rot_mode = ft_render::ROTATION_270; | |
3162 | |
3163 text_element *elt = text_parser_none ().parse (txt); | |
3164 Matrix bbox; | 3175 Matrix bbox; |
3165 uint8NDArray pixels = text_renderer.render (elt, bbox, rot_mode); | 3176 uint8NDArray pixels; |
3177 int rot_mode; | |
3178 text_to_pixels (txt, rotation, pixels, bbox, rot_mode); | |
3179 | |
3166 int x0 = 0, y0 = 0; | 3180 int x0 = 0, y0 = 0; |
3167 int w = bbox(2), h = bbox(3); | 3181 int w = bbox(2), h = bbox(3); |
3168 | 3182 |
3169 if (pixels.numel () == 0) | 3183 if (pixels.numel () == 0) |
3170 { | 3184 { |
3214 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); | 3228 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); |
3215 glDisable (GL_ALPHA_TEST); | 3229 glDisable (GL_ALPHA_TEST); |
3216 if (! blend) | 3230 if (! blend) |
3217 glDisable (GL_BLEND); | 3231 glDisable (GL_BLEND); |
3218 | 3232 |
3219 delete elt; | |
3220 | |
3221 return bbox; | 3233 return bbox; |
3222 #else | 3234 #else |
3223 ::warning ("render_text: cannot render text, Freetype library not available"); | 3235 ::warning ("render_text: cannot render text, Freetype library not available"); |
3224 return Matrix (1, 4, 0.0); | 3236 return Matrix (1, 4, 0.0); |
3225 #endif | 3237 #endif |