mirror of
https://github.com/PR0M3TH3AN/unredact.git
synced 2026-10-27 08:40:29 +00:00
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:
1 parent
23cbfcc862
commit
3c867de6aa
2 files changed
+15
No files matched your search
@@ -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
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user