PageRenderTime 25ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/fanwood/Fanwood-Italic_build.py

https://github.com/chemoelectric/sortsmill
Python | 261 lines | 255 code | 1 blank | 5 comment | 0 complexity | d816ed597e07cebd7dfb6b08f273e613 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. """
  3. Copyright (c) 2010 Barry Schwartz
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. """
  20. import fontforge
  21. import string
  22. from sortsmill import font_db
  23. from sortsmill.glyphbuild import *
  24. from sortsmill.spacing_by_anchors import *
  25. emsize = 1000
  26. spacesize = 200
  27. def build_glyphs(bitbucket, f):
  28. from sortsmill import cap_spacing
  29. figures = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
  30. def base(letter):
  31. if letter == 'i':
  32. base = 'dotlessi'
  33. elif letter == 'j':
  34. base = 'uni0237'
  35. else:
  36. base = letter
  37. return base
  38. db = font_db.db_create(f)
  39. db['spacing_anchor_heights'] = {
  40. 'hi' : 650, # caps and ascenders,
  41. 'x' : 380, # ex-height
  42. 'o' : 200, # like the letter o
  43. 'bl' : 10, # baseline
  44. 'lo' : -260, # descenders
  45. }
  46. all_glyphs = set(f) - set(['.notdef'])
  47. proportional_figures = ['zero.p', 'one.p', 'two.p', 'three.p', 'four.p', 'five.p', 'six.p', 'seven.p', 'eight.p', 'nine.p']
  48. (uppercase, lowercase, fraction_bar, numerators, denominators, remaining) = \
  49. tuple(separate_strings(all_glyphs, [
  50. (lambda s: is_uppercase(s, last_name)),
  51. (lambda s: is_lowercase(s, last_name) or s in proportional_figures),
  52. (lambda s: s == 'fraction'),
  53. (lambda s: s[-6:] == '.numer'),
  54. (lambda s: s[-6:] == '.denom'),
  55. ]))
  56. db["kerning_sets"] = [
  57. (remaining, uppercase | lowercase | remaining),
  58. (uppercase, uppercase | lowercase | remaining),
  59. (lowercase, uppercase | lowercase | remaining),
  60. (numerators, fraction_bar),
  61. (fraction_bar, denominators),
  62. ]
  63. build_several_space_glyphs(f, emsize = emsize, spacesize = spacesize,
  64. thinspacesize = emsize / 6,
  65. hairspacesize = emsize / 10,
  66. tabwidth = f['zero'].width)
  67. propagate_hyphens(f)
  68. propagate_hyphens(f, '.u')
  69. build_spacing_marks(f, width = 2 * 200)
  70. make_glyph_reference('minute', f['quotesingle'])
  71. make_glyph_reference('second', f['quotedbl'])
  72. make_glyph_reference('asciitilde', f['uni2053']) # Swung dash.
  73. make_glyph_reference('i.TRK', f['i'])
  74. make_glyph_reference('L.CAT', f['L'])
  75. make_glyph_reference('l.CAT', f['l'])
  76. make_glyph_reference('Dcroat', f['Eth'])
  77. build_multigraph('ellipsis', [f['period'], f['period'], f['period']])
  78. for extension in [('.numer', 250), ('.sub', -150), ('.sup', 350)]:
  79. for fig in figures + ['comma', 'period', 'hyphen',
  80. 'parenleft', 'parenright',
  81. 'bracketleft', 'bracketright',
  82. 'dollar', 'cent',
  83. ] + [string.ascii_lowercase[i] for i in range(0, 26)]:
  84. make_glyph_reference(fig + extension[0],
  85. f[fig + '.denom'],
  86. transformation = (1, 0, 0, 1, 0, extension[1]),
  87. copy_spacing_anchors = (extension[0] == '.numer'))
  88. make_glyph_reference('uni00B9', f['one.sup'])
  89. make_glyph_reference('uni00B2', f['two.sup'])
  90. make_glyph_reference('uni00B3', f['three.sup'])
  91. make_glyph_reference('ordfeminine', f['a.sup'])
  92. make_glyph_reference('ordmasculine', f['o.sup'])
  93. build_multigraph('onequarter', [f['one.numer'], f['fraction'], f['four.denom']], copy_spacing_anchors = False)
  94. build_multigraph('onehalf', [f['one.numer'], f['fraction'], f['two.denom']], copy_spacing_anchors = False)
  95. build_multigraph('threequarters', [f['three.numer'], f['fraction'], f['four.denom']], copy_spacing_anchors = False)
  96. #--------------------------------------------------------------------------
  97. for letter in 'GKkLlNnRr':
  98. build_accented_glyph(letter + 'commaaccent', f[base(letter)], f['uni0326'])
  99. build_accented_glyph('uni0218', f['S'], f['uni0326'])
  100. build_accented_glyph('uni0219', f['s'], f['uni0326'])
  101. build_accented_glyph('uni021A', f['T'], f['uni0326'])
  102. build_accented_glyph('uni021B', f['t'], f['uni0326'])
  103. build_accented_glyph('gcommaaccent', f['g'], f['uni0312'])
  104. #--------------------------------------------------------------------------
  105. for letter in 'CcSs':
  106. build_accented_glyph(letter + 'cedilla', f[base(letter)], f['uni0327'])
  107. remove_overlap(f[letter + 'cedilla'])
  108. build_accented_glyph('uni0162', f['T'], f['uni0327'])
  109. remove_overlap(f['uni0162'])
  110. build_accented_glyph('uni0163', f['t'], f['uni0327'])
  111. remove_overlap(f['uni0163'])
  112. #--------------------------------------------------------------------------
  113. for letter in 'aeiou':
  114. build_accented_glyph(letter + 'grave', f[base(letter)], f['gravecomb'])
  115. for letter in 'AEIOU':
  116. build_accented_glyph(letter + 'grave', f[base(letter)], f['gravecomb.cap'])
  117. #--------------------------------------------------------------------------
  118. for letter in 'aceinorsuyz':
  119. build_accented_glyph(letter + 'acute', f[base(letter)], f['acutecomb'])
  120. for letter in 'ACEILNORSUYZ':
  121. build_accented_glyph(letter + 'acute', f[base(letter)], f['acutecomb.cap'])
  122. build_accented_glyph('lacute', f['l'], f['acutecomb.cap'])
  123. #--------------------------------------------------------------------------
  124. for letter in 'ainou':
  125. build_accented_glyph(letter + 'tilde', f[base(letter)], f['tildecomb'])
  126. for letter in 'AINOU':
  127. build_accented_glyph(letter + 'tilde', f[base(letter)], f['tildecomb.cap'])
  128. #--------------------------------------------------------------------------
  129. for letter in 'aeouy':
  130. build_accented_glyph(letter + 'dieresis', f[base(letter)], f['uni0308'])
  131. for letter in 'AEIOUY':
  132. build_accented_glyph(letter + 'dieresis', f[base(letter)], f['uni0308.cap'])
  133. for letter in 'i':
  134. build_accented_glyph(letter + 'dieresis', f[base(letter)], f['uni0308.narrow'])
  135. #--------------------------------------------------------------------------
  136. for letter in 'au':
  137. build_accented_glyph(letter + 'ring', f[base(letter)], f['uni030A'])
  138. for letter in 'AU':
  139. build_accented_glyph(letter + 'ring', f[base(letter)], f['uni030A.cap'])
  140. #--------------------------------------------------------------------------
  141. for letter in 'acegijosuwy':
  142. build_accented_glyph(letter + 'circumflex', f[base(letter)], f['uni0302'])
  143. for letter in 'ACEGHIJOSUWYh':
  144. build_accented_glyph(letter + 'circumflex', f[base(letter)], f['uni0302.cap'])
  145. # A gift for Esperantists, although 'ffĥ' seems unlikely.
  146. for letter in ['f_h', 'f_f_h']:
  147. build_accented_glyph(letter + 'circumflex', f[base(letter)], f['uni0302.cap'])
  148. #--------------------------------------------------------------------------
  149. for letter in 'aegiou':
  150. build_accented_glyph(letter + 'breve', f[base(letter)], f['uni0306'])
  151. for letter in 'AEGIOU':
  152. build_accented_glyph(letter + 'breve', f[base(letter)], f['uni0306.cap'])
  153. #--------------------------------------------------------------------------
  154. for letter in 'cegz':
  155. build_accented_glyph(letter + 'dotaccent', f[base(letter)], f['uni0307'])
  156. for letter in 'CEGIZ':
  157. build_accented_glyph(letter + 'dotaccent', f[base(letter)], f['uni0307.cap'])
  158. # Extra dot accents for Old Irish.
  159. build_accented_glyph('uni1E02', f['B'], f['uni0307.cap'])
  160. build_accented_glyph('uni1E03', f['b'], f['uni0307.cap'])
  161. build_accented_glyph('uni1E0A', f['D'], f['uni0307.cap'])
  162. build_accented_glyph('uni1E0B', f['d'], f['uni0307.cap'])
  163. build_accented_glyph('uni1E1E', f['F'], f['uni0307.cap'])
  164. build_accented_glyph('uni1E1F', f['f'], f['uni0307.cap'])
  165. build_accented_glyph('uni1E22', f['H'], f['uni0307.cap'])
  166. build_accented_glyph('uni1E23', f['h'], f['uni0307.cap'])
  167. build_accented_glyph('uni1E40', f['M'], f['uni0307.cap'])
  168. build_accented_glyph('uni1E41', f['m'], f['uni0307'])
  169. build_accented_glyph('uni1E56', f['P'], f['uni0307.cap'])
  170. build_accented_glyph('uni1E57', f['p'], f['uni0307'])
  171. build_accented_glyph('uni1E60', f['S'], f['uni0307.cap'])
  172. build_accented_glyph('uni1E61', f['s'], f['uni0307'])
  173. build_accented_glyph('uni1E6A', f['T'], f['uni0307.cap'])
  174. build_accented_glyph('uni1E6B', f['t'], f['uni0307'])
  175. #--------------------------------------------------------------------------
  176. for letter in 'cenrsz':
  177. build_accented_glyph(letter + 'caron', f[base(letter)], f['uni030C'])
  178. for letter in 'CDENRTSZ':
  179. build_accented_glyph(letter + 'caron', f[base(letter)], f['uni030C.cap'])
  180. for letter in 'dLlt':
  181. build_accented_glyph(letter + 'caron', f[base(letter)], f['uni0315'])
  182. #--------------------------------------------------------------------------
  183. for letter in 'aeiou':
  184. build_accented_glyph(letter + 'macron', f[base(letter)], f['uni0304'])
  185. for letter in 'AEIOU':
  186. build_accented_glyph(letter + 'macron', f[base(letter)], f['uni0304.cap'])
  187. #--------------------------------------------------------------------------
  188. for letter in 'ou':
  189. build_accented_glyph(letter + 'hungarumlaut', f[base(letter)], f['uni030B'])
  190. for letter in 'OU':
  191. build_accented_glyph(letter + 'hungarumlaut', f[base(letter)], f['uni030B.cap'])
  192. #--------------------------------------------------------------------------
  193. build_multigraph('napostrophe', [f['quoteright'], f['n']])
  194. build_multigraph('ldot', [f['l'], f['periodcentered']])
  195. build_multigraph('IJ', [f['I'], f['J']])
  196. build_multigraph('ij', [f['i'], f['j']])
  197. #--------------------------------------------------------------------------
  198. f.selection.all()
  199. space_selected_by_anchors(f)
  200. f.selection.none()
  201. generate_kerning_and_read_features(None, f)
  202. #--------------------------------------------------------------------------
  203. font_db.db_close(f)
  204. #--------------------------------------------------------------------------