Skip to content
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

Make rules processing attribute optional #321

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "norad"
version = "0.12.0"
version = "0.12.1"
authors = ["Colin Rofls <[email protected]>", "Nikolaus Waxweiler <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down
9 changes: 6 additions & 3 deletions src/designspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ pub struct Axis {
#[serde(rename = "@default")]
pub default: f32,
/// Records whether this axis needs to be hidden in interfaces.
#[serde(default)]
#[serde(rename = "@hidden")]
#[serde(default, rename = "@hidden", skip_serializing_if = "is_false")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just do,

Suggested change
#[serde(default, rename = "@hidden", skip_serializing_if = "is_false")]
#[serde(default, rename = "@hidden", skip_serializing_if = "std::convert::identity")]

🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: I tried, it doesn't work :(

pub hidden: bool,
/// The minimum value for a continuous axis, in user space coordinates.
#[serde(rename = "@minimum", skip_serializing_if = "Option::is_none")]
Expand All @@ -70,6 +69,10 @@ pub struct Axis {
pub map: Option<Vec<AxisMapping>>,
}

fn is_false(value: &bool) -> bool {
!(*value)
}

/// Maps one input value (user space coord) to one output value (design space coord).
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename = "map")]
Expand All @@ -89,7 +92,7 @@ pub struct AxisMapping {
pub struct Rules {
/// Indicates whether substitution rules should be applied before or after
/// other glyph substitution features.
#[serde(rename = "@processing")]
#[serde(default, rename = "@processing")]
pub processing: RuleProcessing,
/// The rules.
#[serde(default, rename = "rule")]
Expand Down
8 changes: 8 additions & 0 deletions testdata/wght.designspace
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
<axes>
<axis tag="wght" name="Weight" minimum="400" maximum="700" default="400"/>
</axes>
<rules>
<rule>
<conditionset>
<condition name="Weight"/>
</conditionset>
<sub name="I" with="I.narrow"/>
</rule>
</rules>
<sources>
<source filename="TestFamily-Regular.ufo" name="Test Family Regular" familyname="Test Family" stylename="Regular">
<lib copy="1"/>
Expand Down