Files
font2pic/miniprogram/README.md
2026-02-08 22:31:25 +08:00

60 lines
1.9 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.

# miniprogram
`miniprogram/``font2svg` 的微信小程序版本,面向移动端提供字体预览与导出能力。
## 已实现能力
- 文本输入 + 字体选择(搜索/分类/收藏)
- 远端 API 生成 SVG服务端读取字体并渲染
- SVG 预览
- 导出 SVG 并调用 `wx.shareFileMessage` 分享
- 远端 API 生成 PNG保存到系统相册
## 目录说明
```text
miniprogram/
├── pages/
│ ├── index/ # 首页:输入、预览、导出
│ └── font-picker/ # 字体选择页
├── utils/
│ ├── core/ # 纯算法模块
│ └── mp/ # 小程序 API 适配层
├── assets/fonts.json # 字体清单(由脚本生成)
├── app.js / app.json / app.wxss
└── project.config.json
```
## 使用步骤
1. 在仓库根目录执行 `pnpm run prepare-fonts`,同步字体清单。
2. 打开微信开发者工具,导入 `miniprogram/` 目录。
3. 在小程序后台配置合法域名(`request` + `downloadFile`)。
4. 部署并启动 `apiserver/`(详见 `apiserver/README.md`)。
5. Nginx 配置 `/api/` 反向代理到渲染服务。
6. 编译运行。
## 导出说明
- `SVG`:受微信限制,`shareFileMessage` 需由单次点击直接触发,建议逐个字体导出。
- `PNG`:由服务端 `POST /api/render-png` 直接返回二进制,小程序仅负责保存到相册。
## 字体清单格式(由服务端解析)
`assets/fonts.json` 每项字段:
- `id`: 字体唯一 ID
- `name`: 字体显示名
- `category`: 分类
- `path`: 字体地址(支持相对路径或完整 URL
如果 `path` 是相对路径(例如 `/fonts/a.ttf`),服务端会根据静态根目录拼接到实际文件路径。
## 调试命令(仓库根目录)
```bash
pnpm run mp:syntax
pnpm run mp:lint
pnpm run mp:test
```