diff --git a/py/hexagram/svg.py b/py/hexagram/svg.py index 6df81d4..91a5902 100644 --- a/py/hexagram/svg.py +++ b/py/hexagram/svg.py @@ -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