Kivy 没有正确显示(孟加拉语)加入角色? [英] Kivy isn't showing (Bengali) joining character properly?

查看:19
本文介绍了Kivy 没有正确显示(孟加拉语)加入角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kivy Python 不支持孟加拉语加入字符,有没有其他办法解决这个问题?

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 solve it?

预期输出:

程序输出:

推荐答案

需要适当的文本渲染器来正确处理孟加拉字体(以及其他具有复杂字形的字体).文本渲染器 pango 具有后备、复杂字形处理等许多其他功能.截至目前,Kivy 支持功能有限的 pango 文本渲染器.目前,这已在 MacOS 和 Linux 中进行了测试.下面是演示如何使用 Kivy 安装 pango 文本渲染器的过程以及一个显示正确渲染孟加拉语文本的示例应用程序.该过程假定 Kivy 已安装在 Linux (Ubuntu 18.04) 中.

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. 如果 pango 已经安装,请使用以下命令检查正确:

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

pkg-config --libs pangoft2

如果 pango 安装正确,那么它会产生如下输出:

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.

发出以下命令并等待它完成执行:

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

sudo apt-get update

接下来发出以下命令安装pango:

Next issue the following command to install pango:

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

如果安装正确,请再次检查步骤 1 中的命令.

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

pango安装后,需要重新编译Kivy.对于第一个问题,以下命令:

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

  • 然后依次发出以下三个命令:

  • Then issue the following three commands sequentially:

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

    Cython 安装可能会收到 Requirement already compatible 消息,没关系.

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

    现在使用以下命令卸载 Kivy:

    Now uninstall Kivy with following command:

    sudo python3 -m pip uninstall kivy

    并使用以下命令安装 Kivy:

    And install Kivy with following command:

    sudo pip3 install kivy

    成功重新安装 Kivy 后,您可以运行以下示例:

    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()
    

    KIVY_TEXT 环境设置可能不需要,因为之前已经导出.但这是为了展示如何选择文本渲染器.您需要在名为 font 的子目录下拥有字体文件 kalpurush.ttf(或任何其他孟加拉 unicode 字体文件).

    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.

    运行程序时的Kivy日志如下:

    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 <sdl2>
    [INFO   ] [GL          ] OpenGL version <b'3.1 Mesa 19.0.8'>
    [INFO   ] [GL          ] OpenGL vendor <b'VMware, Inc.'>
    [INFO   ] [GL          ] OpenGL renderer <b'llvmpipe (LLVM 8.0, 256 bits)'>
    [INFO   ] [GL          ] OpenGL parsed version: 3, 1
    [INFO   ] [GL          ] Shading version <b'1.40'>
    [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...
    

    请注意,文本提供程序是 pango.

    Please note that the Text provider is pango.

    程序的输出:

    因此,文本正确呈现.您可以使用任何其他复合孟加拉字母进行测试,它会正确呈现.

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

    对于 Windows 等其他平台,挑战在于正确安装 pango.这样做可能并不简单,因为到目前为止我还没有找到简单的方法.可能是 pango 需要从源代码编译它的依赖项.

    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.

    这篇关于Kivy 没有正确显示(孟加拉语)加入角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