create.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import subprocess
  2. import pathlib
  3. import log
  4. import shutil
  5. import files
  6. from font import TTFont
  7. import compile.ttx
  8. import compile.forc
  9. import compile.ios.create
  10. from format import formats
  11. def createFont(fontFormat, outputPath, manifest, glyphs, compiler, flags):
  12. log.out(f'{fontFormat}', 96)
  13. log.out("-----------------", 90)
  14. # prepare some variables
  15. # --------------------------------------------------------------
  16. # output folder
  17. outPath = pathlib.Path(outputPath).absolute()
  18. tempPath = outPath / '.forc_tmp'
  19. files.tryDirectory(tempPath, "dir", "temporary font build folder", tryMakeFolder=True)
  20. # filenames
  21. # the user setting custom filenames in the manifest is optional.
  22. # If none are given, just use the font format as the base filename.
  23. if "filenames" in manifest["metadata"]:
  24. filename = manifest['metadata']['filenames'][fontFormat]
  25. else:
  26. filename = fontFormat
  27. # format information
  28. formatData = formats[fontFormat]
  29. # create the font!
  30. # --------------------------------------------------------------
  31. log.out(f'🛠 Assembling font...')
  32. emojiFont = TTFont(formatData["name"], manifest, glyphs, flags)
  33. log.out(f'🛠 Performing internal tests...')
  34. emojiFont.test()
  35. log.out(f'✅ Font successfully assembled.\n', 32)
  36. # pass it to compilers and packagers
  37. # --------------------------------------------------------------
  38. log.out(f"⚙️ Compiling and externally testing font...")
  39. if compiler == 'ttx':
  40. tempFontPath = compile.ttx.createFont(formatData, outPath, tempPath, filename, flags, emojiFont)
  41. elif compiler == 'forc':
  42. tempFontPath = compile.forc.createFont(formatData, outPath, tempPath, filename, flags, emojiFont)
  43. else:
  44. raise ValueError("Something went wrong with the build process. I'm not able to run the font data through a compiler.")
  45. log.out(f'✅ Compiling and testing OK.\n', 32)
  46. if formats[fontFormat]["iOSCompile"]:
  47. log.out(f"⚙️ Packaging font...")
  48. compile.ios.create.createPackage(formatData, filename, outPath, tempFontPath, manifest)
  49. log.out(f'✅ Packaging OK.\n', 32)
  50. else:
  51. shutil.copy(str(tempFontPath), str(outPath / (filename + formatData["extension"])))
  52. # finish!
  53. # --------------------------------------------------------------
  54. # delete the temporary folder (recursively)
  55. log.out(f'🗑 Cleaning up...')
  56. shutil.rmtree(tempPath)
  57. log.out(f'✅ Format finished!\n\n', 32)