Debian Codegraph @

texmf-dist/fonts/source/gregoriotex/convertsfdtottf.py

raw
1 # This is a fontforge python script; use fontforge -lang=py -script to run it
2 # coding=utf-8
3 # pylint: disable=import-error
4
5
6 """
7 Python fontforge script to convert from fontforge's native sfd
8 to a TrueType font (ttf).
9
10 Copyright (C) 2015-2025 The Gregorio Project (see CONTRIBUTORS.md)
11
12 This file is part of Gregorio.
13
14 Gregorio is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 Gregorio is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with Gregorio. If not, see <http://www.gnu.org/licenses/>.
26
27 This script takes a .sfd file and converts it to a .ttf file.
28
29 Basic use :
30 fontforge -script convertsfdtottf.py fontfile
31 """
32
33
34 import sys
35 import getopt
36 import fontforge
37
38
39 def usage():
40 "Prints help message."
41 print("""
42 Python script to convert a fontforge native file (.sfd) to a TrueType font
43 (.ttf).
44
45 Usage:
46 fontforge -script convertsfdtottf.py fontfile
47 """)
48
49 def main():
50 "Main function."
51 try:
52 opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help"])
53 except getopt.GetoptError:
54 # print help information and exit:
55 usage()
56 sys.exit(2)
57 outputfile = None
58 for opt, arg in opts:
59 if opt in ("-h", "--help"):
60 usage()
61 sys.exit()
62 if len(args) == 0:
63 usage()
64 sys.exit(2)
65 if args[0][-3:] == "sfd":
66 outputfile = f'{args[0][:-4]}.ttf'
67 inputfile = args[0]
68 else:
69 usage()
70 sys.exit(2)
71 font = fontforge.open(inputfile)
72 font.generate(outputfile)
73 font.close()
74
75 if __name__ == "__main__":
76 main()