Now uses the external libopenui

This commit is contained in:
Bertrand Songis
2019-10-02 14:41:52 +02:00
parent 5b568cd40c
commit 3e2cb83991
250 changed files with 76326 additions and 11869 deletions
-95
View File
@@ -1,95 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
import glob
from PIL import Image, ImageDraw, ImageFont
chars_en = u""" !"#$%&'()*+,-./0123456789:;<=>?°ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~|≥"""
chars_fr = u"""éèàîç"""
chars_de = u"""ÄäÖöÜüß"""
chars_cz = u"""ěščřžýáíéňóůúďťĚŠČŘŽÝÁÍÉŇÓÚŮĎŤ"""
chars_es = u"""Ññ"""
chars_fi = u"""åäöÅÄÖ"""
chars_it = u"""àù"""
chars_pl = u"""ąćęłńóśżźĄĆĘŁŃÓŚŻŹ"""
chars_pt = u"""ÁáÂâÃãÀàÇçÉéÊêÍíÓóÔôÕõÚú"""
COUNT_EXTRA_CHARS = 21
chars_extra = u"".join([chr(1+i) for i in range(COUNT_EXTRA_CHARS)])
chars = chars_en + chars_extra + chars_fr + chars_de + chars_cz + chars_es + chars_fi + chars_it + chars_pl
def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, background, coordsfile=True):
coords = [fontsize + 4]
font_filename = 'fonts/' + fontname + '.ttf'
print("Font filename: %s" % font_filename)
font = ImageFont.truetype(font_filename, fontsize)
extraImage = None
extraFilename = 'fonts/extra_%dpx.png' % fontsize
try:
extraImage = Image.open(extraFilename)
extraImage = extraImage.convert('RGB')
except IOError:
print("Missing extra symbol filename %s" % extraFilename)
def getCharWidth(c):
if c in chars_extra:
if extraImage:
# Extra characters 16px
#if fontsize == 16:
if ord(c) <= 9:
return 13
else:
return 15
else:
return 0
elif c == " ":
return 4
else:
w, h = font.getsize(c)
return w + 1
def getFontWidth():
width = 0
for c in chars:
width += getCharWidth(c)
return width
width = getFontWidth()
image = Image.new('RGB', (width, fontsize + 4), background)
print(fontsize + 4)
draw = ImageDraw.Draw(image)
width = 0
for c in chars:
coords.append(width)
if c in chars_extra:
if extraImage and c == chars_extra[0]:
image.paste(extraImage.copy(), (width, fontsize % 2))
elif c == " ":
pass
else:
w, h = font.getsize(c)
draw.text((width + 1, fontoffset), c, fill=foreground, font=font)
width += getCharWidth(c)
coords.append(width)
image.save(filename + ".png")
if coordsfile:
with open(filename + ".specs", "w") as f:
f.write(",".join(str(tmp) for tmp in coords))
if __name__ == "__main__":
createFontBitmap(sys.argv[4], sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), (0, 0, 0), (255, 255, 255))
-193
View File
@@ -1,193 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Imports
import argparse
import codecs
import sys
translations = {'cz_reduced': [('\\200', u'á'),
('\\201', u'č'),
('\\201', u'Č'),
('\\202', u'é'),
('\\203', u'ě'),
('\\203', u'Ě'),
('\\204', u'í'),
('\\205', u'ó'),
('\\206', u'ř'),
('\\207', u'š'),
('\\207', u'Š'),
('\\210', u'ú'),
('\\210', u'Ú'),
('\\211', u'ů'),
('\\211', u'Ů'),
('\\212', u'ý'),
('\\213', u'Á'),
('\\214', u'Í'),
('\\215', u'Ř'),
('\\216', u'Ý'),
('\\217', u'ž'),
('\\217', u'Ž'),
('\\220', u'É')],
'cz': [('\\200', u'ě'),
('\\201', u'š'),
('\\202', u'č'),
('\\203', u'ř'),
('\\204', u'ž'),
('\\205', u'ý'),
('\\206', u'á'),
('\\207', u'í'),
('\\210', u'é'),
('\\211', u'ň'),
('\\212', u'ó'),
('\\213', u'ů'),
('\\214', u'ú'),
('\\215', u'ď'),
('\\216', u'ť'),
('\\217', u'Ě'),
('\\220', u'Š'),
('\\221', u'Č'),
('\\222', u'Ř'),
('\\223', u'Ž'),
('\\224', u'Ý'),
('\\225', u'Á'),
('\\226', u'Í'),
('\\227', u'É'),
('\\230', u'Ň'),
('\\231', u'Ó'),
('\\232', u'Ú'),
('\\233', u'Ů'),
('\\234', u'Ď'),
('\\235', u'Ť')],
'de': [('\\200', u'Ä'),
('\\201', u'ä'),
('\\202', u'Ö'),
('\\203', u'ö'),
('\\204', u'Ü'),
('\\205', u'ü'),
('\\206', u'ß')],
'es': [('\\200', u'Ñ'),
('\\201', u'ñ')],
'fi': [('\\200', u'å'),
('\\201', u'ä'),
('\\202', u'ö'),
('\\203', u'Å'),
('\\204', u'Ä'),
('\\205', u'Ö')],
'fr': [('\\200', u'é'),
('\\201', u'è'),
('\\202', u'à'),
('\\203', u'î'),
('\\204', u'ç')],
'it': [('\\200', u'à'),
('\\201', u'ù')],
'pl': [('\\200', u'ą'),
('\\201', u'ć'),
('\\202', u'ę'),
('\\203', u'ł'),
('\\204', u'ń'),
('\\205', u'ó'),
('\\206', u'ś'),
('\\207', u'ż'),
('\\210', u'ź'),
('\\211', u'Ą'),
('\\212', u'Ć'),
('\\213', u'Ę'),
('\\214', u'Ł'),
('\\215', u'Ń'),
('\\216', u'Ó'),
('\\217', u'Ś'),
('\\220', u'Ż'),
('\\221', u'Ź')],
'pt': [('\\200', u'Á'),
('\\201', u'á'),
('\\202', u'Â'),
('\\203', u'â'),
('\\204', u'Ã'),
('\\205', u'ã'),
('\\206', u'À'),
('\\207', u'à'),
('\\210', u'Ç'),
('\\211', u'ç'),
('\\212', u'É'),
('\\213', u'é'),
('\\214', u'Ê'),
('\\215', u'ê'),
('\\216', u'Í'),
('\\217', u'í'),
('\\218', u'Ó'),
('\\219', u'ó'),
('\\220', u'Ô'),
('\\221', u'ô'),
('\\222', u'Õ'),
('\\223', u'õ'),
('\\224', u'Ú'),
('\\225', u'ú'), ],
'se': [('\\200', u'å'),
('\\201', u'ä'),
('\\202', u'ö'),
('\\203', u'Å'),
('\\204', u'Ä'),
('\\205', u'Ö')],
'en': [],
'nl': [],
'all': [('\\306', u'Δ'),
('\\173', u'~'),
('\\036', u'\\n'),
('\\035', u'\\t')],
}
# Take care of command line options
parser = argparse.ArgumentParser(description='Encoder for open9x translations')
parser.add_argument('input', action="store", help="Input file name")
parser.add_argument('output', action="store", help="Output file name")
parser.add_argument('language', action="store", help="Two letter language identifier")
parser.add_argument("--reverse", help="Reversed char conversion (from number to char)", action="store_true")
args = parser.parse_args()
if args.language not in translations:
parser.error(args.language + ' is not a supported language. Try one of the supported ones: ' + str(list(translations.keys())))
sys.exit()
if args.reverse:
for translation in translations:
translations[translation] = [(after, before) for (before, after) in translations[translation]]
# Read the input file into a buffer
in_file = codecs.open(args.input, "r", "utf-8")
# Write the result to a temporary file
out_file = codecs.open(args.output, 'w', 'utf-8')
for line in in_file.readlines():
# Do the special chars replacements
for after, before in translations[args.language] + translations["all"]:
line = line.replace(before, after)
if line.startswith("#define ZSTR_"):
before = line[32:-2]
after = ""
for c in before:
if ord(c) >= ord('A') and ord(c) <= ord('Z'):
c = "\\%03o" % (ord(c) - ord('A') + 1)
elif ord(c) >= ord('a') and ord(c) <= ord('z'):
c = "\\%03o" % (-ord(c) + ord('a') + 255)
elif ord(c) >= ord('0') and ord(c) <= ord('9'):
c = "\\%03o" % (ord(c) - ord('0') + 27)
after = after + c
line = line[:32] + after + line[-2:]
out_file.write(line)
out_file.close()
in_file.close()