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): require complete gradient stops

hugohe39c400673a06e
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index eeaf5055..f3132d53 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -737,13 +737,17 @@ Linear export preserves stops/alpha/direction but reduces coordinates to an
angle. Radial export becomes a centered circular gradient and does not preserve
`cx/cy/r/fx/fy`. Gradient strokes remain editable, but PPTX-to-SVG re-import may
retain only the first stop. Stop alpha and element opacity multiply.
-PPTX import writes stop offsets with five decimal places, and export parses the
-shared unitless/percentage grammar before half-up quantization to 1/100000.
-Thus small positions and values such as `1%` round-trip without truncation or
-percentage reinterpretation.
-Each imported `a:gs` requires an integer `pos` from `0` through `100000`.
+Non-line PPTX gradient-fill import writes stop offsets with five decimal places,
+and export parses the shared unitless/percentage grammar before half-up
+quantization to 1/100000. Thus small positions and values such as `1%`
+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.
The quality checker and exporter preflight both validate definition location,
references, gradient structure, and paint context from the same closed contract.
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 e7b71127..66981c7a 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
@@ -123,16 +123,29 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
grad_id = f"{prefix}grad{seq[0]}"
# Stops
- gs_lst = elem.find("a:gsLst", NS)
- if gs_lst is None:
- return FillResult.inherit()
+ gs_lists = elem.findall("a:gsLst", NS)
+ if len(gs_lists) != 1:
+ 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"
+ )
stops_xml = []
- for gs in gs_lst.findall("a:gs", NS):
+ for gs in gradient_stops:
pos_pct = _gradient_stop_position(gs)
color_elem = find_color_elem(gs)
- hex_, alpha = resolve_color(color_elem, palette, placeholder_hex=placeholder_hex)
+ hex_, alpha = resolve_color(
+ color_elem,
+ palette,
+ placeholder_hex=placeholder_hex,
+ )
if hex_ is None:
- continue
+ raise ValueError(
+ "DrawingML gradient stop color cannot be resolved"
+ )
opacity_attr = (
f' stop-opacity="{format_ooxml_alpha(alpha)}"'
if alpha < 1.0
@@ -142,9 +155,6 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
f'<stop offset="{format_ooxml_unit_ratio(pos_pct)}" '
f'stop-color="{hex_}"{opacity_attr}/>'
)
- if not stops_xml:
- return FillResult.inherit()
-
# Linear vs radial vs path
lin = elem.find("a:lin", NS)
rad = elem.find("a:path", NS)
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index a3594051..c7a80865 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2838,6 +2838,42 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, expected):
resolve_fill(sp_pr, None)
+ def test_native_gradient_requires_resolvable_stops(self):
+ invalid_gradients = (
+ (
+ '',
+ 'requires exactly one gsLst',
+ ),
+ (
+ '<a:gsLst/><a:gsLst/>',
+ 'requires exactly one gsLst',
+ ),
+ (
+ '<a:gsLst/>',
+ 'requires at least one color stop',
+ ),
+ (
+ '<a:gsLst><a:gs pos="0"/></a:gsLst>',
+ 'gradient stop color cannot be resolved',
+ ),
+ (
+ '<a:gsLst>'
+ '<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>'
+ '<a:gs pos="100000"><a:schemeClr val="accent1"/></a:gs>'
+ '</a:gsLst>',
+ 'gradient stop color cannot be resolved',
+ ),
+ )
+ for gradient_markup, expected in invalid_gradients:
+ with self.subTest(gradient_markup=gradient_markup):
+ sp_pr = ET.fromstring(f'''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:gradFill>{gradient_markup}</a:gradFill>
+</p:spPr>''')
+ with self.assertRaisesRegex(ValueError, expected):
+ resolve_fill(sp_pr, None)
+
def test_compound_native_line_is_rejected_on_import(self):
for compound in ('dbl', 'thickThin', 'thinThick', 'tri'):
with self.subTest(compound=compound):