fix chars continued

This commit is contained in:
3djc
2020-12-18 20:37:11 +01:00
parent acdc2343dd
commit 7d2178cb5c
11 changed files with 34 additions and 43 deletions
+8 -7
View File
@@ -9,8 +9,9 @@ from charset import get_chars, special_chars, extra_chars, standard_chars
class FontBitmap:
def __init__(self, chars, font_size, font_name, cjk_font_name, foreground, background):
self.chars = chars
def __init__(self, language, font_size, font_name, cjk_font_name, foreground, background):
self.language = language
self.chars = get_chars(language)
self.font_size = font_size
self.foreground = foreground
self.background = background
@@ -95,11 +96,9 @@ class FontBitmap:
for c in self.chars:
if c == " ":
w = 4
elif c in special_chars["cn"]:
w = self.draw_char(image, width, c, self.cjk_font, -3)
elif c in extra_chars:
if self.extra_bitmap:
for i in range(128 - 32 - len(standard_chars) - 1):
for i in range(128 - 32 - len(standard_chars)):
coords.append(width)
image.paste(self.extra_bitmap.copy(), (width, 0))
for coord in [14, 14, 12, 12, 13, 13, 13, 13, 13] + [15] * 12:
@@ -107,6 +106,8 @@ class FontBitmap:
width += coord
self.extra_bitmap = None
continue
elif c in special_chars[self.language]:
w = self.draw_char(image, width, c, self.cjk_font, -3)
else:
w = self.draw_char(image, width, c, self.font)
@@ -135,13 +136,13 @@ def main():
parser = argparse.ArgumentParser(description="Builder for OpenTX font files")
parser.add_argument('--output', help="Output file name")
parser.add_argument('--subset', help="Subset", default="all")
parser.add_argument('--subset', help="Subset")
parser.add_argument('--size', type=int, help="Font size")
parser.add_argument('--font', help="Font name")
parser.add_argument('--cjk-font', help="CJK font name")
args = parser.parse_args()
font = FontBitmap(get_chars(args.subset), args.size, args.font, args.cjk_font, (0, 0, 0), (255, 255, 255))
font = FontBitmap(args.subset, args.size, args.font, args.cjk_font, (0, 0, 0), (255, 255, 255))
font.generate(args.output)
+4 -4
View File
@@ -54,7 +54,7 @@ subset_lowercase = {
def get_chars(subset):
result = standard_chars + extra_chars
if subset == "all":
if False: # subset == "all":
for key, chars in special_chars.items():
result += "".join([char for char in chars if char not in result])
else:
@@ -65,11 +65,11 @@ def get_chars(subset):
def get_chars_encoding(subset):
result = {}
if subset == "all":
if subset in ("cn", "tw"):
chars = get_chars(subset)
for char in chars:
if char in special_chars["cn"]:
index = special_chars["cn"].index(char) + 1
if char in special_chars[subset]:
index = special_chars[subset].index(char) + 1
if index >= 0x100:
index += 1
result[char] = "\\%03o\\%03o" % (0xFE + ((index >> 8) & 0x01), index & 0xFF)
+1 -1
View File
@@ -15,7 +15,7 @@ def main():
parser.add_argument("--reverse", help="Reversed char conversion (from number to char)", action="store_true")
args = parser.parse_args()
if args.language != "all" and args.language not in special_chars:
if args.language not in special_chars:
parser.error(args.language + ' is not a supported language. Try one of the supported ones: %s' % list(special_chars.keys()))
sys.exit()