Make style optional

This commit is contained in:
XANTRONIX Development 2024-01-03 20:30:46 -05:00
parent cf251ce09a
commit 873d2e86d1

View file

@ -1,11 +1,13 @@
import cairo
import gi
from typing import Optional
gi.require_version('Rsvg', '2.0')
from gi.repository import Rsvg
def to_surface(path: str, width: float, height: float, style: str) -> cairo.Surface:
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))
@ -18,7 +20,10 @@ def to_surface(path: str, width: float, height: float, style: str) -> cairo.Surf
rect.height = height
svg = Rsvg.Handle.new_from_file(path)
svg.set_stylesheet(bytes(style, 'utf8'))
if style is not None:
svg.set_stylesheet(bytes(style, 'utf8'))
svg.render_layer(cr, None, rect)
return surface