Skip to content

Commit 5ab978a

Browse files
committed
This works, but is still ugly (very verbose)
1 parent da0133e commit 5ab978a

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
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
};
@@ -89,16 +89,16 @@ impl TestFont {
8989
Ok(os2.fs_selection())
9090
}
9191

92-
pub fn get_gdef_glyph_class_def(&self) -> Result<ClassDef, Box<dyn Error>> {
93-
let gdef = self.font().gdef()?;
94-
Ok(gdef.glyph_class_def().unwrap()?)
95-
}
96-
9792
pub fn get_cmap(&self) -> Result<Cmap, Box<dyn Error>> {
9893
let cmap = self.font().cmap()?;
9994
Ok(cmap)
10095
}
10196

97+
pub fn get_gdef(&self) -> Result<Gdef, Box<dyn Error>> {
98+
let gdef = self.font().gdef()?;
99+
Ok(gdef)
100+
}
101+
102102
pub fn get_name_entry_strings(&self, name_id: StringId) -> LocalizedStrings {
103103
self.font().localized_strings(name_id)
104104
}

profile-universal/src/checks/arabic_spacing_symbols.rs

+32-6
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,48 @@ const ARABIC_SPACING_SYMBOLS: [u16; 17] = [
2020
0xFBC2, // Wasla Above
2121
];
2222

23-
fn arabic_spacing_symbols(t: &Testable) -> StatusList {
23+
fn arabic_spacing_symbols(t: &Testable) -> CheckFnResult {
2424
let mut problems: Vec<Status> = vec![];
25-
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();
25+
let f = TTF.from_testable(t).ok_or("Not a TTF file")?;
26+
let cmap = match f.get_cmap() {
27+
Err(_) => {
28+
problems.push(Status::fail("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::fail("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);
31-
if gid.is_some() && class_def.get(gid.unwrap()) == 3 {
57+
if gid.is_some() && class_def.get(gid.ok_or("Failed to read gid")?) == 3 {
3258
problems.push(Status::fail(&format!(
3359
"U+{:04X} is defined in GDEF as a mark (class 3).", codepoint)));
3460
}
3561
}
3662

3763
if problems.is_empty() {
38-
Status::just_one_pass()
64+
Ok(Status::just_one_pass())
3965
} else {
4066
return_result(problems)
4167
}

0 commit comments

Comments
 (0)