Marthee commited on
Commit
107b04c
·
verified ·
1 Parent(s): 19d9836

Update InitialMarkups.py

Browse files
Files changed (1) hide show
  1. InitialMarkups.py +32 -28
InitialMarkups.py CHANGED
@@ -8,7 +8,7 @@ Original file is located at
8
  """
9
  baselink='https://findconsole-initialmarkups.hf.space/view-pdf?'
10
 
11
-
12
 
13
  from io import BytesIO
14
  import re
@@ -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,36 @@ 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
- 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:
 
8
  """
9
  baselink='https://findconsole-initialmarkups.hf.space/view-pdf?'
10
 
11
+
12
 
13
  from io import BytesIO
14
  import re
 
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 > 30:
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
+ if stringtowrite.startswith('Not'):
550
+ annot.set_colors(stroke=(0.5, 0.5, 0.5), fill=(0.5, 0.5, 0.5))
551
+ else:
552
+ annot.set_colors(stroke=(1, 1, 0), fill=(1, 1, 0))
553
+
554
+ annot.set_opacity(0.3)
555
+ annot.update()
556
+
557
+ # Add right-aligned freetext annotation inside the fixed-width box
558
+ text = '['+stringtowrite +']'
559
+ annot1 = page.add_freetext_annot(
560
+ new_rect,
561
+ text,
562
+ fontsize=15,
563
+ fontname='helv',
564
+ text_color=(1, 0, 0),
565
+ rotate=page.rotation,
566
+ align=2 # right alignment
567
+ )
568
+ annot1.update()
569
 
570
  def get_leaf_headers_with_paths(listtoloop, path=None, output=None):
571
  if path is None: