Skip to content

Commit

Permalink
Merge pull request #328 from linebender/accept-always-on-rules
Browse files Browse the repository at this point in the history
Accept empty condition sets
  • Loading branch information
madig authored Oct 12, 2023
2 parents 9d87c2b + 5dbaffb commit 8a69746
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
38 changes: 36 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,37 @@ 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()
}],
},
]
}
);
}
}
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub enum ErrorKind {
BadImage,
/// Has an invalid identifier.
BadIdentifier,
/// Name is not a valid [`Name`](crate::Name).
/// Name is not a valid [`Name`].
InvalidName,
/// Has an invalid lib.
BadLib,
Expand Down
1 change: 1 addition & 0 deletions src/glyph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ impl Contour {
.map(|idx| self.points.len() - 1 - idx);
self.points.iter().cycle().skip(rotate.unwrap_or(0)).take(self.points.len() + 1)
} else {
#[allow(clippy::iter_skip_zero)]
self.points.iter().cycle().skip(0).take(self.points.len())
};
if let Some(start) = points.next() {
Expand Down
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 8a69746

Please sign in to comment.