Skip to content

Update :class:~.Text to use new ManimPango color setting #2341

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 14 commits into from
Jan 3, 2022

Conversation

marcin-serwin
Copy link
Collaborator

@marcin-serwin marcin-serwin commented Nov 29, 2021

Overview: What does this pull request change?

  • :class:~.Text class now uses color setting introduced in ManimPango 0.4.0 for color and gradient.

Motivation and Explanation: Why and how do your changes improve the library?

Fixes #2330

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@naveen521kk
Copy link
Member

Did you check disable_ligature flag?

@marcin-serwin
Copy link
Collaborator Author

Did you check disable_ligature flag?

I haven't and there is indeed an issue with it, but easily fixable. What's harder to fix are the ligatures themselves, since when they are present there is no way for manim to know which glyph corresponds to which letter(s) of the text. E.g. this code

class Test(Scene):
    def construct(self):
        self.add(Text("fitext",
                      t2c={"fi": RED},
                      disable_ligatures=False))

results in
fitext
because method Text.find_indexes doesn't know that fi is a single glyph. This can be fixed by passing color information directly to pango instead of setting it later, but it requires changing ManimPango to support it. I'll try to open a PR there soon, and set this to DRAFT until it is finished.

@naveen521kk
Copy link
Member

Do you know any reason why macOS tests hangs https://github.com/ManimCommunity/manim/runs/4499349852?check_suite_focus=true#step:18:23? Is it something related to ManimPango?

@marcin-serwin
Copy link
Collaborator Author

Do you know any reason why macOS tests hangs https://github.com/ManimCommunity/manim/runs/4499349852?check_suite_focus=true#step:18:23? Is it something related to ManimPango?

I don't know. I don't own a Mac and the github CI message is cryptic. I've tried removing test I added, but it shouldn't break it, since the test is not even run on MacOS.

@naveen521kk
Copy link
Member

@ManimCommunity/macos Can anyone confirm whether this PR works on macOS and the recent version of ManimPango works correctly/doesn't crash?

@PhilippImhof
Copy link
Member

Just tried it on my machine (Python 3.9.7, ManimPango 0.4.0, Manim Community v0.13.1 from this PR).

Result:
Test_ManimCE_v0 13 1

@marcin-serwin
Copy link
Collaborator Author

marcin-serwin commented Dec 14, 2021

@PhilippImhof Do tests pass?

@PhilippImhof
Copy link
Member

Just tried. First, I had a crash, similar to the tests in CI. Checking the output, I modified /manim/tests/test_scene_rendering/opengl/test_opengl_renderer.py:

@pytest.mark.skip(msg="Temporarily skip due to failing in Mac CI")
def test_force_window_opengl_render_with_format(
    using_temp_opengl_config,
    force_window_config_pngs,
    disabling_caching,
):
    """force_window creates window when format is set"""
    scene = SquareToCircle()
    renderer = scene.renderer
    renderer.update_frame = Mock(wraps=renderer.update_frame)
    scene.render()
    assert renderer.window is not None
    renderer.window.close()

Now I have

FAILED tests/test_graphical_units/test_opengl.py::test_Circle - AssertionError: 
FAILED tests/test_graphical_units/test_threed.py::test_Axes - AssertionError: 
 2 failed, 557 passed, 3 skipped, 7 xfailed, 2 xpassed, 224 warnings in 476.46s (0:07:56) 

So no failing tests related to this PR and the crash is due to OpenGL, but I cannot say more, because I am absolutely not into that.

@naveen521kk
Copy link
Member

So no failing tests related to this PR and the crash is due to OpenGL, but I cannot say more, because I am absolutely not into that.

Hmm, does that mean the recent update in ManimPango (at least macOS binary wheels) caused this? Can you confirm that by building manimpango from source and installing it in your venv and then running tests? (run poetry run pip install ManimPango==0.4.0 --force --no-binary :all: --no-cache).

@naveen521kk
Copy link
Member

Also, do you reproduce this test failure/crash when running in the main branch?

@PhilippImhof
Copy link
Member

PhilippImhof commented Dec 14, 2021

Running the tests on main does not cause any errors, except for the same two tests that fail. (But no problems with OpenGL renderer). That is with ManimPango 0.3.0.

