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): reject ambiguous color choices

hugohe31d4f448ab6ab
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index dfdc3fe1..667775cc 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -731,6 +731,14 @@ style/master inheritance and ultimately default it to `schemeColor(bg1)`, the
local SVG mapping does not guess that external context: empty, malformed,
ambiguous, or unresolvable solid fills stop import instead of being treated as
an omitted fill or reduced to the first recognizable color.
+Other imported color-choice containers, including style references,
+background references, pattern foreground/background wrappers, gradient stops,
+and table text styles, use the same direct-child selector. An omitted color is
+retained only where the owning container permits omission; otherwise the
+surrounding structure contract requires one. Multiple registered colors,
+including duplicate color types, and foreign-namespace elements that reuse a
+registered color local name stop import. Selection never depends on color-type
+priority or silently discards a competing child.
Imported `a:srgbClr` uses exactly one `val` attribute containing six ASCII
hexadecimal digits. SVG/CSS conveniences such as three-digit shorthand, a
leading `#`, alpha-bearing eight-digit tokens, extra attributes, and
diff --git a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
index fe1ea33f..0ca9f32a 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
@@ -129,10 +129,19 @@ _COLOR_MAP_SOURCES = (
"hlink",
"folHlink",
)
-_THEME_COLOR_TAGS = frozenset({
+COLOR_TAGS = (
+ "srgbClr",
+ "schemeClr",
+ "sysClr",
+ "prstClr",
+ "hslClr",
+ "scrgbClr",
+)
+_COLOR_QNAMES = frozenset({
f"{{{NS['a']}}}{name}"
- for name in ("srgbClr", "sysClr", "prstClr", "hslClr", "scrgbClr")
+ for name in COLOR_TAGS
})
+_THEME_COLOR_TAGS = _COLOR_QNAMES - {f"{{{NS['a']}}}schemeClr"}
_SRGB_HEX_RE = re.compile(r"[0-9A-Fa-f]{6}")
_OOXML_INTEGER_RE = re.compile(r"[+-]?[0-9]+")
_OOXML_INT_MIN = -(2**31)
@@ -322,11 +331,6 @@ class ColorPalette:
# Color resolution
# ---------------------------------------------------------------------------
-# All concrete color element names under the a: namespace.
-COLOR_TAGS = ("srgbClr", "schemeClr", "sysClr", "prstClr",
- "hslClr", "scrgbClr")
-
-
def validate_no_fill(elem: ET.Element) -> None:
"""Require the empty DrawingML a:noFill leaf contract."""
if elem.attrib or list(elem) or (elem.text or "").strip():
@@ -341,7 +345,6 @@ def resolve_solid_fill_color(
) -> tuple[str, float]:
"""Resolve one explicit color from a closed DrawingML solid fill."""
children = list(elem)
- color_tags = {f"{{{NS['a']}}}{name}" for name in COLOR_TAGS}
if not elem.attrib and not children and not (elem.text or "").strip():
raise ValueError(
"DrawingML solid fill requires one explicit color"
@@ -349,7 +352,7 @@ def resolve_solid_fill_color(
if (
elem.attrib
or len(children) != 1
- or children[0].tag not in color_tags
+ or children[0].tag not in _COLOR_QNAMES
or (elem.text or "").strip()
or (children[0].tail or "").strip()
):
@@ -365,14 +368,26 @@ def resolve_solid_fill_color(
def find_color_elem(parent: ET.Element | None) -> ET.Element | None:
- """Return the first child color element (any of the 6 OOXML color tags)."""
+ """Return the sole direct registered color, rejecting ambiguous aliases."""
if parent is None:
return None
- for tag in COLOR_TAGS:
- elem = parent.find(f"a:{tag}", NS)
- if elem is not None:
- return elem
- return None
+ colors: list[ET.Element] = []
+ for child in list(parent):
+ if not isinstance(child.tag, str):
+ continue
+ name = child.tag.rsplit("}", 1)[-1]
+ if name not in COLOR_TAGS:
+ continue
+ if child.tag not in _COLOR_QNAMES:
+ raise ValueError(
+ f"Invalid DrawingML color child namespace: {child.tag!r}"
+ )
+ colors.append(child)
+ if len(colors) > 1:
+ raise ValueError(
+ "DrawingML color container has multiple direct color children"
+ )
+ return colors[0] if colors else None
def resolve_color(
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 28a97ed4..a1462f1c 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -40,7 +40,11 @@ from pptx_to_svg.preset_authoring import (
validate_authored_preset_tree,
)
from pptx_to_svg.emu_units import Xfrm, format_ooxml_alpha
-from pptx_to_svg.color_resolver import ColorPalette, resolve_color
+from pptx_to_svg.color_resolver import (
+ ColorPalette,
+ find_color_elem,
+ resolve_color,
+)
from pptx_to_svg.effect_to_svg import (
convert_effects,
unsupported_target_effect_metadata,
@@ -3006,6 +3010,46 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
('#445566', 1.0),
)
+ def test_native_color_selector_rejects_ambiguous_or_aliased_children(self):
+ namespace = (
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"'
+ )
+ single = ET.fromstring(
+ f'<a:fontRef {namespace} idx="minor">'
+ '<a:srgbClr val="112233"/></a:fontRef>'
+ )
+ selected = find_color_elem(single)
+ self.assertIsNotNone(selected)
+ self.assertEqual(selected.tag.rsplit('}', 1)[-1], 'srgbClr')
+
+ omitted = ET.fromstring(
+ f'<a:fontRef {namespace} idx="minor"/>'
+ )
+ self.assertIsNone(find_color_elem(omitted))
+
+ ambiguous_colors = (
+ '<a:srgbClr val="112233"/><a:schemeClr val="accent1"/>',
+ '<a:srgbClr val="112233"/><a:srgbClr val="445566"/>',
+ )
+ for children in ambiguous_colors:
+ with self.subTest(children=children):
+ parent = ET.fromstring(
+ f'<a:fontRef {namespace} idx="minor">'
+ f'{children}</a:fontRef>'
+ )
+ with self.assertRaisesRegex(
+ ValueError,
+ 'multiple direct color children',
+ ):
+ find_color_elem(parent)
+
+ aliased = ET.fromstring(
+ f'<a:fontRef {namespace} xmlns:future="urn:future" idx="minor">'
+ '<future:srgbClr val="112233"/></a:fontRef>'
+ )
+ with self.assertRaisesRegex(ValueError, 'color child namespace'):
+ find_color_elem(aliased)
+
def test_native_theme_palette_uses_closed_scheme_and_map_contracts(self):
a_ns = 'http://schemas.openxmlformats.org/drawingml/2006/main'
p_ns = 'http://schemas.openxmlformats.org/presentationml/2006/main'