fix conflicts caused by meterbridge merge
[ardour.git] / libs / canvas / text.cc
index 4c4d16d85c4e246d60d3a94337fa1070cbcef0e7..7143f2aca704257547c5a1fe06671af79405b7f9 100644 (file)
@@ -65,6 +65,10 @@ Text::set (string const & text)
 void
 Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
 {
+       if (_text.empty()) {
+               return;
+       }
+
        Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
 
        layout->set_text (_text);
@@ -90,6 +94,7 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
        /* and draw, in the appropriate color of course */
 
        set_source_rgba (img_context, _color);
+
        layout->show_in_cairo_context (img_context);
 
        /* text has now been rendered in _image and is ready for blit in
@@ -131,25 +136,32 @@ Text::compute_bounding_box () const
                return;
        }
 
-       PangoContext* _pc = gdk_pango_context_get ();
-       Glib::RefPtr<Pango::Context> context = Glib::wrap (_pc); // context now owns _pc and will free it
-       Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
-       
-       layout->set_text (_text);
-       if (_font_description) {
-               layout->set_font_description (*_font_description);
+       if (_bounding_box_dirty) {
+               if (!_image) {
+
+                       PangoContext* _pc = gdk_pango_context_get ();
+                       Glib::RefPtr<Pango::Context> context = Glib::wrap (_pc); // context now owns _pc and will free it
+                       Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
+                       
+                       layout->set_text (_text);
+                       if (_font_description) {
+                               layout->set_font_description (*_font_description);
+                       }
+                       layout->set_alignment (_alignment);
+                       Pango::Rectangle const r = layout->get_ink_extents ();
+                       
+                       _bounding_box = Rect (
+                               0, 0, 
+                               (r.get_x() + r.get_width()) / Pango::SCALE,
+                               (r.get_y() + r.get_height()) / Pango::SCALE
+                               );
+               } else {
+
+                       _bounding_box = Rect (0, 0, _image->get_width(), _image->get_height());
+               }
+
+               _bounding_box_dirty = false;
        }
-       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;
 }
 
 void