From: Neil Brown Date: Wed, 27 Aug 2008 20:30:50 +0000 (+1000) Subject: Fix detection of position of glyph on screen. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=ec0fb0a5d69c063feec570692d68db11b971d92a;p=scribble.git Fix detection of position of glyph on screen. Using BBox.relpos to find position of glyph on screen didn't work so well as it is too easy to miss the 'middle' which should be the easiest to hit. So modify bbox so that above/below midline are easy to detect. --- diff --git a/scribble.py b/scribble.py index 01b912a..d448006 100755 --- a/scribble.py +++ b/scribble.py @@ -411,10 +411,12 @@ class BBox: self.maxy = p.y if p.y < self.miny: self.miny = p.y - def finish(self): + def finish(self, div = 3): # if aspect ratio is bad, we adjust max/min accordingly # before setting [xy][12]. We don't change self.min/max # as they are used to place stroke in bigger bbox. + # Normally divisions are at 1/3 and 2/3. They can be moved + # by setting div e.g. 2 = 1/2 and 1/2 (minx,miny,maxx,maxy) = (self.minx,self.miny,self.maxx,self.maxy) if (maxx - minx) * 3 < (maxy - miny) * 2: # too narrow @@ -429,10 +431,11 @@ class BBox: miny = mid - halfheight maxy = mid + halfheight - self.x1 = int((2*minx + maxx)/3) - self.x2 = int((minx + 2*maxx)/3) - self.y1 = int((2*miny + maxy)/3) - self.y2 = int((miny + 2*maxy)/3) + div1 = div - 1 + self.x1 = int((div1*minx + maxx)/div) + self.x2 = int((minx + div1*maxx)/div) + self.y1 = int((div1*miny + maxy)/div) + self.y2 = int((miny + div1*maxy)/div) def row(self, p): # 0, 1, 2 - top to bottom @@ -874,7 +877,7 @@ class ScribblePad: alloc = self.page.get_allocation() pagebb = BBox(Point(0,0)) pagebb.add(Point(alloc.width, alloc.height)) - pagebb.finish() + pagebb.finish(div = 2) p = PPath(self.line[1][0], self.line[1][1]) for pp in self.line[1:]: