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): enforce gradient angle scaling

hugohe37aa5303b2ef7
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 195efad6..246a1a7d 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -752,6 +752,11 @@ 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
silently becoming a horizontal gradient.
+The normalized SVG endpoint mapping preserves `a:lin@scaled="1"` / `"true"`
+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.
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 73a746cd..79e8cb43 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
@@ -163,7 +163,9 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
if lin is not None:
# ang is 1/60000 deg. 0° = horizontal left-to-right.
- angle_deg = _linear_gradient_angle(lin)
+ angle = _linear_gradient_angle(lin)
+ _validate_linear_gradient_scaling(lin, angle)
+ angle_deg = angle / ANGLE_UNIT
x1, y1, x2, y2 = _angle_to_unit_endpoints(angle_deg)
defs_xml = (
f'<linearGradient id="{grad_id}" '
@@ -213,11 +215,11 @@ def _gradient_stop_position(gs: ET.Element) -> float:
return position / PERCENT_UNIT
-def _linear_gradient_angle(lin: ET.Element) -> float:
- """Parse one optional DrawingML positive fixed angle in degrees."""
+def _linear_gradient_angle(lin: ET.Element) -> int:
+ """Parse one optional DrawingML positive fixed angle."""
raw = lin.get("ang")
if raw is None:
- return 0.0
+ return 0
token = raw.strip()
if _OOXML_INTEGER_RE.fullmatch(token) is None:
raise ValueError(f"Invalid DrawingML linear gradient angle: {raw!r}")
@@ -227,7 +229,33 @@ def _linear_gradient_angle(lin: ET.Element) -> float:
f"DrawingML linear gradient angle={angle} is outside "
f"0..{_OOXML_FULL_CIRCLE - 1}"
)
- return angle / ANGLE_UNIT
+ return angle
+
+
+def _validate_linear_gradient_scaling(
+ lin: ET.Element,
+ angle: int,
+) -> None:
+ """Require a scaling mode representable by unit-box SVG geometry."""
+ raw = lin.get("scaled")
+ if raw is None:
+ scaled = False
+ else:
+ token = raw.strip()
+ if token in {"1", "true"}:
+ scaled = True
+ elif token in {"0", "false"}:
+ scaled = False
+ else:
+ raise ValueError(
+ f"Invalid DrawingML linear gradient scaled value: {raw!r}"
+ )
+ quarter_turn = 90 * ANGLE_UNIT
+ if not scaled and angle % quarter_turn:
+ raise ValueError(
+ "Unscaled non-cardinal DrawingML linear gradients are not "
+ "representable by the normalized SVG mapping"
+ )
def _resolve_blip_fill(_elem, _palette, _prefix, _seq, _placeholder_hex) -> FillResult:
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 3cafbe53..eb92b5a7 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2875,10 +2875,15 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
resolve_fill(sp_pr, None)
def test_native_linear_gradient_angle_must_be_valid(self):
- valid_angles = ((None, 0.0), ('0', 0.0), ('21599999', 360.0))
- for angle, expected_degrees in valid_angles:
- with self.subTest(angle=angle):
+ valid_angles = (
+ (None, None, 0.0),
+ ('0', None, 0.0),
+ ('21599999', '1', 360.0),
+ )
+ for angle, scaled, expected_degrees in valid_angles:
+ with self.subTest(angle=angle, scaled=scaled):
angle_attr = '' if angle is None else f' ang="{angle}"'
+ scaled_attr = '' if scaled is None else f' scaled="{scaled}"'
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">
@@ -2886,7 +2891,7 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
<a:gsLst>
<a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
</a:gsLst>
- <a:lin{angle_attr}/>
+ <a:lin{angle_attr}{scaled_attr}/>
</a:gradFill>
</p:spPr>''')
fill = resolve_fill(sp_pr, None)
@@ -2925,6 +2930,44 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, expected):
resolve_fill(sp_pr, None)
+ def test_native_linear_gradient_scaling_must_be_representable(self):
+ def resolve_linear(angle: str, scaled: str | None):
+ scaled_attr = '' if scaled is None else f' scaled="{scaled}"'
+ 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>
+ <a:lin ang="{angle}"{scaled_attr}/>
+ </a:gradFill>
+</p:spPr>''')
+ return resolve_fill(sp_pr, None)
+
+ for scaled in (None, '0', 'false'):
+ with self.subTest(cardinal_scaled=scaled):
+ self.assertTrue(resolve_linear('5400000', scaled).defs)
+ for scaled in ('1', 'true'):
+ with self.subTest(diagonal_scaled=scaled):
+ self.assertTrue(resolve_linear('2700000', scaled).defs)
+
+ for scaled in (None, '0', 'false'):
+ with self.subTest(unscaled_diagonal=scaled):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Unscaled non-cardinal DrawingML linear gradients',
+ ):
+ resolve_linear('2700000', scaled)
+
+ for scaled in ('', '2', 'TRUE', 'on', 'yes'):
+ with self.subTest(invalid_scaled=scaled):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Invalid DrawingML linear gradient scaled value',
+ ):
+ resolve_linear('0', scaled)
+
def test_compound_native_line_is_rejected_on_import(self):
for compound in ('dbl', 'thickThin', 'thinThick', 'tri'):
with self.subTest(compound=compound):