|
1 |
| -// use std::collections::HashSet; |
| 1 | +use std::collections::HashSet; |
2 | 2 |
|
3 | 3 | use fontspector_checkapi::{return_result, Check, FontCollection, Status, StatusCode, StatusList};
|
4 |
| -// use read_fonts::tables::os2::SelectionFlags; |
5 |
| -// use skrifa::string::StringId; |
| 4 | +use read_fonts::tables::os2::SelectionFlags; |
| 5 | +use skrifa::string::StringId; |
6 | 6 |
|
7 |
| -fn bold_italic_unique(_c: &FontCollection) -> StatusList { |
8 |
| - return_result(vec![]) |
9 |
| - // let ribbi = c.ribbi_fonts(); |
10 |
| - // let mut problems = vec![]; |
11 |
| - // let mut flags: HashSet<(bool, bool)> = HashSet::new(); |
12 |
| - // for font in ribbi.iter() { |
13 |
| - // let _names_list = font.get_name_entry_strings(StringId::FAMILY_NAME); |
14 |
| - // match font.get_os2_fsselection() { |
15 |
| - // Ok(fsselection) => { |
16 |
| - // let val = ( |
17 |
| - // fsselection.intersects(SelectionFlags::BOLD), |
18 |
| - // fsselection.intersects(SelectionFlags::ITALIC), |
19 |
| - // ); |
20 |
| - // if flags.contains(&val) { |
21 |
| - // problems.push(Status { |
22 |
| - // message: Some(format!( |
23 |
| - // "Font {} has the same selection flags ({}{}{}) as another font", |
24 |
| - // font.filename, |
25 |
| - // if val.0 { "bold" } else { "" }, |
26 |
| - // if val.0 && val.1 { " & " } else { "" }, |
27 |
| - // if val.1 { "italic" } else { "" } |
28 |
| - // )), |
29 |
| - // code: StatusCode::Error, |
30 |
| - // }); |
31 |
| - // } else { |
32 |
| - // flags.insert(val); |
33 |
| - // } |
34 |
| - // } |
35 |
| - // Err(_e) => problems.push(Status { |
36 |
| - // message: Some(format!("Font {} had no OS2 table", font.filename)), |
37 |
| - // code: StatusCode::Error, |
38 |
| - // }), |
39 |
| - // } |
40 |
| - // } |
41 |
| - // return_result(problems) |
| 7 | +fn bold_italic_unique(c: &FontCollection) -> StatusList { |
| 8 | + let ribbi = c.ribbi_fonts(); |
| 9 | + let mut problems = vec![]; |
| 10 | + let mut flags: HashSet<(bool, bool)> = HashSet::new(); |
| 11 | + for font in ribbi.iter() { |
| 12 | + let _names_list = font.get_name_entry_strings(StringId::FAMILY_NAME); |
| 13 | + match font.get_os2_fsselection() { |
| 14 | + Ok(fsselection) => { |
| 15 | + let val = ( |
| 16 | + fsselection.intersects(SelectionFlags::BOLD), |
| 17 | + fsselection.intersects(SelectionFlags::ITALIC), |
| 18 | + ); |
| 19 | + if flags.contains(&val) { |
| 20 | + problems.push(Status { |
| 21 | + message: Some(format!( |
| 22 | + "Font {} has the same selection flags ({}{}{}) as another font", |
| 23 | + font.filename, |
| 24 | + if val.0 { "bold" } else { "" }, |
| 25 | + if val.0 && val.1 { " & " } else { "" }, |
| 26 | + if val.1 { "italic" } else { "" } |
| 27 | + )), |
| 28 | + code: StatusCode::Error, |
| 29 | + }); |
| 30 | + } else { |
| 31 | + flags.insert(val); |
| 32 | + } |
| 33 | + } |
| 34 | + Err(_e) => problems.push(Status { |
| 35 | + message: Some(format!("Font {} had no OS2 table", font.filename)), |
| 36 | + code: StatusCode::Error, |
| 37 | + }), |
| 38 | + } |
| 39 | + } |
| 40 | + return_result(problems) |
42 | 41 | }
|
43 | 42 | pub const BOLD_ITALIC_UNIQUE_CHECK: Check = Check {
|
44 | 43 | id: "com.adobe.fonts/check/family/bold_italic_unique_for_nameid1",
|
|
0 commit comments