jorisschellekens / borb-examples

412 stars 58 forks source link

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

Open BouhamedMohammedMounir opened 1 year ago

BouhamedMohammedMounir commented 1 year ago

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)
BouhamedMohammedMounir commented 1 year ago

Mentioning that not using the bidi algorithm results in non-concatenated characters image