Skip to content

Commit

Permalink
Merge pull request #267 from linebender/privatize-glyph-names
Browse files Browse the repository at this point in the history
Take glyph name crate-public
  • Loading branch information
madig authored Jul 15, 2022
2 parents cd8b56d + 0d3303f commit 667a109
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
8 changes: 7 additions & 1 deletion src/glyph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use crate::{Color, Guideline, Identifier, Line, Plist, WriteOptions};
#[cfg_attr(feature = "druid", derive(Lens))]
pub struct Glyph {
/// The name of the glyph.
pub name: Name,
#[cfg_attr(feature = "druid", lens(ignore))]
pub(crate) name: Name,
/// Glyph height.
pub height: f64,
/// Glyph width.
Expand Down Expand Up @@ -125,6 +126,11 @@ impl Glyph {
}
}

/// Returns the name of the glyph.
pub fn name(&self) -> &Name {
&self.name
}

/// Returns true if [`Glyph`] contains one or more [`Component`]s.
pub fn has_component(&self) -> bool {
!self.components.is_empty()
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! let mut font_obj = Font::load(inpath).expect("failed to load font");
//! # let layer = font_obj.default_layer();
//! # let glyph_a = layer.get_glyph("A").expect("missing glyph");
//! # assert_eq!(glyph_a.name.as_ref(), "A");
//! # assert_eq!(glyph_a.name().as_ref(), "A");
//! # let outpath = "RoflsSemiDim.ufo";
//! # font_obj.save(outpath);
//! ```
Expand All @@ -28,7 +28,7 @@
//! # let mut font_obj = Font::load(inpath).expect("failed to load font");
//! let layer = font_obj.default_layer();
//! let glyph_a = layer.get_glyph("A").expect("missing glyph");
//! assert_eq!(glyph_a.name.as_ref(), "A");
//! assert_eq!(glyph_a.name().as_ref(), "A");
//! # let outpath = "RoflsSemiDim.ufo";
//! # font_obj.save(outpath);
//! ```
Expand All @@ -41,7 +41,7 @@
//! # let mut font_obj = Font::load(inpath).expect("failed to load font");
//! # let layer = font_obj.default_layer();
//! # let glyph_a = layer.get_glyph("A").expect("missing glyph");
//! # assert_eq!(glyph_a.name.as_ref(), "A");
//! # assert_eq!(glyph_a.name().as_ref(), "A");
//! let outpath = "RoflsSemiDim.ufo";
//! font_obj.save(outpath);
//! ```
Expand Down
22 changes: 6 additions & 16 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, Name, Plist};
use norad::{Font, FormatVersion, Glyph, Identifier, Plist};
use plist::Value;

#[test]
Expand Down Expand Up @@ -62,8 +62,8 @@ fn save_fancy() {
assert_eq!(pre_layer.iter().count(), post_layer.iter().count());

for glyph in pre_layer.iter() {
let other = post_layer.get_glyph(&glyph.name);
assert!(other.is_some(), "missing {}", &glyph.name);
let other = post_layer.get_glyph(glyph.name());
assert!(other.is_some(), "missing {}", glyph.name());
assert_eq!(glyph, other.unwrap());
}
}
Expand Down Expand Up @@ -191,19 +191,9 @@ fn object_libs_reject_existing_key() {
assert!(ufo.save(&dir).is_err());
ufo.lib.remove("public.objectLibs");

let glyph = Glyph {
name: Name::new("test").unwrap(),
height: 0.,
width: 0.,
anchors: vec![],
codepoints: vec![],
guidelines: vec![],
image: None,
lib: test_lib,
note: None,
components: vec![],
contours: vec![],
};
let mut glyph = Glyph::new("test");
glyph.lib = test_lib;

ufo.default_layer_mut().insert_glyph(glyph);
assert!(ufo.save(&dir).is_err());
}

0 comments on commit 667a109

Please sign in to comment.