# HG changeset patch # User Shai Ayal # Date 1258604049 18000 # Node ID 92d8f35ff217f3c40fbe6ae3228c98c6ff3ba58b # Parent 637fa784d10202f3a12708476a0d94b620acb621 compute bounding boxes for text in opengl graphics backend diff -r 637fa784d102 -r 92d8f35ff217 src/ChangeLog --- a/src/ChangeLog Wed Nov 18 21:02:49 2009 -0500 +++ b/src/ChangeLog Wed Nov 18 23:14:09 2009 -0500 @@ -1,3 +1,15 @@ +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. + (opengl_renderer::render_text): Call text_to_pixels to compute + rotation mode and bounding box. + * gl-renger.h (opengl_renderer::text_to_pixels): Provide decl. + * gl2ps-renderer.cc (glps_renderer::render_text): + Call text_to_pixels to compute bounding box. + (glps_renderer::set_font): Call opengl_renderer::set_font. + 2009-11-18 Michael Godfrey * txt-eng-ft.cc: Relax font match test. diff -r 637fa784d102 -r 92d8f35ff217 src/gl-render.cc --- a/src/gl-render.cc Wed Nov 18 21:02:49 2009 -0500 +++ b/src/gl-render.cc Wed Nov 18 23:14:09 2009 -0500 @@ -3140,18 +3140,16 @@ return ID; } -Matrix -opengl_renderer::render_text (const std::string& txt, - double x, double y, double z, - int halign, int valign, double rotation) +void +opengl_renderer::text_to_pixels (const std::string& txt, + double rotation, + uint8NDArray& pixels, + Matrix& bbox, + int& rot_mode) { -#if HAVE_FREETYPE - if (txt.empty ()) - return Matrix (1, 4, 0.0); - // FIXME: clip "rotation" between 0 and 360 - int rot_mode = ft_render::ROTATION_0; + rot_mode = ft_render::ROTATION_0; if (rotation == 90.0) rot_mode = ft_render::ROTATION_90; @@ -3161,8 +3159,24 @@ 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, + int halign, int valign, double rotation) +{ +#if HAVE_FREETYPE + if (txt.empty ()) + return Matrix (1, 4, 0.0); + Matrix bbox; - uint8NDArray pixels = text_renderer.render (elt, bbox, rot_mode); + uint8NDArray pixels; + int rot_mode; + text_to_pixels (txt, rotation, pixels, 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 -r 637fa784d102 -r 92d8f35ff217 src/gl-render.h --- a/src/gl-render.h Wed Nov 18 21:02:49 2009 -0500 +++ b/src/gl-render.h Wed Nov 18 23:14:09 2009 -0500 @@ -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 -r 637fa784d102 -r 92d8f35ff217 src/gl2ps-renderer.cc --- a/src/gl2ps-renderer.cc Wed Nov 18 21:02:49 2009 -0500 +++ b/src/gl2ps-renderer.cc Wed Nov 18 23:14:09 2009 -0500 @@ -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,21 @@ 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 ();