So here I am trying to come up with a workaround for the disappearance of Gnome Canvas from the latest Debian....
It looks like I can draw text with Pango. OK. I've even figured out how to draw it on a Layout of specified width. So:
Now what? It needs to end up superimposed on a base image, which is in a Gdk::Pixbuf. It seems like a Gdk::Drawable ought to be involved somehow. But... the relationships among Pixbuf, Drawable, and Layout are somewhere between unclear and nonexistent.
I'm remembering why I used Canvas in the first place. And why I decided to switch to Qt for future work.
But, I've got these existing little utilities written using GTK+, and they need to put text on little background images, and it has to work with both current Linux and old Windows installations. So I need to make this work, somehow, without Canvas.
Time to dig out a Book, printed on real paper, and see if that offers any insight.
Update: 'tis ugly, on account of sundry things don't Just Work and/or are exceedingly nonobvious. Here's the new, canvas-free code snippet, and using an ad-hoc fudge factor that happens to give decent vertical centering in my application:
# Without canvas
if (!@font)
@font = Pango::FontDescription.new("Sans bold 10")
end
pingo = Pango::Layout.new(Gdk::Pango.context)
pingo.width = width * Pango::SCALE
pingo.alignment = Pango::ALIGN_CENTER
pingo.font_description = @font
pingo.text = text
draw_off = Gdk::Pixmap.new(nil, width, height, 24)
if (!@gc)
@gc = Gdk::GC.new(draw_off)
end
draw_off.draw_pixbuf(nil, off, 0, 0, 0, 0, width, height, Gdk::RGB::DITHER_NORMAL, 0, 0)
draw_off.draw_layout(@gc, 0, 7, pingo, nil, nil)
draw_on = Gdk::Pixmap.new(nil, width, height, 24)
draw_on.draw_pixbuf(nil, on, 0, 0, 0, 0, width, height, Gdk::RGB::DITHER_NORMAL, 0, 0)
draw_on.draw_layout(@gc, 0, 7, pingo, nil, nil)
img_off = Gtk::Image.new(draw_off)
img_on = Gtk::Image.new(draw_on)
super(img_off, img_on, name)
Recent Comments