-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! A little tool for normalizing UFOs. | ||
//! | ||
//! It will scrub layer and lib data of a UFO in an opinionated way, as done | ||
//! in the Cantarell font project, to show a real-world script. | ||
//! | ||
//! Call like `cargo run --release --example normalize some.ufo another.ufo`. | ||
|
||
fn main() { | ||
for arg in std::env::args().skip(1) { | ||
let mut ufo = match norad::Ufo::load(&arg) { | ||
Ok(v) => v, | ||
Err(e) => { | ||
eprintln!("Loading UFO failed: {}", e); | ||
std::process::exit(1); | ||
} | ||
}; | ||
|
||
// Prune all non-foreground layers. | ||
ufo.layers.retain(|l| l.name == "public.default"); | ||
|
||
// Prune the foreground layer's lib. | ||
let default_layer = ufo.get_default_layer_mut().unwrap(); | ||
default_layer.info.lib.as_mut().and_then(|lib| { | ||
Some(lib.retain(|k, &mut _| { | ||
k.starts_with("public.") || k.starts_with("com.schriftgestaltung.layerId") | ||
})) | ||
}); | ||
|
||
// Prune all glyphs' libs. | ||
for glyph in default_layer.iter_contents_mut() { | ||
glyph.lib.as_mut().and_then(|lib| { | ||
Some(lib.retain(|k, &mut _| { | ||
(k.starts_with("public.") | ||
|| k.starts_with("com.schriftgestaltung.") | ||
|| k == "com.schriftgestaltung.componentsAlignment") | ||
&& k != "public.markColor" | ||
})) | ||
}); | ||
} | ||
|
||
// Prune the UFO lib. | ||
ufo.lib.as_mut().and_then(|lib| { | ||
Some(lib.retain(|k, &mut _| { | ||
k.starts_with("public.") | ||
|| k.starts_with("com.github.googlei18n.ufo2ft.") | ||
|| k == "com.schriftgestaltung.appVersion" | ||
|| k == "com.schriftgestaltung.fontMasterID" | ||
|| k == "com.schriftgestaltung.customParameter.GSFont.disablesLastChange" | ||
|| k == "com.schriftgestaltung.customParameter.GSFontMaster.paramArea" | ||
|| k == "com.schriftgestaltung.customParameter.GSFontMaster.paramDepth" | ||
|| k == "com.schriftgestaltung.customParameter.GSFontMaster.paramOver" | ||
})) | ||
}); | ||
|
||
ufo.meta.creator = "org.linebender.norad".to_string(); | ||
match ufo.save(arg) { | ||
Err(e) => { | ||
eprintln!("Saving UFO failed: {}", e); | ||
std::process::exit(1); | ||
} | ||
_ => {} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters