Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(edit-native): keep source txBody on pure moves and warn before math turns into text

hugohe32e1658cc294e
diff --git a/skills/ppt-master/scripts/authoring_roundtrip.py b/skills/ppt-master/scripts/authoring_roundtrip.py
index 33f3142f..4411b7fd 100644
--- a/skills/ppt-master/scripts/authoring_roundtrip.py
+++ b/skills/ppt-master/scripts/authoring_roundtrip.py
@@ -16,11 +16,15 @@ Dependencies:
from __future__ import annotations
+import base64
+import binascii
import copy
import hashlib
import json
+import math
import os
import re
+import sys
import tempfile
from collections import Counter
from dataclasses import dataclass
@@ -52,12 +56,13 @@ from svg_authoring_view import (
SOURCE_PROXY_ATTRIBUTE,
SOURCE_PROXY_KIND,
_element_chain,
+ _format_transform_number,
_materialize_adopted_context,
project_svg_batch,
semantic_subtree_sha256,
)
from svg_compatibility import normalize_single_child_group_filters
-from svg_to_pptx.drawingml.utils import INHERITABLE_ATTRS
+from svg_to_pptx.drawingml.utils import INHERITABLE_ATTRS, parse_transform_matrix
SVG_NS = "http://www.w3.org/2000/svg"
@@ -1538,25 +1543,109 @@ def _restore_preserved_effect_metadata(
item.set(name, value)
+def _text_body_frame(element: ET.Element) -> tuple[float, ...] | None:
+ """Read a finite carrier frame for geometry and relative text comparisons."""
+ try:
+ frame = tuple(float(value) for value in re.split(
+ r"[\s,]+", (element.get("data-pptx-frame") or "").strip(),
+ ))
+ except ValueError:
+ return None
+ if len(frame) != 4 or not all(math.isfinite(value) for value in frame):
+ return None
+ return frame
+
+
+def _text_body_geometry(occurrence: RefOccurrence) -> tuple | None:
+ """Compare carrier size and effective axes, allowing only position changes."""
+ frame = _text_body_frame(occurrence.element)
+ if frame is None:
+ return None
+ contextual = _contextual_authoring_element(occurrence.element, occurrence.root)
+ # Match the precision used when the shared context helper composes ancestry.
+ axes = tuple(f"{value:.12g}" for value in parse_transform_matrix(contextual.get("transform", ""))[:4])
+ return frame[2:], axes
+
+
+def _text_body_state(occurrence: RefOccurrence, *, frame_relative: bool = False) -> list[str] | None:
+ """Fingerprint text with carrier translations removed, retaining local edits."""
+ carrier = copy.deepcopy(occurrence.element)
+ root = carrier
+ context = [carrier]
+ for ancestor in reversed(_element_chain(occurrence.root, occurrence.element)[:-1]):
+ wrapper = ET.Element(ancestor.tag, ancestor.attrib)
+ wrapper.append(root)
+ root = wrapper
+ context.append(wrapper)
+ # Normalize only the carrier and its ancestors. Text-local coordinates and
+ # transforms (including those on wrappers inside the carrier) still count.
+ for node in context:
+ axes = parse_transform_matrix(node.get("transform", ""))[:4]
+ node.attrib.pop("transform", None)
+ if axes != (1.0, 0.0, 0.0, 1.0):
+ node.set("transform", "matrix(" + " ".join(
+ f"{value:.12g}" for value in (*axes, 0.0, 0.0)
+ ) + ")")
+ if frame_relative:
+ frame = _text_body_frame(carrier)
+ if frame is None:
+ return None
+ for text in carrier.iter(f"{{{SVG_NS}}}text"):
+ for node in text.iter():
+ if node.tag not in {f"{{{SVG_NS}}}text", f"{{{SVG_NS}}}tspan"}:
+ continue
+ for axis, origin in zip(("x", "y"), frame[:2]):
+ raw = node.get(axis)
+ if raw is None:
+ continue
+ try:
+ values = [float(value) - origin for value in re.split(r"[\s,]+", raw.strip())]
+ except ValueError:
+ return None
+ if not all(math.isfinite(value) for value in values):
+ return None
+ node.set(axis, " ".join(_format_transform_number(value) for value in values))
+ return [
+ semantic_subtree_sha256(_contextual_authoring_element(text, root))
+ for text in carrier.iter(f"{{{SVG_NS}}}text")
+ ]
+
+
+def _text_body_formula_loss_warning(metadata: ET.Element, target: ET.Element, reason: str) -> str | None:
+ """Diagnose lost native math without taking over payload validation."""
+ try:
+ body = ET.fromstring(base64.b64decode((metadata.text or "").strip(), validate=True))
+ except (ValueError, binascii.Error, UnicodeDecodeError, ET.ParseError):
+ # An unreadable payload has an unknown formula count. Keep validation
+ # with the converter when the original restoration path consumes it.
+ return None
+ math_count = sum(1 for _ in body.iter("{http://schemas.microsoft.com/office/drawing/2010/main}m"))
+ marker_count = sum(
+ 1 for node in target.iter()
+ if node.get("data-pptx-inline-formula") or node.get("data-pptx-replace-with") == "formula"
+ )
+ if math_count > marker_count:
+ return f"native formulas will become plain text; reason={reason}; source txBody cannot be restored"
+ return None
+
+
def _restore_unchanged_text_body(
target: ET.Element,
source: ET.Element,
current: RefOccurrence,
baseline: RefOccurrence,
-) -> None:
- """Recover native text only while its projected text and context agree."""
+) -> str | None:
+ """Recover unchanged native text after translation, or diagnose lost math."""
metadata = next((child for child in source if child.get("data-pptx-part") == "txbody"), None)
- if metadata is None or current.element.get("data-pptx-frame") != baseline.element.get("data-pptx-frame"):
- return
-
- def text_state(occurrence: RefOccurrence) -> list[str]:
- return [
- semantic_subtree_sha256(_contextual_authoring_element(text, occurrence.root))
- for text in occurrence.element.iter(f"{{{SVG_NS}}}text")
- ]
-
- if text_state(current) != text_state(baseline):
+ if metadata is None:
return
+ geometry = _text_body_geometry(current)
+ if geometry is None or geometry != _text_body_geometry(baseline):
+ return _text_body_formula_loss_warning(metadata, target, "size/transform-changed")
+ if _text_body_state(current) != _text_body_state(baseline):
+ relative_state = _text_body_state(current, frame_relative=True)
+ if relative_state is None or relative_state != _text_body_state(baseline, frame_relative=True):
+ return _text_body_formula_loss_warning(metadata, target, "text-edited")
restored = copy.deepcopy(metadata)
# Projection compacts text runs and paragraphs. Validate that projection
# above, then let the existing decoder validate the recovered payload.
@@ -1798,6 +1887,8 @@ def _materialize_document(
"picture relationship"
)
+ warnings: list[dict[str, Any]] = []
+
def restore_nodes(
element: ET.Element,
source_dir: Path | None = None,
@@ -1872,9 +1963,25 @@ def _materialize_document(
if clone.get(name) is None and source.get(name) is not None:
clone.set(name, str(source.get(name)))
_restore_preserved_effect_metadata(clone, source)
- _restore_unchanged_text_body(
+ warning = _restore_unchanged_text_body(
clone, source, current_occurrences[source_ref][0], baseline_occurrences[source_ref][0],
)
+ if warning:
+ object_id = element.get("id") or source_ref
+ output_index = page.output_index if page else document.source_slide
+ warnings.append({
+ "code": "native-formula-to-text",
+ "output_page": output_index,
+ "source_slide": document.source_slide,
+ "object_id": object_id,
+ "source_ref": source_ref,
+ "message": warning,
+ })
+ print(
+ f"[ROUNDTRIP][WARNING] page={output_index} ({document.name}) "
+ f"object={object_id} source_ref={source_ref}: {warning}",
+ file=sys.stderr,
+ )
if (
_local_name(clone.tag) == "g" and source_ref is None
and set(clone.attrib) <= {*INHERITABLE_ATTRS, "style", "opacity", "transform"}
@@ -2022,6 +2129,7 @@ def _materialize_document(
"authored_unreferenced": authored_unreferenced,
"expanded_vector_uses": expanded_vector_uses,
"defs_changed": defs_changed,
+ "warnings": warnings,
}
diff --git a/skills/ppt-master/scripts/docs/svg-pipeline.md b/skills/ppt-master/scripts/docs/svg-pipeline.md
index ef1fb94d..d5a94dfb 100644
--- a/skills/ppt-master/scripts/docs/svg-pipeline.md
+++ b/skills/ppt-master/scripts/docs/svg-pipeline.md
@@ -93,10 +93,34 @@ vector edit units from `icons/imported/`, and retains edits/deletions/new
content without rewriting the bundle. Unchanged slides and resources pass
through byte-for-byte. Object comparison includes effective ancestor transforms,
opacity, inherited styles, and enclosing links; changing a proxy's context also
-fails. When an edited shape's text and text context still match the baseline,
-the materializer restores its relationship-free source `txBody` through the
-existing fingerprint/relationship checks, preserving fields, numbering,
-autofit, language, and text effects. Edited text follows normal conversion.
+fails. When an edited shape's text and effective text style still match the
+baseline, unchanged geometry or a pure translation retains its relationship-free
+source `txBody` through the existing fingerprint/relationship checks. This
+preserves the complete text body, including native Office Math, fields,
+numbering, autofit, language, and text effects. Translation may change frame
+x/y without changing width/height, or move the object or its ancestors with
+unchanged effective rotation, flip, and scale. Moving frame, geometry, and
+text coordinates together is also supported: when absolute text positions
+differ, the materializer compares every numeric `text`/`tspan` x/y coordinate
+relative to the frame origin. Relative text positions, text-local transforms,
+and styles remain part of the fingerprint; moving only one line or editing
+text/style never restores stale text over the edit.
+
+Width/height or non-translation transform changes continue to rebuild from
+SVG. Whenever a source `txBody` is not restored and its `a14:m` count exceeds
+the remaining formula marker count, including after text or style edits, the
+materializer emits a non-blocking `[ROUNDTRIP][WARNING]` to stderr with the
+output page, SVG filename, object id, and source ref, stating that native
+formulas will become plain text. Its reason is `size/transform-changed` or
+`text-edited`. An unreadable payload has an unknown formula count, produces
+no formula-loss warning, and remains subject to the converter's existing
+payload validation when consumed. The same `native-formula-to-text` diagnostic
+is recorded under each document's `warnings` in the postflight report's
+`source.authoring_roundtrip`; ordinary text and formulas rebuilt from native
+markers do not receive this warning. This does not expand the formula reverse
+import boundary, certify resized text layout/autofit, or change the existing
+POSTFLIGHT quality-gate status.
+
A page edit rebuilds that output page; a changed
materialized or derived resource rebuilds every output page that references it.
Changed materialized bytes must still match the source package part's extension
diff --git a/skills/ppt-master/scripts/tests/test_roundtrip_text_body_move.py b/skills/ppt-master/scripts/tests/test_roundtrip_text_body_move.py
new file mode 100644
index 00000000..84caca4e
--- /dev/null
+++ b/skills/ppt-master/scripts/tests/test_roundtrip_text_body_move.py
@@ -0,0 +1,396 @@
+#!/usr/bin/env python3
+"""PPT Master - Round-trip Text Body Translation Regression Tests
+
+Exercise native text retention through import, materialization, and conversion.
+
+Usage:
+ python3 -m unittest tests.test_roundtrip_text_body_move
+
+Examples:
+ Run the module from the scripts directory.
+
+Dependencies:
+ Standard library and the local PPTX/SVG converters.
+"""
+
+from __future__ import annotations
+
+import base64
+import io
+import re
+import tempfile
+import unittest
+import zipfile
+from contextlib import redirect_stderr, redirect_stdout
+from pathlib import Path
+from unittest.mock import patch
+from xml.etree import ElementTree as ET
+
+import authoring_roundtrip
+from authoring_roundtrip import materialize_flat_authoring_roundtrip
+from pptx_shapes import svg_text_fingerprint
+from pptx_to_svg.converter import ConvertOptions, convert_pptx_to_svg
+from svg_to_pptx.drawingml.converter import SvgNativeConversionError, convert_svg_to_slide_shapes
+from svg_to_pptx.pptx_package.builder import create_pptx_with_native_svg
+
+
+NS = {
+ "s": "http://www.w3.org/2000/svg",
+ "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
+ "a": "http://schemas.openxmlformats.org/drawingml/2006/main",
+ "a14": "http://schemas.microsoft.com/office/drawing/2010/main",
+ "m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
+}
+
+
+def _normalized(element: ET.Element) -> str:
+ return ET.canonicalize(ET.tostring(element, encoding="unicode"), rewrite_prefixes=True)
+
+
+def _body(*, formula: bool, reversible: bool = False, multiline: bool = False) -> str:
+ # System colors are valid native math but outside the reverse-import subset.
+ color = '<a:srgbClr val="123456"/>' if reversible else '<a:sysClr val="windowText" lastClr="123456"/>'
+ math = (
+ '<a14:m><m:oMath><m:r><a:rPr><a:solidFill>'
+ f'{color}'
+ '</a:solidFill></a:rPr><m:t>x</m:t></m:r></m:oMath></a14:m>'
+ ) if formula else ""
+ second_line = '<a:p><a:r><a:rPr sz="1800"/><a:t>Second line</a:t></a:r></a:p>' if multiline else ""
+ return (
+ f'<p:txBody xmlns:p="{NS["p"]}" xmlns:a="{NS["a"]}" '
+ f'xmlns:a14="{NS["a14"]}" xmlns:m="{NS["m"]}">'
+ '<a:bodyPr wrap="square" lIns="19050" tIns="28575" rIns="38100" bIns="47625">'
+ '<a:normAutofit fontScale="90000" lnSpcReduction="10000"/>'
+ '</a:bodyPr><a:lstStyle/><a:p><a:pPr>'
+ '<a:buAutoNum type="arabicPeriod" startAt="3"/></a:pPr>'
+ '<a:r><a:rPr lang="fr-FR" sz="1800"/><a:t>Bonjour </a:t></a:r>'
+ f'{math}{math}<a:endParaRPr lang="fr-FR" sz="1800"/>'
+ f'</a:p>{second_line}</p:txBody>'
+ )
+
+
+class RoundtripTextBodyMoveTests(unittest.TestCase):
+ def setUp(self) -> None:
+ temporary = tempfile.TemporaryDirectory()
+ self.addCleanup(temporary.cleanup)
+ self.root = Path(temporary.name)
+ self.workspace = self.root / "workspace"
+
+ def _import(
+ self, *, formula: bool = True, reversible: bool = False, multiline: bool = False, transform: str = "",
+ ) -> None:
+ svg = ET.fromstring(
+ f'<svg xmlns="{NS["s"]}" width="960" height="540" viewBox="0 0 960 540">'
+ '<g id="shape-7" data-pptx-object="shape" data-pptx-shape-id="7" '
+ 'data-pptx-shape-scope="slide" data-pptx-frame="80 100 500 120" '
+ 'data-pptx-prst="rect" data-pptx-semantic-object="shape">'
+ '<path d="M80 100 H580 V220 H80 Z" fill="#FFFFFF" '
+ 'stroke="none" data-pptx-part="geometry"/>'
+ '<text x="90" y="145" font-size="24" font-family="Arial" '
+ 'fill="#123456">Bonjour xx</text></g></svg>'
+ )
+ carrier = svg.find("s:g", NS)
+ if transform:
+ carrier.set("transform", transform)
+ metadata = ET.SubElement(carrier, f'{{{NS["s"]}}}metadata', {
+ "data-pptx-part": "txbody",
+ "data-pptx-encoding": "base64",
+ "data-pptx-text-sha256": svg_text_fingerprint(carrier),
+ })
+ body = _body(formula=formula, reversible=reversible, multiline=multiline)
+ metadata.text = base64.b64encode(body.encode()).decode("ascii")
+ svg_path = self.root / "slide.svg"
+ svg_path.write_bytes(ET.tostring(svg))
+ source = self.root / "source.pptx"
+ log = io.StringIO()
+ with redirect_stdout(log), redirect_stderr(log):
+ success = create_pptx_with_native_svg(
+ [svg_path], source, resource_root=self.root, pptx_structure="flat",
+ use_compat_mode=False, transition=None, workers=1, verbose=False,
+ )
+ self.assertTrue(success, log.getvalue())
+ convert_pptx_to_svg(
+ source, self.workspace, ConvertOptions(inheritance_mode="both", roundtrip=True),
+ )
+ with zipfile.ZipFile(source) as archive:
+ self.original = ET.fromstring(archive.read("ppt/slides/slide1.xml"))
+ self.original = next(
+ shape for shape in self.original.findall(".//p:sp", NS)
+ if shape.find("p:nvSpPr/p:cNvPr", NS).get("id") == "7"
+ )
+ self.path = self.workspace / "authoring-svg-flat" / "slide_01.svg"
+ self.svg = ET.parse(self.path).getroot()
+ self.carrier = next(
+ node for node in self.svg.iter() if node.get("data-pptx-source-ref") == "slide:7"
+ )
+ if formula and not reversible:
+ self.assertFalse(any(node.get("data-pptx-inline-formula") for node in self.carrier.iter()))
+
+ def _move_frame(self, index: int = 0, delta: float = 20) -> None:
+ frame = self.carrier.get("data-pptx-frame").split()
+ frame[index] = str(float(frame[index]) + delta)
+ self.carrier.set("data-pptx-frame", " ".join(frame))
+
+ def _move_coordinates(self, dx: float, dy: float) -> None:
+ self._move_frame(0, dx)
+ self._move_frame(1, dy)
+ x, y, width, height = map(float, self.carrier.get("data-pptx-frame").split())
+ self.carrier.find('*[@data-pptx-part="geometry"]').set(
+ "d", f"M {x:g} {y:g} L {x + width:g} {y:g} L {x + width:g} {y + height:g} L {x:g} {y + height:g} Z",
+ )
+ for node in self.carrier.iter():
+ if node.tag not in {f'{{{NS["s"]}}}text', f'{{{NS["s"]}}}tspan'}:
+ continue
+ for axis, delta in (("x", dx), ("y", dy)):
+ if node.get(axis) is not None:
+ node.set(axis, " ".join(
+ f"{float(value) + delta:.12g}" for value in re.split(r"[\s,]+", node.get(axis).strip())
+ ))
+
+ def _materialize(self):
+ self.path.write_bytes(ET.tostring(self.svg))
+ stderr = io.StringIO()
+ with redirect_stdout(io.StringIO()), redirect_stderr(stderr):
+ materialized = materialize_flat_authoring_roundtrip(
+ self.workspace, self.path.parent, self.workspace / "materialized",
+ )
+ self.materialized = ET.parse(materialized.svg_files[0]).getroot()
+ self.warning_output = stderr.getvalue()
+ self.warnings = materialized.report["documents"][0]["warnings"]
+ return materialized.svg_files[0]
+
+ def _convert(self) -> ET.Element:
+ path = self._materialize()
+ with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
+ xml, *_ = convert_svg_to_slide_shapes(path, resource_root=self.workspace, text_flow="preserve")
+ return ET.fromstring(xml)
+
+ def _export(self) -> ET.Element:
+ return next(
+ shape for shape in self._convert().findall(".//p:sp", NS)
+ if shape.find("p:nvSpPr/p:cNvPr", NS).get("id") == "7"
+ )
+
+ def _wrap_carrier(self, **attributes) -> None:
+ parent = next(node for node in self.svg.iter() if self.carrier in list(node))
+ index = list(parent).index(self.carrier)
+ parent.remove(self.carrier)
+ wrapper = ET.Element(f'{{{NS["s"]}}}g', attributes)
+ wrapper.append(self.carrier)
+ parent.insert(index, wrapper)
+
+ def _assert_preserved(self, result: ET.Element, *, dx: int = 20, dy: int = 0) -> None:
+ self.assertEqual(_normalized(result.find("p:txBody", NS)),
+ _normalized(self.original.find("p:txBody", NS)))
+ before = self.original.find("p:spPr/a:xfrm", NS)
+ after = result.find("p:spPr/a:xfrm", NS)
+ self.assertEqual(after.attrib, before.attrib)
+ self.assertEqual(after.find("a:ext", NS).attrib, before.find("a:ext", NS).attrib)
+ for axis, delta in (("x", dx), ("y", dy)):
+ self.assertEqual(int(after.find("a:off", NS).get(axis)),
+ int(before.find("a:off", NS).get(axis)) + delta * 9525)
+ self.assertEqual(self.warnings, [])
+ self.assertNotIn("native-formula-to-text", self.warning_output)
+
+ def test_frame_translation_preserves_complete_txbody_and_math(self) -> None:
+ self._import()
+ self._move_frame()
+ self._move_frame(1, -10)
+ result = self._export()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 2)
+ self._assert_preserved(result, dy=-10)
+
+ def test_coordinate_translation_preserves_complete_txbody_and_math(self) -> None:
+ self._import(multiline=True)
+ self._move_coordinates(20, -10)
+ result = self._export()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 2)
+ self._assert_preserved(result, dy=-10)
+
+ def test_coordinate_translation_includes_explicit_tspan_positions(self) -> None:
+ self._import()
+ parse_svg = authoring_roundtrip._parse_svg
+
+ def with_run_positions(path):
+ # Exercise equivalent imported projections with explicit run origins.
+ root = parse_svg(path)
+ for text in root.iter(f'{{{NS["s"]}}}text'):
+ span = text.find("s:tspan", NS)
+ if span is not None:
+ for axis in ("x", "y"):
+ if span.get(axis) is None:
+ span.set(axis, text.get(axis))
+ return root
+
+ self.svg = with_run_positions(self.path)
+ self.carrier = next(node for node in self.svg.iter() if node.get("data-pptx-source-ref") == "slide:7")
+ self._move_coordinates(20, -10)
+ with patch("authoring_roundtrip._parse_svg", side_effect=with_run_positions):
+ result = self._export()
+ self._assert_preserved(result, dy=-10)
+
+ def test_moving_only_one_line_does_not_restore_and_warns(self) -> None:
+ self._import(multiline=True)
+ self._move_coordinates(20, -10)
+ line = next(node for node in self.carrier.iter() if node.text == "Second line")
+ line.set("x", str(float(self.carrier.find(".//s:text", NS).get("x")) + 5))
+ self._materialize()
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+ self.assertIn("reason=text-edited", self.warning_output)
+
+ def test_object_translation_preserves_complete_txbody(self) -> None:
+ self._import()
+ self.carrier.set("transform", "translate(20 0)")
+ self._assert_preserved(self._export())
+
+ def test_ancestor_translation_preserves_complete_txbody(self) -> None:
+ self._import()
+ self._wrap_carrier(transform="translate(20 0)")
+ self._assert_preserved(self._export())
+
+ def test_translation_keeps_existing_rotation(self) -> None:
+ self._import(transform="rotate(15 330 160)")
+ self._wrap_carrier(transform="translate(20 0)")
+ self._assert_preserved(self._export())
+
+ def test_width_change_warns_and_does_not_restore(self) -> None:
+ self._import()
+ self._move_frame(2, 100)
+ result = self._export()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+ self.assertEqual(len(self.warnings), 1)
+ self.assertEqual(self.warnings[0]["code"], "native-formula-to-text")
+ self.assertEqual(self.warnings[0]["output_page"], 1)
+ self.assertEqual(self.warnings[0]["source_ref"], "slide:7")
+ for value in ("page=1", "slide_01.svg", "object=shape-7", "native formulas will become plain text",
+ "reason=size/transform-changed"):
+ self.assertIn(value, self.warning_output)
+
+ def test_rotation_and_flip_warn_and_do_not_restore(self) -> None:
+ for transform in ("rotate(15 330 160)", "translate(660 0) scale(-1 1)"):
+ with self.subTest(transform=transform), tempfile.TemporaryDirectory() as directory:
+ self.root = Path(directory)
+ self.workspace = self.root / "workspace"
+ self._import()
+ self.carrier.set("transform", transform)
+ result = self._export()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+ self.assertEqual(len(self.warnings), 1)
+
+ def test_scale_warns_and_does_not_restore_at_materialization(self) -> None:
+ self._import()
+ self._wrap_carrier(transform="scale(1.1 1)")
+ self._materialize()
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+ self.assertEqual(len(self.warnings), 1)
+
+ def test_edited_text_is_not_overwritten_after_move(self) -> None:
+ self._import()
+ self._move_frame()
+ run = next(node for node in self.carrier.iter() if node.text and "Bonjour" in node.text)
+ run.text = run.text.replace("Bonjour", "Bonsoir")
+ result = self._export()
+ text = "".join(node.text or "" for node in result.findall(".//a:t", NS))
+ self.assertIn("Bonsoir", text)
+ self.assertNotIn("Bonjour", text)
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+ self.assertIn("reason=text-edited", self.warning_output)
+
+ def test_text_edit_without_move_warns(self) -> None:
+ self._import()
+ run = next(node for node in self.carrier.iter() if node.text and "Bonjour" in node.text)
+ run.text = run.text.replace("Bonjour", "Bonsoir")
+ result = self._export()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+ self.assertIn("reason=text-edited", self.warning_output)
+
+ def test_edited_style_is_not_overwritten_after_move(self) -> None:
+ self._import()
+ self._move_frame()
+ self.carrier.find(".//s:text", NS).set("font-size", "32")
+ result = self._export()
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+ self.assertIsNotNone(result.find('.//a:rPr[@sz="2400"]', NS))
+ self.assertIn("reason=text-edited", self.warning_output)
+
+ def test_local_text_translation_does_not_restore(self) -> None:
+ self._import()
+ self._move_frame()
+ self.carrier.find(".//s:text", NS).set("transform", "translate(5 0)")
+ self._export()
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+
+ def test_plain_text_translation_preserves_complete_txbody(self) -> None:
+ self._import(formula=False)
+ self._move_frame()
+ self._assert_preserved(self._export())
+
+ def test_plain_text_resize_has_no_formula_warning(self) -> None:
+ self._import(formula=False)
+ self._move_frame(2, 100)
+ self._export()
+ self.assertEqual(self.warnings, [])
+ self.assertNotIn("native formulas will become plain text", self.warning_output)
+
+ def test_native_markers_rebuild_after_resize_without_loss_warning(self) -> None:
+ self._import(reversible=True)
+ self.assertEqual(sum(bool(node.get("data-pptx-inline-formula")) for node in self.carrier.iter()), 2)
+ self._move_frame(2, 100)
+ result = self._convert()
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 2)
+ self.assertEqual(self.warnings, [])
+
+ def test_ancestor_opacity_edit_is_not_overwritten_after_move(self) -> None:
+ self._import()
+ self._wrap_carrier(transform="translate(20 0)", opacity="0.5")
+ result = self._export()
+ self.assertIsNone(self.materialized.find('.//s:metadata[@data-pptx-part="txbody"]', NS))
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+
+ def test_bad_payload_does_not_raise_during_loss_diagnosis(self) -> None:
+ for payload in ("not base64!", base64.b64encode(b"<broken>").decode("ascii")):
+ for edit in ("size", "text"):
+ with self.subTest(payload=payload, edit=edit), tempfile.TemporaryDirectory() as directory:
+ self.root = Path(directory)
+ self.workspace = self.root / "workspace"
+ self._import()
+ if edit == "size":
+ self._move_frame(2, 100)
+ else:
+ self.carrier.find(".//s:text/s:tspan", NS).text = "Edited"
+ parse_svg = authoring_roundtrip._parse_svg
+ corrupted = []
+
+ def corrupt_payload(path):
+ root = parse_svg(path)
+ metadata = root.find('.//s:metadata[@data-pptx-part="txbody"]', NS)
+ if metadata is not None:
+ metadata.text = payload
+ corrupted.append(path)
+ return root
+
+ with patch("authoring_roundtrip._parse_svg", side_effect=corrupt_payload):
+ result = self._export()
+ self.assertTrue(corrupted)
+ self.assertEqual(len(result.findall(".//a14:m", NS)), 0)
+ self.assertEqual(self.warnings, [])
+
+ def test_restored_bad_payload_keeps_converter_validation(self) -> None:
+ self._import()
+ self._move_frame()
+ parse_svg = authoring_roundtrip._parse_svg
+ corrupted = []
+
+ def corrupt_payload(path):
+ root = parse_svg(path)
+ metadata = root.find('.//s:metadata[@data-pptx-part="txbody"]', NS)
+ if metadata is not None:
+ metadata.text = "not base64!"
+ corrupted.append(path)
+ return root
+
+ with patch("authoring_roundtrip._parse_svg", side_effect=corrupt_payload):
+ with self.assertRaisesRegex(SvgNativeConversionError, "Invalid txbody metadata"):
+ self._export()
+ self.assertTrue(corrupted)