Open typemytype opened 1 year ago
It could also be a variant of fontVariations()
. In a way, named instances are just shortcuts for designspace locations.
def fontVariations(self, namedInstance=None, **axes):
if namedInstance is not None:
assert not axes
...select named instance...
else:
...select location from axes...
True, only those named instances have already their own listFontVariations
and named instances are not listed there.
So to make it similar it could also be fontNamedInstance(name)
fontNamedInstance(name)
is fine with me, too.
We'd need to ensure this also works with installed fonts.
we store the fontNameOrPath
in self._font, see
if this is not a path then fontNamedInstance(Name)
would just redirect to font(name)
if this is not a path then fontNamedInstance(Name) would just redirect to font(name)
Hm, so this would "work"?:
font("Helvetica")
fontNamedInstance("A-Named-Instance-From-An-Unrelated-VF-That-Is-Installed")
Either we provide something that works transparently (and intuititely) for both installed and path-based fonts, or we need to make clear this funtionality is specific to path-based fonts. The latter is not something we currently have I think.
It should test if the font has an instance with that name, otherwise raise or warn (redirect wasnt the smartest plan :) )
oke, proposal:
from drawBot.misc import DrawBotError
def fontNamedInstance(name):
instances = listNamedInstances()
if name in instances:
fontVariations(**instances[name])
else:
raise DrawBotError(f"Can not find instance with name: '{name}'.")
font("Skia", 200)
fontNamedInstance("Skia-Regular_Black-Extended")
fontNamedInstance("Skia-Regular_Light-Extended")
text("abc", (50, 50))
installFonts(...)
is deprecated in favour of providing a font path... but for a variation font a script must be able to select a named instance, now the fontName is a path and not a PS font name.I would like to propose something similar to
fontNumber
font(path, namedInstance="myCool-Regular")
https://github.com/typemytype/drawbot/blob/master/drawBot/drawBotDrawingTools.py#L1312
this should raise an error when the current font is not a variation font and warn when the name instance is not available