Skip to content

Arabic fonts cannot represent several caracter when using bidi algrothim and resharper #32

@BouhamedMohammedMounir

Description

@BouhamedMohammedMounir

I am trying to print some Arabic text, and since we need to support bidirectional text, we are using bidi algorithm and Arabic Resharper. We are getting an exception to say
assert cid is not None, "Font %s can not represent '%s'" % (
AssertionError: Font HSNIbtisam can not represent 'ﺕ'

Knowing that the font support all Arabic characters.

def format(self, delivery_voucher: DeliveryVoucher):
        document = Document()
        page = Page()
        document.add_page(page)

        layout: PageLayout = SingleColumnLayout(page)
        font_path = Path(__file__).parent / 'misc/fonts/Ibtisam.ttf'
        custom_font = TrueTypeFont.true_type_font_from_file(font_path)
        print(font_path)

        arabic_text= "ابتثجحخدذرزسشصضطظعغفقكلمنهوي"
        reshaped_text = arabic_reshaper.reshape(arabic_text)
        bidirectional_text = algorithm.get_display(reshaped_text)

        # add a Paragraph
        layout.add(borb.pdf.Paragraph(bidirectional_text, font=custom_font))

        # store
        with open("output.pdf", "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, document)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions