diff --git a/packages/ffi-js/package.json b/packages/ffi-js/package.json index d46cb88a..b762f9a4 100644 --- a/packages/ffi-js/package.json +++ b/packages/ffi-js/package.json @@ -1,6 +1,6 @@ { "name": "cn-font-split", - "version": "7.0.0-beta.4", + "version": "7.0.1", "description": "划时代的字体切割工具,CJK与任何字符!支持 otf、ttf、woff2 字体多线程切割,完美地细颗粒度地进行包大小控制。A revolutionary font subetter that supports CJK and any characters! It enables multi-threaded subset of otf, ttf, and woff2 fonts, allowing for precise control over package size.", "main": "./dist/node/index.js", "module": "./dist/node/index.mjs", diff --git a/src/lib.rs b/src/lib.rs index 08cda9a7..94720527 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ fn main_test() { use cn_font_utils::{output_file, read_binary_file}; use log::info; - let path = "./src/国标宋体.ttf"; + let path = "./src/白路棒棒手写体.ttf"; let font_file = read_binary_file(&path).expect("Failed to read file"); let input = InputTemplate { input: font_file, diff --git a/src/pre_subset/features/gsub.rs b/src/pre_subset/features/gsub.rs index c2485eee..07a1c95a 100644 --- a/src/pre_subset/features/gsub.rs +++ b/src/pre_subset/features/gsub.rs @@ -8,6 +8,7 @@ pub fn analyze_gsub( font: &Font, font_file: &mut Cursor<&Vec>, ) -> Vec> { + // 丑陋的多层 unwrap 处理 let temp: Result, std::io::Error> = font.take(font_file); // 国标宋体,解析就报错,所以干脆先不解析 @@ -15,8 +16,14 @@ pub fn analyze_gsub( error!("{}", temp.unwrap_err()); return vec![vec![]]; } + // GSUB - let data: GlyphSubstitution = temp.unwrap().unwrap(); + let temp1 = temp.unwrap(); + if temp1.is_none() { + error!("Font without GSUB table"); + return vec![vec![]]; + } + let data: GlyphSubstitution = temp1.unwrap(); // let mut feature_tags: Vec<&str> = data // .features diff --git a/src/pre_subset/gen_svg.rs b/src/pre_subset/gen_svg.rs index 1ce372c5..980ce2ec 100644 --- a/src/pre_subset/gen_svg.rs +++ b/src/pre_subset/gen_svg.rs @@ -18,8 +18,13 @@ pub fn gen_svg_from_font_file(file: &[u8], text: &str) -> String { pub fn gen_svg_from_ctx(ctx: &mut Context) { if let Some(preview) = &ctx.input.preview_image { let text = gen_svg(&mut ctx.face, &preview.text); + let name = if preview.name == "" { + String::from("preview") + } else { + preview.name.clone() + }; (ctx.callback)(EventMessage::output_data( - format!("{}.svg", preview.name).as_str(), + format!("{}.svg", name).as_str(), text.as_bytes().to_vec(), )); }