-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MetaInfo: creator is optional now #190
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, and set the creator on saving? I'd prefer to keep the explicit norad reference, since norad is the only user of it currently. |
||
format_version: FormatVersion::V3, | ||
format_version_minor: 0, | ||
} | ||
|
@@ -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)?; | ||
|
@@ -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] | ||
|
@@ -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), | ||
|
@@ -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), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right, but in line with the other changes you've been making we could also just treat the empty string as none. (I prefer this way, though, it's more explicit and more "correct".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, an empty string would still land in the serialized stream unless I stop serde; and the spec doesn't say that the field must be non-empty 🤔