diff --git a/pixelocr/page.py b/pixelocr/page.py index 5db0b72..cc0e384 100644 --- a/pixelocr/page.py +++ b/pixelocr/page.py @@ -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):