You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import os
  5. import time
  6. from reportlab.lib.units import mm, cm, inch, pica
  7. from reportlab.lib.pagesizes import A4, A5, LETTER, LEGAL
  8. from reportlab.pdfbase import pdfmetrics
  9. from reportlab.pdfbase.ttfonts import TTFont
  10. from chordsheet.common import scriptDir
  11. from chordsheet.document import Document, Style, Chord, Block, Section
  12. from chordsheet.render import Renderer
  13. from chordsheet.parsers import parseFingering, parseName
  14. import _version
  15. pdfmetrics.registerFont(
  16. TTFont('FreeSans', os.path.join(scriptDir, 'fonts', 'FreeSans.ttf')))
  17. if sys.platform == "darwin":
  18. pdfmetrics.registerFont(
  19. TTFont('HelveticaNeue', 'HelveticaNeue.ttc', subfontIndex=0))
  20. if len(sys.argv) == 2:
  21. inputFilePath = sys.argv[1]
  22. else:
  23. print("Please provide a .cml, .xml, or .cma file to process.")
  24. sys.exit()
  25. doc = Document()
  26. if inputFilePath[-4:] == ".cma":
  27. doc.loadCSMacro(inputFilePath)
  28. else:
  29. doc.loadXML(inputFilePath)
  30. style = Style()
  31. renderer = Renderer(doc, style)
  32. outputFilePath = ".".join(inputFilePath.split(".")[:-1]) + ".pdf"
  33. renderer.savePDF(outputFilePath)