Esempio n. 1
0
    def _render(self, cr):
        Window._render(self, cr)
        if not self.text:
            return 
        style = self.style
        layout = pango.cairo_create_layout(cr)
        layout.set_markup(self.text, -1)
        layout.set_width(pango.units_from_double(self.rwidth))
        layout.set_height(pango.units_from_double(self.rheight))
        layout.set_alignment(self.pango_alignments[style.get('text.align', 'centre')])
        font_desc = style.get('text.font-description', 'Bitstream Vera Sans Mono 8')
        desc = pango.FontDescription.from_string(font_desc)
        layout.font_description = desc
        desc.free()

        valign = style.get('text.vertical-align', 'top')
        assert valign in ('top', 'middle', 'bottom')
        if valign == 'top':
            y = self.ry
        else:
            extents = pango.PangoRectangle()
            layout.get_extents(None, byref(extents))
            eheight = pango.units_to_double(extents.height)
            if valign == 'middle':
                y = self.ry + (self.rheight / 2) - (eheight / 2)
            elif valign == 'bottom':
                y = self.ry + self.rheight - eheight

        cr.set_source_rgb(*style['text.color'])
        cr.move_to(self.rx, y)
        pango.cairo_update_layout(cr, layout)
        pango.cairo_show_layout(cr, layout)
Esempio n. 2
0
    def _render(self, cr):
        desc = pango.FontDescription.from_string('Bitstream Vera Sans Mono 8')
        y = self.ry + self.char_height
        for row in self.term.screen[self.term.screen.visible_start:self.term.screen.visible_start+self.term.screen.rows]:
            if row.dirty:
                curr = row.rendition[0]
                #print "curr %08x" % curr, curr >> 24, (curr & 0x00ff0000) >> 16
                markup = ('<span foreground="%s" background="%s">' % (
                        color_map[curr >> 24], 
                        color_map[(curr & 0x00ff0000) >> 16],
                        )) + row.chars[0]
                for c in xrange(1, self.chars_width):
                    ch = row.chars[c]
                    r = row.rendition[c]
                    if curr != r:
                        curr = r
                        markup += ('</span><span foreground="%s" background="%s">' % (
                                color_map[curr >> 24], 
                                color_map[(curr & 0x00ff0000) >> 16],
                                ))
                    if ch == '>':
                        markup += '&gt;'
                    elif ch == '<':
                        markup += '&lt;'
                    else:
                        markup += ch
                markup += '</span>'
                row.layout = pango.cairo_create_layout(cr)
                row.layout.font_description = desc
                row.layout.set_markup(markup, -1)
                row.dirty = False
            if row.layout:
                cr.move_to(self.rx, y-pango.pango_units_to_double(row.layout.get_baseline()))
                pango.cairo_update_layout(cr, row.layout)
                pango.cairo_show_layout(cr, row.layout)

            y += self.char_height
        desc.free()

        cr.rectangle(
            self.rx+(self.term.screen.cursor_col*self.char_width),
            2+self.ry+(self.term.screen.cursor_row*self.char_height),
            self.char_width,
            self.char_height)
        cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
        cr.fill()