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

查看:65
本文介绍了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?

预期输出:

程序输出:

推荐答案

需要适当的文本渲染器才能正确处理bangla字体(以及其他带有复杂字形的字体).文本渲染器pango具有回退,复杂字形处理等功能,还有许多其他功能.到目前为止,Kivy支持功能有限的Pango文本渲染器.目前,这已经在MacOS和Linux中进行了测试.以下是演示如何使用Kivy安装pango文本渲染器以及显示正确渲染孟加拉文本的示例应用程序的过程.该过程假定已经在Linux(Ubuntu 18.04)中安装了Kivy.

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
    

    您可能会收到安装CythonRequirement already satisfied消息,没关系.

    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天全站免登陆