skills/ppt-station-skill/ppt_station/renderers/text_renderer.py
wangyitong a65adcc2e5 Initial commit: merged, deduplicated, and vetted skill collection
Sources: extracted from two upstream archives (skill-repo, skills-main),
merged with the following policy:

- 15 broken symlinks (pointing to /Users/jameslee/.cc-switch/skills or
  ../../.agents/skills on a foreign machine) discarded
- 3 real name collisions with identical content (ai-pair, ifind-http-api,
  zhipu-websearch) kept as one copy
- Functional overlaps deduped keeping the strongest variant:
  - docx family: kept docx (official, full toolchain) + docx-cn
    (GB/T 9704 Chinese official-document constants),
    dropped docx_writer (no scripts, name collided with docx)
  - humanizer family: kept humanizer-zh (6 zh reference docs),
    dropped humanizer (en, redundant for CN workflow)
- Skills that only ran in a foreign environment removed:
  ablemind-ops, app-publish, hlb-design-system, openclaw-adj-skill,
  claude-driver
- alphapai excluded from this public repo because its SKILL.md hard-coded
  live credentials

Result: 25 skills, 572 files, ~7.5 MB.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 14:47:12 +08:00

47 lines
1.3 KiB
Python

"""
文本渲染器
"""
from typing import Dict, Any, List
from jinja2 import Template
from pptx.slide import Slide
from ppt_station.models.job import TextSpec
from ppt_station.utils.template_utils import find_shape_by_name
class TextRenderer:
"""文本渲染器"""
@staticmethod
def render(slide: Slide, texts: List[TextSpec], context: Dict[str, Any]) -> None:
"""
渲染文本到幻灯片
Args:
slide: 幻灯片对象
texts: 文本配置列表
context: 模板变量上下文
"""
for text_spec in texts or []:
shape = find_shape_by_name(slide, text_spec.target)
if not shape:
print(f"警告: 未找到文本框 '{text_spec.target}'")
continue
if not shape.has_text_frame:
print(f"警告: '{text_spec.target}' 不是文本框")
continue
# 使用 Jinja2 渲染文本
value = Template(text_spec.value).render(**context)
# 清除现有文本并添加新文本
text_frame = shape.text_frame
text_frame.clear()
# 添加段落和文本
p = text_frame.paragraphs[0]
run = p.add_run()
run.text = value