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): validate preset color values

hugohe39467b52eb44d
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 49936bf9..be34ace5 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -751,6 +751,11 @@ machine's dynamic system palette. Missing/unknown system identities, malformed
fallbacks, extra attributes, namespace aliases, and interleaved text stop
import; a valid `lastClr` is normalized into static SVG paint, so this route is
`Native-normalized` rather than system-color-preserving.
+Imported `a:prstClr` has exactly one `val` attribute selected from the complete
+190-value DrawingML preset-color enum, all of which have a registered static
+RGB mapping. Missing/unknown/case-altered values, extra attributes, namespace
+aliases, and interleaved text stop import instead of falling back to black or
+an adjacent CSS color name.
---
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 b46f8cf5..4dbaf0d9 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
@@ -22,7 +22,7 @@ from .ooxml_loader import PartRef
# Preset color names (DrawingML <a:prstClr val="...">)
# ---------------------------------------------------------------------------
-# Source: ECMA-376 ST_PresetColorVal (subset — full list has ~140 entries).
+# Source: complete ECMA-376 ST_PresetColorVal enumeration (190 values).
PRST_COLORS = {
"aliceBlue": "F0F8FF", "antiqueWhite": "FAEBD7", "aqua": "00FFFF",
"aquamarine": "7FFFD4", "azure": "F0FFFF", "beige": "F5F5DC",
@@ -300,8 +300,7 @@ def resolve_color(
elif tag == "sysClr":
base_hex = _system_color_fallback(color_elem)
elif tag == "prstClr":
- name = color_elem.attrib.get("val", "")
- base_hex = PRST_COLORS.get(name)
+ base_hex = _preset_color_hex(color_elem)
elif tag == "hslClr":
# DrawingML hue is in 1/60000 deg ([0, 21_600_000) maps to [0°, 360°));
# _hsl_to_hex expects a fraction in [0, 1), so divide by 60000 * 360.
@@ -382,6 +381,23 @@ def _system_color_fallback(color_elem: ET.Element) -> str:
return fallback.upper()
+def _preset_color_hex(color_elem: ET.Element) -> str:
+ """Resolve one exact value from the complete DrawingML preset enum."""
+ children = list(color_elem)
+ if (
+ color_elem.tag != f"{{{NS['a']}}}prstClr"
+ or set(color_elem.attrib) != {"val"}
+ or (color_elem.text or "").strip()
+ or any((child.tail or "").strip() for child in children)
+ ):
+ raise ValueError("Invalid DrawingML preset color structure")
+ name = color_elem.attrib["val"]
+ hex_ = PRST_COLORS.get(name)
+ if hex_ is None:
+ raise ValueError(f"Invalid DrawingML preset color value: {name!r}")
+ return hex_
+
+
def _apply_modifiers(hex_color: str, color_elem: ET.Element) -> tuple[str, float]:
"""Apply tint / shade / lumMod / lumOff / satMod / hueMod / alpha modifiers
in document order. DrawingML stacks these on the color in order.
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 6e78bb13..4be1beda 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -3068,6 +3068,49 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
</a:sysClr>''')
self.assertEqual(resolve_color(valid, None), ('#A1B2C3', 0.5))
+ def test_native_preset_color_requires_registered_value(self):
+ invalid_colors = (
+ ('<a:prstClr/>', 'preset color structure'),
+ (
+ '<a:prstClr val="red" future="x"/>',
+ 'preset color structure',
+ ),
+ ('<a:prstClr val="Red"/>', 'preset color value'),
+ ('<a:prstClr val="futureColor"/>', 'preset color value'),
+ ('<a:prstClr val=" red "/>', 'preset color value'),
+ (
+ '<a:prstClr val="red">payload</a:prstClr>',
+ 'preset color structure',
+ ),
+ (
+ '<a:prstClr val="red"><a:alpha val="50000"/>payload'
+ '</a:prstClr>',
+ 'preset color structure',
+ ),
+ )
+ namespace = (
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"'
+ )
+ for color, expected in invalid_colors:
+ with self.subTest(color=color):
+ fill = ET.fromstring(
+ f'<a:solidFill {namespace}>{color}</a:solidFill>'
+ )
+ with self.assertRaisesRegex(ValueError, expected):
+ resolve_fill(fill, None)
+
+ foreign_color = ET.fromstring(
+ '<future:prstClr xmlns:future="urn:future" val="red"/>'
+ )
+ with self.assertRaisesRegex(ValueError, 'preset color structure'):
+ resolve_color(foreign_color, None)
+
+ valid = ET.fromstring(f'''
+<a:prstClr {namespace} val="dkBlue">
+ <a:alpha val="50000"/>
+</a:prstClr>''')
+ self.assertEqual(resolve_color(valid, None), ('#00008B', 0.5))
+
def test_native_gradient_stop_position_round_trips(self):
for position in (0, 1, 7, 13, 33333, 99999, 100000):
with self.subTest(position=position):