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(pptx_to_svg): resolve theme-style backgrounds when rendering masters/layouts standalone

hugohe378f9029515fe
diff --git a/skills/ppt-master/scripts/pptx_to_svg/converter.py b/skills/ppt-master/scripts/pptx_to_svg/converter.py
index 6905dc3d..4bc82af3 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/converter.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/converter.py
@@ -248,20 +248,23 @@ def _convert_inheritance_parts(
if master.path not in seen_masters:
seen_masters[master.path] = master
- seen_layouts: dict[str, PartRef] = {}
- for layout in pkg.iter_all_layouts():
- if layout.path not in seen_layouts:
- seen_layouts[layout.path] = layout
+ layouts_with_parent: list[tuple[PartRef, PartRef]] = []
+ seen_layout_paths: set[str] = set()
+ for layout, parent_master in pkg.iter_all_layouts_with_parent():
+ if layout.path in seen_layout_paths:
+ continue
+ seen_layout_paths.add(layout.path)
+ layouts_with_parent.append((layout, parent_master))
for seq, part in enumerate(seen_masters.values(), start=1):
result.masters.append(_render_part(
pkg, part, palette, options, result.theme_fonts,
role="master", seq=seq,
))
- for seq, part in enumerate(seen_layouts.values(), start=1):
+ for seq, (layout, parent_master) in enumerate(layouts_with_parent, start=1):
result.layouts.append(_render_part(
- pkg, part, palette, options, result.theme_fonts,
- role="layout", seq=seq,
+ pkg, layout, palette, options, result.theme_fonts,
+ role="layout", seq=seq, parent_master=parent_master,
))
@@ -274,11 +277,13 @@ def _render_part(
*,
role: str,
seq: int,
+ parent_master: PartRef | None = None,
) -> PartArtifact:
"""Render a master/layout part, returning a PartArtifact with output filename."""
svg, media = assemble_part_solo(
pkg, part, palette,
role=role,
+ parent_master=parent_master,
theme_fonts=theme_fonts,
media_subdir=options.media_subdir,
embed_images=options.embed_images,
diff --git a/skills/ppt-master/scripts/pptx_to_svg/ooxml_loader.py b/skills/ppt-master/scripts/pptx_to_svg/ooxml_loader.py
index 9010ff69..a18fa3ee 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/ooxml_loader.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/ooxml_loader.py
@@ -337,6 +337,20 @@ class OoxmlPackage:
"""Yield every slideLayout reachable from any master, regardless of
slide usage. Layouts live under ``master.sldLayoutIdLst`` in document
order; we walk every master so the export reflects the full set.
+
+ See :meth:`iter_all_layouts_with_parent` when you need each layout's
+ owning master alongside the layout itself (e.g. for theme-fill
+ resolution during standalone rendering).
+ """
+ for layout, _master in self.iter_all_layouts_with_parent():
+ yield layout
+
+ def iter_all_layouts_with_parent(self) -> Iterator[tuple[PartRef, PartRef]]:
+ """Like :meth:`iter_all_layouts` but yields ``(layout, parent_master)``
+ pairs. The parent master is the one whose ``sldLayoutIdLst`` contains
+ the layout, which is the source of truth for theme-style resolution
+ (e.g. ``<p:bgRef idx=...>`` on the layout still hops through the
+ master's theme).
"""
seen: set[str] = set()
for master in self.iter_all_masters():
@@ -357,5 +371,5 @@ class OoxmlPackage:
if cached is None:
continue
self._layouts[target] = cached
- yield cached
+ yield cached, master
diff --git a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
index ac856a54..12fca1cc 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
@@ -163,6 +163,7 @@ def assemble_part_solo(
palette: ColorPalette | None,
*,
role: str,
+ parent_master: PartRef | None = None,
theme_fonts: dict[str, str] | None = None,
media_subdir: str = "assets",
embed_images: bool = False,
@@ -179,6 +180,11 @@ def assemble_part_solo(
Args:
role: 'master' or 'layout'. Used as the group_id_prefix to keep ids
unique when the workspace inlines multiple parts in a viewer.
+ parent_master: when ``role == "layout"``, pass the parent slide
+ master so theme-style background fills (``<p:bgRef idx=...>``)
+ can resolve via the theme attached to that master. For
+ ``role == "master"`` the master is its own parent and this
+ argument is ignored.
"""
if role not in {"master", "layout"}:
raise ValueError(f"role must be 'master' or 'layout', got {role!r}")
@@ -198,9 +204,24 @@ def assemble_part_solo(
body_parts: list[str] = []
- # Background: only meaningful if the part itself declares one.
- fake_slide = SlideRef(index=0, part=part, layout=None, master=None)
- bg_xml = _emit_background(fake_slide, ctx, canvas_w, canvas_h)
+ # Layered semantics: each part's standalone SVG must contain only that
+ # part's own contribution. The master gets its own bg, the layout gets
+ # its own bg only if it overrides the master's, and consumers re-stack
+ # the layers when they need a flat view. We therefore inspect <p:bg> on
+ # this part alone — never inherited from above. Theme-style fills
+ # (<p:bgRef idx=...>) still need the parent master's <a:fmtScheme> to
+ # resolve, hence the SlideRef.master plumbing below.
+ if role == "master":
+ master_for_theme: PartRef | None = part
+ else:
+ master_for_theme = parent_master
+ fake_slide = SlideRef(
+ index=0,
+ part=part,
+ layout=None,
+ master=master_for_theme,
+ )
+ bg_xml = _emit_part_background(fake_slide, ctx, canvas_w, canvas_h)
if bg_xml:
body_parts.append(bg_xml)
@@ -612,6 +633,44 @@ def _emit_background(slide: SlideRef, ctx: AssemblyContext,
return ""
+def _emit_part_background(slide: SlideRef, ctx: AssemblyContext,
+ w: float, h: float) -> str:
+ """Render the background declared on the part itself only.
+
+ Distinct from `_emit_background`, which walks the slide → layout →
+ master inheritance chain. Used by the layered solo renderer so each
+ standalone master / layout SVG carries only its own ``<p:bg>`` — the
+ inheritance is rebuilt by consumers re-stacking the layers, and we'd
+ rather output nothing than have master decoration leak into a layout
+ file.
+ """
+ bg = get_background(slide.part.xml)
+ if bg is None:
+ return ""
+ bg_pr = bg.find("p:bgPr", NS)
+ bg_ref = bg.find("p:bgRef", NS)
+ placeholder_hex = None
+
+ if bg_pr is None and bg_ref is not None:
+ bg_pr = _theme_background_fill(slide, ctx, bg_ref)
+ color_elem = find_color_elem(bg_ref)
+ placeholder_hex, _ = resolve_color(color_elem, ctx.palette)
+ if bg_pr is None:
+ return ""
+
+ fill = resolve_fill(
+ bg_pr, ctx.palette,
+ id_prefix="bg", id_seq=ctx.grad_seq,
+ placeholder_hex=placeholder_hex,
+ )
+ ctx.defs.extend(fill.defs)
+ if not fill.attrs:
+ return ""
+ attrs_xml = _attrs_to_xml(fill.attrs)
+ return (f'<rect x="0" y="0" width="{fmt_num(w)}" height="{fmt_num(h)}"'
+ f"{attrs_xml}/>")
+
+
def _theme_background_fill(
slide: SlideRef,
ctx: AssemblyContext,