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

feat(gradients): preserve radial point focus

hugohe3fb5adabf202d
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 6469e287..81152543 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
@@ -260,11 +260,41 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
elif rad is not None:
_validate_path_gradient_structure(rad)
_validate_path_gradient_type(rad)
- _validate_path_gradient_focus(rad)
+ focus = _validate_path_gradient_focus(rad)
+ focus_attrs = ""
+ if focus is not None:
+ focus_x = focus["l"]
+ focus_y = focus["t"]
+ point_focus = (
+ focus_x + focus["r"] == Decimal(1)
+ and focus_y + focus["b"] == Decimal(1)
+ and Decimal(0) <= focus_x <= Decimal(1)
+ and Decimal(0) <= focus_y <= Decimal(1)
+ )
+ if (
+ point_focus
+ and (
+ focus_x != Decimal("0.5")
+ or focus_y != Decimal("0.5")
+ )
+ ):
+ focus_attrs = (
+ f' fx="{format_ooxml_unit_ratio(float(focus_x))}"'
+ f' fy="{format_ooxml_unit_ratio(float(focus_y))}"'
+ )
+ elif not point_focus and palette is not None:
+ palette._diagnose(
+ "path-gradient-focus-normalized",
+ "DrawingML path gradient focus is not one point within "
+ "the SVG 0..1 focus range",
+ "center the radial gradient while preserving its stops",
+ )
# Treat as radial regardless of path="circle" / "rect" / "shape" — SVG
- # only has circle/ellipse, and path="circle" maps to fillToRect=center.
+ # only has circle/ellipse. Point-style fillToRect retains its focus;
+ # the outer center and radius remain normalized.
defs_xml = (
- f'<radialGradient id="{grad_id}" cx="0.5" cy="0.5" r="0.5">'
+ f'<radialGradient id="{grad_id}" cx="0.5" cy="0.5" '
+ f'r="0.5"{focus_attrs}>'
+ "".join(stops_xml)
+ "</radialGradient>"
)
@@ -459,18 +489,25 @@ def _validate_gradient_tile_rect(gradient: ET.Element) -> None:
)
-def _validate_path_gradient_focus(path: ET.Element) -> None:
- """Validate the focus rectangle normalized by the radial approximation."""
+def _validate_path_gradient_focus(
+ path: ET.Element,
+) -> dict[str, Decimal] | None:
+ """Validate and return one path-gradient focus rectangle."""
focus_rects = path.findall("a:fillToRect", NS)
if len(focus_rects) > 1:
raise ValueError(
"DrawingML path gradient must contain at most one fillToRect"
)
- if focus_rects:
- _relative_rect_values(
- focus_rects[0],
- label="path gradient fillToRect",
- )
+ if not focus_rects:
+ return None
+ values = _relative_rect_values(
+ focus_rects[0],
+ label="path gradient fillToRect",
+ )
+ return {
+ edge: values.get(edge, Decimal(0))
+ for edge in ("l", "t", "r", "b")
+ }
def _relative_rect_values(
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
index 7a44fba1..bf2aeb76 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
@@ -119,10 +119,20 @@ def build_gradient_fill(
</a:gradFill>'''
elif tag == 'radialGradient':
+ focus_x = parse_project_gradient_ratio(
+ grad_elem.get('fx', grad_elem.get('cx', '0.5'))
+ )
+ focus_y = parse_project_gradient_ratio(
+ grad_elem.get('fy', grad_elem.get('cy', '0.5'))
+ )
+ focus_l = quantize_ooxml_unit_ratio(focus_x)
+ focus_t = quantize_ooxml_unit_ratio(focus_y)
+ focus_r = 100000 - focus_l
+ focus_b = 100000 - focus_t
return f'''<a:gradFill>
<a:gsLst>{gs_list}</a:gsLst>
<a:path path="circle">
-<a:fillToRect l="50000" t="50000" r="50000" b="50000"/>
+<a:fillToRect l="{focus_l}" t="{focus_t}" r="{focus_r}" b="{focus_b}"/>
</a:path>
</a:gradFill>'''