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
feat(svg_to_pptx): consume svg_output/ directly for native pptx
hugohe35ad80a94be7e
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.pyindex 767c051f..f0c65c5b 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py@@ -260,6 +260,18 @@ def convert_svg_to_slide_shapes(tree = ET.parse(str(svg_path))root = tree.getroot()+ # Expand <use data-icon="..."/> placeholders in-memory so this dispatcher+ # can consume svg_output/ directly. Standard renderers and this converter+ # both ignore data-icon, so without expansion icons would silently drop.+ # The on-disk finalize_svg pipeline does the same expansion for svg_final/;+ # running this here makes the two pipelines behaviourally aligned.+ icons_dir = Path(__file__).resolve().parent.parent.parent / 'templates' / 'icons'+ if icons_dir.exists():+ from .use_expander import expand_use_data_icons+ expanded = expand_use_data_icons(root, icons_dir)+ if verbose and expanded:+ print(f' Expanded {expanded} <use data-icon="..."/> placeholder(s)')+defs = collect_defs(root)ctx = ConvertContext(defs=defs, slide_num=slide_num, svg_dir=Path(svg_path).parent)diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.pyindex 8bd1eb6e..4b097ea6 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py@@ -60,7 +60,15 @@ def _wrap_shape(# ---------------------------------------------------------------------------def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:- """Convert SVG <rect> to DrawingML shape."""+ """Convert SVG <rect> to DrawingML shape.++ Symmetric rounded corners (rx == ry) are emitted as ``prstGeom roundRect``+ so PowerPoint treats them as a native rounded-rectangle shape: the yellow+ adjustment handle stays draggable, and "Reset Picture / Shape" works as+ expected. Elliptical corners (rx != ry) fall back to plain rect geometry+ for now — current corpora contain none, but the branch keeps callers from+ silently producing distorted custom geometry if one ever appears.+ """x = ctx_x(_f(elem.get('x')), ctx)y = ctx_y(_f(elem.get('y')), ctx)w = ctx_w(_f(elem.get('width')), ctx)@@ -69,6 +77,20 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:if w <= 0 or h <= 0:return None+ # SVG spec: when only one of rx/ry is specified, the other inherits its+ # value. Real-world svg_output decks always write only `rx`, so ry must+ # be inferred to keep round corners from collapsing to zero on one axis.+ rx_attr = elem.get('rx')+ ry_attr = elem.get('ry')+ rx_raw = _f(rx_attr) if rx_attr is not None else 0.0+ ry_raw = _f(ry_attr) if ry_attr is not None else 0.0+ if rx_attr is not None and ry_attr is None:+ ry_raw = rx_raw+ elif ry_attr is not None and rx_attr is None:+ rx_raw = ry_raw+ rx = rx_raw * ctx.scale_x+ ry = ry_raw * ctx.scale_y+fill_op = get_fill_opacity(elem, ctx)stroke_op = get_stroke_opacity(elem, ctx)fill = build_fill_xml(elem, ctx, fill_op)@@ -86,7 +108,20 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:if r_match:rot = int(float(r_match.group(1)) * ANGLE_UNIT)- geom = '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'+ if rx > 0 and abs(rx - ry) < 0.5:+ # Native rounded-rect: adj is the corner radius as a fraction of the+ # shorter side, in 1/1000-percent units, capped at 50000 (= radius+ # equals half the shorter side, i.e. capsule end).+ short_side = min(w, h)+ radius = min(rx, short_side / 2)+ adj = max(0, min(50000, int(round(radius / short_side * 100000))))+ geom = (+ '<a:prstGeom prst="roundRect">'+ f'<a:avLst><a:gd name="adj" fmla="val {adj}"/></a:avLst>'+ '</a:prstGeom>'+ )+ else:+ geom = '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'shape_id = ctx.next_id()off_x = px_to_emu(x)diff --git a/skills/ppt-master/scripts/svg_to_pptx/use_expander.py b/skills/ppt-master/scripts/svg_to_pptx/use_expander.pynew file mode 100644index 00000000..72289b0d--- /dev/null+++ b/skills/ppt-master/scripts/svg_to_pptx/use_expander.py@@ -0,0 +1,127 @@+"""In-memory expansion of ``<use data-icon="lib/name">`` elements.++The icon placeholder ``<use data-icon="...">`` is a project-internal SVG+extension; standard renderers (browsers, PowerPoint's SVG parser) and our+own DrawingML dispatcher do not understand it. ``finalize_svg`` already+expands it on disk into ``svg_final/``; this module provides the same+expansion in memory so ``svg_to_pptx`` can consume ``svg_output/`` directly+without first running the on-disk finalize step.++Public API:+ expand_use_data_icons(root, icons_dir) -> int+ Walk the SVG element tree, replace every ``<use data-icon="...">``+ with its expanded ``<g>`` group of primitive shapes, and return+ the number of replacements made.++The heavy lifting (icon resolution, color application, scaling) is+delegated to ``svg_finalize.embed_icons`` so the two pipelines stay+behaviourally aligned.+"""++from __future__ import annotations++import sys+from pathlib import Path+from xml.etree import ElementTree as ET+++SVG_NS = 'http://www.w3.org/2000/svg'+++def _import_embed_icons():+ """Lazy import so svg_to_pptx doesn't hard-require svg_finalize at import time."""+ scripts_dir = Path(__file__).resolve().parent.parent+ if str(scripts_dir) not in sys.path:+ sys.path.insert(0, str(scripts_dir))+ from svg_finalize import embed_icons # type: ignore+ return embed_icons+++def _build_replacement_g(+ use_elem: ET.Element,+ icons_dir: Path,+ embed_icons_mod,+) -> ET.Element | None:+ """Resolve a single ``<use data-icon="...">`` into an expanded ``<g>``.++ Returns None when the icon name is missing, unresolved, or the icon+ file cannot be parsed. Callers should leave the original ``<use>`` in+ place in that case (matching the on-disk finalize_svg behaviour, which+ also leaves unresolvable placeholders untouched).+ """+ use_str = ET.tostring(use_elem, encoding='unicode')+ attrs = embed_icons_mod.parse_use_element(use_str)+ if 'icon' not in attrs:+ return None++ icon_path, _base_size = embed_icons_mod.resolve_icon_path(+ attrs['icon'], icons_dir,+ )+ if not icon_path.exists():+ return None++ color = attrs.get('fill', '#000000')+ elements, style, base_size = embed_icons_mod.extract_paths_from_icon(+ icon_path, color,+ )+ if not elements:+ return None++ g_xml = embed_icons_mod.generate_icon_group(attrs, elements, style, base_size)++ # Wrap with a namespaced root so the parsed subtree carries the SVG+ # namespace through to every primitive (path/circle/...).+ wrapped = f'<svg xmlns="{SVG_NS}">{g_xml}</svg>'+ try:+ parsed_root = ET.fromstring(wrapped)+ except ET.ParseError:+ return None++ for child in parsed_root:+ local = child.tag.split('}')[-1] if '}' in child.tag else child.tag+ if local == 'g':+ return child+ return None+++def expand_use_data_icons(root: ET.Element, icons_dir: Path) -> int:+ """Replace every ``<use data-icon="...">`` in *root* with its expansion.++ Walks the tree, finds use elements that carry a ``data-icon`` attribute,+ builds a new ``<g>`` subtree from the corresponding icon library, and+ swaps it into the parent element at the same position.++ Returns the number of placeholders successfully expanded. Unresolvable+ placeholders are left in place so callers can decide whether to warn.+ """+ if not icons_dir.exists():+ return 0++ embed_icons_mod = _import_embed_icons()++ # ElementTree elements don't carry a parent reference, so build a map.+ parent_of: dict[ET.Element, ET.Element] = {}+ for parent in root.iter():+ for child in parent:+ parent_of[child] = parent++ targets: list[ET.Element] = []+ for elem in root.iter():+ local = elem.tag.split('}')[-1] if '}' in elem.tag else elem.tag+ if local == 'use' and elem.get('data-icon'):+ targets.append(elem)++ expanded = 0+ for use_elem in targets:+ parent = parent_of.get(use_elem)+ if parent is None:+ continue+ replacement = _build_replacement_g(use_elem, icons_dir, embed_icons_mod)+ if replacement is None:+ continue+ idx = list(parent).index(use_elem)+ parent.remove(use_elem)+ parent.insert(idx, replacement)+ expanded += 1++ return expanded