v0.20.6 rebuild platform environments from templates

This commit is contained in:
Deep Research System
2026-05-07 21:00:21 +08:00
parent bb2c91754b
commit b3050260b2
93 changed files with 6027 additions and 89 deletions
@@ -0,0 +1,67 @@
# Fonts 目录
## 说明
本目录存放 Deep Research 系统生成 PDF 报告所需的中文字体。
**所有字体文件均通过 `.gitignore` 排除**,不会进入 git 版本库,以避免仓库体积膨胀(~140MB)。
## 快速开始
首次使用时,运行:
```bash
bash .opencode/templates/fonts/download-fonts.sh
```
脚本会自动从官方 GitHub 下载以下字体:
| 文件 | 字体名 | 用途 |
|---|---|---|
| `SourceHanSerifSC-Regular.otf` | 思源宋体 Regular | 正文 |
| `SourceHanSerifSC-Bold.otf` | 思源宋体 Bold | 正文粗体/术语 |
| `SourceHanSansSC-Light.otf` | 思源黑体 Light | 页眉页脚 |
| `SourceHanSansSC-Medium.otf` | 思源黑体 Medium | 三级标题、图表 |
| `SourceHanSansSC-Bold.otf` | 思源黑体 Bold | 一二级标题 |
| `SourceHanSansSC-Heavy.otf` | 思源黑体 Heavy | 封面大标题 |
| `LXGWWenKai-Regular.ttf` | 霞鹜文楷 Regular | 摘要、引文、批注 |
## 许可证
全部字体为 **SIL Open Font License 1.1**,可自由商用、嵌入 PDF 分发。
- 思源宋体 / 思源黑体:© Adobe Systems Incorporated + GoogleSIL OFL 1.1
- 霞鹜文楷:© LXGW(基于台北黑体和 Klee One 修改),SIL OFL 1.1
## 手动下载(脚本失败时的备用方案)
如果 `download-fonts.sh` 因网络问题失败,请手动从官方 Release 下载并放入本目录:
- **思源宋体**https://github.com/adobe-fonts/source-han-serif/releases
-`SubsetOTF/CN/` 路径下的 `SourceHanSerifCN-Regular.otf``SourceHanSerifCN-Bold.otf`
- 放入本目录并重命名为 `SourceHanSerifSC-Regular.otf``SourceHanSerifSC-Bold.otf`
- **思源黑体**https://github.com/adobe-fonts/source-han-sans/releases
-`SubsetOTF/CN/` 路径下的 Light / Medium / Bold / Heavy 四个字重
- 放入本目录并重命名(CN → SC)
- **霞鹜文楷**https://github.com/lxgw/LxgwWenKai/releases
- 取最新版 `LXGWWenKai-Regular.ttf` 放入本目录(无需改名)
## 常见问题
### Q: 下载速度慢 / 失败
A: 国内网络访问 GitHub 可能不稳定。`download-fonts.sh` 会自动尝试镜像。仍失败可手动从国内字体镜像下载(注意认证版本号一致)。
### Q: 为什么不用系统自带的苹方/微软雅黑?
A: 这两个字体许可**禁止嵌入 PDF 分发**。用思源系列(SIL OFL)可无限制嵌入,报告传给客户/团队不会有许可问题。
### Q: 字体文件可以入 git 吗?
A: 不推荐。140MB 会严重拖慢 git 操作。目前策略是 `.gitignore` + `download-fonts.sh` 按需下载。
### Q: 我已经有字体文件了,在别的路径
A: 有两种选择:
1. 直接 `cp / ln -s` 到本目录
2. 调用 `report-template.py` 时用 `--fonts-dir /path/to/your/fonts`
### Q: 字体版本会影响渲染吗?
A: 思源字体 v2.x 之后字形基本稳定。霞鹜文楷不同版本字形有微调,建议锁定到 v1.330 或更高。
@@ -0,0 +1,142 @@
#!/usr/bin/env bash
# 字体下载脚本:思源宋体 + 思源黑体 + 霞鹜文楷
# 用法:bash .opencode/templates/fonts/download-fonts.sh
# 许可:全部 SIL OFL,可自由商用、嵌入 PDF 分发
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FONTS_DIR="$SCRIPT_DIR"
echo "====================================="
echo "Deep Research 字体下载"
echo "目标目录:$FONTS_DIR"
echo "====================================="
# 检测下载工具
if command -v curl >/dev/null 2>&1; then
DOWNLOADER="curl -fL --retry 3 --retry-delay 5 -o"
elif command -v wget >/dev/null 2>&1; then
DOWNLOADER="wget -O"
else
echo "❌ 需要 curl 或 wget,请先安装"
exit 1
fi
# 字体清单:文件名 | 下载 URL
# 思源字体走 adobe-fonts GitHub Release 的 "Language Specific OTFs Simplified Chinese" 包
# 霞鹜文楷走 lxgw/LxgwWenKai Release
declare -a FONTS=(
"SourceHanSerifSC-Regular.otf|https://github.com/adobe-fonts/source-han-serif/raw/release/SubsetOTF/CN/SourceHanSerifCN-Regular.otf"
"SourceHanSerifSC-Bold.otf|https://github.com/adobe-fonts/source-han-serif/raw/release/SubsetOTF/CN/SourceHanSerifCN-Bold.otf"
"SourceHanSansSC-Light.otf|https://github.com/adobe-fonts/source-han-sans/raw/release/SubsetOTF/CN/SourceHanSansCN-Light.otf"
"SourceHanSansSC-Medium.otf|https://github.com/adobe-fonts/source-han-sans/raw/release/SubsetOTF/CN/SourceHanSansCN-Medium.otf"
"SourceHanSansSC-Bold.otf|https://github.com/adobe-fonts/source-han-sans/raw/release/SubsetOTF/CN/SourceHanSansCN-Bold.otf"
"SourceHanSansSC-Heavy.otf|https://github.com/adobe-fonts/source-han-sans/raw/release/SubsetOTF/CN/SourceHanSansCN-Heavy.otf"
"LXGWWenKai-Regular.ttf|https://github.com/lxgw/LxgwWenKai/releases/download/v1.330/LXGWWenKai-Regular.ttf"
)
# 备用镜像(主源失败时用)
declare -a MIRRORS=(
"SourceHanSerifSC-Regular.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-serif/release/SubsetOTF/CN/SourceHanSerifCN-Regular.otf"
"SourceHanSerifSC-Bold.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-serif/release/SubsetOTF/CN/SourceHanSerifCN-Bold.otf"
"SourceHanSansSC-Light.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-sans/release/SubsetOTF/CN/SourceHanSansCN-Light.otf"
"SourceHanSansSC-Medium.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-sans/release/SubsetOTF/CN/SourceHanSansCN-Medium.otf"
"SourceHanSansSC-Bold.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-sans/release/SubsetOTF/CN/SourceHanSansCN-Bold.otf"
"SourceHanSansSC-Heavy.otf|https://raw.githubusercontent.com/adobe-fonts/source-han-sans/release/SubsetOTF/CN/SourceHanSansCN-Heavy.otf"
"LXGWWenKai-Regular.ttf|https://ghproxy.com/https://github.com/lxgw/LxgwWenKai/releases/download/v1.330/LXGWWenKai-Regular.ttf"
)
download_font() {
local filename="$1"
local url="$2"
local target="$FONTS_DIR/$filename"
if [[ -f "$target" ]]; then
local size
size=$(stat -f%z "$target" 2>/dev/null || stat -c%s "$target" 2>/dev/null || echo 0)
if [[ $size -gt 100000 ]]; then
echo " ✓ 已存在($size bytes),跳过:$filename"
return 0
else
echo " ⚠ 文件过小($size bytes),重新下载:$filename"
rm -f "$target"
fi
fi
echo " ↓ 下载 $filename ..."
if $DOWNLOADER "$target" "$url" 2>/dev/null; then
local size
size=$(stat -f%z "$target" 2>/dev/null || stat -c%s "$target" 2>/dev/null || echo 0)
if [[ $size -gt 100000 ]]; then
echo " ✓ 完成($size bytes"
return 0
else
echo " ⚠ 下载的文件过小,可能失败"
rm -f "$target"
return 1
fi
else
echo " ✗ 下载失败"
rm -f "$target"
return 1
fi
}
get_mirror_url() {
local filename="$1"
for entry in "${MIRRORS[@]}"; do
IFS='|' read -r fn url <<< "$entry"
if [[ "$fn" == "$filename" ]]; then
echo "$url"
return 0
fi
done
return 1
}
echo ""
echo "开始下载..."
echo ""
FAILED=()
for entry in "${FONTS[@]}"; do
IFS='|' read -r filename url <<< "$entry"
if ! download_font "$filename" "$url"; then
# 主源失败,试镜像
mirror_url=$(get_mirror_url "$filename" || true)
if [[ -n "$mirror_url" ]]; then
echo " ↻ 尝试镜像..."
if download_font "$filename" "$mirror_url"; then
continue
fi
fi
FAILED+=("$filename")
fi
done
echo ""
echo "====================================="
if [[ ${#FAILED[@]} -eq 0 ]]; then
echo "✅ 全部字体下载成功!"
echo ""
echo "字体文件清单:"
ls -lh "$FONTS_DIR" | grep -E '\.(otf|ttf)$' || true
echo ""
echo "许可证:全部 SIL OFL,可自由商用、嵌入 PDF 分发。"
exit 0
else
echo "❌ 以下字体下载失败:"
for f in "${FAILED[@]}"; do
echo " - $f"
done
echo ""
echo "请手动下载,并放入 $FONTS_DIR/"
echo ""
echo "手动下载链接:"
echo " 思源宋体:https://github.com/adobe-fonts/source-han-serif/releases"
echo " 思源黑体:https://github.com/adobe-fonts/source-han-sans/releases"
echo " 霞鹜文楷:https://github.com/lxgw/LxgwWenKai/releases"
exit 1
fi