From 77af9ab92b1a02a4a833093fd16918d91ffe7ee9 Mon Sep 17 00:00:00 2001 From: Joachim LF Date: Mon, 6 Apr 2020 18:06:44 +0200 Subject: [PATCH] I18NWarn --- apps/Makefile | 2 +- apps/i18n.py | 44 +++++++++++++++++++++++++++++++++++++------- kandinsky/Makefile | 2 ++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/apps/Makefile b/apps/Makefile index f31363b31..ee63f399b 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -80,7 +80,7 @@ $(eval $(call rule_for, \ I18N, \ apps/i18n.cpp, \ $(i18n_files), \ - $$(PYTHON) apps/i18n.py --header $$(subst .cpp,.h,$$@) --implementation $$@ --locales $$(EPSILON_I18N) --files $$^, \ + $$(PYTHON) apps/i18n.py --codepoints $(code_points) --header $$(subst .cpp,.h,$$@) --implementation $$@ --locales $$(EPSILON_I18N) --files $$^, \ global \ )) diff --git a/apps/i18n.py b/apps/i18n.py index b6e5dcdca..6ed920a40 100644 --- a/apps/i18n.py +++ b/apps/i18n.py @@ -12,6 +12,19 @@ import unicodedata import argparse import io + +parser = argparse.ArgumentParser(description="Process some i18n files.") +parser.add_argument('--header', help='the .h file to generate') +parser.add_argument('--implementation', help='the .cpp file to generate') +parser.add_argument('--locales', nargs='+', help='locale to actually generate') +parser.add_argument('--codepoints', help='the code_points.h file') +parser.add_argument('--files', nargs='+', help='an i18n file') + +args = parser.parse_args() + +def has_glyph(glyph): + return glyph in codepoints + def source_definition(i18n_string): s = unicodedata.normalize("NFKD", i18n_string) result = u"\"" @@ -29,6 +42,9 @@ def source_definition(i18n_string): # Remove the uppercase characters with combining chars checkForCombining = s[i].isupper() result = result + s[i] + if not has_glyph(s[i]): + sys.stderr.write(s[i] + " (" + str(hex(ord(s[i]))) + ") is not a character present in " + args.codepoints + " . Exiting !\n") + sys.exit(-1) i = i+1 result = result + u"\"" return result.encode("utf-8") @@ -73,6 +89,27 @@ def parse_files(files): data[locale][name] = definition return {"messages": sorted(messages), "universal_messages": sorted(universal_messages), "data": data} +def parse_codepoints(file): + codepoints = [] + with io.open(file, "r", encoding='utf-8') as file: + IsCodePoint = False + for line in file: + if "};" in line: + IsCodePoint = False + if IsCodePoint: + start = line.find('0x') + stop = line.find(',') + if not (start == -1 or stop == -1): + hexstring = line[start:stop] + value = int(hexstring, 16) + char = chr(value) + codepoints.append(char) + if "CodePoints[]" in line: + IsCodePoint = True + return codepoints + +codepoints = parse_codepoints(args.codepoints) + def print_header(data, path, locales): f = open(path, "w") f.write("#ifndef APPS_I18N_H\n") @@ -175,13 +212,6 @@ def print_implementation(data, path, locales): f.write("}\n") f.close() -parser = argparse.ArgumentParser(description="Process some i18n files.") -parser.add_argument('--header', help='the .h file to generate') -parser.add_argument('--implementation', help='the .cpp file to generate') -parser.add_argument('--locales', nargs='+', help='locale to actually generate') -parser.add_argument('--files', nargs='+', help='an i18n file') - -args = parser.parse_args() data = parse_files(args.files) if args.header: print_header(data, args.header, args.locales) diff --git a/kandinsky/Makefile b/kandinsky/Makefile index 0deb00a90..1e1ad24ff 100644 --- a/kandinsky/Makefile +++ b/kandinsky/Makefile @@ -25,6 +25,8 @@ tests_src += $(addprefix kandinsky/test/,\ rect.cpp\ ) +code_points = kandinsky/fonts/code_points.h + RASTERIZER_CFLAGS := -std=c99 $(shell pkg-config freetype2 --cflags) RASTERIZER_LDFLAGS := $(shell pkg-config freetype2 --libs)