ttx.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import pathlib
  2. import log
  3. import shutil
  4. import files
  5. from format import formats
  6. def createFont(formatData, outPath, tempPath, filename, flags, font):
  7. """
  8. Calls the functions that assemble and create a font via forc's TTX compiler method.
  9. """
  10. # VARIABLES
  11. # ------------------------------------------------------
  12. extension = formatData["extension"]
  13. imageFormat = formatData["imageFormat"]
  14. formatName = formatData["name"]
  15. originalTTXPath = tempPath / (filename + "_dev.ttx")
  16. afterExportTTX = tempPath / (filename + ".ttx")
  17. outFontPath = tempPath / (filename + extension)
  18. # COMPILER
  19. # ------------------------------------------------------
  20. log.out(f"[ttx compiler]", 90)
  21. # save TTX
  22. log.out(f"- Saving forc's assembled (initial) TTX to file...", 90)
  23. files.writeFile(originalTTXPath, font.toTTX(asString=True), 'Could not write initial TTX to file')
  24. # --dev-ttx flag
  25. if flags["dev_ttx_output"]:
  26. shutil.copy(str(originalTTXPath), str(outPath / (filename + "_dev.ttx")))
  27. log.out(f'- Compiling font...', 90)
  28. files.compileTTX(originalTTXPath, outFontPath)
  29. # TESTING
  30. # ------------------------------------------------------
  31. # We use TTX again because TTX actually doesn't catch all font errors on the first pass.
  32. if not flags['no_test'] and flags["ttx_output"]:
  33. log.out(f'- Testing font by compiling it back to TTX...', 90)
  34. files.compileTTX(outFontPath, afterExportTTX)
  35. # -ttx flag
  36. shutil.copy(str(afterExportTTX), str(outPath / (filename + ".ttx")))
  37. elif not flags['no_test']:
  38. log.out(f'- Testing font by compiling it back to TTX...', 90)
  39. files.compileTTX(outFontPath, afterExportTTX)
  40. return outFontPath