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(svg-to-pptx): require explicit filter flood opacity

hugohe34c2d866a84fe
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 68aad83f..103d21d3 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -758,7 +758,7 @@ Filters are native-effect metadata, not a general pixel-filter surface.
| Definition/reference | Direct `<defs><filter id="...">` child with unique id; direct `filter="url(#id)"` attribute, never inline style |
| Public targets | `<rect>`, `<circle>`, `<path>`, `<text>` |
| Required primitive | `feDropShadow` or `feGaussianBlur` |
-| Required parameters | Explicit `stdDeviation` on either effect primitive; explicit `dx` and `dy` on `feDropShadow`; explicit `slope` on linear `feFuncA` |
+| Required parameters | Explicit `stdDeviation` on either effect primitive; explicit `dx`, `dy`, and `flood-opacity` on `feDropShadow`; explicit `flood-opacity` on `feFlood`; explicit `slope` on linear `feFuncA` |
| Accepted helpers | `feOffset`, `feFlood`, `feComposite`, `feMerge`, `feMergeNode`, `feComponentTransfer`, linear `feFuncA` |
| Numeric values | Finite unitless values; non-negative `stdDeviation`; finite `dx` / `dy`; `feFuncA slope` within `0..1`; mapped glow `rad = stdDeviation × 9525`, shadow `blurRad = stdDeviation × 2 × 9525`, and shadow `dist = hypot(dx,dy) × 9525` must round into DrawingML `0..27273042316900` |
| Classification | Meaningful non-zero offset → one outer shadow; zero/no offset → one glow |
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index c5f8ef75..13ba070a 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -1964,6 +1964,12 @@ def parse_project_filter_params(
def effect_attr(name: str, default: str | None = None) -> str | None:
return style_values.get(name) or child.get(name, default)
+ def required_effect_attr(name: str) -> str:
+ raw_value = effect_attr(name)
+ if raw_value is None:
+ raise ValueError(f'<{tag}> requires explicit {name}')
+ return raw_value
+
if tag == 'feDropShadow':
std_dev = required_number(child, 'stdDeviation')
dx = required_number(child, 'dx')
@@ -1971,8 +1977,7 @@ def parse_project_filter_params(
if abs(dx) > 0.01 or abs(dy) > 0.01:
has_offset = True
paint_opacity = parse_opacity(
- effect_attr('flood-opacity'),
- 0.3,
+ required_effect_attr('flood-opacity'),
allow_percentage=True,
)
parsed_color, parsed_alpha = parse_svg_color(
@@ -1990,8 +1995,7 @@ def parse_project_filter_params(
has_offset = True
elif tag == 'feFlood':
paint_opacity = parse_opacity(
- effect_attr('flood-opacity'),
- 0.3,
+ required_effect_attr('flood-opacity'),
allow_percentage=True,
)
parsed_color, parsed_alpha = parse_svg_color(
@@ -2117,7 +2121,7 @@ def project_filter_errors(root: ET.Element) -> list[str]:
for filter_id, filter_elem in filters_by_id.items():
label = f'filter #{filter_id}'
- geometry_is_valid = True
+ parameters_are_valid = True
primitives = [
_svg_element_tag(descendant) or str(descendant.tag)
for descendant in filter_elem.iter()
@@ -2150,6 +2154,17 @@ def project_filter_errors(root: ET.Element) -> list[str]:
for primitive in filter_elem.iter():
primitive_tag = _svg_element_tag(primitive)
+ if primitive_tag in {'feDropShadow', 'feFlood'}:
+ style_values = parse_inline_style(primitive.get('style'))
+ if (
+ primitive.get('flood-opacity') is None
+ and 'flood-opacity' not in style_values
+ ):
+ parameters_are_valid = False
+ errors.add(
+ f'{label} <{primitive_tag}> requires explicit '
+ 'flood-opacity'
+ )
numeric_attrs: tuple[tuple[str, bool, bool], ...] = ()
if primitive_tag in {'feDropShadow', 'feGaussianBlur'}:
numeric_attrs = (('stdDeviation', True, True),)
@@ -2169,7 +2184,7 @@ def project_filter_errors(root: ET.Element) -> list[str]:
raw_value = primitive.get(attribute_name)
if raw_value is None:
if required:
- geometry_is_valid = False
+ parameters_are_valid = False
errors.add(
f'{label} <{primitive_tag}> requires explicit '
f'{attribute_name}'
@@ -2189,7 +2204,7 @@ def project_filter_errors(root: ET.Element) -> list[str]:
)
):
if attribute_name in {'stdDeviation', 'dx', 'dy'}:
- geometry_is_valid = False
+ parameters_are_valid = False
qualifier = (
' from 0 to 1'
if primitive_tag == 'feFuncA'
@@ -2199,7 +2214,7 @@ def project_filter_errors(root: ET.Element) -> list[str]:
f'{label} <{primitive_tag}> {attribute_name} must be a '
f'finite number{qualifier}; got {raw_value!r}'
)
- if len(effect_primitives) == 1 and geometry_is_valid:
+ if len(effect_primitives) == 1 and parameters_are_valid:
try:
params = parse_project_filter_params(filter_elem)
project_filter_drawingml_coordinates(params)
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 527ef500..6f1be5c4 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2563,6 +2563,44 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
'invalid project filter',
)
+ def test_filter_flood_opacity_must_be_explicit(self):
+ cases = (
+ (
+ 'drop-shadow shorthand',
+ '<feDropShadow dx="0" dy="4" stdDeviation="6" '
+ 'flood-color="#000000"/>',
+ '<feDropShadow> requires explicit flood-opacity',
+ ),
+ (
+ 'expanded flood primitive',
+ '<feGaussianBlur stdDeviation="6"/>'
+ '<feFlood flood-color="#000000"/>',
+ '<feFlood> requires explicit flood-opacity',
+ ),
+ )
+ for label, graph, expected in cases:
+ with self.subTest(label=label):
+ self._assert_checker_and_exporter_reject(
+ f'''<svg xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 1280 720">
+ <defs><filter id="effect">{graph}</filter></defs>
+ <rect x="80" y="80" width="300" height="180"
+ fill="#FFFFFF" filter="url(#effect)"/>
+</svg>''',
+ expected,
+ 'invalid project filter',
+ )
+
+ styled = ET.fromstring('''<svg xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <filter id="effect">
+ <feGaussianBlur stdDeviation="6"/>
+ <feFlood flood-color="#000000" style="flood-opacity:0.2"/>
+ </filter>
+ </defs>
+</svg>''')
+ self.assertEqual(project_filter_errors(styled), [])
+
def test_filter_coordinates_block_drawingml_overflow(self):
cases = (
(
@@ -2573,13 +2611,13 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
(
'shadow blur radius',
'<feDropShadow dx="1" dy="0" '
- 'stdDeviation="1431655765"/>',
+ 'stdDeviation="1431655765" flood-opacity="0.2"/>',
'DrawingML blurRad must map within',
),
(
'shadow distance',
'<feDropShadow dx="2863311530" dy="0" '
- 'stdDeviation="1"/>',
+ 'stdDeviation="1" flood-opacity="0.2"/>',
'DrawingML dist must map within',
),
(
@@ -2612,7 +2650,8 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
</filter>
<filter id="shadow">
<feDropShadow dx="{glow_std_dev!r}" dy="0"
- stdDeviation="{shadow_std_dev!r}"/>
+ stdDeviation="{shadow_std_dev!r}"
+ flood-opacity="0.2"/>
</filter>
</defs>
<rect x="80" y="80" width="300" height="180"