From 87da5926397c07b465ee4af26e63ad0b8b8e4caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=AE=D8=A7=D9=84=D8=AF=20=D8=AD=D8=B3=D9=86=D9=8A=20=28K?= =?UTF-8?q?haled=20Hosny=29?= Date: Mon, 30 Sep 2024 22:27:14 +0300 Subject: [PATCH] Support fonts named Oblique instead of Italic (#1034) 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 --- Lib/glyphsLib/builder/names.py | 4 ++-- Lib/glyphsLib/classes.py | 29 +++++++++++++++++++++++++---- tests/classes_test.py | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Lib/glyphsLib/builder/names.py b/Lib/glyphsLib/builder/names.py index aed5c0379..93d2b6bac 100644 --- a/Lib/glyphsLib/builder/names.py +++ b/Lib/glyphsLib/builder/names.py @@ -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 @@ -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) diff --git a/Lib/glyphsLib/classes.py b/Lib/glyphsLib/classes.py index ef4a2bd84..5cd002841 100755 --- a/Lib/glyphsLib/classes.py +++ b/Lib/glyphsLib/classes.py @@ -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) @@ -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 @@ -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" @@ -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" diff --git a/tests/classes_test.py b/tests/classes_test.py index 22b9492f6..2a2316f2c 100755 --- a/tests/classes_test.py +++ b/tests/classes_test.py @@ -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() @@ -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 = [ # , , ,