upgrade to 2.14.2
[platform/upstream/fontconfig.git] / conf.d / write-35-lang-normalize-conf.py
1 #!/usr/bin/env python3
2 #
3 # fontconfig write-35-lang-normalize-conf.py
4
5 import os
6 import sys
7
8 if len(sys.argv) < 2:
9   print('ERROR: usage: {} ORTH_LIST [OUTPUT.CONF]'.format(sys.argv[0]))
10   sys.exit(-1)
11
12 orth_list_unsorted = sys.argv[1].split(',')
13
14 if len(sys.argv) > 2 and sys.argv[2] != '-':
15   f_out = open(sys.argv[2], 'w', encoding='utf8')
16 else:
17   f_out = sys.stdout
18
19 orth_list = sorted(sys.argv[1].split(','))
20
21 print('<?xml version="1.0"?>', file=f_out)
22 print('<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">', file=f_out)
23 print('<fontconfig>', file=f_out)
24
25 for o in orth_list:
26   print(f'  <!-- {o}* -> {o} -->', file=f_out)
27   print(f'  <match>', file=f_out)
28   print(f'    <test name="lang" compare="contains"><string>{o}</string></test>', file=f_out)
29   print(f'    <edit name="lang" mode="assign" binding="same"><string>{o}</string></edit>', file=f_out)
30   print(f'  </match>', file=f_out)
31
32 print('</fontconfig>', file=f_out)
33
34 f_out.close()
35
36 sys.exit(0)