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): preserve OOXML alpha precision
hugohe3c12f19c95d67
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.mdindex 3b848ace..2bb175ca 100644--- a/skills/ppt-master/references/shared-standards.md+++ b/skills/ppt-master/references/shared-standards.md@@ -995,6 +995,11 @@ fidelity.| Gradient stroke | §6.3; re-import may flatten to first stop || `marker-start` / `marker-end` | §1.1 native line end; type `Native-normalized`, size `Approximate` (`sm/med/lg`) |+PPTX import formats normalized paint and text alpha with five decimal places,+matching DrawingML's 1/100000 target precision. The smallest positive source+alpha therefore remains non-zero and quantizes back instead of becoming fully+transparent.+PPTX import accepts `a:ln@w` only as an integer DrawingML `ST_LineWidth` valuefrom `0` through `20116800` EMU. Malformed, negative, or oversized source widthsstop import instead of being dropped and replaced by a default SVG line width.diff --git a/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.pyindex 4ea12936..ef53dd40 100644--- a/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py@@ -16,7 +16,7 @@ from pptx_effects import unsupported_effect_metadatafrom pptx_shapes.formula import OOXML_COORDINATE_MAXfrom .color_resolver import COLOR_TAGS, ColorPalette, resolve_color-from .emu_units import NS, emu_to_px, fmt_num+from .emu_units import NS, emu_to_px, fmt_num, format_ooxml_alpha_OOXML_INTEGER_RE = re.compile(r"[+-]?\d+")@@ -347,7 +347,8 @@ def _outer_shadow(return (f'<feDropShadow dx="{dx_token}" dy="{dy_token}" 'f'stdDeviation="{fmt_num(std, 8)}" '- f'flood-color="{color}" flood-opacity="{fmt_num(alpha, 5)}"/>'+ f'flood-color="{color}" '+ f'flood-opacity="{format_ooxml_alpha(alpha)}"/>')@@ -360,7 +361,8 @@ def _glow(elem: ET.Element, palette: ColorPalette | None) -> str:std = radreturn (f'<feGaussianBlur in="SourceAlpha" stdDeviation="{fmt_num(std, 8)}" result="blurred"/>'- f'<feFlood flood-color="{color}" flood-opacity="{fmt_num(alpha, 5)}" result="flood"/>'+ f'<feFlood flood-color="{color}" '+ f'flood-opacity="{format_ooxml_alpha(alpha)}" result="flood"/>'f'<feComposite in="flood" in2="blurred" operator="in" result="glow"/>'f'<feMerge><feMergeNode in="glow"/><feMergeNode in="SourceGraphic"/></feMerge>')diff --git a/skills/ppt-master/scripts/pptx_to_svg/emu_units.py b/skills/ppt-master/scripts/pptx_to_svg/emu_units.pyindex d5c5c681..45478d39 100644--- a/skills/ppt-master/scripts/pptx_to_svg/emu_units.py+++ b/skills/ppt-master/scripts/pptx_to_svg/emu_units.py@@ -238,6 +238,11 @@ def _fmt(val: float, ndigits: int = 2) -> str:fmt_num = _fmt+def format_ooxml_alpha(alpha: float) -> str:+ """Format a normalized alpha without losing 1/100000 OOXML precision."""+ return _fmt(alpha, 5)++def format_canvas_px_from_emu(emu: int) -> str:"""Format a slide-size coordinate with enough precision to recover EMU."""with localcontext() as context: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.pyindex 317219d4..1234c670 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@@ -17,7 +17,7 @@ from dataclasses import dataclass, fieldfrom xml.etree import ElementTree as ETfrom .color_resolver import ColorPalette, find_color_elem, resolve_color-from .emu_units import NS, fmt_num, percent_to_ratio+from .emu_units import NS, fmt_num, format_ooxml_alpha, percent_to_ratio@dataclass@@ -100,7 +100,7 @@ def _resolve_solid_fill(elem: ET.Element, palette: ColorPalette | None,return FillResult.inherit()attrs: dict[str, str] = {"fill": hex_}if alpha < 1.0:- attrs["fill-opacity"] = fmt_num(alpha, 4)+ attrs["fill-opacity"] = format_ooxml_alpha(alpha)return FillResult(attrs=attrs)@@ -123,7 +123,11 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,hex_, alpha = resolve_color(color_elem, palette, placeholder_hex=placeholder_hex)if hex_ is None:continue- opacity_attr = f' stop-opacity="{fmt_num(alpha, 4)}"' if alpha < 1.0 else ""+ opacity_attr = (+ f' stop-opacity="{format_ooxml_alpha(alpha)}"'+ if alpha < 1.0+ else ""+ )stops_xml.append(f'<stop offset="{fmt_num(pos_pct, 4)}" stop-color="{hex_}"{opacity_attr}/>')@@ -199,7 +203,7 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,# least carries the right tone. Round-trip will lose the texture.attrs: dict[str, str] = {"fill": fg_hex}if fg_alpha < 1.0:- attrs["fill-opacity"] = fmt_num(fg_alpha, 4)+ attrs["fill-opacity"] = format_ooxml_alpha(fg_alpha)return FillResult(attrs=attrs)tile_w, tile_h, fg_svg = geom@@ -210,7 +214,7 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,bg_rect = ""if bg_hex is not None:bg_opacity = (- f' fill-opacity="{fmt_num(bg_alpha, 4)}"'+ f' fill-opacity="{format_ooxml_alpha(bg_alpha)}"'if bg_alpha < 1.0 else "")bg_rect = (@@ -243,11 +247,11 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,def _pattern_foreground(prst: str, fg: str,fg_alpha: float) -> tuple[int, int, str] | None:stroke_op = (- f' stroke-opacity="{fmt_num(fg_alpha, 4)}"'+ f' stroke-opacity="{format_ooxml_alpha(fg_alpha)}"'if fg_alpha < 1.0 else "")fill_op = (- f' fill-opacity="{fmt_num(fg_alpha, 4)}"'+ f' fill-opacity="{format_ooxml_alpha(fg_alpha)}"'if fg_alpha < 1.0 else "")diff --git a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.pyindex 25efde2a..33f5eea3 100644--- a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py@@ -15,7 +15,7 @@ from xml.etree import ElementTree as ETfrom pptx_shapes.formula import validate_ooxml_line_widthfrom .color_resolver import ColorPalette, find_color_elem, resolve_color-from .emu_units import NS, emu_to_px, fmt_num+from .emu_units import NS, emu_to_px, fmt_num, format_ooxml_alpha@dataclass@@ -134,7 +134,7 @@ def resolve_stroke(raise ValueError("DrawingML solid line color cannot be resolved")attrs["stroke"] = hex_if alpha < 1.0:- attrs["stroke-opacity"] = fmt_num(alpha, 4)+ attrs["stroke-opacity"] = format_ooxml_alpha(alpha)elif paint_name == "gradFill":# Approximate gradient stroke as the first stop color (SVG supports# gradient strokes via fill="url()" but it adds a lot of plumbing;@@ -150,7 +150,7 @@ def resolve_stroke()attrs["stroke"] = hex_if alpha < 1.0:- attrs["stroke-opacity"] = fmt_num(alpha, 4)+ attrs["stroke-opacity"] = format_ooxml_alpha(alpha)# Dash patternpreset_tag = f"{{{NS['a']}}}prstDash"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 b3ba9038..5d9c27b3 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@@ -44,7 +44,7 @@ except ImportError: # pragma: no cover - optional visual enhancement dependencyImage = NoneImageEnhance = None-from .emu_units import NS, Xfrm, fmt_num+from .emu_units import NS, Xfrm, fmt_num, format_ooxml_alphafrom .ooxml_loader import OoxmlPackage, PartRef@@ -182,7 +182,7 @@ def _blip_opacity_attr(blip: ET.Element) -> str:return ""if opacity >= 1.0:return ""- return f' opacity="{fmt_num(opacity, 5)}"'+ return f' opacity="{format_ooxml_alpha(opacity)}"'_OFFICE_VECTOR_EXTS = {".emf", ".wmf"}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 9181c682..678ecf9a 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@@ -27,7 +27,8 @@ from xml.etree import ElementTree as ETfrom .color_resolver import ColorPalette, find_color_elem, resolve_colorfrom .emu_units import (- NS, Xfrm, fmt_num, emu_to_px, hundredths_pt_to_px,+ NS, Xfrm, fmt_num, emu_to_px, format_ooxml_alpha,+ hundredths_pt_to_px,)from .fill_to_svg import resolve_fill@@ -1152,7 +1153,9 @@ def _text_base_attrs(run: TextRun | None, x: float, y: float,parts.append(f'font-size="{fmt_num(run.font_size_px)}"')parts.append(f'fill="{run.fill}"')if run.fill_opacity < 1.0:- parts.append(f'fill-opacity="{fmt_num(run.fill_opacity, 4)}"')+ parts.append(+ f'fill-opacity="{format_ooxml_alpha(run.fill_opacity)}"'+ )if run.bold:parts.append('font-weight="bold"')if run.italic:@@ -1180,7 +1183,9 @@ def _run_tspan_attrs(run: TextRun) -> str:f'font-size="{fmt_num(run.font_size_px)}"',]if run.fill_opacity < 1.0:- parts.append(f'fill-opacity="{fmt_num(run.fill_opacity, 4)}"')+ parts.append(+ f'fill-opacity="{format_ooxml_alpha(run.fill_opacity)}"'+ )if run.bold:parts.append('font-weight="bold"')if run.italic:diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.pyindex 1af583aa..673e0d38 100644--- a/skills/ppt-master/scripts/test_svg_quality_checker.py+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py@@ -39,7 +39,7 @@ from pptx_to_svg.preset_authoring import (render_preset_shape_fragment,validate_authored_preset_tree,)-from pptx_to_svg.emu_units import Xfrm+from pptx_to_svg.emu_units import Xfrm, format_ooxml_alphafrom pptx_to_svg.effect_to_svg import (convert_effects,unsupported_target_effect_metadata,@@ -64,7 +64,7 @@ from svg_to_pptx.drawingml.converter import (convert_svg_to_slide_shapes,)from svg_to_pptx.drawingml.context import ConvertContext-from svg_to_pptx.drawingml.styles import build_stroke_xml+from svg_to_pptx.drawingml.styles import build_stroke_xml, get_stroke_opacityfrom svg_to_pptx.pptx_package.builder import create_pptx_with_native_svgfrom svg_to_pptx.pptx_package.dimensions import (CANVAS_FORMATS as PACKAGE_CANVAS_FORMATS,@@ -2737,6 +2737,33 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):stroke_xml = build_stroke_xml(line, ConvertContext())self.assertIn('<a:ln w="1">', stroke_xml)+ def test_minimum_positive_native_alpha_round_trips(self):+ self.assertEqual(format_ooxml_alpha(0.00001), '0.00001')+ self.assertEqual(format_ooxml_alpha(0.99999), '0.99999')+ sp_pr = ET.fromstring('''+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">+ <a:ln>+ <a:solidFill>+ <a:srgbClr val="112233"><a:alpha val="1"/></a:srgbClr>+ </a:solidFill>+ </a:ln>+</p:spPr>''')+ stroke = resolve_stroke(sp_pr, None)+ opacity = stroke.attrs['stroke-opacity']+ self.assertEqual(opacity, '0.00001')+ line = ET.fromstring(+ '<line xmlns="http://www.w3.org/2000/svg" '+ f'stroke="#112233" stroke-opacity="{opacity}"/>'+ )+ context = ConvertContext()+ stroke_xml = build_stroke_xml(+ line,+ context,+ get_stroke_opacity(line, context),+ )+ self.assertIn('<a:alpha val="1"/>', stroke_xml)+def test_compound_native_line_is_rejected_on_import(self):for compound in ('dbl', 'thickThin', 'thinThick', 'tri'):with self.subTest(compound=compound):