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(edit-native): import normAutofit font scale and theme minor fonts; checker admits an edit no wider than its slot's source text and refuses absolute-y rows in a semantic shape
hugohe3f4ab81fb9584
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 f2789c18..8fb3fdf4 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@@ -154,6 +154,7 @@ def convert_txbody()if not paragraphs or not _has_visible_text(paragraphs):return TextResult()+ _apply_norm_autofit(body_pr, paragraphs)# Insets + anchor + wraplins = _read_emu_attr(body_pr, "lIns", DEFAULT_INSETS_EMU["l"])@@ -281,6 +282,7 @@ def convert_vertical_txbody(strict=strict,diagnostic_sink=diagnostic_sink,)+ _apply_norm_autofit(body_pr, paragraphs)if body_pr is not None and body_pr.attrib.get("vert") == "eaVert":return _convert_east_asian_vertical(paragraphs,@@ -763,6 +765,33 @@ def _parse_paragraph(return para+def _apply_norm_autofit(+ body_pr: ET.Element | None,+ paragraphs: list[TextParagraph],+) -> None:+ """Scale runs by the stored shrink-on-overflow result PowerPoint renders with."""+ autofit = body_pr.find("a:normAutofit", NS) if body_pr is not None else None+ if autofit is None:+ return++ def fraction(attr: str, default: float) -> float:+ try:+ value = int(autofit.attrib.get(attr, "")) / 100000.0+ except ValueError:+ return default+ return value if 0.0 < value <= 1.0 else default++ font_scale = fraction("fontScale", 1.0)+ line_scale = 1.0 - fraction("lnSpcReduction", 0.0)+ if font_scale == 1.0 and line_scale == 1.0:+ return+ for para in paragraphs:+ para.empty_line_font_size_px *= font_scale+ para.line_height_ratio *= line_scale+ for run in para.runs:+ run.font_size_px *= font_scale++def _font_size_px(sources: tuple[ET.Element | None, ...],default_font_size_px: float,@@ -889,6 +918,9 @@ def _build_run(alt_lang=alt_lang,)+ # No typeface anywhere in the chain means the theme's minor font pair.+ latin_face = latin_face or theme_fonts.get("minorLatin") or None+ ea_face = ea_face or theme_fonts.get("minorEastAsia") or Nonefont_family = _build_font_stack(latin_face, ea_face, cs_face)hyperlink_href: str | None = Noneif rpr is not None and hyperlink_resolver is not None:diff --git a/skills/ppt-master/scripts/svg_quality/checker.py b/skills/ppt-master/scripts/svg_quality/checker.pyindex 25162db4..cd81e011 100644--- a/skills/ppt-master/scripts/svg_quality/checker.py+++ b/skills/ppt-master/scripts/svg_quality/checker.py@@ -1724,6 +1724,7 @@ class SVGQualityChecker:result,included_text_ids,unchanged_text_ids,+ baseline_root=baseline_root,)self._check_roundtrip_unsupported_table_edits(root,@@ -1779,9 +1780,31 @@ class SVGQualityChecker:) is not None:continuetry:- semantic_shape_text_component(shape, included_text_ids=included_text_ids)+ component = semantic_shape_text_component(+ shape, included_text_ids=included_text_ids,+ )except ValueError as exc:result['errors'].append(f"{_element_label(shape)}: {exc}")+ continue+ if (+ component is None+ or _classify_paragraph_block is None+ or not any(+ _local_name(child) == 'tspan'+ and any(child.get(name) for name in ('x', 'y', 'dy'))+ for child in component+ )+ or _classify_paragraph_block(+ component, preserve_line_breaks=True,+ ) is not None+ ):+ continue+ result['errors'].append(+ f"{_element_label(shape)}: multi-line semantic shape text must "+ "stay one paragraph block, which export otherwise splits into "+ "several text components; write the first line on <text x y> "+ "and each later line as <tspan x dy>, never an absolute tspan y"+ )@staticmethoddef _roundtrip_text_diff_ids(@@ -2144,6 +2167,7 @@ class SVGQualityChecker:result: Dict,included_text_ids: set[int],unchanged_text_ids: set[int],+ baseline_root: ET.Element | None = None,) -> None:"""Calibrate source text widths, then check edited owning frames."""helpers = (@@ -2221,6 +2245,7 @@ class SVGQualityChecker:max(positive_overflow_ratios, default=0.0),_ROUNDTRIP_TEXT_CALIBRATION_CAP,)+ source_slot_overflow = self._roundtrip_source_slot_overflow(baseline_root)result['info']['roundtrip_text_calibration'] = {'factor': calibration,'measured_unchanged': measured_unchanged,@@ -2280,6 +2305,12 @@ class SVGQualityChecker:)if corrected_horizontal_ratio <= 0:continue+ # The source text of this same slot already reached this far.+ if horizontal_ratio <= source_slot_overflow.get(+ self._roundtrip_frame_source_ref(text_element, parent_by_id),+ 0.0,+ ):+ continueleft, top, right, bottom = estimatedframe_left, frame_top, frame_right, frame_bottom = frameoverflow_detail = (@@ -2306,6 +2337,68 @@ class SVGQualityChecker:else:result['errors'].append(finding)+ @staticmethod+ def _roundtrip_frame_source_ref(+ text_element: ET.Element,+ parent_by_id: Dict[int, ET.Element],+ ) -> str | None:+ """Return the source ref of the object whose frame owns one text."""+ current: ET.Element | None = text_element+ while current is not None:+ if current.get('data-pptx-frame') is not None:+ return current.get('data-pptx-source-ref')+ current = parent_by_id.get(id(current))+ return None++ def _roundtrip_source_slot_overflow(+ self,+ baseline_root: ET.Element | None,+ ) -> Dict[str | None, float]:+ """Measure how far each imported slot's own source text overflows it."""+ if baseline_root is None:+ return {}+ try:+ font_sizes = _resolve_project_font_sizes(baseline_root)+ letter_spacings = _resolve_project_letter_spacings(+ baseline_root,+ font_sizes,+ )+ except ValueError:+ return {}+ parent_by_id = {+ id(child): parent+ for parent in baseline_root.iter()+ for child in list(parent)+ }+ overflow: Dict[str | None, float] = {}+ for text_element in baseline_root.iter(f'{{{SVG_NS}}}text'):+ source_ref = self._roundtrip_frame_source_ref(+ text_element,+ parent_by_id,+ )+ if source_ref is None:+ continue+ estimated = self._estimated_text_bounds(+ text_element,+ parent_by_id,+ font_sizes,+ letter_spacings,+ include_headroom=True,+ )+ _label, frame, _error, _inferred = self._roundtrip_text_frame(+ text_element,+ parent_by_id,+ )+ if estimated is None or frame is None:+ continue+ metrics = self._bounds_overflow_metrics(estimated, frame)+ if metrics is not None and metrics[1] > 0:+ overflow[source_ref] = max(+ overflow.get(source_ref, 0.0),+ metrics[1],+ )+ return overflow+@classmethoddef _roundtrip_text_frame(cls,diff --git a/skills/ppt-master/scripts/tests/test_dogfood_template_material_fixes.py b/skills/ppt-master/scripts/tests/test_dogfood_template_material_fixes.pynew file mode 100644index 00000000..1c55064a--- /dev/null+++ b/skills/ppt-master/scripts/tests/test_dogfood_template_material_fixes.py@@ -0,0 +1,81 @@+"""Regressions from the 2026-09-18 template-plus-new-material Edit Native run."""++from __future__ import annotations++import sys+import unittest+from pathlib import Path+from xml.etree import ElementTree as ET++SCRIPTS_DIR = Path(__file__).resolve().parents[1]+if str(SCRIPTS_DIR) not in sys.path:+ sys.path.insert(0, str(SCRIPTS_DIR))++from pptx_to_svg.emu_units import Xfrm # noqa: E402+from pptx_to_svg.txbody_to_svg import convert_txbody # noqa: E402+from svg_quality.checker import SVGQualityChecker # noqa: E402++A = "http://schemas.openxmlformats.org/drawingml/2006/main"+SVG = "http://www.w3.org/2000/svg"+++def _tx_body(body_pr: str, run_pr: str = '<a:rPr sz="6000"/>') -> ET.Element:+ return ET.fromstring(+ f'<p:txBody xmlns:a="{A}" '+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">'+ f'{body_pr}<a:p><a:r>{run_pr}<a:t>61%</a:t></a:r></a:p></p:txBody>'+ )+++def _convert(tx_body: ET.Element, theme_fonts: dict[str, str] | None = None) -> str:+ return convert_txbody(+ tx_body, Xfrm(x=0, y=0, w=400, h=200), None, theme_fonts=theme_fonts,+ ).svg+++class ImportedTextFidelityTests(unittest.TestCase):+ def test_norm_autofit_font_scale_reaches_the_svg_font_size(self) -> None:+ plain = _convert(_tx_body('<a:bodyPr wrap="none"/>'))+ shrunk = _convert(_tx_body(+ '<a:bodyPr wrap="none"><a:normAutofit fontScale="25000" '+ 'lnSpcReduction="20000"/></a:bodyPr>'+ ))+ self.assertIn('font-size="80"', plain)+ self.assertIn('font-size="20"', shrunk)++ def test_run_without_any_typeface_takes_the_theme_minor_pair(self) -> None:+ svg = _convert(+ _tx_body('<a:bodyPr/>'),+ {"minorLatin": "Arial", "minorEastAsia": "微软雅黑"},+ )+ self.assertIn('font-family="Arial, "微软雅黑", sans-serif"', svg)+++class SemanticShapeParagraphBlockTests(unittest.TestCase):+ def _errors(self, text: str) -> list[str]:+ root = ET.fromstring(+ f'<svg xmlns="{SVG}" viewBox="0 0 1280 720">'+ '<g id="s" data-pptx-semantic-object="shape" '+ f'data-pptx-frame="0 0 600 200">{text}</g></svg>'+ )+ result: dict = {"errors": [], "warnings": []}+ SVGQualityChecker._check_semantic_shape_text(root, result)+ return result["errors"]++ def test_absolute_y_rows_are_refused_before_export(self) -> None:+ errors = self._errors(+ '<text x="300" font-size="40"><tspan x="300" y="80">a</tspan>'+ '<tspan x="300" y="130">b</tspan></text>'+ )+ self.assertEqual(len(errors), 1)+ self.assertIn("<tspan x dy>", errors[0])++ def test_relative_dy_rows_pass(self) -> None:+ self.assertEqual(self._errors(+ '<text x="300" y="80" font-size="40">a'+ '<tspan x="300" dy="50">b</tspan></text>'+ ), [])+++if __name__ == "__main__":+ unittest.main()