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

Unable to render Tibetan unicode sign #6601

Closed
orinciog opened this issue Sep 19, 2022 · 6 comments
Closed

Unable to render Tibetan unicode sign #6601

orinciog opened this issue Sep 19, 2022 · 6 comments

Comments

@orinciog
Copy link

orinciog commented Sep 19, 2022

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?

  • OS: Ubuntu 20.04
  • Python: 3.8.10
  • Pillow: 9.2.0
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
Copy link
Author

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

Trying TibetanMachineUni.ttf, I was able to generate
text

@orinciog
Copy link
Author

orinciog commented Sep 21, 2022

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

radarhere commented Sep 21, 2022

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

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

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.

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

No branches or pull requests

2 participants