xorg-x11-fonts/convertfont.py
Stefan Dirsch f23523ccbf Accepting request 910306 from home:alarrosa:branches:X11:XOrg
- Convert the helv*.otb and cour*.otb files in a different way,
  generating all available font sizes as fonts files named
  *-75-dpi-converted and *-100dpi-converted and having the same
  font name for 75 and 100 dpi converted fonts (fixes boo#1174895).
- As part of the above fix, don't remove the "Regular" suffix from
  the full name of fonts in convertfont.py

OBS-URL: https://build.opensuse.org/request/show/910306
OBS-URL: https://build.opensuse.org/package/show/X11:XOrg/xorg-x11-fonts?expand=0&rev=109
2021-08-05 13:11:40 +00:00

58 lines
1.6 KiB
Python

#!/usr/bin/python3
# This script is licensed under the GPL-3.0-or-later license.
# Automatically group the font files by family names and style names,
# and assume each bitmap font only contains one font face.
# This tool requires ftdump and fonttosfnt.
# Some changes by Hans Ulrich Niedermann and Antonio Larrosa.
import sys
import subprocess
usage = '''
convertfont.py [BITMAPFONTFILE]...
'''
fontnames = dict()
# get font family name and style name by ftdump
def getfullname(fontname):
output = subprocess.check_output(
'ftdump ' + fontname,
shell = True)
output = output.decode('utf8')
# only contain one font face
assert not 'Face number: 1' in output
result = {}
for row in output.split('\n'):
if ':' in row:
key, value = row.split(': ')
result[key.strip()] = value.strip()
familyname, stylename = result['family'], result['style']
return familyname + ' ' + stylename
def generate_fonts():
for fullname, filenames in fontnames.items():
outputfilename = fullname.replace(' ', '-') + '.otb'
argv = 'fonttosfnt -b -c -g 2 -m 2 -o'.split(' ')
argv.append(outputfilename)
argv.extend(filenames)
print(' '.join(argv))
print(subprocess.check_output(argv).decode('utf8'))
if __name__ == '__main__':
for bitmapfontname in sys.argv[1:]:
fullname = getfullname(bitmapfontname)
if fullname in fontnames:
fontnames[fullname].append(bitmapfontname)
else:
fontnames[fullname] = [bitmapfontname]
generate_fonts()