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): keep overflowing text vertically anchored
hugohe3d54247565d5b
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 4694513a..686b3d0c 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@@ -206,10 +206,15 @@ def convert_txbody(space_after,))+ anchor_space = inner_h - total_h+ # Overflow stays anchored: centered text grows both ways, bottom text up.+ # Explicit clipping keeps the leading lines inside the frame instead.+ if clip_vertical:+ anchor_space = max(0.0, anchor_space)if anchor == "ctr":- cursor_y = inner_y + max(0.0, (inner_h - total_h) / 2.0)+ cursor_y = inner_y + anchor_space / 2.0elif anchor == "b":- cursor_y = inner_y + max(0.0, inner_h - total_h)+ cursor_y = inner_y + anchor_spaceelse:cursor_y = inner_ydiff --git a/skills/ppt-master/scripts/tests/test_text_overflow_import.py b/skills/ppt-master/scripts/tests/test_text_overflow_import.pyindex 786667f7..4eb1fd74 100644--- a/skills/ppt-master/scripts/tests/test_text_overflow_import.py+++ b/skills/ppt-master/scripts/tests/test_text_overflow_import.py@@ -44,6 +44,9 @@ def _text_body(*,spacing_percent: int = 100000,paragraphs: bool = False,+ anchor: str = 't',+ top_inset_px: int = 0,+ bottom_inset_px: int = 0,) -> ET.Element:runs = ['<a:r><a:rPr sz="2400"><a:latin typeface="Arial"/>'@@ -61,7 +64,8 @@ def _text_body(overflow_attribute = f' vertOverflow="{overflow}"' if overflow is not None else ''return ET.fromstring(f'<p:txBody xmlns:p="{P}" xmlns:a="{A}">'- '<a:bodyPr anchor="t" wrap="none" lIns="0" tIns="0" rIns="0" bIns="0"'+ f'<a:bodyPr anchor="{anchor}" wrap="none" lIns="0" '+ f'tIns="{top_inset_px * 9525}" rIns="0" bIns="{bottom_inset_px * 9525}"'f'{overflow_attribute}/><a:lstStyle/>{content}</p:txBody>')@@ -75,10 +79,39 @@ def _visible_text(root: ET.Element) -> str:class TextOverflowImportTests(unittest.TestCase):- def _import(self, body: ET.Element) -> ET.Element:- result = convert_txbody(body, Xfrm(x=80, y=100, w=600, h=32), None)+ def _import(self, body: ET.Element, *, height: float = 32) -> ET.Element:+ result = convert_txbody(body, Xfrm(x=80, y=100, w=600, h=height), None)return _svg_root(result.svg)+ def _assert_anchor_shift(+ self,+ mode: str | None,+ anchor: str,+ paragraphs: bool,+ expected_shift: float,+ *,+ height: float = 32,+ top_inset_px: int = 0,+ bottom_inset_px: int = 0,+ ) -> None:+ options = {+ 'paragraphs': paragraphs,+ 'top_inset_px': top_inset_px,+ 'bottom_inset_px': bottom_inset_px,+ }+ top = self._import(_text_body(mode, **options), height=height)+ anchored = self._import(_text_body(mode, anchor=anchor, **options), height=height)+ self.assertEqual(_visible_text(anchored), 'FirstSecondThird')+ top_texts = top.findall('s:text', NS)+ anchored_texts = anchored.findall('s:text', NS)+ self.assertEqual(len(anchored_texts), len(top_texts))+ for original, shifted in zip(top_texts, anchored_texts):+ self.assertAlmostEqual(float(shifted.get('y')) - float(original.get('y')), expected_shift)+ self.assertEqual(+ [span.get('dy') for span in anchored.findall('.//s:tspan', NS)],+ [span.get('dy') for span in top.findall('.//s:tspan', NS)],+ )+def test_default_and_explicit_overflow_keep_all_soft_break_lines(self) -> None:for mode in (None, 'overflow'):for percent, advance in ((100000, 38.4), (150000, 57.6)):@@ -107,13 +140,46 @@ class TextOverflowImportTests(unittest.TestCase):for mode in ('clip', 'ellipsis'):for paragraphs in (False, True):for percent in (100000, 150000):- with self.subTest(mode=mode, paragraphs=paragraphs, percent=percent):- imported = self._import(_text_body(- mode, spacing_percent=percent, paragraphs=paragraphs,- ))- # Ellipsis glyph synthesis is outside this importer fix.- self.assertEqual(_visible_text(imported), 'First')- self.assertEqual(len(imported.findall('s:text', NS)), 1)+ top = self._import(_text_body(+ mode, spacing_percent=percent, paragraphs=paragraphs,+ ))+ top_baseline = float(top.find('s:text', NS).get('y'))+ for anchor in ('t', 'ctr', 'b'):+ with self.subTest(mode=mode, paragraphs=paragraphs, percent=percent, anchor=anchor):+ imported = self._import(_text_body(+ mode, spacing_percent=percent, paragraphs=paragraphs, anchor=anchor,+ ))+ # Ellipsis glyph synthesis is outside this importer fix.+ self.assertEqual(_visible_text(imported), 'First')+ texts = imported.findall('s:text', NS)+ self.assertEqual(len(texts), 1)+ self.assertEqual(float(texts[0].get('y')), top_baseline)++ def test_overflow_keeps_center_and_bottom_alignment(self) -> None:+ # Layout-model height: three 32px lines at 1.2 leading = 115.2px.+ # These shifts test anchoring, not absolute native-render measurements.+ for mode in (None, 'overflow'):+ for paragraphs in (False, True):+ for anchor, shift in (('ctr', -41.6), ('b', -83.2)):+ with self.subTest(mode=mode, paragraphs=paragraphs, anchor=anchor):+ self._assert_anchor_shift(mode, anchor, paragraphs, shift)++ def test_nonoverflow_center_and_bottom_alignment_stays_within_frame(self) -> None:+ for mode in (None, 'overflow'):+ for paragraphs in (False, True):+ for anchor, shift in (('ctr', 22.4), ('b', 44.8)):+ with self.subTest(mode=mode, paragraphs=paragraphs, anchor=anchor):+ self._assert_anchor_shift(mode, anchor, paragraphs, shift, height=160)++ def test_overflow_alignment_uses_inner_frame_after_insets(self) -> None:+ for mode in (None, 'overflow'):+ for paragraphs in (False, True):+ for anchor, shift in (('ctr', -51.6), ('b', -103.2)):+ with self.subTest(mode=mode, paragraphs=paragraphs, anchor=anchor):+ self._assert_anchor_shift(+ mode, anchor, paragraphs, shift,+ top_inset_px=8, bottom_inset_px=12,+ )def test_table_cells_follow_their_text_bodys_overflow_mode(self) -> None:for mode, expected in ((None, 'FirstSecondThird'), ('overflow', 'FirstSecondThird'),