Kivy isn't showing (Bengali) joining character properly?

后端 未结 2 931
闹比i
闹比i 2021-01-25 06:12

Kivy Python does not support Bengali joining characters,Is there any other way to solve this problem?

Can any one please describe what is the problem? What can i do to so

2条回答
  •  独厮守ぢ
    2021-01-25 06:43

    Appropriate text renderer is needed to handle bangla fonts (and other fonts with complex glyphs) properly. The text renderer pango has features like fallback, complex glyph processing among many other features. Kivy supports pango text renderer with limited features as of now. Currently this has been tested in MacOS and Linux. Below is the procedure to demonstrate installation of pango text renderer with Kivy and an example app showing correct rendering of bangla text. The procedure assumed that Kivy is already installed in Linux (Ubuntu 18.04).

    1. Check with the following command if pango is already installed correctly:

      pkg-config --libs pangoft2

      if pango is installed correctly, then it would produce following output:

      -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype

      Otherwise, if it produces no output, then it is not installed correctly. In this case proceed to next step.

    2. Issue the following command and wait for it to finish the execution:

      sudo apt-get update

    3. Next issue the following command to install pango:

      sudo apt install libfreetype6-dev libpango1.0-dev libpangoft2-1.0-0

      Again check with command in step 1 if installation is done properly.

    4. After pango installation, Kivy needs to be re-compiled. For this first issue the following command:

      sudo apt-get install -y \
          python-pip \
          build-essential \
          git \
          python \
          python3-dev \
          ffmpeg \
          libsdl2-dev \
          libsdl2-image-dev \
          libsdl2-mixer-dev \
          libsdl2-ttf-dev \
          libportmidi-dev \
          libswscale-dev \
          libavformat-dev \
          libavcodec-dev \
          zlib1g-dev
      
    5. Then issue the following three commands sequentially:

      sudo pip3 install cython
      export USE_PANGOFT2=1
      export KIVY_TEXT=pango
      

      You may receive Requirement already satisfied message for Cython installation, which is ok.

    6. Now uninstall Kivy with following command:

      sudo python3 -m pip uninstall kivy

    7. And install Kivy with following command:

      sudo pip3 install kivy

    8. Once Kivy is re-installed successfully, you can run the following example:

    import os
    os.environ['KIVY_TEXT'] = 'pango'
    from kivy.app import App
    from kivy.lang import Builder
    
    
    APP_KV = """
    BoxLayout:
        Label:
            text: "সকালে"
            font_size: '48sp'
            font_name: 'font/kalpurush.ttf'
    """
    
    class MainApp(App):
        def build(self):
            return Builder.load_string(APP_KV)
    
    if __name__ == '__main__':
        MainApp().run()
    

    The KIVY_TEXT environment setting may not be needed as already exported earlier. But this is to show how you can select the text renderer. You need to have the font file kalpurush.ttf (or any other bangla unicode font file) under sub directory named font.

    The Kivy log when you run the program is as follows:

    [INFO   ] [Logger      ] Record log in /home/kivy/.kivy/logs/kivy_20-08-31_9.txt
    [INFO   ] [Kivy        ] v1.11.1
    [INFO   ] [Kivy        ] Installed at "/usr/local/lib/python3.6/dist-packages/kivy/__init__.py"
    [INFO   ] [Python      ] v3.6.8 (default, Oct  7 2019, 12:59:55) 
    [GCC 8.3.0]
    [INFO   ] [Python      ] Interpreter at "/usr/bin/python3"
    [INFO   ] [Factory     ] 184 symbols loaded
    [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
    [INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
    [INFO   ] [GL          ] Using the "OpenGL" graphics system
    [INFO   ] [GL          ] Backend used 
    [INFO   ] [GL          ] OpenGL version 
    [INFO   ] [GL          ] OpenGL vendor 
    [INFO   ] [GL          ] OpenGL renderer 
    [INFO   ] [GL          ] OpenGL parsed version: 3, 1
    [INFO   ] [GL          ] Shading version 
    [INFO   ] [GL          ] Texture max size <8192>
    [INFO   ] [GL          ] Texture max units <32>
    [INFO   ] [Window      ] auto add sdl2 input provider
    [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
    [INFO   ] [Text        ] Provider: pango
    [INFO   ] [Base        ] Start application main loop
    [INFO   ] [GL          ] NPOT texture support is available
    [INFO   ] [WindowSDL   ] exiting mainloop and closing.
    [INFO   ] [Base        ] Leaving application in progress...
    

    Please note that the Text provider is pango.

    The output of the program:

    So, the text is rendered correctly. You can test with any other compound bangla letters, it will render correctly.

    For other platforms like Windows, the challenge is to correctly install pango. It may not be trivial to do so as there is no simple way I have found so far. May be pango needs to be compiled from source with it's dependencies.

提交回复
热议问题