Mercurial > octave
comparison libinterp/corefcn/gl-render.cc @ 21209:67d2965af0b5
revamp text rendering classes
* base-text-renderer.h: New file.
* ft-text-renderer.h, ft-text-renderer.cc: New files for freetype text
rendering classes, adapted from txt-eng-ft.h and txt-eng.cc.
* text-renderer.h, text-renderer.cc: New files. Public interface for
text rendering.
* gl-select.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
graphics.cc, graphics.in.h: Adapt to use new text rendering interface
that does not require checking HAVE_FREETYPE.
* libinterp/corefcn/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Feb 2016 08:15:53 -0500 |
parents | fcac5dbbf9ed |
children | 40de9f8f23a6 |
comparison
equal
deleted
inserted
replaced
21208:f5e05c11c343 | 21209:67d2965af0b5 |
---|---|
38 #include "oct-refcount.h" | 38 #include "oct-refcount.h" |
39 | 39 |
40 #include "errwarn.h" | 40 #include "errwarn.h" |
41 #include "gl-render.h" | 41 #include "gl-render.h" |
42 #include "oct-opengl.h" | 42 #include "oct-opengl.h" |
43 #include "txt-eng.h" | 43 #include "text-renderer.h" |
44 #include "txt-eng-ft.h" | |
45 | 44 |
46 #define LIGHT_MODE GL_FRONT_AND_BACK | 45 #define LIGHT_MODE GL_FRONT_AND_BACK |
47 | 46 |
48 // Use symbolic names for axes | 47 // Use symbolic names for axes |
49 enum | 48 enum |
2895 | 2894 |
2896 void | 2895 void |
2897 opengl_renderer::set_color (const Matrix& c) | 2896 opengl_renderer::set_color (const Matrix& c) |
2898 { | 2897 { |
2899 glColor3dv (c.data ()); | 2898 glColor3dv (c.data ()); |
2900 #if HAVE_FREETYPE | 2899 |
2901 text_renderer.set_color (c); | 2900 txt_renderer.set_color (c); |
2902 #endif | |
2903 } | 2901 } |
2904 | 2902 |
2905 void | 2903 void |
2906 opengl_renderer::set_font (const base_properties& props) | 2904 opengl_renderer::set_font (const base_properties& props) |
2907 { | 2905 { |
2908 #if HAVE_FREETYPE | 2906 txt_renderer.set_font (props.get ("fontname").string_value (), |
2909 text_renderer.set_font (props.get ("fontname").string_value (), | 2907 props.get ("fontweight").string_value (), |
2910 props.get ("fontweight").string_value (), | 2908 props.get ("fontangle").string_value (), |
2911 props.get ("fontangle").string_value (), | 2909 props.get ("fontsize_points").double_value ()); |
2912 props.get ("fontsize_points").double_value ()); | |
2913 #endif | |
2914 } | 2910 } |
2915 | 2911 |
2916 void | 2912 void |
2917 opengl_renderer::set_polygon_offset (bool on, float offset) | 2913 opengl_renderer::set_polygon_offset (bool on, float offset) |
2918 { | 2914 { |
3236 opengl_renderer::text_to_pixels (const std::string& txt, | 3232 opengl_renderer::text_to_pixels (const std::string& txt, |
3237 uint8NDArray& pixels, | 3233 uint8NDArray& pixels, |
3238 Matrix& bbox, | 3234 Matrix& bbox, |
3239 int halign, int valign, double rotation) | 3235 int halign, int valign, double rotation) |
3240 { | 3236 { |
3241 #if HAVE_FREETYPE | 3237 txt_renderer.text_to_pixels (txt, pixels, bbox, halign, valign, |
3242 text_renderer.text_to_pixels (txt, pixels, bbox, | 3238 rotation, interpreter); |
3243 halign, valign, rotation, interpreter); | |
3244 #endif | |
3245 } | 3239 } |
3246 | 3240 |
3247 void | 3241 void |
3248 opengl_renderer::text_to_strlist (const std::string& txt, | 3242 opengl_renderer::text_to_strlist (const std::string& txt, |
3249 std::list<ft_render::ft_string>& lst, | 3243 std::list<text_renderer::string>& lst, |
3250 Matrix& bbox, | 3244 Matrix& bbox, |
3251 int halign, int valign, double rotation) | 3245 int halign, int valign, double rotation) |
3252 { | 3246 { |
3253 #if HAVE_FREETYPE | 3247 txt_renderer.text_to_strlist (txt, lst, bbox, halign, valign, |
3254 text_renderer.text_to_strlist (txt, lst, bbox, | 3248 rotation, interpreter); |
3255 halign, valign, rotation, interpreter); | |
3256 #endif | |
3257 } | 3249 } |
3258 | 3250 |
3259 Matrix | 3251 Matrix |
3260 opengl_renderer::render_text (const std::string& txt, | 3252 opengl_renderer::render_text (const std::string& txt, |
3261 double x, double y, double z, | 3253 double x, double y, double z, |
3262 int halign, int valign, double rotation) | 3254 int halign, int valign, double rotation) |
3263 { | 3255 { |
3264 #if HAVE_FREETYPE | 3256 Matrix bbox (1, 4, 0.0); |
3257 | |
3265 if (txt.empty ()) | 3258 if (txt.empty ()) |
3266 return Matrix (1, 4, 0.0); | 3259 return bbox; |
3267 | 3260 |
3268 uint8NDArray pixels; | 3261 if (txt_renderer.ok ()) |
3269 Matrix bbox; | 3262 { |
3270 text_to_pixels (txt, pixels, bbox, halign, valign, rotation); | 3263 uint8NDArray pixels; |
3271 | 3264 text_to_pixels (txt, pixels, bbox, halign, valign, rotation); |
3272 bool blend = glIsEnabled (GL_BLEND); | 3265 |
3273 | 3266 bool blend = glIsEnabled (GL_BLEND); |
3274 glEnable (GL_BLEND); | 3267 |
3275 glEnable (GL_ALPHA_TEST); | 3268 glEnable (GL_BLEND); |
3276 glRasterPos3d (x, y, z); | 3269 glEnable (GL_ALPHA_TEST); |
3277 glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0); | 3270 glRasterPos3d (x, y, z); |
3278 glDrawPixels (bbox(2), bbox(3), | 3271 glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0); |
3279 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); | 3272 glDrawPixels (bbox(2), bbox(3), |
3280 glDisable (GL_ALPHA_TEST); | 3273 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ()); |
3281 if (! blend) | 3274 glDisable (GL_ALPHA_TEST); |
3282 glDisable (GL_BLEND); | 3275 |
3276 if (! blend) | |
3277 glDisable (GL_BLEND); | |
3278 } | |
3283 | 3279 |
3284 return bbox; | 3280 return bbox; |
3285 #else | 3281 } |
3286 warn_disabled_feature ("opengl_renderer::render_text", | 3282 |
3287 "rendering text (FreeType)"); | |
3288 return Matrix (1, 4, 0.0); | |
3289 #endif | 3283 #endif |
3290 } | |
3291 | |
3292 #endif |