Doing poetry run pip install ManimPango==0.4.0 --force --no-binary :all: --no-cache and running the tests again, I get the same result. But I am not sure it is correct, because poetry show says manimpango 0.3.0, but pip says Successfully installed ManimPango-0.4.0. @naveen521kk: Does poetry show actually check the installed version or does it just repeat what is written in the lock file? I checked with pip show manimpango and it confirms version 0.4.0 is installed.

So just to be sure, I changed the dependencies for ManimPango to 0.4.0 and updated the packages. Now poetry show gives me manimpango 0.4.0 and the tests run fine, except for test_opengl.py::test_Circle and test_threed.py::test_Axes again.

Thus, I would say that ManimPango is not the culprit.

@PhilippImhof
Copy link
Member

I can see CI tests are still failing for Mac OS. However, on my machine all tests are passing, except for the unrelated test_opengl.py::test_Circle and test_threed.py::test_Axes.

@marcin-serwin marcin-serwin force-pushed the t2c-bug branch 6 times, most recently from f299c24 to b4d6c34 Compare December 24, 2021 00:24
@marcin-serwin
Copy link
Collaborator Author

marcin-serwin commented Dec 24, 2021

@naveen521kk It took a while, but I've managed to pinpoint the problem. It's the wheels of ManimPango 0.4.0 for macos. As you can see after modifying files to build ManimPango from sources the macos tests pass (windows fails but this is unimportant). I don't have any experience with wheels, do you have any idea what could cause the problem?

@naveen521kk
Copy link
Member

It's the wheels of ManimPango 0.4.0 for macos. As you can see after modifying files to build ManimPango from sources the macos tests pass (windows fails but this is unimportant). I don't have any experience with wheels, do you have any idea what could cause the problem?

Ah, I see. I thought the same. On ManimCommunity/ManimPango#68 I have changed the macOS to statically link with Pango and for some reason, it crashes here. I think reverting that change would be easier than actually debugging why it crashes here. I work on doing that soon. Thanks for investigating.

@PhilippImhof
Copy link
Member

With @naveen521kk's changes from ManimCommunity/ManimPango#71 the problem will most certainly be solved. Well done!

@naveen521kk
Copy link
Member

A new version is released(0.4.0.post0) and you can test it by upgrading to it. If that works, I would like this to be included in this months release #2411. Sorry for the delay!

@marcin-serwin marcin-serwin force-pushed the t2c-bug branch 2 times, most recently from 3df473f to df3b73d Compare January 1, 2022 16:38
@PhilippImhof
Copy link
Member

Tests are now working fine on Mac, problem solved. IMHO this should now be marked as ready for review. Thanks for the work!

Oh and...Happy New Year!

@PhilippImhof
Copy link
Member

Any ideas why there is an error in the Linux tests now? IIRC all tests passed before, except for Mac where they crashed...

@marcin-serwin
Copy link
Collaborator Author

Any ideas why there is an error in the Linux tests now? IIRC all tests passed before, except for Mac where they crashed...

I think some new tests were added that exposed a bug in my current implementation. I'm trying to fix it now.

@marcin-serwin marcin-serwin changed the title Find indexes in stripped text, not original text Update Text to use new ManimPango color setting Jan 1, 2022
@marcin-serwin marcin-serwin marked this pull request as ready for review January 1, 2022 17:31
@@ -594,55 +590,137 @@ def set_color_by_t2c(self, t2c=None):
"""Internally used function. Sets color for specified strings."""
t2c = t2c if t2c else self.t2c
for word, color in list(t2c.items()):
for start, end in self.find_indexes(word, self.original_text):
for start, end in self.find_indexes(word, self.text):
self.chars[start:end].set_color(color)

def set_color_by_t2g(self, t2g=None):
Copy link
Member

Choose a reason for hiding this comment

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

Is this function used anywhere else? If not you can deprecate it or rather remove it. Same for set_color_by_t2c

Copy link
Member

@naveen521kk naveen521kk left a comment

Choose a reason for hiding this comment

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

LGTM other than the comment above

Copy link
Member

@naveen521kk naveen521kk left a comment

Choose a reason for hiding this comment

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

lgtm now

@naveen521kk naveen521kk merged commit 540dc70 into ManimCommunity:main Jan 3, 2022
@naveen521kk naveen521kk added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Jan 3, 2022
@behackl behackl changed the title Update Text to use new ManimPango color setting Update :class:~.Text to use new ManimPango color setting Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text - Changing colors, styles, etc does not work as expected
3 participants