Make style optional
This commit is contained in:
parent
cf251ce09a
commit
873d2e86d1
1 changed files with 7 additions and 2 deletions
|
@ -1,11 +1,13 @@
|
||||||
import cairo
|
import cairo
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
gi.require_version('Rsvg', '2.0')
|
gi.require_version('Rsvg', '2.0')
|
||||||
|
|
||||||
from gi.repository import Rsvg
|
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,
|
surface = cairo.RecordingSurface(cairo.CONTENT_ALPHA,
|
||||||
cairo.Rectangle(0, 0, width, height))
|
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
|
rect.height = height
|
||||||
|
|
||||||
svg = Rsvg.Handle.new_from_file(path)
|
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)
|
svg.render_layer(cr, None, rect)
|
||||||
|
|
||||||
return surface
|
return surface
|
||||||
|
|
Loading…
Add table
Reference in a new issue