修正导出字体的 CSS 格式声明
Project CI / Backend tests (pull_request) Failing after 15s
Project CI / Native shell tests (pull_request) Failing after 17m20s
Project CI / Repository checks (pull_request) Failing after 9s
Project CI / Frontend tests (pull_request) Successful in 3m5s

将 TrueType/OpenType 映射为标准的 truetype/opentype format() 字符串

补充四种字体格式的 CSS 名称单元测试
This commit is contained in:
2026-09-01 19:09:45 +08:00
parent e708e09c91
commit e776a8d8af
2 changed files with 18 additions and 1 deletions
@@ -5,7 +5,7 @@ pub(super) fn font_face_rule(
family: &str,
) -> Result<String, String> {
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 {
@@ -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");
}
}