def __init__(self, text, **config): self.full2short(config) digest_config(self, config) self.lsh = self.size if self.lsh == -1 else self.lsh text_without_tabs = text if text.find('\t') != -1: text_without_tabs = text.replace('\t', ' ' * self.tab_width) self.text = text_without_tabs file_name = self.text2svg() PangoUtils.remove_last_M(file_name) self.remove_empty_path(file_name) SVGMobject.__init__(self, file_name, **config) self.text = text if self.disable_ligatures: self.apply_space_chars() if self.t2c: self.set_color_by_t2c() if self.gradient: self.set_color_by_gradient(*self.gradient) if self.t2g: self.set_color_by_t2g() # anti-aliasing if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR * self.font_size)
def __init__(self, text, **kwargs): self.full2short(kwargs) digest_config(self, kwargs) if self.size: warnings.warn( "self.size has been deprecated and will " "be removed in future.", DeprecationWarning) self.font_size = self.size if self.lsh == -1: self.lsh = self.font_size + self.font_size * DEFAULT_LINE_SPACING_SCALE else: self.lsh = self.font_size + self.font_size * self.lsh text_without_tabs = text if text.find('\t') != -1: text_without_tabs = text.replace('\t', ' ' * self.tab_width) self.text = text_without_tabs file_name = self.text2svg() PangoUtils.remove_last_M(file_name) self.remove_empty_path(file_name) SVGMobject.__init__(self, file_name, **kwargs) self.text = text if self.disable_ligatures: self.apply_space_chars() if self.t2c: self.set_color_by_t2c() if self.gradient: self.set_color_by_gradient(*self.gradient) if self.t2g: self.set_color_by_t2g() # anti-aliasing if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR)
def __init__(self, text, **config): digest_config(self, config) self.text = f'<span>{text}</span>' self.original_text = self.text self.text_for_parsing = self.text text_without_tabs = text if "\t" in text: text_without_tabs = text.replace("\t", " " * self.tab_width) try: colormap = self.extract_color_tags() gradientmap = self.extract_gradient_tags() except ET.ParseError: # let pango handle that error pass validate_error = MarkupUtils.validate(self.text) if validate_error: raise ValueError(validate_error) file_name = self.text2svg() PangoUtils.remove_last_M(file_name) super().__init__( file_name, **config, ) self.chars = self.get_group_class()(*self.submobjects) self.text = text_without_tabs.replace(" ", "").replace("\n", "") if self.gradient: self.set_color_by_gradient(*self.gradient) for col in colormap: self.chars[col["start"] - col["start_offset"]:col["end"] - col["start_offset"] - col["end_offset"]].set_color( self._parse_color(col["color"])) for grad in gradientmap: self.chars[grad["start"] - grad["start_offset"]:grad["end"] - grad["start_offset"] - grad["end_offset"]].set_color_by_gradient( *(self._parse_color(grad["from"]), self._parse_color(grad["to"]))) # anti-aliasing if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR)
def __init__(self, text, **config): self.full2short(config) digest_config(self, config) if self.size: warnings.warn( "self.size has been deprecated and will " "be removed in future.", DeprecationWarning ) self.font_size = self.size if self.lsh == -1: self.lsh = self.font_size + self.font_size * DEFAULT_LINE_SPACING_SCALE else: self.lsh = self.font_size + self.font_size * self.lsh text_without_tabs = text if text.find('\t') != -1: text_without_tabs = text.replace('\t', ' ' * self.tab_width) self.text = text_without_tabs file_name = self.text2svg() PangoUtils.remove_last_M(file_name) self.remove_empty_path(file_name) SVGMobject.__init__(self, file_name, **config) self.text = text if self.disable_ligatures: self.apply_space_chars() if self.t2c: self.set_color_by_t2c() if self.gradient: self.set_color_by_gradient(*self.gradient) if self.t2g: self.set_color_by_t2g() # anti-aliasing if self.height is None: self.scale(TEXT_MOB_SCALE_FACTOR) # Just a temporary hack to get better triangulation # See pr #1552 for details for i in self.submobjects: i.insert_n_curves(len(i.get_points()))
def __init__( self, text: str, fill_opacity: int = 1, stroke_width: int = 0, color: str = WHITE, size: int = 1, line_spacing: int = -1, font: str = "", slant: str = NORMAL, weight: str = NORMAL, justify: bool = False, gradient: tuple = None, tab_width: int = 4, height: int = None, width: int = None, should_center: bool = True, unpack_groups: bool = True, disable_ligatures: bool = False, **kwargs, ): self.text = text self.color = color self.size = size self.line_spacing = line_spacing self.font = font self.slant = slant self.weight = weight self.gradient = gradient self.tab_width = tab_width self.justify = justify self.original_text = text self.disable_ligatures = disable_ligatures text_without_tabs = text if "\t" in text: text_without_tabs = text.replace("\t", " " * self.tab_width) colormap = self.extract_color_tags() if len(colormap) > 0: logger.warning( 'Using <color> tags in MarkupText is deprecated. Please use <span foreground="..."> instead.' ) gradientmap = self.extract_gradient_tags() validate_error = MarkupUtils.validate(self.text) if validate_error: raise ValueError(validate_error) if self.line_spacing == -1: self.line_spacing = self.size + self.size * 0.3 else: self.line_spacing = self.size + self.size * self.line_spacing file_name = self.text2svg() PangoUtils.remove_last_M(file_name) super().__init__( file_name, fill_opacity=fill_opacity, stroke_width=stroke_width, height=height, width=width, should_center=should_center, unpack_groups=unpack_groups, **kwargs, ) self.chars = self.get_group_class()(*self.submobjects) self.text = text_without_tabs.replace(" ", "").replace("\n", "") if config.renderer == "opengl": nppc = self.n_points_per_curve else: nppc = self.n_points_per_cubic_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.gradient: self.set_color_by_gradient(*self.gradient) for col in colormap: self.chars[ col["start"] - col["start_offset"] : col["end"] - col["start_offset"] - col["end_offset"] ].set_color(self._parse_color(col["color"])) for grad in gradientmap: self.chars[ grad["start"] - grad["start_offset"] : grad["end"] - grad["start_offset"] - grad["end_offset"] ].set_color_by_gradient( *(self._parse_color(grad["from"]), self._parse_color(grad["to"])) ) # anti-aliasing if height is None and width is None: self.scale(TEXT_MOB_SCALE_FACTOR)
def __init__( self, text: str, fill_opacity: float = 1.0, stroke_width: int = 0, color: str = WHITE, size: int = 1, line_spacing: int = -1, font: str = "", slant: str = NORMAL, weight: str = NORMAL, t2c: Dict[str, str] = None, t2f: Dict[str, str] = None, t2g: Dict[str, tuple] = None, t2s: Dict[str, str] = None, t2w: Dict[str, str] = None, gradient: tuple = None, tab_width: int = 4, # Mobject height: int = None, width: int = None, should_center: bool = True, unpack_groups: bool = True, disable_ligatures: bool = False, **kwargs, ): self.size = size self.line_spacing = line_spacing self.font = font self.slant = slant self.weight = weight self.gradient = gradient self.tab_width = tab_width if t2c is None: t2c = {} if t2f is None: t2f = {} if t2g is None: t2g = {} if t2s is None: t2s = {} if t2w is None: t2w = {} # If long form arguments are present, they take precedence t2c = kwargs.pop("text2color", t2c) t2f = kwargs.pop("text2font", t2f) t2g = kwargs.pop("text2gradient", t2g) t2s = kwargs.pop("text2slant", t2s) t2w = kwargs.pop("text2weight", t2w) self.t2c = t2c self.t2f = t2f self.t2g = t2g self.t2s = t2s self.t2w = t2w self.original_text = text self.disable_ligatures = disable_ligatures text_without_tabs = text if text.find("\t") != -1: text_without_tabs = text.replace("\t", " " * self.tab_width) self.text = text_without_tabs if self.line_spacing == -1: self.line_spacing = self.size + self.size * 0.3 else: self.line_spacing = self.size + self.size * self.line_spacing file_name = self.text2svg() PangoUtils.remove_last_M(file_name) SVGMobject.__init__( self, file_name, color=color, fill_opacity=fill_opacity, stroke_width=stroke_width, height=height, width=width, should_center=should_center, unpack_groups=unpack_groups, **kwargs, ) self.text = text if self.disable_ligatures: if config.renderer == "opengl": self.set_submobjects(self.gen_chars()) else: self.submobjects = [*self.gen_chars()] self.chars = self.get_group_class()(*self.submobjects) self.text = text_without_tabs.replace(" ", "").replace("\n", "") if config.renderer == "opengl": nppc = self.n_points_per_curve else: nppc = self.n_points_per_cubic_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: self.set_color_by_t2c() if self.gradient: self.set_color_by_gradient(*self.gradient) if self.t2g: self.set_color_by_t2g() # anti-aliasing if height is None and width is None: self.scale(TEXT_MOB_SCALE_FACTOR)
def __init__( self, text, # Mobject color=WHITE, height=None, width=None, fill_opacity=1, stroke_width=0, should_center=True, unpack_groups=True, # Text font="", gradient=None, line_spacing=-1, size=1, slant: str = NORMAL, weight: str = NORMAL, t2c=None, t2f=None, t2g=None, t2s=None, t2w=None, tab_width=4, **kwargs, ): # self.full2short(config) if t2c is None: t2c = {} if t2f is None: t2f = {} if t2g is None: t2g = {} if t2s is None: t2s = {} if t2w is None: t2w = {} # If long form arguments are present, they take precedence t2c = kwargs.pop("text2color", t2c) t2f = kwargs.pop("text2font", t2f) t2g = kwargs.pop("text2gradient", t2g) t2s = kwargs.pop("text2slant", t2s) t2w = kwargs.pop("text2weight", t2w) self.t2c = t2c self.t2f = t2f self.t2g = t2g self.t2s = t2s self.t2w = t2w self.font = font self.gradient = gradient self.line_spacing = line_spacing self.size = size self.slant = slant self.weight = weight self.tab_width = tab_width self.original_text = text text_without_tabs = text if text.find("\t") != -1: text_without_tabs = text.replace("\t", " " * self.tab_width) self.text = text_without_tabs if self.line_spacing == -1: self.line_spacing = self.size + self.size * 0.3 else: self.line_spacing = self.size + self.size * self.line_spacing file_name = self.text2svg() PangoUtils.remove_last_M(file_name) SVGMobject.__init__( self, file_name, height=height, width=width, unpack_groups=unpack_groups, color=color, fill_opacity=fill_opacity, stroke_width=stroke_width, should_center=should_center, **kwargs, ) self.text = text self.submobjects = [*self.gen_chars()] self.chars = VGroup(*self.submobjects) self.text = text_without_tabs.replace(" ", "").replace("\n", "") nppc = self.n_points_per_cubic_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: self.set_color_by_gradient(*self.gradient) if self.t2g: self.set_color_by_t2g() # anti-aliasing if self.height is None and self.width is None: self.scale(TEXT_MOB_SCALE_FACTOR)
def __init__( self, text: str, fill_opacity: int = 1, stroke_width: int = 0, color: str = WHITE, size: int = 1, line_spacing: int = -1, font: str = "", slant: str = NORMAL, weight: str = NORMAL, gradient: tuple = None, tab_width: int = 4, height: int = None, width: int = None, should_center: bool = True, unpack_groups: bool = True, disable_ligatures: bool = False, **kwargs, ): self.text = text self.size = size self.line_spacing = line_spacing self.font = font self.slant = slant self.weight = weight self.gradient = gradient self.tab_width = tab_width self.original_text = text self.disable_ligatures = disable_ligatures text_without_tabs = text if "\t" in text: text_without_tabs = text.replace("\t", " " * self.tab_width) colormap = self.extract_color_tags() gradientmap = self.extract_gradient_tags() if self.line_spacing == -1: self.line_spacing = self.size + self.size * 0.3 else: self.line_spacing = self.size + self.size * self.line_spacing file_name = self.text2svg() PangoUtils.remove_last_M(file_name) SVGMobject.__init__( self, file_name, color=color, fill_opacity=fill_opacity, stroke_width=stroke_width, height=height, width=width, should_center=should_center, unpack_groups=unpack_groups, **kwargs, ) self.chars = VGroup(*self.submobjects) self.text = text_without_tabs.replace(" ", "").replace("\n", "") nppc = self.n_points_per_cubic_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.gradient: self.set_color_by_gradient(*self.gradient) for col in colormap: self.chars[ col["start"] - col["start_offset"] : col["end"] - col["start_offset"] - col["end_offset"] ].set_color(self._parse_color(col["color"])) for grad in gradientmap: self.chars[ grad["start"] - grad["start_offset"] : grad["end"] - grad["start_offset"] - grad["end_offset"] ].set_color_by_gradient( *(self._parse_color(grad["from"]), self._parse_color(grad["to"])) ) # anti-aliasing if self.height is None and self.width is None: self.scale(TEXT_MOB_SCALE_FACTOR)