Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Diacritics/Harakat positions and placement and tested on 6 fonts #95

Open
bossxero opened this issue May 9, 2024 · 0 comments

Comments

@bossxero
Copy link

bossxero commented May 9, 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

textgeneration


# -*- 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()
@bossxero 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant