2

Currently I am Working on a Kivy desktop application but I am facing a problem while trying to display unicode characters in Bengali in my application's Label and Button Text. Every time I'm getting output like the image below. I have tried different fonts such as SolaimanLipi.ttf, kalpurush.ttf, NikoshBAN.ttf but still no luck. I am using a Windows PC. The same text in the same font displays correctly outside of Kivy; it works fine in all text editors and to make sure I have tested in a Java Swing desktop application, too.

Can any one please describe what is the problem? What can i do to solve it?

Expected Output:

correctly rendered sakālē

Program Output:

incorrect rendering

        #-- coding: utf-8 --

        from kivy.base import runTouchApp
        from kivy.lang import Builder

        runTouchApp(Builder.load_string("""
        #:import sp kivy.metrics.sp
        Label:
            text: 'সকালে'
            font_size: sp(50)
            font_name: "SolaimanLipi.ttf"    
        """))
tripleee
  • 175,061
  • 34
  • 275
  • 318
Shakib Ahmed
  • 87
  • 1
  • 9
  • So the problem is that the last two letters are swapped, correct? – lenz Jul 23 '20 at 05:53
  • Or to be more precise: they are displayed in strict left-to-right order wrt. to the order of the codepoints in the string, which is not the correct placement according to the orthography rules, right? Maybe the typesetting algorithm of kivy is not fancy enough... – lenz Jul 23 '20 at 05:57
  • No, depends on the unicode character. – Shakib Ahmed Jul 23 '20 at 05:59
  • May be u r right about typesetting algorithm, But now how can i solve this problem? Is this problem is all about font or kivy can not render unicode – Shakib Ahmed Jul 23 '20 at 06:05
  • I don't know, but I think it's important to more accurately describe the problem, also in the title (increases your chances to get help). The problem is not just "Unicode" or "font", as you clearly have Bengali letters in the output, not boxes or question marks. – lenz Jul 23 '20 at 06:17
  • Did you specify the correct language somewhere? Fonts will display (and "merge") letters, according to language (many Western people are surprised about this, because it is not very noticeable [on good fonts], or there is no differences [on generic fonts]). – Giacomo Catenazzi Jul 23 '20 at 06:59
  • Didn't found any docs about specifying Language in Kivy. That's why didn't apply that. – Shakib Ahmed Jul 23 '20 at 07:02
  • Does the same text in the same font display correctly outside of Kivy? – tripleee Jul 23 '20 at 07:29
  • Yes, It works fine all text editors and to make sure I have tested in Java Swing desktop application, it works fine in same windows pc – Shakib Ahmed Jul 23 '20 at 07:32
  • 1
    Do the same rendering rules apply in other languages which use Devanagari script? I.e. does the same glyph combination occur e.g. in Hindi, and if so, does it render the same in that language? (It would help us Western illiterates if you could name the glyphs, and explain how the rendering is wrong.) – tripleee Jul 23 '20 at 07:34
  • FWIW Google Translate transcribes this word as **sakālē** and translates it as *in the morning.* – tripleee Jul 23 '20 at 07:52
  • Yes ," in the morning" we call it in Bengali "সকালে" – Shakib Ahmed Jul 23 '20 at 08:05
  • You can find the solution for Windows and Linux environments for properly rendering Bangla (and other non-english) fonts in Kivy in the answers I have provided in https://stackoverflow.com/questions/63646050/kivy-isnt-showing-bengali-joining-character-properly/63668449#63668449 – amras Sep 06 '20 at 15:15

2 Answers2

0

There is a bug in Kivy which has been open since 2014 (!) - https://github.com/kivy/kivy/issues/2669

To the extent that I can understand the discussion and the current status, the developer is looking for a solution still.

Languages such as Tamil require reshaping, a process which is not supported in our current providers. I'm working on a new text provider using Pango as an option to provide this support on Linux (and probably OSX).

-- kived in 2014

This (from 2017) seems relevant, too, but also vaguely stale: https://github.com/kivy/kivy/issues/4902

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Still no solution since 2014??? kivy uses Pango backend default right?? – Shakib Ahmed Jul 23 '20 at 10:22
  • I'm not familiar enough with Kivy to tell whether you can work around this somehow. It looks like they are still not using Pango, but I could be wrong. To my understanding, you'd have to recompile or otherwise reassemble Kivy itself to use Pango. The patch in the second bug report is probably no longer possible to apply directly, but should give you a general idea at least. – tripleee Jul 23 '20 at 11:21
0

Unicode text can be converted to Bijoy (ANSI) text and can be used easily in Kivy with the use of [font] tag like this:

text = "[font=font/SutonnyMJ]Avwg evsjvq K_v ewj[/font] means I speak Bangla"

This repo provides code and instructions related to Unicode to Bijoy (ANSI) conversion in Kivy. Not a perfect solution, but most of the apps will meet their need.

sarwar47
  • 174
  • 1
  • 1
  • 9