3b1b / manim

Animation engine for explanatory math videos
MIT License
70.71k stars 6.22k forks source link

Bengali and Assamese characters showing improperly after following #680 to use PC fonts. #1015

Open Ayan2357 opened 4 years ago

Ayan2357 commented 4 years ago

If this is a support request:

Please attempt to solve the problem on your own before opening an issue. Between old issues, StackOverflow, and Google, you should be able to find solutions to most of the common problems.

Include at least:

  1. Steps to reproduce the issue (e.g. the command you ran)
  2. The unexpected behavior that occurred (e.g. error messages or screenshots)
  3. The environment (e.g. operating system and version of manim)

If this is a feature request:

Include the motivation for making this change.

Ayan2357 commented 4 years ago

For instance, if I intend to animate বাংলা লেখা (look closely at the output), what I get is বাংলা লখো. Most of the times it spits out absolutely meaningless words.

script = '''এনেদৰে ''' class FirstScene(Scene): def construct(self): text=Text(script,font="Kalpurush" ) self.play(Write(text))
A sample code where the error occurs

kyoobey commented 4 years ago

this issue already exists #1012 please close the duplicate

workaround for now

see updated code below

Ayan2357 commented 4 years ago

@tshrpl where am i to paste it ?

kyoobey commented 4 years ago
# testing script
script = """বয়লারপ্লেট পাঠ্য বা সহজভাবে বয়লারপ্লেট হ'ল
এমন কোনও লিখিত পাঠ্য (অনুলিপি) যা মূল ক্ষেত্রে উল্লেখযোগ্য পরিবর্তন
ছাড়াই নতুন প্রসঙ্গে বা অ্যাপ্লিকেশনগুলিতে পুনরায় ব্যবহার করা
যেতে পারে। শব্দটি বিবৃতি, চুক্তি এবং কম্পিউটার কোডের
প্রসঙ্গে ব্যবহৃত হয় এবং মিডিয়াতে হ্যাকনিয়েড বা অনিয়মিত
লেখার জন্য ব্যবহৃত হয়।"""

class bangla_3(Scene):
    def construct(self):
        text1 = Assamese_Text(script).scale(0.5).set_color_by_gradient(BLUE, RED)
        self.play(Write(text1))
        self.wait()

# not heavily tested
class Assamese_Text(Text):
    CONFIG = {
        'font': 'Akaash'     # put a bangla/assamese font which is installed
    }
    _bytes = {                          # replace multiple byte versions (left) with single byte ones (right)
        'য়': 'য়',
        'ড়': 'ড়'
    }
    _left_side_chars = ['ে', 'ি']         # bengali/assamese chars which are written on right but displayed on left

    def __init__(self, text, **args):
        text = self.format(text)
        super(Assamese_Text, self).__init__(text, **args)

    def format(self, s):
        for i,j in self._bytes.items():
            s = s.replace(i, j)                 # replace the two byte one with single byte version
        s = list(s)
        for i in range(1, len(s)):
            if s[i] in self._left_side_chars:
                s[i-1], s[i] = s[i], s[i-1]
        return ''.join(s)
kyoobey commented 4 years ago

bangla_3

Ayan2357 commented 4 years ago

@tshrpl Check the very first word. It does not completely match with what it is meant to be

Ayan2357 commented 4 years ago

বয়লারপ্লেট, উল্লেখযোগ্য, অ্যাপ্লিকেশনগুলিতে.....these words are completely different than the input. Even without the code you inserted, they appear wrongly.

kyoobey commented 4 years ago

@Ayan2357 I asked my bangali friend to proofread he text presented here ........ she told me that the output is absolutely correct syntactically

প্লে roughly means e + P (half) + L and the line bellow P means that it should be interpreted as half P, but this approach is considered outdated for some reason in bangla community ..... nonetheless this syntax in not invalid

but they appear wrong because they were written by google translator ...... also the code is very incomplete ......... i.e. you have to find the errors yourself and make changes in the code ..... I can't do that for you because I don't know bengali

Ayan2357 commented 4 years ago

@tshrpl I am a bit confused about what you meant. I tried out some words written by myself, not through google translator but i still got same errors. Just so that i get a little glimpse of what i need to work on can you just render প্লে in Manim so i get an idea of how to proceed.

Ayan2357 commented 4 years ago

@tshrpl Another observation of mine is that when i try to use tex works based on miktex, those words come out perfectly as desired but when rendered with manim it shows the wrong output.

Ayan2357 commented 4 years ago

\documentclass[preview]{standalone}

\usepackage{amsmath} \usepackage{amssymb} \usepackage{dsfont} \usepackage{setspace} \usepackage{tipa} \usepackage{relsize} \usepackage{textcomp} \usepackage{mathrsfs} \usepackage{calligra} \usepackage{wasysym} \usepackage{ragged2e} \usepackage{physics} \usepackage{xcolor} \usepackage{textcomp} \usepackage{microtype} %\DisableLigatures{encoding = , family = } \usepackage[UTF8]{ctex}

\usepackage{polyglossia} \setmainlanguage[numerals=Devanagari]{bengali} \setotherlanguage{english} \newfontfamily\englishfont[Scale=MatchLowercase]{Cambria} \newfontfamily\bengalifont[Script=Bengali]{Kalpurush}

\begin{document}

বয়লারপ্লেট

\end{document} Screenshot (8)

xy-23 commented 4 years ago

The reason Bengali and Assamese characters showing improperly is that Text is using cairo as its text layout engine, which can't handle those languages correctly. Currently I'm trying to switch cairo into pango, which can layout those languages properly. But this takes time. Because in order to use pango, I need to wait a another python package called cairocffi to publish a new release. And other annoying staffs need to be adapted. I estimate that I can finish this in the next year. So until that, you probably need to use other softwares like Adobe Illustrator to generate the text svg and let SVGMobject to handle that. Or using LaTeX