]> git.neil.brown.name Git - scribble.git/commitdiff
Store important fontmentrics globally for easier access
authorNeil Brown <neilb@notabene.brown>
Thu, 28 Aug 2008 10:18:59 +0000 (20:18 +1000)
committerNeil Brown <neilb@notabene.brown>
Thu, 28 Aug 2008 10:18:59 +0000 (20:18 +1000)
scribble.py

index f1a797984a932f93d9dac4a82219cf717b24ced8..483443fe5c693f19b088efb3bed2e3a954654ab7 100755 (executable)
@@ -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:]