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 sRGB color tokens

hugohe3de4f86f0c464
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index f5be3563..91d8927a 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -731,6 +731,12 @@ 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.
+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
+interleaved text stop import instead of being normalized into a different
+DrawingML token. Lowercase hexadecimal digits remain equivalent input and
+normalize to uppercase SVG paint.
---
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 ce915148..210351bd 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
@@ -11,6 +11,7 @@ a:clrScheme.
from __future__ import annotations
import colorsys
+import re
from xml.etree import ElementTree as ET
from .emu_units import NS, percent_to_ratio
@@ -100,6 +101,7 @@ SCHEME_ALIASES = {
"bg1": "lt1", "bg2": "lt2",
"tx1": "dk1", "tx2": "dk2",
}
+_SRGB_HEX_RE = re.compile(r"[0-9A-Fa-f]{6}")
# ---------------------------------------------------------------------------
@@ -237,8 +239,7 @@ def resolve_color(
alpha: float = 1.0
if tag == "srgbClr":
- val = color_elem.attrib.get("val", "")
- base_hex = _normalize_hex(val)
+ base_hex = _srgb_hex_value(color_elem)
elif tag == "schemeClr":
name = color_elem.attrib.get("val", "")
if name == "phClr":
@@ -273,6 +274,22 @@ def resolve_color(
return f"#{base_hex}", alpha
+def _srgb_hex_value(color_elem: ET.Element) -> str:
+ """Parse the closed six-digit DrawingML sRGB base token."""
+ children = list(color_elem)
+ if (
+ color_elem.tag != f"{{{NS['a']}}}srgbClr"
+ 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 sRGB color structure")
+ raw = color_elem.attrib["val"]
+ if _SRGB_HEX_RE.fullmatch(raw) is None:
+ raise ValueError(f"Invalid DrawingML sRGB color value: {raw!r}")
+ return raw.upper()
+
+
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 698e8d74..cebe7524 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -40,6 +40,7 @@ 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 resolve_color
from pptx_to_svg.effect_to_svg import (
convert_effects,
unsupported_target_effect_metadata,
@@ -2901,6 +2902,58 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, expected):
resolve_stroke(sp_pr, None)
+ def test_native_srgb_color_requires_six_digit_hex(self):
+ invalid_colors = (
+ ('<a:srgbClr/>', 'sRGB color structure'),
+ ('<a:srgbClr val="ABC"/>', 'sRGB color value'),
+ ('<a:srgbClr val="#112233"/>', 'sRGB color value'),
+ ('<a:srgbClr val="11223344"/>', 'sRGB color value'),
+ ('<a:srgbClr val="GGGGGG"/>', 'sRGB color value'),
+ (
+ '<a:srgbClr val="112233" future="x"/>',
+ 'sRGB color structure',
+ ),
+ (
+ '<a:srgbClr val="112233" '
+ 'xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" '
+ 'a14:legacySpreadsheetColorIndex="1"/>',
+ 'sRGB color structure',
+ ),
+ (
+ '<a:srgbClr val="112233">payload</a:srgbClr>',
+ 'sRGB color structure',
+ ),
+ (
+ '<a:srgbClr val="112233"><a:alpha val="50000"/>payload'
+ '</a:srgbClr>',
+ 'sRGB 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:srgbClr xmlns:future="urn:future" val="112233"/>'
+ )
+ with self.assertRaisesRegex(ValueError, 'sRGB color structure'):
+ resolve_color(foreign_color, None)
+
+ valid = ET.fromstring(f'''
+<a:solidFill {namespace}>
+ <a:srgbClr val="a1b2c3"><a:alpha val="50000"/></a:srgbClr>
+</a:solidFill>''')
+ resolved = resolve_fill(valid, None)
+ self.assertEqual(resolved.attrs['fill'], '#A1B2C3')
+ self.assertEqual(resolved.attrs['fill-opacity'], '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):