Skip to content

Commit

Permalink
Implement basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Jun 14, 2020
1 parent 4a0327e commit ee3042f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
56 changes: 56 additions & 0 deletions src/ufo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ fn validate_groups(groups_map: &Groups) -> Result<(), GroupsValidationError> {
#[cfg(test)]
mod tests {
use super::*;
use crate::shared_types::IntegerOrFloat;

#[test]
fn new_is_v3() {
Expand Down Expand Up @@ -467,6 +468,61 @@ mod tests {
assert_eq!(font_obj.features.unwrap(), "# this is the feature from lightWide\n");
}

#[test]
fn upconvert_ufov1_robofab_data() {
let path = "testdata/fontinfotest_v1.ufo";
let font = Ufo::load(path).unwrap();

assert_eq!(font.meta.format_version, FormatVersion::V3);

let font_info = font.font_info.unwrap();
assert_eq!(font_info.postscript_blue_fuzz, Some(IntegerOrFloat::from(1)));
assert_eq!(font_info.postscript_blue_scale, Some(0.039625));
assert_eq!(font_info.postscript_blue_shift, Some(IntegerOrFloat::from(7)));
assert_eq!(
font_info.postscript_blue_values,
Some(vec![
IntegerOrFloat::from(-10),
IntegerOrFloat::from(0),
IntegerOrFloat::from(482),
IntegerOrFloat::from(492),
IntegerOrFloat::from(694),
IntegerOrFloat::from(704),
IntegerOrFloat::from(739),
IntegerOrFloat::from(749)
])
);
assert_eq!(
font_info.postscript_other_blues,
Some(vec![IntegerOrFloat::from(-260), IntegerOrFloat::from(-250)])
);
assert_eq!(
font_info.postscript_family_blues,
Some(vec![IntegerOrFloat::from(500.0), IntegerOrFloat::from(510.0)])
);
assert_eq!(
font_info.postscript_family_other_blues,
Some(vec![IntegerOrFloat::from(-260), IntegerOrFloat::from(-250)])
);
assert_eq!(font_info.postscript_force_bold, Some(true));
assert_eq!(
font_info.postscript_stem_snap_h,
Some(vec![IntegerOrFloat::from(100), IntegerOrFloat::from(120)])
);
assert_eq!(
font_info.postscript_stem_snap_v,
Some(vec![IntegerOrFloat::from(80), IntegerOrFloat::from(90)])
);

let lib_data = font.lib.unwrap();
assert_eq!(lib_data.keys().collect::<Vec<&String>>(), vec!["org.robofab.testFontLibData"]);

assert_eq!(
font.features.unwrap(),
"@myClass = [A B];\nfeature liga {\n sub A A by b;\n} liga;\n"
);
}

#[test]
fn metainfo() {
let path = "testdata/mutatorSans/MutatorSansLightWide.ufo/metainfo.plist";
Expand Down
8 changes: 4 additions & 4 deletions src/upconversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ pub(crate) fn upconvert_ufov1_robofab_data(
family_other_blues: Option<Vec<Vec<IntegerOrFloat>>>,
force_bold: Option<bool>,
other_blues: Option<Vec<Vec<IntegerOrFloat>>>,
stem_snap_h: Option<Vec<IntegerOrFloat>>,
stem_snap_v: Option<Vec<IntegerOrFloat>>,
h_stems: Option<Vec<IntegerOrFloat>>,
v_stems: Option<Vec<IntegerOrFloat>>,
}

// Reead lib.plist again because it is easier than pulling out the data manually.
Expand Down Expand Up @@ -185,8 +185,8 @@ pub(crate) fn upconvert_ufov1_robofab_data(
Some(family_other_blues.into_iter().flatten().collect());
};
fontinfo.postscript_force_bold = ps_hinting_data.force_bold;
fontinfo.postscript_stem_snap_h = ps_hinting_data.stem_snap_h;
fontinfo.postscript_stem_snap_v = ps_hinting_data.stem_snap_v;
fontinfo.postscript_stem_snap_h = ps_hinting_data.h_stems;
fontinfo.postscript_stem_snap_v = ps_hinting_data.v_stems;

fontinfo.validate()?;
}
Expand Down

0 comments on commit ee3042f

Please # to comment.