hexagram/py/hexagram/icons.py

30 lines
684 B
Python

import cairo
import gi
gi.require_version('Rsvg', '2.0')
from gi.repository import Rsvg
def to_surface(path: str, width: float, height: float, style: str) -> cairo.Surface:
surface = cairo.RecordingSurface(cairo.CONTENT_ALPHA,
cairo.Rectangle(0, 0, width, height))
cr = cairo.Context(surface)
rect = Rsvg.Rectangle()
rect.x = 0
rect.y = 0
rect.width = width
rect.height = height
svg = Rsvg.Handle.new_from_file(path)
svg.set_stylesheet(bytes(style, 'utf8'))
svg.render_layer(cr, None, rect)
return surface
class ISO7000():
__icons__ = dict()
def __init__(self):
pass