Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc bugfixes and improvements #32

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pdftext/pdf/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ def _reconstruct_spans(orig_span: dict, links: List[Link]) -> List[Span]:
link_bboxes = [Bbox(link['bbox']) for link in links]

for char in orig_span['chars']:
char_bbox = Bbox(char['bbox'])
char_bbox = Bbox(char['bbox'].bbox)
intersections: List[Tuple[float, Link]] = []
for i, link_bbox in enumerate(link_bboxes):
area = link_bbox.intersection_area(char_bbox)
if char_bbox.area > 0:
area = link_bbox.intersection_area(char_bbox)
else:
area = link_bbox.intersection_area(Bbox(char['bbox'].bbox, ensure_nonzero_area=True))
if area > 0:
intersections.append((area, links[i]))

Expand Down
7 changes: 6 additions & 1 deletion pdftext/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@


class Bbox:
def __init__(self, bbox: List[float]):
def __init__(self, bbox: List[float], ensure_nonzero_area=False):
if ensure_nonzero_area:
bbox = list(bbox)
bbox[2] = max(bbox[0], bbox[2] + 1)
bbox[3] = max(bbox[1], bbox[3] + 1)
self.bbox = bbox
self.ensure_nonzero_area = ensure_nonzero_area

def __getitem__(self, item):
return self.bbox[item]
Expand Down
Loading
Loading