From 5727d95d90762ab50d5037aaf6807206f8698ba8 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Thu, 26 Nov 2026 22:50:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(crates/panache-mcp):=20=E7=85=A7=E7=89=87?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=9C=AA=E6=8C=87=E5=AE=9A=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E6=97=B6=E4=BD=BF=E7=94=A8=E6=89=8B=E5=86=99=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景:模型选了作业排版却省略字体,首份照片小样仍使用文楷。 解决手段:只在新建照片作业且未指定字体时优先选用已捆绑的李国夫手写体。 收益:省略字体也能生成手写小样,显式选字和旧稿保持原样。 --- crates/panache-mcp/src/inputs.rs | 39 ++++++++++++++++++++--- crates/panache-mcp/src/save.rs | 53 ++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/crates/panache-mcp/src/inputs.rs b/crates/panache-mcp/src/inputs.rs index 54638337..7bd5096a 100644 --- a/crates/panache-mcp/src/inputs.rs +++ b/crates/panache-mcp/src/inputs.rs @@ -41,18 +41,20 @@ pub enum Format { #[serde(default, deny_unknown_fields)] pub struct Style { /// Main font ID from list_fonts. Bundled filenames remain valid. English letters and digits follow it by default. + #[schemars(transform = remove_schema_default)] pub font: String, pub paper: Paper, /// RGB hex color, e.g. #302c30. pub ink: String, /// Pixels at the paper's native resolution (794 × 1123 for presets). Accepted range 16–72. pub font_size: u8, + /// Homework paragraph layout. On a new photo sheet this also selects a handwriting font when font is omitted. pub homework: bool, /// Keep this value to reproduce handwriting variations. - #[schemars(transform = remove_seed_default)] + #[schemars(transform = remove_schema_default)] pub seed: u32, } -fn remove_seed_default(schema: &mut schemars::Schema) { +fn remove_schema_default(schema: &mut schemars::Schema) { schema.remove("default"); } @@ -97,6 +99,32 @@ pub struct Guide { pub right: [u32; 2], } +// Only creation distinguishes an omitted font from an explicitly selected default. +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +pub struct CreationStyle { + #[serde(default, deserialize_with = "explicit_font")] + font: Option, + #[serde(flatten)] + settings: Style, +} +fn explicit_font<'de, D: serde::Deserializer<'de>>(d: D) -> Result, D::Error> { + String::deserialize(d).map(Some) +} + +impl CreationStyle { + pub fn resolve(&self, photo: bool, bundled: &[String]) -> Style { + let mut style = self.settings.clone(); + if let Some(font) = &self.font { + style.font.clone_from(font); + } else if photo && style.homework && bundled.iter().any(|id| id == "李国夫手写体.ttf") + { + style.font = "李国夫手写体.ttf".into(); + } + style + } +} + #[derive(Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] pub struct Save { @@ -117,8 +145,11 @@ pub struct Save { pub section: Option, /// Set only on creation. pub title: Option, - /// Set only on creation. Stored with the draft. - pub style: Option