pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.23k stars 326 forks source link

Text.default_font does not work for dynamic fonts #609

Closed BurntRanch closed 1 year ago

BurntRanch commented 1 year ago

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'
BurntRanch commented 1 year ago

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