summaryrefslogtreecommitdiff
path: root/libs/canvas/text.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-04-09 14:22:58 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-04-09 14:22:58 -0400
commit053eaf77fde7639d4e200d36a9db99b2d4fc615b (patch)
tree1ef0d29aae9c0130b74ae42abb4bb2873291d5ae /libs/canvas/text.cc
parent1267b1d61cbce8688f3d0f1c4c7932de49735e75 (diff)
a variety of fixes for the cairocanvas, but it still buggy as hell handling events and lots of other stuff
Diffstat (limited to 'libs/canvas/text.cc')
-rw-r--r--libs/canvas/text.cc35
1 files changed, 20 insertions, 15 deletions
diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc
index 162f814478..4d240db3fd 100644
--- a/libs/canvas/text.cc
+++ b/libs/canvas/text.cc
@@ -1,7 +1,10 @@
+#include <gdk/gdk.h>
+
#include <cairomm/cairomm.h>
#include <gtkmm/label.h>
#include "pbd/xml++.h"
+#include "pbd/stacktrace.h"
#include "canvas/text.h"
#include "canvas/canvas.h"
@@ -68,13 +71,6 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
/* and draw, in the appropriate color of course */
set_source_rgba (img_context, _color);
-
- std::cerr << "render " << _text << " as "
- << ((_color >> 24) & 0xff) / 255.0
- << ((_color >> 16) & 0xff) / 255.0
- << ((_color >> 8) & 0xff) / 255.0
- << ((_color >> 0) & 0xff) / 255.
- << std::endl;
layout->show_in_cairo_context (img_context);
@@ -88,18 +84,29 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
void
Text::compute_bounding_box () const
{
- if (!_canvas || !_canvas->context () || _text.empty()) {
+ if (!_canvas || _text.empty()) {
_bounding_box = boost::optional<Rect> ();
_bounding_box_dirty = false;
return;
}
- redraw (_canvas->context());
-
- _bounding_box = Rect (_origin.x, _origin.y, _width - _origin.x, _height - _origin.y);
+ 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;
-
- cerr << "bbox for " << _text << " = " << _bounding_box << endl;
}
void
@@ -113,8 +120,6 @@ Text::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) cons
redraw (context);
}
- cerr << " with " << _origin << " and " << _width << " x " << _height << " render " << _text << endl;
-
context->set_source (_image, 0, 0);
context->rectangle (0, 0, _width, _height);
context->fill ();