Skip to content

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): keep and report zero-axis geometry instead of dropping it

hugohe3cafb4ccff9b0
diff --git a/skills/ppt-master/scripts/mirror_template_materialize.py b/skills/ppt-master/scripts/mirror_template_materialize.py
index ec45b9bd..1d26a209 100644
--- a/skills/ppt-master/scripts/mirror_template_materialize.py
+++ b/skills/ppt-master/scripts/mirror_template_materialize.py
@@ -69,7 +69,11 @@ from svg_authoring_view import (
semantic_subtree_sha256,
)
from svg_finalize.flatten_tspan import flatten_text_with_tspans
-from svg_to_pptx.drawingml.utils import parse_transform_matrix, transform_point
+from svg_to_pptx.drawingml.utils import (
+ is_stroked_zero_axis_shape,
+ parse_transform_matrix,
+ transform_point,
+)
from svg_to_pptx.pptx_package.template_structure import (
SOURCE_THEMES_FILENAME,
SOURCE_THEMES_SCHEMA,
@@ -1716,6 +1720,7 @@ def _root_group_bounds(
if (
element.get("data-pptx-object") not in {"connector", "group"}
and element.get("data-pptx-prst") not in CONNECTOR_PRESET_TYPES
+ and not is_stroked_zero_axis_shape(element)
):
return None
bounds = _source_bounds(element)
@@ -2592,7 +2597,9 @@ def _compose_template(
atoms[0].set("id", item.get("id"))
item = atoms[0]
if _local_name(item.tag) == "g" and (
- _frame(item) is not None or _visible_leaf(item)
+ _frame(item) is not None
+ or _visible_leaf(item)
+ or is_stroked_zero_axis_shape(item)
):
bounds = _root_group_bounds(item, width, height)
if bounds is None:
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.py
index 1709a321..25afc131 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
@@ -594,6 +594,25 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->
node.inherited_body_properties,
)
is_vertical = is_vertical_txbody(tx_body, node.xfrm)
+ if (
+ is_vertical
+ and (node.xfrm.w <= 0 or node.xfrm.h <= 0)
+ and tx_body is not None
+ and any(element.text for element in tx_body.iter(f"{{{NS['a']}}}t"))
+ and (
+ node.placeholder is None
+ or _shape_scope(ctx) == "slide"
+ or (sp_pr is not None and sp_pr.find("a:xfrm", NS) is not None)
+ )
+ ):
+ # Standalone Layout/Master guides can await inherited geometry. Slide
+ # nodes already carry resolved inheritance, so their zero frame is real.
+ ctx.diagnose(
+ "degenerate-text-frame",
+ "Vertical text has a nonpositive source frame: "
+ + _object_metadata(node, ctx)["data-pptx-frame"],
+ "honor source overflow without inventing a frame; repair it in PowerPoint",
+ )
block_formula = _block_formula_zone(tx_body)
block_formula_failed = False
if block_formula is not None and not is_vertical:
@@ -747,6 +766,7 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->
if (
export_tx_body is not None
and geom is not None
+ and geom_xml
and not text_result.contains_inline_formula
):
inner_parts.append(
@@ -1206,9 +1226,13 @@ def _resolve_geometry(node: ShapeNode, sp_pr: ET.Element | None) -> GeomResult |
if geom is None:
return None
+ # An evaluated path can retain a collapsed axis without inventing a frame.
+ # Mirror/native validation still decides whether that source is exportable.
permits_degenerate_axis = (
node.kind == CONNECTOR
or prst in CONNECTOR_PRESET_TYPES
+ or (node.xfrm.w >= 0 and node.xfrm.h >= 0
+ and (node.xfrm.w > 0 or node.xfrm.h > 0))
)
if (
not permits_degenerate_axis
@@ -1225,8 +1249,17 @@ def _build_geometry_xml(node: ShapeNode, sp_pr: ET.Element | None,
if geom is None:
geom = _resolve_geometry(node, sp_pr)
if geom is None:
+ if sp_pr is not None and any(
+ sp_pr.find(path, NS) is not None
+ for path in ("a:prstGeom", "a:custGeom")
+ ):
+ ctx.diagnose(
+ "geometry-omitted",
+ "Source geometry could not be recovered at frame "
+ + _object_metadata(node, ctx)["data-pptx-frame"],
+ "retain any text/image content; no replacement geometry is invented",
+ )
return ""
-
# Resolve style defaults early so markers can adopt the theme stroke color
# when <a:ln> doesn't carry an explicit solidFill.
try:
@@ -1330,6 +1363,30 @@ def _build_geometry_xml(node: ShapeNode, sp_pr: ET.Element | None,
# Skip emitting stroke="none" to keep markup tight.
pass
+ if (
+ (node.xfrm.w <= 0 or node.xfrm.h <= 0)
+ and not (
+ (node.kind == CONNECTOR or geom.attrs.get("data-pptx-prst") in CONNECTOR_PRESET_TYPES)
+ and node.xfrm.w >= 0 and node.xfrm.h >= 0
+ and (node.xfrm.w > 0 or node.xfrm.h > 0)
+ )
+ ):
+ # Restoring evaluated zero-axis paths must not resurrect empty,
+ # explicitly unpainted text-box outlines as exportable source content.
+ if (
+ node.kind == SHAPE
+ and attrs.get("fill", "none") == "none"
+ and attrs.get("stroke", "none") == "none"
+ and not any(key in attrs for key in ("filter", "marker-start", "marker-end"))
+ ):
+ return ""
+ ctx.diagnose(
+ "geometry-degenerate-frame",
+ "Source geometry has a missing or degenerate frame: "
+ + _object_metadata(node, ctx)["data-pptx-frame"],
+ "retain evaluated geometry and the exact source frame",
+ )
+
semantic_attrs = {
**geom.attrs,
**_object_metadata(node, ctx),
@@ -1711,6 +1768,15 @@ def _convert_connector(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool
def _convert_group(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) -> str:
"""Render group contents flat (children already remapped to slide space)."""
+ if node.children and (
+ (node.xfrm.w == 0 and node.xfrm.ch_w is not None and node.xfrm.ch_w > 0)
+ or (node.xfrm.h == 0 and node.xfrm.ch_h is not None and node.xfrm.ch_h > 0)
+ ):
+ ctx.diagnose(
+ "group-collapsed-axis",
+ "The source group maps a positive child-coordinate extent to a zero frame axis",
+ "retain the source coordinate mapping; child geometry may collapse or be omitted",
+ )
parent_fill = ctx.group_fills[-1] if ctx.group_fills else None
group_properties = node.xml.find("p:grpSpPr", NS)
try:
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.py
index 9b24cf54..7e0ea64b 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
@@ -331,6 +331,10 @@ def convert_vertical_txbody(
box_x, box_y, box_w, box_h = _rotated_bbox(xfrm)
center_x = box_x + box_w / 2.0
+ clip_vertical = (
+ body_pr is not None
+ and body_pr.attrib.get("vertOverflow") in {"clip", "ellipsis"}
+ )
glyphs: list[tuple[str, TextRun]] = []
for run in runs:
@@ -351,7 +355,7 @@ def convert_vertical_txbody(
first_baseline: float | None = None
previous_baseline: float | None = None
for (char, run), advance in zip(glyphs, advances):
- if cursor_y + advance > bottom_y:
+ if clip_vertical and cursor_y + advance > bottom_y:
break
baseline_y = cursor_y + run.font_size_px * 0.85
tspan_attrs = _run_tspan_attrs(run)
@@ -437,6 +441,7 @@ def _convert_east_asian_vertical(
right_x -= width
anchor = body_pr.attrib.get("anchor", "t")
+ clip_vertical = body_pr.attrib.get("vertOverflow") in {"clip", "ellipsis"}
bottom_y = inner_y + inner_h
text_blocks: list[str] = []
for column, center_x in zip(columns, column_centers):
@@ -453,11 +458,14 @@ def _convert_east_asian_vertical(
for upright, text, run in column:
available = bottom_y - cursor_y
- if available <= 0:
+ if clip_vertical and available <= 0:
break
if upright:
advance = run.font_size_px * 1.05
- visible_count = min(len(text), int(available // advance))
+ visible_count = (
+ min(len(text), int(available // advance))
+ if clip_vertical else len(text)
+ )
visible = text[:visible_count]
if not visible:
break
@@ -475,7 +483,10 @@ def _convert_east_asian_vertical(
break
continue
- visible = _fit_sideways_vertical_text(text, run, available)
+ visible = (
+ _fit_sideways_vertical_text(text, run, available)
+ if clip_vertical else text
+ )
if not visible:
break
text_blocks.append(
diff --git a/skills/ppt-master/scripts/svg_authoring_view.py b/skills/ppt-master/scripts/svg_authoring_view.py
index 547e41f2..65b0c1eb 100644
--- a/skills/ppt-master/scripts/svg_authoring_view.py
+++ b/skills/ppt-master/scripts/svg_authoring_view.py
@@ -73,6 +73,7 @@ from svg_authoring_contract import (
from svg_to_pptx.drawingml.context import IDENTITY_MATRIX
from svg_to_pptx.drawingml.utils import (
INHERITABLE_ATTRS,
+ is_stroked_zero_axis_shape,
matrix_multiply,
parse_inline_style,
parse_opacity,
@@ -949,12 +950,15 @@ def _strip_import_attributes(
continue
if (
geometry_owner is not None
- and geometry_owner.get("data-pptx-object") == "connector"
+ and (
+ geometry_owner.get("data-pptx-object") == "connector"
+ or is_stroked_zero_axis_shape(geometry_owner)
+ )
and element.get("data-pptx-part") == "geometry"
and name in {"data-pptx-custgeom", "data-pptx-geometry-sha256"}
):
- # Connectors need the source custom geometry when exported from
- # the compact projection, which no longer rehydrates source refs.
+ # Collapsed stroked shapes and connectors need the source geometry
+ # because the compact projection no longer rehydrates source refs.
continue
stats.source_attributes[name] += 1
del element.attrib[name]
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
index c9bdb21d..f2f6a0ca 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -85,6 +85,7 @@ from .utils import (
quantize_ooxml_alpha,
project_definition_index,
svg_hidden_reason,
+ is_stroked_zero_axis_shape,
matrix_multiply, parse_transform_matrix, parse_transform_operations,
transform_point, _xml_escape,
)
@@ -807,6 +808,7 @@ _PPTX_GUIDE_NAME_RE = re.compile(r'[A-Za-z_][A-Za-z0-9_.-]{0,63}')
_PPTX_VAL_FORMULA_RE = re.compile(r'val[\t ]+([+-]?\d+)')
def _parse_preset_geometry_metadata(
elem: ET.Element,
+ ctx: ConvertContext | None = None,
) -> tuple[str | None, list[tuple[str, str]], tuple[float, float, float, float] | None]:
"""Parse and validate rendering-neutral preset geometry metadata."""
status = (elem.get('data-pptx-geometry-status') or '').strip()
@@ -952,7 +954,7 @@ def _parse_preset_geometry_metadata(
elem.tag.rsplit('}', 1)[-1] == 'g'
and elem.get('data-pptx-object') == 'group'
)
- if is_connector or is_native_group:
+ if is_connector or is_native_group or is_stroked_zero_axis_shape(elem, ctx):
if frame[2] < 0 or frame[3] < 0 or (frame[2] == 0 and frame[3] == 0):
kind = 'Connector' if is_connector else 'Group'
raise ValueError(
@@ -1040,9 +1042,9 @@ def complete_preset_adjustments(
]
-def _build_preset_geom_from_meta(elem: ET.Element) -> str | None:
+def _build_preset_geom_from_meta(elem: ET.Element, ctx: ConvertContext) -> str | None:
"""Build validated native DrawingML preset geometry from SVG metadata."""
- prst, guides, _frame = _parse_preset_geometry_metadata(elem)
+ prst, guides, _frame = _parse_preset_geometry_metadata(elem, ctx)
if prst is None:
return None
if not guides:
@@ -1099,7 +1101,7 @@ def _shape_xfrm_from_preset_frame(
transform: str | None,
) -> tuple[str, int, int, int, int, tuple[int, int, int, int]]:
"""Use the preserved logical frame for native preset size when present."""
- prst, _guides, frame = _parse_preset_geometry_metadata(elem)
+ prst, _guides, frame = _parse_preset_geometry_metadata(elem, ctx)
if frame is None:
raw_x, raw_y, raw_w, raw_h = fallback_raw_rect
x, y, w, h = fallback_resolved_rect
@@ -1112,6 +1114,7 @@ def _shape_xfrm_from_preset_frame(
preserves_zero_axis = (
elem.get('data-pptx-object') == 'connector'
or prst in CONNECTOR_PRESET_TYPES
+ or is_stroked_zero_axis_shape(elem, ctx)
)
xfrm_attr, off_x, off_y, ext_cx, ext_cy, bounds_emu = _shape_xfrm_from_svg_rect(
ctx,
@@ -1148,7 +1151,7 @@ def _pathlike_preset_xfrm(
height: float,
) -> tuple[str, int, int, int, int, tuple[int, int, int, int]]:
"""Resolve a path-like preset xfrm from its logical frame or visual bounds."""
- _prst, _guides, frame = _parse_preset_geometry_metadata(elem)
+ _prst, _guides, frame = _parse_preset_geometry_metadata(elem, ctx)
if frame is None:
if _uses_full_transform(ctx, transform):
tag = elem.tag.rsplit('}', 1)[-1]
@@ -1287,9 +1290,11 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
y = ctx_y(raw_y, ctx)
w = ctx_w(raw_w, ctx)
h = ctx_h(raw_h, ctx)
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
- if w <= 0 or h <= 0:
+ if (w <= 0 or h <= 0) and not (
+ preset_geom is not None and is_stroked_zero_axis_shape(elem, ctx)
+ ):
return None
# SVG spec: when only one of rx/ry is specified, the other inherits its
@@ -1477,7 +1482,7 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
cx_ = svg_length_x(elem.get('cx'), ctx)
cy_ = svg_length_y(elem.get('cy'), ctx)
r = svg_length_size(elem.get('r'), ctx)
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
if r <= 0:
return None
@@ -1641,7 +1646,7 @@ def convert_line(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
heads (headEnd / tailEnd) correctly. Plain lines (no markers) continue to
use custom geometry which is sufficient and avoids flipH/flipV complexity.
"""
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
transform = elem.get('transform')
raw_x1 = svg_length_x(elem.get('x1'), ctx)
raw_y1 = svg_length_y(elem.get('y1'), ctx)
@@ -1802,7 +1807,7 @@ def convert_line(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
def convert_path(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
"""Convert SVG <path> to DrawingML custom geometry shape."""
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
preserved_custom_geom = _build_preserved_custom_geom(elem)
native_geom = preset_geom or preserved_custom_geom
d = elem.get('d', '')
@@ -1890,7 +1895,7 @@ def convert_path(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
"""Convert SVG <polygon> to DrawingML custom geometry shape."""
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
points = parse_svg_points(elem.get('points', ''), min_points=3)
commands = [PathCommand('M', [points[0][0], points[0][1]])]
@@ -1967,7 +1972,7 @@ def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None
def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
"""Convert SVG <polyline> to DrawingML custom geometry shape."""
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
points = parse_svg_points(elem.get('points', ''), min_points=2)
commands = [PathCommand('M', [points[0][0], points[0][1]])]
@@ -5114,7 +5119,7 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
"""Convert SVG <ellipse> to DrawingML ellipse shape."""
- preset_geom = _build_preset_geom_from_meta(elem)
+ preset_geom = _build_preset_geom_from_meta(elem, ctx)
raw_cx = svg_length_x(elem.get('cx'), ctx)
raw_cy = svg_length_y(elem.get('cy'), ctx)
rx_attr = elem.get('rx')
@@ -5130,7 +5135,9 @@ def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None
rx = raw_rx * ctx.scale_x
ry = raw_ry * ctx.scale_y
- if rx <= 0 or ry <= 0:
+ if (rx <= 0 or ry <= 0) and not (
+ preset_geom is not None and is_stroked_zero_axis_shape(elem, ctx)
+ ):
return None
x = cx_ - rx
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index 66d2c54f..e340e515 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -1512,6 +1512,60 @@ def svg_hidden_reason(
return None
+def is_stroked_zero_axis_shape(
+ element: ET.Element,
+ ctx: ConvertContext | None = None,
+) -> bool:
+ """Recognize a native shape whose single collapsed frame axis still has an outline."""
+ geometry_tags = {'rect', 'circle', 'ellipse', 'line', 'path', 'polygon', 'polyline'}
+ if (
+ element.tag.rsplit('}', 1)[-1] not in geometry_tags | {'g'}
+ or element.get('data-pptx-object') != 'shape'
+ or not (
+ element.get('data-pptx-prst')
+ or element.get('data-pptx-geometry-kind') == 'custom'
+ )
+ ):
+ return False
+ try:
+ frame = tuple(float(value) for value in re.split(
+ r'[\s,]+', (element.get('data-pptx-frame') or '').strip(),
+ ))
+ except ValueError:
+ return False
+ if (
+ len(frame) != 4 or not all(math.isfinite(value) for value in frame)
+ or not ((frame[2] == 0 and frame[3] > 0) or (frame[3] == 0 and frame[2] > 0))
+ ):
+ return False
+ parents = {id(child): parent for parent in element.iter() for child in parent}
+ for leaf in element.iter():
+ if leaf.tag.rsplit('}', 1)[-1] not in geometry_tags or svg_hidden_reason(leaf, parents):
+ continue
+ lineage = [leaf]
+ while id(lineage[-1]) in parents:
+ lineage.append(parents[id(lineage[-1])])
+ if any(node.tag.rsplit('}', 1)[-1] in {'defs', 'clipPath', 'mask', 'metadata'} for node in lineage):
+ continue
+ inherited = dict(ctx.inherited_styles) if ctx is not None else {}
+ opacity = ctx.opacity_multiplier if ctx is not None else 1.0
+ try:
+ for node in reversed(lineage):
+ inherited.update(_extract_inheritable_styles(node))
+ local = parse_inline_style(node.get('style'))
+ opacity *= parse_project_opacity(local.get('opacity', node.get('opacity', '1')))
+ kind, _value, alpha = parse_project_paint(inherited.get('stroke', 'none'), 'stroke')
+ width = parse_project_geometry_length(inherited.get('stroke-width', '1'), 'stroke-width')
+ opacity *= parse_project_opacity(inherited.get('stroke-opacity', '1')) * alpha
+ except ValueError:
+ continue
+ # A reference can resolve to fully transparent stops outside this
+ # subtree; only resolved color paint proves that this outline exists.
+ if kind == 'color' and width > 0 and opacity > 0:
+ return True
+ return False
+
+
def iter_project_geometry_lengths(
root: ET.Element,
) -> Iterator[tuple[ET.Element, str, str, str]]:
diff --git a/skills/ppt-master/scripts/tests/test_native_export_guards.py b/skills/ppt-master/scripts/tests/test_native_export_guards.py
index f41f183f..d6f52460 100644
--- a/skills/ppt-master/scripts/tests/test_native_export_guards.py
+++ b/skills/ppt-master/scripts/tests/test_native_export_guards.py
@@ -38,6 +38,7 @@ from svg_to_pptx.drawingml.converter import ( # noqa: E402
convert_svg_to_slide_shapes,
)
from svg_to_pptx.drawingml.styles import build_gradient_fill # noqa: E402
+from svg_to_pptx.drawingml.elements import validate_preset_geometry_metadata # noqa: E402
from svg_to_pptx.pptx_package.discovery import find_notes_files # noqa: E402
@@ -153,6 +154,128 @@ class NativeExportGuardTests(unittest.TestCase):
with self.assertRaisesRegex(SvgNativeConversionError, 'requires preset or preserved'):
self._export()
+ def test_stroked_zero_axis_presets_keep_the_native_frame(self) -> None:
+ for preset in ('rect', 'ellipse'):
+ for width, height in ((300, 0), (0, 100)):
+ for transform in ('', 'transform="rotate(45 120 180)"'):
+ with self.subTest(preset=preset, frame=(width, height), transform=transform):
+ self._svg(
+ '<g data-pptx-semantic-object="shape" data-pptx-object="shape" '
+ f'data-pptx-prst="{preset}" data-pptx-frame="120 180 {width} {height}" '
+ f'{transform}><path data-pptx-part="geometry" '
+ f'd="M 120 180 L {120 + width} {180 + height}" '
+ 'stroke="#3060C0" stroke-width="2" fill="none"/></g>'
+ )
+ root = ET.parse(self.svg_path).getroot()
+ self.assertEqual(validate_preset_geometry_metadata(root[0]), [])
+ slide = self._export()
+ geometry = slide.find('.//p:sp/p:spPr/a:prstGeom', NS)
+ self.assertEqual(geometry.get('prst'), preset)
+ ext = slide.find('.//p:sp/p:spPr/a:xfrm/a:ext', NS)
+ self.assertEqual(ext.attrib, {'cx': str(width * 9525), 'cy': str(height * 9525)})
+
+ def test_stroked_zero_axis_custom_shape_projection_keeps_source_geometry(self) -> None:
+ for width, height in ((300, 0), (0, 100)):
+ with self.subTest(frame=(width, height)):
+ custom = self._custom_connector(
+ f'120 180 {width} {height}', f'M 120 180 L {120 + width} {180 + height}',
+ )
+ self.svg_path.write_text(
+ self.svg_path.read_text(encoding='utf-8').replace(
+ 'data-pptx-object="connector"', 'data-pptx-object="shape"',
+ ), encoding='utf-8',
+ )
+ authoring_dir = self.root / f'authoring-{width}-{height}'
+ projected = authoring_dir / self.svg_path.name
+ project_svg_batch(
+ [(self.svg_path, projected)], self.root, authoring_dir,
+ force=False, projection_kind='layered',
+ )
+ xml, *_ = convert_svg_to_slide_shapes(projected, resource_root=self.root)
+ self.assertIn(custom, xml)
+ slide = ET.fromstring(xml)
+ ext = slide.find('.//p:sp/p:spPr/a:xfrm/a:ext', NS)
+ self.assertEqual(ext.attrib, {'cx': str(width * 9525), 'cy': str(height * 9525)})
+
+ def test_zero_axis_native_rect_and_ellipse_primitives_are_not_omitted(self) -> None:
+ for preset in ('rect', 'ellipse'):
+ for width, height in ((300, 0), (0, 100)):
+ with self.subTest(preset=preset, frame=(width, height)):
+ geometry = (
+ f'x="120" y="180" width="{width}" height="{height}"'
+ if preset == 'rect' else
+ f'cx="{120 + width / 2}" cy="{180 + height / 2}" '
+ f'rx="{width / 2}" ry="{height / 2}"'
+ )
+ self._svg(
+ f'<{preset} data-pptx-object="shape" data-pptx-prst="{preset}" '
+ f'data-pptx-frame="120 180 {width} {height}" {geometry} '
+ 'stroke="#3060C0" fill="none"/>'
+ )
+ ext = self._export().find('.//p:sp/p:spPr/a:xfrm/a:ext', NS)
+ self.assertIsNotNone(ext)
+ self.assertEqual(ext.attrib, {'cx': str(width * 9525), 'cy': str(height * 9525)})
+
+ def test_stroked_zero_axis_shape_uses_inherited_outline_during_export(self) -> None:
+ self._svg(
+ '<g data-pptx-semantic-object="shape" data-pptx-object="shape" '
+ 'data-pptx-prst="rect" data-pptx-frame="120 180 300 0" '
+ 'stroke="#3060C0" stroke-width="2">'
+ '<path data-pptx-part="geometry" d="M 120 180 L 420 180" fill="none"/></g>'
+ )
+ group = ET.parse(self.svg_path).getroot()[0]
+ self.assertEqual(validate_preset_geometry_metadata(group), [])
+ ext = self._export().find('.//p:sp/p:spPr/a:xfrm/a:ext', NS)
+ self.assertEqual(ext.attrib, {'cx': str(300 * 9525), 'cy': '0'})
+
+ def test_zero_axis_native_shape_requires_a_visible_stroke(self) -> None:
+ for paint in (
+ '', 'stroke="none"', 'stroke="transparent"',
+ 'stroke="#3060C0" stroke-width="0"',
+ 'stroke="#3060C0" stroke-opacity="0"',
+ 'stroke="#3060C0" opacity="0"',
+ 'stroke="#3060C000"',
+ ):
+ with self.subTest(paint=paint):
+ self._svg(
+ '<g data-pptx-semantic-object="shape" data-pptx-object="shape" '
+ 'data-pptx-prst="rect" data-pptx-frame="120 180 300 0">'
+ '<path data-pptx-part="geometry" d="M 120 180 L 420 180" '
+ f'{paint} fill="none"/></g>'
+ )
+ group = ET.parse(self.svg_path).getroot()[0]
+ self.assertTrue(validate_preset_geometry_metadata(group))
+ with self.assertRaisesRegex(SvgNativeConversionError, 'must be positive'):
+ self._export()
+
+ def test_zero_axis_shape_exception_keeps_invalid_frames_and_text_strict(self) -> None:
+ for frame, tag in (
+ ('120 180 0 0', 'path'), ('120 180 -1 100', 'path'),
+ ('120 180 300 -1', 'path'), ('120 180 300 0', 'text'),
+ ):
+ with self.subTest(frame=frame, tag=tag):
+ element = ET.fromstring(
+ f'<{tag} data-pptx-object="shape" data-pptx-prst="rect" '
+ f'data-pptx-frame="{frame}" stroke="#3060C0"/>'
+ )
+ self.assertTrue(validate_preset_geometry_metadata(element))
+
+ def test_zero_axis_shape_reference_stroke_does_not_prove_visible_outline(self) -> None:
+ for definitions in (
+ '',
+ '<defs><linearGradient id="g"><stop offset="0" stop-color="#3060C0" '
+ 'stop-opacity="0"/><stop offset="1" stop-color="#000000" '
+ 'stop-opacity="0"/></linearGradient></defs>',
+ ):
+ with self.subTest(definitions=bool(definitions)):
+ group = ET.fromstring(
+ '<g data-pptx-object="shape" data-pptx-prst="rect" '
+ 'data-pptx-frame="120 180 300 0">'
+ f'{definitions}<path d="M 120 180 L 420 180" '
+ 'stroke="url(#g)" stroke-width="2" fill="none"/></g>'
+ )
+ self.assertTrue(validate_preset_geometry_metadata(group))
+
@staticmethod
def _shape_colors(slide: ET.Element) -> list[str]:
return [
diff --git a/skills/ppt-master/scripts/tests/test_pptx_geometry_import_losses.py b/skills/ppt-master/scripts/tests/test_pptx_geometry_import_losses.py
new file mode 100644
index 00000000..828b3e37
--- /dev/null
+++ b/skills/ppt-master/scripts/tests/test_pptx_geometry_import_losses.py
@@ -0,0 +1,162 @@
+#!/usr/bin/env python3
+"""
+PPT Master - Geometry Import Loss Regressions
+
+Keep evaluated zero-axis paths and report geometry that cannot be recovered.
+
+Usage:
+ python3 -m unittest tests.test_pptx_geometry_import_losses
+
+Examples:
+ Run the module from the scripts directory.
+
+Dependencies:
+ Standard library and the local PPT Master importer.
+"""
+
+from __future__ import annotations
+
+import base64
+import json
+import sys
+import tempfile
+import unittest
+import zipfile
+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.converter import convert_pptx_to_svg # noqa: E402
+
+A = 'http://schemas.openxmlformats.org/drawingml/2006/main'
+P = 'http://schemas.openxmlformats.org/presentationml/2006/main'
+SVG = 'http://www.w3.org/2000/svg'
+NS = {'s': SVG, 'a': A}
+
+
+def _frame(width: int, height: int, *, extent: bool = True) -> str:
+ ext = f'<a:ext cx="{width * 9525}" cy="{height * 9525}"/>' if extent else ''
+ return f'<a:xfrm><a:off x="1143000" y="1714500"/>{ext}</a:xfrm>'
+
+
+def _shape(geometry: str, frame: str, *, connector: bool = False, hidden: bool = False) -> str:
+ tag, nv_tag = ('cxnSp', 'CxnSp') if connector else ('sp', 'Sp')
+ return (
+ f'<p:{tag}><p:nv{nv_tag}Pr><p:cNvPr id="2" name="Source" hidden="{int(hidden)}"/>'
+ f'<p:cNv{nv_tag}Pr/><p:nvPr/></p:nv{nv_tag}Pr><p:spPr>{frame}{geometry}'
+ '<a:noFill/><a:ln w="19050"><a:solidFill><a:srgbClr val="123456"/>'
+ f'</a:solidFill></a:ln></p:spPr></p:{tag}>'
+ )
+
+
+class GeometryImportLossTests(unittest.TestCase):
+ def _import(self, content: str) -> tuple[ET.Element, dict]:
+ with tempfile.TemporaryDirectory() as temporary:
+ root = Path(temporary)
+ source = root / 'source.pptx'
+ with zipfile.ZipFile(source, '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>'
+ f'{content}</p:spTree></p:cSld></p:sld>'
+ ))
+ result = convert_pptx_to_svg(source, root / 'output')
+ report = json.loads((root / 'output/validation/conversion-report.json').read_text(encoding='utf-8'))
+ return ET.fromstring(result.slides[0].svg), report
+
+ def _assert_warning(self, report: dict, code: str, shape_id: str = '2') -> None:
+ matching = [item for item in report['diagnostics'] if item['code'] == code and item['shape_id'] == shape_id]
+ # Layered and flat projections must not duplicate the same warning.
+ self.assertEqual(len(matching), 1, report)
+ self.assertEqual(matching[0]['part_path'], 'ppt/slides/slide1.xml')
+ self.assertEqual(matching[0]['slide_index'], 1)
+ self.assertEqual(matching[0]['severity'], 'warning')
+ self.assertEqual(report['summary']['warnings'], len(report['diagnostics']))
+
+ def test_zero_axis_custom_paths_keep_source_payload_and_frame(self) -> None:
+ for width, height, count in ((300, 0, 1), (0, 100, 1), (300, 0, 2)):
+ with self.subTest(width=width, height=height, count=count):
+ path = ('<a:path w="300" h="100" fill="none"><a:moveTo><a:pt x="0" y="0"/>'
+ '</a:moveTo><a:lnTo><a:pt x="300" y="100"/></a:lnTo></a:path>')
+ geometry = f'<a:custGeom><a:pathLst>{path * count}</a:pathLst></a:custGeom>'
+ svg, report = self._import(_shape(geometry, _frame(width, height)))
+ leaf = svg.find('.//s:path', NS)
+ self.assertIsNotNone(leaf)
+ self.assertEqual(leaf.get('data-pptx-frame'), f'120 180 {width} {height}')
+ self.assertEqual(leaf.get('d').count('M '), count)
+ payload = ET.fromstring(base64.b64decode(leaf.get('data-pptx-custgeom')))
+ expected = ET.fromstring(f'<a:custGeom xmlns:a="{A}"><a:pathLst>{path * count}</a:pathLst></a:custGeom>')
+ self.assertEqual(ET.tostring(payload), ET.tostring(expected))
+ self._assert_warning(report, 'geometry-degenerate-frame')
+
+ def test_zero_axis_ordinary_presets_keep_evaluated_outline(self) -> None:
+ for preset in ('rect', 'ellipse'):
+ for width, height in ((300, 0), (0, 100)):
+ with self.subTest(preset=preset, width=width, height=height):
+ svg, report = self._import(_shape(f'<a:prstGeom prst="{preset}"/>', _frame(width, height)))
+ path = svg.find('.//s:path', NS)
+ self.assertIsNotNone(path)
+ self.assertTrue(path.get('d'))
+ self.assertEqual(path.get('stroke'), '#123456')
+ self._assert_warning(report, 'geometry-degenerate-frame')
+
+ def test_unrecoverable_frames_report_omission_without_guessing_geometry(self) -> None:
+ for connector in (False, True):
+ preset = 'straightConnector1' if connector else 'rect'
+ for frame in ('', _frame(0, 0), _frame(0, 0, extent=False)):
+ with self.subTest(connector=connector, frame=frame):
+ svg, report = self._import(_shape(f'<a:prstGeom prst="{preset}"/>', frame, connector=connector))
+ self.assertIsNone(svg.find('.//s:path', NS))
+ self._assert_warning(report, 'geometry-omitted')
+
+ def test_collapsed_group_reports_source_mapping_and_each_omitted_child(self) -> None:
+ child = _shape('<a:prstGeom prst="straightConnector1"/>', _frame(300, 0), connector=True)
+ group = (
+ '<p:grpSp><p:nvGrpSpPr><p:cNvPr id="3" name="Collapsed"/>'
+ '<p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm>'
+ '<a:off x="1143000" y="1714500"/><a:ext cx="0" cy="952500"/>'
+ '<a:chOff x="1143000" y="1714500"/><a:chExt cx="2857500" cy="952500"/>'
+ f'</a:xfrm></p:grpSpPr>{child}</p:grpSp>'
+ )
+ svg, report = self._import(group)
+ self.assertIsNone(svg.find('.//s:path', NS))
+ self._assert_warning(report, 'group-collapsed-axis', '3')
+ self._assert_warning(report, 'geometry-omitted')
+
+ def test_hidden_and_positive_controls_do_not_report_geometry_loss(self) -> None:
+ for frame, hidden in ((_frame(300, 100), False), (_frame(0, 0), True)):
+ with self.subTest(hidden=hidden):
+ _, report = self._import(_shape('<a:prstGeom prst="rect"/>', frame, hidden=hidden))
+ self.assertEqual(report['diagnostics'], [])
+
+ def test_existing_zero_axis_connector_does_not_report_geometry_loss(self) -> None:
+ svg, report = self._import(_shape(
+ '<a:prstGeom prst="straightConnector1"/>', _frame(300, 0), connector=True,
+ ))
+ self.assertIsNotNone(svg.find('.//s:path', NS))
+ self.assertEqual(report['diagnostics'], [])
+
+ def test_unpainted_zero_axis_outline_is_not_resurrected(self) -> None:
+ shape = _shape('<a:prstGeom prst="rect"/>', _frame(300, 0)).replace(
+ '<a:solidFill><a:srgbClr val="123456"/></a:solidFill>', '<a:noFill/>',
+ ).replace(
+ '</p:sp>', '<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>',
+ )
+ svg, report = self._import(shape)
+ self.assertIsNone(svg.find('.//s:path', NS))
+ self.assertIsNone(svg.find('.//s:g', NS))
+ self.assertEqual(report['diagnostics'], [])
diff --git a/skills/ppt-master/scripts/tests/test_template_flow_batch3.py b/skills/ppt-master/scripts/tests/test_template_flow_batch3.py
index ea21d874..5aa18a44 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,53 @@ class TemplateFlowBatch3Tests(unittest.TestCase):
'fill="none"/></g>'
)
+ def test_a_mirror_bounds_stroked_zero_axis_ordinary_shapes(self) -> None:
+ for geometry in ('data-pptx-prst="rect"', 'data-pptx-geometry-kind="custom"'):
+ for frame, path, expected in (
+ ('100 200 400 0', 'M 100 200 L 500 200', '100 198 400 4'),
+ ('100 200 0 300', 'M 100 200 L 100 500', '98 200 4 300'),
+ ):
+ with self.subTest(geometry=geometry, frame=frame):
+ result = self._compose_slide(
+ f'<g id="rule" data-pptx-object="shape" {geometry} '
+ f'data-pptx-frame="{frame}"><path d="{path}" '
+ 'stroke="#123456" stroke-width="4" fill="none"/></g>'
+ )
+ group = next(element for element in result.iter() if element.get('id') == 'rule')
+ self.assertEqual(group.get('data-pptx-bounds'), expected)
+ self.assertEqual(group.get('data-pptx-frame'), frame)
+ self.assertEqual(group.find(f'{{{SVG_NS}}}path').get('d'), path)
+
+ def test_a_mirror_transforms_and_clips_stroked_shape_validation_bounds_only(self) -> None:
+ for transform, expected in (('', '0 0 400 2'), ('translate(10 20)', '10 18 400 4')):
+ with self.subTest(transform=transform):
+ result = self._compose_slide(
+ '<g id="rule" data-pptx-object="shape" data-pptx-prst="rect" '
+ f'data-pptx-frame="0 0 400 0" transform="{transform}" '
+ 'style="stroke:#123456;stroke-width:4"><path d="M 0 0 L 400 0" '
+ 'fill="none"/></g>'
+ )
+ group = next(element for element in result.iter() if element.get('id') == 'rule')
+ self.assertEqual(group.get('data-pptx-bounds'), expected)
+ self.assertEqual(group.get('data-pptx-frame'), '0 0 400 0')
+ self.assertEqual(group.get('transform'), transform)
+
+ def test_a_mirror_keeps_degenerate_ordinary_shape_refusal_boundaries(self) -> None:
+ for frame, paint, content in (
+ ('100 200 400 0', 'stroke="none"', '<path d="M 100 200 L 500 200"/>'),
+ ('100 200 400 0', 'stroke="#000000" stroke-width="0"', '<path d="M 100 200 L 500 200"/>'),
+ ('100 200 400 0', 'stroke="#000000" stroke-opacity="0"', '<path d="M 100 200 L 500 200"/>'),
+ ('100 200 0 0', 'stroke="#000000"', '<path d="M 100 200 L 500 200"/>'),
+ ('100 200 -1 100', 'stroke="#000000"', '<path d="M 100 200 L 500 200"/>'),
+ ('100 200 400 0', 'stroke="#000000"', '<text x="100" y="200">Text</text>'),
+ ):
+ with self.subTest(frame=frame, paint=paint, content=content):
+ element = ET.fromstring(
+ f'<g xmlns="{SVG_NS}" data-pptx-object="shape" data-pptx-prst="rect" '
+ f'data-pptx-frame="{frame}" {paint}>{content}</g>'
+ )
+ self.assertIsNone(mirror._root_group_bounds(element, 1280, 720))
+
def test_a_mirror_bounds_retained_unpainted_positive_frame(self) -> None:
result = self._compose_slide(
'<g id="text-outline" data-pptx-object="shape" '
diff --git a/skills/ppt-master/scripts/tests/test_text_overflow_import.py b/skills/ppt-master/scripts/tests/test_text_overflow_import.py
index debb7ef9..5546a5df 100644
--- a/skills/ppt-master/scripts/tests/test_text_overflow_import.py
+++ b/skills/ppt-master/scripts/tests/test_text_overflow_import.py
@@ -290,3 +290,85 @@ class VerticalTextFrameImportTests(unittest.TestCase):
self.assertIsNotNone(group)
self.assertEqual(group.get('data-pptx-frame'), '240 60 80 320')
self.assertIsNone(group.get('transform'))
+
+ def test_degenerate_slide_text_keeps_its_frame_and_reports_its_source_identity(self) -> None:
+ for width, height in ((80, 0), (0, 0), (0, 320), (80, 320)):
+ for mode in ('vert', 'eaVert', 'wordArtVert', 'wordArtVertRtl'):
+ with self.subTest(width=width, height=height, mode=mode):
+ diagnostics = []
+ root = self._import_slide(
+ _vertical_body(mode), Xfrm(x=120, y=180, w=width, h=height),
+ diagnostics=diagnostics,
+ )
+ group = root.find('s:g[@id="shape-2-text"]', NS)
+ self.assertIsNotNone(group)
+ self.assertEqual(group.get('data-pptx-frame'), f'120 180 {width} {height}')
+ self.assertEqual(_visible_text(group), '中文ABC测试')
+ self.assertEqual(
+ [row.code for row in diagnostics],
+ ['degenerate-text-frame'] if width == 0 or height == 0 else [],
+ )
+ for diagnostic in diagnostics:
+ self.assertEqual(diagnostic.shape_id, '2')
+ self.assertEqual(diagnostic.part_path, 'ppt/slides/slide1.xml')
+
+ def test_layout_guide_without_local_frame_is_not_diagnosed_as_a_source_loss(self) -> None:
+ for explicit_frame in (False, True):
+ with self.subTest(explicit_frame=explicit_frame), tempfile.TemporaryDirectory() as temporary:
+ path = Path(temporary) / 'source.pptx'
+ local_frame = (
+ '<a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></a:xfrm>'
+ if explicit_frame else ''
+ )
+ with zipfile.ZipFile(path, 'w') as archive:
+ archive.writestr('ppt/presentation.xml', (
+ f'<p:presentation xmlns:p="{P}">'
+ '<p:sldSz cx="12192000" cy="6858000"/></p:presentation>'
+ ))
+ archive.writestr('ppt/slideLayouts/slideLayout1.xml', (
+ f'<p:sldLayout xmlns:p="{P}" xmlns:a="{A}"><p:cSld><p:spTree><p:sp>'
+ '<p:nvSpPr><p:cNvPr id="2" name="Vertical guide"/><p:cNvSpPr/>'
+ '<p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr>'
+ f'<p:spPr>{local_frame}</p:spPr>{ET.tostring(_vertical_body("eaVert"), encoding="unicode")}'
+ '</p:sp></p:spTree></p:cSld></p:sldLayout>'
+ ))
+ archive.writestr('ppt/slideMasters/slideMaster1.xml', (
+ f'<p:sldMaster xmlns:p="{P}" xmlns:a="{A}"><p:cSld><p:spTree><p:sp>'
+ '<p:nvSpPr><p:cNvPr id="3" name="Body"/><p:cNvSpPr/>'
+ '<p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr>'
+ '<p:spPr><a:xfrm><a:off x="914400" y="914400"/>'
+ '<a:ext cx="7620000" cy="3810000"/></a:xfrm></p:spPr>'
+ '</p:sp></p:spTree></p:cSld></p:sldMaster>'
+ ))
+ diagnostics = []
+ with OoxmlPackage(path) as package:
+ assemble_part_solo(
+ package, package.load_part('ppt/slideLayouts/slideLayout1.xml'), None,
+ role='layout', parent_master=package.load_part('ppt/slideMasters/slideMaster1.xml'),
+ diagnostics=diagnostics,
+ )
+ self.assertEqual(
+ [row.code for row in diagnostics], ['degenerate-text-frame'] if explicit_frame else [],
+ )
+
+
+class VerticalTextOverflowImportTests(unittest.TestCase):
+ def test_default_and_explicit_overflow_keep_every_vertical_glyph(self) -> None:
+ for mode in ('vert', 'eaVert', 'wordArtVert', 'wordArtVertRtl'):
+ for overflow in (None, 'overflow'):
+ for width, height in ((80, 30), (80, 0), (0, 0)):
+ with self.subTest(mode=mode, overflow=overflow, width=width, height=height):
+ result = convert_vertical_txbody(
+ _vertical_body(mode, overflow), Xfrm(x=120, y=180, w=width, h=height), None,
+ )
+ self.assertEqual(_visible_text(_svg_root(result.svg)), '中文ABC测试')
+ self.assertEqual(result.frame, (120, 180, width, height))
+
+ def test_explicit_clip_and_ellipsis_retain_existing_vertical_truncation(self) -> None:
+ for mode in ('vert', 'eaVert', 'wordArtVert', 'wordArtVertRtl'):
+ for overflow in ('clip', 'ellipsis'):
+ with self.subTest(mode=mode, overflow=overflow):
+ result = convert_vertical_txbody(
+ _vertical_body(mode, overflow), Xfrm(x=120, y=180, w=80, h=30), None,
+ )
+ self.assertEqual(_visible_text(_svg_root(result.svg)), '中')