Kivy Python显示波斯语和阿拉伯语文本的问题

问题描述 投票:0回答:2

当我使用波斯语或阿拉伯语时,它从下到上显示多行文本。

  1. 当我使用大量波斯语文本时,我遇到这个问题。
  2. 短文本中不会出现此问题,因为屏幕不会将其发送到下一行。
  3. 在长文本中,当屏幕缩小时,转到下一行,就会面临这个问题。
from kivy.lang import Builder
import arabic_reshaper
from bidi.algorithm import get_display
from kivymd.app import MDApp

KV = '''
#:import arabic_reshaper arabic_reshaper
#:import get_display bidi.algorithm.get_display

Screen:

    BoxLayout:
        orientation: "vertical"

        ScrollView:
            do_scroll_x: False
            do_scroll_y: True
            index:1

            MDCard:
                id: md_card
                orientation: "vertical"
                padding: "8dp"
                size_hint: None, None
                size: 300, 300
                #pos_hint: {"center_x": .5, "center_y": .5}

                MDLabel:
                    font_name: 'font/Sahel.ttf'
                    text: get_display(arabic_reshaper.reshape('تست نام'))
                    halign: "right"

                MDSeparator:
                    height: "1dp"

                MDLabel:
                    font_name: 'font/Sahel.ttf'
                    halign: "right"
                    text: get_display(arabic_reshaper.reshape('این یک متن فارسی صرفا برای تست است در کیوی نمایش آن اشتباه از پایین به سمت بالا است.'))

'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()

它应该从上到下显示,提前感谢您的帮助。

这是您在此代码的输出中看到的图像。

checkmark.

我想要什么:

  • 使用图像编辑程序,我移动了文本以使其正确。
  • 我想要从上到下正确显示的内容。

checkmark.

python kivy kivy-language arabic-support
2个回答
0
投票

您需要使用

python-bidi
arabic_reshaper

import arabic_reshaper
import bidi.algorithm

reshaped_text = arabic_reshaper.reshape("متن فارسی")
bidi_text = bidi.algorithm.get_display(reshaped_text)

然后使用

bidi_text
作为 Kivy 标签文本。

检查此链接以了解如何正确使用这些库。


0
投票

链接>>>向她图书馆的程序员提出了一个问题,但仍然没有得到解答。

经过多次排查,我意识到问题出在这部分,但我无法让它像镜子一样解决显示波斯语和阿拉伯语文本的问题。

Lib\site-packages\kiv

© www.soinside.com 2019 - 2024. All rights reserved.