|
| 1 | +use font_types::NameId; |
1 | 2 | use fontspector_checkapi::{prelude::*, testfont, FileTypeConvert};
|
2 | 3 | use read_fonts::TableProvider;
|
| 4 | +use skrifa::MetadataProvider; |
3 | 5 |
|
4 | 6 | #[check(
|
5 | 7 | id = "opentype/name/empty_records",
|
@@ -31,3 +33,70 @@ fn name_empty_records(t: &Testable, _context: &Context) -> CheckFnResult {
|
31 | 33 | }
|
32 | 34 | return_result(problems)
|
33 | 35 | }
|
| 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