SVG rendering in a PyGame application

前端 未结 9 1144
悲哀的现实
悲哀的现实 2020-12-02 12:34

In a pyGame application, I would like to render resolution-free GUI widgets described in SVG.

What tool and/or library can I use to reach this goal ?

(I like

9条回答
  •  甜味超标
    2020-12-02 13:16

    The question is quite old but 10 years passed and there is new possibility that works and does not require librsvg anymore. There is Cython wrapper over nanosvg library and it works:

    from svg import Parser, Rasterizer
    
    
    def load_svg(filename, surface, position, size=None):
        if size is None:
            w = surface.get_width()
            h = surface.get_height()
        else:
            w, h = size
        svg = Parser.parse_file(filename)
        rast = Rasterizer()
        buff = rast.rasterize(svg, w, h)
        image = pygame.image.frombuffer(buff, (w, h), 'ARGB')
        surface.blit(image, position)
    

    I found Cairo/rsvg solution too complicated to get to work because of dependencies are quite obscure to install.

提交回复
热议问题