Skip to content

Commit

Permalink
GSFontMaster horizontalStems and verticalStems parsing for file format 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kontur committed Oct 17, 2022
1 parent cd9b37e commit fc2b551
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions Lib/glyphsLib/builder/masters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


def to_ufo_master_attributes(self, ufo, master):
print("UFO MASTER ATTR", master.horizontalStems)
ufo.info.ascender = master.ascender
ufo.info.capHeight = master.capHeight
ufo.info.descender = master.descender
Expand Down
44 changes: 42 additions & 2 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,17 +1595,17 @@ def __init__(self):
self._name = None
self._userData = None
self._alignmentZones = None
self._horizontalStems = None
self._verticalStems = None
self.axes = list(self._axis_defaults)
self.metrics = []
self.customName = ""
self.font = None
self.guides = []
self.horizontalStems = 0
self.iconName = ""
self.id = str(uuid.uuid4()).upper()
self.numbers = []
self.stems = []
self.verticalStems = 0
self.visible = False
self.weight = self._defaultsForName["weight"]
self.width = self._defaultsForName["width"]
Expand Down Expand Up @@ -1791,6 +1791,46 @@ def alignmentZones(self, value):
zones.append(val)
self._alignmentZones = zones

@property
def horizontalStems(self):
if self._horizontalStems is not None:
return self._horizontalStems

if not hasattr(self.font, "stems"):
return []

horizontalStems = []
for index, font_stem in enumerate(self.font.stems):
if not font_stem.horizontal:
continue
horizontalStems.append(self.stems[index])
return horizontalStems

@horizontalStems.setter
def horizontalStems(self, value):
assert type(value) == list
self._horizontalStems = value

@property
def verticalStems(self):
if self._verticalStems is not None:
return self._verticalStems

if not hasattr(self.font, "stems"):
return []

verticalStems = []
for index, font_stem in enumerate(self.font.stems):
if font_stem.horizontal:
continue
verticalStems.append(self.stems[index])
return verticalStems

@verticalStems.setter
def verticalStems(self, value):
assert type(value) == list
self._verticalStems = value

@property
def ascender(self):
return self._get_metric("ascender")
Expand Down
8 changes: 8 additions & 0 deletions tests/glyphs3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ def test_glyphs3_alignment_zones(datadir):
pos, size = zone
assert master.alignmentZones[i].position == pos
assert master.alignmentZones[i].size == size


def test_glyphs3_stems(datadir):
font = glyphsLib.load(str(datadir.join("GlyphsUnitTestSans3.glyphs")))
master = font.masters[0]

assert master.verticalStems == [17, 19]
assert master.horizontalStems == [16, 16, 18]

0 comments on commit fc2b551

Please sign in to comment.