From 020bd8727113f7c11580c3ae3381671924cea8bb Mon Sep 17 00:00:00 2001 From: YishiMichael Date: Fri, 15 Apr 2022 13:27:50 +0800 Subject: [PATCH] Add back base_color attribute --- manimlib/mobject/svg/labelled_string.py | 29 ++++++++++++++----------- manimlib/mobject/svg/mtex_mobject.py | 1 + manimlib/mobject/svg/text_mobject.py | 5 +++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/manimlib/mobject/svg/labelled_string.py b/manimlib/mobject/svg/labelled_string.py index 3d0efb4f..d20b3c11 100644 --- a/manimlib/mobject/svg/labelled_string.py +++ b/manimlib/mobject/svg/labelled_string.py @@ -36,18 +36,15 @@ class LabelledString(SVGMobject, ABC): "should_subdivide_sharp_curves": True, "should_remove_null_curves": True, }, + "base_color": WHITE, "isolate": [], } def __init__(self, string: str, **kwargs): self.string = string digest_config(self, kwargs) - - self.base_color_int = self.color_to_int( - self.svg_default.get("fill_color") \ - or self.svg_default.get("color") \ - or WHITE - ) + if self.base_color is None: + self.base_color = WHITE self.pre_parse() self.parse() @@ -68,7 +65,8 @@ class LabelledString(SVGMobject, ABC): def generate_mobject(self) -> None: super().generate_mobject() - if self.label_span_list: + num_labels = len(self.label_span_list) + if num_labels: file_path = self.get_file_path_(use_plain_file=False) labelled_svg = SVGMobject(file_path) submob_color_ints = [ @@ -85,7 +83,7 @@ class LabelledString(SVGMobject, ABC): ) unrecognized_color_ints = remove_list_redundancies(sorted(filter( - lambda color_int: color_int > len(self.label_span_list), + lambda color_int: color_int > num_labels, submob_color_ints ))) if unrecognized_color_ints: @@ -100,6 +98,7 @@ class LabelledString(SVGMobject, ABC): def pre_parse(self) -> None: self.string_len = len(self.string) self.full_span = (0, self.string_len) + self.base_color_int = self.color_to_int(self.base_color) def parse(self) -> None: self.command_repl_items = self.get_command_repl_items() @@ -311,7 +310,7 @@ class LabelledString(SVGMobject, ABC): self.extra_entity_spans )) - def index_not_in_entity_spans(self, index: int) -> bool: + def is_splittable_index(self, index: int) -> bool: return not any([ entity_span[0] < index < entity_span[1] for entity_span in self.entity_spans @@ -348,12 +347,16 @@ class LabelledString(SVGMobject, ABC): self.external_specified_spans, self.find_substrs(self.isolate) )) - shrinked_spans = list(filter( - lambda span: span[0] < span[1] and all([ - self.index_not_in_entity_spans(index) + filtered_spans = list(filter( + lambda span: all([ + self.is_splittable_index(index) for index in span ]), - [self.shrink_span(span) for span in spans] + spans + )) + shrinked_spans = list(filter( + lambda span: span[0] < span[1], + [self.shrink_span(span) for span in filtered_spans] )) return remove_list_redundancies(shrinked_spans) diff --git a/manimlib/mobject/svg/mtex_mobject.py b/manimlib/mobject/svg/mtex_mobject.py index 8c7d4843..91d7675b 100644 --- a/manimlib/mobject/svg/mtex_mobject.py +++ b/manimlib/mobject/svg/mtex_mobject.py @@ -47,6 +47,7 @@ class MTex(LabelledString): self.__class__.__name__, self.svg_default, self.path_string_config, + self.base_color, self.isolate, self.tex_string, self.alignment, diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 1e3f073a..2c076551 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -161,6 +161,7 @@ class MarkupText(LabelledString): self.__class__.__name__, self.svg_default, self.path_string_config, + self.base_color, self.isolate, self.text, self.is_markup, @@ -452,7 +453,7 @@ class MarkupText(LabelledString): self.specified_spans )))) breakup_indices = sorted(filter( - self.index_not_in_entity_spans, breakup_indices + self.is_splittable_index, breakup_indices )) return list(filter( lambda span: self.get_substr(span).strip(), @@ -462,7 +463,7 @@ class MarkupText(LabelledString): def get_content(self, use_plain_file: bool) -> str: filtered_attr_dicts = list(filter( lambda item: all([ - self.index_not_in_entity_spans(index) + self.is_splittable_index(index) for index in item[0] ]), self.predefined_attr_dicts