def draw_text(self): """Draw the highlighted pango text.""" widget = self.drawingarea draw_target = self.pixmap view = self.view offset = ( int(self.vadjustment.value), int(self.hadjustment.value), ) yoffset, xoffset = offset size = ( int(self.hadjustment.page_size), int(self.vadjustment.page_size) ) clip_off, clip_size = self.textbox_text_clip clip_yoff, clip_xoff = clip_off width, height = widget.window.get_size() colours = view.colours doc = view.document #must_relex = bool(doc.relex_from) if not self.pl or doc.must_relex: #print "recalculating pango layout.." doc.update_tokens(view.scroll_pos, view.textbox_dimensions) tab_size = self.editor.settings.tab_size self.pl = make_pango_layout(view) self.pl.set_font_description(self.font) if view.selection: pl = self.pl.copy() selection = view.selection add_selection_to_layout(pl, colours, doc, selection, offset, size) else: pl = self.pl colour = colours['plain']['gc'] draw_target.draw_layout(colour, clip_xoff, 0, pl) if self.editor.settings.show_margin: rm = self.editor.settings.right_margin # HACK: 2 is a magic number. Looks like self.char_width is not # perfectly accurate and with long lines the characters don't all # line up pixel-perfectly as a multiple of char_width. guide_x = rm*self.char_width - xoffset*self.char_width - 2 # draw the guide line draw_target.draw_line(colours['guide']['gc'], guide_x, 0, guide_x, height-1)
widget.show() view.colours = get_colours(widget, view.document.tokenizer.lexer, colourscheme) offset = (0, 0) size = view.textbox_dimensions tab_size = 8 b = BenchmarkTimer() for x in xrange(1000): b.start("Warmup (must relex)") view.document.invalidate((0, 0)) view.document.update_tokens(offset, size) layout = make_pango_layout(view, widget) b.end() for x in xrange(1000): b.start("Normal (no lexing)") view.document.update_tokens(offset, size) layout = make_pango_layout(view, widget) b.end() print report = b.get_report() print format_report(report)