Skip to content

Commit

Permalink
Merge pull request #1182 from googlefonts/fixedp
Browse files Browse the repository at this point in the history
Fix the pitch!
  • Loading branch information
rsheeter authored Dec 9, 2024
2 parents 680dc0d + ccece26 commit d0a338d
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 0 deletions.
1 change: 1 addition & 0 deletions fontbe/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Work<Context, AnyWorkId, Error> for PostWork {
.iter()
.map(|g| postscript_names.get(g).unwrap_or(g).as_str()),
);
post.is_fixed_pitch = static_metadata.misc.is_fixed_pitch.unwrap_or_default() as u32;
post.italic_angle = Fixed::from_f64(static_metadata.italic_angle.into_inner());
post.underline_position = FWord::new(metrics.underline_position.ot_round());
post.underline_thickness = FWord::new(metrics.underline_thickness.ot_round());
Expand Down
7 changes: 7 additions & 0 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ pub struct MiscMetadata {
/// See <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fstype>
pub fs_type: Option<u16>,

/// If set, the value the source file specifically stated. Otherwise compiler can choose.
///
/// See <https://learn.microsoft.com/en-us/typography/opentype/spec/post#header>
pub is_fixed_pitch: Option<bool>,

/// See <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fsselection>
pub selection_flags: SelectionFlags,

Expand Down Expand Up @@ -477,6 +482,7 @@ impl StaticMetadata {
number_values: glyphsapp_number_values.unwrap_or_default(),
misc: MiscMetadata {
fs_type: None, // default is, sigh, inconsistent across source formats
is_fixed_pitch: None,
selection_flags: Default::default(),
vendor_id: DEFAULT_VENDOR_ID_TAG,
// https://github.com/googlefonts/ufo2ft/blob/0d2688cd847d003b41104534d16973f72ef26c40/Lib/ufo2ft/fontInfoData.py#L353-L354
Expand Down Expand Up @@ -2175,6 +2181,7 @@ mod tests {
},
misc: MiscMetadata {
fs_type: None,
is_fixed_pitch: None,
selection_flags: SelectionFlags::default(),
vendor_id: Tag::from_be_bytes(*b"DUCK"),
version_major: 42,
Expand Down
2 changes: 2 additions & 0 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub struct Font {
#[derive(Clone, Debug, PartialEq, Hash, Default)]
pub struct CustomParameters {
pub use_typo_metrics: Option<bool>,
pub is_fixed_pitch: Option<bool>,
pub fs_type: Option<u16>,
pub has_wws_names: Option<bool>,
pub typo_ascender: Option<i64>,
Expand Down Expand Up @@ -589,6 +590,7 @@ impl RawCustomParameters {
}
match name.as_str() {
"Use Typo Metrics" => add_and_report_issues!(use_typo_metrics, Plist::as_bool),
"isFixedPitch" => add_and_report_issues!(is_fixed_pitch, Plist::as_bool),
"Has WWS Names" => add_and_report_issues!(has_wws_names, Plist::as_bool),
"typoAscender" => add_and_report_issues!(typo_ascender, Plist::as_i64),
"typoDescender" => add_and_report_issues!(typo_descender, Plist::as_i64),
Expand Down
21 changes: 21 additions & 0 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
// Default per <https://github.com/googlefonts/glyphsLib/blob/cb8a4a914b0a33431f0a77f474bf57eec2f19bcc/Lib/glyphsLib/builder/custom_params.py#L1117-L1119>
static_metadata.misc.fs_type = font.custom_parameters.fs_type.or(Some(1 << 3));

static_metadata.misc.is_fixed_pitch = font.custom_parameters.is_fixed_pitch;

static_metadata.misc.unicode_range_bits = font
.custom_parameters
.unicode_range_bits
Expand Down Expand Up @@ -1981,4 +1983,23 @@ mod tests {
static_metadata.misc.panose
);
}

fn fixed_pitch_of(glyphs_file: PathBuf) -> Option<bool> {
let (_, context) = build_static_metadata(glyphs_file);
let static_metadata = context.static_metadata.get();
static_metadata.misc.is_fixed_pitch
}

#[test]
fn fixed_pitch_on() {
assert_eq!(
Some(true),
fixed_pitch_of(glyphs3_dir().join("FixedPitch.glyphs"))
);
}

#[test]
fn fixed_pitch_off() {
assert_eq!(None, fixed_pitch_of(glyphs3_dir().join("WghtVar.glyphs")));
}
}
17 changes: 17 additions & 0 deletions resources/testdata/FixedPitch.designspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<designspace format="5.0">
<axes>
<axis tag="wght" name="Weight" minimum="400" maximum="400" default="400"/>
</axes>
<sources>
<source filename="FixedPitch.ufo" name="FP Regular" familyname="FP" stylename="Regular">
<lib copy="1"/>
<groups copy="1"/>
<features copy="1"/>
<info copy="1"/>
<location>
<dimension name="Weight" xvalue="400"/>
</location>
</source>
</sources>
</designspace>
40 changes: 40 additions & 0 deletions resources/testdata/FixedPitch.ufo/fontinfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ascender</key>
<integer>800</integer>
<key>capHeight</key>
<integer>700</integer>
<key>descender</key>
<integer>-200</integer>
<key>familyName</key>
<string>FP</string>
<key>italicAngle</key>
<integer>0</integer>
<key>openTypeOS2Type</key>
<array>
<integer>3</integer>
</array>
<key>postscriptIsFixedPitch</key>
<true/>
<key>postscriptUnderlinePosition</key>
<integer>-100</integer>
<key>postscriptUnderlineThickness</key>
<integer>50</integer>
<key>styleMapFamilyName</key>
<string>FP</string>
<key>styleMapStyleName</key>
<string>regular</string>
<key>styleName</key>
<string>Regular</string>
<key>unitsPerEm</key>
<integer>1000</integer>
<key>versionMajor</key>
<integer>1</integer>
<key>versionMinor</key>
<integer>0</integer>
<key>xHeight</key>
<integer>500</integer>
</dict>
</plist>
8 changes: 8 additions & 0 deletions resources/testdata/FixedPitch.ufo/glyphs/contents.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>meh</key>
<string>meh.glif</string>
</dict>
</plist>
6 changes: 6 additions & 0 deletions resources/testdata/FixedPitch.ufo/glyphs/meh.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="meh" format="2">
<advance width="600"/>
<outline>
</outline>
</glyph>
10 changes: 10 additions & 0 deletions resources/testdata/FixedPitch.ufo/layercontents.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<array>
<string>public.default</string>
<string>glyphs</string>
</array>
</array>
</plist>
64 changes: 64 additions & 0 deletions resources/testdata/FixedPitch.ufo/lib.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.github.googlei18n.ufo2ft.featureWriters</key>
<array>
<dict>
<key>class</key>
<string>CursFeatureWriter</string>
</dict>
<dict>
<key>class</key>
<string>KernFeatureWriter</string>
</dict>
<dict>
<key>class</key>
<string>MarkFeatureWriter</string>
</dict>
<dict>
<key>class</key>
<string>GdefFeatureWriter</string>
</dict>
</array>
<key>com.github.googlei18n.ufo2ft.filters</key>
<array>
<dict>
<key>name</key>
<string>eraseOpenCorners</string>
<key>namespace</key>
<string>glyphsLib.filters</string>
<key>pre</key>
<true/>
</dict>
</array>
<key>com.schriftgestaltung.customParameter.GSFont.disablesAutomaticAlignment</key>
<false/>
<key>com.schriftgestaltung.customParameter.GSFont.useNiceNames</key>
<integer>1</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.customValue</key>
<integer>0</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.customValue1</key>
<integer>0</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.customValue2</key>
<integer>0</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.customValue3</key>
<integer>0</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.iconName</key>
<string></string>
<key>com.schriftgestaltung.customParameter.GSFontMaster.weightValue</key>
<integer>400</integer>
<key>com.schriftgestaltung.customParameter.GSFontMaster.widthValue</key>
<integer>100</integer>
<key>com.schriftgestaltung.fontMasterOrder</key>
<integer>0</integer>
<key>com.schriftgestaltung.weightValue</key>
<integer>400</integer>
<key>com.schriftgestaltung.widthValue</key>
<integer>100</integer>
<key>public.glyphOrder</key>
<array>
<string>meh</string>
</array>
</dict>
</plist>
10 changes: 10 additions & 0 deletions resources/testdata/FixedPitch.ufo/metainfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>creator</key>
<string>com.github.fonttools.ufoLib</string>
<key>formatVersion</key>
<integer>3</integer>
</dict>
</plist>
40 changes: 40 additions & 0 deletions resources/testdata/glyphs3/FixedPitch.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
.appVersion = "3219";
.formatVersion = 3;
axes = (
{
name = Weight;
tag = wght;
}
);

customParameters = (
{
name = isFixedPitch;
value = 1;
}
);

familyName = FP;
fontMaster = (
{
axesValues = (
400
);
id = m01;
name = Regular;
}
);
glyphs = (
{
glyphname = meh;
layers = (
{
layerId = m01;
width = 600;
}
);
}
);
unitsPerEm = 1000;
}
18 changes: 18 additions & 0 deletions ufo2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,8 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
.unwrap_or(1_u16 << 2),
);

static_metadata.misc.is_fixed_pitch = font_info_at_default.postscript_is_fixed_pitch;

static_metadata.misc.unicode_range_bits = font_info_at_default
.open_type_os2_unicode_ranges
.as_ref()
Expand Down Expand Up @@ -2432,4 +2434,20 @@ mod tests {

assert!(super::parse_meta_table_values(&plist::Value::Dictionary(plist)).is_none())
}

fn fixed_pitch_of(name: &str) -> Option<bool> {
let (_, context) = build_static_metadata(name, default_test_flags());
let static_metadata = context.static_metadata.get();
static_metadata.misc.is_fixed_pitch
}

#[test]
fn fixed_pitch_on() {
assert_eq!(Some(true), fixed_pitch_of("FixedPitch.designspace"));
}

#[test]
fn fixed_pitch_off() {
assert_eq!(None, fixed_pitch_of("wght_var.designspace"));
}
}

0 comments on commit d0a338d

Please sign in to comment.