Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a font to android application by kivy?

Tags:

android

kivy

i already add some txt files in android by this path /data/data/package-name/files/app/filefolder/file.txt

the txt file is in the same directory with main.py like /same_directory_with_main.py/filefolder/file.txt

based on this experience, i am trying to add some custom fonts in my application. and i makes directory exactly same way which add txt files.

part of main.py

from kivy.config import Config      
Config.set('kivy', 'default_font', [
    '/data/data/org.test.tubuc/files/app/font/NanumSquareR.ttfs',
    '/data/data/org.test.tubuc/files/app/font/NanumSquareL.ttfs',
])

but logcat says can't find the font path. here the log.

09-24 10:47:57.506 18392 18581 I python  : ('Android kivy bootstrap done. __name__ is', '__main__')
09-24 10:47:57.540 18392 18581 I python  : ['/data/user/0/org.test.tubuc/files/app/lib/python2.7/site-packages', '/data/user/0/org.test.tubuc/files/app/lib/site-python']
09-24 10:47:57.540 18392 18581 I python  : AND: Ran string
09-24 10:47:57.540 18392 18581 I python  : Run user program, change dir and execute entrypoint
09-24 10:47:57.650 18392 18581 I python  : [WARNING] [Config      ] Older configuration version detected (0 instead of 19)
09-24 10:47:57.650 18392 18581 I python  : [WARNING] [Config      ] Upgrading configuration in progress.
09-24 10:47:57.659 18392 18581 I python  : [INFO   ] [Logger      ] Record log in /data/user/0/org.test.tubuc/files/app/.kivy/logs/kivy_18-09-24_0.txt
09-24 10:47:57.659 18392 18581 I python  : [INFO   ] [Kivy        ] v1.10.0
09-24 10:47:57.660 18392 18581 I python  : [INFO   ] [Python      ] v2.7.2 (default, Aug 17 2018, 08:01:29) 
09-24 10:47:57.660 18392 18581 I python  : [GCC 4.9.x 20150123 (prerelease)]
09-24 10:47:57.691 18392 18581 I python  : [INFO   ] [Factory     ] 194 symbols loaded
09-24 10:47:57.994 18392 18581 I python  : [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
09-24 10:47:58.022 18392 18581 I python  : [INFO   ] [Text        ] Provider: sdl2
09-24 10:47:58.023 18392 18581 I python  :  Traceback (most recent call last):
09-24 10:47:58.023 18392 18581 I python  :    File "/root/Desktop/hi/.buildozer/android/app/main.py", line 14, in <module>
09-24 10:47:58.024 18392 18581 I python  :    File "/root/Desktop/hi/.buildozer/android/platform/build/dists/tubuc/private/lib/python2.7/site-packages/kivy/uix/button.py", line 40, in <module>
09-24 10:47:58.024 18392 18581 I python  :    File "/root/Desktop/hi/.buildozer/android/platform/build/dists/tubuc/private/lib/python2.7/site-packages/kivy/uix/label.py", line 246, in <module>
09-24 10:47:58.024 18392 18581 I python  :    File "/root/Desktop/hi/.buildozer/android/platform/build/dists/tubuc/private/lib/python2.7/site-packages/kivy/core/text/__init__.py", line 797, in <module>
09-24 10:47:58.025 18392 18581 I python  :    File "/root/Desktop/hi/.buildozer/android/platform/build/dists/tubuc/private/lib/python2.7/site-packages/kivy/core/text/__init__.py", line 248, in register
09-24 10:47:58.025 18392 18581 I python  :  IOError: File /data/data/org.test.tubuc/files/app/font/NanumSquareL.ttfs not found
09-24 10:47:58.042 18392 18581 I python  : Python for android ended.

How can i add a font to android? thank you.

like image 712
m0f1us Avatar asked Nov 07 '22 01:11

m0f1us


1 Answers

This is how I do it with the font file at the same level as main.py

#main.py
import os
tools_path = os.path.dirname(__file__)
icons_path = os.path.join(tools_path, 'NanumSquareL.ttfs')

And also on buildozer.spec include the extension ttfs

#buildozer.spec
source.include_exts = py,png,jpg,kv,atlas, ttfs, json

Hope it helps.

like image 112
ocobacho Avatar answered Nov 14 '22 21:11

ocobacho