Skip to content

Commit

Permalink
Swap in the variable feature writers if variable=True is passed to lo…
Browse files Browse the repository at this point in the history
…adFeatureWriters
  • Loading branch information
simoncozens committed Jul 19, 2022
1 parent 2979873 commit f93228a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Lib/ufo2ft/featureWriters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@
from .gdefFeatureWriter import GdefFeatureWriter
from .kernFeatureWriter import KernFeatureWriter
from .markFeatureWriter import MarkFeatureWriter
from .variableCursWriter import VariableCursFeatureWriter
from .variableKernWriter import VariableKernFeatureWriter
from .variableMarkWriter import VariableMarkFeatureWriter
from .variableRulesWriter import VariableRulesFeatureWriter

__all__ = [
"BaseFeatureWriter",
"CursFeatureWriter",
"GdefFeatureWriter",
"KernFeatureWriter",
"MarkFeatureWriter",
"VariableCursFeatureWriter",
"VariableKernFeatureWriter",
"VariableMarkFeatureWriter",
"VariableRulesFeatureWriter",
"loadFeatureWriters",
]

variableWriters = {
"CursFeatureWriter": "VariableCursFeatureWriter",
"KernFeatureWriter": "VariableKernFeatureWriter",
"MarkFeatureWriter": "VariableMarkFeatureWriter"
}

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -48,7 +62,7 @@ def write(self, font, feaFile, compiler=None)
return True


def loadFeatureWriters(ufo, ignoreErrors=True):
def loadFeatureWriters(ufo, ignoreErrors=True, variable=False):
"""Check UFO lib for key "com.github.googlei18n.ufo2ft.featureWriters",
containing a list of dicts, each having the following key/value pairs:
For example:
Expand All @@ -63,6 +77,10 @@ def loadFeatureWriters(ufo, ignoreErrors=True):
the built-in ufo2ft.featureWriters), and instantiate it with the given
'options' dict.
If ``variable`` is true, then the feature writer class is asked if it
has an associated class which works on Designspace files instead of UFOs,
and if so, then this is used instead.
Return the list of feature writer objects.
If the 'featureWriters' key is missing from the UFO lib, return None.
Expand All @@ -80,6 +98,8 @@ def loadFeatureWriters(ufo, ignoreErrors=True):
if not isinstance(options, dict):
raise TypeError(type(options))
module = importlib.import_module(moduleName)
if variable and className in variableWriters:
className = variableWriters[className]
klass = getattr(module, className)
if not isValidFeatureWriter(klass):
raise TypeError(klass)
Expand Down

0 comments on commit f93228a

Please sign in to comment.