修正导出字体的 CSS 格式声明
将 TrueType/OpenType 映射为标准的 truetype/opentype format() 字符串 补充四种字体格式的 CSS 名称单元测试
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user