Skip to content

Commit 7eddf9e

Browse files
committed
scale stroke_width if font_size is too small or too big
1 parent d3d4204 commit 7eddf9e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

manim/animation/creation.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,17 @@ def interpolate_submobject(
294294

295295

296296
class Write(DrawBorderThenFill):
297-
"""Simulate hand-writing a text-based mobject, such as :class:`~.Text`,
298-
:class:`~.MarkupText`, :class:`~.Tex`, :class:`~.MathTex`,
299-
or :class:`~.VMobject` in general.
297+
"""Simulate hand-writing a text-based mobject, such as :class:`~.Text`
298+
and :class:`~.Tex`, or simulate hand-drawing a :class:`~.VMobject`.
300299
301300
Parameters
302301
----------
303302
vmobject
304303
The VMobject to animate.
305304
stroke_width
306-
Stroke width for drawing. If not given, for SVG-based mobjects (such as :class:`Text`, :class:`MarkupText`, or :class:`MathTex`)
307-
the stroke width is scaled relative to the font size. Others use 2.0.
305+
Stroke width for drawing. If not provided, it is scaled based on font size
306+
for text-based mobjects when the font is very small or very large;
307+
otherwise defaults to 2.0.
308308
rate_func
309309
The function defining the animation progress.
310310
reverse
@@ -386,10 +386,14 @@ def _adjust_stroke_width_for_text(
386386
) -> float:
387387
if stroke_width is not None:
388388
return stroke_width
389-
if not isinstance(vmobject, SVGMobject):
390-
return 2.0 # default in DrawBorderThenFill
389+
if not isinstance(vmobject, SVGMobject) or vmobject.height == 0:
390+
return 2
391391
font_size = getattr(vmobject, "font_size", DEFAULT_FONT_SIZE)
392-
return (font_size / DEFAULT_FONT_SIZE) * DEFAULT_STROKE_WIDTH * scale_factor
392+
if font_size < 20 or font_size > 6 * DEFAULT_FONT_SIZE:
393+
# adjust stroke_width if font_size is too small or too big
394+
return (font_size / DEFAULT_FONT_SIZE) * DEFAULT_STROKE_WIDTH * scale_factor
395+
else:
396+
return 2
393397

394398
def reverse_submobjects(self) -> None:
395399
self.mobject.invert(recursive=True)

0 commit comments

Comments
 (0)