补充字体 CSS 格式回归测试

验证 TTF 与 OTF 导出使用标准 truetype 与 opentype 格式

覆盖 html_renderer @font-face 实际输出
This commit is contained in:
2026-09-01 19:55:35 +08:00
parent 14de561408
commit 13f23a1fad
@@ -54,6 +54,37 @@ pub(super) fn trim_float(value: f32) -> String {
text.trim_end_matches('0').trim_end_matches('.').to_string()
}
#[cfg(test)]
mod tests {
use super::font_face_rule;
use crate::ui_editor::resource::font::{FontAsset, FontAssetMetadata, FontFormat};
use crate::ui_editor::utils::FontAssetId;
fn font(format: FontFormat) -> FontAsset {
FontAsset {
asset_id: FontAssetId::new("font-main").expect("valid font id"),
metadata: FontAssetMetadata {
family_name: "测试字体".to_string(),
face_name: "Regular".to_string(),
weight: 400,
italic: false,
format,
source_file_name: format!("font.{}", format.extension()),
},
path: format!("assets/font.{}", format.extension()),
content_sha256: "0".repeat(64),
}
}
#[test]
fn font_face_rule_uses_standard_css_format_names() {
let truetype = font_face_rule(&font(FontFormat::TrueType), "ui-font").unwrap();
let opentype = font_face_rule(&font(FontFormat::OpenType), "ui-font").unwrap();
assert!(truetype.contains("format('truetype')"));
assert!(opentype.contains("format('opentype')"));
}
}
pub(super) fn hex_id(value: &str) -> String {
value
.as_bytes()