Esempio n. 1
0
    def text2svg(self):
        # anti-aliasing
        size = self.size * 10
        lsh = self.lsh * 10

        if self.font == '':
            self.font = get_customization()['style']['font']

        dir_name = get_text_dir()
        hash_name = self.text2hash()
        file_name = os.path.join(dir_name, hash_name) + '.svg'
        if os.path.exists(file_name):
            return file_name
        settings = self.text2settings()
        width = 600
        height = 400
        disable_liga = self.disable_ligatures
        return manimpango.text2svg(
            settings,
            size,
            lsh,
            disable_liga,
            file_name,
            START_X,
            START_Y,
            width,
            height,
            self.text,
        )
Esempio n. 2
0
    def find_initial_position(self, size):
        custom_position = get_customization()["window_position"]
        monitor = get_monitors()[get_customization()["window_monitor"]]
        window_width, window_height = size
        # Position might be specified with a string of the form
        # x,y for integers x and y
        if "," in custom_position:
            return tuple(map(int, custom_position.split(",")))

        # Alternatively, it might be specified with a string like
        # UR, OO, DL, etc. specifiying what corner it should go to
        char_to_n = {"L": 0, "U": 0, "O": 1, "R": 2, "D": 2}
        width_diff = monitor.width - window_width
        height_diff = monitor.height - window_height
        return (
            monitor.x + char_to_n[custom_position[1]] * width_diff // 2,
            -monitor.y + char_to_n[custom_position[0]] * height_diff // 2,
        )
Esempio n. 3
0
    def __init__(self, text: str, **kwargs):
        self.full2short(kwargs)
        digest_config(self, kwargs)

        if not self.font:
            self.font = get_customization()["style"]["font"]
        if not self.alignment:
            self.alignment = get_customization()["style"]["text_alignment"]
        if self.is_markup:
            self.validate_markup_string(text)

        self.text = text
        super().__init__(text, **kwargs)

        if self.t2g:
            log.warning(
                "Manim currently cannot parse gradient from svg. "
                "Please set gradient via `set_color_by_gradient`.", )
        if self.gradient:
            self.set_color_by_gradient(*self.gradient)
        if self.height is None:
            self.scale(TEXT_MOB_SCALE_FACTOR)
Esempio n. 4
0
    def get_full_markup_str(self):
        if self.t2g:
            log.warning(
                "Manim currently cannot parse gradient from svg. "
                "Please set gradient via `set_color_by_gradient`.", )

        config_style_dict = self.generate_config_style_dict()
        global_attr_dict = {
            "line_height":
            ((self.lsh or DEFAULT_LINE_SPACING_SCALE) + 1) * 0.6,
            "font_family":
            self.font or get_customization()["style"]["font"],
            "font_size":
            self.font_size * 1024,
            "font_style":
            self.slant,
            "font_weight":
            self.weight,
            # TODO, it seems this doesn't work
            "font_features":
            "liga=0,dlig=0,clig=0,hlig=0" if self.disable_ligatures else None,
            "foreground":
            config_style_dict.get("fill", None),
            "alpha":
            config_style_dict.get("fill-opacity", None)
        }
        global_attr_dict = {
            k: v
            for k, v in global_attr_dict.items() if v is not None
        }
        global_attr_dict.update(self.global_config)
        self.parser.update_global_attrs(global_attr_dict)

        local_attr_items = [(word_or_text_span, {
            key: value
        }) for t2x_dict, key in ((self.t2c, "foreground"), (self.t2f,
                                                            "font_family"),
                                 (self.t2s, "font_style"), (self.t2w,
                                                            "font_weight"))
                            for word_or_text_span, value in t2x_dict.items()]
        local_attr_items.extend(self.local_configs.items())
        for word_or_text_span, local_config in local_attr_items:
            for text_span in self.find_indexes(word_or_text_span):
                self.parser.update_local_attrs(text_span, local_config)

        return self.parser.get_markup_str_with_attrs()
Esempio n. 5
0
    def text2svg(self):
        # anti-aliasing
        size = self.size * 10
        lsh = self.lsh * 10

        if self.font == '':
            self.font = get_customization()['style']['font']

        dir_name = get_text_dir()
        hash_name = self.text2hash()
        file_name = os.path.join(dir_name, hash_name) + '.svg'
        if os.path.exists(file_name):
            return file_name

        surface = cairo.SVGSurface(file_name, 600, 400)
        context = cairo.Context(surface)
        context.set_font_size(size)
        context.move_to(START_X, START_Y)

        settings = self.text2settings()
        offset_x = 0
        last_line_num = 0
        for setting in settings:
            font = setting.font
            slant = self.str2slant(setting.slant)
            weight = self.str2weight(setting.weight)
            text = self.text[setting.start:setting.end].replace('\n', ' ')

            context.select_font_face(font, slant, weight)
            if setting.line_num != last_line_num:
                offset_x = 0
                last_line_num = setting.line_num
            context.move_to(START_X + offset_x,
                            START_Y + lsh * setting.line_num)
            context.show_text(text)
            offset_x += context.text_extents(text)[4]

        return file_name
Esempio n. 6
0
 def __init__(self, mobject, color=None, **kwargs):
     if color is None:
         color = get_customization()['style']['background_color']
     SurroundingRectangle.__init__(self, mobject, color=color, **kwargs)
     self.original_fill_opacity = self.fill_opacity
Esempio n. 7
0
def get_directories():
    return get_customization()["directories"]
Esempio n. 8
0
def get_directories() -> dict[str, str]:
    return get_customization()["directories"]