Skip to content

Commit

Permalink
Merge remote-tracking branch 'coding/fixture/cli' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
KonghaYao committed Dec 25, 2024
2 parents 27d80ed + 0d86494 commit a7fbea2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 38 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
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 = "./packages/demo/public/SmileySans-Oblique.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
19 changes: 9 additions & 10 deletions src/link_subset/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,14 @@
<!-- 每个包的数据 -->
<template id="pkg-list">
<van-cell-group inset title="字体分包详情">
<van-collapse v-model="activeNames" ref="collapse">
<van-collapse-item
v-for="(pkg) in reporter.subsetDetail??[]"
:title="pkg.hash"
:name="pkg.hash"
>
<span> {{String.fromCodePoint(...pkg.chars)}} </span>
</van-collapse-item>
</van-collapse>
<div
v-for="(pkg) in reporter.subsetDetail??[]"
:title="pkg.hash"
:name="pkg.hash"
>
<div>{{pkg.hash}}</div>
<span> {{String.fromCodePoint(...pkg.chars)}} </span>
</div>
</van-cell-group>
</template>
<script>
Expand All @@ -410,7 +409,7 @@
};
},
mounted() {
this.$refs.collapse.toggleAll(true);
// this.$refs.collapse.toggleAll(true);
},
});
</script>
Expand Down
44 changes: 26 additions & 18 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 @@ -175,24 +183,23 @@ pub fn analyze_gsub(
}
ChainedContext::Format3(ctx) => {
// println!("??? {:?}\n", context);
// BUG 不知为何有这种规则导致匹配贼多
// ! BUG 不知为何有这种规则导致匹配贼多
// coverages 是触发的glyph
// forward_coverages 和 backward_coverages 是左右匹配的 glyph
// 反正所有的字形都是相关的,合并到一块
let mut result: Vec<u16> = vec![];
collect_glyph_id_from_format_1_and_2(
&ctx.coverages,
&mut result,
);
collect_glyph_id_from_format_1_and_2(
&ctx.forward_coverages,
&mut result,
);
collect_glyph_id_from_format_1_and_2(
&ctx.backward_coverages,
&mut result,
);
// vec![result]
// collect_glyph_id_from_format_1_and_2(
// &ctx.coverages,
// &mut result,
// );
// collect_glyph_id_from_format_1_and_2(
// &ctx.forward_coverages,
// &mut result,
// );
// collect_glyph_id_from_format_1_and_2(
// &ctx.backward_coverages,
// &mut result,
// );
// println!("||| {:?}\n", result);
vec![result]
}
Expand Down Expand Up @@ -238,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 a7fbea2

Please sign in to comment.