GNOME Bugzilla – Bug 721627
bounds of text items in goocanvasmm are wrong
Last modified: 2014-01-12 15:49:25 UTC
I try to get the height and width of a rendered text in a goocanvasmm. But all I tried results in 0 values for all parameters in Bounds object. If I insert a c-function call to the txt item I get the correct values in the c++ interface! This looks very strange to me! See the following code lines Glib::RefPtr<Goocanvas::Text> txt = Goocanvas::Text::create( "W123", 0, 0 ); Goocanvas::Bounds b = txt->get_bounds(); // If the following 2 lines are removed, the output for all values are 0! // if the two lines are inserted, the values for 'b' are valid. GooCanvasBounds bounds; goo_canvas_item_get_bounds (( GooCanvasItem*)txt->gobj(), &bounds); cout << b.get_x1() << endl; cout << b.get_x2() << endl; cout << b.get_y1() << endl; cout << b.get_y2() << endl;
Thanks for the bug report. Could you please provide a small-as-possible test case that shows this? And, maybe even try if the same thing happens when using just the C API?
Created attachment 265429 [details] Example shows bug for text bounds in goocanvasmm This file provides a full example to reproduce the described bug.
Created attachment 265537 [details] [review] patch: ItemSimple: Fix get_bounds() Class hierarchy: class Goocanvas::Item : public Glib::Interface class Goocanvas::ItemSimple : public Glib::Object, public Goocanvas::Item class Goocanvas::Text : public Goocanvas::ItemSimple Goocanvas::ItemSimple::get_bounds() overrides Goocanvas::Item::get_bounds(). It shouldn't do that. Goocanvas::ItemSimple::get_bounds() should be removed. Until we can break ABI, let it call Goocanvas::Item::get_bounds(). Goocanvas::ItemSimple::get_bounds() copies directly from GooCanvasItemSimple::bounds without making sure that it's updated. Goocanvas::Item::get_bounds() calls goo_canvas_item_get_bounds(), which calls goo_canvas_item_simple_get_bounds(), which updates the bounds if necessary. I also wonder if there shall really be a Goocanvas::ItemSimple::set_bounds() method? Or, if it's useful, shouldn't it be protected? I'm not very familiar with goocanvas[mm]. I can be wrong, but I get the impression that the bounds shall be calculated by the GooCanvasItemSimple object itself.
Thanks. (In reply to comment #3) > Goocanvas::ItemSimple::get_bounds() overrides Goocanvas::Item::get_bounds(). > It shouldn't do that. Goocanvas::ItemSimple::get_bounds() should be removed. > Until we can break ABI, let it call Goocanvas::Item::get_bounds(). If it could never be used successfully without this odd workaround, maybe we can safely just remove it. The API and ABI are not officially stable yet, and I wonder if this would cause any real disruption to anyone at all.
Created attachment 265555 [details] [review] patch: Remove ItemSimple::get_bounds() How about this patch then? If you know that GooCanvasItemSimple.bounds is up to date, you could safely use ItemSimple::get_bounds() and save a fraction of a microsecond. IMO the very small saving of time is not worth the complication it would be for the application programmer to choose between the faster ItemSimple::get_bounds() and the safer Item::get_bounds().
Since no one has criticized my patch, I have pushed it.