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 gradient directions

hugohe33992ef3e6269
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 246a1a7d..bf8d9971 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -757,6 +757,10 @@ at every angle. The schema default (`scaled` omitted) and explicit `"0"` /
`"false"` are accepted only at cardinal angles, where aspect-ratio scaling
cannot change the direction. Other unscaled angles and malformed boolean values
stop import instead of producing a direction that varies with shape geometry.
+An imported non-line `a:gradFill` contains at most one direct `a:lin` or
+`a:path` direction. Omitting both uses the schema-defined horizontal linear
+default; duplicate or mixed direction elements stop import instead of being
+selected by implementation priority.
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 79e8cb43..9bcd21a3 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
@@ -158,8 +158,15 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
f'stop-color="{hex_}"{opacity_attr}/>'
)
# Linear vs radial vs path
- lin = elem.find("a:lin", NS)
- rad = elem.find("a:path", NS)
+ linear_directions = elem.findall("a:lin", NS)
+ path_directions = elem.findall("a:path", NS)
+ if len(linear_directions) + len(path_directions) > 1:
+ raise ValueError(
+ "DrawingML gradient fill must contain at most one lin/path "
+ "direction"
+ )
+ lin = linear_directions[0] if linear_directions else None
+ rad = path_directions[0] if path_directions else None
if lin is not None:
# ang is 1/60000 deg. 0° = horizontal left-to-right.
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index eb92b5a7..be5a5eaf 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2968,6 +2968,47 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
):
resolve_linear('0', scaled)
+ def test_native_gradient_direction_must_be_unambiguous(self):
+ direction_cases = (
+ '<a:lin ang="0"/><a:lin ang="0"/>',
+ '<a:path path="circle"/><a:path path="circle"/>',
+ '<a:lin ang="0"/><a:path path="circle"/>',
+ )
+ for directions in direction_cases:
+ with self.subTest(directions=directions):
+ 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>
+ <a:gsLst>
+ <a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ </a:gsLst>
+ {directions}
+ </a:gradFill>
+</p:spPr>''')
+ with self.assertRaisesRegex(
+ ValueError,
+ 'at most one lin/path direction',
+ ):
+ resolve_fill(sp_pr, None)
+
+ default_direction = ET.fromstring('''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:gradFill>
+ <a:gsLst>
+ <a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ </a:gsLst>
+ </a:gradFill>
+</p:spPr>''')
+ fill = resolve_fill(default_direction, None)
+ gradient = ET.fromstring(fill.defs[0])
+ self.assertEqual(gradient.tag, 'linearGradient')
+ self.assertEqual(
+ tuple(gradient.get(name) for name in ('x1', 'y1', 'x2', 'y2')),
+ ('0', '0', '1', '0'),
+ )
+
def test_compound_native_line_is_rejected_on_import(self):
for compound in ('dbl', 'thickThin', 'thinThick', 'tri'):
with self.subTest(compound=compound):