From 053eaf77fde7639d4e200d36a9db99b2d4fc615b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 9 Apr 2013 14:22:58 -0400 Subject: a variety of fixes for the cairocanvas, but it still buggy as hell handling events and lots of other stuff --- libs/canvas/text.cc | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'libs/canvas/text.cc') diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index 162f814478..4d240db3fd 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -1,7 +1,10 @@ +#include + #include #include #include "pbd/xml++.h" +#include "pbd/stacktrace.h" #include "canvas/text.h" #include "canvas/canvas.h" @@ -68,13 +71,6 @@ Text::redraw (Cairo::RefPtr context) const /* and draw, in the appropriate color of course */ set_source_rgba (img_context, _color); - - std::cerr << "render " << _text << " as " - << ((_color >> 24) & 0xff) / 255.0 - << ((_color >> 16) & 0xff) / 255.0 - << ((_color >> 8) & 0xff) / 255.0 - << ((_color >> 0) & 0xff) / 255. - << std::endl; layout->show_in_cairo_context (img_context); @@ -88,18 +84,29 @@ Text::redraw (Cairo::RefPtr context) const void Text::compute_bounding_box () const { - if (!_canvas || !_canvas->context () || _text.empty()) { + if (!_canvas || _text.empty()) { _bounding_box = boost::optional (); _bounding_box_dirty = false; return; } - redraw (_canvas->context()); - - _bounding_box = Rect (_origin.x, _origin.y, _width - _origin.x, _height - _origin.y); + PangoContext* _pc = gdk_pango_context_get (); + Glib::RefPtr context = Glib::wrap (_pc); // context now owns _pc and will free it + Glib::RefPtr layout = Pango::Layout::create (context); + + layout->set_text (_text); + layout->set_font_description (*_font_description); + layout->set_alignment (_alignment); + Pango::Rectangle const r = layout->get_ink_extents (); + + _bounding_box = Rect ( + r.get_x() / Pango::SCALE, + r.get_y() / Pango::SCALE, + (r.get_x() + r.get_width()) / Pango::SCALE, + (r.get_y() + r.get_height()) / Pango::SCALE + ); + _bounding_box_dirty = false; - - cerr << "bbox for " << _text << " = " << _bounding_box << endl; } void @@ -113,8 +120,6 @@ Text::render (Rect const & /*area*/, Cairo::RefPtr context) cons redraw (context); } - cerr << " with " << _origin << " and " << _width << " x " << _height << " render " << _text << endl; - context->set_source (_image, 0, 0); context->rectangle (0, 0, _width, _height); context->fill (); -- cgit v1.2.3