fix(pdf): le texte persan s'affichait en points d'interrogation
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m51s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m51s
Cause racine (reproduite et verrouillee par test) : l'insertion PDF demandait la police integree Helvetica tout en fournissant un fichier de police — PyMuPDF ignore alors le fichier, et Helvetica n'a aucun glyphe arabe : chaque lettre persane devenait un '?', et ces '?' debordaient les boites d'origine (les nombreux « [translation overflow] »). Defaut present dans toutes les versions deployees. - le nom de police est desormais Personnalise quand un fichier de police est fourni : le fichier est reellement integre - reproduction complete avant/apres : 0 '?', 0 debordement, persan rendu avec la police resolue - test de non-regression : la page traduite ne contient PAS Helvetica et le texte extrait n'a aucun '?' - bouton « Reconstruire » de la relecture : une infobulle explique desormais pourquoi il est grise (aucun segment approuve ni modifie), dans les 13 langues
This commit is contained in:
@@ -1151,3 +1151,35 @@ class TestLtrNormalization:
|
||||
assert out_para is not None
|
||||
out_pPr = out_para._p.find(f"{{{A_NS}}}pPr")
|
||||
assert out_pPr is None or out_pPr.get("rtl") != "1"
|
||||
|
||||
@pytest.mark.skipif(_host_rtl_font() is None, reason="no Arabic-capable font on this host")
|
||||
def test_layout_mode_uses_the_resolved_font_file(self, tmp_path):
|
||||
"""Regression guard: PyMuPDF ignores the fontfile when fontname is a
|
||||
base-14 name ("helv") — every Persian/Arabic glyph used to render as
|
||||
'?' in Helvetica, with mass "[translation overflow]" markers."""
|
||||
import fitz
|
||||
|
||||
src = tmp_path / "src.pdf"
|
||||
doc = fitz.open()
|
||||
page = doc.new_page()
|
||||
page.insert_textbox(
|
||||
fitz.Rect(72, 72, 400, 96), "Bonjour le monde",
|
||||
fontsize=11, fontname="helv",
|
||||
)
|
||||
doc.save(str(src))
|
||||
doc.close()
|
||||
|
||||
translator = PDFTranslator(
|
||||
provider=MockTranslationProvider({"Bonjour le monde": "سلام دنیا"})
|
||||
)
|
||||
out = tmp_path / "out.pdf"
|
||||
translator.translate_file(src, out, "fa")
|
||||
|
||||
doc2 = fitz.open(str(out))
|
||||
fonts = [f[3] for f in doc2[0].get_fonts()]
|
||||
text = doc2[0].get_text()
|
||||
doc2.close()
|
||||
|
||||
assert "Helvetica" not in fonts, fonts
|
||||
assert "?" not in text
|
||||
assert any(0xFB50 <= ord(c) <= 0xFEFF for c in text)
|
||||
|
||||
Reference in New Issue
Block a user