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): close gradient stop lists

hugohe311ea27d523f1
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 6ebf21ec..0ff1d7cb 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -744,10 +744,11 @@ round-trip without truncation or percentage reinterpretation. In that non-line
import mapping, each `a:gs` requires an integer `pos` from `0` through `100000`.
Missing, malformed, or out-of-range source positions stop import instead of
being silently relocated to the start of the gradient.
-An explicit non-line imported `a:gradFill` requires exactly one `a:gsLst` with
-at least one `a:gs`, and every stop must provide a resolvable color. Missing or
-duplicate lists, empty lists, and unresolvable stops stop import instead of
-becoming an inherited fill or a partial gradient.
+An explicit non-line imported `a:gradFill` requires exactly one attribute-free
+`a:gsLst` with at least two direct `a:gs` children and no other payload. Every
+stop must provide a resolvable color. Missing or duplicate lists, undersized or
+malformed lists, and unresolvable stops stop import instead of becoming an
+inherited fill or a partial gradient.
An imported non-line `a:lin@ang` may be omitted for the schema-defined zero
default. When present, it must be an integer from `0` through `21599999`
(1/60000 degree); malformed or out-of-range values stop import instead of
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 5dd2bd0e..c14f4518 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
@@ -140,11 +140,7 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
raise ValueError(
"DrawingML gradient fill requires exactly one gsLst"
)
- gradient_stops = gs_lists[0].findall("a:gs", NS)
- if not gradient_stops:
- raise ValueError(
- "DrawingML gradient fill requires at least one color stop"
- )
+ gradient_stops = _gradient_stop_list(gs_lists[0])
stops_xml = []
for gs in gradient_stops:
pos_pct = _gradient_stop_position(gs)
@@ -236,6 +232,26 @@ def _gradient_stop_position(gs: ET.Element) -> float:
return position / PERCENT_UNIT
+def _gradient_stop_list(gs_list: ET.Element) -> list[ET.Element]:
+ """Validate one DrawingML gradient-stop list and return its stops."""
+ stops = list(gs_list)
+ stop_tag = f"{{{NS['a']}}}gs"
+ if (
+ gs_list.attrib
+ or (gs_list.text or "").strip()
+ or any(
+ stop.tag != stop_tag or (stop.tail or "").strip()
+ for stop in stops
+ )
+ ):
+ raise ValueError("Invalid DrawingML gradient stop list structure")
+ if len(stops) < 2:
+ raise ValueError(
+ "DrawingML gradient fill requires at least two color stops"
+ )
+ return stops
+
+
def _linear_gradient_angle(lin: ET.Element) -> int:
"""Parse one optional DrawingML positive fixed angle."""
raw = lin.get("ang")
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index f2e74ad3..b705341d 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2793,6 +2793,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="{position}"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:lin ang="0"/>
</a:gradFill>
@@ -2832,6 +2833,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs{pos_attr}><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
</a:gradFill>
</p:spPr>''')
@@ -2850,12 +2852,41 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
),
(
'<a:gsLst/>',
- 'requires at least one color stop',
+ 'requires at least two color stops',
),
(
'<a:gsLst><a:gs pos="0"/></a:gsLst>',
+ 'requires at least two color stops',
+ ),
+ (
+ '<a:gsLst>'
+ '<a:gs pos="0"/>'
+ '<a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>'
+ '</a:gsLst>',
'gradient stop color cannot be resolved',
),
+ (
+ '<a:gsLst future="x">'
+ '<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>'
+ '<a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>'
+ '</a:gsLst>',
+ 'Invalid DrawingML gradient stop list structure',
+ ),
+ (
+ '<a:gsLst>'
+ '<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>'
+ '<a:future/>'
+ '<a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>'
+ '</a:gsLst>',
+ 'Invalid DrawingML gradient stop list structure',
+ ),
+ (
+ '<a:gsLst>payload'
+ '<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>'
+ '<a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>'
+ '</a:gsLst>',
+ 'Invalid DrawingML gradient stop list structure',
+ ),
(
'<a:gsLst>'
'<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>'
@@ -2890,6 +2921,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:lin{angle_attr}{scaled_attr}/>
</a:gradFill>
@@ -2923,6 +2955,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:lin ang="{angle}"/>
</a:gradFill>
@@ -2939,6 +2972,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:lin ang="{angle}"{scaled_attr}/>
</a:gradFill>
@@ -2983,6 +3017,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
{linear_direction}
</a:gradFill>
@@ -3007,6 +3042,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
{directions}
</a:gradFill>
@@ -3023,6 +3059,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
</a:gradFill>
</p:spPr>''')
@@ -3043,6 +3080,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:path{path_attr}/>
</a:gradFill>
@@ -3082,6 +3120,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
{path_direction}
</a:gradFill>
@@ -3103,6 +3142,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill{rotation_attr}>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
</a:gradFill>
</p:spPr>''')
@@ -3137,6 +3177,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill{flip_attr}>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
</a:gradFill>
</p:spPr>''')
@@ -3162,6 +3203,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill futureMode="x" future:mode="y">
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
</a:gradFill>
</p:spPr>''')
@@ -3179,6 +3221,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
{tile_rect}
</a:gradFill>
@@ -3236,6 +3279,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gradFill>
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ <a:gs pos="100000"><a:srgbClr val="445566"/></a:gs>
</a:gsLst>
<a:path path="circle">{focus_rect}</a:path>
</a:gradFill>
@@ -3357,7 +3401,8 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
),
(
'<a:gradFill><a:gsLst><a:gs pos="0">'
- '<a:srgbClr val="445566"/></a:gs></a:gsLst></a:gradFill>',
+ '<a:srgbClr val="445566"/></a:gs><a:gs pos="100000">'
+ '<a:srgbClr val="778899"/></a:gs></a:gsLst></a:gradFill>',
'#445566',
),
)