Skip to content

Commit 12a4163

Browse files
committed
Some name checks
1 parent 0ef8110 commit 12a4163

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

fontspector-checkapi/src/font.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::{
44
CheckError, FileType, Testable,
55
};
66
use read_fonts::{
7-
tables::cmap::Cmap,
8-
tables::gdef::Gdef,
9-
tables::{os2::SelectionFlags, post::DEFAULT_GLYPH_NAMES},
7+
tables::{cmap::Cmap, gdef::Gdef, os2::SelectionFlags, post::DEFAULT_GLYPH_NAMES},
108
types::Version16Dot16,
119
TableProvider,
1210
};
@@ -127,8 +125,10 @@ impl TestFont<'_> {
127125
Ok(os2.fs_selection())
128126
}
129127

130-
pub fn get_name_entry_strings(&self, name_id: StringId) -> LocalizedStrings {
131-
self.font().localized_strings(name_id)
128+
pub fn get_name_entry_strings(&self, name_id: StringId) -> impl Iterator<Item = String> + '_ {
129+
self.font()
130+
.localized_strings(name_id)
131+
.map(|s| s.to_string())
132132
}
133133

134134
pub fn glyph_name_for_id(&self, gid: GlyphId, synthesize: bool) -> Option<String> {

profile-universal/src/checks/bold_italic_unique.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fn bold_italic_unique(c: &TestableCollection, _context: &Context) -> CheckFnResu
2323
let mut flags: HashSet<(bool, bool)> = HashSet::new();
2424
let ribbi = fonts.iter().filter(|f| f.is_ribbi());
2525
for font in ribbi {
26-
let _names_list = font.get_name_entry_strings(StringId::FAMILY_NAME);
2726
let fsselection = font.get_os2_fsselection()?;
2827
let val = (
2928
fsselection.intersects(SelectionFlags::BOLD),

profile-universal/src/checks/name.rs

+69
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use font_types::NameId;
12
use fontspector_checkapi::{prelude::*, testfont, FileTypeConvert};
23
use read_fonts::TableProvider;
4+
use skrifa::MetadataProvider;
35

46
#[check(
57
id = "opentype/name/empty_records",
@@ -31,3 +33,70 @@ fn name_empty_records(t: &Testable, _context: &Context) -> CheckFnResult {
3133
}
3234
return_result(problems)
3335
}
36+
37+
#[check(
38+
id = "opentype/name/no_copyright_on_description",
39+
rationale = "
40+
The name table in a font file contains strings about the font;
41+
there are entries for a copyright field and a description. If the
42+
copyright entry is being used correctly, then there should not
43+
be any copyright information in the description entry.
44+
",
45+
proposal = "https://github.com/fonttools/fontbakery/issues/4829",
46+
title = "Description strings in the name table must not contain copyright info"
47+
)]
48+
fn check_name_no_copyright_on_description(t: &Testable, _context: &Context) -> CheckFnResult {
49+
let f = testfont!(t);
50+
let mut problems: Vec<Status> = vec![];
51+
for record in f.get_name_entry_strings(NameId::DESCRIPTION) {
52+
if record.contains("opyright") {
53+
problems.push(Status::fail(
54+
"copyright-on-description",
55+
&format!(
56+
"Some namerecords with ID={} (NameID.DESCRIPTION) containing copyright info
57+
should be removed (perhaps these were added by a longstanding FontLab Studio
58+
5.x bug that copied copyright notices to them.)",
59+
NameId::DESCRIPTION.to_u16()
60+
),
61+
))
62+
}
63+
}
64+
return_result(problems)
65+
}
66+
67+
#[check(
68+
id = "opentype/name/match_familyname_fullfont",
69+
rationale = r#"
70+
The FULL_FONT_NAME entry in the ‘name’ table should start with the same string
71+
as the Family Name (FONT_FAMILY_NAME, TYPOGRAPHIC_FAMILY_NAME or
72+
WWS_FAMILY_NAME).
73+
74+
If the Family Name is not included as the first part of the Full Font Name, and
75+
the user embeds the font in a document using a Microsoft Office app, the app
76+
will fail to render the font when it opens the document again.
77+
78+
NOTE: Up until version 1.5, the OpenType spec included the following exception
79+
in the definition of Full Font Name:
80+
81+
"An exception to the [above] definition of Full font name is for Microsoft
82+
platform strings for CFF OpenType fonts: in this case, the Full font name
83+
string must be identical to the PostScript FontName in the CFF Name INDEX."
84+
85+
https://docs.microsoft.com/en-us/typography/opentype/otspec150/name#name-ids
86+
"#,
87+
proposal = "https://github.com/fonttools/fontbakery/issues/4829",
88+
title = "Does full font name begin with the font family name?"
89+
)]
90+
fn check_name_match_familyname_fullfont(t: &Testable, _context: &Context) -> CheckFnResult {
91+
let font = testfont!(t);
92+
// We actually care about localization here, so don't just want
93+
// a vec of String.
94+
let full_names = font.font().localized_strings(NameId::FULL_NAME);
95+
let family_names = font.font().localized_strings(NameId::FAMILY_NAME);
96+
let typographic_names = font
97+
.font()
98+
.localized_strings(NameId::TYPOGRAPHIC_FAMILY_NAME);
99+
let wws_names = font.font().localized_strings(NameId::WWS_FAMILY_NAME);
100+
if full_names.len() {}
101+
return_result(vec![])
102+
}

0 commit comments

Comments
 (0)