Kivy Isn't Showing (bengali) Joining Character Properly?
Solution 1:
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).
Check with the following command if pango is already installed correctly:
pkg-config --libs pangoft2if pango is installed correctly, then it would produce following output:
-lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetypeOtherwise, 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 updateNext issue the following command to install pango:
sudo apt install libfreetype6-dev libpango1.0-dev libpangoft2-1.0-0Again check with command in step 1 if installation is done properly.
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-devThen issue the following three commands sequentially:
sudo pip3 install cython export USE_PANGOFT2=1 export KIVY_TEXT=pangoYou may receive
Requirement already satisfiedmessage forCythoninstallation, which is ok.Now uninstall Kivy with following command:
sudo python3 -m pip uninstall kivyAnd install Kivy with following command:
sudo pip3 install kivyOnce 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'
"""classMainApp(App):
defbuild(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 72019, 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...
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.
Solution 2:
In my previous answer I have outlined procedure to install and activate pango text rendered back-end in Linux. Here I will explain a working procedure to install and activate pango for Kivy in Windows environment. Following is the environment where the procedure is tested:
- Windows 10
- Python 3.6.8 (64-bit)
- Kivy 2.0.0rc3
Following are the steps to be followed:
Create a directory named
srcin the root ofC:drive and go to that directory:C:\>mkdir src C:\>cd srcRun the following command to clone the
vcpkgto thesrcdirectory:git clone https://github.com/microsoft/vcpkgYou need to have Git installed to run the above command.
Then bootstrap
vcpkgand move tovcpkgdirectory:C:\src>.\vcpkg\bootstrap-vcpkg.batC:\src>cd vcpkgNow run the following command to install
pango(with it's dependencies):vcpkg install pango --triplet x64-windowsAfter successful installation of
pango, download the source tar ball of Kivy 2.0.0rc3 release from https://pypi.org/project/Kivy/2.0.0rc3/#files and extract in any suitable folder.Now go to the folder where Kivy 2.0.0rc3 source files are extracted and open the
setup.pyfile in a text editor (preferably Notepad++). Search for the line containingif c_options['use_pangoft2'] in (None, True)and add the following block of code before that line and save the file:if c_options['use_pangoft2'] in (None, True) and platform == 'win32': pango_flags = {} pango_flags['include_dirs'] = (['C:/src/vcpkg/installed/x64-windows/include', 'C:/src/vcpkg/installed/x64-windows/include/harfbuzz']) pango_flags['library_dirs'] = (['C:/src/vcpkg/installed/x64-windows/lib']) pango_flags['libraries'] = (['pangoft2-1.0', 'pango-1.0', 'gobject-2.0', 'glib-2.0', 'harfbuzz', 'freetype', 'fontconfig']) c_options['use_pangoft2'] = True pango_depends = {'depends': ['lib/pango/pangoft2.pxi', 'lib/pango/pangoft2.h']} sources['core/text/_text_pango.pyx'] = merge(base_flags, pango_flags, pango_depends) import subprocess subprocess.call(["setx", "FONTCONFIG_FILE", "C:\\src\\vcpkg\\installed\\x64-windows\\tools\\fontconfig\\fonts.conf"])This manual configuration is required as
vcpkgcurrently doesn't produce.pcfiles for automatic population of compiler linking variables throughpkg-conifg. Also as of now there is nopkg-configtool integration withvcpkg.Add
C:/src/vcpkg/installed/x64-windows/libandC:/src/vcpkg/installed/x64-windows/binto thePATHsystem environment variable.Now Kivy needs to be compiled from it's source. If Kivy is already installed please uninstall it first. And then the procedure mentioned in the official kivy site can be followed - though I am listing here the required steps to be followed. Upgrade pip and wheel with:
python -m pip install --upgrade pip wheel setuptoolsGet Visual C++ Build Tools and install the following components from the "visual c++ build tools" section: "Windows 10 SDK (version)", "C++ CMake tools for Windows", "C++/CLI support", "MSVC v142 - VS 2019 C++ x64/x86 build tools".
Set the required environment variables:
set USE_SDL2=1 set USE_PANGOFT2=1 set USE_GSTREAMER=1Install the latest versions of kivy dependencies:
python -m pip install Cython==0.29.10 docutils pygments pypiwin32 kivy_deps.sdl2 kivy_deps.glew kivy_deps.gstreamer kivy_deps.glew_dev kivy_deps.sdl2_dev kivy_deps.gstreamer_devNow go to the root folder where the Kivy 2.0.0rc3 source files are extracted (where the ```setup.py`` file is located) and issue the following command to compile and install Kivy:
python -m pip install .After successful installation of Kivy, 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' """classMainApp(App): defbuild(self): return Builder.load_string(APP_KV) if __name__ == '__main__': MainApp().run()You need to have the font file
kalpurush.ttf(or any other bangla unicode font file) under sub directory namedfont.The Kivy log when you run the program is as follows:
[INFO ] [Logger ] Record log in C:\Users\user\.kivy\logs\kivy_20-09-06_12.txt [INFO ] [deps ] Successfully imported "kivy_deps.gstreamer_dev"0.2.0 [INFO ] [deps ] Successfully imported "kivy_deps.gstreamer"0.2.0 [INFO ] [deps ] Successfully imported "kivy_deps.glew"0.2.0 [INFO ] [deps ] Successfully imported "kivy_deps.glew_dev"0.2.0 [INFO ] [deps ] Successfully imported "kivy_deps.sdl2"0.2.0 [INFO ] [deps ] Successfully imported "kivy_deps.sdl2_dev"0.2.0 [INFO ] [Kivy ] v2.0.0rc3, git-Unknown, 20200906 [INFO ] [Kivy ] Installed at "C:\Python\Python36\lib\site-packages\kivy\__init__.py" [INFO ] [Python ] v3.6.8 (tags/v3.6.8:3c6b436a57, Dec 242018, 00:16:47) [MSC v.191664 bit (AMD64)] [INFO ] [Python ] Interpreter at "C:\Python\Python36\python.exe" [INFO ] [Factory ] 185 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer, img_gif ignored) [INFO ] [Window ] Provider: sdl2 [INFO ] [GL ] Using the "OpenGL" graphics system [INFO ] [GL ] GLEW initialization succeeded [INFO ] [GL ] Backend used <glew> [INFO ] [GL ] OpenGL version <b'4.6.0 - Build 26.20.100.7812'> [INFO ] [GL ] OpenGL vendor <b'Intel'> [INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 520'> [INFO ] [GL ] OpenGL parsed version: 4, 6 [INFO ] [GL ] Shading version <b'4.60 - Build 26.20.100.7812'> [INFO ] [GL ] Texture max size <16384> [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 availablePlease note that the Text provider is
pango.The text is rendered correctly. With
pangoother non-english language fonts having requirements of font fallback, complex glyph processing would render correctly.There are other procedures for installing
pango, like withgvsbuildscripts as mentioned in the official site of GTK. It has thepkg-configintegration as well. But it doesn't integrate successfully with Kivy. The installation throughvcpkg, as outlined in this procedure, is the only successful procedure I have found.


Post a Comment for "Kivy Isn't Showing (bengali) Joining Character Properly?"