Skip to content

Commit 3ba53ab

Browse files
committed
italics_have_roman_counterparts
1 parent 7bda88d commit 3ba53ab

File tree

4 files changed

+95
-20
lines changed

4 files changed

+95
-20
lines changed

fontspector-py/tests/test_checks_googlefonts.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -2396,53 +2396,52 @@ def test_check_fvar_instances__whats_going_on_here(check): # TODO: REVIEW THIS.
23962396
assert_PASS(check(ttFont), "with a good font...")
23972397

23982398

2399-
@pytest.mark.skip("Check not ported yet.")
24002399
@check_id("googlefonts/family/italics_have_roman_counterparts")
24012400
def test_check_family_italics_have_roman_counterparts(check):
24022401
"""Ensure Italic styles have Roman counterparts."""
24032402

2404-
# The path used here, "some-crazy.path/", is meant to ensure
2405-
# that the parsing code does not get lost when trying to
2406-
# extract the style of a font file.
24072403
fonts = [
2408-
"some-crazy.path/merriweather/Merriweather-BlackItalic.ttf",
2409-
"some-crazy.path/merriweather/Merriweather-Black.ttf",
2410-
"some-crazy.path/merriweather/Merriweather-BoldItalic.ttf",
2411-
"some-crazy.path/merriweather/Merriweather-Bold.ttf",
2412-
"some-crazy.path/merriweather/Merriweather-Italic.ttf",
2413-
"some-crazy.path/merriweather/Merriweather-LightItalic.ttf",
2414-
"some-crazy.path/merriweather/Merriweather-Light.ttf",
2415-
"some-crazy.path/merriweather/Merriweather-Regular.ttf",
2404+
TEST_FILE("merriweather/Merriweather-BlackItalic.ttf"),
2405+
TEST_FILE("merriweather/Merriweather-Black.ttf"),
2406+
TEST_FILE("merriweather/Merriweather-BoldItalic.ttf"),
2407+
TEST_FILE("merriweather/Merriweather-Bold.ttf"),
2408+
TEST_FILE("merriweather/Merriweather-Italic.ttf"),
2409+
TEST_FILE("merriweather/Merriweather-LightItalic.ttf"),
2410+
TEST_FILE("merriweather/Merriweather-Light.ttf"),
2411+
TEST_FILE("merriweather/Merriweather-Regular.ttf"),
24162412
]
24172413

2418-
assert_PASS(check([MockFont(file=font) for font in fonts]), "with a good family...")
2414+
assert_PASS(check(fonts), "with a good family...")
24192415

24202416
fonts.pop(-1) # remove the last one, which is the Regular
2421-
assert "some-crazy.path/merriweather/Merriweather-Regular.ttf" not in fonts
2422-
assert "some-crazy.path/merriweather/Merriweather-Italic.ttf" in fonts
24232417
assert_results_contain(
24242418
check(fonts),
24252419
FAIL,
24262420
"missing-roman",
24272421
"with a family that has an Italic but lacks a Regular.",
24282422
)
24292423

2430-
fonts.append("some-crazy.path/merriweather/MerriweatherItalic.ttf")
2424+
shutil.copy(
2425+
TEST_FILE("merriweather/Merriweather-Italic.ttf"),
2426+
TEST_FILE("merriweather/MerriweatherItalic.ttf"),
2427+
)
2428+
fonts.append(TEST_FILE("merriweather/MerriweatherItalic.ttf"))
24312429
assert_results_contain(
24322430
check(fonts),
24332431
WARN,
24342432
"bad-filename",
24352433
"with a family that has a non-canonical italic filename.",
24362434
)
2435+
os.unlink(TEST_FILE("merriweather/MerriweatherItalic.ttf"))
24372436

24382437
# This check must also be able to deal with variable fonts!
24392438
fonts = [
2440-
"cabinvfbeta/CabinVFBeta-Italic[wdth,wght].ttf",
2441-
"cabinvfbeta/CabinVFBeta[wdth,wght].ttf",
2439+
TEST_FILE("cabinvf/Cabin-Italic[wdth,wght].ttf"),
2440+
TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"),
24422441
]
24432442
assert_PASS(check(fonts), "with a good set of varfonts...")
24442443

