]> git.neil.brown.name Git - scribble.git/commitdiff
Handle 'newline' to start new line of text.
authorNeil Brown <neilb@notabene.brown>
Wed, 27 Aug 2008 21:10:48 +0000 (07:10 +1000)
committerNeil Brown <neilb@notabene.brown>
Wed, 27 Aug 2008 21:10:48 +0000 (07:10 +1000)
'newline' is a straigth line: to-right to bottom left.

scribble.py

index e30198a31ee23a98214ec7c82af4e5b1c0666af7..2707b236d383746434d954fd5cd9e0da42cbb228 100755 (executable)
@@ -172,6 +172,7 @@ def LoadDict(dict):
     dict.add('_', "S(4)3,5.S(4)5,3.S(4)3,5")
     dict.add("<left>", "S(4)5,3.S(3)3,5")
     dict.add("<right>","S(4)3,5.S(5)5,3")
+    dict.add("<newline>", "S(4)2,6")
 
 
 class DictSegment:
@@ -866,6 +867,15 @@ class ScribblePad:
         elif sym == "<right>":
             if self.textcurs < len(self.textstr):
                 self.textcurs += 1
+        elif sym == "<newline>":
+            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 ]
         else:
             self.textstr = self.textstr[0:self.textcurs] + sym + \
                            self.textstr[self.textcurs:]
@@ -915,7 +925,7 @@ class ScribblePad:
             if type(l[2]) == str:
                 self.draw_text(st, col, l[2])
 
-        if self.textstr:
+        if self.textstr != None:
             self.draw_text(self.textpos, self.colour, self.textstr,
                            self.textcurs)