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(import): carry the source frame on vertical text groups
hugohe36965c0db86a7
diff --git a/skills/ppt-master/scripts/mirror_template_materialize.py b/skills/ppt-master/scripts/mirror_template_materialize.pyindex 4745173d..ec45b9bd 100644--- a/skills/ppt-master/scripts/mirror_template_materialize.py+++ b/skills/ppt-master/scripts/mirror_template_materialize.py@@ -2591,7 +2591,9 @@ def _compose_template(if len(atoms) == 1:atoms[0].set("id", item.get("id"))item = atoms[0]- if _local_name(item.tag) == "g" and _visible_leaf(item):+ if _local_name(item.tag) == "g" and (+ _frame(item) is not None or _visible_leaf(item)+ ):bounds = _root_group_bounds(item, width, height)if bounds is None:raise MirrorMaterializationError(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 a8531bc7..1709a321 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@@ -727,9 +727,13 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->)if not visible_text_svg:return shape_xml+ text_frame_attr = ""+ if text_result.frame is not None:+ text_frame = " ".join(fmt_num(value, 8) for value in text_result.frame)+ text_frame_attr = f' data-pptx-frame="{text_frame}"'text_group = (f'<g id="{ctx.group_id_prefix}shape-{node.spid or ctx.shape_seq[0]}-text"'- f' data-name="{_xml_escape(node.name)} text">\n'+ f' data-name="{_xml_escape(node.name)} text"{text_frame_attr}>\n'f"{visible_text_svg}\n</g>")return f"{shape_xml}\n{text_group}"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 1aead190..9b24cf54 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@@ -109,11 +109,13 @@ class TextResult:`svg` is one or more <text> elements, already absolutely positionedinside the slide coordinate system. `defs` holds text gradient fills.+ `frame` carries the source box used by separately positioned vertical text."""svg: str = ""defs: list[str] = field(default_factory=list)contains_inline_formula: bool = False+ frame: tuple[float, float, float, float] | None = NoneVERTICAL_TEXT_MODES = {"eaVert", "vert", "wordArtVert", "wordArtVertRtl"}@@ -377,6 +379,7 @@ def convert_vertical_txbody(svg=f"<text{attrs}>{''.join(spans)}</text>",defs=_collect_text_defs(paragraphs),contains_inline_formula=False,+ frame=(box_x, box_y, box_w, box_h),)@@ -491,6 +494,7 @@ def _convert_east_asian_vertical(svg="\n".join(text_blocks),defs=_collect_text_defs(paragraphs),contains_inline_formula=False,+ frame=(box_x, box_y, box_w, box_h),)diff --git a/skills/ppt-master/scripts/tests/test_template_flow_batch3.py b/skills/ppt-master/scripts/tests/test_template_flow_batch3.pyindex dad3dd0b..ea21d874 100644--- a/skills/ppt-master/scripts/tests/test_template_flow_batch3.py+++ b/skills/ppt-master/scripts/tests/test_template_flow_batch3.py@@ -158,6 +158,18 @@ class TemplateFlowBatch3Tests(unittest.TestCase):'fill="none"/></g>')+ def test_a_mirror_bounds_retained_unpainted_positive_frame(self) -> None:+ result = self._compose_slide(+ '<g id="text-outline" data-pptx-object="shape" '+ 'data-pptx-frame="120 180 80 320">'+ '<path d="M 120 180 L 200 180 L 200 500 L 120 500 Z" fill="none"/></g>'+ '<g id="vertical-text" data-pptx-frame="120 180 80 320">'+ '<text x="160" y="205" fill="#000000" font-size="24">A</text></g>'+ )+ by_id = {element.get('id'): element for element in result.iter() if element.get('id')}+ self.assertEqual(by_id['text-outline'].get('data-pptx-bounds'), '120 180 80 320')+ self.assertEqual(by_id['vertical-text'].get('data-pptx-bounds'), '120 180 80 320')+def test_a_export_accepts_native_group_with_one_zero_axis(self) -> None:from svg_to_pptx.drawingml.elements import (_parse_preset_geometry_metadata,diff --git a/skills/ppt-master/scripts/tests/test_text_overflow_import.py b/skills/ppt-master/scripts/tests/test_text_overflow_import.pyindex 5e9f43fa..debb7ef9 100644--- a/skills/ppt-master/scripts/tests/test_text_overflow_import.py+++ b/skills/ppt-master/scripts/tests/test_text_overflow_import.py@@ -18,7 +18,9 @@ Dependencies:from __future__ import annotationsimport sys+import tempfileimport unittest+import zipfilefrom pathlib import Pathfrom xml.etree import ElementTree as ET@@ -28,8 +30,10 @@ 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.ooxml_loader import OoxmlPackage # noqa: E402+from pptx_to_svg.slide_to_svg import assemble_part_solo, assemble_slide # noqa: E402from pptx_to_svg.tbl_to_svg import convert_tbl # noqa: E402-from pptx_to_svg.txbody_to_svg import convert_txbody # noqa: E402+from pptx_to_svg.txbody_to_svg import convert_txbody, convert_vertical_txbody # noqa: E402A = 'http://schemas.openxmlformats.org/drawingml/2006/main'@@ -211,3 +215,78 @@ class RunEmphasisImportTests(unittest.TestCase):svg = convert_txbody(body, Xfrm(x=0, y=0, w=300, h=100), None).svgself.assertIn('font-weight="bold"', svg)self.assertIn('font-style="italic"', svg)+++def _vertical_body(mode: str | None, overflow: str | None = None) -> ET.Element:+ mode_attr = f' vert="{mode}"' if mode is not None else ''+ overflow_attr = f' vertOverflow="{overflow}"' if overflow is not None else ''+ return ET.fromstring(+ f'<p:txBody xmlns:p="{P}" xmlns:a="{A}">'+ f'<a:bodyPr lIns="0" tIns="0" rIns="0" bIns="0"{mode_attr}{overflow_attr}/>'+ '<a:lstStyle/><a:p><a:r><a:rPr sz="1800"><a:latin typeface="Arial"/>'+ '<a:ea typeface="Microsoft YaHei"/></a:rPr><a:t>中文ABC测试</a:t></a:r></a:p>'+ '</p:txBody>'+ )+++class VerticalTextFrameImportTests(unittest.TestCase):+ def _import_slide(self, body: ET.Element, frame: Xfrm, *, diagnostics=None) -> ET.Element:+ with tempfile.TemporaryDirectory() as temporary:+ path = Path(temporary) / 'source.pptx'+ with zipfile.ZipFile(path, 'w') as archive:+ archive.writestr('ppt/presentation.xml', (+ f'<p:presentation xmlns:p="{P}" '+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'+ '<p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst>'+ '<p:sldSz cx="12192000" cy="6858000"/></p:presentation>'+ ))+ archive.writestr('ppt/_rels/presentation.xml.rels', (+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'+ '<Relationship Id="rId1" '+ 'Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" '+ 'Target="slides/slide1.xml"/></Relationships>'+ ))+ archive.writestr('ppt/slides/slide1.xml', (+ f'<p:sld xmlns:p="{P}" xmlns:a="{A}"><p:cSld><p:spTree><p:sp>'+ '<p:nvSpPr><p:cNvPr id="2" name="Vertical"/><p:cNvSpPr txBox="1"/>'+ '<p:nvPr/></p:nvSpPr><p:spPr>'+ f'<a:xfrm rot="{int(frame.rot * 60000)}">'+ f'<a:off x="{int(frame.x * 9525)}" y="{int(frame.y * 9525)}"/>'+ f'<a:ext cx="{int(frame.w * 9525)}" cy="{int(frame.h * 9525)}"/>'+ '</a:xfrm><a:noFill/><a:ln><a:noFill/></a:ln></p:spPr>'+ f'{ET.tostring(body, encoding="unicode")}'+ '</p:sp></p:spTree></p:cSld></p:sld>'+ ))+ with OoxmlPackage(path) as package:+ svg, _ = assemble_slide(+ package, next(package.iter_slides()), None, diagnostics=diagnostics,+ )+ return ET.fromstring(svg)++ def test_vertical_root_groups_keep_positive_source_frame(self) -> None:+ for mode in ('vert', 'eaVert', 'wordArtVert', 'wordArtVertRtl'):+ with self.subTest(mode=mode):+ root = self._import_slide(_vertical_body(mode), Xfrm(x=120, y=180, w=80, h=320))+ group = root.find('s:g[@id="shape-2-text"]', NS)+ self.assertIsNotNone(group)+ self.assertEqual(group.get('data-pptx-frame'), '120 180 80 320')+ self.assertIsNone(group.get('transform'))+ self.assertEqual(_visible_text(group), '中文ABC测试')++ def test_auto_stacked_cjk_root_keeps_its_narrow_source_frame(self) -> None:+ body = _vertical_body(None)+ body.find('a:p/a:r/a:t', NS).text = '中文窄框测试'+ root = self._import_slide(body, Xfrm(x=120, y=180, w=20, h=320))+ group = root.find('s:g[@id="shape-2-text"]', NS)+ self.assertIsNotNone(group)+ self.assertEqual(group.get('data-pptx-frame'), '120 180 20 320')+ self.assertEqual(_visible_text(group), '中文窄框测试')++ def test_rotated_vertical_text_frame_matches_its_positioned_glyphs(self) -> None:+ root = self._import_slide(+ _vertical_body('eaVert'), Xfrm(x=120, y=180, w=320, h=80, rot=90),+ )+ group = root.find('s:g[@id="shape-2-text"]', NS)+ self.assertIsNotNone(group)+ self.assertEqual(group.get('data-pptx-frame'), '240 60 80 320')+ self.assertIsNone(group.get('transform'))