Skip to content

Use Manimpango #878

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

Merged
merged 16 commits into from
Dec 31, 2020
Merged

Use Manimpango #878

merged 16 commits into from
Dec 31, 2020

Conversation

naveen521kk
Copy link
Member

@naveen521kk naveen521kk commented Dec 23, 2020

Motivation

Stop of pangocffi, pangocairocffi and cairofffi.
Use Manimpango instead.
The problem started with cairocffi, stating that it wouldn't be maintained in future Kozea/cairocffi#173 (comment)
Created a custom binding for Pango which seems to work, also fixes installation issues on Windows(:wink:). The only thing which doesn't work for now is the newly made MarkupText(sorry @PhilippImhof ). I will try to fix that soon. Need new tests for this though, removed the old ones.
Need to check the docs whether things work correctly.

Oneline Summary of Changes

- Use custom bindings for Pango (:pr:`PR NUMBER HERE`)

Testing Status

Worked as expected on my machine.

Acknowledgements

Reviewer Checklist

  • Newly added functions/classes are either private or have a docstring
  • Newly added functions/classes have tests added and (optional) examples in the docs
  • Newly added documentation builds, looks correctly formatted, and adds no additional build warnings
  • The oneline summary has been included in the wiki

@naveen521kk
Copy link
Member Author

I suspect one of the dependency has published wrong wheels or something and because of that, there is a segmentation fault of MacOS 3.8 and 3.7 need to investigate. And I don't think it is because of Github Actions update.

@PhilippImhof
Copy link
Member

The only thing which doesn't work for now is the newly made MarkupText(sorry @PhilippImhof ). I will try to fix that soon.

AFAICS MarkupText does not use other methods from Pango / Cairo than Text, so I would say there is no reason why MarkupText could not work with it. (I see that you changed the names of the old methods, but that should be easy to fix.)

@PhilippImhof
Copy link
Member

I can confirm that this works fine on Mac OS Catalina with Python 3.9 and Pango 1.48 installed

@naveen521kk
Copy link
Member Author

I can confirm that this works fine on Mac OS Catalina with Python 3.9 and Pango 1.48 installed

I have just released it. It will take some time for wheels to build and uploaded to PyPi. After that, poetry.lock needs to be updated.

@naveen521kk naveen521kk marked this pull request as ready for review December 27, 2020 06:29
@naveen521kk naveen521kk requested a review from leotrs December 27, 2020 06:29
@naveen521kk
Copy link
Member Author

This is ready for Review.

@behackl
Copy link
Member

behackl commented Dec 29, 2020

I've played around with this a little, some observations (I'm on Ubuntu):

  • When working directly from the interpreter, I get
>>> from manim import *
>>> Text("asdf")
[12/29/20 13:27:54] INFO     Text now uses Pango for rendering. In case of problems, the old implementation is available as CairoText.                                                                                      text_mobject.py:717
Fontconfig error: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 72: non-double matrix element
Fontconfig error: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 72: non-double matrix element
Fontconfig warning: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 80: saw unknown, expected number
Text('asdf')

and the same thing for MarkupText. This also creates a directory fontconfig in my current working directory with many files in it.

  • Trying to use Code leads to an error:
$ manim av.py TextTest -qm
[12/29/20 13:34:01] INFO     Text now uses Pango for rendering. In case of problems, the old implementation is available as CairoText.                                             text_mobject.py:717



Traceback (most recent call last):
  File "/home/behackl/code/manim/manim/__main__.py", line 95, in main
    scene.render()
  File "/home/behackl/code/manim/manim/scene/scene.py", line 165, in render
    self.construct()
  File "av.py", line 5, in construct
    c = Code("./ag.py")
  File "/home/behackl/code/manim/manim/mobject/svg/code_mobject.py", line 188, in __init__
    self.code = self.gen_colored_lines()
  File "/home/behackl/code/manim/manim/mobject/svg/code_mobject.py", line 316, in gen_colored_lines
    stroke_width=self.stroke_width,
  File "/home/behackl/code/manim/manim/mobject/svg/text_mobject.py", line 441, in __init__
    self.lines_text = Text(lines_str, **config)
  File "/home/behackl/code/manim/manim/mobject/svg/text_mobject.py", line 759, in __init__
    file_name = self.text2svg()
  File "/home/behackl/code/manim/manim/mobject/svg/text_mobject.py", line 964, in text2svg
    self.text,
  File "cmanimpango.pyx", line 234, in manimpango.cmanimpango.text2svg
  File "/usr/lib/python3.7/xml/sax/saxutils.py", line 27, in escape
    data = data.replace("&", "&")
