[pygtk] Pango AttrRise bug ?

Vitaly Ostanin vyt at vzljot.ru
Tue Aug 31 18:20:13 WST 2004


Hello.

I found strange problem in pango layout. Attached example paint 
text layout (wrapped by words):
"First second three".

Word "three" have AttrRise and AttrWeight. Pango layout width 
changed when main window resized.

Try to decrease width of main window. Word "three" should be 
wrapped to next line with correct rising. But some time (at begin 
of wrapping) rising is missed.

-- 
Regards, Vyt
mailto:  vyt ÎÁ vzljot.ru
JID:     vyt ÎÁ vzljot.ru
-------------- next part --------------
#!/usr/bin/env python

# example drawingarea.py

import pygtk
pygtk.require('2.0')
import gtk
import pango

class DrawingAreaExample:
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_title("Drawing Area Example")
        window.connect("destroy", lambda w: gtk.main_quit())
#        window.connect("configure-event", self.area_expose_cb)
        self.area = gtk.DrawingArea()
#        self.area.set_size_request(400, 300)
        window.add(self.area)
        self.area.connect("expose-event", self.area_expose_cb)
        self.area.show()
        window.show()

    def area_expose_cb(self, area, event):
        self.style = self.area.get_style()
        self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
        text = 'First second third'
        self.pangolayout = self.area.create_pango_layout(text)
        self.pangolayout.set_alignment(pango.ALIGN_LEFT)
        win_width, win_height = self.area.window.get_size()
        self.pangolayout.set_width (win_width * pango.SCALE)
        self.pangolayout.set_wrap(pango.WRAP_WORD)
        attrlist=pango.AttrList()
        width, height = self.pangolayout.get_size()
        start_index, end_index = 13,18
        attr=pango.AttrWeight(pango.WEIGHT_BOLD, start_index, end_index)
        attrlist.insert(attr)
        attr=pango.AttrRise(-height, start_index, end_index)
        attrlist.insert(attr)
        self.pangolayout.set_attributes(attrlist)
        self.area.window.draw_layout(self.gc, 0, 0, self.pangolayout)
        return gtk.TRUE

def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    DrawingAreaExample()
    main()


More information about the pygtk mailing list