Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions manim/mobject/svg/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def __init__(
)
self.move_into_position()

# Glyph submobjects are added after super().__init__ set self.z_index,
# so a z_index passed to the constructor never reached them. Propagate
# it so the whole SVG (e.g. Text/MathTex) shares one z_index. Guard with
# getattr since the OpenGL renderer does not track z_index as an attribute.
z_index = getattr(self, "z_index", None)
if z_index is not None:
for submob in self.get_family():
submob.z_index = z_index

def init_svg_mobject(self, use_svg_cache: bool) -> None:
"""Checks whether the SVG has already been imported and
generates it if not.
Expand Down
15 changes: 15 additions & 0 deletions tests/module/mobject/text/test_text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ def test_font_size():
assert round(markuptext_string.font_size, 5) == 14.4


def test_z_index_propagates_to_glyphs():
"""A z_index passed to the constructor must reach the glyph submobjects,
otherwise the z-ordering is ignored during rendering (see issue #4667).
"""
text = Text("AB", z_index=3)
assert text.z_index == 3
assert all(glyph.z_index == 3 for glyph in text.family_members_with_points())

markup = MarkupText("AB", z_index=3)
assert all(glyph.z_index == 3 for glyph in markup.family_members_with_points())

# The default must remain unchanged.
assert all(glyph.z_index == 0 for glyph in Text("AB").family_members_with_points())


def test_font_warnings():
def warning_printed(font: str, **kwargs) -> bool:
io = StringIO()
Expand Down
Loading