問題描述
Kivy Python 不支持孟加拉語加入字符,有沒有其他辦法解決這個(gè)問題?
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?
預(yù)期輸出:
程序輸出:
推薦答案
需要適當(dāng)?shù)奈谋句秩酒鱽碚_處理孟加拉字體(以及其他具有復(fù)雜字形的字體).文本渲染器 pango 具有后備、復(fù)雜字形處理等許多其他功能.截至目前,Kivy 支持功能有限的 pango 文本渲染器.目前,這已在 MacOS 和 Linux 中進(jìn)行了測試.下面是演示如何使用 Kivy 安裝 pango 文本渲染器的過程以及一個(gè)顯示正確渲染孟加拉語文本的示例應(yīng)用程序.該過程假定 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).
如果 pango 已經(jīng)安裝,請使用以下命令檢查正確:
Check with the following command if pango is already installed correctly:
pkg-config --libs pangoft2
如果 pango 安裝正確,那么它會(huì)產(chǎn)生如下輸出:
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
否則,如果它沒有產(chǎn)生輸出,那么它就沒有被安裝正確.在這種情況下,請繼續(xù)下一步.
Otherwise, if it produces no output, then it is not installed correctly. In this case proceed to next step.
發(fā)出以下命令并等待它完成執(zhí)行:
Issue the following command and wait for it to finish the execution:
sudo apt-get update
接下來發(fā)出以下命令安裝pango:
Next issue the following command to install pango:
sudo apt install libfreetype6-dev libpango1.0-dev libpangoft2-1.0-0
如果安裝正確,請?jiān)俅螜z查步驟 1 中的命令.
Again check with command in step 1 if installation is done properly.
pango安裝后,需要重新編譯Kivy.對于第一個(gè)問題,以下命令:
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
然后依次發(fā)出以下三個(gè)命令:
Then issue the following three commands sequentially:
sudo pip3 install cython
export USE_PANGOFT2=1
export KIVY_TEXT=pango
Cython
安裝可能會(huì)收到 Requirement already compatible
消息,沒關(guān)系.
You may receive Requirement already satisfied
message for Cython
installation, which is ok.
現(xiàn)在使用以下命令卸載 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 后,您可以運(yùn)行以下示例:
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
環(huán)境設(shè)置可能不需要,因?yàn)橹耙呀?jīng)導(dǎo)出.但這是為了展示如何選擇文本渲染器.您需要在名為 font
的子目錄下?lián)碛凶煮w文件 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
.
運(yùn)行程序時(shí)的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
.
程序的輸出:
因此,文本正確呈現(xiàn).您可以使用任何其他復(fù)合孟加拉字母進(jìn)行測試,它會(huì)正確呈現(xiàn).
So, the text is rendered correctly. You can test with any other compound bangla letters, it will render correctly.
對于 Windows 等其他平臺(tái),挑戰(zhàn)在于正確安裝 pango.這樣做可能并不簡單,因?yàn)榈侥壳盀橹刮疫€沒有找到簡單的方法.可能是 pango 需要從源代碼編譯它的依賴項(xiàng).
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.
這篇關(guān)于Kivy 沒有正確顯示(孟加拉語)加入角色?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!