writeDesignSpace-min.py 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from designSpaceDocument import DesignSpaceDocument, SourceDescriptor, InstanceDescriptor, AxisDescriptor
  2. import os
  3. ###
  4. designSpacePath = "Roboto-min.designspace"
  5. familyName = "Roboto"
  6. sources = [
  7. dict(path="master_ufo/Roboto-Thin.ufo", name="Roboto-Thin.ufo", location=dict(weight=-1), styleName="Thin", familyName=familyName, copyInfo=False),
  8. dict(path="master_ufo/Roboto-Regular.ufo", name="Roboto-Regular.ufo", location=dict(weight=-0.1, width=100, slant=0), styleName="Regular", familyName=familyName, copyInfo=True),
  9. dict(path="master_ufo/Roboto-Black.ufo", name="Roboto-Black.ufo", location=dict(weight=1.125), styleName="Black", familyName=familyName, copyInfo=False),
  10. dict(path="master_ufo/Roboto-ThinItalic.ufo", name="Roboto-ThinItalic.ufo", location=dict(weight=-1, slant=12), styleName="Thin Italic", familyName=familyName, copyInfo=False),
  11. dict(path="master_ufo/Roboto-Italic.ufo", name="Roboto-Italic.ufo", location=dict(slant=12), styleName="Italic", familyName=familyName, copyInfo=False),
  12. dict(path="master_ufo/Roboto-BlackItalic.ufo", name="Roboto-BlackItalic.ufo", location=dict(weight=1.125, slant=12), styleName="Black Italic", familyName=familyName, copyInfo=False),
  13. dict(path="master_ufo/RobotoCondensed-Light.ufo", name="RobotoCondensed-Light.ufo", location=dict(weight=-0.55, width=75), styleName="Condensed Light", familyName=familyName, copyInfo=False),
  14. dict(path="master_ufo/RobotoCondensed-Regular.ufo", name="RobotoCondensed-Regular.ufo", location=dict(width=75), styleName="Condensed Regular", familyName=familyName, copyInfo=False),
  15. dict(path="master_ufo/RobotoCondensed-Bold.ufo", name="RobotoCondensed-Bold.ufo", location=dict(weight=0.75, width=75), styleName="Condensed Bold", familyName=familyName, copyInfo=False),
  16. dict(path="master_ufo/RobotoCondensed-LightItalic.ufo", name="RobotoCondensed-LightItalic.ufo", location=dict(weight=-0.55, width=75, slant=12), styleName="Condensed Light Italic", familyName=familyName, copyInfo=False),
  17. dict(path="master_ufo/RobotoCondensed-Italic.ufo", name="RobotoCondensed-Italic.ufo", location=dict(width=75, slant=12), styleName="Condensed Italic", familyName=familyName, copyInfo=False),
  18. dict(path="master_ufo/RobotoCondensed-BoldItalic.ufo", name="RobotoCondensed-BoldItalic.ufo", location=dict(weight=0.75, width=75, slant=12), styleName="Condensed Bold Italic", familyName=familyName, copyInfo=False),
  19. ]
  20. axes = [
  21. dict(minimum=-1, maximum=1.125, default=-0.1, name="weight", tag="wght", labelNames={"en": "Weight"}, map=[]),
  22. dict(minimum=75, maximum=100, default=100, name="width", tag="wdth", labelNames={"en": "Width"}, map=[]),
  23. dict(minimum=0, maximum=12, default=0, name="slant", tag="slnt", labelNames={"en": "Slant"}, map=[]),
  24. ]
  25. instances = []
  26. for source in sources:
  27. instances.append(dict(location=source["location"], styleName=source["styleName"], familyName=source["familyName"]))
  28. #Thin
  29. instances.insert(1, dict(location=dict(weight=-0.55), styleName="Light", familyName=familyName))
  30. #Regular
  31. instances.insert(3, dict(location=dict(weight=0.35), styleName="Medium", familyName=familyName))
  32. instances.insert(4, dict(location=dict(weight=0.73), styleName="Bold", familyName=familyName))
  33. #Bold
  34. #Thin Italic
  35. instances.insert(7, dict(location=dict(weight=-0.55, slant=12), styleName="Light Italic", familyName=familyName))
  36. #Italic
  37. instances.insert(9, dict(location=dict(weight=0.35, slant=12), styleName="Medium Italic", familyName=familyName))
  38. instances.insert(10, dict(location=dict(weight=0.73, slant=12), styleName="Bold Italic", familyName=familyName))
  39. #Black Italic
  40. instances.pop(2) # fix bug with 2 regular?
  41. doc = DesignSpaceDocument()
  42. for source in sources:
  43. s = SourceDescriptor()
  44. s.path = source["path"]
  45. s.name = source["name"]
  46. s.copyInfo = source["copyInfo"]
  47. s.location = source["location"]
  48. s.familyName = source["familyName"]
  49. s.styleName = source["styleName"]
  50. doc.addSource(s)
  51. for instance in instances:
  52. i = InstanceDescriptor()
  53. i.location = instance["location"]
  54. i.familyName = instance["familyName"]
  55. i.styleName = instance["styleName"]
  56. doc.addInstance(i)
  57. for axis in axes:
  58. a = AxisDescriptor()
  59. a.minimum = axis["minimum"]
  60. a.maximum = axis["maximum"]
  61. a.default = axis["default"]
  62. a.name = axis["name"]
  63. a.tag = axis["tag"]
  64. for languageCode, labelName in axis["labelNames"].items():
  65. a.labelNames[languageCode] = labelName
  66. a.map = axis["map"]
  67. doc.addAxis(a)
  68. #doc.checkAxes()
  69. #doc.checkDefault()
  70. doc.write(designSpacePath)