Skip to content
Merged
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
17 changes: 11 additions & 6 deletions src/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,18 @@ def __setitem__(self, key, value):
CHARS = _TableStateList(_CHARS_VAR) # text characters from PyMuPDF
TEXT_BOLD = mupdf.FZ_STEXT_BOLD
TEXT_STRIKEOUT = mupdf.FZ_STEXT_STRIKEOUT

FLAGS = (
0
| pymupdf.TEXTFLAGS_TEXT
| pymupdf.TEXT_COLLECT_STYLES
| pymupdf.TEXT_ACCURATE_BBOXES
| pymupdf.TEXT_MEDIABOX_CLIP
)
def textpage_flags():
if pymupdf._layout_available() and pymupdf._layout_enabled:
return FLAGS | pymupdf.TEXT_ACCURATE_BBOXES
return FLAGS

# needed by mupdf function fz_find_table_within_bounds().
TABLE_DETECTOR_FLAGS = (
0
Expand Down Expand Up @@ -2051,17 +2056,17 @@ def row_has_bold(bbox):
h0 = line_heights[-1]
bold0 = line_bolds[-1]

if bold0 and not bold:
break # stop if switching from bold to non-bold

# if fitting in height of previous span, modify bbox
if y0 - y1 <= y_delta or abs((y0 - h0) - s["bbox"][1]) <= y_delta:
s["bbox"] = (s["bbox"][0], y0 - h0, s["bbox"][2], y0)
spans[i] = s
line_heights[-1] = min(h0, h)
if bold:
line_bolds[-1] = bold
continue
elif y0 - y1 > 1.5 * h0:
if bold0 and not bold:
break # stop if switching from bold to non-bold
if y0 - y1 > 1.5 * h0:
break # stop if distance to previous line too large
select.append(y1)
line_heights.append(h)
Expand Down Expand Up @@ -2395,7 +2400,7 @@ def make_chars(page, clip=None):
page_number = page.number + 1
page_height = page.rect.height
ctm = page.transformation_matrix
TEXTPAGE = page.get_textpage(clip=clip, flags=FLAGS)
TEXTPAGE = page.get_textpage(clip=clip, flags=textpage_flags())
blocks = page.get_text("rawdict", textpage=TEXTPAGE)["blocks"]
doctop_base = page_height * page.number
for block in blocks:
Expand Down
Loading