Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TrueType and OpenType fonts #11

Open
BNNorman opened this issue Feb 28, 2018 · 11 comments
Open

Add support for TrueType and OpenType fonts #11

BNNorman opened this issue Feb 28, 2018 · 11 comments

Comments

@BNNorman
Copy link
Owner

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
Copy link

ValDY69 commented Mar 9, 2018

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

did you have any news ?

@BNNorman
Copy link
Owner Author

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
Copy link

ValDY69 commented Mar 13, 2018

ok brian amazing ! i will test it soon !

thank you

@ValDY69
Copy link

ValDY69 commented Mar 14, 2018

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
Copy link
Owner Author

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
Copy link

ValDY69 commented Mar 14, 2018

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
Copy link
Owner Author

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
Copy link

ValDY69 commented Mar 14, 2018

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

@ValDY69
Copy link

ValDY69 commented Mar 14, 2018

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

@BNNorman
Copy link
Owner Author

Just what I figured. LOL.

@ValDY69
Copy link

ValDY69 commented Mar 14, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants