diff --git a/manimlib/mobject/numbers.py b/manimlib/mobject/numbers.py index fc0cecd3..f1d039bb 100644 --- a/manimlib/mobject/numbers.py +++ b/manimlib/mobject/numbers.py @@ -1,10 +1,12 @@ from manimlib.constants import * from manimlib.mobject.svg.tex_mobject import SingleStringTex -from manimlib.mobject.svg.tex_mobject import tex_string_to_mob_map -from manimlib.mobject.svg.tex_mobject import SCALE_FACTOR_PER_FONT_POINT +from manimlib.mobject.svg.text_mobject import Text from manimlib.mobject.types.vectorized_mobject import VMobject +string_to_mob_map = {} + + class DecimalNumber(VMobject): CONFIG = { "stroke_width": 0, @@ -34,7 +36,7 @@ class DecimalNumber(VMobject): # Add non-numerical bits if self.show_ellipsis: - self.add(self.string_to_mob("\\dots")) + self.add(self.string_to_mob("\\dots", SingleStringTex)) if num_string.startswith("-"): minus = self.submobjects[0] @@ -44,7 +46,7 @@ class DecimalNumber(VMobject): ) if self.unit is not None: - self.unit_sign = self.string_to_mob(self.unit) + self.unit_sign = self.string_to_mob(self.unit, SingleStringTex) self.add(self.unit_sign) self.arrange( @@ -55,7 +57,7 @@ class DecimalNumber(VMobject): # Handle alignment of parts that should be aligned # to the bottom for i, c in enumerate(num_string): - if c == "-" and len(num_string) > i + 1: + if c == "–" and len(num_string) > i + 1: self[i].align_to(self[i + 1], UP) self[i].shift(self[i + 1].get_height() * DOWN / 2) elif c == ",": @@ -79,6 +81,7 @@ class DecimalNumber(VMobject): num_string = "+" + num_string[1:] else: num_string = num_string[1:] + num_string = num_string.replace("-", "–") return num_string def init_data(self): @@ -88,17 +91,12 @@ class DecimalNumber(VMobject): def get_font_size(self): return self.data["font_size"][0] - def string_to_mob(self, tex_string): - # Could just call SingleStringTex, and there is - # some code repetition here by looking to the same cache, - # but it keeps things from initializing a new object - # more than is necessary - if tex_string in tex_string_to_mob_map: - result = tex_string_to_mob_map[tex_string].copy() - result.scale(self.get_font_size() * SCALE_FACTOR_PER_FONT_POINT) - return result - else: - return SingleStringTex(tex_string, font_size=self.get_font_size()) + def string_to_mob(self, string, mob_class=Text): + if string not in string_to_mob_map: + string_to_mob_map[string] = mob_class(string, font_size=1) + mob = string_to_mob_map[string].copy() + mob.scale(self.get_font_size()) + return mob def get_formatter(self, **kwargs): """