cn_font_split/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
pub mod link_subset;
pub mod pre_subset;
pub mod run_subset;
pub mod runner;
pub use runner::font_split;
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::u32_array_to_u8_array;
use cn_font_utils::{output_file, read_binary_file};
use log::info;
let path = "./packages/demo/public/SmileySans-Oblique.ttf";
let font_file = read_binary_file(&path).expect("Failed to read file");
let input = InputTemplate {
input: font_file,
preview_image: Some(PreviewImage {
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()
}),
// 精确控制
// subsets: vec![[65]].iter().map(|x| u32_array_to_u8_array(x)).collect(),
// language_areas: Some(false),
// auto_subset: Some(false),
// font_feature: Some(false),
// reduce_mins: Some(false),
// rename_output_font: Some("font_[hash:6].[ext]".to_string()),
..Default::default()
};
let start = std::time::Instant::now();
env_logger::init();
info!("this is a debug {}", "message");
font_split(input, |m| {
// println!("{} {}", m.event, m.message.unwrap_or("".to_owned()));
// 打开一个文件以供写入,如果文件不存在,则创建它
match m.data {
Some(data) => {
output_file(&format!("dist/{}", m.message), &data)
.expect("write file error");
}
_ => (),
}
});
let duration = start.elapsed();
println!("Time: {:?}", duration);
}