pokepetter / ursina

A game engine powered by python and panda3d.

Home Page:https://pokepetter.github.io/ursina/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text.default_font does not work for dynamic fonts

BurntRanch opened this issue · comments

If a custom font is set as the default font, trying to get its width in the future will cause it to crash, works only for fonts bundled like VeraMono and OpenSans

Code is in text.py, Just execute it with the line Text.default_font = 'consola.ttf' uncommented.
Result:

Traceback (most recent call last):
  File "/home/burntranch/ursina/.venv/lib/python3.11/site-packages/ursina/text.py", line 479, in <module>
    print('....', Text.get_width('yolo'))
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/burntranch/ursina/.venv/lib/python3.11/site-packages/ursina/text.py", line 429, in get_width
    w = t.width
        ^^^^^^^
  File "/home/burntranch/ursina/.venv/lib/python3.11/site-packages/ursina/text.py", line 278, in width
    temp_text_node.setFont(self._font)
                           ^^^^^^^^^^
AttributeError: 'Text' object has no attribute '_font'

I just realized it did not import fonts that are installed in the system.