Skip to content

Commit

Permalink
Merge pull request #229 from linebender/privatize-some-loadsavers
Browse files Browse the repository at this point in the history
Take some load/save methods private
  • Loading branch information
madig authored Jan 1, 2022
2 parents 16ada43 + a887f9d commit 4b23a52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/fontinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl FontInfo {
/// converted by taking their absolute value. Fields that could be floats before and are
/// integers now are rounded. Fields that could be floats before and are unsigned integers
/// now are rounded before taking their absolute value.
pub fn from_file<P: AsRef<Path>>(
pub(crate) fn from_file<P: AsRef<Path>>(
path: P,
format_version: FormatVersion,
lib: &mut Plist,
Expand Down
10 changes: 6 additions & 4 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl LayerSet {
///
/// The `glyph_names` argument allows norad to reuse glyph name strings,
/// reducing memory use.
pub fn load(base_dir: &Path, glyph_names: &NameList) -> Result<LayerSet, Error> {
pub(crate) fn load(base_dir: &Path, glyph_names: &NameList) -> Result<LayerSet, Error> {
let layer_contents_path = base_dir.join(LAYER_CONTENTS_FILE);
let to_load: Vec<(LayerName, PathBuf)> = if layer_contents_path.exists() {
plist::from_file(&layer_contents_path)
Expand Down Expand Up @@ -225,7 +225,8 @@ impl Layer {
///
/// You generally shouldn't need this; instead prefer to load all layers
/// with [`LayerSet::load`] and then get the layer you need from there.
pub fn load(path: impl AsRef<Path>, name: LayerName) -> Result<Layer, Error> {
#[cfg(test)]
pub(crate) fn load(path: impl AsRef<Path>, name: LayerName) -> Result<Layer, Error> {
let path = path.as_ref();
let names = NameList::default();
Layer::load_impl(path, name, &names)
Expand Down Expand Up @@ -321,7 +322,8 @@ impl Layer {
/// [`WriteOptions`] serialization format configuration.
///
/// The path should not exist.
pub fn save(&self, path: impl AsRef<Path>) -> Result<(), Error> {
#[cfg(test)]
pub(crate) fn save(&self, path: impl AsRef<Path>) -> Result<(), Error> {
let options = WriteOptions::default();
self.save_with_options(path.as_ref(), &options)
}
Expand All @@ -330,7 +332,7 @@ impl Layer {
/// [`WriteOptions`] serialization format configuration.
///
/// The path should not exist.
pub fn save_with_options(&self, path: &Path, opts: &WriteOptions) -> Result<(), Error> {
pub(crate) fn save_with_options(&self, path: &Path, opts: &WriteOptions) -> Result<(), Error> {
fs::create_dir(&path).map_err(|source| Error::UfoWrite { path: path.into(), source })?;
crate::write::write_xml_to_file(&path.join(CONTENTS_FILE), &self.contents, opts)?;

Expand Down
7 changes: 3 additions & 4 deletions tests/save.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Testing saving files.
use norad::{Font, FormatVersion, Glyph, Identifier, Layer, Plist};
use norad::{Font, FormatVersion, Glyph, Identifier, Plist};
use plist::Value;

#[test]
Expand Down Expand Up @@ -50,9 +50,8 @@ fn save_new_file() {
#[test]
fn save_fancy() {
let mut my_ufo = Font::new();
let layer_path = "testdata/MutatorSansLightWide.ufo/glyphs";
let layer = Layer::load(layer_path, "foreground".into()).unwrap();
*my_ufo.default_layer_mut() = layer;
let other_ufo = Font::load("testdata/MutatorSansLightWide.ufo").unwrap();
*my_ufo.default_layer_mut() = other_ufo.layers.get("foreground").unwrap().clone();

let dir = tempdir::TempDir::new("Fancy.ufo").unwrap();
my_ufo.save(&dir).unwrap();
Expand Down

0 comments on commit 4b23a52

Please sign in to comment.