Files
sliding-automation/patches/patch_render_engine_c6b.py

92 lines
3.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
patch_render_engine_c6b.py — Finition C6 (ombres parasites des shapes)
======================================================================
Les blocs freeform « shape » (add_shape) portent un élément <p:style>
implicite que LibreOffice/PowerPoint interprètent avec une ombre par
défaut — shadow.inherit=False ne suffit pas. Ce patch retire l'élément
de style à la création : rendu strictement plat, conforme à la charte.
Usage (dossier du pipeline, single-line) :
python3 patch_render_engine_c6b.py
Prérequis : C6 appliqué. Vérifie l'ancre, écrit .bak-c6b, compile,
idempotent.
"""
import py_compile
import shutil
import sys
from pathlib import Path
TARGET = Path("render_engine_v2.py")
PATCHES = [
(
' sh.line.fill.background()\n'
' sh.shadow.inherit = False\n'
' if blk.get("text"):\n',
' sh.line.fill.background()\n'
' sh.shadow.inherit = False\n'
' _st = sh._element.find(qn("p:style"))\n'
' if _st is not None: # style implicite = '
'ombre\n'
' sh._element.remove(_st)\n'
' if blk.get("text"):\n',
),
(
' if blk.get("dash"):\n'
' sh.line.dash_style = MSO_LINE.DASH\n'
' sh.shadow.inherit = False\n'
' sh = None # pas de décoration fill sur '
'ligne\n',
' if blk.get("dash"):\n'
' sh.line.dash_style = MSO_LINE.DASH\n'
' sh.shadow.inherit = False\n'
' _st = sh._element.find(qn("p:style"))\n'
' if _st is not None:\n'
' sh._element.remove(_st)\n'
' sh = None # pas de décoration fill sur '
'ligne\n',
),
]
MARKER = 'sh._element.remove(_st)'
def fail(msg):
print(" ! %s" % msg)
sys.exit(1)
def main():
if not TARGET.exists():
fail("%s introuvable — lancer depuis le dossier du pipeline."
% TARGET)
content = TARGET.read_text(encoding="utf-8")
if MARKER in content:
fail("Déjà patché — rien à faire.")
for i, (old, _) in enumerate(PATCHES, 1):
n = content.count(old)
if n == 0:
fail("Ancre %d introuvable — le patch C6 est-il appliqué ?"
% i)
if n > 1:
fail("Ancre %d non unique (%d occurrences)." % (i, n))
shutil.copy2(TARGET, str(TARGET) + ".bak-c6b")
for old, new in PATCHES:
content = content.replace(old, new)
TARGET.write_text(content, encoding="utf-8")
print(" + Style implicite retiré des shapes et lignes freeform.")
try:
py_compile.compile(str(TARGET), doraise=True)
print(" + Compilation OK.")
except py_compile.PyCompileError as e:
shutil.copy2(str(TARGET) + ".bak-c6b", TARGET)
fail("Erreur de compilation — fichier restauré :\n%s" % e)
if __name__ == "__main__":
main()