(page, textout, GRID, fontsize, noformfeed, skip_empty, flags)
| 575 | |
| 576 | |
| 577 | def page_layout(page, textout, GRID, fontsize, noformfeed, skip_empty, flags): |
| 578 | eop = b"\n" if noformfeed else bytes([12]) |
| 579 | |
| 580 | # -------------------------------------------------------------------- |
| 581 | def find_line_index(values: List[int], value: int) -> int: |
| 582 | """Find the right row coordinate. |
| 583 | |
| 584 | Args: |
| 585 | values: (list) y-coordinates of rows. |
| 586 | value: (int) lookup for this value (y-origin of char). |
| 587 | Returns: |
| 588 | y-ccordinate of appropriate line for value. |
| 589 | """ |
| 590 | i = bisect.bisect_right(values, value) |
| 591 | if i: |
| 592 | return values[i - 1] |
| 593 | raise RuntimeError("Line for %g not found in %s" % (value, values)) |
| 594 | |
| 595 | # -------------------------------------------------------------------- |
| 596 | def curate_rows(rows: Set[int], GRID) -> List: |
| 597 | rows = list(rows) |
| 598 | rows.sort() # sort ascending |
| 599 | nrows = [rows[0]] |
| 600 | for h in rows[1:]: |
| 601 | if h >= nrows[-1] + GRID: # only keep significant differences |
| 602 | nrows.append(h) |
| 603 | return nrows # curated list of line bottom coordinates |
| 604 | |
| 605 | def process_blocks(blocks: List[Dict], page: fitz.Page): |
| 606 | rows = set() |
| 607 | page_width = page.rect.width |
| 608 | page_height = page.rect.height |
| 609 | rowheight = page_height |
| 610 | left = page_width |
| 611 | right = 0 |
| 612 | chars = [] |
| 613 | for block in blocks: |
| 614 | for line in block["lines"]: |
| 615 | if line["dir"] != (1, 0): # ignore non-horizontal text |
| 616 | continue |
| 617 | x0, y0, x1, y1 = line["bbox"] |
| 618 | if y1 < 0 or y0 > page.rect.height: # ignore if outside CropBox |
| 619 | continue |
| 620 | # upd row height |
| 621 | height = y1 - y0 |
| 622 | |
| 623 | if rowheight > height: |
| 624 | rowheight = height |
| 625 | for span in line["spans"]: |
| 626 | if span["size"] <= fontsize: |
| 627 | continue |
| 628 | for c in span["chars"]: |
| 629 | x0, _, x1, _ = c["bbox"] |
| 630 | cwidth = x1 - x0 |
| 631 | ox, oy = c["origin"] |
| 632 | oy = int(round(oy)) |
| 633 | rows.add(oy) |
| 634 | ch = c["c"] |
nothing calls this directly
no test coverage detected
searching dependent graphs…