Skip to content

Commit

Permalink
fix: 修复图片名称及 gsub 的判断缺失
Browse files Browse the repository at this point in the history
  • Loading branch information
KonghaYao committed Jan 1, 2025
1 parent 079e42e commit 2f7493a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ffi-js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/pre_subset/features/gsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ pub fn analyze_gsub(
font: &Font,
font_file: &mut Cursor<&Vec<u8>>,
) -> Vec<Vec<u16>> {
// 丑陋的多层 unwrap 处理
let temp: Result<Option<GlyphSubstitution>, std::io::Error> =
font.take(font_file);
// 国标宋体,解析就报错,所以干脆先不解析
if temp.is_err() {
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
Expand Down
7 changes: 6 additions & 1 deletion src/pre_subset/gen_svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
}
Expand Down

0 comments on commit 2f7493a

Please sign in to comment.