Skip to content

Commit

Permalink
add support for axis labelNames while creating registered axis
Browse files Browse the repository at this point in the history
  • Loading branch information
typemytype committed Dec 12, 2023
1 parent 1e57c72 commit 5e86c1d
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from mojo.roboFont import AllFonts, OpenFont, RFont, internalFontClasses

from lib.tools.debugTools import ClassNameIncrementer
from lib.tools.misc import coalescingDecorator
from lib.tools.misc import coalescingDecorator, tryExceptDecorator

from lib.cells.doubleClickCell import RFDoubleClickCell
from lib.formatters import PathFormatter

Expand All @@ -40,12 +41,11 @@
("weight", "wght"),
]


preferredAxes = [
("weight", "wght", 400, 700, 400),
("width", "wdth", 50, 100, 100),
("optical", "opsz", 10, 16, 10),
# ("italic", "ital", 0, 0, 0), # must be a discrete axis
# ("slant", "slnt", -90, 0, 90),
("weight", "wght", 400, 700, 400, dict(en="Weight")),
("width", "wdth", 50, 100, 100, dict(en="Width")),
("optical", "opsz", 10, 16, 10, dict(en="Optical Size")),
]

designspacenotesLibKey = "designspaceEdit.notes"
Expand Down Expand Up @@ -354,6 +354,7 @@ def axisMinimum(self):
return None
return self.axisDescriptor.minimum

#@tryExceptDecorator
def setAxisMinimum_(self, value):
if self.axisIsDescrete():
# convert to a continuous axis
Expand All @@ -373,6 +374,7 @@ def axisMaximum(self):
return None
return self.axisDescriptor.maximum

#@tryExceptDecorator
def setAxisMaximum_(self, value):
if self.axisIsDescrete():
# convert to a continuous axis
Expand All @@ -388,6 +390,7 @@ def axisDiscreteValues(self):
return " ".join([numberToString(value) for value in self.axisDescriptor.values])
return ""

#@tryExceptDecorator
def setAxisDiscreteValues_(self, value):
if not self.axisIsDescrete():
# convert to a discrete axis
Expand Down Expand Up @@ -810,7 +813,7 @@ def build(self):
(72, 5, 370, 22),
selectionStyle="momentary",
callback=self.axisEditorToolsCallback,
segmentDescriptions=[dict(title=f"Add {preferredAxis[0].title()} Axis") for preferredAxis in preferredAxes]
segmentDescriptions=[dict(title=f"Add {preferredAxis[-1]['en']} Axis") for preferredAxis in preferredAxes]
)

axisDoubleClickCell = RFDoubleClickCell.alloc().init()
Expand Down Expand Up @@ -1082,21 +1085,22 @@ def axisToolsCallback(self, sender):
self.updateColumnHeadersFromAxes()

def axisEditorToolsCallback(self, sender):
value = sender.get()
name, tag, minimum, maximum, default = preferredAxes[value]
self._addAxis(name, tag, minimum, maximum, default)
index = sender.get()
name, tag, minimum, maximum, default, labelNames = preferredAxes[index]
self._addAxis(name, tag, minimum, maximum, default, labelNames)

self.setDocumentNeedSave(True, who="Axes")
self.updateColumnHeadersFromAxes()

def _addAxis(self, name, tag, minimum, maximum, default):
def _addAxis(self, name, tag, minimum, maximum, default, labelNames=None):
if self.validateAxisName(name) and self.validateAxisTag(tag):
self.operator.addAxisDescriptor(
name=name,
tag=tag,
minimum=minimum,
maximum=maximum,
default=default
default=default,
labelNames=labelNames
)
else:
print(f"Duplicate axis: '{name}'")
Expand Down Expand Up @@ -1980,5 +1984,5 @@ def designspaceEditorInstancesDidChange(self, notification):

path = "/Users/frederik/Documents/dev/letterror/mutatorSans/MutatorSans.designspace"
# path = "/Users/frederik/Documents/fontsGit/RoboType/RF.designspace"
# path = None
path = None
DesignspaceEditorController(path)

0 comments on commit 5e86c1d

Please sign in to comment.