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): improve imported slide visual fidelity" -m "PPTX template imports were losing or degrading several visual constructs that are valid PowerPoint output but were not fully represented in the reverse SVG pipeline.
hugohe390e7ec797847
diff --git a/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.pyindex 193b0ecd..48f79385 100644--- a/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py@@ -28,10 +28,18 @@ Strategy:from __future__ import annotationsimport base64+import hashlib+import ioimport mimetypesfrom dataclasses import dataclass, fieldfrom xml.etree import ElementTree as ET+try:+ from PIL import Image, ImageEnhance+except ImportError: # pragma: no cover - optional visual enhancement dependency+ Image = None+ ImageEnhance = None+from .emu_units import NS, Xfrm, fmt_numfrom .ooxml_loader import OoxmlPackage, PartRef@@ -79,6 +87,7 @@ def convert_blip_fill(return PictureResult()filename = pkg.media_filename(target)+ filename, img_bytes = _apply_blip_image_effects(filename, img_bytes, blip)href = _build_href(filename, img_bytes, media_subdir, embed_inline)# srcRect: l/t/r/b in 1/100000ths (so 50000 = 50%).@@ -165,6 +174,81 @@ def _parse_src_rect(elem: ET.Element | None) -> tuple[float, float, float, floatreturn vb_x, vb_y, vb_w, vb_h+def _apply_blip_image_effects(+ filename: str,+ img_bytes: bytes,+ blip: ET.Element,+) -> tuple[str, bytes]:+ """Bake supported DrawingML blip effects into extracted image bytes.++ Keeping the SVG as a plain <image> avoids introducing CSS filters that the+ downstream native PPTX converter cannot reliably map back to DrawingML.+ """+ lum = blip.find("a:lum", NS)+ if lum is None:+ return filename, img_bytes++ bright = _signed_pct_attr(lum, "bright")+ contrast = _signed_pct_attr(lum, "contrast")+ if bright is None and contrast is None:+ return filename, img_bytes+ if Image is None or ImageEnhance is None:+ return filename, img_bytes++ try:+ image = Image.open(io.BytesIO(img_bytes))+ output_format = image.format or _pil_format_from_filename(filename)+ if image.mode not in ("RGB", "RGBA"):+ image = image.convert("RGBA" if "A" in image.getbands() else "RGB")+ if bright is not None:+ image = ImageEnhance.Brightness(image).enhance(max(0.0, 1.0 + bright))+ if contrast is not None:+ image = ImageEnhance.Contrast(image).enhance(max(0.0, 1.0 + contrast))++ out = io.BytesIO()+ save_format = output_format or "PNG"+ save_kwargs = {"quality": 95} if save_format.upper() in {"JPEG", "JPG"} else {}+ image.save(out, format=save_format, **save_kwargs)+ effect_key = f"lum-{bright}-{contrast}".encode("ascii")+ digest = hashlib.sha1(effect_key).hexdigest()[:8]+ return _effect_filename(filename, digest, save_format), out.getvalue()+ except Exception:+ return filename, img_bytes+++def _signed_pct_attr(elem: ET.Element, name: str) -> float | None:+ val = elem.attrib.get(name)+ if val is None:+ return None+ try:+ return float(val) / 100000.0+ except ValueError:+ return None+++def _pil_format_from_filename(filename: str) -> str | None:+ ext = filename.rsplit(".", 1)[-1].lower() if "." in filename else ""+ if ext in {"jpg", "jpeg"}:+ return "JPEG"+ if ext == "png":+ return "PNG"+ if ext == "gif":+ return "GIF"+ if ext == "webp":+ return "WEBP"+ return None+++def _effect_filename(filename: str, digest: str, image_format: str) -> str:+ stem, sep, ext = filename.rpartition(".")+ if not sep:+ ext = (image_format or "png").lower()+ stem = filename+ if ext.lower() == "jpg":+ ext = "jpeg"+ return f"{stem}_fx_{digest}.{ext}"++def _pct_attr(elem: ET.Element, name: str) -> float:val = elem.attrib.get(name)if val is None:diff --git a/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.pyindex 44fe7deb..8f13ada5 100644--- a/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py@@ -137,6 +137,28 @@ def _round_rect(xfrm: Xfrm, sp_pr) -> GeomResult:)+def _round_2_diag_rect(xfrm: Xfrm, sp_pr) -> GeomResult:+ """Rectangle with two diagonal rounded corners.++ DrawingML's round2DiagRect rounds the top-left and bottom-right corners.+ SVG has no direct primitive for per-corner radii, so emit a native-friendly+ path with quadratic curves.+ """+ adj = _adj_value(sp_pr, "adj", default_pct=0.16667)+ r = min(adj * min(xfrm.w, xfrm.h), min(xfrm.w, xfrm.h) / 2.0)+ x, y, w, h = xfrm.x, xfrm.y, xfrm.w, xfrm.h+ d = (+ f"M {fmt_num(x + r)} {fmt_num(y)} "+ f"L {fmt_num(x + w)} {fmt_num(y)} "+ f"L {fmt_num(x + w)} {fmt_num(y + h - r)} "+ f"Q {fmt_num(x + w)} {fmt_num(y + h)} {fmt_num(x + w - r)} {fmt_num(y + h)} "+ f"L {fmt_num(x)} {fmt_num(y + h)} "+ f"L {fmt_num(x)} {fmt_num(y + r)} "+ f"Q {fmt_num(x)} {fmt_num(y)} {fmt_num(x + r)} {fmt_num(y)} Z"+ )+ return GeomResult(tag="path", path_d=d)++def _ellipse(xfrm: Xfrm, _sp_pr) -> GeomResult:cx = xfrm.x + xfrm.w / 2.0cy = xfrm.y + xfrm.h / 2.0@@ -361,6 +383,27 @@ def _up_arrow(xfrm: Xfrm, sp_pr) -> GeomResult:])+# ---------- Decorative shapes ----------++def _plaque(xfrm: Xfrm, sp_pr) -> GeomResult:+ """Approximate DrawingML plaque with concave curved corner cuts."""+ adj = _adj_value(sp_pr, "adj", default_pct=0.16667)+ r = min(adj * min(xfrm.w, xfrm.h), min(xfrm.w, xfrm.h) / 2.0)+ x, y, w, h = xfrm.x, xfrm.y, xfrm.w, xfrm.h+ d = (+ f"M {fmt_num(x + r)} {fmt_num(y)} "+ f"L {fmt_num(x + w - r)} {fmt_num(y)} "+ f"Q {fmt_num(x + w - r)} {fmt_num(y + r)} {fmt_num(x + w)} {fmt_num(y + r)} "+ f"L {fmt_num(x + w)} {fmt_num(y + h - r)} "+ f"Q {fmt_num(x + w - r)} {fmt_num(y + h - r)} {fmt_num(x + w - r)} {fmt_num(y + h)} "+ f"L {fmt_num(x + r)} {fmt_num(y + h)} "+ f"Q {fmt_num(x + r)} {fmt_num(y + h - r)} {fmt_num(x)} {fmt_num(y + h - r)} "+ f"L {fmt_num(x)} {fmt_num(y + r)} "+ f"Q {fmt_num(x + r)} {fmt_num(y + r)} {fmt_num(x + r)} {fmt_num(y)} Z"+ )+ return GeomResult(tag="path", path_d=d)++# ---------- Pie / chord / arc (path-based) ----------def _pie(xfrm: Xfrm, sp_pr) -> GeomResult:@@ -418,6 +461,7 @@ _PRESET_HANDLERS = {# Core 4 (svg_to_pptx round-trip)"rect": _rect,"roundRect": _round_rect,+ "round2DiagRect": _round_2_diag_rect,"ellipse": _ellipse,"line": _line,@@ -452,6 +496,9 @@ _PRESET_HANDLERS = {"downArrow": _down_arrow,"upArrow": _up_arrow,+ # Decorative+ "plaque": _plaque,+# Pie / chord / arc"pie": _pie,"chord": _chord,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.pyindex 12fca1cc..3a98a298 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@@ -28,7 +28,7 @@ from xml.etree import ElementTree as ETfrom .color_resolver import ColorPalette, find_color_elem, resolve_colorfrom .custgeom_to_svg import convert_custom_geomfrom .effect_to_svg import convert_effects-from .emu_units import NS, fmt_num+from .emu_units import NS, Xfrm, fmt_numfrom .fill_to_svg import resolve_fillfrom .ln_to_svg import resolve_strokefrom .ooxml_loader import OoxmlPackage, PartRef, SlideRef@@ -405,6 +405,8 @@ def _build_geometry_xml(node: ShapeNode, sp_pr: ET.Element | None,def _geom_to_svg(geom: GeomResult, attrs_xml: str = "") -> str:"""Serialize a resolved geometry with optional SVG attributes."""+ if not attrs_xml:+ attrs_xml = _attrs_to_xml(geom.attrs)if geom.tag == "path":return f'<path d="{geom.path_d}"{attrs_xml}/>'if geom.tag in ("polygon", "polyline"):@@ -618,6 +620,10 @@ def _emit_background(slide: SlideRef, ctx: AssemblyContext,if bg_pr is None:continue+ bg_image = _emit_background_image(bg_pr, part, ctx, w, h)+ if bg_image:+ return bg_image+fill = resolve_fill(bg_pr, ctx.palette,id_prefix="bg", id_seq=ctx.grad_seq,@@ -658,6 +664,10 @@ def _emit_part_background(slide: SlideRef, ctx: AssemblyContext,if bg_pr is None:return ""+ bg_image = _emit_background_image(bg_pr, slide.part, ctx, w, h)+ if bg_image:+ return bg_image+fill = resolve_fill(bg_pr, ctx.palette,id_prefix="bg", id_seq=ctx.grad_seq,@@ -671,6 +681,31 @@ def _emit_part_background(slide: SlideRef, ctx: AssemblyContext,f"{attrs_xml}/>")+def _emit_background_image(+ bg_pr: ET.Element,+ source_part: PartRef,+ ctx: AssemblyContext,+ w: float,+ h: float,+) -> str:+ """Render a slide/layout/master background image fill as a full-canvas image."""+ blip_fill = bg_pr.find("a:blipFill", NS)+ if blip_fill is None:+ return ""++ result = convert_blip_fill(+ blip_fill,+ Xfrm(0.0, 0.0, w, h),+ source_part,+ ctx.pkg,+ media_subdir=ctx.media_subdir,+ embed_inline=ctx.embed_images,+ )+ if result.media:+ ctx.media.update(result.media)+ return result.svg++def _theme_background_fill(slide: SlideRef,ctx: AssemblyContext,diff --git a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.pyindex bcb2f10e..fc050122 100644--- a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py@@ -143,11 +143,18 @@ def convert_txbody(else:cursor_y = inner_y+ bottom_y = inner_y + inner_htext_blocks: list[str] = []for para, lines, height in zip(paragraphs, para_lines, para_heights):cursor_y += para.space_before_px- text_blocks.append(_emit_paragraph(para, lines, inner_x, inner_w, cursor_y))+ visible_lines = _clip_lines_to_bottom(para, lines, cursor_y, bottom_y)+ if visible_lines:+ text_blocks.append(+ _emit_paragraph(para, visible_lines, inner_x, inner_w, cursor_y)+ )cursor_y += height + para.space_after_px+ if cursor_y >= bottom_y:+ breakreturn TextResult(svg="\n".join(text_blocks))@@ -207,18 +214,35 @@ def convert_vertical_txbody(total_h = sum(advances)top_y = box_y + max(0.0, (box_h - total_h) / 2.0)- text_blocks: list[str] = []+ bottom_y = box_y + box_h+ spans: list[str] = []cursor_y = top_y+ first_run: TextRun | None = None+ first_baseline: float | None = None+ previous_baseline: float | None = Nonefor (char, run), advance in zip(glyphs, advances):+ if cursor_y + advance > bottom_y:+ breakbaseline_y = cursor_y + run.font_size_px * 0.85- attrs = _text_base_attrs(run, center_x, baseline_y, "middle")tspan_attrs = _run_tspan_attrs(run)- text_blocks.append(- f"<text{attrs}><tspan{tspan_attrs}>{_xml_escape(char)}</tspan></text>"- )+ if first_run is None:+ first_run = run+ first_baseline = baseline_y+ spans.append(f"<tspan{tspan_attrs}>{_xml_escape(char)}</tspan>")+ else:+ dy = baseline_y - (previous_baseline or baseline_y)+ spans.append(+ f'<tspan x="{fmt_num(center_x)}" dy="{fmt_num(dy)}"'+ f"{tspan_attrs}>{_xml_escape(char)}</tspan>"+ )+ previous_baseline = baseline_ycursor_y += advance- return TextResult(svg="\n".join(text_blocks))+ if first_run is None or first_baseline is None:+ return TextResult()++ attrs = _text_base_attrs(first_run, center_x, first_baseline, "middle")+ return TextResult(svg=f"<text{attrs}>{''.join(spans)}</text>")def _rotated_bbox(xfrm: Xfrm) -> tuple[float, float, float, float]:@@ -687,11 +711,33 @@ def _paragraph_height_from_lines(p: TextParagraph,return DEFAULT_FONT_SIZE_PX * p.line_height_ratioheight = 0.0for line in lines:- max_font = max((r.font_size_px for r in line), default=DEFAULT_FONT_SIZE_PX)- height += max_font * p.line_height_ratio+ height += _line_height(p, line)return height+def _line_height(p: TextParagraph, line: list[TextRun]) -> float:+ max_font = max((r.font_size_px for r in line), default=DEFAULT_FONT_SIZE_PX)+ return max_font * p.line_height_ratio+++def _clip_lines_to_bottom(+ para: TextParagraph,+ lines: list[list[TextRun]],+ top_y: float,+ bottom_y: float,+) -> list[list[TextRun]]:+ """Return the leading display lines whose line boxes fit in the text frame."""+ visible: list[list[TextRun]] = []+ cursor_y = top_y+ for line in lines:+ line_h = _line_height(para, line)+ if cursor_y + line_h > bottom_y:+ break+ visible.append(line)+ cursor_y += line_h+ return visible++def _paragraph_height(p: TextParagraph) -> float:"""Legacy helper kept for callers that don't pre-wrap (currently unused)."""lines = 1