Skip to content

Commit

Permalink
layout: LAParams.boxes_flow may be None
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Sep 3, 2021
1 parent 164f816 commit 43701e1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self,
char_margin: float = 2.0,
line_margin: float = 0.5,
word_margin: float = 0.1,
boxes_flow: float = 0.5,
boxes_flow: Optional[float] = 0.5,
detect_vertical: bool = False,
all_texts: bool = False):
self.line_overlap = line_overlap
Expand Down Expand Up @@ -614,20 +614,24 @@ def __init__(self, objs: Iterable[TextGroupElement]):
class LTTextGroupLRTB(LTTextGroup):
def analyze(self, laparams: LAParams) -> None:
super().analyze(laparams)
assert laparams.boxes_flow is not None
boxes_flow = laparams.boxes_flow
# reorder the objects from top-left to bottom-right.
self._objs.sort(
key=lambda obj: (1 - laparams.boxes_flow) * obj.x0
- (1 + laparams.boxes_flow) * (obj.y0 + obj.y1))
key=lambda obj: (1 - boxes_flow) * obj.x0
- (1 + boxes_flow) * (obj.y0 + obj.y1))
return


class LTTextGroupTBRL(LTTextGroup):
def analyze(self, laparams: LAParams) -> None:
super().analyze(laparams)
assert laparams.boxes_flow is not None
boxes_flow = laparams.boxes_flow
# reorder the objects from top-right to bottom-left.
self._objs.sort(
key=lambda obj: - (1 + laparams.boxes_flow) * (obj.x0 + obj.x1)
- (1 - laparams.boxes_flow) * obj.y1)
key=lambda obj: - (1 + boxes_flow) * (obj.x0 + obj.x1)
- (1 - boxes_flow) * obj.y1)
return


Expand Down

0 comments on commit 43701e1

Please sign in to comment.