diff --git a/src/lib.rs b/src/lib.rs index 51b6f0d..c9cab4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ mod message; #[test] fn main_test() { + use cn_font_proto::api_interface::input_template::CssProperties; use cn_font_proto::api_interface::input_template::PreviewImage; use cn_font_proto::api_interface::InputTemplate; use cn_font_utils::{output_file, read_binary_file}; @@ -20,6 +21,20 @@ fn main_test() { name: "preview".to_string(), text: "中文网字计划\nThe Chinese Web Font Project".to_string(), }), + css: Some(CssProperties { + // font_family: Some("New".to_string()), + // font_weight: Some("200".to_string()), + // font_style: Some("italic".to_string()), + // font_display: Some("auto".to_string()), + // local_family: vec!["New2".to_string()], + // polyfill: vec![], + // comment_base: Some(true), + // comment_name_table: Some(true), + // comment_unicodes: Some(true), + // compress: Some(true), + // file_name: Some("input.css".to_string()), + ..Default::default() + }), ..Default::default() }; diff --git a/src/link_subset/output_css.rs b/src/link_subset/output_css.rs index 066b594..6bc27d8 100644 --- a/src/link_subset/output_css.rs +++ b/src/link_subset/output_css.rs @@ -74,20 +74,23 @@ pub fn output_css(ctx: &mut Context, css: &CssProperties) -> String { .join(",") + polyfill_str.as_str(); let unicode_range = &UnicodeRange::stringify(&res.unicodes); + let space = + if css.compress.unwrap_or(true) == true { "" } else { " " }; let face_code = format!( r#"@font-face{{ -font-family:"{font_family}"; -src:{src_str}; -font-style:{font_style}; -font-display:{display}; -font-weight:{font_weight}; -unicode-range:{unicode_range}; +{space}font-family:"{font_family}"; +{space}src:{src_str}; +{space}font-style:{font_style}; +{space}font-display:{display}; +{space}font-weight:{font_weight}; +{space}unicode-range:{unicode_range}; }}"# ); // css 这个句尾不需要分号😭 // 根据注释设置生成Unicode范围的注释。 let comment = if css.comment_unicodes.unwrap_or(false) { - vec_u32_to_string(&res.unicodes) + let code_string = vec_u32_to_string(&res.unicodes); + format!("/* {} */\n", code_string) } else { "".to_string() };