Some small refactors

This commit is contained in:
YishiMichael 2022-01-29 14:35:27 +08:00
parent 5d2dcec307
commit a6675eb043
No known key found for this signature in database
GPG key ID: EC615C0C5A86BC80

View file

@ -3,6 +3,7 @@ import re
import sys import sys
from types import MethodType from types import MethodType
from manimlib.constants import BLACK
from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.mobject.svg.svg_mobject import SVGMobject
from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
@ -31,6 +32,7 @@ def _get_neighbouring_pairs(iterable):
class _TexSVG(SVGMobject): class _TexSVG(SVGMobject):
CONFIG = { CONFIG = {
"color": BLACK,
"height": None, "height": None,
"path_string_config": { "path_string_config": {
"should_subdivide_sharp_curves": True, "should_subdivide_sharp_curves": True,
@ -39,17 +41,14 @@ class _TexSVG(SVGMobject):
} }
@staticmethod @staticmethod
def color_str_to_label(color_str): def color_to_label(fill_color):
if len(color_str) == 4: r, g, b = color_to_int_rgb(fill_color)
# "#RGB" => "#RRGGBB" rg = r * 256 + g
color_str = "#" + "".join([c * 2 for c in color_str[1:]]) return rg * 256 + b
if color_str == "#ffffff":
return 0
return int(color_str[1:], 16)
def parse_labels(self): def parse_labels(self):
for glyph in self: for glyph in self:
glyph.glyph_label = _TexSVG.color_str_to_label(glyph.fill_color) glyph.glyph_label = _TexSVG.color_to_label(glyph.fill_color)
return self return self
@ -90,8 +89,7 @@ class _TexParser(object):
@staticmethod @staticmethod
def label_to_color_tuple(rgb): def label_to_color_tuple(rgb):
# Get a unique color different from black, # Get a unique color different from black.
# or the svg file will not include the color information.
rg, b = divmod(rgb, 256) rg, b = divmod(rgb, 256)
r, g = divmod(rg, 256) r, g = divmod(rg, 256)
return r, g, b return r, g, b
@ -306,6 +304,7 @@ class _TexParser(object):
@staticmethod @staticmethod
def get_color_related_commands_dict(): def get_color_related_commands_dict():
# Only list a few commands that are commonly used.
return { return {
"\\color": 1, "\\color": 1,
"\\textcolor": 1, "\\textcolor": 1,