TypeError: a bytes-like object is required, not 'str'

This is from trying to run

from manim import *

class TextTest(Scene):
    def construct(self):
        c = Code("./ag.py")
        self.play(ShowCreation(c))

which simply uses

from manim import *

class SimpleScene(Scene):
    def construct(self):
        s = Square()
        self.play(ShowCreation(s))

as ag.py.

  • Simply using Text seems to work just fine, great job!!

@naveen521kk
Copy link
Member Author

Oh! I didn't notice that. I see where the bug is. I will quickly patch it, in an hour or so. Meanwhile, this time after update, there would be a different wheel released for linux which latest Pango version. I will also update this PR so that it uses that version as the minimum one.

@naveen521kk
Copy link
Member Author

Also, I will update the docs about loading from a TTF file, also specify it is only available for linux.

@naveen521kk
Copy link
Member Author

naveen521kk commented Dec 29, 2020

Also, I think @behackl would need to update the docker image so that this wheel for ManimPango works. I have tested this on default python file but it fails on slim version of the same docker image. Either we should try fixing it or use python default as our base image.

@behackl
Copy link
Member

behackl commented Dec 29, 2020

Also, I think @behackl would need to update the docker image so that this wheel for ManimPango works. I have tested this on default python file but it fails on slim version of the same docker image. Either we should try fixing it or use python default as our base image.

Good to know, thank you. I'll investigate docker a bit later.

@naveen521kk
Copy link
Member Author

Also, when can it be merged? Before or after this month's release?

@naveen521kk
Copy link
Member Author

This PR is ready. Just some docs on Linux only feature of font from file is remaining.
I would like to merge this before the release. Because without this it will be another solving the horrible DLL HELL for another month 😨

@kolibril13 kolibril13 added this to the Release v0.2.0 milestone Dec 30, 2020
@kolibril13
Copy link
Member

I just tested this branch on Ubuntu 20.04.
Text works, and also when I run it from the python console

>>> from manim import *
>>> Text("Hello")
[12/31/20 10:09:17] INFO     Text now uses Pango for         text_mobject.py:716
                             rendering. In case of problems,                    
                             the old implementation is                          
                             available as CairoText.                            

I do not get any errors.
Further, also the Code example from @behackl works now on my machine:

TextTest.mp4

@behackl
Copy link
Member

behackl commented Dec 31, 2020

A bit late, but I still managed: I've looked into potential issues with docker, found that our Dockerfile does not require the workaround for generating the ffi bindings any longer (removed via ad9fa7e), and then tested the Code example from above. I did need to pass font="Monospace" to Code, but the fact that docker manages to render this as

CodeTest.mp4

is very good; no further adaptions seem to be required.

I'm positively leaning towards merging this before the release, I'll test it some more before approving.

@behackl
Copy link
Member

behackl commented Dec 31, 2020

I've updated the troubleshooting page via cdb9178.

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the fact that this

  • (has the potential to) significantly simplify the installation procedure and free us from pango-related issues (especially for Windows users),
  • replaces an interface that will not be maintained any longer soon,
  • and works really well,

I will go ahead and approve this, with the intention of merging it before the release. I do believe that this time around, the switch will be smoother than when switching from CairoText to PangoText -- but in case something seriously breaks, nothing stops us from releasing a bugfix version earlier than our usual release schedule.

@naveen521kk
Copy link
Member Author

Let both CairoText and ManimText be there as it is and can be seen in next release.
I'm merging this.

@naveen521kk naveen521kk merged commit fe2ba6d into ManimCommunity:master Dec 31, 2020
@naveen521kk naveen521kk deleted the manimpango branch December 31, 2020 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants