Skip to content

Commit 6eecb60

Browse files
committed
This works, but is very verbose
and still has got a gid.unwrap, which I think is fine due to the preceding gid.is_some(), but I may be wrong.
1 parent 7ee16f5 commit 6eecb60

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

fontspector-checkapi/src/font.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{constants::RIBBI_STYLE_NAMES, filetype::FileTypeConvert, FileType, Testable};
22
use read_fonts::{
33
tables::cmap::Cmap,
4-
tables::gdef::ClassDef,
4+
tables::gdef::Gdef,
55
tables::os2::SelectionFlags,
66
TableProvider,
77
};
@@ -73,16 +73,16 @@ impl TestFont {
7373
Ok(os2.fs_selection())
7474
}
7575

76-
pub fn get_gdef_glyph_class_def(&self) -> Result<ClassDef, Box<dyn Error>> {
77-
let gdef = self.font().gdef()?;
78-
Ok(gdef.glyph_class_def().unwrap()?)
79-
}
80-
8176
pub fn get_cmap(&self) -> Result<Cmap, Box<dyn Error>> {
8277
let cmap = self.font().cmap()?;
8378
Ok(cmap)
8479
}
8580

81+
pub fn get_gdef(&self) -> Result<Gdef, Box<dyn Error>> {
82+
let gdef = self.font().gdef()?;
83+
Ok(gdef)
84+
}
85+
8686
pub fn get_name_entry_strings(&self, name_id: StringId) -> LocalizedStrings {
8787
self.font().localized_strings(name_id)
8888
}

fontspector-checkapi/src/status.rs

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl Status {
6060
code: StatusCode::Fail,
6161
}
6262
}
63+
pub fn error(s: &str) -> Self {
64+
Self {
65+
message: Some(s.to_string()),
66+
code: StatusCode::Error,
67+
}
68+
}
6369
pub fn skip(s: &str) -> Self {
6470
Self {
6571
message: Some(s.to_string()),

profile-universal/src/checks/arabic_spacing_symbols.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,34 @@ const ARABIC_SPACING_SYMBOLS: [u16; 17] = [
2323
fn arabic_spacing_symbols(t: &Testable) -> StatusList {
2424
let mut problems: Vec<Status> = vec![];
2525
let f = TTF.from_testable(t).expect("Not a TTF file");
26-
let cmap = f.get_cmap().unwrap();
27-
let class_def = f.get_gdef_glyph_class_def().unwrap();
26+
let cmap = match f.get_cmap() {
27+
Err(_) => {
28+
problems.push(Status::error("Font lacks a cmap table"));
29+
return return_result(problems);
30+
},
31+
Ok(c) => c
32+
};
33+
34+
let gdef = match f.get_gdef() {
35+
Err(_) => {
36+
problems.push(Status::error("Font lacks a gdef table"));
37+
return return_result(problems);
38+
},
39+
Ok(g) => g
40+
};
41+
42+
let class_def = match gdef.glyph_class_def() {
43+
None => return return_result(problems),
44+
Some(d) => d
45+
};
46+
47+
let class_def = match class_def {
48+
Err(e) => {
49+
problems.push(Status::error(&format!("Some classDef error: {}", e)));
50+
return return_result(problems);
51+
},
52+
Ok(d) => d
53+
};
2854

2955
for codepoint in ARABIC_SPACING_SYMBOLS {
3056
let gid = cmap.map_codepoint(codepoint);

0 commit comments

Comments
 (0)