【问题标题】:Kivy does not find fonts in CygwinKivy 在 Cygwin 中找不到字体
【发布时间】:2017-02-18 05:02:13
【问题描述】:

我在Cygwin.中使用Kivy

瓦西尔科夫,马克。 Kivy 蓝图。伯明翰:Packt Publishing,2015。第 17 页,我想在以下代码中使用 Roboto 字体:

# File: main.py

from kivy.app import App
from kivy.core.text import LabelBase

LabelBase.register(name='Roboto',
        fn_regular='Roboto-Thin.ttf',
        fn_bold='Roboto-Medium.ttf')

class ClockApp(App):
    pass

if __name__ == '__main__':
    ClockApp().run()

然而,即使Cygwin 知道Roboto 字体安装在/usr/share/fonts/, 中,即:

$ fc-list | grep -i robot
/usr/share/fonts/roboto/Roboto-Regular.ttf: Roboto:style=Regular
/usr/share/fonts/roboto/Roboto-LightItalic.ttf: Roboto,Roboto Light:style=Light Italic,Italic
/usr/share/fonts/roboto/Roboto-Bold.ttf: Roboto:style=Bold
/usr/share/fonts/roboto/Roboto-MediumItalic.ttf: Roboto,Roboto Medium:style=Medium Italic,Italic
/usr/share/fonts/roboto/Roboto-ThinItalic.ttf: Roboto,Roboto Thin:style=Thin Italic,Italic
/usr/share/fonts/roboto/RobotoCondensed-Italic.ttf: Roboto Condensed:style=Italic
/usr/share/fonts/roboto/Roboto-Italic.ttf: Roboto:style=Italic
/usr/share/fonts/roboto/Roboto-Black.ttf: Roboto,Roboto Black:style=Black,Regular
/usr/share/fonts/roboto/RobotoCondensed-LightItalic.ttf: Roboto Condensed,Roboto Condensed Light:style=Light Italic,Italic
/usr/share/fonts/roboto/Roboto-Light.ttf: Roboto,Roboto Light:style=Light,Regular
/usr/share/fonts/roboto/RobotoCondensed-Regular.ttf: Roboto Condensed:style=Regular
/usr/share/fonts/roboto/Roboto-BoldItalic.ttf: Roboto:style=Bold Italic
/usr/share/fonts/roboto/RobotoCondensed-BoldItalic.ttf: Roboto Condensed:style=Bold Italic
/usr/share/fonts/roboto/RobotoCondensed-Light.ttf: Roboto Condensed,Roboto Condensed Light:style=Light,Regular
/usr/share/fonts/roboto/RobotoCondensed-Bold.ttf: Roboto Condensed:style=Bold
/usr/share/fonts/roboto/Roboto-Medium.ttf: Roboto,Roboto Medium:style=Medium,Regular
/usr/share/fonts/roboto/Roboto-Thin.ttf: Roboto,Roboto Thin:style=Thin,Regular
/usr/share/fonts/roboto/Roboto-BlackItalic.ttf: Roboto,Roboto Black:style=Black Italic,Italic

当我运行上面的 Python 代码时,我得到:

$ python main.py
[INFO   ] [Logger      ] Record log in /home/Administrator/.kivy/logs/kivy_16-10-09_18.txt
[INFO   ] [Kivy        ] v1.9.1
[INFO   ] [Python      ] v2.7.10 (default, Jun  1 2015, 18:17:45)
[GCC 4.9.2]
[INFO   ] [Factory     ] 179 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_pygame, img_pil (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pygame
 Traceback (most recent call last):
   File "main.py", line 9, in <module>
     fn_bold='Roboto-Medium.ttf')
   File "/usr/lib/python2.7/site-packages/kivy/core/text/__init__.py", line 223, in register
     raise IOError('File {0}s not found'.format(font_type))
 IOError: File Roboto-Thin.ttfs not found

我应该怎么做才能让Kivy 使用Roboto 字体?

【问题讨论】:

    标签: python fonts cygwin kivy x11


    【解决方案1】:

    您必须在LabelBase.register() 中提供字体的路径。你的目录中有那些字体文件吗?

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      相关资源
      最近更新 更多