mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 12:47:43 +00:00
Added Text.get_parts_by_text
This commit is contained in:
parent
0e326c7ac5
commit
15f3b359ae
1 changed files with 15 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import manimpango
|
|||
from manimlib.constants import *
|
||||
from manimlib.mobject.geometry import Dot
|
||||
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.customization import get_customization
|
||||
from manimlib.utils.directories import get_downloads_dir, get_text_dir
|
||||
|
|
@ -100,6 +101,19 @@ class Text(SVGMobject):
|
|||
index = self.text.find(word, index + len(word))
|
||||
return indexes
|
||||
|
||||
def get_parts_by_text(self, word):
|
||||
return VGroup(*(
|
||||
self[i:j]
|
||||
for i, j in self.find_indexes(word)
|
||||
))
|
||||
|
||||
def get_part_by_text(word):
|
||||
parts = self.get_parts_by_text()
|
||||
if len(parts) > 0:
|
||||
return parts[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def full2short(self, config):
|
||||
for kwargs in [config, self.CONFIG]:
|
||||
if kwargs.__contains__('line_spacing_height'):
|
||||
|
|
@ -212,6 +226,7 @@ class Text(SVGMobject):
|
|||
self.text,
|
||||
)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def register_font(font_file: typing.Union[str, Path]):
|
||||
"""Temporarily add a font file to Pango's search path.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue