mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
fix Text in shaders
This commit is contained in:
parent
7b67f4556b
commit
79b8136330
2 changed files with 7 additions and 23 deletions
|
@ -7,6 +7,7 @@ import manimlib.constants as consts
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
|
from manimlib.utils.directories import get_text_dir
|
||||||
|
|
||||||
|
|
||||||
TEXT_MOB_SCALE_FACTOR = 0.05
|
TEXT_MOB_SCALE_FACTOR = 0.05
|
||||||
|
@ -30,6 +31,7 @@ class Text(SVGMobject):
|
||||||
# Mobject
|
# Mobject
|
||||||
'color': consts.WHITE,
|
'color': consts.WHITE,
|
||||||
'height': None,
|
'height': None,
|
||||||
|
'stroke_width': 0,
|
||||||
# Text
|
# Text
|
||||||
'font': '',
|
'font': '',
|
||||||
'gradient': None,
|
'gradient': None,
|
||||||
|
@ -51,23 +53,8 @@ class Text(SVGMobject):
|
||||||
self.lsh = self.size if self.lsh == -1 else self.lsh
|
self.lsh = self.size if self.lsh == -1 else self.lsh
|
||||||
|
|
||||||
file_name = self.text2svg()
|
file_name = self.text2svg()
|
||||||
self.remove_last_M(file_name)
|
|
||||||
SVGMobject.__init__(self, file_name, **config)
|
SVGMobject.__init__(self, file_name, **config)
|
||||||
|
|
||||||
nppc = self.n_points_per_curve
|
|
||||||
for each in self:
|
|
||||||
if len(each.get_points()) == 0:
|
|
||||||
continue
|
|
||||||
points = each.get_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:
|
if self.t2c:
|
||||||
self.set_color_by_t2c()
|
self.set_color_by_t2c()
|
||||||
if self.gradient:
|
if self.gradient:
|
||||||
|
@ -79,13 +66,6 @@ class Text(SVGMobject):
|
||||||
if self.height is None:
|
if self.height is None:
|
||||||
self.scale(TEXT_MOB_SCALE_FACTOR)
|
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):
|
def find_indexes(self, word):
|
||||||
m = re.match(r'\[([0-9\-]{0,}):([0-9\-]{0,})\]', word)
|
m = re.match(r'\[([0-9\-]{0,}):([0-9\-]{0,})\]', word)
|
||||||
if m:
|
if m:
|
||||||
|
@ -206,7 +186,7 @@ class Text(SVGMobject):
|
||||||
if self.font == '':
|
if self.font == '':
|
||||||
print(NOT_SETTING_FONT_MSG)
|
print(NOT_SETTING_FONT_MSG)
|
||||||
|
|
||||||
dir_name = consts.TEXT_DIR
|
dir_name = get_text_dir()
|
||||||
hash_name = self.text2hash()
|
hash_name = self.text2hash()
|
||||||
file_name = os.path.join(dir_name, hash_name) +'.svg'
|
file_name = os.path.join(dir_name, hash_name) +'.svg'
|
||||||
if os.path.exists(file_name):
|
if os.path.exists(file_name):
|
||||||
|
|
|
@ -33,6 +33,10 @@ def get_tex_dir():
|
||||||
return guarantee_existence(os.path.join(get_temp_dir(), "Tex"))
|
return guarantee_existence(os.path.join(get_temp_dir(), "Tex"))
|
||||||
|
|
||||||
|
|
||||||
|
def get_text_dir():
|
||||||
|
return guarantee_existence(os.path.join(get_temp_dir(), "Text"))
|
||||||
|
|
||||||
|
|
||||||
def get_mobject_data_dir():
|
def get_mobject_data_dir():
|
||||||
return guarantee_existence(os.path.join(get_temp_dir(), "mobject_data"))
|
return guarantee_existence(os.path.join(get_temp_dir(), "mobject_data"))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue