Skip to content

Commit

Permalink
Accept empty condition sets
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Oct 12, 2023
1 parent 9d87c2b commit 85efd4e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/designspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub struct Rule {
/// Name of the rule.
#[serde(rename = "@name")]
pub name: Option<String>,
/// Condition sets. If any condition is true, the rule is applied.
/// Condition sets. If any condition is true or the condition set is empty,
/// the rule is applied.
#[serde(rename = "conditionset")]
pub condition_sets: Vec<ConditionSet>,
/// Subtitutions (in, out).
Expand All @@ -143,7 +144,7 @@ pub struct Substitution {
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ConditionSet {
/// The conditions.
#[serde(rename = "condition")]
#[serde(rename = "condition", default)]
pub conditions: Vec<Condition>,
}

Expand Down Expand Up @@ -541,4 +542,36 @@ mod tests {
);
assert_eq!(ds_initial, ds_after);
}

#[test]
fn accept_always_on_rules() {
// Given
let designspace = DesignSpaceDocument::load("testdata/MutatorSansAlwaysOnRules.designspace").unwrap();

// Then
assert_eq!(
&designspace.rules,
&Rules {
processing: RuleProcessing::Last,
rules: vec![
Rule {
name: Some("fold_I_serifs".into()),
condition_sets: vec![ConditionSet { conditions: vec![] }],
substitutions: vec![Substitution {
name: "I".into(),
with: "I.narrow".into()
}],
},
Rule {
name: Some("fold_S_terminals".into()),
condition_sets: vec![ConditionSet { conditions: vec![] }],
substitutions: vec![Substitution {
name: "S".into(),
with: "S.closed".into()
}],
},
]
}
);
}
}
27 changes: 27 additions & 0 deletions testdata/MutatorSansAlwaysOnRules.designspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='UTF-8'?>
<designspace format="4.1">
<axes>
<axis tag="wdth" name="width" minimum="0" maximum="1000" default="0"/>
<axis tag="wght" name="weight" minimum="0" maximum="1000" default="0"/>
</axes>
<rules processing="last">
<rule name="fold_I_serifs">
<conditionset>
</conditionset>
<sub name="I" with="I.narrow"/>
</rule>
<rule name="fold_S_terminals">
<conditionset>
</conditionset>
<sub name="S" with="S.closed"/>
</rule>
</rules>
<sources>
<source filename="MutatorSansLightCondensed.ufo" familyname="MutatorMathTest" stylename="LightCondensed">
<location>
<dimension name="width" xvalue="0"/>
<dimension name="weight" xvalue="0"/>
</location>
</source>
</sources>
</designspace>

0 comments on commit 85efd4e

Please sign in to comment.