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(svg_to_pptx): elliptical-corner rect via custGeom
hugohe344390346a240
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.pyindex 4b097ea6..1a71c963 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py@@ -59,6 +59,105 @@ def _wrap_shape(# rect# ---------------------------------------------------------------------------+# Cubic-Bézier control distance for approximating a quarter circle / ellipse.+# Distance from corner to control point along the tangent, expressed as a+# fraction of the radius. Standard "magic number" for a 90° arc (max error+# ~0.027% of the radius).+_BEZIER_QUARTER_K = 0.5522847498+++def _build_round_rect_custgeom(w: float, h: float, rx: float, ry: float) -> str:+ """Build a DrawingML ``custGeom`` for a rectangle with elliptical corners.++ Used when ``<rect>`` has rx ≠ ry, which DrawingML's preset ``roundRect``+ cannot express (the preset takes a single ``adj`` shared by all four+ corners and is implicitly symmetric). Each 90° elliptical arc is+ approximated by one cubic Bézier — within 0.03% of the true ellipse, far+ below any visible threshold at slide resolution.++ Trade-off vs. the symmetric ``prstGeom roundRect`` path: this geometry+ is custom, so PowerPoint's yellow corner-radius handle is gone and the+ shape can no longer be retuned in-place. That matches the underlying+ reality — rx ≠ ry has no single "radius" to drag — and remains far+ better than the previous behaviour (silently dropping all corners and+ rendering a hard rectangle).++ Args:+ w, h: Pixel dimensions of the rectangle (post ctx-scale).+ rx, ry: Pixel corner radii along x and y. Will be clamped to half+ of w / h respectively per the SVG spec.++ Returns:+ A complete ``<a:custGeom>...</a:custGeom>`` XML string. Coordinates+ are emitted in EMU within a path-local coordinate system whose+ ``w`` / ``h`` equal the rectangle's pixel-converted dimensions.+ """+ # Clamp radii (SVG spec): rx > w/2 collapses to a half-circle end.+ rx = min(max(rx, 0.0), w / 2)+ ry = min(max(ry, 0.0), h / 2)++ width_emu = px_to_emu(w)+ height_emu = px_to_emu(h)+ rx_emu = px_to_emu(rx)+ ry_emu = px_to_emu(ry)++ cx_off = int(round(rx_emu * _BEZIER_QUARTER_K))+ cy_off = int(round(ry_emu * _BEZIER_QUARTER_K))++ def pt(x: int, y: int) -> str:+ return f'<a:pt x="{x}" y="{y}"/>'++ def cubic(c1: tuple[int, int], c2: tuple[int, int], end: tuple[int, int]) -> str:+ return (+ f'<a:cubicBezTo>{pt(*c1)}{pt(*c2)}{pt(*end)}</a:cubicBezTo>'+ )++ # Path traversed clockwise, starting just past the top-left corner.+ parts = [+ f'<a:moveTo>{pt(rx_emu, 0)}</a:moveTo>',+ f'<a:lnTo>{pt(width_emu - rx_emu, 0)}</a:lnTo>',+ # Top-right corner: (W-Rx, 0) → (W, Ry)+ cubic(+ (width_emu - rx_emu + cx_off, 0),+ (width_emu, ry_emu - cy_off),+ (width_emu, ry_emu),+ ),+ f'<a:lnTo>{pt(width_emu, height_emu - ry_emu)}</a:lnTo>',+ # Bottom-right corner: (W, H-Ry) → (W-Rx, H)+ cubic(+ (width_emu, height_emu - ry_emu + cy_off),+ (width_emu - rx_emu + cx_off, height_emu),+ (width_emu - rx_emu, height_emu),+ ),+ f'<a:lnTo>{pt(rx_emu, height_emu)}</a:lnTo>',+ # Bottom-left corner: (Rx, H) → (0, H-Ry)+ cubic(+ (rx_emu - cx_off, height_emu),+ (0, height_emu - ry_emu + cy_off),+ (0, height_emu - ry_emu),+ ),+ f'<a:lnTo>{pt(0, ry_emu)}</a:lnTo>',+ # Top-left corner: (0, Ry) → (Rx, 0)+ cubic(+ (0, ry_emu - cy_off),+ (rx_emu - cx_off, 0),+ (rx_emu, 0),+ ),+ '<a:close/>',+ ]++ path_xml = '\n'.join(parts)+ return (+ '<a:custGeom>'+ '<a:avLst/><a:gdLst/><a:ahLst/><a:cxnLst/>'+ '<a:rect l="l" t="t" r="r" b="b"/>'+ f'<a:pathLst><a:path w="{width_emu}" h="{height_emu}">'+ f'\n{path_xml}\n'+ '</a:path></a:pathLst>'+ '</a:custGeom>'+ )++def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <rect> to DrawingML shape.@@ -109,9 +208,10 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:rot = int(float(r_match.group(1)) * ANGLE_UNIT)if rx > 0 and abs(rx - ry) < 0.5:- # Native rounded-rect: adj is the corner radius as a fraction of the- # shorter side, in 1/1000-percent units, capped at 50000 (= radius- # equals half the shorter side, i.e. capsule end).+ # Symmetric corners → native PowerPoint rounded rectangle. adj is+ # the corner radius as a fraction of the shorter side, in 1/1000-+ # percent units, capped at 50000 (= radius equals half the shorter+ # side, i.e. capsule end).short_side = min(w, h)radius = min(rx, short_side / 2)adj = max(0, min(50000, int(round(radius / short_side * 100000))))@@ -120,6 +220,14 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:f'<a:avLst><a:gd name="adj" fmla="val {adj}"/></a:avLst>''</a:prstGeom>')+ elif rx > 0 or ry > 0:+ # Asymmetric corners (rx != ry) → DrawingML has no preset for+ # elliptical-corner rectangles, so emit a custGeom with one cubic+ # Bézier per 90° arc. We lose the prstGeom roundRect adjustment+ # handle, but symmetric and asymmetric cases now both render with+ # rounded corners instead of one of them silently flattening to+ # a hard rectangle.+ geom = _build_round_rect_custgeom(w, h, rx, ry)else:geom = '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'