diff --git a/trdg/data_generator.py b/trdg/data_generator.py index 75a79467fc..ca1f75a6bc 100644 --- a/trdg/data_generator.py +++ b/trdg/data_generator.py @@ -26,6 +26,7 @@ def generate( cls, index: int, text: str, + language: str, font: str, out_dir: str, size: int, @@ -249,6 +250,15 @@ def generate( # Generate name for resulting image # ##################################### # We remove spaces if space_width == 0 + if language in ("ar", "fa"): + from arabic_reshaper import ArabicReshaper + from bidi.algorithm import get_display + + arabic_reshaper = ArabicReshaper() + text = " ".join( + [get_display(arabic_reshaper.reshape(w)) for w in text.split(" ")[::-1]] + ) + if space_width == 0: text = text.replace(" ", "") if name_format == 0: diff --git a/trdg/fonts/fa/B Titr Bold_0.ttf b/trdg/fonts/fa/B Titr Bold_0.ttf new file mode 100644 index 0000000000..1cb90342b8 Binary files /dev/null and b/trdg/fonts/fa/B Titr Bold_0.ttf differ diff --git a/trdg/fonts/fa/B-NAZANIN.ttf b/trdg/fonts/fa/B-NAZANIN.ttf new file mode 100644 index 0000000000..72bbfc3803 Binary files /dev/null and b/trdg/fonts/fa/B-NAZANIN.ttf differ diff --git a/trdg/fonts/fa/Sahel.ttf b/trdg/fonts/fa/Sahel.ttf new file mode 100644 index 0000000000..3b6533494c Binary files /dev/null and b/trdg/fonts/fa/Sahel.ttf differ diff --git a/trdg/fonts/fa/Samim.ttf b/trdg/fonts/fa/Samim.ttf new file mode 100644 index 0000000000..a9a97a792e Binary files /dev/null and b/trdg/fonts/fa/Samim.ttf differ diff --git a/trdg/fonts/fa/Tahoma Regular font.ttf b/trdg/fonts/fa/Tahoma Regular font.ttf new file mode 100644 index 0000000000..95009c1be5 Binary files /dev/null and b/trdg/fonts/fa/Tahoma Regular font.ttf differ diff --git a/trdg/fonts/fa/Tanha.ttf b/trdg/fonts/fa/Tanha.ttf new file mode 100644 index 0000000000..cd8b48616b Binary files /dev/null and b/trdg/fonts/fa/Tanha.ttf differ diff --git a/trdg/fonts/fa/Times New Roman.ttf b/trdg/fonts/fa/Times New Roman.ttf new file mode 100644 index 0000000000..51261a005c Binary files /dev/null and b/trdg/fonts/fa/Times New Roman.ttf differ diff --git a/trdg/fonts/fa/Vazirmatn-Regular.ttf b/trdg/fonts/fa/Vazirmatn-Regular.ttf new file mode 100644 index 0000000000..64e4a81895 Binary files /dev/null and b/trdg/fonts/fa/Vazirmatn-Regular.ttf differ diff --git a/trdg/run.py b/trdg/run.py index 65edd1291c..7e4f7c7db4 100755 --- a/trdg/run.py +++ b/trdg/run.py @@ -416,7 +416,7 @@ def main(): args.length, args.random, args.count, lang_dict ) - if args.language == "ar": + if args.language in ("ar", "fa"): from arabic_reshaper import ArabicReshaper from bidi.algorithm import get_display @@ -441,6 +441,7 @@ def main(): zip( [i for i in range(0, string_count)], strings, + [args.language] * string_count, [fonts[rnd.randrange(0, len(fonts))] for _ in range(0, string_count)], [args.output_dir] * string_count, [args.format] * string_count, @@ -486,6 +487,13 @@ def main(): label = strings[i] if args.space_width == 0: label = label.replace(" ", "") + if args.language in ("ar", "fa"): + label = " ".join( + [ + get_display(arabic_reshaper.reshape(w)) + for w in strings[i].split(" ")[::-1] + ] + ) f.write("{} {}\n".format(file_name, label))