Mercurial > octave
diff 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 |
line wrap: on
line diff
--- a/src/gl2ps-renderer.cc Thu Jan 06 19:56:50 2011 +0100 +++ b/src/gl2ps-renderer.cc Thu Jan 06 20:46:03 2011 +0100 @@ -88,14 +88,9 @@ opengl_renderer::draw (go); } -Matrix -glps_renderer::render_text (const std::string& txt, - double x, double y, double z, - int ha, int va, double rotation) +int +glps_renderer::alignment_to_mode (int ha, int va) const { - if (txt.empty ()) - return Matrix (1, 4, 0.0); - int gl2psa=GL2PS_TEXT_BL; if (ha == 0) { @@ -124,18 +119,26 @@ else if (va == 1) gl2psa=GL2PS_TEXT_C; } + return gl2psa; +} + +Matrix +glps_renderer::render_text (const std::string& txt, + double x, double y, double z, + int ha, int va, double rotation) +{ + if (txt.empty ()) + return Matrix (1, 4, 0.0); glRasterPos3d (x, y, z); - - gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, gl2psa, rotation); + gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize, + alignment_to_mode (ha, va), rotation); // 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); - + text_to_pixels (txt, pixels, bbox, 0, 0, rotation); return bbox; } @@ -186,4 +189,36 @@ gl2psDrawPixels (w, h, 0, 0, format, type, data); } +void +glps_renderer::draw_text (const text::properties& props) +{ + if (props.get_string ().empty ()) + return; + + set_font (props); + set_color (props.get_color_rgb ()); + + const Matrix pos = get_transform ().scale (props.get_data_position ()); + int halign = 0, valign = 0; + + if (props.horizontalalignment_is ("center")) + halign = 1; + else if (props.horizontalalignment_is ("right")) + halign = 2; + + if (props.verticalalignment_is ("top")) + valign = 2; + else if (props.verticalalignment_is ("baseline")) + valign = 3; + else if (props.verticalalignment_is ("middle")) + valign = 1; + + // FIXME: handle margin and surrounding box + + glRasterPos3d (pos(0), pos(1), pos(2)); + gl2psTextOpt (props.get_string ().c_str (), fontname.c_str (), fontsize, + alignment_to_mode (halign, valign), props.get_rotation ()); + +} + #endif