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

chore(svg): 对齐黑名单规则并清理尺寸检查 - 统一并扩展 SVG 禁用项与兼容规则(外部 CSS、marker、symbol+use、rgba、opacity、事件等) - 更新质量检查器与错误提示,补齐对应规则并移除文件大小检查 - 同步 AGENTS 与角色文档为完整禁用项列表,其它文档引用 AGENTS.md - 修正文档示例,移除 clipPath 圆角示例并补全记忆口诀

hugohe3b990145ac681
diff --git a/AGENTS.md b/AGENTS.md
index 164dd2d5..37c0cbc3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -287,7 +287,6 @@ python3 tools/svg_to_pptx.py <项目路径> -s final
| --------------- | -------------------------------- | ----------------------- |
| **裁剪 / 遮罩** | ❌ `clipPath` | PPT 不支持 SVG 裁剪路径 |
| | ❌ `mask` | PPT 不支持 SVG 遮罩 |
-| **特效** | ❌ `filter`(所有 `fe*`) | 滤镜效果无法导出到 PPT |
| **样式系统** | ❌ `<style>` | 内部样式表不兼容 |
| | ❌ `class` / `id` 选择器 | 使用内联属性替代 |
| | ❌ 外部 CSS | 禁止引用外部样式 |
@@ -295,10 +294,11 @@ python3 tools/svg_to_pptx.py <项目路径> -s final
| | ❌ `<symbol>` + `<use>` 复杂用法 | 简单 `<use>` 引用可用 |
| **文本 / 字体** | ❌ `textPath` | 路径文本不兼容 |
| | ❌ Web 字体(`@font-face`) | 使用系统字体栈 |
-| **动画 / 交互** | ❌ SMIL 动画(`<animate*>`) | SVG 动画不导出 |
-| | ❌ JS / 事件 | 禁止脚本和事件处理 |
+| **动画 / 交互** | ❌ SMIL 动画(`<animate*>` / `<set>`) | SVG 动画不导出 |
+| | ❌ `<script>` / 事件属性 | 禁止脚本和事件处理 |
| **标记 / 箭头** | ❌ `marker` / `marker-end` | PPT 不支持 SVG 标记 |
| | ❌ `<marker>` + `<defs>` | 使用 `<polygon>` 替代 |
+| **其他** | ❌ `<iframe>` | 不应出现在 SVG 中 |
> 📌 **记忆口诀**:PPT 只认基础形状 + 内联样式 + 系统字体
@@ -441,7 +441,7 @@ project/
- [ ] viewBox 与画布尺寸一致
- [ ] 使用 `<tspan>` 手动换行
- [ ] 颜色符合设计规范
-- [ ] **黑名单检查**: 无 `clipPath` / `mask` / `filter` / `<style>` / `class` / `foreignObject` / `textPath` / `animate*` / `script`
+- [ ] **黑名单检查**: 无 `clipPath` / `mask` / `<style>` / `class` / `id` / 外部 CSS / `<foreignObject>` / `<symbol>+<use>` / `textPath` / `@font-face` / `animate*` / `set` / `script` / `on*` / `marker` / `marker-end` / `iframe`
- [ ] **PPT 兼容**: 无 `rgba()`、无 `<g opacity>`、图片用遮罩层、仅内联样式
- [ ] **对齐**: 元素沿网格线对齐
- [ ] **对比**: 建立清晰的视觉层级
diff --git a/README.md b/README.md
index 52db361c..7b4bb78f 100644
--- a/README.md
+++ b/README.md
@@ -370,7 +370,7 @@ graph TD
- **技术要求**:
- 画布尺寸:根据选定格式自动适配(PPT: 1280×720,小红书: 1242×1660 等)
- viewBox 与画布尺寸一致
- - 严禁使用 `<foreignObject>`
+ - 禁用项与 PPT 兼容规则遵循 `AGENTS.md`
- 使用 `<tspan>` 手动换行
- 根据画布比例调整布局和卡片尺寸
@@ -582,7 +582,8 @@ Optimizer_CRAP:
- 更多格式...
- **ViewBox**: 与画布尺寸一致
- **背景**: 使用 `<rect>`元素定义
-- **文本**: 禁用 `<foreignObject>`,使用 `<tspan>`手动换行
+- **文本**: 使用 `<tspan>` 手动换行(禁用项详见 `AGENTS.md`)
+- **禁用项**: 遵循 `AGENTS.md` 中完整黑名单与 PPT 兼容规则
- **字体**: 使用《设计规范与内容大纲》中指定的字体方案(详见 [字体选择](./docs/design_guidelines.md#字体选择))
### PPT 兼容性规则(必须遵守)
@@ -595,7 +596,7 @@ Optimizer_CRAP:
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
### 布局规范
@@ -902,7 +903,7 @@ python3 tools/svg_quality_checker.py --all examples
python3 tools/svg_quality_checker.py examples/project --format ppt169
```
-**检查项目**:viewBox 属性、禁用元素(foreignObject)、字体使用、width/height 一致性、文本换行方式、文件大小
+**检查项目**:viewBox 属性、禁用元素(见 `AGENTS.md`)、字体使用、width/height 一致性、文本换行方式
### 批量验证工具 (`batch_validate.py`)
diff --git a/docs/canvas_formats.md b/docs/canvas_formats.md
index d2bb7d9b..9929586b 100644
--- a/docs/canvas_formats.md
+++ b/docs/canvas_formats.md
@@ -151,7 +151,7 @@
### 所有格式通用规范
- **格式**: SVG 矢量图
- **viewBox**: 与实际尺寸一致
-- **文本**: 禁用 `<foreignObject>`;生成阶段使用 `<tspan>` 手动换行;后处理使用 `tools/finalize_svg.py`(输出到 `svg_final/`)
+- **文本**: 使用 `<tspan>` 手动换行(禁用项详见 `AGENTS.md`);后处理使用 `tools/finalize_svg.py`(输出到 `svg_final/`)
- **颜色**: 使用 HEX 值
- **字体**: 优先使用系统字体栈
diff --git a/docs/design_guidelines.md b/docs/design_guidelines.md
index 05de93a3..d0748860 100644
--- a/docs/design_guidelines.md
+++ b/docs/design_guidelines.md
@@ -202,7 +202,7 @@ H3 - 章节标题: 28-32px, SemiBold
### 文本换行与扁平化
-- 生成阶段:禁止使用 `<foreignObject>`,采用 `<tspan>` 手动换行,并通过 `x`/`dy` 控制行起点与行距,保证与版式行高规范一致。
+- 生成阶段:采用 `<tspan>` 手动换行,并通过 `x`/`dy` 控制行起点与行距,保证与版式行高规范一致(禁用项详见 `AGENTS.md`)。
- 发布/后处理:推荐使用统一后处理工具 `tools/finalize_svg.py`,已包含文本扁平化功能:
```bash
python3 tools/finalize_svg.py <项目路径>
diff --git a/docs/quick_reference.md b/docs/quick_reference.md
index bd490922..65ddfda0 100644
--- a/docs/quick_reference.md
+++ b/docs/quick_reference.md
@@ -421,7 +421,7 @@ yh_02_kpi_dashboard.svg
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
## 🔧 后处理工具
diff --git a/docs/svg_image_embedding.md b/docs/svg_image_embedding.md
index d13a680e..056b08a0 100644
--- a/docs/svg_image_embedding.md
+++ b/docs/svg_image_embedding.md
@@ -287,21 +287,14 @@ project/
└── 01_cover_embedded.svg # 导出版(Base64 内嵌)
```
-### 3. clipPath 裁剪圆角
+### 3. 圆角处理(禁止 clipPath)
-如果需要给图片添加圆角:
+由于 `clipPath` 在 PPT 中不兼容,**禁止**使用裁剪路径为图片加圆角。
-```xml
-<defs>
- <clipPath id="roundedClip">
- <rect x="60" y="110" width="540" height="380" rx="10" ry="10"/>
- </clipPath>
-</defs>
-
-<image href="image.png" x="60" y="110" width="540" height="380"
- clip-path="url(#roundedClip)"
- preserveAspectRatio="xMidYMid slice"/>
-```
+推荐替代方案:
+
+- 在生成图片时直接处理圆角(如导出为带圆角的 PNG)
+- 或用同尺寸的圆角矩形覆盖边缘(视觉模拟)
---
diff --git a/docs/workflow_tutorial.md b/docs/workflow_tutorial.md
index 86600c9e..4041e7c9 100644
--- a/docs/workflow_tutorial.md
+++ b/docs/workflow_tutorial.md
@@ -693,7 +693,7 @@ Optimizer_CRAP:
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
**检查清单**:
diff --git a/roles/Executor_Consultant.md b/roles/Executor_Consultant.md
index 0b392159..4bffeadb 100644
--- a/roles/Executor_Consultant.md
+++ b/roles/Executor_Consultant.md
@@ -65,7 +65,8 @@
2. **逻辑构建阶段**: SVG 全部定稿后,再批量生成演讲备注,确保叙事逻辑连贯(Narrative Continuity)
- **技术规范**:
- viewBox 必须与画布尺寸一致
- - **严禁使用 `<foreignObject>`**,用 `<tspan>` 手动换行
+ - 使用 `<tspan>` 手动换行
+ - **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
- 使用 `<rect>` 定义背景色
@@ -180,7 +181,8 @@
## 技术规范
- viewBox 必须与画布尺寸一致
-- **严禁使用 `<foreignObject>`**,用 `<tspan>` 换行
+- 使用 `<tspan>` 换行
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
### 字体使用
@@ -205,12 +207,12 @@
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
## 生成后自检
- [ ] viewBox 与画布尺寸一致
-- [ ] 无 `<foreignObject>`
+- [ ] 无禁用元素(见技术规范清单)
- [ ] 数据与源数据一致
- [ ] 简洁专业,留白充足
- [ ] **PPT 兼容**: 无 `rgba()`、无 `<g opacity>`、图片用遮罩层
diff --git a/roles/Executor_Consultant_Top.md b/roles/Executor_Consultant_Top.md
index 511b84b3..390465c8 100644
--- a/roles/Executor_Consultant_Top.md
+++ b/roles/Executor_Consultant_Top.md
@@ -101,10 +101,11 @@
- **分阶段批量生成**(推荐):
1. **视觉构建阶段**: 连续生成所有 SVG 页面,确保设计风格和布局坐标的高度一致性(Visual Consistency)
2. **逻辑构建阶段**: SVG 全部定稿后,再批量生成演讲备注,确保叙事逻辑连贯(Narrative Continuity)
-- **技术规范**:
- - viewBox 必须与画布尺寸一致
- - **严禁使用 `<foreignObject>`**,用 `<tspan>` 手动换行
- - 使用 `<rect>` 定义背景色
+ - **技术规范**:
+ - viewBox 必须与画布尺寸一致
+ - 使用 `<tspan>` 手动换行
+ - **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
+ - 使用 `<rect>` 定义背景色
## 咨询级表达核心技巧
@@ -276,7 +277,8 @@
## 技术规范
- viewBox 必须与画布尺寸一致
-- **严禁使用 `<foreignObject>`**,用 `<tspan>` 换行
+- 使用 `<tspan>` 换行
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
### 字体使用
@@ -301,7 +303,7 @@
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
---
@@ -310,7 +312,7 @@
### 技术检查
- [ ] viewBox 与画布尺寸一致
-- [ ] 无 `<foreignObject>`
+- [ ] 无禁用元素(见技术规范清单)
- [ ] 数据与源数据一致
- [ ] **PPT 兼容**: 无 `rgba()`、无 `<g opacity>`、图片用遮罩层
diff --git a/roles/Executor_General.md b/roles/Executor_General.md
index 049ec226..6573fa87 100644
--- a/roles/Executor_General.md
+++ b/roles/Executor_General.md
@@ -66,7 +66,8 @@
2. **逻辑构建阶段**: SVG 全部定稿后,再批量生成演讲备注,确保叙事逻辑连贯(Narrative Continuity)
- **技术规范**:
- viewBox 必须与画布尺寸一致
- - **严禁使用 `<foreignObject>`**,用 `<tspan>` 手动换行
+ - 使用 `<tspan>` 手动换行
+ - **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
- 使用 `<rect>` 定义背景色
- 使用《设计规范与内容大纲》中指定的字体方案
@@ -128,7 +129,7 @@
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+**记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
## 图标使用
@@ -207,7 +208,7 @@
## 生成后自检
- [ ] viewBox 与画布尺寸一致
-- [ ] 无 `<foreignObject>`
+- [ ] 无禁用元素(见技术规范清单)
- [ ] 用 `<tspan>` 换行
- [ ] 元素不超出边界
- [ ] 颜色符合规范
diff --git a/roles/Optimizer_CRAP.md b/roles/Optimizer_CRAP.md
index 59efa9a7..5354007d 100644
--- a/roles/Optimizer_CRAP.md
+++ b/roles/Optimizer_CRAP.md
@@ -117,6 +117,6 @@
## 技术约束
- **保持画布尺寸**: 优化后的 SVG 必须保持与原始 SVG 相同的 `width`、`height` 和 `viewBox`
-- **禁用元素**: 不得引入 `<foreignObject>`、`<iframe>`、`<script>`
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
- **文本处理**: 保持使用 `<tspan>` 进行文本换行
- **文件命名**: 优化后的文件名格式为 `yh_原文件名.svg`
diff --git a/roles/README.md b/roles/README.md
index fd69fb37..b57f976c 100644
--- a/roles/README.md
+++ b/roles/README.md
@@ -177,9 +177,9 @@ Strategist → Image_Generator → Executor
**技术特点**:
- 画布尺寸: 根据已选画布格式自动适配(详见 `docs/canvas_formats.md`)
-- 禁用 `<foreignObject>`
- 使用 `<tspan>` 手动换行
- 强制卡片高度规则
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
📄 [查看完整定义](./Executor_General.md)
@@ -200,6 +200,7 @@ Strategist → Image_Generator → Executor
- 简洁、清晰、数据可视化
- 使用图表呈现关键信息
- 融入行业标准的设计元素
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
📄 [查看完整定义](./Executor_Consultant.md)
@@ -225,6 +226,7 @@ Strategist → Image_Generator → Executor
- 每个数据点都有对比参照
- 结论先行,核心信息在标题位置
- 配色服务于信息传达
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
📄 [查看完整定义](./Executor_Consultant_Top.md)
@@ -240,6 +242,7 @@ Strategist → Image_Generator → Executor
- 诊断视觉问题
- 重构 SVG 代码
- 提升专业度和清晰度
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
**四大原则**:
diff --git a/roles/Template_Designer.md b/roles/Template_Designer.md
index 1f52a47a..7e4b2938 100644
--- a/roles/Template_Designer.md
+++ b/roles/Template_Designer.md
@@ -167,7 +167,7 @@ templates/layouts/
遵循与 Executor 相同的 SVG 技术约束:
- **viewBox**: 与画布尺寸一致
-- **禁止**: `clipPath`, `mask`, `filter`, `<style>`, `class`, `foreignObject`
+- **禁止**: `clipPath`, `mask`, `<style>`, `class`, `id`, 外部 CSS, `<foreignObject>`, `<symbol>+<use>`, `textPath`, `@font-face`, `<animate*>` / `<set>`, `<script>` / 事件属性, `marker` / `marker-end`, `<iframe>`
- **PPT 兼容**: 无 `rgba()`、无 `<g opacity>`、图片用遮罩层
- **字体**: 使用系统字体栈
diff --git a/tools/README.md b/tools/README.md
index 2b6d7823..d8de6a13 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -330,7 +330,7 @@ python3 tools/project_manager.py info projects/my_presentation_ppt169_20251116
将含有多行 `<tspan>` 的 `<text>` 结构扁平化为多条独立的 `<text>` 元素,便于部分渲染器兼容或文本抽取。
-**注意**: 生成端仍应使用 `<tspan>` 手动换行(禁止 `<foreignObject>`)。此工具仅用于后处理。
+**注意**: 生成端仍应使用 `<tspan>` 手动换行(禁用项详见 `AGENTS.md`)。此工具仅用于后处理。
**用法**:
@@ -461,7 +461,7 @@ python3 tools/error_helper.py missing_readme project_path=my_project
- `missing_spec` - 缺少设计规范
- `missing_svg_output` - 缺少 svg_output 目录
- `viewbox_mismatch` - viewBox 不匹配
-- `foreignobject_detected` - 检测到禁用元素
+- `foreignobject_detected` - 检测到禁用元素(详见 AGENTS.md 黑名单)
- 等等...
---
@@ -473,11 +473,10 @@ python3 tools/error_helper.py missing_readme project_path=my_project
**功能**:
- 验证 viewBox 属性
-- 检测禁用元素(foreignObject)
+- 检测禁用元素(详见 AGENTS.md)
- 检查字体使用
- 验证 width/height 与 viewBox 一致性
- 检查文本换行方式
-- 分析文件大小
**用法**:
@@ -504,11 +503,10 @@ python3 tools/svg_quality_checker.py examples/project --export
**检查项目**:
- ✅ viewBox 属性存在且格式正确
-- ✅ 无 `<foreignObject>` 元素
+- ✅ 无禁用元素(详见 AGENTS.md)
- ✅ 使用《设计规范》指定的字体
- ✅ width/height 与 viewBox 一致
- ✅ 文本使用 `<tspan>` 换行
-- ✅ 文件大小合理(< 500KB)
---
@@ -522,7 +520,7 @@ python3 tools/svg_quality_checker.py examples/project --export
| `<g opacity="0.2">...</g>` | 每个子元素单独设置透明度 |
| `<image opacity="0.3"/>` | 图片后加遮罩层 `<rect fill="背景色" opacity="0.7"/>` |
-> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明
+> 📌 **记忆口诀**:PPT 不认 rgba、不认组透明、不认图片透明、不认 marker
---
@@ -1215,4 +1213,3 @@ pip install python-pptx
_最后更新: 2025-12-20_
_gemini_watermark_remover.py 文档更新: 2025-12-20_
-
diff --git a/tools/config.py b/tools/config.py
index 80c00831..3a3441c8 100644
--- a/tools/config.py
+++ b/tools/config.py
@@ -350,13 +350,11 @@ SVG_CONSTRAINTS = {
# 裁剪 / 遮罩
'clipPath',
'mask',
- # 特效
- 'filter',
# 样式系统
'style',
# 结构 / 嵌套
'foreignObject',
- 'symbol', # 复杂用法不兼容
+ 'marker',
# 文本 / 字体
'textPath',
# 动画 / 交互
@@ -372,16 +370,23 @@ SVG_CONSTRAINTS = {
# 禁用属性
'forbidden_attributes': [
'class',
+ 'id',
'onclick', 'onload', 'onmouseover', 'onmouseout',
'onfocus', 'onblur', 'onchange',
+ 'marker-end',
],
# 禁用模式(正则匹配)
'forbidden_patterns': [
r'@font-face', # Web 字体
r'rgba\s*\(', # rgba 颜色(PPT 不兼容)
+ r'<\?xml-stylesheet\b', # 外部 CSS
+ r'<link[^>]*rel\s*=\s*["\']stylesheet["\']',
+ r'@import\s+', # 外部 CSS
+ r'<g[^>]*\sopacity\s*=', # 组透明度
+ r'<image[^>]*\sopacity\s*=', # 图片透明度
+ r'\bon\w+\s*=', # 事件属性
+ r'(?s)(?=.*<symbol)(?=.*<use\b)', # <symbol> + <use> 复杂用法(顺序无关)
],
- 'max_file_size_kb': 500,
- 'warning_file_size_kb': 200,
'recommended_fonts': [
'system-ui',
'-apple-system',
diff --git a/tools/error_helper.py b/tools/error_helper.py
index 90ce7c82..578491f5 100644
--- a/tools/error_helper.py
+++ b/tools/error_helper.py
@@ -128,15 +128,6 @@ class ErrorHelper:
],
'severity': 'error'
},
- 'filter_detected': {
- 'message': '检测到禁用的 <filter> 元素',
- 'solutions': [
- '移除 <filter> 及所有 fe* 滤镜元素',
- '滤镜效果无法导出到 PPT',
- '阴影效果可用多个偏移的浅色形状模拟'
- ],
- 'severity': 'error'
- },
'style_element_detected': {
'message': '检测到禁用的 <style> 元素',
'solutions': [
@@ -155,6 +146,105 @@ class ErrorHelper:
],
'severity': 'error'
},
+ 'id_attribute_detected': {
+ 'message': '检测到禁用的 id 属性',
+ 'solutions': [
+ '移除所有 id 属性',
+ '使用内联样式替代',
+ '避免依赖选择器定位或样式复用'
+ ],
+ 'severity': 'error'
+ },
+ 'external_css_detected': {
+ 'message': '检测到禁用的外部 CSS 引用',
+ 'solutions': [
+ '移除 <?xml-stylesheet?> 声明',
+ '移除 <link rel="stylesheet"> 引用',
+ '移除 @import 外部样式',
+ '将样式改为内联属性'
+ ],
+ 'severity': 'error'
+ },
+ 'symbol_use_detected': {
+ 'message': '检测到禁用的 <symbol> + <use> 复杂用法',
+ 'solutions': [
+ '将 <symbol> 展开为实际 SVG 代码',
+ '避免 <symbol> + <use> 的复用结构',
+ '需要图标时可直接嵌入 SVG 路径'
+ ],
+ 'severity': 'error'
+ },
+ 'marker_detected': {
+ 'message': '检测到禁用的 <marker> 元素',
+ 'solutions': [
+ '移除 <marker> 定义',
+ '使用 line + polygon 绘制箭头',
+ '参考 AGENTS.md 的箭头绘制方案'
+ ],
+ 'severity': 'error'
+ },
+ 'marker_end_detected': {
+ 'message': '检测到禁用的 marker-end 属性',
+ 'solutions': [
+ '移除 marker-end 属性',
+ '使用 line + polygon 绘制箭头',
+ '确保箭头方向与线条一致'
+ ],
+ 'severity': 'error'
+ },
+ 'rgba_detected': {
+ 'message': '检测到禁用的 rgba() 颜色',
+ 'solutions': [
+ '将 rgba() 改为 hex + opacity 写法',
+ '示例: fill="#FFFFFF" fill-opacity="0.1"',
+ '描边使用 stroke-opacity'
+ ],
+ 'severity': 'error'
+ },
+ 'group_opacity_detected': {
+ 'message': '检测到禁用的 <g opacity>',
+ 'solutions': [
+ '移除组级 opacity',
+ '为每个子元素单独设置透明度',
+ '使用 fill-opacity / stroke-opacity 控制'
+ ],
+ 'severity': 'error'
+ },
+ 'image_opacity_detected': {
+ 'message': '检测到禁用的 <image opacity>',
+ 'solutions': [
+ '移除图片 opacity 属性',
+ '添加遮罩层 <rect> 控制透明度',
+ '确保遮罩颜色与背景一致'
+ ],
+ 'severity': 'error'
+ },
+ 'event_attribute_detected': {
+ 'message': '检测到禁用的事件属性',
+ 'solutions': [
+ '移除 onclick/onload 等事件属性',
+ 'SVG 禁止脚本和事件处理',
+ '交互请在 PPT 中实现'
+ ],
+ 'severity': 'error'
+ },
+ 'set_detected': {
+ 'message': '检测到禁用的 <set> 元素',
+ 'solutions': [
+ '移除 <set> 元素',
+ 'SVG 动画不会导出到 PPT',
+ '如需动画效果请在 PPT 中设置'
+ ],
+ 'severity': 'error'
+ },
+ 'iframe_detected': {
+ 'message': '检测到禁用的 <iframe> 元素',
+ 'solutions': [
+ '移除 <iframe> 元素',
+ 'SVG 中不应嵌入外部页面'
+ ],
+ 'severity': 'error'
+ },
'textpath_detected': {
'message': '检测到禁用的 <textPath> 元素',
'solutions': [
diff --git a/tools/svg_quality_checker.py b/tools/svg_quality_checker.py
index d76a3849..c97081c5 100644
--- a/tools/svg_quality_checker.py
+++ b/tools/svg_quality_checker.py
@@ -89,9 +89,6 @@ class SVGQualityChecker:
# 5. 检查文本换行方式
self._check_text_elements(content, result)
- # 6. 检查文件大小
- self._check_file_size(svg_path, result)
-
# 判断是否通过
result['passed'] = len(result['errors']) == 0
@@ -153,22 +150,32 @@ class SVGQualityChecker:
if '<mask' in content_lower and '<mask>' not in content_lower: # 排除纯文本 "mask"
result['errors'].append("检测到禁用的 <mask> 元素(PPT 不支持 SVG 遮罩)")
- # 特效
- if '<filter' in content_lower:
- result['errors'].append("检测到禁用的 <filter> 元素(滤镜效果无法导出到 PPT)")
-
# 样式系统
if '<style' in content_lower:
result['errors'].append("检测到禁用的 <style> 元素(使用内联属性替代)")
if re.search(r'\bclass\s*=', content):
result['errors'].append("检测到禁用的 class 属性(使用内联样式替代)")
+ if re.search(r'\bid\s*=', content):
+ result['errors'].append("检测到禁用的 id 属性(使用内联样式替代)")
+ if re.search(r'<\?xml-stylesheet\b', content_lower):
+ result['errors'].append("检测到禁用的 xml-stylesheet(禁止引用外部 CSS)")
+ if re.search(r'<link[^>]*rel\s*=\s*["\']stylesheet["\']', content_lower):
+ result['errors'].append("检测到禁用的 <link rel=\"stylesheet\">(禁止引用外部 CSS)")
+ if re.search(r'@import\s+', content_lower):
+ result['errors'].append("检测到禁用的 @import(禁止引用外部 CSS)")
# 结构 / 嵌套
if '<foreignobject' in content_lower:
result['errors'].append(
"检测到禁用的 <foreignObject> 元素(使用 <tspan> 手动换行)")
- if '<symbol' in content_lower:
- result['warnings'].append("检测到 <symbol> 元素(复杂用法可能不兼容 PPT)")
+ has_symbol = '<symbol' in content_lower
+ has_use = re.search(r'<use\b', content_lower) is not None
+ if has_symbol and has_use:
+ result['errors'].append("检测到禁用的 <symbol> + <use> 复杂用法(请改用基础形状或简单 <use>)")
+ if '<marker' in content_lower:
+ result['errors'].append("检测到禁用的 <marker> 元素(PPT 不支持 SVG marker)")
+ if re.search(r'\bmarker-end\s*=', content_lower):
+ result['errors'].append("检测到禁用的 marker-end 属性(请用 line + polygon 代替)")
# 文本 / 字体
if '<textpath' in content_lower:
@@ -179,6 +186,8 @@ class SVGQualityChecker:
# 动画 / 交互
if re.search(r'<animate', content_lower):
result['errors'].append("检测到禁用的 SMIL 动画元素 <animate*>(SVG 动画不导出)")
+ if re.search(r'<set\b', content_lower):
+ result['errors'].append("检测到禁用的 SMIL 动画元素 <set>(SVG 动画不导出)")
if '<script' in content_lower:
result['errors'].append("检测到禁用的 <script> 元素(禁止脚本和事件处理)")
if re.search(r'\bon\w+\s*=', content): # onclick, onload 等
@@ -187,6 +196,12 @@ class SVGQualityChecker:
# 其他不推荐的元素
if '<iframe' in content_lower:
result['errors'].append("检测到 <iframe> 元素(不应出现在 SVG 中)")
+ if re.search(r'rgba\s*\(', content_lower):
+ result['errors'].append("检测到禁用的 rgba() 颜色(请用 fill-opacity/stroke-opacity)")
+ if re.search(r'<g[^>]*\sopacity\s*=', content_lower):
+ result['errors'].append("检测到禁用的 <g opacity>(请为子元素单独设置透明度)")
+ if re.search(r'<image[^>]*\sopacity\s*=', content_lower):
+ result['errors'].append("检测到禁用的 <image opacity>(请使用遮罩层方案)")
def _check_fonts(self, content: str, result: Dict):
"""检查字体使用"""
@@ -248,23 +263,6 @@ class SVGQualityChecker:
f"检测到 {len(text_matches)} 个可能过长的单行文本(建议使用 tspan 换行)"
)
- def _check_file_size(self, svg_path: Path, result: Dict):
- """检查文件大小"""
- size_bytes = svg_path.stat().st_size
- size_kb = size_bytes / 1024
-
- result['info']['file_size'] = f"{size_kb:.1f} KB"
-
- # 警告过大的文件
- if size_kb > 500:
- result['warnings'].append(
- f"文件较大 ({size_kb:.1f} KB),建议优化"
- )
- elif size_kb > 1000:
- result['errors'].append(
- f"文件过大 ({size_kb:.1f} KB),必须优化"
- )
-
def _categorize_issue(self, error_msg: str) -> str:
"""分类问题类型"""
if 'viewBox' in error_msg:
@@ -273,8 +271,6 @@ class SVGQualityChecker:
return 'foreignObject'
elif '字体' in error_msg or 'font' in error_msg:
return '字体问题'
- elif '文件' in error_msg and ('大' in error_msg or 'size' in error_msg):
- return '文件大小'
else:
return '其他'
@@ -336,8 +332,6 @@ class SVGQualityChecker:
info_items = []
if 'viewbox' in result['info']:
info_items.append(f"viewBox: {result['info']['viewbox']}")
- if 'file_size' in result['info']:
- info_items.append(f"大小: {result['info']['file_size']}")
if info_items:
print(f" {' | '.join(info_items)}")
@@ -380,7 +374,6 @@ class SVGQualityChecker:
print(f" 1. viewBox 问题: 确保与画布格式一致(参考 docs/canvas_formats.md)")
print(f" 2. foreignObject: 改用 <text> + <tspan> 进行手动换行")
print(f" 3. 字体问题: 使用系统 UI 字体栈")
- print(f" 4. 文件过大: 移除不必要的元素,优化路径数据")
def _percentage(self, count: int) -> int:
"""计算百分比"""