A community-maintained Python framework for creating mathematical animations.
Add disable ligarature method
Syrus Dark17253a738e3d
diff --git a/manim/mobject/svg/code_mobject.py b/manim/mobject/svg/code_mobject.pyindex a4a1f8efe..02986ec09 100644--- a/manim/mobject/svg/code_mobject.py+++ b/manim/mobject/svg/code_mobject.py@@ -262,6 +262,7 @@ class Code(VGroup):line_spacing=self.line_spacing,alignment="right",font=self.font,+ disable_ligaratures=True,stroke_width=self.stroke_width).scale(self.scale_factor)for i in line_numbers:@@ -287,6 +288,7 @@ class Code(VGroup):line_spacing=self.line_spacing,tab_width=self.tab_width,font=self.font,+ disable_ligaratures=True,stroke_width=self.stroke_width).scale(self.scale_factor)for line_no in range(code.__len__()):@@ -304,7 +306,6 @@ class Code(VGroup):"""Function to generate html string with code highlighted and stores in variable html_string."""file = open(self.file_path, "r")code_str = file.read()- file.close()self.html_string = hilite_me(code_str,self.language,diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.pyindex f7d2f8254..723cb38ff 100644--- a/manim/mobject/svg/text_mobject.py+++ b/manim/mobject/svg/text_mobject.py@@ -54,6 +54,7 @@ import cairoimport cairocffiimport pangocairocffiimport pangocffi+from xml.sax.saxutils import escapefrom ... import config, loggerfrom ...constants import *@@ -709,7 +710,9 @@ class Text(SVGMobject):"tab_width": 4,}- def __init__(self, text: str, **config): # pylint: disable=redefined-outer-name+ def __init__(+ self, text: str, disable_ligaratures: bool = False, **config+ ): # pylint: disable=redefined-outer-namelogger.info("Text now uses Pango for rendering. ""In case of problems, the old implementation is available as CairoText."@@ -717,6 +720,7 @@ class Text(SVGMobject):self.full2short(config)digest_config(self, config)self.original_text = text+ self.disable_ligaratures = disable_ligaraturestext_without_tabs = textif text.find("\t") != -1:text_without_tabs = text.replace("\t", " " * self.tab_width)@@ -729,6 +733,11 @@ class Text(SVGMobject):self.remove_last_M(file_name)SVGMobject.__init__(self, file_name, **config)self.text = text+ print("hi")+ if self.disable_ligaratures:+ print("yes")+ self.submobjects = [*self.gen_chars()]+ self.chars = VGroup(*self.submobjects)self.chars = VGroup(*self.submobjects)self.text = text_without_tabs.replace(" ", "").replace("\n", "")nppc = self.n_points_per_cubic_curve@@ -761,6 +770,28 @@ class Text(SVGMobject):def __repr__(self):return f"Text({repr(self.original_text)})"+ def gen_chars(self):+ chars = VGroup()+ submobjects_char_index = 0+ for char_index in range(self.text.__len__()):+ if (+ self.text[char_index] == " "+ or self.text[char_index] == "\t"+ or self.text[char_index] == "\n"+ ):+ space = Dot(redius=0, fill_opacity=0, stroke_opacity=0)+ if char_index == 0:+ space.move_to(self.submobjects[submobjects_char_index].get_center())+ else:+ space.move_to(+ self.submobjects[submobjects_char_index - 1].get_center()+ )+ chars.add(space)+ else:+ chars.add(self.submobjects[submobjects_char_index])+ submobjects_char_index += 1+ return chars+def remove_last_M(self, file_name: str): # pylint: disable=invalid-name"""Internally used. Use to format the rendered SVG files."""with open(file_name, "r") as fpr:@@ -926,6 +957,7 @@ class Text(SVGMobject):size = self.size * 10line_spacing = self.line_spacing * 10dir_name = config.get_dir("text_dir")+ disable_liga = self.disable_ligaraturesif not os.path.exists(dir_name):os.makedirs(dir_name)hash_name = self.text2hash()@@ -959,7 +991,11 @@ class Text(SVGMobject):START_X + offset_x, START_Y + line_spacing * setting.line_num)pangocairocffi.update_layout(context, layout)- layout.set_text(text)+ if disable_liga:+ text = escape(text)+ layout.set_markup(f"<span font_features='liga=0'>{text}</span>")+ else:+ layout.set_text(text)logger.debug(f"Setting Text {text}")pangocairocffi.show_layout(context, layout)offset_x += pangocffi.units_to_double(layout.get_size()[0])