Hadi Farhadi
Hadi Farhadi

Reputation: 1761

multiline text in kivy label(python-bidi)

i have a label that show a multiline text in persian

kv file:

    <FarsiLabel@Label>:
        font_name: 'tabassom'

    FarsiLabel:
        text: set_text('پیروزی  برای افرادی امکان پذیر است که از مبارزه دست نمی کشند\n')
        text_size: self.size
        halign: 'center'
        color: utils.get_color_from_hex('546E7A')

set_text method:

    def set_text(text):
        text = unicode(text, 'utf-8')
        result = arabic_reshaper.reshape(text)
        result = get_display(result)
        return result

result(incorrect):

enter image description here

correct result(gimp):

enter image description here

I've found that the problem in the python-bidi get_display method, but i don't know how to solve it

question is: how to solve this problem?

Upvotes: 4

Views: 977

Answers (1)

Assem
Assem

Reputation: 12087

That's how bidi.algorithm.get_display works, it inverts the order of letters. So what you consider it as the first word is the last word in output.

You should detect the width of the label in characters and do the segmentation in lines yourself. Then apply get_display on each line.

  • line 1: پیروزی برای افرادی امکان پذیر است که از مبارزه
  • line 2: دست نمی کشند

Upvotes: 2

Related Questions