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-effects): preserve clipped picture effects

hugohe3a51f7d33e781
diff --git a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
index 66b1a844..17fb9ce0 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
@@ -978,9 +978,12 @@ def _convert_picture(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool)
group_attrs = _metadata_group_attrs(effect_metadata)
if effect.filter_id is not None:
filter_attr = f"url(#{effect.filter_id})"
- if clipped_svg.startswith("<svg"):
+ if (
+ clipped_svg.startswith("<svg")
+ or clipped_svg.startswith("<image clip-path=")
+ ):
# Keep the effect outside the crop viewport so shadows and glows
- # remain visible beyond the picture frame in SVG previews.
+ # remain visible beyond the picture geometry in SVG previews.
group_attrs.append(f'filter="{filter_attr}"')
else:
picture_attrs["filter"] = filter_attr
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
index 916cfc07..d5342139 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
@@ -51,7 +51,7 @@ from .utils import (
_extract_inheritable_styles,
_get_attr,
_is_unit_axis_reflection,
- is_imported_picture_crop_effect_carrier,
+ is_picture_effect_carrier,
parse_svg_length,
parse_transform_operations,
parse_transform_matrix,
@@ -863,7 +863,7 @@ def convert_g(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
)
logical_picture_effect_group = (
filter_id is not None
- and is_imported_picture_crop_effect_carrier(elem)
+ and is_picture_effect_carrier(elem)
)
explicit_native_group = elem.get('data-pptx-object') == 'group'
if (
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 42cd6d7c..ade00da8 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -2638,11 +2638,17 @@ def project_filter_errors(root: ET.Element) -> list[str]:
if (
tag not in PROJECT_FILTER_PUBLIC_TARGETS
and not _is_imported_preset_preview_filter_target(elem, parents)
- and not is_imported_picture_crop_effect_carrier(elem)
+ and not is_picture_effect_carrier(elem)
):
errors.add(
f'{label} cannot use filter; supported native targets are '
- 'rect, circle, image, path, and text'
+ 'rect, circle, image, path, text, and an exact single clipped-'
+ 'image carrier group'
+ )
+ if tag == 'image' and elem.get('clip-path') is not None:
+ errors.add(
+ f'{label} cannot combine filter and clip-path on the same '
+ 'image; put the filter on an exact single-image outer <g>'
)
match = re.fullmatch(r'url\(#([^)]+)\)', raw_filter.strip())
if match is None:
@@ -2857,11 +2863,11 @@ def _is_imported_preset_preview_filter_target(
)
-def is_imported_picture_crop_effect_carrier(elem: ET.Element) -> bool:
- """Recognize the private effect carrier around an imported picture crop."""
+def is_picture_effect_carrier(elem: ET.Element) -> bool:
+ """Recognize one effect carrier around exactly one clipped picture."""
if (
_svg_element_tag(elem) != 'g'
- or elem.get('data-pptx-object') != 'picture'
+ or elem.get('data-pptx-object') == 'group'
):
return False
children = [
@@ -2870,17 +2876,37 @@ def is_imported_picture_crop_effect_carrier(elem: ET.Element) -> bool:
]
if len(children) != 1:
return False
- crop = children[0]
+ picture = children[0]
+ if picture.get('filter') is not None:
+ return False
+ owner_kind = elem.get('data-pptx-object')
+ if _svg_element_tag(picture) == 'image':
+ if resolve_url_id(picture.get('clip-path', '')) is None:
+ return False
+ if owner_kind is None:
+ return True
+ shape_id = elem.get('data-pptx-shape-id')
+ return (
+ owner_kind == 'picture'
+ and shape_id is not None
+ and picture.get('data-pptx-object') == 'picture'
+ and picture.get('data-pptx-shape-id') == shape_id
+ )
+ if (
+ _svg_element_tag(picture) != 'svg'
+ or owner_kind != 'picture'
+ or picture.get('data-pptx-object') != 'picture'
+ or picture.get('viewBox') is None
+ or picture.get('preserveAspectRatio') != 'none'
+ ):
+ return False
+ shape_id = elem.get('data-pptx-shape-id')
if (
- _svg_element_tag(crop) != 'svg'
- or crop.get('data-pptx-object') != 'picture'
- or crop.get('viewBox') is None
- or crop.get('preserveAspectRatio') != 'none'
- or crop.get('filter') is not None
- or crop.get('data-pptx-shape-id') != elem.get('data-pptx-shape-id')
+ shape_id is None
+ or picture.get('data-pptx-shape-id') != shape_id
):
return False
- crop_children = list(crop)
+ crop_children = list(picture)
return (
len(crop_children) == 1
and _svg_element_tag(crop_children[0]) == 'image'