You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to produce arabic text using the python reshaper but was unable to get the diacritics to show well in any of the text generated. I have tested with different fonts but it has not worked properly so far. I would be grateful if I could get some help from the community to resolve this issue. Please find the test code i have used and the generated image. I am using PIL to place the text on the image. As we can see in the image below, the diacritics often overlaps the letters or other symbols. The Shift_Harakat_Position did not solve the issue.
List of fonts which I tested are Amiri, Arabic Typesetting, Arial,NotoSansArabic, Traditional Arabic and Zekr Quran fonts.zip
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import unittest
import sys
from arabic_reshaper import ArabicReshaper
from bidi.algorithm import get_display
from PIL import Image, ImageFont, ImageDraw, ImageEnhance
all_fonts = [i for i in os.listdir() if (i[i.find(".") + 1:]).lower() in ["ttf"]]
text_to_be_reshaped = u"هَذِهِ الأَفْكارِ المَغْلوطَةِ"
configuration = {
'delete_harakat': False,
'delete_tatweel': False,
'support_ligatures': True,
'support_zwj': True,
'shift_harakat_position': False,
'use_unshaped_instead_of_isolated': True
}
reshaper = ArabicReshaper(configuration=configuration)
reshaped_text = reshaper.reshape(text_to_be_reshaped) # Arabic Reshaper
reshaped_text = get_display(reshaped_text) # Bidi
img = Image.new('RGBA', (1000,1000), "black")
draw_layer = ImageDraw.Draw(img)
text_h_sum = 50
line_spacing = 16
for i, font in enumerate(all_fonts) :
font = ImageFont.truetype(font, 50)
space_taken_by_text = draw_layer.textbbox(xy = (0, 0), text = reshaped_text, font = font)
text_w = space_taken_by_text[0] + space_taken_by_text[2]
text_h = space_taken_by_text[1] + space_taken_by_text[3]
if i != 0 :
text_h_sum = text_h_sum + (text_h + (i * line_spacing))
draw_layer.text(
xy = (50, text_h_sum),
text = reshaped_text,
fill = (255, 255, 255, 128),
font = font
)
img.show()
The text was updated successfully, but these errors were encountered:
bossxero
changed the title
Issue with Tashkeel/Harakat positions and placement.
Issue with Tashkeel/Harakat positions and placement and tested on 6 fonts
May 9, 2024
bossxero
changed the title
Issue with Tashkeel/Harakat positions and placement and tested on 6 fonts
Issue with Diacritics/Harakat positions and placement and tested on 6 fonts
May 10, 2024
Hello,
I have been trying to produce arabic text using the python reshaper but was unable to get the diacritics to show well in any of the text generated. I have tested with different fonts but it has not worked properly so far. I would be grateful if I could get some help from the community to resolve this issue. Please find the test code i have used and the generated image. I am using PIL to place the text on the image. As we can see in the image below, the diacritics often overlaps the letters or other symbols. The Shift_Harakat_Position did not solve the issue.
List of fonts which I tested are Amiri, Arabic Typesetting, Arial,NotoSansArabic, Traditional Arabic and Zekr Quran
fonts.zip
The text was updated successfully, but these errors were encountered: