From 6eabbe943bdb67adaaf666f1fbd173c2fc565252 Mon Sep 17 00:00:00 2001 From: kolibril13 <44469195+kolibril13@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:26:06 +0200 Subject: [PATCH 1/2] Changed -1 to -1.0 for broader GPU suppot. Some GLSL compilers are more sensitive to types than others. With this fix, my Intel HD Graphics 5500 (Broadwell GT2) gives no error on this script anymore. --- manimlib/shaders/quadratic_bezier_fill_frag.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manimlib/shaders/quadratic_bezier_fill_frag.glsl b/manimlib/shaders/quadratic_bezier_fill_frag.glsl index 785d9a90..dded4521 100644 --- a/manimlib/shaders/quadratic_bezier_fill_frag.glsl +++ b/manimlib/shaders/quadratic_bezier_fill_frag.glsl @@ -38,7 +38,7 @@ bool is_inside_curve(){ float sdf(){ - if(is_inside_curve()) return -1; + if(is_inside_curve()) return -1.0; return min_dist_to_curve(uv_coords, uv_b2, bezier_degree, false); } @@ -49,4 +49,4 @@ void main() { if (fill_type == FILL_ALL) return; frag_color.a *= smoothstep(1, 0, sdf() / uv_anti_alias_width); // frag_color.a += 0.2; -} \ No newline at end of file +} From d83fa90606d02d008b9fec7950e62f71e2a6e833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=A4=E7=BF=94=E4=B8=87=E9=87=8C?= <44120331+Tony031218@users.noreply.github.com> Date: Thu, 7 May 2020 16:21:43 +0800 Subject: [PATCH 2/2] Fix Text Class's bugs in shaders branch (the same as #1030) (#1031) * fix: remove the last M tag in svg files to make Text run in shaders branch * fix: close the svg path manually to fix the bug of wrong stroke * fix: remove Space mobjects in Text to fix the bug of TransformText * feat: make Text and TextMobject equal in size * this will lead to more bugs of setting color, so I delete it * fix typo in text_mobject.py * fix conflict of default size and height --- manimlib/mobject/svg/text_mobject.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 2be9b758..8b6ff7d1 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -9,6 +9,9 @@ from manimlib.mobject.svg.svg_mobject import SVGMobject 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 @@ -45,8 +48,23 @@ class Text(SVGMobject): 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: @@ -55,7 +73,15 @@ class Text(SVGMobject): 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)