Skip to content

Commit

Permalink
fix: 修复国标宋体效果
Browse files Browse the repository at this point in the history
  • Loading branch information
huangxn27 committed Dec 25, 2024
1 parent 38d8ed2 commit 72fdeb3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ harfbuzz_rs_now = "2.2.6"
lang-unicodes = { version = "0.1.0", path = "crates/lang_unicodes" }
log = "0.4.22"
md5 = "0.7.0"
opentype = "0.38.0"
opentype = "0.38.1"
prost = "0.13.3"
cn-font-proto = { version = "0.1.1", path = "crates/proto" }
rayon = "1.10.0"
Expand Down
17 changes: 13 additions & 4 deletions src/pre_subset/features/gsub.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::error;
use opentype::layout::{context, ChainedContext, Coverage};
use opentype::tables::glyph_substitution::Type;
use opentype::tables::GlyphSubstitution;
Expand All @@ -7,8 +8,15 @@ pub fn analyze_gsub(
font: &Font,
font_file: &mut Cursor<&Vec<u8>>,
) -> Vec<Vec<u16>> {
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 = font.take(font_file).unwrap().unwrap();
let data: GlyphSubstitution = temp.unwrap().unwrap();

// let mut feature_tags: Vec<&str> = data
// .features
Expand Down Expand Up @@ -237,9 +245,10 @@ pub fn analyze_gsub(
#[test]
fn test_gsub() {
use cn_font_utils::read_binary_file;
let font_file =
read_binary_file("./packages/demo/public/WorkSans-VariableFont_wght.ttf")
.unwrap();
let font_file = read_binary_file(
"./packages/demo/public/WorkSans-VariableFont_wght.ttf",
)
.unwrap();
let mut font_file = Cursor::new(&font_file);
let font = Font::read(&mut font_file).unwrap();
let result = analyze_gsub(&font, &mut font_file);
Expand Down
1 change: 1 addition & 0 deletions src/run_subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub fn run_subset(ctx: &mut Context) {
warn!(
"subsets result diff: {}",
diff.iter()
.filter(|x| **x != 0)
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(" ")
Expand Down

0 comments on commit 72fdeb3

Please sign in to comment.