mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
398 stars 80 forks source link

Custom harakat postion #21

Closed Ashraf-Ali-aa closed 6 years ago

Ashraf-Ali-aa commented 6 years ago

Hi, is it possible to set custom harakat position, when I use ZekrQuran font the harakat are positioned really high or is possible to hide Arabic letters so that I can redraw the letters twice one for the Harakat and the other for the letters with custom text position

imagedraw

# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import unittest
import sys
from arabic_reshaper import ArabicReshaper
from bidi.algorithm import get_display
from PIL import Image, ImageFont, ImageDraw, ImageEnhance

# text_to_be_reshaped = 'اللغة العربية رائعة'
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': False
}
reshaper = ArabicReshaper(configuration=configuration)

reshaped_text = reshaper.reshape(text_to_be_reshaped)
font = ImageFont.truetype("/Users/aal29/Github/Personal/gq-tool/ZekrQuran.ttf", 50)

bidi_text = get_display(reshaped_text)

image = Image.new('RGBA', (500,500), "black")
image_draw = ImageDraw.Draw(image)
image_draw.text((50,50), bidi_text, fill=(255,255,255,128), font=font)
# image_draw.text((50,75), bidi_text, fill=(255,255,255,128), font=font)
image.save("ImageDraw.png")
mpcabd commented 6 years ago

It's outside the scope of the tool, the tool works on strings, it is not concerned with the rendering engine you use or what font you use with what options.

I suggest you check what options you can use with Image.text and see if you can setup a line-height like what's in CSS.

The reshaper only shuffles characters and changes them from a form to another, it doesn't do anything else.

Ashraf-Ali-aa commented 6 years ago

thanks for the suggestion

ghost commented 1 year ago

Great Thanks Mr. Ashraf-Ali-aa. for your python code.