2445-
fonts = ["cabinvfbeta/CabinVFBeta-Italic[wdth,wght].ttf"]
2444+
fonts = [TEST_FILE("cabinvf/Cabin-Italic[wdth,wght].ttf")]
24462445
assert_results_contain(
24472446
check(fonts),
24482447
FAIL,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use fontspector_checkapi::prelude::*;
2+
3+
#[check(
4+
id = "googlefonts/family/italics_have_roman_counterparts",
5+
rationale = "
6+
7+
For each font family on Google Fonts, every Italic style must have
8+
a Roman sibling.
9+
10+
This kind of problem was first observed at [1] where the Bold style was
11+
missing but BoldItalic was included.
12+
13+
[1] https://github.com/google/fonts/pull/1482
14+
15+
",
16+
proposal = "https://github.com/fonttools/fontbakery/issues/1733",
17+
title = "Ensure Italic styles have Roman counterparts.",
18+
implementation = "all"
19+
)]
20+
fn italics_have_roman_counterparts(c: &TestableCollection, context: &Context) -> CheckFnResult {
21+
let filenames: Vec<String> = c
22+
.testables
23+
.iter()
24+
.map(|t| t.filename.to_string_lossy().to_string())
25+
.filter(|x| x.ends_with(".ttf"))
26+
.collect();
27+
let italics: Vec<&String> = filenames
28+
.iter()
29+
.filter(|x| x.contains("Italic") && x.find("-") < x.find("Italic"))
30+
.collect();
31+
let mut missing_roman = vec![];
32+
let mut problems = vec![];
33+
for italic in italics {
34+
if !italic.contains("-") {
35+
problems.push(Status::warn(
36+
"bad-filename",
37+
&format!("Filename seems to be incorrect: '{}'", italic),
38+
));
39+
continue;
40+
}
41+
#[allow(clippy::unwrap_used)] // We just tested for one
42+
let after_hyphen = italic.split("-").last().unwrap();
43+
let Some(style_from_filename) = after_hyphen.split(".").next() else {
44+
problems.push(Status::warn(
45+
"bad-filename",
46+
&format!("Filename seems to be incorrect: '{}'", italic),
47+
));
48+
continue;
49+
};
50+
let is_varfont = style_from_filename.contains("[");
51+
let roman_counterpart = if style_from_filename == "Italic" {
52+
if is_varfont {
53+
italic.replace("-Italic", "")
54+
} else {
55+
italic.replace("Italic", "Regular")
56+
}
57+
} else {
58+
italic.replace("-Italic", "")
59+
};
60+
if !filenames.contains(&roman_counterpart) {
61+
missing_roman.push(italic);
62+
}
63+
}
64+
if !missing_roman.is_empty() {
65+
problems.push(Status::fail(
66+
"missing-roman",
67+
&format!(
68+
"Italics missing a Roman counterpart:\n{}",
69+
bullet_list(context, missing_roman)
70+
),
71+
));
72+
}
73+
return_result(problems)
74+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ mod equal_codepoint_coverage;
22
pub use equal_codepoint_coverage::equal_codepoint_coverage;
33
mod has_license;
44
pub use has_license::has_license;
5+
mod italics_have_roman_counterparts;
6+
pub use italics_have_roman_counterparts::italics_have_roman_counterparts;

profile-googlefonts/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl fontspector_checkapi::Plugin for GoogleFonts {
102102
.add_and_register_check(checks::googlefonts::description::valid_html)
103103
.add_section("Family Checks")
104104
.add_and_register_check(checks::googlefonts::family::equal_codepoint_coverage)
105-
// .add_and_register_check(checks::googlefonts::family::italics_have_roman_counterparts)
105+
.add_and_register_check(checks::googlefonts::family::italics_have_roman_counterparts)
106106
// .add_and_register_check(checks::googlefonts::family::tnum_horizontal_metrics)
107107
.add_section("Name table checks")
108108
.add_and_register_check(checks::googlefonts::name::family_name_compliance)

0 commit comments

Comments
 (0)