Skip to content

Commit b2a6b0b

Browse files
committed
Clean up warnings
1 parent 89e2a0e commit b2a6b0b

File tree

9 files changed

+57
-58
lines changed

9 files changed

+57
-58
lines changed
File renamed without changes.

fontspector-checkapi/src/font.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// use crate::constants::RIBBI_STYLE_NAMES;
1+
use crate::constants::RIBBI_STYLE_NAMES;
22
use read_fonts::{tables::os2::SelectionFlags, TableProvider};
33
use skrifa::{
44
font::FontRef,
55
string::{LocalizedStrings, StringId},
6-
Tag,
7-
MetadataProvider,
6+
MetadataProvider, Tag,
87
};
98
use std::error::Error;
109

@@ -32,7 +31,7 @@ impl TestFont {
3231
Some("Regular")
3332
}
3433

35-
pub(crate) fn get_os2_fsselection(&self) -> Result<SelectionFlags, Box<dyn Error>> {
34+
pub fn get_os2_fsselection(&self) -> Result<SelectionFlags, Box<dyn Error>> {
3635
let os2 = self.font().os2()?;
3736
Ok(os2.fs_selection())
3837
}
@@ -49,15 +48,15 @@ impl TestFont {
4948
pub struct FontCollection<'a>(pub Vec<&'a TestFont>);
5049

5150
impl FontCollection<'_> {
52-
// pub fn ribbi_fonts(&self) -> FontCollection {
53-
// let filtered: Vec<&TestFont> = self
54-
// .0
55-
// .iter()
56-
// .copied()
57-
// .filter(|x| RIBBI_STYLE_NAMES.contains(&x.style().unwrap_or("None")))
58-
// .collect();
59-
// FontCollection(filtered)
60-
// }
51+
pub fn ribbi_fonts(&self) -> FontCollection {
52+
let filtered: Vec<&TestFont> = self
53+
.0
54+
.iter()
55+
.copied()
56+
.filter(|x| RIBBI_STYLE_NAMES.contains(&x.style().unwrap_or("None")))
57+
.collect();
58+
FontCollection(filtered)
59+
}
6160
pub fn iter(&self) -> std::slice::Iter<'_, &TestFont> {
6261
self.0.iter()
6362
}

fontspector-checkapi/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod check;
2+
mod constants;
23
mod font;
34
mod profile;
45
mod registry;

fontspector-checkapi/src/profile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::{CheckId, Registry, StatusCode};
4-
use std::{collections::HashMap, error::Error};
4+
use std::collections::HashMap;
55

66
#[derive(Serialize, Deserialize)]
77
pub struct Override {

fontspector-checkapi/src/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use crate::{Check, Plugin, Profile};
3+
use crate::{Check, Profile};
44

55
#[derive(Default)]
66
pub struct Registry<'a> {

fontspector-cli/src/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use fontspector_checkapi::{
88
use itertools::iproduct;
99
// use rayon::prelude::*;
1010

11-
mod constants;
1211
use fontspector_universal::Universal;
1312

1413
/// Quality control for OpenType fonts
@@ -72,8 +71,7 @@ fn main() {
7271
.collect();
7372
let thing: Vec<&TestFont> = testables.iter().collect();
7473
let collection = FontCollection(thing);
75-
let checkmap: HashMap<&str, &Check<'_>> =
76-
registry.checks.iter().map(|c| (c.id.clone(), c)).collect();
74+
let checkmap: HashMap<&str, &Check<'_>> = registry.checks.iter().map(|c| (c.id, c)).collect();
7775

7876
for (sectionname, checknames) in profile.sections.iter() {
7977
println!("Checking section {:}", sectionname);

fontspector-testplugin/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use fontspector_checkapi::{return_result, Check, Profile, Registry, StatusList,
22

33
struct Test;
44

5-
fn say_hello(c: &TestFont) -> StatusList {
5+
fn say_hello(_c: &TestFont) -> StatusList {
66
println!("Hello from the test plugin!");
77
return_result(vec![])
88
}

fontspector-universal/src/checks/bold_italic_unique.rs

+37-38
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
// use std::collections::HashSet;
1+
use std::collections::HashSet;
22

33
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;
66

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)
4241
}
4342
pub const BOLD_ITALIC_UNIQUE_CHECK: Check = Check {
4443
id: "com.adobe.fonts/check/family/bold_italic_unique_for_nameid1",

fontspector-universal/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl fontspector_checkapi::Plugin for Universal {
88
cr.checks.push(checks::BOLD_ITALIC_UNIQUE_CHECK);
99
cr.checks.push(checks::NAME_TRAILING_SPACES_CHECK);
1010
cr.checks.push(checks::UNWANTED_TABLES_CHECK);
11+
cr.checks.push(checks::REQUIRED_TABLES_CHECK);
1112
cr.register_profile(
1213
"universal",
1314
Profile::from_toml(
@@ -18,7 +19,8 @@ impl fontspector_checkapi::Plugin for Universal {
1819
]
1920
"Universal Profile Checks" = [
2021
"com.google.fonts/check/name/trailing_spaces",
21-
"com.google.fonts/check/unwanted_tables"
22+
"com.google.fonts/check/unwanted_tables",
23+
"com.google.fonts/check/required_tables",
2224
]
2325
"#,
2426
)

0 commit comments

Comments
 (0)