From: Neil Brown Date: Thu, 28 Aug 2008 10:18:59 +0000 (+1000) Subject: Store important fontmentrics globally for easier access X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=4089774f0db20b87d8a3ddceed09c35761b9f760;p=scribble.git Store important fontmentrics globally for easier access --- diff --git a/scribble.py b/scribble.py index f1a7979..483443f 100755 --- a/scribble.py +++ b/scribble.py @@ -764,6 +764,13 @@ class ScribblePad: LoadDict(self.dict) self.textstr = None + + ctx = page.get_pango_context() + fd = ctx.get_font_description() + met = ctx.get_metrics(fd) + self.lineheight = (met.get_ascent() + met.get_descent()) / pango.SCALE + self.lineascent = met.get_ascent() / pango.SCALE + def close_application(self, widget): self.save_page() gtk.main_quit() @@ -843,9 +850,7 @@ class ScribblePad: def draw_text(self, pos, colour, str, cursor = None): layout = self.page.create_pango_layout(str) - ctx = self.page.get_pango_context() - ascent = ctx.get_metrics(ctx.get_font_description()).get_ascent() - self.page.window.draw_layout(colour, pos[0], pos[1] - ascent/pango.SCALE, + self.page.window.draw_layout(colour, pos[0], pos[1] - self.lineascent, layout) if cursor != None: (strong,weak) = layout.get_cursor_pos(cursor) @@ -872,11 +877,8 @@ class ScribblePad: self.flush_text() self.textcurs = 0 self.textstr = "" - ctx = self.page.get_pango_context() - ascent = ctx.get_metrics(ctx.get_font_description()).get_ascent() - descent = ctx.get_metrics(ctx.get_font_description()).get_descent() self.textpos = [ self.textpos[0], self.textpos[1] + - (ascent + descent) / pango.SCALE ] + self.lineheight ] else: self.textstr = self.textstr[0:self.textcurs] + sym + \ self.textstr[self.textcurs:]