Skip to content

Commit 5e1ecd6

Browse files
committed
[models] support custom axes with axis names from the name table
1 parent 239e612 commit 5e1ecd6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/slice/models.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class DesignAxisModel(SliceBaseTableModel):
179179
def __init__(self, *args):
180180
SliceBaseTableModel.__init__(self, *args)
181181
self.fvar_axes = {}
182+
self.fvar_name_map = {}
182183
self.ordered_axis_tags = []
183184
self._data = [
184185
["", ""],
@@ -214,8 +215,10 @@ def headerData(self, section, orientation, role):
214215
if role == Qt.ToolTipRole:
215216
if orientation == Qt.Vertical:
216217
axis_name = self.get_axis_name_string(self._v_header[section])
217-
# if this is a defined registered axis value, create a tooltip
218-
# with the full axis name
218+
# if we receive a axis name string value, create a tooltip
219+
# with the full axis name. The method returns None if the
220+
# axis name is not available. Skip tooltip gen if that is
221+
# the case
219222
if axis_name:
220223
return axis_name
221224

@@ -242,7 +245,9 @@ def load_font(self, font_model):
242245
# clear the axis tag list attribute
243246
self.ordered_axis_tags = []
244247
for axis in fvar.axes:
248+
# maintain order of axes in the font
245249
self.ordered_axis_tags.append(axis.axisTag)
250+
# create a map of the min, default, max axis values
246251
self.fvar_axes[axis.axisTag] = [
247252
axis.minValue,
248253
axis.defaultValue,
@@ -251,6 +256,11 @@ def load_font(self, font_model):
251256
new_data.append(
252257
[f"({axis.minValue}, {axis.maxValue}) [{axis.defaultValue}]", ""]
253258
)
259+
# use the axisID to locate the axis name in the name table
260+
# if it does not exist, the getName method returns None
261+
self.fvar_name_map[axis.axisTag] = (
262+
ttfont["name"].getName(axis.axisNameID, 3, 1, 1033).toUnicode()
263+
)
254264

255265
# set header with ordered axis tags
256266
self._v_header = self.ordered_axis_tags
@@ -319,7 +329,10 @@ def get_axis_name_string(self, needle):
319329
elif needle in unregistered_axes:
320330
return unregistered_axes[needle]
321331
else:
322-
return None
332+
if needle in self.fvar_name_map:
333+
return self.fvar_name_map[needle]
334+
else:
335+
return None
323336

324337

325338
class FontBitFlagModel(object):

0 commit comments

Comments
 (0)