python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.29k stars 2.23k forks source link

Unable to render Tibetan unicode sign #6601

Closed orinciog closed 2 years ago

orinciog commented 2 years ago

What did you do?

I'm trying to render an image that contains a Tibetan sign (\u0F1D). I tried a lot of fonts, none are working. For this sign, all fonts output a rectangle. I tried also the font that is used in LibreOffice Writer to output the sign (Lohit-Devanagari.ttf). In LibreOffice is ok, in python is not ok.

What did you expect to happen?

I expect to create an image with the sign \u0F1D (https://www.compart.com/en/unicode/U+0F1D)

What are your OS, Python and Pillow versions?

from PIL import Image, ImageDraw, ImageFont, ImageFilter

#configuration
font_size=36
width=500
height=100
back_ground_color=(255,255,255)
font_size=36
font_color=(0,0,0)
unicode_text = u"\u0F1D" + u"\u2606" + u"It works"

im  =  Image.new ( "RGB", (width,height), back_ground_color )
draw  =  ImageDraw.Draw ( im )
#insert whatever font - including Lohit-Devanagari.ttf
unicode_font = ImageFont.truetype("DejaVuSans.ttf", font_size)
draw.text ( (10,10), unicode_text, font=unicode_font, fill=font_color )

im.save("text.jpg")

The output from Python is text

The output from Libre Office Writer is (CTRL+shift+U -> u0f1d and enter): Screenshot from 2022-09-19 19-45-53

Thank you

orinciog commented 2 years ago

I also tested with symbola.ttf, font shown in: https://apps.timwhitlock.info/unicode/inspect?s=%E0%BC%9D%E2%98%86It+works

Unicode viewer: Screenshot 2022-09-20 at 15-38-59 Unicode character inspector ༝☆It works

Python: text

radarhere commented 2 years ago

Trying TibetanMachineUni.ttf, I was able to generate text

orinciog commented 2 years ago

Thank for your comment, but that font does not render other symbols: for example the star, as your picture already shows. What I want to do is to create an image from some Twitter display names, which can contain arbitrary symbols and emoji.

The question was actually why Pillow does not render symbols that the font knows about it. (From what I know, Symbola.ttf actually can render all unicode symbols, but with Pillow some special symbols are not rendered).

radarhere commented 2 years ago

I've tried inspecting symbola.ttf and Lohit-Devanagari.ttf with https://fontdrop.info/ and https://github.com/fonttools/fonttools - I don't think they have "Tibetan Sign Rdel Nag Gcig"

From what I know, Symbola.ttf actually can render all unicode symbols

I don't think that is correct.

It doesn't look like you can change the font for https://apps.timwhitlock.info/unicode/inspect, but for Libre Office Writer, here is a screenshot I put together, after copying and pasting in characters, and changing the font to 'Times New Roman'. I hope this demonstrates that your earlier screenshot doesn't show conclusively that Lohit Devanagari has those characters.

Screen Shot 2022-09-21 at 11 14 06 pm

Furthermore, if I go into the Insert menu, and into 'Special Character...', U+0F1D shows as a 'Missing Character'.

Screen Shot 2022-09-21 at 11 21 14 pm
radarhere commented 2 years ago

If you are interested in combining multiple fonts to cover more character ranges, see #4808 as an open request for a new feature to allow different fonts to be used based on whether or not characters are missing.

The beginning of that request states that this feature would be

Similarly to how web browsers work when they are missing characters from fonts - the OS fills that void from a default font.

orinciog commented 2 years ago

Thank you very much for such a deep debugging. Indeed, I was incorrect in my assumptions and I'm sorry.

I will try to merge multiple fonts in order to render as many as possible chars. (For that particular sign, it is ok with TibetanMachineUni.ttf)

Again, thank you.