Re: Embedding icons in Pango text, the "right" way?
See: https://github.com/GNOME/pango/blob/master/examples/cairoshape.c On Aug 11, 2016 8:04 AM, "Andy Meneely"wrote: > Hi, > I maintain a Ruby gem that uses Pango heavily ( > https://github.com/andymeneely/squib/). One of the key features is to be > able to draw an icon into the text such that it flows just like any other > word. Carving out the space in the Pango layout has proven to be a > finicky challenge. (Once we carve out the proper space in the layout, we > use Cairo to paint the image separately.) > > What is the proper way to carve out space for image? We need this space to > flow like any other word. > > The way we currently carve out space is a bit hacky ( > https://github.com/andymeneely/squib/blob/master/lib/squib/ > graphics/text.rb#L98). We (1) replace the key with a control character, > then (2) change the letter spacing of the middle character to the width we > need. This fails on some platforms and not others. > > If we created a zero-sized regular character (e.g "a"), then stroking path > will fail because a zero-sized font invalidates the matrix math. Plus, we > get strange behavior happening when the text is ONLY an embedded icon of a > zero-sized font (i.e. we get a warning that the font can't be found). > > So I've never been happy with the way we implement this and I'm convinced > Pango provides a better way. I see the AttrShape struct - should I be > using that? How do I set attributes for just one character? I've been > scouring the docs and mailing lists archives and I'm not grasping exactly > how attribute lists work, so that's why I went with markup. > > If you have solutions in just C, or in another scripting language, I can > port it. > > Thanks! > > ___ > gtk-i18n-list mailing list > gtk-i18n-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-i18n-list > > ___ gtk-i18n-list mailing list gtk-i18n-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Re: Embedding icons in Pango text, the "right" way?
On Fri, Aug 12, 2016 at 5:26 AM, Stefan Salewskiwrote: > On Thu, 2016-08-11 at 11:04 -0400, Andy Meneely wrote: > > One of the key features is to be able to draw an icon > > into the text > > You do know that GTK3 textview is doing exactly that? > > See GTK3 gtk3-demo program, textview, "Multiple Views". No idea how > that works internally, sorry. > Ah, I was not aware of those. I don't use gtk in my project, so I didn't think to look there. I haven't found gtk's exact implementation, but that information led me to figure out how to create a Shape attribute and add it to the to the AttrList and hook in a "shape renderer" with a Pango::Rectangle. I'll post a minimal solution here for posterity once I get the details ironed out. Thanks! ___ gtk-i18n-list mailing list gtk-i18n-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Re: Embedding icons in Pango text, the "right" way?
On Thu, 2016-08-11 at 11:04 -0400, Andy Meneely wrote: > One of the key features is to be able to draw an icon > into the text You do know that GTK3 textview is doing exactly that? See GTK3 gtk3-demo program, textview, "Multiple Views". No idea how that works internally, sorry. ___ gtk-i18n-list mailing list gtk-i18n-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-i18n-list