-void
-Text::compute_bounding_box () const
-{
- if (!_canvas || _text.empty()) {
- _bounding_box = boost::optional<Rect> ();
- _bounding_box_dirty = false;
- 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);
- 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;
-}
-