1
0
Files
PPTX/openspec/changes/archive/2026-03-04-fix-multiline-text-font-size/proposal.md
lanyuanxiaoyao 5b367f7ef3 fix: 修复多行文本渲染时字号只应用于第一段的bug
当使用 YAML 多行字符串语法定义文本内容时,python-pptx 会自动
将包含换行符的文本分割成多个段落。修改 _render_text 方法使其
遍历所有段落并应用相同的字体样式(大小、粗体、斜体、颜色、对齐)。

主要变更:
- renderers/pptx_renderer.py: 将 p = tf.paragraphs[0] 改为 for p in tf.paragraphs
- tests/unit/test_renderers/test_pptx_renderer.py: 新增多行文本测试用例
- openspec/specs/element-rendering/spec.md: 更新 spec 文档
- openspec/changes/archive/: 归档完成的变更
2026-03-04 12:18:23 +08:00

25 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## Why
当使用 YAML 多行字符串语法(`|`)定义文本内容时,内容包含换行符(`\n`。python-pptx 会自动将包含换行符的文本分割成多个段落paragraphs但当前渲染代码只对第一个段落应用字体样式导致只有第一行文字使用指定字号其余行使用默认字号。这破坏了文本框样式的统一性。
## What Changes
- 修改 `renderers/pptx_renderer.py` 中的 `_render_text` 方法,使其遍历所有段落并应用相同的字体样式
- 确保字体大小、粗体、斜体、颜色和对齐方式应用到文本框中的所有段落
- 添加多行文本渲染的单元测试
## Capabilities
### New Capabilities
### Modified Capabilities
- `text-rendering`: 修复多行文本渲染时字体样式只应用于第一段的问题
## Impact
- **受影响的代码**: `renderers/pptx_renderer.py`
- **受影响的测试**: `tests/unit/test_renderers/test_pptx_renderer.py` 需要新增多行文本测试用例
- **向后兼容性**: 完全兼容,单行文本行为不变,多行文本从错误行为变为正确行为
- **依赖变化**: 无