From 873d2e86d1aff4da3f89d302311a24ac67237d85 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 3 Jan 2024 20:30:46 -0500 Subject: [PATCH] Make style optional --- py/hexagram/svg.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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