instantiate_statics.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import sys
  2. import shutil
  3. import os
  4. from fontTools.ttLib import TTFont
  5. from fontTools.varLib.instancer import instantiateVariableFont
  6. from scripts import (
  7. update_names,
  8. update_attribs,
  9. mkdir
  10. )
  11. instances = [
  12. {
  13. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 250},
  14. "axes": {"ital": 0.0, "wdth": 100, "wght": 100},
  15. "filename": "Roboto-Thin.ttf",
  16. "names": {
  17. "1,3,1,1033": "Roboto Thin",
  18. "16,3,1,1033": "Roboto",
  19. "17,3,1,1033": "Thin",
  20. "2,3,1,1033": "Regular",
  21. "3,3,1,1033": "Google:Roboto Thin:2016",
  22. "4,3,1,1033": "Roboto Thin",
  23. "6,3,1,1033": "Roboto-Thin",
  24. },
  25. },
  26. {
  27. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 250, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  28. "axes": {"ital": 1.0, "wdth": 100, "wght": 100},
  29. "filename": "Roboto-ThinItalic.ttf",
  30. "names": {
  31. "1,3,1,1033": "Roboto Thin",
  32. "16,3,1,1033": "Roboto",
  33. "17,3,1,1033": "Thin Italic",
  34. "2,3,1,1033": "Italic",
  35. "3,3,1,1033": "Google:Roboto Thin Italic:2016",
  36. "4,3,1,1033": "Roboto Thin Italic",
  37. "6,3,1,1033": "Roboto-ThinItalic",
  38. },
  39. },
  40. {
  41. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 300},
  42. "axes": {"ital": 0.0, "wdth": 100, "wght": 300},
  43. "filename": "Roboto-Light.ttf",
  44. "names": {
  45. "1,3,1,1033": "Roboto Light",
  46. "16,3,1,1033": "Roboto",
  47. "17,3,1,1033": "Light",
  48. "2,3,1,1033": "Regular",
  49. "3,3,1,1033": "Google:Roboto Light:2016",
  50. "4,3,1,1033": "Roboto Light",
  51. "6,3,1,1033": "Roboto-Light",
  52. },
  53. },
  54. {
  55. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 300, "usWidthClass": 5},
  56. "axes": {"ital": 0.0, "wdth": 75.0, "wght": 300},
  57. "filename": "RobotoCondensed-Light.ttf",
  58. "names": {
  59. "1,3,1,1033": "Roboto Condensed Light",
  60. "16,3,1,1033": "Roboto Condensed",
  61. "17,3,1,1033": "Light",
  62. "2,3,1,1033": "Regular",
  63. "3,3,1,1033": "Google:Roboto Condensed Light:2016",
  64. "4,3,1,1033": "Roboto Condensed Light",
  65. "6,3,1,1033": "RobotoCondensed-Light",
  66. },
  67. },
  68. {
  69. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 300, "italicAngle": -12, "usWidthClass": 5, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  70. "axes": {"ital": 1.0, "wdth": 75.0, "wght": 300},
  71. "filename": "RobotoCondensed-LightItalic.ttf",
  72. "names": {
  73. "1,3,1,1033": "Roboto Condensed Light",
  74. "16,3,1,1033": "Roboto Condensed",
  75. "17,3,1,1033": "Light Italic",
  76. "2,3,1,1033": "Italic",
  77. "3,3,1,1033": "Google:Roboto Condensed Light Italic:2016",
  78. "4,3,1,1033": "Roboto Condensed Light Italic",
  79. "6,3,1,1033": "RobotoCondensed-LightItalic",
  80. },
  81. },
  82. {
  83. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 300, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  84. "axes": {"ital": 1.0, "wdth": 100, "wght": 300},
  85. "filename": "Roboto-LightItalic.ttf",
  86. "names": {
  87. "1,3,1,1033": "Roboto Light",
  88. "16,3,1,1033": "Roboto",
  89. "17,3,1,1033": "Light Italic",
  90. "2,3,1,1033": "Italic",
  91. "3,3,1,1033": "Google:Roboto Light Italic:2016",
  92. "4,3,1,1033": "Roboto Light Italic",
  93. "6,3,1,1033": "Roboto-LightItalic",
  94. },
  95. },
  96. {
  97. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 400},
  98. "axes": {"ital": 0.0, "wdth": 100, "wght": 400},
  99. "filename": "Roboto-Regular.ttf",
  100. "names": {
  101. "1,3,1,1033": "Roboto",
  102. "2,3,1,1033": "Regular",
  103. "3,3,1,1033": "Google:Roboto Regular:2016",
  104. "4,3,1,1033": "Roboto",
  105. "6,3,1,1033": "Roboto-Regular",
  106. },
  107. },
  108. {
  109. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 400, "usWidthClass": 5},
  110. "axes": {"ital": 0.0, "wdth": 75.0, "wght": 400},
  111. "filename": "RobotoCondensed-Regular.ttf",
  112. "names": {
  113. "1,3,1,1033": "Roboto Condensed",
  114. "2,3,1,1033": "Regular",
  115. "3,3,1,1033": "Google:Roboto Condensed Regular:2016",
  116. "4,3,1,1033": "Roboto Condensed",
  117. "6,3,1,1033": "RobotoCondensed-Regular",
  118. },
  119. },
  120. {
  121. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 400, "italicAngle": -12, "usWidthClass": 5, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  122. "axes": {"ital": 1.0, "wdth": 75.0, "wght": 400},
  123. "filename": "RobotoCondensed-Italic.ttf",
  124. "names": {
  125. "1,3,1,1033": "Roboto Condensed",
  126. "2,3,1,1033": "Italic",
  127. "3,3,1,1033": "Google:Roboto Condensed Italic:2016",
  128. "4,3,1,1033": "Roboto Condensed Italic",
  129. "6,3,1,1033": "RobotoCondensed-Italic",
  130. },
  131. },
  132. {
  133. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 400, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  134. "axes": {"ital": 1.0, "wdth": 100, "wght": 400},
  135. "filename": "Roboto-Italic.ttf",
  136. "names": {
  137. "1,3,1,1033": "Roboto",
  138. "2,3,1,1033": "Italic",
  139. "3,3,1,1033": "Google:Roboto Italic:2016",
  140. "4,3,1,1033": "Roboto Italic",
  141. "6,3,1,1033": "Roboto-Italic",
  142. },
  143. },
  144. {
  145. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 500, "usWidthClass": 5},
  146. "axes": {"ital": 0.0, "wdth": 75.0, "wght": 500},
  147. "filename": "RobotoCondensed-Medium.ttf",
  148. "names": {
  149. "1,3,1,1033": "Roboto Condensed Medium",
  150. "2,3,1,1033": "Regular",
  151. "3,3,1,1033": "Google:Roboto Condensed Medium:2016",
  152. "4,3,1,1033": "Roboto Condensed Medium",
  153. "6,3,1,1033": "RobotoCondensed-Medium",
  154. "16,3,1,1033": "Roboto Condensed",
  155. "17,3,1,1033": "Medium",
  156. },
  157. },
  158. {
  159. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 500},
  160. "axes": {"ital": 0.0, "wdth": 100, "wght": 500},
  161. "filename": "Roboto-Medium.ttf",
  162. "names": {
  163. "1,3,1,1033": "Roboto Medium",
  164. "16,3,1,1033": "Roboto",
  165. "17,3,1,1033": "Medium",
  166. "2,3,1,1033": "Regular",
  167. "3,3,1,1033": "Google:Roboto Medium:2016",
  168. "4,3,1,1033": "Roboto Medium",
  169. "6,3,1,1033": "Roboto-Medium",
  170. },
  171. },
  172. {
  173. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 500, "italicAngle": -12, "usWidthClass": 5, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  174. "axes": {"ital": 1.0, "wdth": 75.0, "wght": 500},
  175. "filename": "RobotoCondensed-MediumItalic.ttf",
  176. "names": {
  177. "1,3,1,1033": "Roboto Condensed Medium",
  178. "2,3,1,1033": "Italic",
  179. "3,3,1,1033": "Google:Roboto Condensed Medium Italic:2016",
  180. "4,3,1,1033": "Roboto Condensed Medium Italic",
  181. "6,3,1,1033": "RobotoCondensed-MediumItalic",
  182. "16,3,1,1033": "Roboto Condensed",
  183. "17,3,1,1033": "Medium Italic",
  184. },
  185. },
  186. {
  187. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 500, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  188. "axes": {"ital": 1.0, "wdth": 100, "wght": 500},
  189. "filename": "Roboto-MediumItalic.ttf",
  190. "names": {
  191. "1,3,1,1033": "Roboto Medium",
  192. "16,3,1,1033": "Roboto",
  193. "17,3,1,1033": "Medium Italic",
  194. "2,3,1,1033": "Italic",
  195. "3,3,1,1033": "Google:Roboto Medium Italic:2016",
  196. "4,3,1,1033": "Roboto Medium Italic",
  197. "6,3,1,1033": "Roboto-MediumItalic",
  198. },
  199. },
  200. {
  201. "attribs": {"fsSelection": 32, "macStyle": 1, "usWeightClass": 700, "usWidthClass": 5},
  202. "axes": {"ital": 0.0, "wdth": 75.0, "wght": 700},
  203. "filename": "RobotoCondensed-Bold.ttf",
  204. "names": {
  205. "1,3,1,1033": "Roboto Condensed",
  206. "2,3,1,1033": "Bold",
  207. "3,3,1,1033": "Google:Roboto Condensed Bold:2016",
  208. "4,3,1,1033": "Roboto Condensed Bold",
  209. "6,3,1,1033": "RobotoCondensed-Bold",
  210. },
  211. },
  212. {
  213. "attribs": {"fsSelection": 32, "macStyle": 1, "usWeightClass": 700},
  214. "axes": {"ital": 0.0, "wdth": 100, "wght": 700},
  215. "filename": "Roboto-Bold.ttf",
  216. "names": {
  217. "1,3,1,1033": "Roboto",
  218. "2,3,1,1033": "Bold",
  219. "3,3,1,1033": "Google:Roboto Bold:2016",
  220. "4,3,1,1033": "Roboto Bold",
  221. "6,3,1,1033": "Roboto-Bold",
  222. },
  223. },
  224. {
  225. "attribs": {"fsSelection": 545, "macStyle": 3, "usWeightClass": 700, "italicAngle": -12, "usWidthClass": 5, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  226. "axes": {"ital": 1.0, "wdth": 75.0, "wght": 700},
  227. "filename": "RobotoCondensed-BoldItalic.ttf",
  228. "names": {
  229. "1,3,1,1033": "Roboto Condensed",
  230. "2,3,1,1033": "Bold Italic",
  231. "3,3,1,1033": "Google:Roboto Condensed Bold Italic:2016",
  232. "4,3,1,1033": "Roboto Condensed Bold Italic",
  233. "6,3,1,1033": "RobotoCondensed-BoldItalic",
  234. },
  235. },
  236. {
  237. "attribs": {"fsSelection": 545, "macStyle": 3, "usWeightClass": 700, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  238. "axes": {"ital": 1.0, "wdth": 100, "wght": 700},
  239. "filename": "Roboto-BoldItalic.ttf",
  240. "names": {
  241. "1,3,1,1033": "Roboto",
  242. "2,3,1,1033": "Bold Italic",
  243. "3,3,1,1033": "Google:Roboto Bold Italic:2016",
  244. "4,3,1,1033": "Roboto Bold Italic",
  245. "6,3,1,1033": "Roboto-BoldItalic",
  246. },
  247. },
  248. {
  249. "attribs": {"fsSelection": 64, "macStyle": 0, "usWeightClass": 900},
  250. "axes": {"ital": 0.0, "wdth": 100, "wght": 900},
  251. "filename": "Roboto-Black.ttf",
  252. "names": {
  253. "1,3,1,1033": "Roboto Black",
  254. "16,3,1,1033": "Roboto",
  255. "17,3,1,1033": "Black",
  256. "2,3,1,1033": "Regular",
  257. "3,3,1,1033": "Google:Roboto Black:2016",
  258. "4,3,1,1033": "Roboto Black",
  259. "6,3,1,1033": "Roboto-Black",
  260. },
  261. },
  262. {
  263. "attribs": {"fsSelection": 513, "macStyle": 2, "usWeightClass": 900, "italicAngle": -12, "caretSlopeRise": 2048, "caretSlopeRun": 435},
  264. "axes": {"ital": 1.0, "wdth": 100, "wght": 900},
  265. "filename": "Roboto-BlackItalic.ttf",
  266. "names": {
  267. "1,3,1,1033": "Roboto Black",
  268. "16,3,1,1033": "Roboto",
  269. "17,3,1,1033": "Black Italic",
  270. "2,3,1,1033": "Italic",
  271. "3,3,1,1033": "Google:Roboto Black Italic:2016",
  272. "4,3,1,1033": "Roboto Black Italic",
  273. "6,3,1,1033": "Roboto-BlackItalic",
  274. },
  275. },
  276. ]
  277. vf = TTFont(sys.argv[1])
  278. out_dir = mkdir(sys.argv[2])
  279. for inst in instances:
  280. print(f"Making {inst['filename']}")
  281. instance = instantiateVariableFont(vf, inst["axes"])
  282. update_attribs(instance, **inst["attribs"])
  283. update_names(instance, **inst["names"])
  284. del instance['STAT']
  285. out_path = os.path.join(sys.argv[2], inst["filename"])
  286. instance.save(out_path)