-
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.
Merge pull request #486 from googlefonts/case
Add an underscore after capitals in glyph names
- Loading branch information
Showing
2 changed files
with
44 additions
and
4 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
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 |
---|---|---|
@@ -1,5 +1,45 @@ | ||
pub fn glyph_file(glyph_name: &str, suffix: &str) -> String { | ||
// TODO handle names that are invalid for the filesystem | ||
// Ref https://github.com/unified-font-object/ufo-spec/issues/164 | ||
glyph_name.to_owned() + suffix | ||
let mut filename = Vec::new(); | ||
for ch in glyph_name.chars() { | ||
filename.push(ch); | ||
if ch == '_' || ch.is_uppercase() { | ||
filename.push('_'); | ||
} | ||
} | ||
filename.extend(suffix.chars()); | ||
filename.into_iter().collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::HashSet; | ||
|
||
use super::glyph_file; | ||
|
||
/// <https://github.com/googlefonts/fontc/issues/41> | ||
fn assert_unique_for_caseinsensitive_fs(names: &[&str]) { | ||
let filenames: HashSet<_> = names | ||
.iter() | ||
.map(|n| glyph_file(n, "")) | ||
.map(|n| n.to_lowercase()) | ||
.collect(); | ||
assert_eq!( | ||
names.len(), | ||
filenames.len(), | ||
"{names:?} became {filenames:?}" | ||
); | ||
} | ||
|
||
#[test] | ||
fn lower_and_upper_a() { | ||
assert_unique_for_caseinsensitive_fs(&["a", "A"]); | ||
} | ||
|
||
#[test] | ||
fn adding_underscore_avoids_collisions() { | ||
// if we don't add _ to _ the resulting names are identical | ||
assert_unique_for_caseinsensitive_fs(&["Aa", "a_a"]); | ||
} | ||
} |