Skip to content

Commit

Permalink
Merge pull request #190 from linebender/optional-creator
Browse files Browse the repository at this point in the history
MetaInfo: creator is optional now
  • Loading branch information
madig authored Oct 20, 2021
2 parents 6593259 + 07dcb01 commit c60251c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() {
|| k == "com.schriftgestaltung.customParameter.GSFontMaster.paramOver"
});

ufo.meta.creator = "org.linebender.norad".to_string();
ufo.meta.creator = Some("org.linebender.norad".to_string());
if let Err(e) = ufo.save(arg) {
eprintln!("Saving UFO failed: {}", e);
std::process::exit(1);
Expand Down
10 changes: 6 additions & 4 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum FormatVersion {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MetaInfo {
pub creator: String,
pub creator: Option<String>,
pub format_version: FormatVersion,
#[serde(default, skip_serializing_if = "is_zero")]
pub format_version_minor: u32,
Expand All @@ -77,7 +77,7 @@ fn is_zero(v: &u32) -> bool {
impl Default for MetaInfo {
fn default() -> Self {
MetaInfo {
creator: DEFAULT_METAINFO_CREATOR.to_string(),
creator: Some(DEFAULT_METAINFO_CREATOR.to_string()),
format_version: FormatVersion::V3,
format_version_minor: 0,
}
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Font {

// we want to always set ourselves as the creator when serializing,
// but we also don't have mutable access to self.
if self.meta.creator == DEFAULT_METAINFO_CREATOR {
if self.meta.creator == Some(DEFAULT_METAINFO_CREATOR.into()) {
write::write_xml_to_file(&path.join(METAINFO_FILE), &self.meta, options)?;
} else {
write::write_xml_to_file(&path.join(METAINFO_FILE), &MetaInfo::default(), options)?;
Expand Down Expand Up @@ -630,7 +630,7 @@ mod tests {
fn metainfo() {
let path = "testdata/MutatorSansLightWide.ufo/metainfo.plist";
let meta: MetaInfo = plist::from_file(path).expect("failed to load metainfo");
assert_eq!(meta.creator, "org.robofab.ufoLib");
assert_eq!(meta.creator, Some("org.robofab.ufoLib".into()));
}

#[test]
Expand All @@ -643,6 +643,7 @@ mod tests {
&[
Token::Struct { name: "MetaInfo", len: 2 },
Token::Str("creator"),
Token::Some,
Token::Str(DEFAULT_METAINFO_CREATOR),
Token::Str("formatVersion"),
Token::U8(3),
Expand All @@ -656,6 +657,7 @@ mod tests {
&[
Token::Struct { name: "MetaInfo", len: 3 },
Token::Str("creator"),
Token::Some,
Token::Str(DEFAULT_METAINFO_CREATOR),
Token::Str("formatVersion"),
Token::U8(3),
Expand Down
2 changes: 1 addition & 1 deletion tests/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn save_default() {

let loaded = Font::load(dir).unwrap();
assert!(loaded.meta.format_version == FormatVersion::V3);
assert!(loaded.meta.creator == "org.linebender.norad");
assert!(loaded.meta.creator == Some("org.linebender.norad".into()));
assert_eq!(loaded.layers.len(), 1);
}

Expand Down

0 comments on commit c60251c

Please sign in to comment.