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(svg-to-pptx): preserve editable text layout and transformed strokes

hugohe3f1e180e97f42
diff --git a/docs/faq.md b/docs/faq.md
index 845b20f7..4123656f 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -81,7 +81,7 @@ Yes. The only PPTX export route in the SVG pipeline is PPT Master's own `svg_out
## Q: Why is one paragraph split into multiple text boxes? Can I get one text box per paragraph instead?
-By default, mergeable body-text paragraphs export as one editable PowerPoint text frame with multiple paragraphs. Resizing the box reflows text inside it.
+By default, mergeable body text exports as one editable PowerPoint text frame. Authored SVG visual lines remain hard line breaks inside that frame; larger gaps and list items remain separate paragraphs. Only text explicitly marked with `data-pptx-break="soft"` joins authored rows during export. The frame still uses normal PowerPoint wrapping, so deleting a hard break or editing the text reflows it within the frame.
If you need strict line-layout fidelity, re-export with `--no-merge`:
@@ -91,7 +91,7 @@ python3 skills/ppt-master/scripts/svg_to_pptx.py <project_path> --no-merge
With `--no-merge`, every visual line becomes its own PowerPoint text frame. This preserves the SVG's exact line layout pixel-for-pixel, which matters for covers, charts, tables, and any page with tight typographic alignment.
-**Trade-off**: default paragraph merging lets PowerPoint wrap merged paragraphs to a different line count than the SVG source. Best for long-form body text (abstracts, multi-paragraph sections, reference lists); use `--no-merge` for layout-tight pages. The detection is conservative — mixed-layout `<text>` falls through to the per-line path automatically.
+**Trade-off**: default merging keeps one editable frame and preserves authored line boundaries. Use `--no-merge` only when every visual line must also remain an independently movable text box. The detection is conservative — mixed-layout `<text>` falls through to the per-line path automatically.
When you're chatting with the AI, you can also just ask for strict line fidelity on layout-sensitive pages — the AI will add `--no-merge` when re-exporting.
diff --git a/docs/zh/faq.md b/docs/zh/faq.md
index 3d261342..9db945cb 100644
--- a/docs/zh/faq.md
+++ b/docs/zh/faq.md
@@ -83,7 +83,7 @@ Step 7 仍会强制生成 `svg_final/`。其中每页都是自包含的视觉预
## Q: 为什么一段正文被拆成了好几个文本框?能不能一段一个文本框?
-默认会把可合并的正文段落导出成一个可编辑的 PowerPoint 文本框,内部保留多个段落。**拉伸框时文字会在框内自动重排**。
+默认会把可合并的正文导出成一个可编辑的 PowerPoint 文本框。SVG 中已经排好的视觉行会在框内保留为硬换行;较大行距和列表项保留为独立段落。只有显式标记 `data-pptx-break="soft"` 的文字才会在导出时拼接视觉行。文本框仍保留 PowerPoint 的正常自动换行,因此删除硬换行或修改文字后,会按文本框宽度重新排版。
如果你需要严格保持逐行版式,重新导出时加上 `--no-merge`:
@@ -93,7 +93,7 @@ python3 skills/ppt-master/scripts/svg_to_pptx.py <project_path> --no-merge
使用 `--no-merge` 时,SVG 里的每一视觉行都会变成一个独立的 PowerPoint 文本框。这样能**逐像素保留 SVG 的版式**,适合封面、图表、表格、以及任何对版式精度敏感的页面。
-**代价**:默认段落合并后,PowerPoint 自动换行的行数可能与原 SVG 不一致。默认更适合正文密集型页面(abstract、多段落章节、参考文献等);版式敏感页面使用 `--no-merge`。判定足够保守——非段落型 `<text>` 会自动落回按行拆框路径。
+**代价**:默认合并会保留一个可编辑文本框和原始视觉行边界;只有需要让每一视觉行都能单独移动时才使用 `--no-merge`。判定足够保守——非段落型 `<text>` 会自动落回按行拆框路径。
跟 AI 对话时也可以直接说:"这个页面要严格保持逐行版式" —— AI 重新导出时会加上 `--no-merge`。
diff --git a/skills/ppt-master/SKILL.md b/skills/ppt-master/SKILL.md
index 9842d466..22c48751 100644
--- a/skills/ppt-master/SKILL.md
+++ b/skills/ppt-master/SKILL.md
@@ -860,14 +860,17 @@ python3 ${SKILL_DIR}/scripts/svg_to_pptx.py <project_path>
> section and use page-role compatibility families.
> **Paragraph editability vs line fidelity** — by default, mergeable dy-stacked
-> paragraph blocks collapse into one editable PowerPoint text frame with multiple
-> `<a:p>`, improving body-text editing and resize/reflow behavior. Add `--no-merge`
-> only when the user explicitly asks for strict line-layout fidelity or when a
-> layout-tight page must keep every dy-stacked line as its own text frame. The
-> merge detector is conservative; mixed-layout text falls back to per-line
-> frames. A multiline `data-pptx-placeholder` must remain one native text frame;
-> do not combine it with `--no-merge`. Strict-line text stays Slide-local rather
-> than claiming one PowerPoint placeholder.
+> text collapses into one editable PowerPoint text frame. Evenly spaced authored
+> visual lines stay in one paragraph as hard line breaks; larger gaps and list
+> items start new paragraphs. Only an explicit `data-pptx-break="soft"` joins
+> SVG-authored rows during export. The merged frame keeps normal PowerPoint
+> wrapping, so deleting a hard break or editing the text reflows it within the
+> frame. Add `--no-merge` only when the user explicitly asks for every
+> dy-stacked line to remain its own text frame. The merge detector is
+> conservative; mixed-layout text falls back to per-line frames. A multiline
+> `data-pptx-placeholder` must remain one native text frame; do not combine it
+> with `--no-merge`. Strict-line text stays Slide-local rather than claiming one
+> PowerPoint placeholder.
> **Native table/chart objects** — supported data charts and pure text-grid
> tables carry `data-pptx-native` markers by default (Executor transcribes
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 645da79e..ac383d52 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -415,7 +415,7 @@ These forms are needed only when the stated PPT behavior matters:
| Desired behavior | Required form |
|---|---|
-| One editable PPT text frame with mixed inline formatting | Put the logical line in one `<text>` with non-positional `<tspan>` children. A `<tspan>` with `x`/`y`/`dy` starts a new positioned line; evenly `dy`-stacked lines that repeat the parent `<text>`'s `x` **merge into one frame as multiple paragraphs** (the default paragraph-merge), while an irregular gap or a mismatched `x` flattens to separate frames. Separate `<text>` elements stay valid when separate frames are intended. |
+| One editable PPT text frame with mixed inline formatting | Put the logical line in one `<text>` with non-positional `<tspan>` children. A `<tspan>` with `x`/`y`/`dy` starts a new positioned line; evenly `dy`-stacked lines that repeat the parent `<text>`'s `x` merge into one frame with hard line breaks. A larger accepted gap or list marker starts a new paragraph; `data-pptx-break="soft"` explicitly joins authored rows. The merged frame keeps normal PowerPoint wrapping for later edits. An unmergeable gap or mismatched `x` flattens to separate frames. Separate `<text>` elements stay valid when separate frames are intended. |
| Stable object grouping or object-level animation anchor | Wrap the intended object in `<g id="...">`. Content grouping is **mandatory** per §4.3 — a top-level `<g id>` is also the animation anchor; it is not an optional convenience. |
| Native PowerPoint background promotion | Use a direct, full-canvas, solid `<rect>` without transform, filter, clip, rounding, or visible stroke. Other SVG backgrounds remain ordinary slide shapes. Template routes add the ownership metadata in §7. |
| Free-design PowerPoint Layout | Use the locked `pptx_layouts` key/name plus the explicit metadata in §7. A legacy baseline project without that section uses §4.1 page-family/chrome hints. No route infers visual similarity. |
diff --git a/skills/ppt-master/scripts/docs/svg-pipeline.md b/skills/ppt-master/scripts/docs/svg-pipeline.md
index dee9287e..a2ef773f 100644
--- a/skills/ppt-master/scripts/docs/svg-pipeline.md
+++ b/skills/ppt-master/scripts/docs/svg-pipeline.md
@@ -57,10 +57,10 @@ Behavior:
- `backup/<timestamp>/svg_output/` — copy of Executor SVG source, always written so the pptx can be rebuilt via `finalize_svg → svg_to_pptx` without re-running the LLM
- `finalize_svg.py` always creates `svg_final/` before export. This directory is the self-contained SVG visual preview; it is not packaged as a second PPTX.
- Explicit `-o/--output` changes the native PPTX destination and skips `backup/`.
-- Paragraph merging is enabled by default and trades some SVG line-layout fidelity for PowerPoint editability:
- - Default: mergeable paragraph blocks (same x, dy clustered around one base line-height, optional larger gap for paragraph breaks) collapse into one editable text frame with multiple `<a:p>` and precise `<a:lnSpc>` / `<a:spcBef>`. Resizing the box reflows text inside it.
+- Paragraph merging is enabled by default and preserves authored line boundaries inside one editable PowerPoint text frame:
+ - Default: evenly spaced visual lines become hard `<a:br>` boundaries inside one `<a:p>`; larger accepted gaps and list items start new `<a:p>` elements with precise `<a:lnSpc>` / `<a:spcBef>`.
+ - Only explicit `data-pptx-break="soft"` content joins authored rows without a break. The merged frame still uses normal PowerPoint wrapping, so deleting a hard break or editing the text reflows it within the frame.
- With `--no-merge`: every dy-stacked `<tspan>` becomes its own text frame — exact SVG line layout is preserved but a 12-line paragraph is 12 separate textboxes
- - Side effect: PowerPoint may wrap merged paragraphs to a different line count than the SVG source. Long body text (abstracts, multi-paragraph sections, reference lists) usually benefits from the default; pages with tight typographic alignment (covers, charts, tables) usually want `--no-merge`
- Mergeable detection is conservative: only fires when the children form a clean paragraph block; mixed-layout `<text>` falls through to the default per-line path
- Native release export reads `svg_output/`. `-s final` is an explicit diagnostic override for comparing conversion behavior against post-processed SVGs; it does not change artifact ownership or create a supported release path.
- `svg_final/` may be opened directly or inserted into PowerPoint as an SVG picture. PowerPoint's manual Convert-to-Shape operation is outside the compatibility contract.
diff --git a/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py b/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
index f2007922..3a88a4ee 100644
--- a/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
+++ b/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
@@ -203,10 +203,9 @@ def copy_text_attrs(
PARAGRAPH_MARK_ATTR = "data-paragraph-line-height"
PARAGRAPH_SPACE_BEFORE_ATTR = "data-paragraph-space-before"
PARAGRAPH_TOP_INSET_ATTR = "data-paragraph-top-inset"
-# Marks a line-break tspan as a SOFT break inside the current paragraph
-# (SVG used dy to simulate text wrapping; the downstream converter should
-# merge its runs into the previous <a:p> rather than start a new one).
-PARAGRAPH_SOFT_BREAK_ATTR = "data-paragraph-soft-break"
+# Internal line-break marker consumed by the DrawingML converter. Explicit
+# soft joins remain represented solely by author-owned data-pptx-break="soft".
+PARAGRAPH_LINE_BREAK_ATTR = "data-paragraph-line-break"
# Tolerance for detecting "base line-height" vs "paragraph gap": dy values
# within ±DY_TOLERANCE_PX of each other are considered the same line-height.
@@ -283,19 +282,25 @@ def _classify_paragraph_block(
text_el: ET.Element,
is_svg_tag,
is_new_line_tspan,
-) -> tuple[float, list[float], list[bool], list[list[ET.Element]], ET.Element | None] | None:
+) -> tuple[
+ float,
+ list[float],
+ list[bool],
+ list[list[ET.Element]],
+ ET.Element | None,
+] | None:
"""Detect a mergeable paragraph block.
Returns ``(base_line_height_px, extra_space_before_px_per_line,
- is_soft_break_per_line, line_groups, synthetic_first_line)`` if the children
+ is_line_break_per_line, line_groups, synthetic_first_line)`` if the children
form a mergeable paragraph. Each list has one entry per direct-child tspan
(line), including a synthetic first line when the source used leading text:
- extra_space_before_px_per_line[i]: extra px above base line-height,
used as <a:spcBef> on the downstream <a:p>. First entry is 0.
- - is_soft_break_per_line[i]: True if this line should merge into the
- previous <a:p> (SVG dy was simulating word-wrap); False if it starts
- a fresh <a:p>. First entry is always False (paragraph head).
+ - is_line_break_per_line[i]: True if the line stays in the previous
+ <a:p> behind an explicit line break; False if it starts a fresh <a:p>.
+ First entry is always False (paragraph head).
Conditions (all must hold):
- No direct text under <text>, except simple leading text that can be
@@ -376,7 +381,7 @@ def _classify_paragraph_block(
return None
extras: list[float] = [0.0] # first line never has space-before
- soft_breaks: list[bool] = [False] # first line starts a paragraph
+ line_breaks: list[bool] = [False] # first line starts a paragraph
for idx, d in enumerate(dy_values[1:], start=1):
if d + DY_TOLERANCE_PX < base:
return None # below base — line overlap, not a paragraph
@@ -385,25 +390,24 @@ def _classify_paragraph_block(
extra = d - base
if extra < 0:
extra = 0.0
- # dy at the base line-height = soft break (SVG was simulating wrap);
- # dy strictly greater than base = hard paragraph break. List markers
- # also start a fresh paragraph so bullet/ordered items do not merge
- # into the previous item when exported to PowerPoint.
- is_soft = (
+ # Equal-dy visual lines are authored line breaks, not permission for
+ # Office to reflow them. Larger gaps and list markers start a fresh
+ # paragraph so spacing and bullet semantics remain independent.
+ is_line = (
abs(extra) <= DY_TOLERANCE_PX
and not _starts_with_list_marker(line_groups[idx])
)
- extras.append(0.0 if is_soft else extra)
- soft_breaks.append(is_soft)
+ extras.append(0.0 if is_line else extra)
+ line_breaks.append(is_line)
- return base, extras, soft_breaks, line_groups, synthetic_first
+ return base, extras, line_breaks, line_groups, synthetic_first
def _emit_mergeable_paragraph(
text_el: ET.Element,
base_dy: float | None,
extras: list[float],
- soft_breaks: list[bool],
+ line_breaks: list[bool],
line_groups: list[list[ET.Element]],
synthetic_first: ET.Element | None = None,
) -> None:
@@ -412,8 +416,7 @@ def _emit_mergeable_paragraph(
The base line-height goes on the parent <text> via PARAGRAPH_MARK_ATTR.
Each direct-child tspan is normalized: x/y/dy stripped; inline-run
styling and nested tspans are preserved. Per-tspan attrs:
- - PARAGRAPH_SOFT_BREAK_ATTR="1" on tspans that should be appended to
- the previous <a:p> downstream (SVG used dy to simulate wrap)
+ - PARAGRAPH_LINE_BREAK_ATTR="1" on authored visual line breaks
- PARAGRAPH_SPACE_BEFORE_ATTR on tspans that open a new paragraph
with an extra gap (omitted when 0)
"""
@@ -447,19 +450,21 @@ def _emit_mergeable_paragraph(
text_el.remove(child)
extras_iter = iter(extras)
- soft_iter = iter(soft_breaks)
+ line_break_iter = iter(line_breaks)
for tspan in normalized_lines:
for k in ("x", "y", "dy"):
if k in tspan.attrib:
del tspan.attrib[k]
+ tspan.attrib.pop(PARAGRAPH_LINE_BREAK_ATTR, None)
+ tspan.attrib.pop(PARAGRAPH_SPACE_BEFORE_ATTR, None)
try:
extra = next(extras_iter)
- soft = next(soft_iter)
+ line_break = next(line_break_iter)
except StopIteration:
extra = 0.0
- soft = False
- if soft:
- tspan.set(PARAGRAPH_SOFT_BREAK_ATTR, "1")
+ line_break = False
+ if line_break:
+ tspan.set(PARAGRAPH_LINE_BREAK_ATTR, "1")
elif extra > 1e-6:
tspan.set(PARAGRAPH_SPACE_BEFORE_ATTR, format_number(extra))
@@ -528,12 +533,15 @@ def _emit_explicit_paragraph(
line_groups = [list(line.elements) for line in contract.visual_lines]
extras = [line.space_before for line in contract.visual_lines]
- soft_breaks = [line.break_kind == "soft" for line in contract.visual_lines]
+ line_breaks = [
+ line.break_kind == "line"
+ for line in contract.visual_lines
+ ]
_emit_mergeable_paragraph(
text_el,
contract.base_line_height,
extras,
- soft_breaks,
+ line_breaks,
line_groups,
)
@@ -563,12 +571,13 @@ def flatten_text_with_tspans(
"""Flatten multi-line tspan text into independent text nodes when needed.
When ``merge_paragraphs`` is True, mergeable paragraph blocks (same x,
- dy clustered around one base line-height) are kept as a single <text>
- so downstream conversion emits one editable PowerPoint text frame
- with multiple <a:p>. Default False preserves the original behavior:
- every line-break tspan becomes its own <text>, matching the SVG's
- pixel-fidelity contract. ``enforce_native_carrier=False`` is reserved for
- that on-disk visual preview; PPTX export keeps the native carrier guard.
+ dy clustered around one base line-height) remain one <text>. Downstream
+ conversion emits one editable PowerPoint text frame with authored hard
+ line breaks and paragraph gaps. Default False preserves the original
+ behavior: every positioned tspan becomes its own <text>, matching the
+ SVG's strict line-layout contract. ``enforce_native_carrier=False`` is
+ reserved for that on-disk visual preview; PPTX export keeps the native
+ carrier guard.
"""
root = tree.getroot()
if root in _NORMALIZED_ROOTS:
@@ -657,22 +666,22 @@ def flatten_text_with_tspans(
# Paragraph fast-path (opt-in via merge_paragraphs=True): if the
# children form a mergeable paragraph (same x, dy clustered around
# one base line-height with optional paragraph gaps, no nested
- # positional tspans), keep as one <text> and let the downstream
- # converter emit multiple <a:p> runs. When disabled, every tspan
- # gets its own independent <text> so the SVG's exact line layout
- # is preserved in PowerPoint.
+ # positional tspans), keep one <text> and let the downstream converter
+ # preserve hard line/paragraph boundaries in one frame. When disabled,
+ # every tspan gets its own independent <text> so the SVG's exact line
+ # layout is preserved in PowerPoint.
if (
merge_paragraphs
and (contract is None or contract.requested_mode == "auto")
):
paragraph = _classify_paragraph_block(text_el, is_svg_tag, is_new_line_tspan)
if paragraph is not None:
- base_dy, extras, soft_breaks, line_groups, synthetic_first = paragraph
+ base_dy, extras, line_breaks, line_groups, synthetic_first = paragraph
_emit_mergeable_paragraph(
text_el,
base_dy,
extras,
- soft_breaks,
+ line_breaks,
line_groups,
synthetic_first=synthetic_first,
)
@@ -953,8 +962,9 @@ def main() -> None:
help=(
"Opt-in: merge mergeable paragraph blocks (same x, dy clustered "
"around one base line-height) into a single <text> annotated for "
- "downstream multi-<a:p> conversion. Default off — every line-break "
- "tspan becomes its own <text>, preserving SVG pixel fidelity."
+ "downstream hard-line and paragraph conversion. Default off — "
+ "every line-break tspan becomes its own <text>, preserving SVG "
+ "pixel fidelity."
),
)
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
index 5744655b..66a84e10 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
@@ -69,8 +69,8 @@ class ConvertContext:
# Explicit sidecar group ids may override the legacy chrome-name heuristic.
# Explicit structural layer/role/placeholder markers remain non-animatable.
animation_group_overrides: frozenset[str] = frozenset()
- # Default-on flag: merge mergeable paragraph blocks into one editable
- # text frame with multiple <a:p>. Disable it for strict line fidelity.
+ # Default-on flag: merge eligible dy-stacked lines into one editable text
+ # frame while preserving authored line and paragraph boundaries.
merge_paragraphs: bool = True
# Explicit opt-in: convert data-pptx-native table/chart marker groups to
# native PowerPoint graphicFrames. Default stays off to preserve SVG output.
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
index 82b5e8c5..69174209 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
@@ -1284,10 +1284,9 @@ def convert_svg_to_slide_shapes(
svg_path: Path to the SVG file.
slide_num: Slide number (for naming).
verbose: Print progress info.
- merge_paragraphs: When True, mergeable paragraph blocks (same x,
- dy clustered around one base line-height) become a single
- editable text frame with multiple <a:p>. Disable it to preserve
- the SVG's exact line layout (one textbox per line).
+ merge_paragraphs: When True, eligible dy-stacked lines become one
+ editable text frame with authored line and paragraph boundaries.
+ Disable it to keep one textbox per visual line.
image_optimize: Downsample oversized raster images for PPTX export.
image_max_dimension: Maximum optimized image dimension in pixels.
image_sizing: ``cap`` to only cap source dimensions, ``display`` to
@@ -1420,8 +1419,8 @@ def convert_svg_to_slide_shapes(
# and an x-anchored tspan would render in the wrong column. finalize_svg
# does the same flattening on disk; doing it here keeps native pptx output
# correct when reading raw svg_output/.
- # merge_paragraphs additionally folds mergeable paragraph blocks into a
- # single annotated <text> for downstream multi-<a:p> conversion.
+ # merge_paragraphs additionally keeps eligible blocks as one annotated
+ # <text> for downstream hard-line and paragraph conversion.
from ..tspan_flattener import flatten_positional_tspans
flattened = flatten_positional_tspans(
tree,
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 62ee3561..623db9f7 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -38,7 +38,7 @@ from .utils import (
rect_to_dml_xfrm,
combine_opacity, parse_hex_color, parse_svg_color,
resolve_url_id, get_effective_filter_id,
- parse_inline_style, parse_font_family, is_cjk_char, estimate_text_width,
+ parse_inline_style, parse_font_family, estimate_text_width,
detect_text_lang, font_px_to_hpt, resolve_text_run_fonts,
matrix_multiply, parse_transform_matrix, transform_point, _xml_escape,
)
@@ -2225,6 +2225,7 @@ _TEXT_CONTRACT_LINE_INDEX_ATTR = 'data-pptx-runtime-line-index'
_TEXT_CONTRACT_LINE_COUNT_ATTR = 'data-pptx-runtime-line-count'
_TEXT_CONTRACT_REASON_ATTR = 'data-pptx-runtime-mode-reason'
_TEXT_CONTRACT_TOP_INSET_ATTR = 'data-paragraph-top-inset'
+_PARAGRAPH_LINE_BREAK_ATTR = 'data-paragraph-line-break'
def _contract_round(
@@ -2469,28 +2470,14 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
paragraph_space_before.append(_f(sb_attr) if sb_attr else 0.0)
continue
- soft_break = child.get('data-paragraph-soft-break') == '1'
- if soft_break and paragraph_runs:
- # Append to the previous paragraph. A Latin line-wrap needs a
- # space to keep two words apart (SVG used a dy break, not
- # punctuation); CJK wraps mid-sentence with no inter-character
- # space, so a joining space there is a spurious artifact.
- prev = paragraph_runs[-1]
- prev_text = prev[-1]['text'] if prev else ''
- next_text = line_runs[0]['text']
- boundary_is_cjk = (
- (prev_text and is_cjk_char(prev_text[-1]))
- or (next_text and is_cjk_char(next_text[0]))
- )
- if prev and not prev_text.endswith(' ') \
- and not next_text.startswith(' ') \
- and not boundary_is_cjk:
- prev[-1] = {**prev[-1], 'text': prev_text + ' '}
- prev.extend(line_runs)
- else:
- paragraph_runs.append(line_runs)
- sb_attr = child.get('data-paragraph-space-before')
- paragraph_space_before.append(_f(sb_attr) if sb_attr else 0.0)
+ line_break = child.get(_PARAGRAPH_LINE_BREAK_ATTR) == '1'
+ if line_break and paragraph_runs:
+ paragraph_runs[-1].append({'_break': True})
+ paragraph_runs[-1].extend(line_runs)
+ continue
+ paragraph_runs.append(line_runs)
+ sb_attr = child.get('data-paragraph-space-before')
+ paragraph_space_before.append(_f(sb_attr) if sb_attr else 0.0)
if explicit_paragraph and paragraph_runs and not preserve_space:
_trim_explicit_paragraph_edges(paragraph_runs)
if not paragraph_runs:
@@ -2530,8 +2517,8 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
# Estimate text dimensions
if paragraph_runs is not None:
# Use the WIDEST visual line (per-tspan as the deck author drew it),
- # not the joined-up paragraph: soft-broken paragraphs concatenate
- # many lines into one <a:p>, and measuring the joined string would
+ # not the joined-up paragraph: explicit soft joins concatenate many
+ # visual lines into one <a:p>, and measuring the joined string would
# blow the textbox past the canvas.
text_width = max(visual_line_widths) if visual_line_widths else 0.0
# Total height assumes the visual line count from the SVG source;
@@ -2734,12 +2721,10 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
ext_cx = px_to_emu(box_w)
ext_cy = px_to_emu(box_h)
- # Paragraph mode: wrap="square" so text reflows when the user resizes,
- # but NO spAutoFit — otherwise PowerPoint expands the frame to fit a
- # long joined-up <a:p> on one line, blowing past the canvas. The cx we
- # write below is the longest source SVG line without single-line renderer
- # headroom; PowerPoint wraps long paragraphs inside this design width.
- # Single-line text keeps wrap="none" + spAutoFit for tight fidelity.
+ # Hard breaks preserve the authored initial layout; wrap="square" keeps the
+ # frame editable so deleting a break or changing text restores normal
+ # PowerPoint wrapping. Paragraph frames avoid spAutoFit, which could resize
+ # them past their SVG bounds. Single-line text keeps its tight-frame path.
if paragraph_runs is not None:
top_inset = 0
if explicit_paragraph:
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
index 87eb53ae..fcb71f8b 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
@@ -14,7 +14,7 @@ from .utils import (
SVG_NS, ANGLE_UNIT, DASH_PRESETS,
px_to_emu, _f, _get_attr, parse_svg_length,
combine_opacity, parse_inline_style, parse_opacity, parse_stop_style,
- parse_svg_color, resolve_url_id,
+ matrix_multiply, parse_svg_color, parse_transform_matrix, resolve_url_id,
)
@@ -444,6 +444,33 @@ def _emit_line_end(
return f'<a:{dml_tag} type="{typ}" w="{w_bucket}" len="{len_bucket}"/>'
+def _effective_stroke_scale(elem: ET.Element, ctx: ConvertContext) -> float:
+ """Approximate the effective SVG geometry transform as one line-width scale."""
+ vector_effect = _get_attr(elem, 'vector-effect', ctx)
+ if vector_effect and vector_effect.strip().lower() == 'non-scaling-stroke':
+ return 1.0
+
+ if ctx.use_transform_matrix:
+ matrix = ctx.transform_matrix
+ else:
+ matrix = (
+ ctx.scale_x, 0.0,
+ 0.0, ctx.scale_y,
+ ctx.translate_x, ctx.translate_y,
+ )
+
+ # The context already contains ancestor transforms. Shape converters apply
+ # the leaf element's transform directly, so compose that local matrix once.
+ transform = elem.get('transform')
+ if transform:
+ matrix = matrix_multiply(matrix, parse_transform_matrix(transform))
+
+ # DrawingML has one line width. sqrt(|det|) equals the uniform scale for a
+ # similarity transform and the principal-scale geometric mean otherwise.
+ a, b, c, d, _e, _f = matrix
+ return math.sqrt(abs(a * d - b * c))
+
+
def build_stroke_xml(
elem: ET.Element,
ctx: ConvertContext,
@@ -454,8 +481,8 @@ def build_stroke_xml(
if not stroke or stroke.strip().lower() in ('none', 'transparent'):
return '<a:ln><a:noFill/></a:ln>'
- width = parse_svg_length(_get_attr(elem, 'stroke-width', ctx), 1.0)
- width_emu = px_to_emu(width)
+ source_width = parse_svg_length(_get_attr(elem, 'stroke-width', ctx), 1.0)
+ width_emu = px_to_emu(source_width * _effective_stroke_scale(elem, ctx))
validate_ooxml_line_width(width_emu)
# Dash pattern
@@ -471,7 +498,7 @@ def build_stroke_xml(
parts = re.split(r'[\s,]+', dasharray.strip())
d_raw = float(parts[0])
sp_raw = float(parts[1]) if len(parts) > 1 else d_raw
- sw = max(width, 0.001)
+ sw = max(source_width, 0.001)
d_pct = int(d_raw / sw * 100000)
sp_pct = int(sp_raw / sw * 100000)
dash_xml = f'<a:custDash><a:ds d="{d_pct}" sp="{sp_pct}"/></a:custDash>'
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
index 508ba267..c04cfd1f 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
@@ -1183,6 +1183,18 @@ _TEMPLATE_PLACEHOLDER_PROMPTS = {
"footer": "Footer",
}
+_PARAGRAPH_BULLET_CHOICE_TAGS = {
+ f"{{{DML_NS}}}buNone",
+ f"{{{DML_NS}}}buAutoNum",
+ f"{{{DML_NS}}}buChar",
+ f"{{{DML_NS}}}buBlip",
+}
+_PARAGRAPH_PROPERTIES_TRAILING_TAGS = {
+ f"{{{DML_NS}}}tabLst",
+ f"{{{DML_NS}}}defRPr",
+ f"{{{DML_NS}}}extLst",
+}
+
def _template_runtime_slides(
extract_dir: Path,
@@ -1699,7 +1711,7 @@ def _placeholder_text_body(
tx_body.append(list_style)
paragraph = ET.SubElement(tx_body, f"{{{DML_NS}}}p")
- if item.placeholder == "body":
+ if item.placeholder in {"body", "subtitle"}:
paragraph_props = ET.SubElement(paragraph, f"{{{DML_NS}}}pPr")
ET.SubElement(paragraph_props, f"{{{DML_NS}}}buNone")
if item.placeholder in {"slide-number", "date"}:
@@ -1739,44 +1751,44 @@ def _placeholder_text_body(
return tx_body
-def _set_body_placeholder_no_bullets(
+def _insert_no_bullet_choice(paragraph_props: ET.Element) -> None:
+ """Disable inherited bullets unless the paragraph already chooses a mode."""
+ if any(
+ child.tag in _PARAGRAPH_BULLET_CHOICE_TAGS
+ for child in paragraph_props
+ ):
+ return
+ insert_at = next(
+ (
+ index
+ for index, child in enumerate(paragraph_props)
+ if child.tag in _PARAGRAPH_PROPERTIES_TRAILING_TAGS
+ ),
+ len(paragraph_props),
+ )
+ paragraph_props.insert(insert_at, ET.Element(f"{{{DML_NS}}}buNone"))
+
+
+def _set_placeholder_no_inherited_bullets(
shape: ET.Element,
item: TemplateElementSpec,
) -> None:
- """Preserve SVG prose instead of inheriting master bullet defaults."""
- if item.placeholder != "body":
+ """Keep prose bullet-free while preserving explicit subtitle bullets."""
+ if item.placeholder not in {"body", "subtitle"}:
return
tx_body = shape.find(f"{{{PML_NS}}}txBody")
if tx_body is None:
return
- bullet_tags = {
- f"{{{DML_NS}}}buNone",
- f"{{{DML_NS}}}buAutoNum",
- f"{{{DML_NS}}}buChar",
- f"{{{DML_NS}}}buBlip",
- }
- trailing_tags = {
- f"{{{DML_NS}}}tabLst",
- f"{{{DML_NS}}}defRPr",
- f"{{{DML_NS}}}extLst",
- }
for paragraph in tx_body.findall(f"{{{DML_NS}}}p"):
paragraph_props = paragraph.find(f"{{{DML_NS}}}pPr")
if paragraph_props is None:
paragraph_props = ET.Element(f"{{{DML_NS}}}pPr")
paragraph.insert(0, paragraph_props)
- for child in list(paragraph_props):
- if child.tag in bullet_tags:
- paragraph_props.remove(child)
- insert_at = next(
- (
- index
- for index, child in enumerate(paragraph_props)
- if child.tag in trailing_tags
- ),
- len(paragraph_props),
- )
- paragraph_props.insert(insert_at, ET.Element(f"{{{DML_NS}}}buNone"))
+ if item.placeholder == "body":
+ for child in list(paragraph_props):
+ if child.tag in _PARAGRAPH_BULLET_CHOICE_TAGS:
+ paragraph_props.remove(child)
+ _insert_no_bullet_choice(paragraph_props)
def _set_placeholder_theme_font_role(
@@ -1887,7 +1899,7 @@ def _patch_slide_placeholder(
raise TemplateStructureError(
f"Placeholder {item.element_id!r} has no non-visual properties"
)
- _set_body_placeholder_no_bullets(shape, item)
+ _set_placeholder_no_inherited_bullets(shape, item)
_set_placeholder_theme_font_role(shape, item, theme_font_spec)
for existing in list(nv_pr):
if existing.tag == f"{{{PML_NS}}}ph":
diff --git a/skills/ppt-master/scripts/svg_to_pptx/tspan_flattener.py b/skills/ppt-master/scripts/svg_to_pptx/tspan_flattener.py
index c782304c..641cdff0 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/tspan_flattener.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/tspan_flattener.py
@@ -38,8 +38,8 @@ def flatten_positional_tspans(
Delegates to ``svg_finalize.flatten_tspan.flatten_text_with_tspans`` so
the in-memory transform exactly matches the on-disk one. When
- ``merge_paragraphs`` is True, mergeable paragraph blocks are preserved
- as a single <text> for downstream multi-<a:p> conversion.
+ ``merge_paragraphs`` is True, eligible blocks remain one <text> for
+ downstream hard-line and paragraph conversion.
Returns True if any tspan was rewritten.
"""