Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Text Class's bugs in shaders branch (the same as #1030) #1031

Merged
merged 7 commits into from May 7, 2020
28 changes: 27 additions & 1 deletion manimlib/mobject/svg/text_mobject.py
Expand Up @@ -9,6 +9,9 @@
from manimlib.utils.config_ops import digest_config


TEXT_MOB_SCALE_FACTOR = 0.05


class TextSetting(object):
def __init__(self, start, end, font, slant, weight, line_num=-1):
self.start = start
Expand Down Expand Up @@ -45,8 +48,23 @@ def __init__(self, text, **config):
self.lsh = self.size if self.lsh == -1 else self.lsh

file_name = self.text2svg()
self.remove_last_M(file_name)
SVGMobject.__init__(self, file_name, **config)

nppc = self.n_points_per_curve
for each in self:
if len(each.points) == 0:
continue
points = each.points
last = points[0]
each.clear_points()
for index, point in enumerate(points):
each.append_points([point])
if index != len(points) - 1 and (index + 1) % nppc == 0 and any(point != points[index+1]):
each.add_line_to(last)
last = points[index + 1]
each.add_line_to(last)

if self.t2c:
self.set_color_by_t2c()
if self.gradient:
Expand All @@ -55,7 +73,15 @@ def __init__(self, text, **config):
self.set_color_by_t2g()

# anti-aliasing
self.scale(0.1)
if self.height is None:
self.scale(TEXT_MOB_SCALE_FACTOR)

def remove_last_M(self, file_name):
with open(file_name, 'r') as fpr:
content = fpr.read()
content = re.sub(r'Z M [^A-Za-z]*? "\/>', 'Z "/>', content)
with open(file_name, 'w') as fpw:
fpw.write(content)

def find_indexes(self, word):
m = re.match(r'\[([0-9\-]{0,}):([0-9\-]{0,})\]', word)
Expand Down