Skip to content

Commit 16bc0b0

Browse files
authored
Merge pull request #9 from felipesanches/a_few_additional_ports_of_checks
new check: 'opentype/code_pages'
2 parents 332ecc3 + a6a5e35 commit 16bc0b0

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use fontspector_checkapi::{prelude::*, testfont, FileTypeConvert};
2+
use read_fonts::TableProvider;
3+
4+
#[check(
5+
id = "opentype/code_pages",
6+
title = "Check code page character ranges",
7+
rationale = "
8+
At least some programs (such as Word and Sublime Text) under Windows 7
9+
do not recognize fonts unless code page bits are properly set on the
10+
ulCodePageRange1 (and/or ulCodePageRange2) fields of the OS/2 table.
11+
12+
More specifically, the fonts are selectable in the font menu, but whichever
13+
Windows API these applications use considers them unsuitable for any
14+
character set, so anything set in these fonts is rendered with Arial as a
15+
fallback font.
16+
17+
This check currently does not identify which code pages should be set.
18+
Auto-detecting coverage is not trivial since the OpenType specification
19+
leaves the interpretation of whether a given code page is \"functional\"
20+
or not open to the font developer to decide.
21+
22+
So here we simply detect as a FAIL when a given font has no code page
23+
declared at all.
24+
",
25+
proposal = "https://github.com/fonttools/fontbakery/issues/2474"
26+
)]
27+
fn code_pages(t: &Testable, _context: &Context) -> CheckFnResult {
28+
let f = testfont!(t);
29+
let os2 = f.font().os2()?;
30+
let cpr1 = os2.ul_code_page_range_1();
31+
let cpr2 = os2.ul_code_page_range_2();
32+
if !cpr1.is_some() || !cpr2.is_some() || ((cpr1 == Some(0)) && (cpr2 == Some(0))) {
33+
Ok(Status::just_one_fail(
34+
"no-code-pages",
35+
"No code pages defined in the OS/2 table ulCodePageRange1 \
36+
and CodePageRange2 fields.",
37+
))
38+
} else {
39+
Ok(Status::just_one_pass())
40+
}
41+
}

profile-universal/src/checks/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod arabic_spacing_symbols;
22
pub mod bold_italic_unique;
3+
pub mod code_pages;
34
pub mod fvar;
45
pub mod glyphnames;
56
pub mod head;

profile-universal/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,17 @@ pub struct Universal;
66

77
impl fontspector_checkapi::Plugin for Universal {
88
fn register(&self, cr: &mut Registry) -> Result<(), String> {
9-
cr.register_check(checks::arabic_spacing_symbols::arabic_spacing_symbols);
9+
10+
// For the OpenType profile:
1011
cr.register_check(checks::bold_italic_unique::bold_italic_unique);
12+
cr.register_check(checks::code_pages::code_pages);
1113
cr.register_check(checks::fvar::axis_ranges_correct);
1214
cr.register_check(checks::fvar::regular_coords_correct);
13-
cr.register_check(checks::glyphnames::valid_glyphnames);
14-
cr.register_check(checks::head::equal_font_versions);
15-
cr.register_check(checks::head::font_version);
16-
cr.register_check(checks::head::mac_style);
17-
cr.register_check(checks::head::unitsperem);
1815
cr.register_check(checks::hhea::caret_slope);
1916
cr.register_check(checks::hhea::maxadvancewidth);
20-
cr.register_check(checks::name_trailing_spaces::name_trailing_spaces);
21-
cr.register_check(checks::name::name_empty_records);
22-
cr.register_check(checks::os2::fsselection);
2317
cr.register_check(checks::post::post_table_version);
2418
cr.register_check(checks::post::underline_thickness);
25-
cr.register_check(checks::required_tables::required_tables);
2619
cr.register_check(checks::stat::stat_axis_record);
27-
cr.register_check(checks::unwanted_tables::unwanted_tables);
2820

2921
let opentype_profile = Profile::from_toml(
3022
r#"
@@ -113,6 +105,14 @@ impl fontspector_checkapi::Plugin for Universal {
113105
.map_err(|_| "Couldn't parse profile")?;
114106
cr.register_profile("opentype", opentype_profile)?;
115107

108+
// For the Universal profile:
109+
cr.register_check(checks::arabic_spacing_symbols::arabic_spacing_symbols);
110+
cr.register_check(checks::glyphnames::valid_glyphnames);
111+
cr.register_check(checks::name::name_empty_records);
112+
cr.register_check(checks::name_trailing_spaces::name_trailing_spaces);
113+
cr.register_check(checks::required_tables::required_tables);
114+
cr.register_check(checks::unwanted_tables::unwanted_tables);
115+
116116
let universal_profile = Profile::from_toml(
117117
r#"
118118
include_profiles = ["opentype"]

0 commit comments

Comments
 (0)