Add Page.leftmost_nonblank and Line.indent.

This commit is contained in:
Andrey Golovizin 2014-08-30 21:00:47 +02:00
parent 05f7eb4585
commit c739892e5b

View file

@ -114,6 +114,11 @@ class Page(PageObject):
def lines(self):
return self._merge_lines(self._iter_lines())
@cached_property
def leftmost_nonblank(self):
"""X coordinate of the leftmost non-blank pixel."""
return min(line.glyphs[0].left for line in self.lines)
def _iter_lines(self):
line_start = None
prev_line_end = 0
@ -174,6 +179,10 @@ class Line(PageObject):
bottom = np.argmin(gradient) + skip
return self.y + bottom
@cached_property
def indent(self):
return self.glyphs[0].left - self.page.leftmost_nonblank
@cached_property
@collect_iterable
def glyphs(self):