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(pptx-to-svg): enforce the line-paint choice

hugohe3cb32c580a90f
diff --git a/docs/powerpoint-svg-mapping.md b/docs/powerpoint-svg-mapping.md
index 4136b6c4..c96b03f9 100644
--- a/docs/powerpoint-svg-mapping.md
+++ b/docs/powerpoint-svg-mapping.md
@@ -156,6 +156,7 @@ preset selection and authoring behavior are documented in
| Solid outline | Registered `stroke` and width | Native `a:ln` | `Native-stable` | Width and paint must use canonical units/grammar |
| Compound outline | No registered single-stroke SVG representation | Explicit geometry alternative or baked asset | `Bake-required` for the compound-line identity | PPTX import accepts only omitted/`sng` `cmpd`; other source values stop instead of becoming a single line |
| Inside-aligned outline | No registered ordinary SVG stroke representation | Explicit inset geometry or baked asset | `Bake-required` for exact outline alignment | PPTX import accepts only omitted/`ctr` `algn`; `in` stops instead of becoming a centered stroke |
+| Pattern, image, or group-derived outline paint | No registered line-paint SVG mapping | Explicit geometry alternative or baked asset | `Bake-required` | PPTX import stops instead of substituting a default solid line color |
| Outline scaling under transforms | Exact `vector-effect="none"` or `vector-effect="non-scaling-stroke"` | Choice resolved into native line width | `Native-normalized` | Other values are rejected; generated spelling is exact and lowercase |
| Dashed or dotted outline | Registered dash array | Preset or custom DrawingML dash | `Native-normalized` | Unsupported dash semantics are rejected |
| Line cap and join | Registered cap/join values | Native line cap/join properties | `Native-stable` within the fixed join contract | Import accepts one join; miter requires exact `lim="800000"` |
diff --git a/docs/zh/powerpoint-svg-mapping.md b/docs/zh/powerpoint-svg-mapping.md
index 3f46c95a..f89741f1 100644
--- a/docs/zh/powerpoint-svg-mapping.md
+++ b/docs/zh/powerpoint-svg-mapping.md
@@ -151,6 +151,7 @@ PowerPoint 意图
| 实线轮廓 | 已登记 `stroke` 与宽度 | 原生 `a:ln` | `Native-stable` | 宽度与 paint 必须使用规范单位/语法 |
| 复合轮廓线 | 无已登记的单一 SVG stroke 表达 | 显式几何替代或烘焙资产 | 复合线身份为 `Bake-required` | PPTX 回导仅接受省略/`sng` 的 `cmpd`;其他源值会阻断,不得退化为单线 |
| 内侧对齐轮廓 | 无已登记的普通 SVG stroke 表达 | 显式内缩几何或烘焙资产 | 精确轮廓对齐为 `Bake-required` | PPTX 回导仅接受省略/`ctr` 的 `algn`;`in` 会阻断,不得退化为居中描边 |
+| 图案、图片或组派生轮廓 paint | 无已登记的线条 paint SVG 映射 | 显式几何替代或烘焙资产 | `Bake-required` | PPTX 回导会阻断,不得替换为默认纯色线 |
| transform 下的轮廓缩放 | 精确的 `vector-effect="none"` 或 `vector-effect="non-scaling-stroke"` | 选择被解析为原生线宽 | `Native-normalized` | 拒绝其他取值;生成拼法必须精确且为小写 |
| 虚线或点线轮廓 | 已登记 dash array | 预设或自定义 DrawingML dash | `Native-normalized` | 拒绝不支持的 dash 语义 |
| 线端与连接样式 | 已登记 cap/join 值 | 原生 line cap/join 属性 | 固定 join 合同内为 `Native-stable` | 回导仅接受一个 join;miter 必须精确使用 `lim="800000"` |
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 20c07224..029bdaf7 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -1000,6 +1000,10 @@ single-stroke SVG mapping and stop import instead of becoming an ordinary line.
PPTX import likewise accepts an omitted `a:ln@algn` or explicit `ctr`.
Inside-aligned (`in`) and unknown source values stop import because an ordinary
SVG stroke is centered and cannot preserve the source outline boundary.
+An imported line contains at most one direct paint. The registered import
+choices are `a:noFill`, a resolvable `a:solidFill`, and `a:gradFill` normalized
+to its first resolvable stop. Ambiguous paint, unresolved registered paint, and
+pattern/image/group line paint stop import instead of becoming a default color.
An explicit source `a:ln@cap` must be `flat`, `rnd`, or `sq`, which map to SVG
`butt`, `round`, and `square`; unknown values stop import instead of falling
back to the SVG default cap.
diff --git a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
index e8206565..26cc58d1 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
@@ -41,6 +41,17 @@ PRST_DASH_TO_ARRAY = {
"sysDashDotDot": "3 3 1 3 1 3",
}
_OOXML_INT_MAX = 2**31 - 1
+_LINE_PAINT_TAGS = {
+ f"{{{NS['a']}}}{name}": name
+ for name in (
+ "noFill",
+ "solidFill",
+ "gradFill",
+ "pattFill",
+ "blipFill",
+ "grpFill",
+ )
+}
# DrawingML cap -> SVG stroke-linecap
CAP_MAP = {
@@ -107,32 +118,39 @@ def resolve_stroke(
attrs["stroke-linecap"] = CAP_MAP[cap]
# Fill: noFill / solidFill / gradFill
- no_fill = ln.find("a:noFill", NS)
- if no_fill is not None:
+ paints = [child for child in ln if child.tag in _LINE_PAINT_TAGS]
+ if len(paints) > 1:
+ raise ValueError("DrawingML line must contain at most one paint")
+ paint = paints[0] if paints else None
+ paint_name = _LINE_PAINT_TAGS.get(paint.tag) if paint is not None else None
+ if paint_name not in {None, "noFill", "solidFill", "gradFill"}:
+ raise ValueError(f"Unsupported DrawingML line paint: {paint_name}")
+ if paint_name == "noFill":
attrs["stroke"] = "none"
- else:
- solid = ln.find("a:solidFill", NS)
- if solid is not None:
- color_elem = find_color_elem(solid)
- hex_, alpha = resolve_color(color_elem, palette)
- if hex_:
- attrs["stroke"] = hex_
- if alpha < 1.0:
- attrs["stroke-opacity"] = fmt_num(alpha, 4)
- else:
- grad = ln.find("a:gradFill", NS)
- if grad is not None:
- # Approximate gradient stroke as the first stop color (SVG
- # supports gradient strokes via fill="url()" but it adds a lot
- # of plumbing; first-stop is good enough for v1).
- first_gs = grad.find("a:gsLst/a:gs", NS)
- if first_gs is not None:
- color_elem = find_color_elem(first_gs)
- hex_, alpha = resolve_color(color_elem, palette)
- if hex_:
- attrs["stroke"] = hex_
- if alpha < 1.0:
- attrs["stroke-opacity"] = fmt_num(alpha, 4)
+ elif paint_name == "solidFill":
+ color_elem = find_color_elem(paint)
+ hex_, alpha = resolve_color(color_elem, palette)
+ if hex_ is None:
+ raise ValueError("DrawingML solid line color cannot be resolved")
+ attrs["stroke"] = hex_
+ if alpha < 1.0:
+ attrs["stroke-opacity"] = fmt_num(alpha, 4)
+ elif paint_name == "gradFill":
+ # Approximate gradient stroke as the first stop color (SVG supports
+ # gradient strokes via fill="url()" but it adds a lot of plumbing;
+ # first-stop is the registered import normalization).
+ first_gs = paint.find("a:gsLst/a:gs", NS)
+ if first_gs is None:
+ raise ValueError("DrawingML gradient line requires a color stop")
+ color_elem = find_color_elem(first_gs)
+ hex_, alpha = resolve_color(color_elem, palette)
+ if hex_ is None:
+ raise ValueError(
+ "DrawingML gradient line first color cannot be resolved"
+ )
+ attrs["stroke"] = hex_
+ if alpha < 1.0:
+ attrs["stroke-opacity"] = fmt_num(alpha, 4)
# Dash pattern
prst_dash = ln.find("a:prstDash", NS)
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 97368708..533cf8cd 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2723,6 +2723,58 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
</p:spPr>''')
self.assertEqual(resolve_stroke(centered, None).attrs, {})
+ def test_native_line_paint_must_be_unique_and_resolvable(self):
+ cases = (
+ (
+ '<a:noFill/><a:solidFill><a:srgbClr val="112233"/>'
+ '</a:solidFill>',
+ 'DrawingML line must contain at most one paint',
+ ),
+ (
+ '<a:pattFill/>',
+ 'Unsupported DrawingML line paint: pattFill',
+ ),
+ (
+ '<a:solidFill/>',
+ 'DrawingML solid line color cannot be resolved',
+ ),
+ (
+ '<a:gradFill/>',
+ 'DrawingML gradient line requires a color stop',
+ ),
+ )
+ for paint_markup, expected in cases:
+ with self.subTest(paint_markup=paint_markup):
+ sp_pr = ET.fromstring(f'''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:ln>{paint_markup}</a:ln>
+</p:spPr>''')
+ with self.assertRaisesRegex(ValueError, expected):
+ resolve_stroke(sp_pr, None)
+
+ valid_cases = (
+ ('<a:noFill/>', 'none'),
+ (
+ '<a:solidFill><a:srgbClr val="112233"/></a:solidFill>',
+ '#112233',
+ ),
+ (
+ '<a:gradFill><a:gsLst><a:gs pos="0">'
+ '<a:srgbClr val="445566"/></a:gs></a:gsLst></a:gradFill>',
+ '#445566',
+ ),
+ )
+ for paint_markup, expected_stroke in valid_cases:
+ with self.subTest(valid_paint=paint_markup):
+ sp_pr = ET.fromstring(f'''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:ln>{paint_markup}</a:ln>
+</p:spPr>''')
+ stroke = resolve_stroke(sp_pr, None)
+ self.assertEqual(stroke.attrs['stroke'], expected_stroke)
+
def test_unknown_native_line_cap_is_rejected_on_import(self):
sp_pr = ET.fromstring('''
<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"