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(export): keep imported custom-geometry connectors exportable

hugohe33b865783570b
diff --git a/skills/ppt-master/scripts/svg_authoring_view.py b/skills/ppt-master/scripts/svg_authoring_view.py
index fff8771c..547e41f2 100644
--- a/skills/ppt-master/scripts/svg_authoring_view.py
+++ b/skills/ppt-master/scripts/svg_authoring_view.py
@@ -938,10 +938,24 @@ def _unwrap_preview(parent: ET.Element, wrapper: ET.Element) -> bool:
return True
-def _strip_import_attributes(element: ET.Element, stats: ProjectionStats) -> None:
+def _strip_import_attributes(
+ element: ET.Element,
+ stats: ProjectionStats,
+ *,
+ geometry_owner: ET.Element | None = None,
+) -> None:
for name in list(element.attrib):
if name not in AUTHORING_OMITTED_SOURCE_ATTRIBUTES:
continue
+ if (
+ geometry_owner is not None
+ and geometry_owner.get("data-pptx-object") == "connector"
+ and element.get("data-pptx-part") == "geometry"
+ and name in {"data-pptx-custgeom", "data-pptx-geometry-sha256"}
+ ):
+ # Connectors need the source custom geometry when exported from
+ # the compact projection, which no longer rehydrates source refs.
+ continue
stats.source_attributes[name] += 1
del element.attrib[name]
@@ -997,7 +1011,7 @@ def _project_subtree(parent: ET.Element, stats: ProjectionStats) -> None:
continue
_project_subtree(child, stats)
- _strip_import_attributes(child, stats)
+ _strip_import_attributes(child, stats, geometry_owner=parent)
if part == "geometry-preview":
child.attrib.pop("data-pptx-part", None)
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
index 7339f0c3..cdcc8788 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
@@ -891,7 +891,12 @@ def _convert_semantic_shape(
# The carrier path becomes the native object; keep the group's name.
carrier.set('data-name', str(shape.get('id')))
- if shape.get('data-pptx-geometry-kind') == 'custom':
+ # Imported carriers retain their hash-guarded source geometry. Only a
+ # semantic custom shape without a source payload compiles from SVG alone.
+ if (
+ shape.get('data-pptx-geometry-kind') == 'custom'
+ and carrier.get('data-pptx-custgeom') is None
+ ):
for name in (
'data-pptx-custgeom',
'data-pptx-geometry-kind',
diff --git a/skills/ppt-master/scripts/tests/test_native_export_guards.py b/skills/ppt-master/scripts/tests/test_native_export_guards.py
index c845a024..f41f183f 100644
--- a/skills/ppt-master/scripts/tests/test_native_export_guards.py
+++ b/skills/ppt-master/scripts/tests/test_native_export_guards.py
@@ -3,6 +3,8 @@
from __future__ import annotations
+import base64
+import hashlib
import io
import json
import sys
@@ -23,6 +25,7 @@ from pptx_shapes.formula import OOXML_COORDINATE_MAX # noqa: E402
from animation_config import main as animation_config_main # noqa: E402
from pptx_gradients import native_gradient_metadata, preserved_native_gradient_xml # noqa: E402
from svg_finalize.flatten_tspan import flatten_text_with_tspans # noqa: E402
+from svg_authoring_view import project_svg_batch # noqa: E402
from svg_quality.checker import SVGQualityChecker # noqa: E402
from svg_to_pptx.animation_config import ( # noqa: E402
build_group_listing,
@@ -69,6 +72,87 @@ class NativeExportGuardTests(unittest.TestCase):
def _check(self) -> dict:
return SVGQualityChecker(quick_generate=True).check_file(str(self.svg_path))
+ def _custom_connector(self, frame: str, path: str, *, transform: str = '') -> str:
+ custom = (
+ f'<a:custGeom xmlns:a="{NS["a"]}"><a:avLst/>'
+ '<a:gdLst><a:gd name="middle" fmla="*/ w 1 2"/></a:gdLst>'
+ '<a:ahLst/><a:cxnLst><a:cxn ang="0"><a:pos x="r" y="t"/>'
+ '</a:cxn></a:cxnLst><a:rect l="l" t="t" r="r" b="b"/>'
+ '<a:pathLst><a:path w="300" h="100" fill="none">'
+ '<a:moveTo><a:pt x="0" y="0"/></a:moveTo>'
+ '<a:lnTo><a:pt x="300" y="100"/></a:lnTo></a:path>'
+ '<a:path w="300" h="100" fill="none">'
+ '<a:moveTo><a:pt x="75" y="25"/></a:moveTo>'
+ '<a:lnTo><a:pt x="225" y="75"/></a:lnTo></a:path>'
+ '</a:pathLst></a:custGeom>'
+ )
+ encoded = base64.b64encode(custom.encode('utf-8')).decode('ascii')
+ digest = hashlib.sha256(path.encode('utf-8')).hexdigest()
+ self._svg(
+ '<g id="custom" data-pptx-semantic-object="shape" '
+ 'data-pptx-object="connector" data-pptx-geometry-kind="custom" '
+ f'data-pptx-frame="{frame}" {transform}>'
+ f'<path d="{path}" data-pptx-part="geometry" '
+ f'data-pptx-custgeom="{encoded}" data-pptx-geometry-sha256="{digest}" '
+ 'fill="none" stroke="#3060C0" stroke-width="2"/></g>'
+ )
+ return custom
+
+ def test_semantic_custom_connector_preserves_source_geometry(self) -> None:
+ for frame, path, transform in (
+ ('120 180 300 0', 'M 120 180 L 420 180 M 195 180 L 345 180', ''),
+ ('120 180 0 100', 'M 120 180 L 120 280 M 120 205 L 120 255', ''),
+ ('120 180 300 100', 'M 120 180 L 420 280 M 195 205 L 345 255', ''),
+ ('120 180 300 0', 'M 120 180 L 420 180 M 195 180 L 345 180',
+ 'transform="rotate(45 270 180)"'),
+ ('120 180 300 0', 'M 120 180 L 420 180 M 195 180 L 345 180',
+ 'transform="translate(540 0) scale(-1 1)"'),
+ ):
+ with self.subTest(frame=frame, transform=transform):
+ custom = self._custom_connector(frame, path, transform=transform)
+ xml, *_ = convert_svg_to_slide_shapes(self.svg_path, resource_root=self.root)
+ self.assertIn(custom, xml)
+ slide = ET.fromstring(xml)
+ self.assertEqual(len(slide.findall('.//p:cxnSp', NS)), 1)
+ ext = slide.find('.//p:cxnSp/p:spPr/a:xfrm/a:ext', NS)
+ self.assertEqual(int(ext.get('cx')), int(float(frame.split()[2]) * 9525))
+ self.assertEqual(int(ext.get('cy')), int(float(frame.split()[3]) * 9525))
+
+ def test_semantic_custom_connector_recompiles_an_edited_path(self) -> None:
+ path = 'M 120 180 L 420 280 M 195 205 L 345 255'
+ custom = self._custom_connector('120 180 300 100', path)
+ self.svg_path.write_text(
+ self.svg_path.read_text(encoding='utf-8').replace(path, 'M 120 180 L 300 240'),
+ encoding='utf-8',
+ )
+ xml, *_ = convert_svg_to_slide_shapes(self.svg_path, resource_root=self.root)
+ self.assertNotIn(custom, xml)
+ slide = ET.fromstring(xml)
+ self.assertEqual(len(slide.findall('.//p:cxnSp', NS)), 1)
+ self.assertEqual(len(slide.findall('.//a:custGeom/a:pathLst/a:path', NS)), 1)
+
+ def test_custom_connector_projection_keeps_source_geometry(self) -> None:
+ custom = self._custom_connector('120 180 300 0', 'M 120 180 L 420 180')
+ authoring_dir = self.root / 'authoring'
+ projected = authoring_dir / self.svg_path.name
+ project_svg_batch(
+ [(self.svg_path, projected)], self.root, authoring_dir,
+ force=False, projection_kind='layered',
+ )
+ xml, *_ = convert_svg_to_slide_shapes(projected, resource_root=self.root)
+ self.assertIn(custom, xml)
+ self.assertEqual(len(ET.fromstring(xml).findall('.//p:cxnSp', NS)), 1)
+
+ def test_semantic_custom_connector_without_source_geometry_still_fails(self) -> None:
+ self._svg(
+ '<g data-pptx-semantic-object="shape" data-pptx-object="connector" '
+ 'data-pptx-geometry-kind="custom" data-pptx-frame="120 180 300 100">'
+ '<path d="M 120 180 L 420 280" data-pptx-part="geometry" '
+ 'stroke="#3060C0" fill="none"/></g>'
+ )
+ with self.assertRaisesRegex(SvgNativeConversionError, 'requires preset or preserved'):
+ self._export()
+
@staticmethod
def _shape_colors(slide: ET.Element) -> list[str]:
return [