Skip to content

feat(crates/panache-mcp): 照片作业未指定字体时使用手写体 - #64

Merged
SXP-Simon merged 1 commit into
mainfrom
fix/worksheet-font
Nov 27, 2026
Merged

SXP-Simon merged 1 commit into
mainfrom
fix/worksheet-font

Conversation

@SXP-Simon

@SXP-Simon SXP-Simon commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

为什么改

拍下来的作业纸上,希望第一份小样像平常写作业的字。模型即使查过字体表,在保存时也可能省略字体,原来的默认效果仍是文楷。

这个草稿做什么

只在新建稿件、传入照片底纸、启用 style.homework 且省略 style.font 时,优先使用已捆绑的李国夫手写体。用户指定字体时沿用指定值。未安装这款字时沿用原先默认。普通稿、拉正模式和已保存稿件沿用各自原有选择。工具字段同时说清适用场景,并建议在原纸上看一小段中英文和数字。

本机证据

同一题目,两个独立模型会话各跑一次。给模型一张合成原纸、一张打印模板和一行中英数字作业,请它在原纸上先出小样。客户端限用真实 MCP,转发器略去启动说明。通过 SQLite 核对第一页真正存入的字体。

版本 Luna Terra
当前 main 文楷 文楷
只改创建字段提示的实验版 查了字体,仍省略,保存为文楷 主动选手写体
最终草稿 省略字体,保存为手写体 省略字体,保存为手写体

17 项 MCP 单元测试通过,Clippy 通过。新增测试覆盖显式文楷、自定义字体、缺少手写字体、普通稿、拉正模式和非法参数。固定底纸、文字和随机种子后,两款字体均能生成预览,实际像素不同。

这是两次独立小样的结果。若模型没有选择作业排版,服务端仍按常规稿处理。#56 负责如何展示和延续获选小样,这个 PR 只决定第一份照片作业小样在省略字体时使用哪款字。

Summary by Sourcery

Default new photo homework drafts to the bundled handwriting font while preserving explicit and existing font selections in all other cases.

New Features:

  • Use the bundled 李国夫手写体.ttf as the default font for newly created photo-based homework drafts when no font is specified.

Bug Fixes:

  • Preserve the existing default font behavior when the handwriting font is unavailable or when the draft is not a new photo homework draft.

Enhancements:

  • Distinguish omitted fonts from explicitly selected fonts during creation and clarify the applicable style behavior in the tool schema.

Tests:

  • Add coverage for photo homework defaults, explicit fonts, unavailable handwriting fonts, non-photo modes, ordinary drafts, and invalid style parameters.

背景:模型选了作业排版却省略字体,首份照片小样仍使用文楷。

解决手段:只在新建照片作业且未指定字体时优先选用已捆绑的李国夫手写体。

收益:省略字体也能生成手写小样,显式选字和旧稿保持原样。
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Update the MCP creation-style input schema and guidance to document the photo-homework default while keeping schema defaults from overriding omission semantics.

  • crates/panache-mcp/src/inputs.rs L44, L51-57, L148-152

Implementation

Preserve whether the creation request explicitly supplied a font and resolve the omitted-font case to the bundled handwriting font only for photo homework.

  • crates/panache-mcp/src/inputs.rs L102-127

Pass the bundled-font list into validation and apply the creation default only when the request is a new photo-sheet homework draft.

  • crates/panache-mcp/src/save.rs L8, L19, L44-50

Tests

Cover the photo-homework default, explicit font choices, missing bundled font, non-photo cases, and invalid creation-style arguments.

  • crates/panache-mcp/src/save.rs L130-170

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@SXP-Simon
SXP-Simon marked this pull request as ready for review November 27, 2026 06:29
@sourcery-ai

sourcery-ai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Sorry @SXP-Simon, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 22 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@SXP-Simon
SXP-Simon merged commit 434230e into main Nov 27, 2026
1 check passed
SXP-Simon added a commit that referenced this pull request Nov 27, 2026
## 使用场景

用户只贴一段文字,说「请把这段文字排成一份手写作业」。#64
已能为照片作业选用李国夫手写体,但同一份作业换成白纸时仍会落回文楷。底纸负责落字位置,是否是作业由聊天里的请求决定。

## 改后怎么用

