rougier / freetype-py

Python binding for the freetype library
Other
304 stars 88 forks source link

set_char_size() fails with float parameter #113

Open buzmeg opened 5 years ago

buzmeg commented 5 years ago

set_char_size() claims to take floats as parameters in the documentation. However, if you feed it a float, freetype-py crashes.

face.set_char_size(128, 128, 128, 128) works fine

face.set_char_size(128.0, 128, 128, 128) crashes with:

Traceback (most recent call last):
  File "main.py", line 517, in <module>
    sys.exit(main())
  File "main.py", line 483, in main
    initialize_freetype()
  File "main.py", line 24, in initialize_freetype
    face.set_char_size(128.0, 128, 128, 128)  # Render directly to correct bitmap size
  File "/Users/andrewl/python/triangles/venv/lib/python3.7/site-packages/freetype/__init__.py", line 1081, in set_char_size
    error = FT_Set_Char_Size( self._FT_Face, width, height, hres, vres )
ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2
HinTak commented 5 years ago

I think the documentation is mis-worded - width and height are both 26.6 fractional numbers . It is a special type of integer to mean x / 64, when you write x. (I.e. 128 means 2 , 96 means 1.5). Hres and vres are just integers, not floats. They are passed directly to freetype as documented in freetype's documentation.

buzmeg commented 2 months ago

Closing.

HinTak commented 2 months ago

The crash probably should be avoided. Again, this is a good and somewhat easy to fix first issue for new contributors.

HinTak commented 2 months ago

There are code elsewhere checking the type of inputs (e.g. file names are byte arrays, what freetype c expects, and python 3 strings are converted to byte arrays) and convert if mismatch to what freetype expects. This is a good new contributor issue to add such.