2015-07-05 43 views
5

我有一個標籤,該標籤顯示在波斯多行文本

千伏文件多行文本:

<[email protected]>: 
     font_name: 'tabassom' 

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

set_text方法:

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

結果(不正確):

enter image description here

正確的結果(GIMP):

enter image description here

我發現,在Python,比迪煙get_display方法的問題,但我不知道如何解決它

問題是:如何解決這個問題?

回答

2

這就是bidi.algorithm.get_display的工作原理,它顛倒了字母的順序。所以你認爲第一個詞是輸出中的最後一個詞。

您應該檢測字符的標籤寬度並自行對線進行分割。然後在每行上應用get_display

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