Refactor SVG rendering a bit

This commit is contained in:
XANTRONIX 2024-01-03 20:39:21 -05:00
parent 873d2e86d1
commit 5de46ed5fd

View file

@ -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