Git Product home page Git Product logo

Comments (4)

mpcabd avatar mpcabd commented on July 28, 2024 1

I can't seem to reproduce it, maybe the font file you're using is not properly configured, have you tried using a TrueType® (.ttf) file?

import arabic_reshaper
import os

from PIL import Image, ImageDraw, ImageFont
from bidi.algorithm import get_display

directory = os.path.abspath(os.path.dirname(__file__))


def f(p): return os.path.join(directory, p)


text_to_be_reshaped = 'امتحان الرياضيات النهائي'
reshaper = arabic_reshaper.ArabicReshaper({
    'use_unshaped_instead_of_isolated': True
})
reshaped_text = reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)

font = ImageFont.truetype(f('arabic-typesetting.ttf'), 120)
image = Image.new('RGBA', (800, 600), (255, 255, 255, 255))
image_draw = ImageDraw.Draw(image)
image_draw.text((10, 10), bidi_text, fill=(0, 0, 0, 255), font=font)
image.save(f('text-manual-config.png'))

config_from_font = arabic_reshaper.config_for_true_type_font(
    f('arabic-typesetting.ttf'))
reshaper = arabic_reshaper.ArabicReshaper(config_from_font)
reshaped_text = reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)
image_draw.rectangle([0, 0, 800, 600], fill=(255, 255, 255, 255))
image_draw.text((10, 10), bidi_text, fill=(0, 0, 0, 255), font=font)
image.save(f('text-auto-config.png'))

Manual Config:
image


Auto Config:
image


The code is using my latest release 2.1.0 which has a new method to read a .ttf file and configure the reshaper accordingly. See this new section in the README for more info.

from python-arabic-reshaper.

mpcabd avatar mpcabd commented on July 28, 2024

Can you show me how you're using the config mentioned? I suspect it's not being used or utilised correctly.

This image show the text you provided while enabling use_unshaped_instead_of_isolated

image

from python-arabic-reshaper.

ahmed4end avatar ahmed4end commented on July 28, 2024

image
here is a snippet of how i used the "use_unshaped_instead_of_isolated" option and i wish i'm wrong at using it.
and this is the result of me code :
image

from python-arabic-reshaper.

ahmed4end avatar ahmed4end commented on July 28, 2024

@mpcabd i did upgrade the library and tried your code and amazingly solved my problems and worked smoothly, i'm very grateful, thanks.

from python-arabic-reshaper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.