feat: add offset_x/offset_y to analyze response for alignment guess

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Alex-GilbertandClaude Opus 4.6 committed 2026-02-16 15:20:11 -06:00
1 parent 23cbfcc862
commit 3c867de6aa
2 files changed
+15

No files matched your search

+4
View File
@@ -97,6 +97,10 @@ async def test_redaction_analyze(pdf_bytes: bytes):
assert data["gap"]["w"] > 0
assert data["font"]["name"]
assert data["font"]["size"] > 0
assert "offset_x" in data
assert "offset_y" in data
assert isinstance(data["offset_x"], (int, float))
assert isinstance(data["offset_y"], (int, float))
@pytest.mark.anyio
+11
View File
@@ -184,6 +184,15 @@ async def analyze_redaction(req: AnalyzeRequest):
left_text = "".join(c.text for c in left_chars).rstrip()
right_text = "".join(c.text for c in right_chars).lstrip()
# Compute initial offset guess: align end of left text with gap start
pil_font = font_match.to_pil_font()
if left_text:
left_rendered_width = pil_font.getlength(left_text)
offset_x = float(rx - left_rendered_width - best_line.x)
else:
offset_x = 0.0
offset_y = 0.0
if left_text:
lx = left_chars[0].x
lw = (left_chars[-1].x + left_chars[-1].w) - lx
@@ -216,6 +225,8 @@ async def analyze_redaction(req: AnalyzeRequest):
"text": best_line.text,
},
"chars": chars_json,
"offset_x": round(offset_x, 1),
"offset_y": round(offset_y, 1),
}