fix(rtl): les textes centrs en persan s'affichaient du mauvais cote

- Word: sous w:bidi, w:jc est logique (left=dbut=droite visuelle,
  right=fin=gauche visuelle) ; forcer jc=right alignait donc les
  paragraphes a gauche et crasait le centrage hrit du style.
  Dsormais le RTL pose w:bidi et w:rtl sans jamais toucher w:jc,
  comme le fait Word lui-mme pour un document RTL.
- PowerPoint: algn n'est plus crit quand le paragraphe n'en dfinit
  pas, afin de respecter l'alignement hrit du masque (titres centrs) ;
  algn=l explicite reste converti en r (algn est visuel en DrawingML).
- tests: centrage par style Word prserv, aucun w:jic crit, algn
  absent non cras côté PowerPoint
This commit is contained in:
2026-09-01 20:45:05 +02:00
parent f22f645fab
commit ffbd85a7b6
3 changed files with 70 additions and 19 deletions

View File

@@ -73,9 +73,15 @@ def _set_pptx_paragraph_rtl(paragraph) -> None:
Enable RTL mode on a PowerPoint paragraph.
Sets rtl="1" on the <a:pPr> element, which controls the paragraph
text direction. The horizontal alignment (algn) is only forced to
"r" when the paragraph has no explicit alignment or is aligned
"l" (left) — a centered or justified title keeps its alignment.
text direction; with rtl="1" and no explicit algn, PowerPoint
renders the paragraph from its start edge — the right edge.
algn is only rewritten when the paragraph explicitly says "l": in
DrawingML algn is visual (not logical like Word's w:jc), so an
explicit left would keep RTL text on the left edge. When algn is
absent, the inherited layout/master alignment (often centered
titles) must keep playing — writing "r" here would override it,
which is the centered-text mis-rendering reported for Persian.
"""
p_elem = paragraph._p
tag_pPr = f"{{{_NS_A}}}pPr"
@@ -84,7 +90,7 @@ def _set_pptx_paragraph_rtl(paragraph) -> None:
pPr = etree.Element(tag_pPr)
p_elem.insert(0, pPr)
pPr.set("rtl", "1")
if pPr.get("algn") in (None, "", "l"):
if pPr.get("algn") == "l":
pPr.set("algn", "r")