diff --git a/py/hexagram/svg.py b/py/hexagram/svg.py index 91a5902..612f6a7 100644 --- a/py/hexagram/svg.py +++ b/py/hexagram/svg.py @@ -7,10 +7,7 @@ gi.require_version('Rsvg', '2.0') from gi.repository import Rsvg -def to_surface(path: str, width: float, height: float, style: Optional[str]=None) -> cairo.Surface: - surface = cairo.RecordingSurface(cairo.CONTENT_ALPHA, - cairo.Rectangle(0, 0, width, height)) - +def render_to_surface(path: str, surface: cairo.Surface, width: float, height: float, style: Optional[str]=None): cr = cairo.Context(surface) rect = Rsvg.Rectangle() @@ -26,4 +23,11 @@ def to_surface(path: str, width: float, height: float, style: Optional[str]=None svg.render_layer(cr, None, rect) + surface + +def render_to_image(path: str, width: float, height: float, style: Optional[str]=None) -> cairo.Surface: + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + + render_to_surface(path, surface, width, height, style) + return surface