Added FreeTypeFont has_characters()
Resolves #9158. The issue requested a method to check if glyphs are present in a font. This question has arisen previously in https://github.com/python-pillow/Pillow/issues/7380#issuecomment-1708041463, and I think this would also help users from #4808, in a less elegant way.
This adds FreeTypeFont.has_characters(text). I expect that the issue was only thinking about checking a single character at a time, but if user wanted to check multiple characters at once, I don't see any reason not to let them. If any character in the string is missing, then False is returned.
The C code in here is based on https://github.com/python-pillow/Pillow/blob/9d39fe6adac233ccd26ba20bff9adda53a1ec89d/src/_imagingft.c#L432-L463
I'm on the fence with this. It feels outside the core focus of Pillow, and it's not too tricky to do this with Pillow in Python:
https://github.com/python-pillow/Pillow/issues/9158#issuecomment-3194350459
Plus it's a even easier with a dedicated FreeType library:
https://github.com/python-pillow/Pillow/issues/9158#issue-3328268124
A font is roughly a collection of images and checking if an image exists in the collection is pretty basic functionality?
Of course it's doable in other ways but:
- The pillow way suggested is verbose and inefficient.
- The freetype way requires loading the font twice (once in Pillow, once in Freetype).