All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m36s
B3.6 — fix two visual bugs reported on the user's prod PDF:
1. Title 'Spécification technique : Office Translator v3.0' overflowed
its 2-line bbox and overlapped the 'Version du document...' block.
Root cause: MAX_VERTICAL_EXPANSION was 1.5x the original height,
way too small for a long French title. Bumped to 6.0x.
2. 'Avis important' blue background had white rectangular patches.
Root cause: redaction always used fill=(1,1,1) (opaque white),
which erased the colored drawing underneath the text.
Fix: detect when a block's bbox intersects a page drawing,
and use fill=None (transparent) for the redaction in that case.
The original drawing survives intact.
B3.7 — eliminate remaining block-vs-next-block overlap:
Computes each block's 'next_block_y' (the y0 of the nearest block
below it on the same page) and uses it as the ceiling for vertical
expansion. Previously the smart-fit logic used the page bottom as
the ceiling, which let long translated blocks flow into their
neighbour (e.g. 'Pour la dernière version...' overlapping
'8. Résolution des problèmes' in the TOC).
Also includes:
- 9 new tests (6 B3.6 + 3 B3.7) — total 446 tests pass, zero regression
- scripts/verify_b3_6_fix.py — visual+structural verification
- Updated sample_files/test_corpus/test_pdf_translated.pdf with the
clean B3.6+B3.7 output
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Reproduce the image issues: title overflow + white box on colored block."""
|
|
import sys
|
|
sys.path.insert(0, '.')
|
|
import fitz
|
|
from pathlib import Path
|
|
|
|
# Open the translated PDF from the user
|
|
src = Path('sample_files/test_corpus/test_pdf_translated (1).pdf')
|
|
doc = fitz.open(str(src))
|
|
|
|
# Page 1
|
|
p = doc[0]
|
|
print("=== Page 1 text blocks ===")
|
|
for i, b in enumerate(p.get_text("dict").get("blocks", [])):
|
|
bbox = b.get("bbox", (0, 0, 0, 0))
|
|
if b.get("type") != 0: # not text
|
|
continue
|
|
text_lines = []
|
|
for line in b.get("lines", []):
|
|
for span in line.get("spans", []):
|
|
text_lines.append(span.get("text", ""))
|
|
text = " ".join(text_lines)[:60]
|
|
print(f" [{i}] bbox=({bbox[0]:.0f},{bbox[1]:.0f},{bbox[2]:.0f},{bbox[3]:.0f}) text={text!r}")
|
|
|
|
print()
|
|
print("=== Page 1 drawings ===")
|
|
for i, d in enumerate(p.get_drawings()):
|
|
rect = d.get("rect")
|
|
fill = d.get("fill")
|
|
color = d.get("color")
|
|
print(f" [{i}] rect=({rect.x0:.0f},{rect.y0:.0f},{rect.x1:.0f},{rect.y1:.0f}) fill={fill} color={color}")
|
|
|
|
# Open the original to compare
|
|
orig = fitz.open('sample_files/test_corpus/test_pdf.pdf')
|
|
p_orig = orig[0]
|
|
print()
|
|
print("=== Original Page 1 drawings (for comparison) ===")
|
|
for i, d in enumerate(p_orig.get_drawings()):
|
|
rect = d.get("rect")
|
|
fill = d.get("fill")
|
|
color = d.get("color")
|
|
print(f" [{i}] rect=({rect.x0:.0f},{rect.y0:.0f},{rect.x1:.0f},{rect.y1:.0f}) fill={fill} color={color}")
|
|
|
|
doc.close()
|
|
orig.close()
|