start.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import pathlib
  2. import log
  3. import files
  4. from create import createFont
  5. from manifest.manifest import checkTransformManifest
  6. from validate.aliases import validateAliases
  7. from glyphProc import getGlyphs
  8. from format import formats, compilers
  9. # start.py
  10. # -------------------------------
  11. #
  12. # All of the data gathering and validation required before initiating font export.
  13. # Also initiates font export when all of these things are completed and satisfactory.
  14. def start( inputPath
  15. , outputPath
  16. , manifestPath
  17. , aliasesPath
  18. , delim_codepoint
  19. , outputFormats
  20. , compiler
  21. , flags
  22. ):
  23. """
  24. Performs a variety of initial data gathering and validation tasks,
  25. designed to make sure all of the user-given data is valid and usable.
  26. Once this has all been validated, it starts the font making process.
  27. """
  28. log.out(f'\nFetching resources...', 35)
  29. log.out("----------------------------------", 90)
  30. # check folder stuff
  31. # ------------------------------------------------
  32. log.out(f'Checking file + folder locations...')
  33. inputPathPath = pathlib.Path(inputPath).absolute()
  34. files.tryUserDirectory(inputPathPath, "dir", "input folder")
  35. outputPathPath = pathlib.Path(outputPath).absolute()
  36. files.tryUserDirectory(outputPathPath, "dir", "output folder", tryMakeFolder=True)
  37. manifestPathPath = pathlib.Path(manifestPath).absolute()
  38. files.tryUserDirectory(manifestPathPath, "file", "manifest file")
  39. if aliasesPath:
  40. aliasesPathPath = pathlib.Path(aliasesPath).absolute()
  41. files.tryUserDirectory(aliasesPathPath, "file", "aliases file")
  42. log.out(f'File + folder locations OK!\n', 32)
  43. # determine what image formats need to be used
  44. # (also check if the output formats are valid)
  45. # ------------------------------------------------
  46. glyphImageFormats = set()
  47. log.out(f'Checking output parameters...')
  48. for f in outputFormats:
  49. # check if it's in the list of accepted formats
  50. if f not in formats:
  51. raise ValueError(f"'{f}' isn't a valid output format!")
  52. # check what formats are needed
  53. if formats[f]["imageFormat"] == 'svg':
  54. glyphImageFormats.add('svg')
  55. elif formats[f]["imageFormat"] == 'png':
  56. glyphImageFormats.add('png')
  57. log.out(f'Output format(s) OK!\n', 32)
  58. # check compiler
  59. # ------------------------------------------------
  60. if compiler not in compilers:
  61. raise ValueError(f"You gave '{compiler}' as the compiler to use. This doesn't exist in forc. Check the help menu (-h) to see which compilers you can use.")
  62. # manifest
  63. # ------------------------------------------------
  64. log.out(f'Getting + checking manifest data...')
  65. manifest = files.loadJson(manifestPath, "manifest file")
  66. checkTransformManifest(outputFormats, manifest)
  67. log.out(f'Manifest OK!.\n', 32)
  68. # aliases (file)
  69. # ------------------------------------------------
  70. if aliasesPath:
  71. log.out(f'Getting + checking aliases data...')
  72. aliases = files.loadJson(aliasesPath, "aliases file")
  73. validateAliases(aliases)
  74. log.out(f'Aliases OK!.\n', 32)
  75. else:
  76. aliases = None
  77. # glyphs
  78. # ------------------------------------------------
  79. log.out(f'Getting + checking glyphs...')
  80. glyphs = getGlyphs(inputPathPath, manifest, aliases, delim_codepoint, glyphImageFormats, flags)
  81. log.out(f'Glyphs OK!\n', 32)
  82. log.out(f'All resources OK!', 32)
  83. # assemble each font format.
  84. # ------------------------------------------------
  85. log.out(f'Starting font compilation...\n\n', 35)
  86. for f in outputFormats:
  87. createFont(f, outputPath, manifest, glyphs, compiler, flags)