writeDesignSpace.py 4.6 KB

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