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(scripts): SVG-first chart companions sit on the fallback baseline; table padding yields to the authored row height

hugohe39dcb32039b88
diff --git a/skills/ppt-master/scripts/docs/native-data.md b/skills/ppt-master/scripts/docs/native-data.md
index 26f4aafc..5920b332 100644
--- a/skills/ppt-master/scripts/docs/native-data.md
+++ b/skills/ppt-master/scripts/docs/native-data.md
@@ -19,7 +19,7 @@ one child `<metadata type="application/json">` (attribute `data-pptx-json` is re
## §2 Table schema — `ppt-master.semantic-table.v2`
-Every payload carries that exact `schema`. Native tables are rectangular grids: `columns` for the optional header row, `rows` for body rows (shorter rows padded unless `strict_grid: true`; at most 1000 resolved rows and columns); `column_widths` / `row_heights` are finite non-negative relative weights matching the grid with one positive value; `header_rows` is an integer in range; `strict_grid`, `style.band_row`, and `bold` are JSON booleans. Exact repetition may be factored into `defaults.cell` / `defaults.paragraph` / `defaults.run` and kebab-case `cell_styles` selected by `cell_style` (precedence: cell defaults → named style → cell fields; object-valued `padding` merges, everything else replaces; `<style>` and `class` remain forbidden).
+Every payload carries that exact `schema`. Native tables are rectangular grids: `columns` for the optional header row, `rows` for body rows (shorter rows padded unless `strict_grid: true`; at most 1000 resolved rows and columns); `column_widths` / `row_heights` are finite non-negative relative weights matching the grid with one positive value (a row's top and bottom padding shrink to what its resolved height can hold beside the text line, since PowerPoint would otherwise grow the row past the drawn one); `header_rows` is an integer in range; `strict_grid`, `style.band_row`, and `bold` are JSON booleans. Exact repetition may be factored into `defaults.cell` / `defaults.paragraph` / `defaults.run` and kebab-case `cell_styles` selected by `cell_style` (precedence: cell defaults → named style → cell fields; object-valued `padding` merges, everything else replaces; `<style>` and `class` remain forbidden).
Cells accept `text`, `fill`, `fill_opacity`, `color`, `align` (`l` / `ctr` / `r`), `valign` (`top` / `middle` / `bottom`), `bold`, `font_size`, `padding` and side-specific `padding_*`, `border_color`, `border_width`, `borders`, `lang`, `anchor_center`, `horizontal_overflow`. Multi-paragraph text replaces `text` with a non-empty `paragraphs` list of strings or objects — empty paragraph strings are preserved as blank lines — (`align` plus exactly one of `text` or non-empty `runs`; runs carry required `text` and optional `bold`, `italic`, `underline`, `strike`, `color`, `font_size`, one-typeface `font_family`, `lang`, `alt_lang`); unknown fields, wrong types, empty runs, multi-typeface families, and unsupported colors fail. Per-side borders use `borders.left|right|top|bottom|diagonal_down|diagonal_up` as `{ "style": "none" }` or `{ "style": "solid", "color": "#RRGGBB", "width": <positive-px> }`, overriding a uniform `border_color` / `border_width` on style or cell. A missing `lang` derives `zh-CN` for CJK and `en-US` otherwise. `style.band_row: false` disables banding and materialized alternating fills. Typography mirrors the fallback: `style.font_family` and `style.font_size` from the drawn table text, `style.header_font_size` or per-cell `font_size` only where the fallback differs; with no explicit table font, Default uses the deck body family and anchor, Quick its active-context values.
@@ -40,4 +40,4 @@ Cells accept `text`, `fill`, `fill_opacity`, `color`, `align` (`l` / `ctr` / `r`
## §2 Chart chrome, typography, and color
-SVG-first metadata matches the fallback chrome; JSON-first owns it. Metadata sizes use SVG px (`1px = 0.75pt`); `style.font_family` and `title_font_size`, `subtitle_font_size`, `axis_font_size`, `axis_title_font_size`, `legend_font_size`, `note_font_size` are required only when native must preserve typography an SVG-first fallback cannot supply unambiguously (JSON-first never infers from its preview). A string or unbounded-object `title` becomes native `c:title` (`subtitle` line two); a title object with complete `x`, `y`, `width`, `height` becomes a companion text box (partial bounds or `subtitle` fail); `name` names the object; `title`, `subtitle`, and axis-title objects accept `text`, `font_size`, `font_family`, `color`; the checker rejects SVG-first title/axis text absent from the fallback. Axis titles are explicit via `axis_titles` (`category`, `value`, `x`, `y`, `secondary_value`) or the root aliases `category_axis_title`, `value_axis_title`, `x_axis_title`, `y_axis_title`, `secondary_value_axis_title`; `show_value_axis_labels: false` hides numeric tick labels (e.g. a radar without radial coordinates); native legends are opt-in via `show_legend: true` and `legend_position` (`bottom` default; `top` / `left` / `right`). SVG-first parity reads the fallback literally — `style.axis_color` is the dominant stroke among elements whose id or class names `axis`, `style.grid_color` the dominant stroke among those naming `grid` / `gridline`, and a role with no labeled stroke falls back to the marker's dominant stroke (axis and grid lines in different colors need those labels or one steals the other's dominant); bar/column fills that are not a series or point colour, line-chart circles with no `lineMarker` / `point_colors` (or in a colour neither carries), translucent area fills without `fill_opacity`, a stroked line or markers over a single-type area, and a bar/column fallback whose first and last category labels contradict the resolved `axes.category.reverse` are each reported; numbers match in written form (`286.20` ≠ `286.2`; a payload `73.0` is stored as `73` and renders as `73` under General, so a fallback that shows `73.0` needs `number_format: "0.0"`; a `number_format` on `data_labels` or an axis makes its rendered form, such as `28.0` for `0.0`, an accepted variant), and marker text that is not a category, data label, axis label, or legend entry needs a companion entry. Companion text (`caption`, `source`, `note`, `notes`, `footnote`, `footnotes`) exports as editable text boxes — strings or objects with `text`, `x`, `y`, `width`, `height` (slide coordinates), `font_size`, `color`, `align`, `bold`; use it for captions, sources, center labels, and annotations, and `data_labels` for point values. `style.colors` sets series colors (treemap/sunburst tile palette in order); the exporter writes explicit chart-area fill, plot-area fill, axis, gridline, and label colors (SVG-first infers them from the largest panel `<rect>`, text, and strokes; JSON-first from JSON or stable defaults), overridable under `style` with `chart_area_fill`, `plot_area_fill`, `text_color`, `axis_color`, `grid_color` (`"none"` for transparent); generated payloads use uppercase `#RRGGBB`, with `#RGB`, `rgb()`, and CSS names normalized. Negative bars keep the series fill. The final checker reports every SVG-first parity finding as a warning tagged `(blocks --native-charts-and-tables export)`; that export refuses the same findings as errors, so clear them before exporting the native variant.
+SVG-first metadata matches the fallback chrome; JSON-first owns it. Metadata sizes use SVG px (`1px = 0.75pt`); `style.font_family` and `title_font_size`, `subtitle_font_size`, `axis_font_size`, `axis_title_font_size`, `legend_font_size`, `note_font_size` are required only when native must preserve typography an SVG-first fallback cannot supply unambiguously (JSON-first never infers from its preview). A string or unbounded-object `title` becomes native `c:title` (`subtitle` line two); a title object with complete `x`, `y`, `width`, `height` becomes a companion text box (partial bounds or `subtitle` fail); `name` names the object; `title`, `subtitle`, and axis-title objects accept `text`, `font_size`, `font_family`, `color`; the checker rejects SVG-first title/axis text absent from the fallback. Axis titles are explicit via `axis_titles` (`category`, `value`, `x`, `y`, `secondary_value`) or the root aliases `category_axis_title`, `value_axis_title`, `x_axis_title`, `y_axis_title`, `secondary_value_axis_title`; `show_value_axis_labels: false` hides numeric tick labels (e.g. a radar without radial coordinates); native legends are opt-in via `show_legend: true` and `legend_position` (`bottom` default; `top` / `left` / `right`). SVG-first parity reads the fallback literally — `style.axis_color` is the dominant stroke among elements whose id or class names `axis`, `style.grid_color` the dominant stroke among those naming `grid` / `gridline`, and a role with no labeled stroke falls back to the marker's dominant stroke (axis and grid lines in different colors need those labels or one steals the other's dominant); bar/column fills that are not a series or point colour, line-chart circles with no `lineMarker` / `point_colors` (or in a colour neither carries), translucent area fills without `fill_opacity`, a stroked line or markers over a single-type area, and a bar/column fallback whose first and last category labels contradict the resolved `axes.category.reverse` are each reported; numbers match in written form (`286.20` ≠ `286.2`; a payload `73.0` is stored as `73` and renders as `73` under General, so a fallback that shows `73.0` needs `number_format: "0.0"`; a `number_format` on `data_labels` or an axis makes its rendered form, such as `28.0` for `0.0`, an accepted variant), and marker text that is not a category, data label, axis label, or legend entry needs a companion entry. Companion text (`caption`, `source`, `note`, `notes`, `footnote`, `footnotes`) exports as editable text boxes — strings or objects with `text`, `x`, `y`, `width`, `height` (slide coordinates), `font_size`, `color`, `align`, `bold`; use it for captions, sources, center labels, and annotations, and `data_labels` for point values. On an SVG-first marker a companion whose text appears exactly once in the fallback is placed from that `<text>`: the box top sits one em above its baseline, `text-anchor` decides which edge `x` names and the paragraph alignment, and the payload keeps only `width` — so a `y` copied from the SVG baseline does not push the box onto the plot. JSON-first and unmatched companions use the payload box. `style.colors` sets series colors (treemap/sunburst tile palette in order); the exporter writes explicit chart-area fill, plot-area fill, axis, gridline, and label colors (SVG-first infers them from the largest panel `<rect>`, text, and strokes; JSON-first from JSON or stable defaults), overridable under `style` with `chart_area_fill`, `plot_area_fill`, `text_color`, `axis_color`, `grid_color` (`"none"` for transparent); generated payloads use uppercase `#RRGGBB`, with `#RGB`, `rgb()`, and CSS names normalized. Negative bars keep the series fill. The final checker reports every SVG-first parity finding as a warning tagged `(blocks --native-charts-and-tables export)`; that export refuses the same findings as errors, so clear them before exporting the native variant.
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
index 7445cebf..97283386 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
@@ -410,6 +410,7 @@ def _build_native_chart(elem: ET.Element, ctx: ConvertContext, payload: dict[str
or _chart_title_is_bounded(payload)
),
include_subtitle_as_caption=chart_data["kind"] == "chartex",
+ fallback=None if native_json_is_authoritative(elem) else elem,
)
if not companions:
return ShapeResult(xml=chart_frame_xml, bounds_emu=chart_bounds)
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_style.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_style.py
index aada79f8..a3c3041a 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_style.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_style.py
@@ -12,6 +12,8 @@ from .marker_attributes import native_import_source, native_json_is_authoritativ
from ..drawingml.context import ConvertContext, ShapeResult
from ..drawingml.utils import (
_xml_escape,
+ ctx_x,
+ ctx_y,
detect_text_lang,
parse_font_family,
px_to_emu,
@@ -1542,10 +1544,27 @@ def _chart_companion_shapes(
title_font_size: int,
include_title: bool,
include_subtitle_as_caption: bool,
+ fallback: ET.Element | None = None,
) -> list[ShapeResult]:
- """Build editable companion text with its resolved slide-space bounds."""
+ """Build editable companion text with its resolved slide-space bounds.
+
+ With an SVG-first ``fallback``, a companion whose text appears exactly
+ once in the fallback takes that text's position: the box top sits one
+ em above the baseline and the anchor decides which edge ``x`` names,
+ so a payload ``y`` copied from the SVG baseline cannot land the box on
+ the plot.
+ """
if _chart_title_is_bounded(payload):
include_title = True
+ fallback_texts = (
+ [
+ record
+ for record in _fallback_text_records(fallback)
+ if record.x is not None and record.y is not None
+ ]
+ if fallback is not None
+ else []
+ )
entries = _chart_companion_entries(
payload,
include_title=include_title,
@@ -1589,6 +1608,24 @@ def _chart_companion_shapes(
ext_cx = chart_ext_cx
ext_cy = px_to_emu(16)
below_index += 1
+ matches = [
+ record for record in fallback_texts
+ if record.text == _normalized_fallback_text(text)
+ ]
+ if len(matches) == 1 and ctx is not None:
+ record = matches[0]
+ font_px = font_size / 100 / 0.75
+ anchor_x = ctx_x(record.x, ctx)
+ baseline_y = ctx_y(record.y, ctx)
+ width_px = ext_cx / px_to_emu(1)
+ left_px = {
+ "middle": anchor_x - width_px / 2,
+ "end": anchor_x - width_px,
+ }.get(record.anchor, anchor_x)
+ off_x = _powerpoint_emu_value(px_to_emu(left_px), "companion text x")
+ off_y = _powerpoint_emu_value(px_to_emu(baseline_y - font_px), "companion text y")
+ ext_cy = px_to_emu(font_px * 1.5)
+ align = {"middle": "ctr", "end": "r"}.get(record.anchor, "l")
text_xml = _text_box_xml(
ctx,
text=text,
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
index 9cad4549..5933cd6d 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+import re
from dataclasses import dataclass
from typing import Any
from xml.etree import ElementTree as ET
@@ -16,6 +17,7 @@ from ..drawingml.utils import (
_xml_escape,
detect_text_lang,
font_px_to_hpt,
+ px_to_emu,
text_has_rtl_characters,
text_uses_rtl,
)
@@ -1412,7 +1414,44 @@ def _table_padding_value(
return _powerpoint_emu(pixels, f"table {side} padding")
-def _table_padding_attrs(cell_data: dict[str, Any], style: dict[str, Any]) -> str:
+_TEXT_LINE_FACTOR = 1.4 # PowerPoint line box per em, covering CJK faces' tall metrics
+
+
+def _table_text_height_emu(paragraphs_xml: str) -> int:
+ """Estimate the vertical space the cell's paragraphs need in PowerPoint."""
+ sizes = [int(value) for value in re.findall(r' sz="(\d+)"', paragraphs_xml)]
+ paragraph_count = max(1, paragraphs_xml.count("<a:p>"))
+ if not sizes:
+ return 0
+ line_px = max(sizes) / 100 / 0.75 * _TEXT_LINE_FACTOR
+ return px_to_emu(line_px * paragraph_count)
+
+
+def _table_padding_attrs(
+ cell_data: dict[str, Any],
+ style: dict[str, Any],
+ *,
+ row_height: int | None = None,
+ paragraphs_xml: str | None = None,
+) -> str:
+ values = {
+ side: _table_padding_value(cell_data, style, side)
+ for side in ("left", "right", "top", "bottom")
+ }
+ # An authored row height is geometry; vertical padding is style. When the
+ # text line plus both margins would exceed the row, PowerPoint grows the
+ # row instead, so shrink the margins to what the row can hold.
+ if row_height is not None and paragraphs_xml is not None:
+ top = values["top"] or 0
+ bottom = values["bottom"] or 0
+ room = row_height - _table_text_height_emu(paragraphs_xml)
+ if top + bottom > room > 0:
+ scale = room / (top + bottom)
+ values["top"] = int(top * scale) if values["top"] is not None else None
+ values["bottom"] = int(bottom * scale) if values["bottom"] is not None else None
+ elif top + bottom > room:
+ values["top"] = 0 if values["top"] is not None else None
+ values["bottom"] = 0 if values["bottom"] is not None else None
attrs = []
for attr, side in (
("marL", "left"),
@@ -1420,7 +1459,7 @@ def _table_padding_attrs(cell_data: dict[str, Any], style: dict[str, Any]) -> st
("marT", "top"),
("marB", "bottom"),
):
- value = _table_padding_value(cell_data, style, side)
+ value = values[side]
if value is not None:
attrs.append(f'{attr}="{value}"')
return (" " + " ".join(attrs)) if attrs else ""
@@ -1893,7 +1932,7 @@ def _build_native_table(elem: ET.Element, ctx: ConvertContext, payload: dict[str
anchor_attr = f' anchor="{_table_anchor(cell_data, style)}"'
tc_pr_attrs = (
f'{anchor_attr}'
- f'{_table_padding_attrs(cell_data, style)}'
+ f'{_table_padding_attrs(cell_data, style, row_height=row_heights[row_idx], paragraphs_xml=paragraphs_xml)}'
f'{_table_cell_extra_attrs(cell_data)}'
)
border_xml = _table_border_xml(
diff --git a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
index 568d4874..21a41470 100644
--- a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
+++ b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
@@ -286,5 +286,53 @@ class SpacingTests(unittest.TestCase):
self.assertIn('<c:majorTickMark val="out"/>', val_ax)
+class CompanionPlacementTests(unittest.TestCase):
+ def test_svg_first_companion_sits_on_the_fallback_baseline(self) -> None:
+ import json
+ import re
+ import tempfile
+
+ from svg_to_pptx.drawingml.converter import convert_svg_to_slide_shapes
+
+ payload = {
+ "x": 100, "y": 100, "width": 600, "height": 300,
+ "name": "chart-note",
+ "type": "column",
+ "categories": ["A", "B"],
+ "series": [{"name": "S", "values": [1, 2]}],
+ "plot_area": {"x": 140, "y": 130, "width": 540, "height": 250},
+ "style": {"colors": ["#111111"], "text_color": "#111111"},
+ # y copied from the SVG baseline: without fallback anchoring the
+ # box would start at the baseline and cover the plot top.
+ "notes": [{"text": "Unit note", "x": 140, "y": 120, "width": 200, "height": 24, "font_size": 18}],
+ }
+ svg = (
+ f'<svg xmlns="{SVG_NS}" viewBox="0 0 1280 720">'
+ '<g id="chart-note" data-pptx-replace-with="chart">'
+ f'<metadata type="application/json">{json.dumps(payload)}</metadata>'
+ '<rect x="140" y="130" width="540" height="250" fill="#FFFFFF"/>'
+ '<text x="140" y="120" font-size="18" fill="#111111">Unit note</text>'
+ '<text x="410" y="400" font-size="18" fill="#111111">A</text>'
+ '<text x="410" y="400" font-size="18" fill="#111111">B</text>'
+ "</g></svg>"
+ )
+ from svg_to_pptx.native_objects.fallback_hash import stamp_native_fallback_baseline
+
+ root = ET.fromstring(svg)
+ stamp_native_fallback_baseline(root.find(f"{{{SVG_NS}}}g"), document_root=root)
+ svg = ET.tostring(root, encoding="unicode")
+ with tempfile.TemporaryDirectory() as tmp:
+ path = Path(tmp) / "01.svg"
+ path.write_text(svg, encoding="utf-8")
+ slide_xml, *_ = convert_svg_to_slide_shapes(
+ path,
+ resource_root=Path(tmp),
+ native_objects=True,
+ )
+ note = slide_xml[slide_xml.index("Chart Note"):]
+ off_y = int(re.search(r'<a:off x="\d+" y="(\d+)"/>', note).group(1))
+ self.assertEqual(off_y, 102 * 9525) # baseline 120px minus one 18px em
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/skills/ppt-master/scripts/tests/test_native_chart_table_parity.py b/skills/ppt-master/scripts/tests/test_native_chart_table_parity.py
index bf5d67ef..c7286e8f 100644
--- a/skills/ppt-master/scripts/tests/test_native_chart_table_parity.py
+++ b/skills/ppt-master/scripts/tests/test_native_chart_table_parity.py
@@ -499,3 +499,18 @@ class NativeTableFillAndTextDefaultsTests(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
+
+class TableRowHeightTests(unittest.TestCase):
+ def test_vertical_padding_shrinks_to_the_authored_row_height(self) -> None:
+ from svg_to_pptx.native_objects.table import _table_padding_attrs
+
+ cell = {"padding": 16}
+ paragraphs = '<a:p><a:r><a:rPr lang="en-US" sz="1500"/><a:t>x</a:t></a:r></a:p>'
+ loose = _table_padding_attrs(cell, {}, row_height=914400, paragraphs_xml=paragraphs)
+ self.assertIn('marT="152400" marB="152400"', loose)
+ tight = _table_padding_attrs(cell, {}, row_height=457200, paragraphs_xml=paragraphs)
+ top = int(tight.split('marT="')[1].split('"')[0])
+ self.assertLess(top, 152400)
+ self.assertGreater(top, 0)
+ self.assertIn('marL="152400" marR="152400"', tight)