kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17.63k stars 3.06k forks source link

Label,TextInput rtl bug #8525

Open OdzOdz opened 9 months ago

OdzOdz commented 9 months ago

Software Versions

Describe the bug Issue with font_name setting: When setting font_name, the Persian text is displayed, but the order of characters is incorrect. For example, "سلام" is displayed as "مالس".

Improvement with font_script_name: When setting font_script_name to 'Arab', the issue of characters being displayed separately is resolved, and it correctly shows "سلام" as "سلام".

Solution using bidi library: The issue with the order of text from bottom to top is resolved by using the get_display function from the bidi library.

Problem with shrinking the page: When reducing the size of the page, the text is displayed vertically from bottom to top, causing issues like "سلام خوبی" becoming "خوبی سلام".

Expected behavior A clear and concise description of what you expected to happen.

To Reproduce A short, runnable example that reproduces the issue with latest kivy master.

Code and Logs and screenshots

from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.app import MDApp
from bidi.algorithm import get_display

Builder.load_string('''

<Reply@OneLineAvatarIconListItem>:
    id:item
    text_color:[1,1,1,0.7]
    bg_color:[0,0,0,0.9]
    theme_text_color:'Custom'

    IconLeftWidgetWithoutTouch:
        icon: "reply"
        icon_color:[1,1,1,0.7]
        theme_icon_color:'Custom'
    MDLabel:
        id:label
        # shorten:True
        halign: 'right'
        font_hinting: 'light'
        font_script_name:'Arab'
        text_color:"#9a9090"
        theme_text_color:'Custom'
        padding:65,20,40,19
        markup:True
        font_name:'/home/odz/Desktop/projects/ChatGptApp/App/files/shabnam.ttf'
    IconRightWidget:
        icon: "close"
        icon_color:[1,1,1,0.7]
        theme_icon_color:'Custom'
        on_release:app.remove()

<ExampleBanner@Screen>
    MDBoxLayout:
        orientation: "vertical"
        MDBoxLayout:
            orientation: "vertical"
            size_hint:1,0.9
            MDIconButton:
                on_release:app.add()
                icon:'alert-circle-check'
            MDTextField:
                id:textfield
                multiline:True
        MDBoxLayout:
            orientation: "vertical"
            id:list
            size_hint:1,0.1

''')

class Test(MDApp):
    def build(self):
        self.item=Factory.Reply()
        return Factory.ExampleBanner()
    def add(self):
        self.root.ids.list.remove_widget(self.item)
        self.item.ids.label.text=get_display(self.root.ids.textfield.text)
        self.root.ids.list.add_widget(self.item)        
    def remove(self):
        self.root.ids.list.remove_widget(self.item)

Test().run()

![Screenshot from 2023-12-23 13-30-08](https://github.com/kivy/kivy/assets/114577199/804004b3-565f-4873-87be-eca4780879ea)

Additional context Add any other context about the problem here.

OdzOdz commented 9 months ago

I am currently facing issues related to Right-to-Left (RTL) support in KivyMD. It's important to note that these problems stem from the base Kivy library and affect components such as labels and text inputs. Although I'm using KivyMD, the challenges seem to originate from the underlying Kivy framework.

I expect that the RTL support in KivyMD should seamlessly handle Persian text in components like labels and text inputs, maintaining the proper order of characters.

Julian-O commented 9 months ago

Should be considered as part of #8444

OdzOdz commented 9 months ago

I didn't understand?! Have you found a suitable solution for the problem I mentioned? Do not show the text in reverse (display it from top to bottom).

ElliotGarbus commented 9 months ago

The issue is already captured. You might find this helpful: https://medium.com/@ahmedfgad/supporting-arabic-alphabet-in-kivy-for-building-cross-platform-applications-7a1e7c14a068

Julian-O commented 9 months ago

@OdzOdz: Kivy cannot handle RTL text seamlessly.

ElliotGarbus has provided a link above that may help you work around the Kivy problems by using the Python Arabic Reshaper Library.

However, I think Kivy should handle this automatically.

I have collected together all of the bug reports provided over several years related to RTL languages and Unicode issues, and put the list into #8444.

I want the Kivy developers realise it isn't just one small issue, but a large issue that affects many users. I want the Kivy developers to fix all the problems, not just one or two.

I was making sure when people are looking at #8444, there is a mention of this issue there too.

OdzOdz commented 9 months ago

ok thanks