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

@@ -153,8 +153,6 @@ _PPR_BIDI_SUCCESSORS = (
qn("w:sectPr"),
qn("w:pPrChange"),
)
# Elements that must come AFTER w:jc inside w:pPr (w:jc itself excluded).
_PPR_JC_SUCCESSORS = _PPR_BIDI_SUCCESSORS[_PPR_BIDI_SUCCESSORS.index(qn("w:jc")) + 1 :]
# Elements that must come AFTER w:rtl inside w:rPr.
_RPR_RTL_SUCCESSORS = (
qn("w:cs"),
@@ -205,11 +203,18 @@ def _set_paragraph_rtl(paragraph: Paragraph) -> None:
Sets:
- w:pPr/w:bidi → paragraph text direction = RTL
- w:pPr/w:jc → mirrored alignment (left→right), ONLY when the
paragraph has no explicit alignment — centered/justified titles
must not be forced right-aligned.
- w:rPr/w:rtl → run-level RTL marker for each run
w:jc is deliberately left untouched. Under w:bidi, Word interprets
w:jc LOGICALLY (start/end), not visually: "left" means the start —
the RIGHT edge for an RTL paragraph — and "right" means the end, the
LEFT edge. Forcing jc="right" therefore aligns paragraphs to the
visual left and overrides style-level centering, which is exactly
the mis-rendering reported for centered Persian text. With bidi
alone: unaligned paragraphs start at the right edge, "left" resolves
to the right edge, and center/justify stay centered/justified — the
same markup Word itself writes for RTL documents.
Every element is inserted at its schema position inside w:pPr/w:rPr
(OOXML requires a fixed child order; appended-at-the-end elements
make Word flag the file for repair).
@@ -219,14 +224,6 @@ def _set_paragraph_rtl(paragraph: Paragraph) -> None:
if pPr.find(qn("w:bidi")) is None:
_insert_ordered(pPr, OxmlElement("w:bidi"), _PPR_BIDI_SUCCESSORS)
jc = pPr.find(qn("w:jc"))
explicit_alignment = jc is not None and jc.get(qn("w:val")) not in (None, "", "left")
if not explicit_alignment:
if jc is None:
jc = OxmlElement("w:jc")
_insert_ordered(pPr, jc, _PPR_JC_SUCCESSORS)
jc.set(qn("w:val"), "right")
for run in paragraph.runs:
rPr = run._r.get_or_add_rPr()
if rPr.find(qn("w:rtl")) is None: