From 1267b1d61cbce8688f3d0f1c4c7932de49735e75 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 8 Apr 2013 19:48:09 -0400 Subject: mo' better debugging of canvas "structure" via Item::dump and derivatives --- libs/canvas/canvas.cc | 6 +++--- libs/canvas/canvas/text.h | 1 + libs/canvas/item.cc | 8 +++++++- libs/canvas/poly_item.cc | 4 ++-- libs/canvas/text.cc | 37 ++++++++++++++++++++++++++++++++++--- 5 files changed, 47 insertions(+), 9 deletions(-) (limited to 'libs') diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index 0fced89bc4..c4eded11bf 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -77,9 +77,9 @@ Canvas::Canvas (XMLTree const * tree) void Canvas::render (Rect const & area, Cairo::RefPtr const & context) const { - // cerr << "CANVAS @ " << this << endl; - // dump (cerr); - // cerr << "-------------------------\n"; + cerr << "CANVAS @ " << this << endl; + dump (cerr); + cerr << "-------------------------\n"; checkpoint ("render", "-> render"); render_count = 0; diff --git a/libs/canvas/canvas/text.h b/libs/canvas/canvas/text.h index 9395b642e4..c65953783d 100644 --- a/libs/canvas/canvas/text.h +++ b/libs/canvas/canvas/text.h @@ -25,6 +25,7 @@ public: void set_alignment (Pango::Alignment); void set_size_chars (int nchars); + void dump (std::ostream&) const; private: std::string _text; diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 340c503fe7..9b44c333f5 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -341,11 +341,17 @@ Item::dump (ostream& o) const boost::optional bb = bounding_box(); o << _canvas->indent() << whatami() << ' ' << this; + +#ifdef CANVAS_DEBUG + if (!name.empty()) { + o << ' ' << name; + } +#endif if (bb) { o << endl << _canvas->indent() << "\tbbox: " << bb.get(); } else { - o << "bbox unset"; + o << " bbox unset"; } o << endl; diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index e43d48fa8d..d6e67ede0c 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -109,8 +109,8 @@ PolyItem::dump (ostream& o) const { Item::dump (o); - o << _canvas->indent() << _points.size() << " points" << endl; + o << _canvas->indent() << '\t' << _points.size() << " points" << endl; for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) { - o << i->x << ", " << i->y << endl; + o << _canvas->indent() << "\t\t" << i->x << ", " << i->y << endl; } } diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index ee15b13ef6..162f814478 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -57,8 +57,9 @@ Text::redraw (Cairo::RefPtr context) const _origin.x = ink_rect.get_x() / Pango::SCALE; _origin.y = ink_rect.get_y() / Pango::SCALE; - _width = (ink_rect.get_width() + Pango::SCALE / 2) / Pango::SCALE; - _height = (ink_rect.get_height() + Pango::SCALE / 2) / Pango::SCALE; + + _width = _origin.x + ((ink_rect.get_width() + Pango::SCALE / 2) / Pango::SCALE); + _height = _origin.y + ((ink_rect.get_height() + Pango::SCALE / 2) / Pango::SCALE); _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _width, _height); @@ -67,6 +68,14 @@ Text::redraw (Cairo::RefPtr 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); /* text has now been rendered in _image and is ready for blit in @@ -79,8 +88,18 @@ Text::redraw (Cairo::RefPtr context) const void Text::compute_bounding_box () const { - _bounding_box = Rect (_origin.x, _origin.y, _origin.x + _width, _origin.y + _height); + if (!_canvas || !_canvas->context () || _text.empty()) { + _bounding_box = boost::optional (); + _bounding_box_dirty = false; + return; + } + + redraw (_canvas->context()); + + _bounding_box = Rect (_origin.x, _origin.y, _width - _origin.x, _height - _origin.y); _bounding_box_dirty = false; + + cerr << "bbox for " << _text << " = " << _bounding_box << endl; } void @@ -93,6 +112,8 @@ Text::render (Rect const & /*area*/, Cairo::RefPtr context) cons if (_need_redraw) { redraw (context); } + + cerr << " with " << _origin << " and " << _width << " x " << _height << " render " << _text << endl; context->set_source (_image, 0, 0); context->rectangle (0, 0, _width, _height); @@ -152,3 +173,13 @@ Text::set_color (Color color) } +void +Text::dump (ostream& o) const +{ + Item::dump (o); + + o << _canvas->indent() << '\t' << " text = " << _text << endl + << _canvas->indent() << " color = " << _color; + + o << endl; +} -- cgit v1.2.3