Skip to content

Commit 3d09cdb

Browse files
committed
[NIB] Add configurable accuracy
1 parent 1497469 commit 3d09cdb

5 files changed

Lines changed: 32 additions & 18 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ FLAGS:
151151
-V, --version Prints version information
152152
153153
OPTIONS:
154-
-n, --nib <nib> The path to the nib file. FontForge is quite strict about these. The .glif must contain a
155-
single closed spline, running clockwise, which represents a convex shape.
156-
-i, --input <input> The path to the input path file.
157-
-o, --output <output> The path where the output .glif will be saved.
154+
-n, --nib <nib> The path to the nib file. FontForge is quite strict about these. The .glif must contain
155+
a single closed spline, running clockwise, which represents a convex shape.
156+
-i, --input <input> The path to the input path file.
157+
-o, --output <output> The path where the output .glif will be saved.
158+
-a, --accuracy <accuracy> <f64> Accuracy target [default: 0.25]
158159
```
159160

160161
## License

src/constant_width_stroke.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ use glifparser::{Glif, Outline};
1111
use clap::{App, Arg};
1212

1313
pub fn clap_app() -> clap::App<'static, 'static> {
14-
fn arg_validator_width(v: String) -> Result<(), String> {
15-
match v.parse::<f64>() {
16-
Ok(i) => {
17-
if i <= 0.0 + f64::EPSILON {
18-
Err(String::from("Value too small"))
19-
} else {
20-
Ok(())
21-
}
22-
}
23-
Err(_) => Err(String::from("Value must be a float")),
24-
}
25-
}
26-
2714
App::new("CWS")
2815
.alias("constant")
2916
.alias("cws")
@@ -67,7 +54,7 @@ pub fn clap_app() -> clap::App<'static, 'static> {
6754
.short("w")
6855
.takes_value(true)
6956
.help(r#"<f64> Constant stroke width."#)
70-
.validator(arg_validator_width)
57+
.validator(super::arg_validator_positive_f64)
7158
.required(true))
7259
}
7360

src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ mod nib_stroke;
99
mod pattern_along_path;
1010
mod variable_width_stroke;
1111

12+
pub fn arg_validator_positive_f64(v: String) -> Result<(), String> {
13+
match v.parse::<f64>() {
14+
Ok(i) => {
15+
if i <= 0.0 + f64::EPSILON {
16+
Err(String::from("Value too small"))
17+
} else {
18+
Ok(())
19+
}
20+
}
21+
Err(_) => Err(String::from("Value must be a float")),
22+
}
23+
}
24+
1225
fn main() {
1326
#[allow(unused_mut)] // we actually use it if cfg(feature=fontforge)
1427
let mut argparser = App::new("MFEKstroke")

src/nib_stroke.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,27 @@ pub fn clap_app() -> clap::App<'static, 'static> {
3131
.takes_value(true)
3232
.help("The path where the output .glif will be saved.")
3333
.required(true))
34+
.arg(Arg::with_name("accuracy")
35+
.display_order(4)
36+
.short("a")
37+
.long("accuracy")
38+
.takes_value(true)
39+
.default_value("0.25")
40+
.help("<f64> Accuracy target")
41+
.validator(super::arg_validator_positive_f64)
42+
.required(false))
3443
}
3544

3645
pub fn nib_cli(matches: &clap::ArgMatches) {
3746
let nib_file = matches.value_of("nib").unwrap();
3847
let input_file = matches.value_of("input").unwrap();
3948
let output_file = matches.value_of("output").unwrap();
49+
let accuracy = matches.value_of("accuracy").unwrap();
4050

4151
let settings = fontforge::NibSettings {
4252
nib: nib_file.to_string(),
4353
path: input_file.to_string(),
54+
accuracy: accuracy.parse().unwrap(), //validated by super::arg_validator_positive_f64
4455
quiet: true,
4556
};
4657

src/nib_stroke/fontforge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ fn glif_to_ffsplineset<T>(glif: glifparser::Glif<T>) -> (Vec<fontforge::SplineSe
243243
pub struct NibSettings {
244244
pub nib: String,
245245
pub path: String,
246+
pub accuracy: f64,
246247
pub quiet: bool,
247248
}
248249

@@ -288,6 +289,7 @@ pub fn convert_glif(settings: &NibSettings) -> Option<String> {
288289
(*si).stroke_type = fontforge::si_type_si_nib;
289290
(*si).nib = nibss;
290291
(*si).width = 10.;
292+
(*si).accuracy_target = settings.accuracy;
291293
(*si).simplify = -1;
292294
(*si).rmov = fontforge::stroke_rmov_srmov_none;
293295
// Do the stroke for each contour. We do it this way to avoid constructing linked lists of

0 commit comments

Comments
 (0)