How To Fix Arabic/persian Text And Font In Pygame?
I have this piece of code right here: import pygame pygame.display.init() pygame.font.init() win = pygame.display.set_mode((100, 100)) font = pygame.font.Font('./arial.ttf', 10) t
Solution 1:
You have to use arabic_reshaper library.
pip install arabic-reshaper
Refer to this https://github.com/mpcabd/python-arabic-reshaper
You will need python-bidi as well
pip install python-bidi
You can do it as follow
import pygame
import arabic_reshaper
from bidi.algorithm import get_display
pygame.display.init()
pygame.font.init()
win = pygame.display.set_mode((100, 100))
font = pygame.font.Font('arial.ttf', 10)
text_to_be_reshaped = 'اللغة العربية رائعة'
reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)
print(reshaped_text)
text = font.render(bidi_text, True, (255, 255, 255))
win.fill((0, 0, 0))
win.blit(text, (0, 0))
pygame.display.update()
for i inrange(5):
pygame.event.clear()
pygame.time.delay(1000)
pygame.quit()
OUTPUT
Post a Comment for "How To Fix Arabic/persian Text And Font In Pygame?"