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);
/* 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
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