Skip to content

Commit 160b57e

Browse files
committed
family_directory_name
1 parent d150c59 commit 160b57e

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

fontspector-py/tests/test_checks_googlefonts.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -3406,20 +3406,17 @@ def test_check_meta_script_lang_tags(check):
34063406
assert_results_contain(check(ttFont), WARN, "lacks-meta-table")
34073407

34083408

3409-
@pytest.mark.skip("Check not ported yet.")
34103409
@check_id("googlefonts/metadata/family_directory_name")
3411-
def test_check_metadata_family_directory_name(check):
3410+
def test_check_metadata_family_directory_name(check, tmp_path):
34123411
"""Check family directory name."""
34133412

3414-
font = TEST_FILE("overpassmono/OverpassMono-Regular.ttf")
3415-
assert_PASS(check(font))
3416-
old_md = Font(font).family_metadata
3413+
mdpb = TEST_FILE("overpassmono/METADATA.pb")
3414+
assert_PASS(check(mdpb))
34173415

3418-
# Note:
3419-
# Here I explicitly pass 'family_metadata' to avoid it being recomputed
3420-
# after I make the family_directory wrong:
3416+
# Copy it to a temp directory where it won't have the correct parent name
3417+
shutil.copy(mdpb, tmp_path / "METADATA.pb")
34213418
assert_results_contain(
3422-
check(MockFont(file=font, family_metadata=old_md, family_directory="overpass")),
3419+
check(str(tmp_path / "METADATA.pb")),
34233420
FAIL,
34243421
"bad-directory-name",
34253422
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use fontspector_checkapi::{prelude::*, skip};
2+
3+
use crate::checks::googlefonts::metadata::family_proto;
4+
#[check(
5+
id = "googlefonts/metadata/family_directory_name",
6+
rationale = "
7+
We want the directory name of a font family to be predictable and directly
8+
derived from the family name, all lowercased and removing spaces.
9+
",
10+
applies_to = "MDPB",
11+
proposal = "https://github.com/fonttools/fontbakery/issues/3421",
12+
title = "Check font family directory name."
13+
)]
14+
fn family_directory_name(c: &Testable, _context: &Context) -> CheckFnResult {
15+
// Assume we actually have directories, we might not in a WASM context
16+
let Some(directory) = c.filename.parent() else {
17+
skip!("no-directory", "No directory information")
18+
};
19+
let msg = family_proto(c)?;
20+
let last_component = directory
21+
.file_name()
22+
.ok_or(CheckError::Error("No directory name".to_string()))?
23+
.to_string_lossy();
24+
let expected = msg.name().replace(" ", "").to_lowercase();
25+
if expected != last_component {
26+
Ok(Status::just_one_fail(
27+
"bad-directory-name",
28+
&format!(
29+
"Family name on METADATA.pb is \"{}\"\n\
30+
Directory name is \"{}\"\n\
31+
Expected \"{}\"",
32+
msg.name(),
33+
last_component,
34+
expected
35+
),
36+
))
37+
} else {
38+
Ok(Status::just_one_pass())
39+
}
40+
}

profile-googlefonts/src/checks/googlefonts/metadata/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ mod designer_profiles;
5858
pub use designer_profiles::designer_profiles;
5959
mod includes_production_subsets;
6060
pub use includes_production_subsets::includes_production_subsets;
61+
mod family_directory_name;
62+
pub use family_directory_name::family_directory_name;

profile-googlefonts/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl fontspector_checkapi::Plugin for GoogleFonts {
6464

6565
let builder = builder
6666
.add_and_register_check(checks::googlefonts::metadata::escaped_strings)
67-
// .add_and_register_check(checks::googlefonts::metadata::family_directory_name)
67+
.add_and_register_check(checks::googlefonts::metadata::family_directory_name)
6868
.add_and_register_check(checks::googlefonts::metadata::familyname)
6969
.add_and_register_check(checks::googlefonts::metadata::has_regular)
7070
// checks::googlefonts::metadata::match_filename_postscript // Merged into metadata/validate

0 commit comments

Comments
 (0)