1
0

feat: 实现字体主题系统和东亚字体支持

实现完整的字体主题系统,支持可复用字体配置、预设类别和扩展属性。
同时修复中文字体渲染问题,确保 Source Han Sans 等东亚字体正确显示。

核心功能:
- 字体主题配置:metadata.fonts 和 fonts_default
- 三种引用方式:整体引用、继承覆盖、独立定义
- 预设字体类别:sans、serif、mono、cjk-sans、cjk-serif
- 扩展字体属性:family、underline、strikethrough、line_spacing、
  space_before、space_after、baseline、caps
- 表格字体字段:font 和 header_font 替代旧的 style.font_size
- 引用循环检测和属性继承链
- 模板字体继承支持

东亚字体修复:
- 添加 _set_font_with_eastasian() 方法
- 同时设置拉丁字体、东亚字体和复杂脚本字体
- 修复中文字符使用默认字体的问题

测试:
- 58 个单元测试覆盖所有字体系统功能
- 3 个集成测试验证端到端场景
- 移除旧语法相关测试

文档:
- 更新 README.md 添加字体主题系统使用说明
- 更新 README_DEV.md 添加技术文档
- 创建 4 个示例 YAML 文件
- 同步 delta specs 到主 specs

归档:
- 归档 font-theme-system 变更到 openspec/changes/archive/

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 10:38:59 +08:00
parent 7ef29ea039
commit bd12fce14b
22 changed files with 3142 additions and 103 deletions

167
README.md
View File

@@ -204,10 +204,173 @@ slides:
- ["表头1", "表头2", "表头3"]
- ["数据1", "数据2", "数据3"]
- ["数据4", "数据5", "数据6"]
font:
family: "Arial"
size: 14
color: "#333333"
header_font:
bold: true
color: "#ffffff"
style:
font_size: 14
header_bg: "#4a90e2"
header_color: "#ffffff"
```
**字体配置**
- `font`:表格数据单元格的字体样式
- `header_font`:表头单元格的字体样式(未定义时继承 `font`
- `style.header_bg`:表头背景色
## 🎨 字体主题系统
字体主题系统允许你定义可复用的字体配置,统一管理演示文稿的字体样式。
### 定义字体主题
`metadata.fonts` 中定义命名字体配置:
```yaml
metadata:
size: "16:9"
fonts:
title:
family: "cjk-sans"
size: 44
bold: true
color: "#2c3e50"
body:
family: "sans"
size: 18
color: "#34495e"
line_spacing: 1.5
fonts_default: "@body" # 默认字体(可选)
slides:
- elements:
- type: text
content: "标题文本"
box: [1, 1, 8, 1]
font: "@title" # 引用字体主题
- type: text
content: "正文内容"
box: [1, 2.5, 8, 2]
# 未定义 font 时使用 fonts_default
```
### 预设字体类别
系统提供五种预设字体类别,自动映射到跨平台通用字体:
| 类别 | 映射字体 | 说明 |
|------|---------|------|
| `sans` | Arial | 西文无衬线 |
| `serif` | Times New Roman | 西文衬线 |
| `mono` | Courier New | 等宽字体 |
| `cjk-sans` | Microsoft YaHei | 中文无衬线 |
| `cjk-serif` | SimSun | 中文衬线 |
**使用示例**
```yaml
metadata:
fonts:
body:
family: "cjk-sans" # 自动映射到 Microsoft YaHei
size: 18
```
### 字体引用方式
支持三种字体引用方式:
**1. 整体引用**:完全使用定义的字体配置
```yaml
font: "@title"
```
**2. 继承覆盖**:继承字体配置并覆盖特定属性
```yaml
font:
parent: "@title"
size: 60 # 覆盖字号
color: "#ff0000" # 覆盖颜色
```
**3. 独立定义**:完全自定义字体
```yaml
font:
family: "SimSun"
size: 24
bold: true
```
### 扩展字体属性
除了基础属性size、bold、italic、color、align还支持
**字体样式**
- `family`:字体族名称或预设类别
- `underline`下划线true/false
- `strikethrough`删除线true/false
**段落属性**
- `line_spacing`:行距倍数(如 1.5
- `space_before`:段前间距(磅)
- `space_after`:段后间距(磅)
**高级属性**
- `baseline`基线位置normal/superscript/subscript
- `caps`大小写转换normal/allcaps/smallcaps
**完整示例**
```yaml
metadata:
fonts:
heading:
family: "cjk-sans"
size: 32
bold: true
color: "#2c3e50"
line_spacing: 1.2
space_after: 12
body:
family: "sans"
size: 18
color: "#34495e"
line_spacing: 1.5
fonts_default: "@body"
slides:
- elements:
- type: text
content: "章节标题"
box: [1, 1, 8, 1]
font: "@heading"
- type: text
content: "正文内容\n支持多行文本"
box: [1, 2, 8, 2]
font:
parent: "@body"
underline: true
- type: table
position: [1, 4]
col_widths: [3, 3]
data:
- ["列1", "列2"]
- ["数据1", "数据2"]
font: "@body"
header_font:
parent: "@body"
bold: true
color: "#ffffff"
style:
header_bg: "#3498db"
```
## 📋 模板系统