Skip to content

Commit

Permalink
Support fonts named Oblique instead of Italic (#1034)
Browse files Browse the repository at this point in the history
We have a font that is an Oblique, not a true Italic, so we named it Oblique. When creating UFOs, or building static TTFs, the style name for the Obliques would be "Oblique Italic" and "Bold Oblique Italic". I added "Oblique" as an alternative where names were previously tested only for "Italic".

While investigating this, I noticed that the styleMapStyleName was not getting set correctly in the case of Bold Italic (it was getting set as Italic, not Bold and Italic), thus the macStyle and fsSelection bits were not getting set correctly (both the Italic and Bold Italic had bits set the same: i.e. Italic and not Bold). So I changed is_bold=(stylename=="Bold") to is_bold=("Bold" in styleName) in to_ufo_names.

I also added test cases for both.

---------

Co-authored-by: Rob McKaughan <[email protected]>
  • Loading branch information
khaledhosny and robmck-ms authored Sep 30, 2024
1 parent 664779c commit 87da592
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Lib/glyphsLib/builder/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def to_ufo_names(self, ufo, master, family_name):
styleMapFamilyName, styleMapStyleName = build_stylemap_names(
family_name=family_name,
style_name=styleName,
is_bold=(styleName == "Bold"),
is_bold=(styleName in ("Bold", "Bold Italic", "Bold Oblique")),
is_italic=is_italic,
)
ufo.info.styleMapFamilyName = styleMapFamilyName
Expand Down Expand Up @@ -99,7 +99,7 @@ def _get_linked_style(style_name, is_bold, is_italic):
is_regular = False
elif part == "Bold" and is_bold:
is_bold = False
elif part == "Italic" and is_italic:
elif (part == "Italic" or part == "Oblique") and is_italic:
is_italic = False
else:
linked_style.appendleft(part)
Expand Down
29 changes: 25 additions & 4 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ def _joinName(self):
if self.italicAngle:
if names == ["Regular"]:
return "Italic"
if "Italic" not in self.customName:
if "Italic" not in self.customName and "Oblique" not in self.customName:
names.append("Italic")
return " ".join(names)

Expand Down Expand Up @@ -3311,7 +3311,14 @@ def windowsFamily(self):
value = self.customParameters["styleMapFamilyName"]
if value:
return value
if self.name not in ("Regular", "Bold", "Italic", "Bold Italic"):
if self.name not in (
"Regular",
"Bold",
"Italic",
"Oblique",
"Bold Italic",
"Bold Oblique",
):
return self.familyName + " " + self.name
else:
return self.familyName
Expand All @@ -3322,7 +3329,14 @@ def windowsFamily(self, value):

@property
def windowsStyle(self):
if self.name in ("Regular", "Bold", "Italic", "Bold Italic"):
if self.name in (
"Regular",
"Bold",
"Italic",
"Oblique",
"Bold Italic",
"Bold Oblique",
):
return self.name
else:
return "Regular"
Expand All @@ -3331,7 +3345,14 @@ def windowsStyle(self):
def windowsLinkedToStyle(self):
value = self.linkStyle
return value
if self.name in ("Regular", "Bold", "Italic", "Bold Italic"):
if self.name in (
"Regular",
"Bold",
"Italic",
"Oblique",
"Bold Italic",
"Bold Oblique",
):
return self.name
else:
return "Regular"
Expand Down
16 changes: 16 additions & 0 deletions tests/classes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ def test_name(self):
master.italicAngle = 10.0
self.assertEqual("Italic", master.name)

# Test that bold italic gets properly named.
master = GSFontMaster()
master.weight = "Bold"
master.width = "Regular"
master.italicAngle = 10.0
self.assertEqual("Bold Italic", master.name)

# Test that we don't get an extra "Italic" in the name of masters
# whose customName already contain the string "Italic"
master = GSFontMaster()
Expand All @@ -680,6 +687,15 @@ def test_name(self):
master.italicAngle = 10.0
self.assertEqual("Italic", master.name)

# Test that we don't get an extra "Italic" in the name of masters
# whose customName contains the string "Oblique"
master = GSFontMaster()
master.weight = "Regular"
master.width = "Regular"
master.customName = "Oblique"
master.italicAngle = 10.0
self.assertEqual("Oblique", master.name)

def test_name_assignment(self):
test_data = [
# <name>, <expected weight>, <expected width>, <expected custom>
Expand Down

0 comments on commit 87da592

Please sign in to comment.