fix(translators): ameliorer le respect des formats de fichiers pour Excel, PowerPoint et PDF
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m33s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m33s
- Excel: elargissement intelligent des colonnes pour le texte etendu et alignement RTL des cellules - PowerPoint: retour a la ligne et auto-fit anti-debordement, colonnes de tableaux en RTL - PDF: protection multi-colonnes pour eviter les chevauchements et formatage hebreu - Tests: validation de non-regression pour tous les formats
This commit is contained in:
@@ -1225,3 +1225,42 @@ class TestLtrNormalization:
|
||||
assert "1." in lines[0] or "1" in lines[0]
|
||||
# Must not contain overflow marker
|
||||
assert "[translation overflow]" not in " ".join(lines)
|
||||
|
||||
def test_pdf_multicolumn_protection(self, tmp_path):
|
||||
"""Tier 1 expansion on a left column must not expand past the right column."""
|
||||
import fitz
|
||||
|
||||
src = tmp_path / "src_cols.pdf"
|
||||
doc = fitz.open()
|
||||
page = doc.new_page(width=600, height=400)
|
||||
# Left column at x=50..250, right column at x=300..500
|
||||
page.insert_textbox(fitz.Rect(50, 50, 250, 100), "Titre gauche", fontsize=14, fontname="helv")
|
||||
page.insert_textbox(fitz.Rect(300, 50, 500, 100), "Titre droite", fontsize=14, fontname="helv")
|
||||
doc.save(str(src))
|
||||
doc.close()
|
||||
|
||||
translator = PDFTranslator(
|
||||
provider=MockTranslationProvider({
|
||||
"Titre gauche": "A very long left heading translation that requires more width",
|
||||
"Titre droite": "Right heading",
|
||||
})
|
||||
)
|
||||
out = tmp_path / "out_cols.pdf"
|
||||
translator.translate_file(src, out, "en")
|
||||
|
||||
doc2 = fitz.open(str(out))
|
||||
blocks = doc2[0].get_text("blocks")
|
||||
doc2.close()
|
||||
|
||||
left_blocks = [b for b in blocks if "left heading" in b[4]]
|
||||
if left_blocks:
|
||||
# The left block must NOT cross the start of the right column (x=300)
|
||||
assert left_blocks[0][2] <= 300.0
|
||||
|
||||
def test_pdf_hebrew_formatting(self):
|
||||
"""Hebrew text must be visually formatted without Arabic cursive reshaping."""
|
||||
from translators.pdf_translator import _shape_rtl_multiline
|
||||
hebrew_text = "שלום עולם"
|
||||
res = _shape_rtl_multiline(hebrew_text, max_width=200, fontsize=12)
|
||||
assert res is not None
|
||||
assert len(res) > 0
|
||||
|
||||
Reference in New Issue
Block a user