Spaces:
Sleeping
Sleeping
Update InitialMarkups.py
Browse files- InitialMarkups.py +27 -27
InitialMarkups.py
CHANGED
|
@@ -65,7 +65,7 @@ def is_header(span, most_common_font_size, most_common_color, most_common_font):
|
|
| 65 |
(
|
| 66 |
span["size"] > most_common_font_size or
|
| 67 |
span["font"].lower() != most_common_font.lower() or
|
| 68 |
-
is_bold
|
| 69 |
)
|
| 70 |
)
|
| 71 |
|
|
@@ -536,32 +536,32 @@ def highlight_boxes(doc, highlights, stringtowrite, fixed_width=500): # Set you
|
|
| 536 |
# Get original rect for vertical coordinates
|
| 537 |
orig_rect = fitz.Rect(bbox)
|
| 538 |
rect_height = orig_rect.height
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
|
| 566 |
def get_leaf_headers_with_paths(listtoloop, path=None, output=None):
|
| 567 |
if path is None:
|
|
|
|
| 65 |
(
|
| 66 |
span["size"] > most_common_font_size or
|
| 67 |
span["font"].lower() != most_common_font.lower() or
|
| 68 |
+
(is_bold and span["size"] > most_common_font_size )
|
| 69 |
)
|
| 70 |
)
|
| 71 |
|
|
|
|
| 536 |
# Get original rect for vertical coordinates
|
| 537 |
orig_rect = fitz.Rect(bbox)
|
| 538 |
rect_height = orig_rect.height
|
| 539 |
+
if rect_height > 100:
|
| 540 |
+
if orig_rect.width > 10:
|
| 541 |
+
# Center horizontally using fixed width
|
| 542 |
+
center_x = page_width / 2
|
| 543 |
+
new_x0 = center_x - fixed_width / 2
|
| 544 |
+
new_x1 = center_x + fixed_width / 2
|
| 545 |
+
new_rect = fitz.Rect(new_x0, orig_rect.y0, new_x1, orig_rect.y1)
|
| 546 |
+
|
| 547 |
+
# Add highlight rectangle
|
| 548 |
+
annot = page.add_rect_annot(new_rect)
|
| 549 |
+
annot.set_colors(stroke=(1, 1, 0), fill=(1, 1, 0))
|
| 550 |
+
annot.set_opacity(0.3)
|
| 551 |
+
annot.update()
|
| 552 |
+
|
| 553 |
+
# Add right-aligned freetext annotation inside the fixed-width box
|
| 554 |
+
text = '['+stringtowrite +']'
|
| 555 |
+
annot1 = page.add_freetext_annot(
|
| 556 |
+
new_rect,
|
| 557 |
+
text,
|
| 558 |
+
fontsize=15,
|
| 559 |
+
fontname='helv',
|
| 560 |
+
text_color=(1, 0, 0),
|
| 561 |
+
rotate=page.rotation,
|
| 562 |
+
align=2 # right alignment
|
| 563 |
+
)
|
| 564 |
+
annot1.update()
|
| 565 |
|
| 566 |
def get_leaf_headers_with_paths(listtoloop, path=None, output=None):
|
| 567 |
if path is None:
|