diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs index 15c99ce95..b4c433087 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs @@ -5,7 +5,7 @@ pub(super) fn font_face_rule( family: &str, ) -> Result { let path = asset_url(&font.path)?; - Ok(format!("@font-face{{font-family:'{family}';src:url('{path}') format('{}');font-style:{};font-weight:{};}}", font.metadata.format.extension(), if font.metadata.italic { "italic" } else { "normal" }, font.metadata.weight)) + Ok(format!("@font-face{{font-family:'{family}';src:url('{path}') format('{}');font-style:{};font-weight:{};}}", font.metadata.format.css_format(), if font.metadata.italic { "italic" } else { "normal" }, font.metadata.weight)) } pub(super) fn html_comment(label: &str, value: serde_json::Value) -> Markup { diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/resource/font.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/resource/font.rs index 776f4b2e5..70efc4131 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/resource/font.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/resource/font.rs @@ -30,6 +30,15 @@ impl FontFormat { Self::Woff2 => "woff2", } } + + pub fn css_format(self) -> &'static str { + match self { + Self::TrueType => "truetype", + Self::OpenType => "opentype", + Self::Woff => "woff", + Self::Woff2 => "woff2", + } + } } #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TS)] @@ -210,4 +219,12 @@ mod tests { .expect_err("reject unparseable web font") .contains("无法安全解析")); } + + #[test] + fn font_format_uses_css_format_strings() { + assert_eq!(FontFormat::TrueType.css_format(), "truetype"); + assert_eq!(FontFormat::OpenType.css_format(), "opentype"); + assert_eq!(FontFormat::Woff.css_format(), "woff"); + assert_eq!(FontFormat::Woff2.css_format(), "woff2"); + } }