AI 收到作业请求时,在首次 `save_section` 传 `style.homework=true`
即可。用户无需准备纸张照片、点名字体或先调参数。纯文字、预设纸、照片和拉正底纸采用同一套作业默认值。普通通知或便笺仍用普通稿默认值。如果模型先查旧稿,首次查询为空时也会说明如何直接用已给的正文建稿。

```json
{"markdown":"第一题:观察循环中 i 的变化。\n当 i = 10 时,记录结果为 20 cm。","style":{"homework":true}}
```

- 有随包字体时优先选李国夫手写体。显式指定的文楷、个人字体等优先,缺少李国夫时沿用原有字体回退。
- 基于已有的逐字随机变化:字号的标准差从 **1 px 到 1.5 px**,倾角的标准差从 **0.05 到 0.07 弧度**(约
2.9° 到 4.0°)。字间距、行距、横纵偏移、墨色和涂改均沿用原值。数字和字母沿用主字体。
- 想要工整小样,创建时可设 `relaxed_handwriting=false`。已有稿继续用保存时的字体、变化幅度和种子。单项参数仍可通过
`tune_handwriting` 调整,清除覆盖值会恢复建稿时的手感。

## Windows 本机验证

基线 `main@fd44602`。使用真实 stdio MCP,把相同正文、34 px 字号和相同随机种子 60
分别渲染成文楷、只换李国夫、李国夫加轻微变化三份样张。后两张有 **5,020
个像素不同**,主要风格差别来自字体。这个数字只验证变化确实参与出图。预览后导出 1 页 PDF。


新程序重开旧程序创建的纯文字作业和照片作业,重新渲染结果均逐像素相同。新稿固定种子重复渲染相同,普通便笺与基线相同。覆盖上述两项数值后与「只换字体」小样完全相同,清除覆盖后与新默认小样完全相同。另验证照片与拉正底纸的实际参数、缺少字体与显式选字。20
项 MCP 单元测试、Clippy 和格式检查通过;真实稿件列表分页脚本通过。

## Luna / Terra 实测


用独立会话和新数据库,不给纸张或字体提示。真实工具回执和图片向模型开放,转发器省略启动说明,检查实际建稿参数和数据库记录。每个模型、每种措辞、每个受测版本各一次。

| 用户给的任务 | 当前 main | 此稿 |
| --- | --- | --- |
| 明确说「请把这段文字排成一份手写作业,生成第一页给我预览」 | 两者都启用作业排版、都省略字体,首张均是文楷 |
两者同样省略字体,首张均是李国夫,且均已启用轻微扰动 |
| 「帮我把下面的作业写好,先看第一页」后附文字 | 两者都去找旧稿,均未建稿 | Terra 用给定文字建稿并实际预览;Luna 仍要求补材料
|
| 作业明确要求文楷、工整 | — | 两者都保存文楷、关闭额外扰动,并预览 |
| 普通会议便笺 | — | Terra 用文楷及普通排版;Luna 停在查旧稿 |

边界是调用者须将用户的作业意图传入
`homework`。服务端不会根据正文里出现「第一题」等词强行分类。上述会话用于复现操作路径,不能当作整体成功率。与
#56(新手和选版提示)、#59(按需回读控件)分别本地试合,无文本冲突。

## Summary by Sourcery

为文字作业统一应用手写字体和轻微笔迹变化默认值,并完善作业创建与恢复提示。

New Features:
- 为纯文字、预设纸和照片底纸的作业创建统一的默认手写风格,优先使用随包的李国夫手写体并启用轻微字形变化。
- 新增 `relaxed_handwriting` 创建选项,允许用户关闭作业字形的额外大小和倾斜变化。
- 在无旧稿且用户已提供作业正文时,提示客户端直接创建并预览作业。

Bug Fixes:
- 修正作业字体默认值仅在照片底纸场景生效的问题,使其适用于所有底纸类型。

Enhancements:
- 将作业字体与手写变化参数在创建时固定保存,确保已有稿件和后续重新渲染保持一致,并继续支持显式字体和参数覆盖。

Documentation:
- 更新 MCP 使用说明和工具提示,说明如何创建文字作业、选择字体及控制手写变化。

Tests:
- 补充作业默认字体、手写变化、覆盖选项及不同底纸场景的测试,并更新无旧稿列表查询测试。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant