Skip to content

Commit

Permalink
fix: 修复 css 中 space 和 字符显示的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
KonghaYao committed Jan 5, 2025
1 parent 7a05cd0 commit 1c54f20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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()
};

Expand Down
17 changes: 10 additions & 7 deletions src/link_subset/output_css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down

0 comments on commit 1c54f20

Please sign in to comment.