Reputation: 35750
I'm rendering user input text on a background image with Python PIL(I'm using pillow).
the code is simple:
draw = ImageDraw.Draw(im)
draw.text((x, y), text, font=font, fill=font_color)
the problem is, the user may input in any language, how could I determine which font
to use?
ps: I know I have to have font files first, so I searched and found Google Noto, downloaded all the fonts, put them in /usr/local/share/fonts/
, but these fonts are separated by language, so I still can't load a font that can render all user input texts.
Upvotes: 4
Views: 2943
Reputation: 53617
NoTo (which is literally just Adobe's Source Pro fonts with a different name because it's easier for Google to market it that way) isn't a single font, it's a family of fonts. When you go to download them, Google explicitly tells you that there are lots of different versions for lots of different target languages, for the two simple reasons that:
℃
can actually be the letter C
and the symbol °
, so it relies on three glyphs: two real glyphs, and one virtual composition. You run out of space real fast that way) , andSo the proper solution is to grab all the fonts, and then pick the right one based on the {script, language}
pair you're generating text for. Is that more complicated than what you're trying to do? Yes. Is it necessary? Equally yes =)
Upvotes: 6