nathanielfernandes / imagetext-py

A blazing fast text drawing library
https://pypi.org/project/imagetext-py/
MIT License
69 stars 4 forks source link

RTL Language Rendering Problem #14

Closed ihuomtia closed 2 weeks ago

ihuomtia commented 2 months ago

Description

The library is currently unable to properly render text in RTL (Right-to-Left) languages such as Arabic. When attempting to add text in Arabic, for example, the text is rendered in LTR (Left-to-Right) direction, which results in incorrect display and readability issues.

Steps to Reproduce:

from imagetext_py import *
from PIL import Image

FontDB.LoadFromDir("/path/to/fonts")
# using this font: https://fonts.google.com/noto/specimen/Noto+Kufi+Arabic
font = FontDB.Query("NotoKufiArabic-VariableFont_wght")
cv = Canvas(512, 512, (255, 255, 255, 255))
black = Paint.Color((0, 0, 0, 255))

text = "السلام عليكم"

draw_text_wrapped(canvas=cv, text=text, x=256, y=256, ax=0.5, ay=0.5, size=67, width=500, fill=black, align=TextAlign.Center, stroke=2.0, stroke_color=black, font=font)

im = cv.to_image()
im.show()

Expected Behavior:

The Arabic text should be rendered correctly in RTL direction, maintaining the correct reading order and alignment, as shown in the following picture:

image

Actual Behavior:

The Arabic text is rendered in LTR direction, causing the text to appear incorrectly and affecting readability.

image

nathanielfernandes commented 2 weeks ago

Hi @ihuomtia, there is currently no support for RTL text rendering. It is a really complicated task and I currently don't have the time to add support for it. PR's are welcome however :-)