build-v2.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # Copyright 2015 Google Inc. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import sys
  16. from fontTools.misc.transform import Transform
  17. from robofab.objects.objectsRF import RPoint
  18. from fontbuild.Build import FontProject
  19. from fontbuild.italics import condenseGlyph
  20. from fontbuild.italics import transformFLGlyphMembers
  21. from fontbuild.mix import Master
  22. from fontbuild.mix import Mix
  23. # The root of the Roboto tree
  24. BASEDIR = os.path.abspath(
  25. os.path.join(os.path.dirname(__file__), os.pardir))
  26. # Masters
  27. rg = Master("%s/src/v2/Roboto-Regular.ufo" % BASEDIR)
  28. bd = Master("%s/src/v2/Roboto-Bold.ufo" % BASEDIR)
  29. th = Master("%s/src/v2/Roboto-Thin.ufo" % BASEDIR)
  30. lessCondensed = (
  31. "plusminus bracketleft bracketright dieresis macron "
  32. "percent multiply degree at i j "
  33. "zero one two three four five six seven eight nine "
  34. "braceright braceleft").split()
  35. uncondensed = (
  36. "tonos breve acute grave quotesingle quotedbl asterisk "
  37. "period currency registered copyright bullet ring degree "
  38. "dieresis comma bar brokenbar dotaccent dotbelow "
  39. "colon semicolon uniFFFC uniFFFD uni0488 uni0489 ringbelow "
  40. "estimated").split()
  41. moreCondensed = "z Z M W A V".split()
  42. def condenseFont(font, scale=.8, stemWidth=185):
  43. f = font.copy()
  44. xscale = scale
  45. CAPS = ("A B C.cn D.cn E F G.cn H I J K L M N O.cn P Q.cn R S T U.cn V W X "
  46. "Y Z one two three four five six seven eight nine zero").split()
  47. LC = ("a.cn b.cn c.cn d.cn e.cn f g.cn h i j k l m n o.cn p.cn q.cn r s t "
  48. "u v w x y z").split()
  49. # for g in [f[name] for name in LC]:
  50. for g in f:
  51. if len(g) > 0:
  52. if g.name in lessCondensed:
  53. scale = xscale * 1.1
  54. if g.name in uncondensed:
  55. continue
  56. if g.name in moreCondensed:
  57. scale = xscale * .90
  58. # g2 = condenseGlyph(g, xscale)
  59. # g.clear()
  60. # g2.drawPoints(g.getPointPen())
  61. m = Transform(xscale, 0, 0, 1, 20, 0)
  62. g.transform(m)
  63. transformFLGlyphMembers(g, m, transformAnchors=False)
  64. if g.width != 0:
  65. g.width += 40
  66. return f
  67. proj = FontProject(rg.font, BASEDIR, "res/roboto.cfg")
  68. FAMILYNAME = "Roboto"
  69. proj.buildOTF = True
  70. #proj.compatible = True
  71. proj.generateFont(th.font, "%s/Thin/Regular/Th" % FAMILYNAME)
  72. proj.generateFont(Mix([th, rg], 0.45), "%s/Light/Regular/Lt" % FAMILYNAME)
  73. proj.generateFont(Mix([th, rg], RPoint(0.90, 0.92)),
  74. "%s/Regular/Regular/Rg" % FAMILYNAME)
  75. proj.generateFont(Mix([rg, bd], 0.35), "%s/Medium/Regular/Lt" % FAMILYNAME)
  76. proj.generateFont(Mix([rg, bd], RPoint(0.73, 0.73)),
  77. "%s/Bold/Bold/Rg" % FAMILYNAME)
  78. proj.generateFont(Mix([rg, bd], RPoint(1.125, 1.0)),
  79. "%s/Black/Regular/Bk" % FAMILYNAME)
  80. proj.generateFont(th.font, "%s/Thin Italic/Italic/Th" % FAMILYNAME,
  81. italic=True, stemWidth=80)
  82. proj.generateFont(Mix([th, rg], 0.45), "%s/Light Italic/Italic/Lt" % FAMILYNAME,
  83. italic=True, stemWidth=120)
  84. proj.generateFont(Mix([th, rg], RPoint(0.90, 0.92)),
  85. "%s/Italic/Italic/Rg" % FAMILYNAME,
  86. italic=True, stemWidth=185)
  87. proj.generateFont(Mix([rg, bd], 0.35),
  88. "%s/Medium Italic/Italic/Lt" % FAMILYNAME,
  89. italic=True, stemWidth=230)
  90. proj.generateFont(Mix([rg, bd], RPoint(0.73, 0.73)),
  91. "%s/Bold Italic/Bold Italic/Rg" % FAMILYNAME,
  92. italic=True, stemWidth=290)
  93. proj.generateFont(Mix([rg, bd], RPoint(1.125, 1.0)),
  94. "%s/Black Italic/Italic/Bk" % FAMILYNAME,
  95. italic=True, stemWidth=290)
  96. # unfortunately some condensed forms (*.cn) of glyphs are not compatible with
  97. # their original forms, so we can't convert all fonts together compatibly
  98. proj.generateTTFs()
  99. thcn1 = Master(condenseFont(th.font, .84, 40))
  100. cn1 = Master(rg.ffont.addDiff(thcn1.ffont, th.ffont))
  101. bdcn1 = Master(bd.ffont.addDiff(thcn1.ffont, th.ffont))
  102. proj.generateFont(Mix([thcn1, cn1], RPoint(0.45, 0.47)),
  103. "%s Condensed/Light/Regular/Lt" % FAMILYNAME,
  104. swapSuffixes=[".cn"])
  105. proj.generateFont(Mix([thcn1, cn1], RPoint(0.9, 0.92)),
  106. "%s Condensed/Regular/Regular/Rg" % FAMILYNAME,
  107. swapSuffixes=[".cn"])
  108. proj.generateFont(Mix([cn1, bdcn1], 0.4),
  109. "%s Condensed/Medium/Regular/Lt"%FAMILYNAME,
  110. swapSuffixes=[".cn"])
  111. proj.generateFont(Mix([cn1, bdcn1], RPoint(0.75, 0.75)),
  112. "%s Condensed/Bold/Bold/Rg" % FAMILYNAME,
  113. swapSuffixes=[".cn"])
  114. proj.generateFont(Mix([thcn1, cn1], RPoint(0.45, 0.47)),
  115. "%s Condensed/Light Italic/Italic/Lt" % FAMILYNAME,
  116. italic=True, swapSuffixes=[".cn"], stemWidth=120)
  117. proj.generateFont(Mix([thcn1, cn1], RPoint(0.9, 0.92)),
  118. "%s Condensed/Italic/Italic/Rg" % FAMILYNAME,
  119. italic=True, swapSuffixes=[".cn"], stemWidth=185)
  120. proj.generateFont(Mix([cn1, bdcn1], 0.4),
  121. "%s Condensed/Medium Italic/Italic/Lt"%FAMILYNAME,
  122. italic=True, swapSuffixes=[".cn"], stemWidth=230)
  123. proj.generateFont(Mix([cn1, bdcn1], RPoint(0.75, 0.75)),
  124. "%s Condensed/Bold Italic/Bold Italic/Rg" % FAMILYNAME,
  125. italic=True, swapSuffixes=[".cn"], stemWidth=240)
  126. proj.generateTTFs()