INNER CODE UNIT · Python
initial_clip
gokayfem/awesome-vlm-architectures · scripts/extract_architecture_figures.py:97
def initial_clip(page: fitz.Page, caption: fitz.Rect) -> fitz.Rect:
page_rect = page.rect
if caption.width < page_rect.width * 0.57:
center = (caption.x0 + caption.x1) / 2
if center < page_rect.width / 2:
x0, x1 = page_rect.width * 0.035, page_rect.width * 0.51
else:
x0, x1 = page_rect.width * 0.49, page_rect.width * 0.965
else:
x0, x1 = page_rect.width * 0.035, page_rect.width * 0.965
horizontal = fitz.Rect(x0, 0, x1, page_rect.height)
previous = prose_block_before(page, caption, horizontal)
top = previous.y1 + 5 if previous else max(page_rect.y0 + 32, caption.y0 - 390)
if caption.y0 - top < 88:
top = max(page_rect.y0 + 28, caption.y0 - 230)
if caption.y0 - top > 420:
top = caption.y0 - 420
return fitz.Rect(x0, top, x1, max(top + 20, caption.y0 - 3))