# HG changeset patch # User Shai Ayal # Date 1258229245 -7200 # Node ID 8b2e367ee78080d25c1ff5c9544c12f81ba43d0d # Parent 84398271118ca9b45580b199b0bc01e0b80dd329 [mq]: gl2ps_bbox diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2009-11-14 Shai Ayal + + * gl-render.cc (opengl_renderer::text_to_pixels): new function + from code in render_text to produce the pixels and compute + bounding box + * gl2ps-renderer.cc (glps_renderer::render_text): use ft-renderer + to compute bounding box + 2009-11-13 John W. Eaton * Makefile.am (liboctinterp_la_CPPFLAGS): Define. diff --git a/src/gl-render.cc b/src/gl-render.cc --- a/src/gl-render.cc +++ b/src/gl-render.cc @@ -3140,6 +3140,29 @@ return ID; } +void +opengl_renderer::text_to_pixels (const std::string& txt, + double rotation, + uint8NDArray& pixels, + Matrix& bbox, + int& rot_mode) +{ + // FIXME: clip "rotation" between 0 and 360 + + rot_mode = ft_render::ROTATION_0; + + if (rotation == 90.0) + rot_mode = ft_render::ROTATION_90; + else if (rotation == 180.0) + rot_mode = ft_render::ROTATION_180; + else if (rotation == 270.0) + rot_mode = ft_render::ROTATION_270; + + text_element *elt = text_parser_none ().parse (txt); + pixels = text_renderer.render (elt, bbox, rot_mode); + delete elt; +} + Matrix opengl_renderer::render_text (const std::string& txt, double x, double y, double z, @@ -3149,20 +3172,11 @@ if (txt.empty ()) return Matrix (1, 4, 0.0); - // FIXME: clip "rotation" between 0 and 360 + Matrix bbox; + uint8NDArray pixels; + int rot_mode; + text_to_pixels (txt, rotation, pixels, bbox, rot_mode); - int rot_mode = ft_render::ROTATION_0; - - if (rotation == 90.0) - rot_mode = ft_render::ROTATION_90; - else if (rotation == 180.0) - rot_mode = ft_render::ROTATION_180; - else if (rotation == 270.0) - rot_mode = ft_render::ROTATION_270; - - text_element *elt = text_parser_none ().parse (txt); - Matrix bbox; - uint8NDArray pixels = text_renderer.render (elt, bbox, rot_mode); int x0 = 0, y0 = 0; int w = bbox(2), h = bbox(3); @@ -3216,8 +3230,6 @@ if (! blend) glDisable (GL_BLEND); - delete elt; - return bbox; #else ::warning ("render_text: cannot render text, Freetype library not available"); diff --git a/src/gl-render.h b/src/gl-render.h --- a/src/gl-render.h +++ b/src/gl-render.h @@ -95,9 +95,15 @@ virtual void draw_marker (double x, double y, double z, const Matrix& lc, const Matrix& fc); + virtual void text_to_pixels (const std::string& txt, + double rotation, + uint8NDArray& pixels, + Matrix& bbox, + int& rot_mode); + virtual Matrix render_text (const std::string& txt, - double x, double y, double z, - int halign, int valign, double rotation = 0.0); + double x, double y, double z, + int halign, int valign, double rotation = 0.0); private: opengl_renderer (const opengl_renderer&) { } diff --git a/src/gl2ps-renderer.cc b/src/gl2ps-renderer.cc --- a/src/gl2ps-renderer.cc +++ b/src/gl2ps-renderer.cc @@ -76,10 +76,8 @@ double x, double y, double z, int ha, int va, double rotation) { - Matrix retval = Matrix (1, 4, 0.0); - if (txt.empty ()) - return retval; + return Matrix (1, 4, 0.0); int gl2psa=GL2PS_TEXT_BL; if (ha == 0) @@ -114,13 +112,20 @@ gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, gl2psa, rotation); - // FIXME -- we have no way of getting a bounding box from gl2ps - return retval; + // FIXME? -- we have no way of getting a bounding box from gl2ps, so + // we use freetype + Matrix bbox; + uint8NDArray pixels; + int rot_mode; + text_to_pixels (txt, rotation, pixels, bbox, rot_mode); + + return bbox; } void glps_renderer::set_font (const base_properties& props) { + opengl_renderer::set_font (props); fontsize = props.get ("fontsize").double_value (); caseless_str fn = props.get ("fontname").string_value ();