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): enforce the DrawingML fill choice

hugohe3ade60f6f2625
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 0904e875..28a1414d 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -714,6 +714,14 @@ preflight; neither substitutes an opaque default for unknown intent.
plus alpha when a painted transparent layer must remain represented. Prefer
descendant alpha over group opacity when isolated compositing matters (§2.2).
+On PPTX-to-SVG import, a non-line DrawingML fill-bearing container has at most
+one direct fill choice among `a:noFill`, `a:solidFill`, `a:gradFill`,
+`a:blipFill`, `a:pattFill`, and `a:grpFill`. Competing choices and
+foreign-namespace aliases stop import instead of being selected by
+implementation priority. Explicit `a:grpFill` also stops import until group
+fill inheritance has a registered SVG mapping; an omitted fill continues to
+use the owning container's inheritance/default contract.
+
---
### 6.3 Gradients and Paint Effects
diff --git a/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
index 8167f85b..8b6808a3 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
@@ -41,6 +41,17 @@ _OOXML_PERCENT_LITERAL_RE = re.compile(
_OOXML_FULL_CIRCLE = 360 * ANGLE_UNIT
_OOXML_PERCENTAGE_MIN = Decimal(-(2**31)) / Decimal(PERCENT_UNIT)
_OOXML_PERCENTAGE_MAX = Decimal(2**31 - 1) / Decimal(PERCENT_UNIT)
+_DRAWINGML_FILL_NAMES = (
+ "noFill",
+ "solidFill",
+ "gradFill",
+ "blipFill",
+ "pattFill",
+ "grpFill",
+)
+_DRAWINGML_FILL_TAGS = {
+ f"{{{NS['a']}}}{name}": name for name in _DRAWINGML_FILL_NAMES
+}
@dataclass
@@ -85,26 +96,56 @@ def resolve_fill(
if sp_pr is None:
return FillResult.inherit()
- # Direct child fill (in priority order: explicit -> derived).
- handlers = (
- ("noFill", _resolve_no_fill),
- ("solidFill", _resolve_solid_fill),
- ("gradFill", _resolve_grad_fill),
- ("blipFill", _resolve_blip_fill),
- ("pattFill", _resolve_patt_fill),
- )
+ handlers = {
+ "noFill": _resolve_no_fill,
+ "solidFill": _resolve_solid_fill,
+ "gradFill": _resolve_grad_fill,
+ "blipFill": _resolve_blip_fill,
+ "pattFill": _resolve_patt_fill,
+ }
- local_name = sp_pr.tag.split("}", 1)[-1] if isinstance(sp_pr.tag, str) else ""
- for tag, handler in handlers:
- if local_name == tag:
- return handler(sp_pr, palette, id_prefix, id_seq, placeholder_hex)
+ fill_name = _drawingml_fill_name(sp_pr)
+ fill_elem = sp_pr if fill_name is not None else None
+ if fill_elem is None:
+ fill_children = []
+ for child in sp_pr:
+ child_name = _drawingml_fill_name(child)
+ if child_name is not None:
+ fill_children.append((child, child_name))
+ if len(fill_children) > 1:
+ raise ValueError(
+ "DrawingML container must contain at most one fill"
+ )
+ if not fill_children:
+ return FillResult.inherit()
+ fill_elem, fill_name = fill_children[0]
+
+ if fill_name == "grpFill":
+ raise ValueError("Unsupported DrawingML fill: grpFill")
+ return handlers[fill_name](
+ fill_elem,
+ palette,
+ id_prefix,
+ id_seq,
+ placeholder_hex,
+ )
- for tag, handler in handlers:
- elem = sp_pr.find(f"a:{tag}", NS)
- if elem is not None:
- return handler(elem, palette, id_prefix, id_seq, placeholder_hex)
- return FillResult.inherit()
+def _drawingml_fill_name(elem: ET.Element) -> str | None:
+ """Return one exact DrawingML fill tag name or reject a namespace alias."""
+ name = _DRAWINGML_FILL_TAGS.get(elem.tag)
+ if name is not None:
+ return name
+ local_name = (
+ elem.tag.rsplit("}", 1)[-1]
+ if isinstance(elem.tag, str)
+ else ""
+ )
+ if local_name in _DRAWINGML_FILL_NAMES:
+ raise ValueError(
+ f"Invalid DrawingML fill element namespace: {local_name}"
+ )
+ return None
# ---------------------------------------------------------------------------
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 8e4cf10f..836d0357 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2784,6 +2784,45 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
stroke_xml,
)
+ def test_native_fill_choice_must_be_unambiguous(self):
+ competing_fills = ET.fromstring('''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:noFill/>
+ <a:solidFill><a:srgbClr val="112233"/></a:solidFill>
+</p:spPr>''')
+ with self.assertRaisesRegex(
+ ValueError,
+ 'must contain at most one fill',
+ ):
+ resolve_fill(competing_fills, None)
+
+ for group_fill in (
+ '<a:grpFill '
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>',
+ '<p:spPr '
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" '
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">'
+ '<a:grpFill/></p:spPr>',
+ ):
+ with self.subTest(group_fill=group_fill):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Unsupported DrawingML fill: grpFill',
+ ):
+ resolve_fill(ET.fromstring(group_fill), None)
+
+ foreign_fill = ET.fromstring('''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:future="urn:future">
+ <future:solidFill/>
+</p:spPr>''')
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Invalid DrawingML fill element namespace: solidFill',
+ ):
+ resolve_fill(foreign_fill, None)
+
def test_native_gradient_stop_position_round_trips(self):
for position in (0, 1, 7, 13, 33333, 99999, 100000):
with self.subTest(position=position):