Skip to content

Commit a0786b4

Browse files
committed
scale stroke_width if font_size is too small or too big
1 parent 4e49e91 commit a0786b4

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

manim/animation/creation.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def construct(self):
9494
from ..animation.animation import Animation
9595
from ..animation.composition import Succession
9696
from ..mobject.mobject import Group, Mobject
97+
from ..mobject.svg.svg_mobject import SVGMobject
9798
from ..mobject.types.vectorized_mobject import VMobject
9899
from ..utils.bezier import integer_interpolate
99100
from ..utils.rate_functions import double_smooth, linear
@@ -293,9 +294,8 @@ def interpolate_submobject(
293294

294295

295296
class Write(DrawBorderThenFill):
296-
"""Simulate hand-writing a text-based mobject, such as :class:`~.Text`,
297-
:class:`~.MarkupText`, :class:`~.Tex`, :class:`~.MathTex`,
298-
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`.
299299
300300
Parameters
301301
----------
@@ -344,7 +344,6 @@ def __init__(
344344
reverse: bool = False,
345345
**kwargs,
346346
) -> None:
347-
self._typecheck_input(vmobject)
348347
run_time: float | None = kwargs.pop("run_time", None)
349348
lag_ratio: float | None = kwargs.pop("lag_ratio", None)
350349
run_time, lag_ratio = self._set_default_config_from_length(
@@ -387,17 +386,14 @@ def _adjust_stroke_width_for_text(
387386
) -> float:
388387
if stroke_width is not None:
389388
return stroke_width
390-
if vmobject.height != 0:
391-
# if the height is zero, accessing font_size causes ZeroDivisionError
392-
font_size = getattr(vmobject, "font_size", DEFAULT_FONT_SIZE)
393-
if font_size < 20 or font_size > 6 * DEFAULT_FONT_SIZE:
394-
# Assuming the user is using MovingCameraScene and performing a zoom-in or zoom-out
395-
return (
396-
(font_size / DEFAULT_FONT_SIZE)
397-
* DEFAULT_STROKE_WIDTH
398-
* scale_factor
399-
)
400-
return 2 # default in DrawBorderThenFill
389+
if not isinstance(vmobject, SVGMobject) or vmobject.height == 0:
390+
return 2
391+
font_size = getattr(vmobject, "font_size", DEFAULT_FONT_SIZE)
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
401397

402398
def reverse_submobjects(self) -> None:
403399
self.mobject.invert(recursive=True)

0 commit comments

Comments
 (0)