BNNorman / rpi-rgb-led-matrix-animator

Python code to play animation sequences on an RGB LED matrix panel using the HZeller drivers
28 stars 5 forks source link

Add support for TrueType and OpenType fonts #11

Open BNNorman opened 6 years ago

BNNorman commented 6 years ago

OpenCV appears to only use Hershey fonts. Using PIL it is possible to read and render TrueType and OpenType fonts but requires converting the numpy array to a PIL image and back again.

ValDY69 commented 6 years ago

Hello Brian , did you have time to look at this feature ?

did you have any news ?

BNNorman commented 6 years ago

I have added the required support for OpenType/FreeType, TrueType and PIL Font files using PIL. Also corrected font colors were incorrect. Also fixed transparent text background was rendered solid black - which gave the black rectangle on TextAnimations.Wait() (See other issue)

When using TrueType etc anti-aliasing is turned off using lineType=LINE_8 or LINE_4. lineType=LINE_AA is the default. The font I tried with anti-aliasing turned off looked horrid but that's probably just a characteristic of the (free) font I selected.

ValDY69 commented 6 years ago

ok brian amazing ! i will test it soon !

thank you

ValDY69 commented 6 years ago

brian can you add some new examples for the new supported Fonts (PIL , ttf , otf ) to help me to know how i can manipulate them ?

Regards , valentin

BNNorman commented 6 years ago

Is your browser broken LOL?

Try http://www.1001fonts.com/ and http://fonts.webtoolhub.com/?prefix=pil then you can choose whatever you like (Check licensing if intending to use for commercial purposes).

Just pass the filename to LEDAnimator.Font.py. PIL fonts have two files .pil and .pbm - just use the .pil filename (The PBM is a portable bitmap for the font the PIL is the font information).

ValDY69 commented 6 years ago

Is your browser broken LOL?

Try http://www.1001fonts.com/ and http://fonts.webtoolhub.com/?prefix=pil then you can choose whatever you like (Check licensing if intending to use for commercial purposes).

ok thank you i know how to DL .ttf or .otf Fonts but i was speaking about how to integrate them in your library xD

Just pass the filename to LEDAnimator.Font.py. PIL fonts have two files .pil and .pbm - just use the .pil filename (The PBM is a portable bitmap for the font the PIL is the font information).

Ok i understand but when i try with your attached fonts (ComicJensFreePro-Regular.ttf) in my Font object --> ttf=Font("ComicJensFreePro-Regular.ttf",15) i have the following error :

image

Can you help me please ?

Regards , Valentin

BNNorman commented 6 years ago

The error message last line says IOError: cannot open resource - which is computer speak for 'I can't find the font' (in this case)

Since the fonts are in a folder called Fonts and your main.py is invoked from the folder LEDAnimator you need to add '../Fonts' to your font file path.

ttf=Font("../fonts/ComicJensFreePro-Regular.ttf",fontSize) works for me. I get the same error as you if I leave off the ../Fonts/ from the start

ValDY69 commented 6 years ago

ok no exception now but i have absolutely no difference between ComicJensFreePro and FONT_HERSHEY_SIMPLEX

ValDY69 commented 6 years ago

ok my Bad , i haven't change the fontFace in Text object ...

BNNorman commented 6 years ago

Just what I figured. LOL.

ValDY69 commented 6 years ago

ok i close the issue thank you brian , you're the best 👍