From aaea166135ace01709f7e0be64f40be80f4107ec Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Apr 2013 00:32:52 -0400 Subject: initial commit of hand merging, plus getting "ancient" waf script to work correctly --- libs/canvas/text.cc | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 libs/canvas/text.cc (limited to 'libs/canvas/text.cc') diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc new file mode 100644 index 0000000000..541a5f7fc0 --- /dev/null +++ b/libs/canvas/text.cc @@ -0,0 +1,120 @@ +#include +#include "pbd/xml++.h" +#include "canvas/text.h" +#include "canvas/canvas.h" +#include "canvas/utils.h" + +using namespace std; +using namespace ArdourCanvas; + +Text::Text (Group* parent) + : Item (parent) + , _font_description (0) + , _color (0x000000ff) + , _alignment (Pango::ALIGN_LEFT) +{ + +} + +void +Text::set (string const & text) +{ + begin_change (); + + _text = text; + + _bounding_box_dirty = true; + end_change (); +} + +void +Text::compute_bounding_box () const +{ + if (!_canvas || !_canvas->context ()) { + _bounding_box = boost::optional (); + _bounding_box_dirty = false; + return; + } + + Pango::Rectangle const r = layout (_canvas->context())->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; +} + +Glib::RefPtr +Text::layout (Cairo::RefPtr context) const +{ + Glib::RefPtr layout = Pango::Layout::create (context); + layout->set_text (_text); + if (_font_description) { + layout->set_font_description (*_font_description); + } + layout->set_alignment (_alignment); + return layout; +} + +void +Text::render (Rect const & /*area*/, Cairo::RefPtr context) const +{ + set_source_rgba (context, _color); + layout (context)->show_in_cairo_context (context); +} + +XMLNode * +Text::get_state () const +{ + XMLNode* node = new XMLNode ("Text"); +#ifdef CANVAS_DEBUG + if (!name.empty ()) { + node->add_property ("name", name); + } +#endif + return node; +} + +void +Text::set_state (XMLNode const * /*node*/) +{ + /* XXX */ +} + +void +Text::set_alignment (Pango::Alignment alignment) +{ + begin_change (); + + _alignment = alignment; + + _bounding_box_dirty = true; + end_change (); +} + +void +Text::set_font_description (Pango::FontDescription* font_description) +{ + begin_change (); + + _font_description = font_description; + + _bounding_box_dirty = true; + end_change (); +} + +void +Text::set_color (Color color) +{ + begin_change (); + + _color = color; + + end_change (); +} + + -- cgit v1.2.3