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 imported line widths

hugohe3f8a1abb88885
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index e4d7e14c..7ea238d8 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -989,6 +989,10 @@ fidelity.
| Gradient stroke | §6.3; re-import may flatten to first stop |
| `marker-start` / `marker-end` | §1.1 native line end; type `Native-normalized`, size `Approximate` (`sm/med/lg`) |
+PPTX import accepts `a:ln@w` only as an integer DrawingML `ST_LineWidth` value
+from `0` through `20116800` EMU. Malformed, negative, or oversized source widths
+stop import instead of being dropped and replaced by a default SVG line width.
+
The dash grammar is closed: exact lowercase `none`, or at least two finite
unitless numbers separated by whitespace or one comma. Generated SVG uses
ordinary decimal spellings. A leading plus sign, exponent, trailing decimal
diff --git a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
index edd1623f..0956f7b7 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
@@ -12,6 +12,8 @@ from __future__ import annotations
from dataclasses import dataclass, field
from xml.etree import ElementTree as ET
+from pptx_shapes.formula import validate_ooxml_line_width
+
from .color_resolver import ColorPalette, find_color_elem, resolve_color
from .emu_units import NS, emu_to_px, fmt_num
@@ -76,10 +78,14 @@ def resolve_stroke(
width_emu = ln.attrib.get("w")
if width_emu is not None:
try:
- width_px = emu_to_px(int(width_emu))
- attrs["stroke-width"] = fmt_num(width_px, 3)
+ width_value = int(width_emu)
except (ValueError, TypeError):
- pass
+ raise ValueError(
+ f"Invalid DrawingML line width: {width_emu!r}"
+ ) from None
+ validate_ooxml_line_width(width_value)
+ width_px = emu_to_px(width_value)
+ attrs["stroke-width"] = fmt_num(width_px, 3)
# Cap
cap = ln.attrib.get("cap")
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index a38fdb79..c373664c 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2649,6 +2649,22 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
):
resolve_stroke(sp_pr, None)
+ def test_invalid_native_line_width_is_rejected_on_import(self):
+ cases = (
+ ('12.5', "Invalid DrawingML line width: '12.5'"),
+ ('-1', 'DrawingML line width -1 is outside'),
+ ('20116801', 'DrawingML line width 20116801 is outside'),
+ )
+ for width, expected in cases:
+ with self.subTest(width=width):
+ 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:ln w="{width}"/>
+</p:spPr>''')
+ with self.assertRaisesRegex(ValueError, expected):
+ resolve_stroke(sp_pr, None)
+
def test_imported_head_end_uses_supported_reversible_orientation(self):
drawingml_ns = (
'http://schemas.openxmlformats.org/drawingml/2006/main'