Skip to content

Commit

Permalink
Let's not name things Thing Italic Italic
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Dec 4, 2024
1 parent 1b28bb5 commit 930ab11
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
43 changes: 33 additions & 10 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,24 +1549,28 @@ impl RawFont {
if master.name.is_some() {
continue;
}
let width_name = master.width.take();
let weight_name = master.weight.take();
let custom_name = master.custom.take();

// Remove Nones, empty strings and redundant occurrences of 'Regular'
let mut names: Vec<_> = [width_name, weight_name, custom_name]
.into_iter()
.flatten()
.filter(|x| !x.is_empty() && x != "Regular")
.collect();
let mut names = [
master.width.as_deref(),
master.weight.as_deref(),
master.custom.as_deref(),
]
.iter()
.flatten()
.flat_map(|n| n.split_ascii_whitespace())
.filter(|x| *x != "Regular")
.collect::<Vec<_>>();

// append "Italic" if italic angle != 0
if let Some(italic_angle) = master.italic_angle {
if italic_angle != 0.0
&& (names.is_empty()
|| !names
.iter()
.any(|name| name == "Italic" || name == "Oblique"))
.any(|name| *name == "Italic" || *name == "Oblique"))
{
names.push("Italic".into());
names.push("Italic");
}
}
// if all are empty, default to "Regular"
Expand Down Expand Up @@ -3560,6 +3564,7 @@ mod tests {
Some(&OrderedFloat(0f64))
);
}

#[test]
fn read_font_metrics() {
let font =
Expand Down Expand Up @@ -3590,4 +3595,22 @@ mod tests {
.content
.contains("name 3 1 0x409 \"Alternate placeholder\""));
}

// <https://github.com/googlefonts/fontc/issues/1175>
#[test]
fn one_italic_is_enough() {
let font = Font::load(&glyphs2_dir().join("ItalicItalic.glyphs")).unwrap();
for master in font.masters {
let mut fragments = master.name.split_ascii_whitespace().collect::<Vec<_>>();
fragments.sort();
for words in fragments.windows(2) {
assert!(
words[0] != words[1],
"Multiple instances of {} in {}",
words[0],
master.name
);
}
}
}
}
34 changes: 34 additions & 0 deletions resources/testdata/glyphs2/ItalicItalic.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
customParameters = (
{
name = Axes;
value = (
{
Name = Weight;
Tag = wght;
}
);
}
);
familyName = "Master Names";
fontMaster = (
{
custom = "Thin Italic";
id = m01;
italicAngle = 10;
}
);
glyphs = (
{
glyphname = space;
layers = (
{
layerId = m01;
width = 200;
}
);
unicode = 0020;
}
);
unitsPerEm = 1000;
}

0 comments on commit 930ab11

Please sign in to comment.