Help requested for for Devanagri fonts in Python GUIs

96 views
Skip to first unread message

Gaurav Trivedi

unread,
Oct 14, 2020, 9:38:32 PM10/14/20
to sanskrit-programmers
Hi Everyone:

I was wondering if anyone here had some experience with using Devanagari with Python GUI libraries. Here are some open issues in popular frameworks that provide more details:
Thanks,

Gaurav

Shreevatsa R

unread,
Oct 14, 2020, 11:46:27 PM10/14/20
to sanskrit-programmers
I don't have any experience myself, but my understanding is that, as the linked issues say, you need to ultimately use something like Harfbuzz for text shaping (possibly via a layer like Pango).

FWIW, I tried the default tkinter library that comes with Python, using the first tutorial I found online, and it seems to work fine:

>>> import tkinter as tk
>>> window = tk.Tk()
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
>>> greeting = tk.Label(text="Hello, Tkinter")
>>> greeting.pack()
>>> greeting2 = tk.Label(text="विद्या")
>>> greeting2.pack()

(I picked विद्या because it contains both a short-i vowel sign, and a d-y conjunct.) Result:

image.png


So it may be the fancier GUI libraries that are broken.

Also the Pillow link says it should work with libraqm installed, but I haven't tried it.


--
You received this message because you are subscribed to the Google Groups "sanskrit-programmers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sanskrit-program...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sanskrit-programmers/796c6734-906d-4751-ba4b-43a55cfe4261n%40googlegroups.com.

Ram Kosuru

unread,
Oct 15, 2020, 1:14:23 PM10/15/20
to sanskrit-programmers
I do not know much about the background ; but the following may be useful. Consider adding layout_engine parameter (I found this in stack overflow discussion forum)
you need to add raqm module:  apt-get install libaqm-dev

img = Image.new('RGBA', (100, 70), color = (73, 109, 137))

fnt = ImageFont.truetype('sahadeva.ttf', 15, layout_engine=ImageFont.LAYOUT_RAQM)
d = ImageDraw.Draw(img)
#d.text((10,10), u"यात्रा ", font=fnt, fill=(255, 255, 0))
d.text((10,10), "यात्रा ऋच्छति", font=fnt, fill=(255, 255, 0))
img.save('pil_text_font.png')

A question I have is: can I do reverse programmatically: if I have .png with devanagari and english text can I get text back? 

Best.
-Ram

Reply all
Reply to author
Forward
0 new messages