1 #include <gtkmm/label.h>
3 #include "canvas/text.h"
4 #include "canvas/canvas.h"
5 #include "canvas/utils.h"
8 using namespace ArdourCanvas;
10 Text::Text (Group* parent)
12 , _font_description (0)
14 , _alignment (Pango::ALIGN_LEFT)
21 delete _font_description;
25 Text::set (string const & text)
31 _bounding_box_dirty = true;
36 Text::compute_bounding_box () const
38 if (!_canvas || !_canvas->context ()) {
39 _bounding_box = boost::optional<Rect> ();
40 _bounding_box_dirty = false;
44 Pango::Rectangle const r = layout (_canvas->context())->get_ink_extents ();
46 _bounding_box = Rect (
47 r.get_x() / Pango::SCALE,
48 r.get_y() / Pango::SCALE,
49 (r.get_x() + r.get_width()) / Pango::SCALE,
50 (r.get_y() + r.get_height()) / Pango::SCALE
53 _bounding_box_dirty = false;
56 Glib::RefPtr<Pango::Layout>
57 Text::layout (Cairo::RefPtr<Cairo::Context> context) const
59 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
60 layout->set_text (_text);
61 if (_font_description) {
62 layout->set_font_description (*_font_description);
64 layout->set_alignment (_alignment);
69 Text::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
71 set_source_rgba (context, _color);
72 layout (context)->show_in_cairo_context (context);
76 Text::get_state () const
78 XMLNode* node = new XMLNode ("Text");
81 node->add_property ("name", name);
88 Text::set_state (XMLNode const * /*node*/)
94 Text::set_alignment (Pango::Alignment alignment)
98 _alignment = alignment;
100 _bounding_box_dirty = true;
105 Text::set_font_description (Pango::FontDescription font_description)
109 _font_description = new Pango::FontDescription (font_description);
111 _bounding_box_dirty = true;
116 Text::set_color (Color color)