writeDesignSpace-min.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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, width=100, slant=0), 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, width=100, slant=0), styleName="Black", familyName=familyName, copyInfo=False),
  10. dict(path="master_ufo/Roboto-ThinItalic.ufo", name="Roboto-ThinItalic.ufo", location=dict(weight=-1, width=100, slant=-12), styleName="Thin Italic", familyName=familyName, copyInfo=False),
  11. dict(path="master_ufo/Roboto-Italic.ufo", name="Roboto-Italic.ufo", location=dict(weight=-0.1, width=100, 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, width=100, 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, slant=0), styleName="Condensed Light", familyName=familyName, copyInfo=False),
  14. dict(path="master_ufo/RobotoCondensed-Regular.ufo", name="RobotoCondensed-Regular.ufo", location=dict(weight=-0.1, width=75, slant=0), 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, slant=0), 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(weight=-0.1, 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=250, maximum=900, default=400, name="weight", tag="wght", labelNames={"en": "Weight"}, map=[(250.0, -1.0), (300.0, -0.55), (400.0, -0.1), (500.0, 0.35), (700.0, 0.73), (900.0, 1.125)]),
  22. dict(minimum=75, maximum=100, default=100, name="width", tag="wdth", labelNames={"en": "Width"}, map=[]),
  23. dict(minimum=-12, maximum=0, 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. doc = DesignSpaceDocument()
  41. for source in sources:
  42. s = SourceDescriptor()
  43. s.path = source["path"]
  44. s.name = source["name"]
  45. s.copyInfo = source["copyInfo"]
  46. s.location = source["location"]
  47. s.familyName = source["familyName"]
  48. s.styleName = source["styleName"]
  49. doc.addSource(s)
  50. for instance in instances:
  51. i = InstanceDescriptor()
  52. i.location = instance["location"]
  53. i.familyName = instance["familyName"]
  54. i.styleName = instance["styleName"]
  55. doc.addInstance(i)
  56. for axis in axes:
  57. a = AxisDescriptor()
  58. a.minimum = axis["minimum"]
  59. a.maximum = axis["maximum"]
  60. a.default = axis["default"]
  61. a.name = axis["name"]
  62. a.tag = axis["tag"]
  63. for languageCode, labelName in axis["labelNames"].items():
  64. a.labelNames[languageCode] = labelName
  65. a.map = axis["map"]
  66. doc.addAxis(a)
  67. #doc.checkAxes()
  68. #doc.checkDefault()
  69. doc.write(designSpacePath)