Skip to content

Commit

Permalink
Update for final version of clap v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Jan 6, 2022
1 parent adae263 commit e3cef6e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 123 deletions.
87 changes: 18 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ fontforge = ["fontforge-sys"]

[profile.release]
opt-level = 'z'
lto = true
#lto = true
codegen-units = 1
22 changes: 11 additions & 11 deletions src/constant_width_stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@ pub fn clap_app() -> clap::App<'static> {
.short('i')
.long("input")
.takes_value(true)
.about("The path to the input file.")
.help("The path to the input file.")
.required(true))
.arg(Arg::new("output")
.display_order(2)
.short('o')
.long("output")
.takes_value(true)
.about("The path where the output will be saved.")
.help("The path where the output will be saved.")
.required(true))
.arg(Arg::new("startcap")
.long("startcap")
.short('s')
.takes_value(true)
.about(r#"Either the constant strings "circle", "round" or "square", or a .glif file."#)
.help(r#"Either the constant strings "circle", "round" or "square", or a .glif file."#)
.default_value("circle"))
.arg(Arg::new("endcap")
.long("endcap")
.short('e')
.takes_value(true)
.about(r#"Either the constant strings "circle", "round" or "square", or a .glif file."#)
.help(r#"Either the constant strings "circle", "round" or "square", or a .glif file."#)
.default_value("circle"))
.arg(Arg::new("jointype")
.long("jointype")
.short('j')
.takes_value(true)
.possible_values(&["round", "circle", "miter", "bevel"])
.about("How to join discontinuous splines")
.help("How to join discontinuous splines")
.default_value("round"))
.arg(Arg::new("width")
.long("width")
.short('w')
.takes_value(true)
.about(r#"<f64> Constant stroke width."#)
.help(r#"<f64> Constant stroke width."#)
.validator(super::arg_validator_positive_f64)
.conflicts_with("left")
.conflicts_with("right")
Expand All @@ -64,31 +64,31 @@ pub fn clap_app() -> clap::App<'static> {
.long("left")
.short('l')
.takes_value(true)
.about(r#"<f64> Constant stroke width (left)."#)
.help(r#"<f64> Constant stroke width (left)."#)
.validator(super::arg_validator_positive_f64)
.requires("right"))
.arg(Arg::new("right")
.long("right")
.short('r')
.takes_value(true)
.about(r#"<f64> Constant stroke width (right)."#)
.help(r#"<f64> Constant stroke width (right)."#)
.validator(super::arg_validator_positive_f64)
.requires("left"))
.arg(Arg::new("remove-internal")
.long("remove-internal")
.short('I')
.takes_value(false)
.about(r#"Remove internal contour"#))
.help(r#"Remove internal contour"#))
.arg(Arg::new("remove-external")
.long("remove-external")
.short('E')
.takes_value(false)
.about(r#"Remove external contour"#))
.help(r#"Remove external contour"#))
.arg(Arg::new("segmentwise")
.long("segmentwise")
.short('S')
.takes_value(false)
.about(r#"Join all segments with caps (stroke all Bézier segments one by one)"#))
.help(r#"Join all segments with caps (stroke all Bézier segments one by one)"#))
}

#[derive(Debug)]
Expand Down
43 changes: 23 additions & 20 deletions src/dash_along_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub fn clap_app() -> clap::App<'static> {
.short('i')
.takes_value(true)
.required(true)
.about("The path to the input glif file."))
.help("The path to the input glif file."))
.arg(Arg::new("output")
.long("output")
.short('o')
.required(true)
.takes_value(true)
.about("The path to the output glif file."))
.help("The path to the output glif file."))
.arg(Arg::new("dash")
.long("dash-description")
.short('d')
Expand All @@ -31,61 +31,64 @@ pub fn clap_app() -> clap::App<'static> {
.validator(super::validators::arg_validator_positive_or_zero_f64)
.validator_all(|vals| (vals.len() % 2 == 0).then(||Ok(())).unwrap_or_else(||Err("dash lengths not divisible by 2!")))
.default_values(&["30", "30"])
.about("Dash description"))
.help("Dash description"))
.arg(Arg::new("cull")
.short('c')
.required(false)
.long("cull")
.about("Attempt to cull earlier dashes when later dashes cover them"))
.required(false)
.takes_value(false)
.help("Attempt to cull earlier dashes when later dashes cover them"))
.arg(Arg::new("width")
.short('w')
.long("width")
.takes_value(true)
.validator(super::validators::arg_validator_positive_or_zero_f64)
.default_value("30")
.about("Stroke width (to leave an open contour, use 0)"))
.help("Stroke width (to leave an open contour, use 0)"))
.arg(Arg::new("cull-width")
.short('W')
.long("cull-width")
.takes_value(true)
.validator(super::validators::arg_validator_positive_or_zero_f64)
.default_value("40")
.required(false)
.requires("cull")
.about("Cull width"))
.help("Cull width"))
.arg(Arg::new("area")
.short('a')
.short_alias('C')
.long("min-area")
.aliases(&["area-cutoff", "cull-cutoff"])
.takes_value(true)
.required(false)
.validator(super::validators::arg_validator_positive_or_zero_f64)
.required(false)
.requires("cull")
.about("Paths with either a height or width below this number are culled. Do not set if unsure."))
.help("Paths with either a height or width below this number are culled. Do not set if unsure."))
.arg(Arg::new("write-last-path")
.short('l')
.long("write-last")
.alias("write-last-path")
.requires("cull")
.about("Write last path\n\n\n"))
.required(false)
.help("Write last path\n\n\n"))
.arg(Arg::new("join-type")
.long("join")
.alias("jointype")
.short('j')
.takes_value(true)
.case_insensitive(true)
.ignore_case(true)
.required(false)
.possible_values(&["round", "miter", "bevel"])
.about("How to join discontinuous splines")
.help("How to join discontinuous splines")
.default_value("round"))
.arg(Arg::new("cap-type")
.long("cap")
.alias("captype")
.short('J')
.short_alias('A')
.takes_value(true)
.case_insensitive(true)
.ignore_case(true)
.required(false)
.possible_values(&["round", "butt", "square"])
.about("How to cap splines")
.help("How to cap splines")
.default_value("round"))
}

Expand All @@ -96,9 +99,8 @@ pub fn dash_cli(matches: &ArgMatches) {
let cull = matches.is_present("cull");
let cull_width = matches
.value_of("cull-width")
.unwrap()
.parse::<f32>()
.unwrap();
.map(|w|w.parse::<f32>().unwrap())
.unwrap_or(stroke_width);
let cull_cutoff = matches
.value_of("area")
.map(|v| v.parse::<f32>().unwrap())
Expand Down Expand Up @@ -152,7 +154,8 @@ pub fn dash_cli(matches: &ArgMatches) {
let mut path: glifparser::Glif<()> =
glifparser::read(&fs::read_to_string(path_string).expect("Failed to read path file!"))
.expect("glifparser couldn't parse input path glif. Invalid glif?");
let out = MFEKmath::dash_along_glif(&path, &dash_settings);
let mut out = MFEKmath::dash_along_glif(&path, &dash_settings);
out.outline.as_mut().unwrap().retain(|c|c.len() > 1);
path = out;
glifparser::write_to_filename(&path, out_string).unwrap();
}
Loading

0 comments on commit e3cef6e

Please sign in to comment.