問題描述
我正在嘗試將 Kivy 的文本輸入用于阿拉伯文本.我用我的文本輸入設置了一個阿拉伯字體,但是當我輸入輸入(阿拉伯語)時,我只是得到從左到右出現的阿拉伯字母(并且它們沒有連接,因為阿拉伯字母應該是相鄰的彼此).
有沒有辦法讓 Kivy/文本輸入支持我缺少的 RTL 語言輸入(尤其是阿拉伯語).
這是我的代碼,
從 kivy.app 導入 App從 kivy.uix.floatlayout 導入 FloatLayoutConfig.set('圖形', '寬度', '300')Config.set('圖形', '高度', '500')記錄器 = logging.getLogger('')從 kivy.uix.textinput 導入 TextInput類編輯器應用程序(應用程序):定義構建(自我):f = 浮動布局()textinput = TextInput(text='Hello world', font_name='DroidKufi-Regular.ttf')#導入pdb;pdb.set_trace()f.add_widget(文本輸入)返回 f如果 __name__ == '__main__':EditorApp().run()
這段代碼的結果:
不幸的是,Kivy TextInput 對從右到左的支持是 的公開嘗試.另一個封閉的:從右到左的標簽支持.
I'm trying to use Kivy's text input for Arabic text. I have an Arabic font set up with my text input but when I type into the input (in Arabic) I just get Arabic letters appearing from left to right (and they're not connected as Arabic letters should be when they're adjacent to each other).
Is there a way to get Kivy/text input to support RTL languages input that I'm missing (esp Arabic).
Here's my code,
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
Config.set('graphics', 'width', '300')
Config.set('graphics', 'height', '500')
logger = logging.getLogger('')
from kivy.uix.textinput import TextInput
class EditorApp(App):
def build(self):
f = FloatLayout()
textinput = TextInput(text='Hello world', font_name='DroidKufi-Regular.ttf')
# import pdb; pdb.set_trace()
f.add_widget(textinput)
return f
if __name__ == '__main__':
EditorApp().run()
The result of this code:
Unfortunately, Kivy TextInput support for right-to-left is an open issue (checked 29/05/2015). Actually, Kivy is not supporting right-to-left not only to TextInput.
For static texts like labels , there is a hack by using arabic_reshaper and python-bidi (reference):
import arabic_reshaper
from bidi.algorithm import get_display
reshaped_text = arabic_reshaper.reshape(u'????? ??????? ?????')
bidi_text = get_display(reshaped_text)
Yet, as for TextInput
with a dynamic input, you had to override most of class methods to support RTL and you will end up like implementing the whole RTL support to kivy.
Here is an open attempt to implement Kivy bidi support. Another closed one: Right-to-left labels support.
這篇關于阿拉伯語文本的 Kivy 文本輸入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!