A community-maintained Python framework for creating mathematical animations.
Fix Text/MarkupText color argument not applied to mobject (#4817) (#5017)
Golitsin Vyacheslavdc59fd0f05e0
diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.pyindex d9477925b..7f52aa397 100644--- a/manim/mobject/text/text_mobject.py+++ b/manim/mobject/text/text_mobject.py@@ -547,6 +547,7 @@ class Text(SVGMobject):width=width,should_center=should_center,use_svg_cache=use_svg_cache,+ color=parsed_color,**kwargs,)self.text = text@@ -1257,6 +1258,7 @@ class MarkupText(SVGMobject):height=height,width=width,should_center=should_center,+ color=parsed_color,**kwargs,)diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.pyindex a94b587c8..00042a3e5 100644--- a/tests/module/mobject/text/test_text_mobject.py+++ b/tests/module/mobject/text/test_text_mobject.py@@ -5,6 +5,7 @@ from io import StringIOimport pytest+from manim import RED, WHITEfrom manim.mobject.text.text_mobject import MarkupText, Text@@ -62,3 +63,24 @@ def test_gen_chars_handles_spaces_with_disable_ligatures():chars = text._gen_chars()# One entry per character of the (whitespace-stripped) indexing text.assert len(chars) == len(text.text)+++def test_text_color_attribute_applied():+ """``Text``/``MarkupText`` should apply the ``color`` argument to the mobject itself.++ Regression test for #4817: the color was baked into the SVG glyphs but not+ propagated to the :class:`~.SVGMobject`, so ``get_color()`` reported black+ regardless of the ``color`` argument.+ """+ assert Text("test", color=WHITE).get_color() == WHITE+ assert Text("test", color=RED).get_color() == RED+ assert MarkupText("test", color=RED).get_color() == RED+ # the default color is white+ assert Text("test").get_color() == WHITE+++def test_text_color_does_not_break_t2c():+ """Per-character colors from ``t2c`` should still override the default color."""+ text = Text("ab", t2c={"a": RED})+ assert text.get_color() == WHITE+ assert [c.get_color() for c in text.chars] == [RED, WHITE]