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(pptx-to-svg): honor placeholder schema defaults
hugohe36450bb71f9f6
diff --git a/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py b/skills/ppt-master/scripts/pptx_to_svg/shape_walker.pyindex 79600e26..417247df 100644--- a/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py+++ b/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py@@ -33,7 +33,19 @@ GROUP = "grpSp"GRAPHIC = "graphicFrame"_TITLE_PLACEHOLDER_TYPES = {"title", "ctrTitle"}-_BODY_PLACEHOLDER_TYPES = {"body", "subTitle"}+_BODY_PLACEHOLDER_TYPES = {+ "body",+ "chart",+ "clipArt",+ "dgm",+ "media",+ "obj",+ "pic",+ "subTitle",+ "tbl",+}+_DEFAULT_PLACEHOLDER_TYPE = "obj"+_DEFAULT_PLACEHOLDER_INDEX = "0"_TX_STYLE_TITLE_KEY = ("__txStyleTitle", None)_TX_STYLE_BODY_KEY = ("__txStyleBody", None)_TX_STYLE_OTHER_KEY = ("__txStyleOther", None)@@ -278,14 +290,12 @@ def _lookup_placeholder_xfrm(ph: PlaceholderInfo,table: dict[tuple[str | None, str | None], Xfrm],) -> Xfrm | None:- """Find an inherited xfrm for a placeholder. PowerPoint matches first by- (type, idx) exactly, then by type alone, then by idx alone — so a slide- body with idx="1" can pull from a layout body that omits idx, and a slide- title with no idx can pull from a master title that has idx="0"."""+ """Find inherited geometry after applying the OOXML placeholder defaults."""+ ph_type, ph_idx = _placeholder_identity(ph.type, ph.idx)for key in (- (ph.type, ph.idx),- (ph.type, None),- (None, ph.idx),+ (ph_type, ph_idx),+ (ph_type, None),+ (None, ph_idx),):hit = table.get(key)if hit is not None and (hit.w > 0 or hit.h > 0):@@ -298,12 +308,13 @@ def _lookup_placeholder_lst_styles(table: dict[tuple[str | None, str | None], list[ET.Element]],) -> tuple[ET.Element, ...]:"""Find inherited txBody/lstStyle elements for a placeholder."""+ ph_type, ph_idx = _placeholder_identity(ph.type, ph.idx)styles: list[ET.Element] = []seen: set[int] = set()for key in (- (ph.type, ph.idx),- (ph.type, None),- (None, ph.idx),+ (ph_type, ph_idx),+ (ph_type, None),+ (None, ph_idx),_placeholder_tx_style_key(ph),):for style in table.get(key, []):@@ -318,13 +329,25 @@ def _lookup_placeholder_lst_styles(def _placeholder_tx_style_key(ph: PlaceholderInfo,) -> tuple[str | None, str | None]:- if ph.type in _TITLE_PLACEHOLDER_TYPES:+ ph_type, _ph_idx = _placeholder_identity(ph.type, ph.idx)+ if ph_type in _TITLE_PLACEHOLDER_TYPES:return _TX_STYLE_TITLE_KEY- if ph.type in _BODY_PLACEHOLDER_TYPES:+ if ph_type in _BODY_PLACEHOLDER_TYPES:return _TX_STYLE_BODY_KEYreturn _TX_STYLE_OTHER_KEY+def _placeholder_identity(+ ph_type: str | None,+ ph_idx: str | None,+) -> tuple[str, str]:+ """Resolve the schema defaults used for placeholder inheritance keys."""+ return (+ _DEFAULT_PLACEHOLDER_TYPE if ph_type is None else ph_type,+ _DEFAULT_PLACEHOLDER_INDEX if ph_idx is None else ph_idx,+ )++def _build_placeholder_xfrm_table(*parts: ET.Element | None,) -> dict[tuple[str | None, str | None], Xfrm]:@@ -353,8 +376,10 @@ def _build_placeholder_xfrm_table(xfrm = parse_xfrm(xfrm_elem)if xfrm.w <= 0 and xfrm.h <= 0:continue- ph_type = ph_elem.attrib.get("type")- ph_idx = ph_elem.attrib.get("idx")+ ph_type, ph_idx = _placeholder_identity(+ ph_elem.attrib.get("type"),+ ph_elem.attrib.get("idx"),+ )for key in ((ph_type, ph_idx),(ph_type, None),(None, ph_idx)):@@ -382,8 +407,10 @@ def _build_placeholder_lst_style_table(lst_style = sp.find("p:txBody/a:lstStyle", NS)if lst_style is None:continue- ph_type = ph_elem.attrib.get("type")- ph_idx = ph_elem.attrib.get("idx")+ ph_type, ph_idx = _placeholder_identity(+ ph_elem.attrib.get("type"),+ ph_elem.attrib.get("idx"),+ )for key in ((ph_type, ph_idx),(ph_type, None),(None, ph_idx)):diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.pyindex dd9673a6..7e366bbc 100644--- a/skills/ppt-master/scripts/test_svg_quality_checker.py+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py@@ -434,11 +434,18 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):rewritten.replace(path)@staticmethod- def _write_inherited_run_effect_fixture(path: Path) -> None:- """Write placeholder text that inherits one run effect from its layout."""+ def _write_inherited_run_effect_fixture(+ path: Path,+ *,+ style_source: str = 'layout',+ ) -> None:+ """Write placeholder text inheriting one Layout or Master run effect."""+ if style_source not in {'layout', 'master'}:+ raise ValueError("style_source must be 'layout' or 'master'")presentation = Presentation()layout = presentation.slide_layouts[1]layout_part = str(layout.part.partname).lstrip('/')+ master_part = str(layout.slide_master.part.partname).lstrip('/')slide_parts: list[str] = []for index in range(1, 4):slide = presentation.slides.add_slide(layout)@@ -478,19 +485,42 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):layout_placeholder, layout_placeholder_properties = body_placeholder(layout_root)- layout_placeholder_properties.set('type', 'body')+ layout_placeholder_properties.attrib.pop('type', None)list_style = layout_placeholder.find(f'{{{pml}}}txBody/{{{dml}}}lstStyle')assert list_style is not None- level_properties = ET.SubElement(list_style, f'{{{dml}}}lvl1pPr')- default_properties = ET.SubElement(- level_properties,- f'{{{dml}}}defRPr',- )++ if style_source == 'layout':+ style_root = list_style+ else:+ master_root = ET.fromstring(member_data[master_part])+ style_root = master_root.find(+ f'{{{pml}}}txStyles/{{{pml}}}bodyStyle'+ )+ assert style_root is not None++ level_properties = style_root.find(f'{{{dml}}}lvl1pPr')+ if level_properties is None:+ level_properties = ET.SubElement(+ style_root,+ f'{{{dml}}}lvl1pPr',+ )+ default_properties = level_properties.find(f'{{{dml}}}defRPr')+ if default_properties is None:+ default_properties = ET.SubElement(+ level_properties,+ f'{{{dml}}}defRPr',+ )default_properties.append(ET.fromstring(f'''<a:effectLst xmlns:a="{dml}"><a:glow rad="38100"><a:srgbClr val="2563EB"/></a:glow></a:effectLst>'''))+ if style_source == 'master':+ replacements[master_part] = ET.tostring(+ master_root,+ encoding='utf-8',+ xml_declaration=True,+ )replacements[layout_part] = ET.tostring(layout_root,encoding='utf-8',@@ -3312,66 +3342,82 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):2: 'unsupported-run-effect-route:vertical-text',3: 'unsupported-run-effect-route:relationship-bearing-text',}- with tempfile.TemporaryDirectory() as tmp_dir:- root_dir = Path(tmp_dir)- pptx_path = root_dir / 'inherited-run-effects.pptx'- self._write_inherited_run_effect_fixture(pptx_path)- imported = convert_pptx_to_svg(- pptx_path,- options=ConvertOptions(inheritance_mode='flat'),++ def assert_artifact(artifact) -> None:+ reason = expected_reasons[artifact.index]+ root = ET.fromstring(artifact.svg)+ self.assertIn('INHERITED', ''.join(root.itertext()))+ self.assertEqual(project_filter_errors(root), [])+ marked = [+ elem+ for elem in root.iter()+ if elem.get('data-pptx-effect-status') == 'unsupported'+ ]+ self.assertEqual(len(marked), 2)+ self.assertEqual(+ {+ elem.get('data-pptx-effect-reason')+ for elem in marked+ },+ {reason},+ )+ logical_shape = next(+ elem+ for elem in marked+ if elem.tag.rsplit('}', 1)[-1] == 'g')- self.assertEqual(len(imported.slides), 3)+ self.assertEqual(+ logical_shape.get('data-name'),+ 'Content Placeholder 2',+ )+ title_shape = next(+ elem+ for elem in root.iter()+ if elem.get('data-name') == 'Title 1'+ )+ self.assertIsNone(title_shape.get('data-pptx-effect-status'))+ status_errors = project_effect_status_errors(root)+ self.assertEqual(len(status_errors), 1)+ self.assertIn(reason, status_errors[0])- for artifact in imported.slides:- with self.subTest(slide=artifact.index):- reason = expected_reasons[artifact.index]- root = ET.fromstring(artifact.svg)- self.assertIn(- f'INHERITED EFFECT {artifact.index}',- ''.join(root.itertext()),- )- self.assertEqual(project_filter_errors(root), [])- marked = [- elem- for elem in root.iter()- if elem.get('data-pptx-effect-status') == 'unsupported'- ]- self.assertEqual(len(marked), 2)- self.assertEqual(- {- elem.get('data-pptx-effect-reason')- for elem in marked- },- {reason},+ metadata = [+ elem+ for elem in logical_shape.iter()+ if elem.get('data-pptx-part') == 'txbody'+ ]+ if artifact.index == 1:+ self.assertEqual(len(metadata), 1)+ payload = base64.b64decode(+ (metadata[0].text or '').strip()+ ).decode('utf-8')+ self.assertNotIn('<a:effectLst', payload)+ else:+ self.assertEqual(metadata, [])++ self._assert_checker_and_exporter_reject(+ artifact.svg,+ reason,+ 'unsupported imported PPTX effect',+ )++ for style_source in ('layout', 'master'):+ with self.subTest(style_source=style_source):+ with tempfile.TemporaryDirectory() as tmp_dir:+ pptx_path = (+ Path(tmp_dir) / f'{style_source}-run-effects.pptx')- logical_shape = next(- elem- for elem in marked- if elem.tag.rsplit('}', 1)[-1] == 'g'+ self._write_inherited_run_effect_fixture(+ pptx_path,+ style_source=style_source,)- status_errors = project_effect_status_errors(root)- self.assertEqual(len(status_errors), 1)- self.assertIn(reason, status_errors[0])-- metadata = [- elem- for elem in logical_shape.iter()- if elem.get('data-pptx-part') == 'txbody'- ]- if artifact.index == 1:- self.assertEqual(len(metadata), 1)- payload = base64.b64decode(- (metadata[0].text or '').strip()- ).decode('utf-8')- self.assertNotIn('<a:effectLst', payload)- else:- self.assertEqual(metadata, [])-- self._assert_checker_and_exporter_reject(- artifact.svg,- reason,- 'unsupported imported PPTX effect',+ imported = convert_pptx_to_svg(+ pptx_path,+ options=ConvertOptions(inheritance_mode='flat'),)+ self.assertEqual(len(imported.slides), 3)+ for artifact in imported.slides:+ with self.subTest(slide=artifact.index):+ assert_artifact(artifact)def test_table_cell_run_effect_import_fails_closed(self):cases = [