forc.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #!/usr/bin/env python3
  2. import getopt
  3. import os
  4. import sys
  5. from io import StringIO
  6. import log
  7. from start import start
  8. VERSION = '0.0.2'
  9. DEF_INPUT_PATH = 'in'
  10. DEF_OUTPUT_PATH = 'out'
  11. DEF_MANIFEST = 'manifest.json'
  12. DEF_ALIASES = None
  13. DEF_DELIM_CODEPOINT = "-"
  14. DEF_OUTPUT_FORMATS = ['SVGinOT']
  15. DEF_COMPILER = 'ttx'
  16. DEF_NO_VS16 = False
  17. DEF_NO_LIG = False
  18. DEF_NUSC = False
  19. DEF_AFSC = False
  20. DEF_NO_TEST = False
  21. DEF_TTX_OUTPUT = False
  22. DEF_DEV_TTX = False
  23. HELP = f'''forc {VERSION}
  24. by Mutant Standard
  25. (mutant.tech)
  26. USAGE: forc.py [options...]
  27. HELP:
  28. ----------------------------------------------------
  29. -h Prints this help message.
  30. Also look at /docs for full documentation.
  31. WHAT TO BUILD FROM:
  32. ----------------------------------------------------
  33. -i Image glyphs directory (default: {DEF_INPUT_PATH})
  34. -a Alias glyphs file (optional)
  35. -m Manifest file (default: {DEF_MANIFEST})
  36. -o Output directory (default: {DEF_OUTPUT_PATH})
  37. -d Delimiter between ligatured codepoints
  38. (default: '{DEF_DELIM_CODEPOINT}')
  39. HOW TO BUILD IT:
  40. ----------------------------------------------------
  41. -F Format (default: {DEF_OUTPUT_FORMATS[0]})
  42. comma separated with no spaces (ie. 'SVGinOT,CBx,sbixOT')
  43. Formats that require SVG images:
  44. - SVGinOT (Many platforms)
  45. Formats that require PNG images:
  46. - sbixOT
  47. - sbixOTiOS (DEVELOPMENT/TESTING)
  48. - CBx (Google/Android)
  49. -C Compiler (default: {DEF_COMPILER})
  50. - ttx
  51. - forc (*will* give broken results atm)
  52. OPTIONAL EXTRA FLAGS:
  53. ----------------------------------------------------
  54. FOR CODEPOINTS
  55. --no-vs16 Strips any presence of VS16 (U+fe0f) from the output.
  56. --no-lig (DEVELOPMENT OPTION) Strips ligatures from the output.
  57. FOR SVGs
  58. --nusc No Unenforced SVG Contents Checking.
  59. Makes SVG checking less strict by allowing SVG contents
  60. that are not guaranteed to work in SVG checks.
  61. --afsc Affinity SVG Correction.
  62. Corrects quirks in SVGs images exported by Serif's
  63. Affinity software. Always use this if you are making
  64. a font with SVGs that come from Affinity software.
  65. FOR ALL COMPILERS
  66. --no-test (DEVELOPMENT OPTION) Disables the font validation phase of
  67. font compilation.
  68. FOR TTX COMPILER
  69. Will be ignored if you are using a different compiler.
  70. --ttx Exports a matching ttx (.ttx) file for each format.
  71. --dev-ttx (DEVELOPMENT OPTION) Keeps the initial ttx that forc
  72. compiles before passing it to fonttools. This is
  73. different to the above, which is a full representation
  74. of the font file.
  75. '''
  76. def main():
  77. input_path = DEF_INPUT_PATH
  78. output_path = DEF_OUTPUT_PATH
  79. manifest_path = DEF_MANIFEST
  80. aliases_path = DEF_ALIASES
  81. delim_codepoint = DEF_DELIM_CODEPOINT
  82. output_formats = DEF_OUTPUT_FORMATS
  83. compiler = DEF_COMPILER
  84. no_vs16 = DEF_NO_VS16
  85. no_lig = DEF_NO_LIG
  86. nusc = DEF_NUSC
  87. afsc = DEF_AFSC
  88. no_test = DEF_NO_TEST
  89. ttx_output = DEF_TTX_OUTPUT
  90. dev_ttx_output = DEF_DEV_TTX
  91. try:
  92. opts, _ = getopt.getopt(sys.argv[1:],
  93. 'hi:o:m:a:d:F:C:',
  94. ['help', 'no-vs16', 'no-lig', 'nusc', 'afsc', 'no-test', 'ttx', 'dev-ttx'])
  95. for opt, arg in opts:
  96. if opt in ['-h', '--help']:
  97. print(HELP)
  98. sys.exit()
  99. elif opt == '-i':
  100. input_path = arg
  101. elif opt == '-o':
  102. output_path = arg
  103. elif opt == '-m':
  104. manifest_path = arg
  105. elif opt == '-a':
  106. aliases_path = arg
  107. elif opt =='-d':
  108. delim_codepoint = arg
  109. elif opt == '-F':
  110. output_formats = arg.split(',')
  111. elif opt == '-C':
  112. compiler = arg
  113. elif opt =='--no-vs16':
  114. no_vs16 = True
  115. elif opt =='--no-lig':
  116. no_lig = True
  117. elif opt =='--nusc':
  118. nusc = True
  119. elif opt =='--afsc':
  120. afsc = True
  121. elif opt =='--no-test':
  122. no_test = True
  123. elif opt =='--ttx':
  124. ttx_output = True
  125. elif opt =='--dev-ttx':
  126. dev_ttx_output = True
  127. except Exception:
  128. print(HELP)
  129. sys.exit(2)
  130. try:
  131. flags = { "no_vs16": no_vs16
  132. , "no_lig": no_lig
  133. , "nusc": nusc
  134. , "afsc": afsc
  135. , "no_test": no_test
  136. , "ttx_output": ttx_output
  137. , "dev_ttx_output": dev_ttx_output
  138. }
  139. start( input_path
  140. , output_path
  141. , manifest_path
  142. , aliases_path
  143. , delim_codepoint
  144. , output_formats
  145. , compiler
  146. , flags
  147. )
  148. except Exception as e:
  149. log.out(f'\n!!! {e}', 31)
  150. raise e ######################## TEMP
  151. sys.exit(1)
  152. log.out('All done!', 35)
  153. if __name__ == '__main__':
  154. main()