ManimCommunity / ManimPango

Binding for Pango, to use with Manim.
https://manimpango.manim.community
MIT License
43 stars 13 forks source link

Support BytesIO as an argument of file_name in text2svg method #42

Closed shenjing023 closed 3 years ago

shenjing023 commented 3 years ago

In Manim Text class, if override the text2svg method use pycairo:

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

        if self.font == '':
            raise Exception("text font can not be empty")

        # file_name as a writable file object 
        file_name = BytesIO()
        surface = cairo.SVGSurface(file_name, 600, 400)
        context = cairo.Context(surface)
        context.set_font_size(size)
        context.move_to(START_X, START_Y)

It can manipulate SVG in memory. Here is the reference: pycairo svgsurface surface.c

naveen521kk commented 3 years ago

I really don't understand the use case.

Manim creates the SVG file using ManimPango and later parses it. It should anyway save the file because Manim wants to Cache the SVG file for the future as well as the SVG parser doesn't support parsing file object directly (maybe you can make an issue about that in other repo).

In case, you are asking for use in any other project you should possibly wait until #28.

naveen521kk commented 3 years ago

Closing this. I think it should be fine to add this support when #28 is done.