p5py / p5

p5 is a Python package based on the core ideas of Processing.
https://p5.readthedocs.io
GNU General Public License v3.0
724 stars 120 forks source link

P5py cannot create font to set text size #116

Open Abbas-Askari opened 5 years ago

Abbas-Askari commented 5 years ago

i want to set the size of text but am unable to do so, the original text_size() is not implemented and if i create a font with size , i get this error

WARNING: Traceback (most recent call last):
  File "/home/abbas/Desktop/Untitled Document.py", line 13, in <module>
    run()
  File "/home/abbas/.local/lib/python3.6/site-packages/p5/sketch/userspace.py", line 146, in run
    app.run()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/_default_app.py", line 62, in run
    return default_app.run()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/application.py", line 142, in run
    return self._backend._vispy_run()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/backends/_glfw.py", line 194, in _vispy_run
    self._vispy_process_events()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/backends/_glfw.py", line 183, in _vispy_process_events
    timer._tick()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/backends/_glfw.py", line 516, in _tick
    self._vispy_timer._timeout()
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/app/timer.py", line 168, in _timeout
    count=self.iter_count)
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/util/event.py", line 455, in __call__
    self._invoke_callback(cb, event)
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/util/event.py", line 475, in _invoke_callback
    self, cb_event=(cb, event))
  << caught exception here: >>
  File "/home/abbas/.local/lib/python3.6/site-packages/vispy/util/event.py", line 471, in _invoke_callback
    cb(event)
  File "/home/abbas/.local/lib/python3.6/site-packages/p5/sketch/base.py", line 150, in on_timer
    self.draw_method()
  File "/home/abbas/Desktop/Untitled Document.py", line 9, in draw
    create_font("arial.ttf", 15)
  File "/home/abbas/.local/lib/python3.6/site-packages/p5/core/font.py", line 50, in create_font
    _font_family = ImageFont.truetype(name, size)
  File "/home/abbas/.local/lib/python3.6/site-packages/PIL/ImageFont.py", line 280, in truetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/abbas/.local/lib/python3.6/site-packages/PIL/ImageFont.py", line 145, in __init__
    layout_engine=layout_engine)
OSError: cannot open resource

And some repeat stuff

my code:

from p5 import *

def setup():
    size(500, 500)

def draw():
    create_font("arial.ttf", 15)
    fill(14, 140, 255)
    text("Hello", [250, 250])

run()
arihantparsoya commented 5 years ago

Hi @Abbas-Askari , can you share the font file. I have tested your code locally and it doesn't produce any error for me.