Add Image.fits() and PageObject.fits().

This commit is contained in:
Andrey Golovizin 2014-08-25 16:22:01 +02:00
parent 00a6b14e4c
commit c5d04ff6aa
2 changed files with 15 additions and 0 deletions

View file

@ -212,6 +212,16 @@ class Image(object):
data = np.ma.masked_array(self.data, mask3, fill_value=255).filled()
return Image(data, self.x, self.y)
def fits(self, left, top, right, bottom):
"""Return True if the image fits into the given bounding box."""
return (
self.top >= top
and self.left >= left
and self.right <= right
and self.bottom <= bottom
)
def _iter_lines(self, min_space):
def iter_lines():
line_start = None

View file

@ -80,6 +80,11 @@ class PageObject(object):
def ycenter(self):
return (self.bottom - self.top) / 2
def fits(self, left, top, right, bottom):
"""Return True if the glyph fits into the given bounding box."""
return self.image.fits(left, top, right, bottom)
class Page(PageObject):
def __iter__(self):