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/: 归档完成的变更
This commit is contained in:
@@ -101,34 +101,35 @@ class PptxGenerator:
|
||||
# 默认启用文字自动换行
|
||||
tf.word_wrap = True
|
||||
|
||||
# 应用字体样式
|
||||
p = tf.paragraphs[0]
|
||||
# 应用字体样式到所有段落
|
||||
# 当文本包含换行符时,python-pptx 会创建多个段落
|
||||
# 需要确保所有段落都应用相同的字体样式
|
||||
for p in tf.paragraphs:
|
||||
# 字体大小
|
||||
if 'size' in elem.font:
|
||||
p.font.size = Pt(elem.font['size'])
|
||||
|
||||
# 字体大小
|
||||
if 'size' in elem.font:
|
||||
p.font.size = Pt(elem.font['size'])
|
||||
# 粗体
|
||||
if elem.font.get('bold'):
|
||||
p.font.bold = True
|
||||
|
||||
# 粗体
|
||||
if elem.font.get('bold'):
|
||||
p.font.bold = True
|
||||
# 斜体
|
||||
if elem.font.get('italic'):
|
||||
p.font.italic = True
|
||||
|
||||
# 斜体
|
||||
if elem.font.get('italic'):
|
||||
p.font.italic = True
|
||||
# 颜色
|
||||
if 'color' in elem.font:
|
||||
rgb = hex_to_rgb(elem.font['color'])
|
||||
p.font.color.rgb = RGBColor(*rgb)
|
||||
|
||||
# 颜色
|
||||
if 'color' in elem.font:
|
||||
rgb = hex_to_rgb(elem.font['color'])
|
||||
p.font.color.rgb = RGBColor(*rgb)
|
||||
|
||||
# 对齐方式
|
||||
align_map = {
|
||||
'left': PP_ALIGN.LEFT,
|
||||
'center': PP_ALIGN.CENTER,
|
||||
'right': PP_ALIGN.RIGHT
|
||||
}
|
||||
align = elem.font.get('align', 'left')
|
||||
p.alignment = align_map.get(align, PP_ALIGN.LEFT)
|
||||
# 对齐方式
|
||||
align_map = {
|
||||
'left': PP_ALIGN.LEFT,
|
||||
'center': PP_ALIGN.CENTER,
|
||||
'right': PP_ALIGN.RIGHT
|
||||
}
|
||||
align = elem.font.get('align', 'left')
|
||||
p.alignment = align_map.get(align, PP_ALIGN.LEFT)
|
||||
|
||||
def _render_image(self, slide, elem: ImageElement, base_path):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user