本文整理汇总了Python中rsvg.Handle方法的典型用法代码示例。如果您正苦于以下问题:Python rsvg.Handle方法的具体用法?Python rsvg.Handle怎么用?Python rsvg.Handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsvg
的用法示例。
在下文中一共展示了rsvg.Handle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import rsvg [as 别名]
# 或者: from rsvg import Handle [as 别名]
def __init__(self, x, y, rsvg_handle, **kwargs):
"""
Initializer
@param self this object
"""
super(SvgItem, self).__init__(**kwargs)
assert isinstance(rsvg_handle, rsvg.Handle)
self.x = x
self.y = y
self.sx = 1.0
self.sy = 1.0
self.handle = rsvg_handle
self.width = self.handle.props.width
self.height = self.handle.props.height
self.custom_width = None
self.custom_height = None
示例2: svg2png
# 需要导入模块: import rsvg [as 别名]
# 或者: from rsvg import Handle [as 别名]
def svg2png(svg_file, output_file, scale=1):
# Get the svg files content
svg_data = open(svg_file).read()
# Get the width / height inside of the SVG
doc = minidom.parseString(svg_data)
width = [path.getAttribute('width') for path in doc.getElementsByTagName('svg')][0]
height = [path.getAttribute('height') for path in doc.getElementsByTagName('svg')][0]
width = int(round(float(re.compile('(\d+\.*\d*)\w*').findall(width)[0])))
height = int(round(float(re.compile('(\d+\.*\d*)\w*').findall(height)[0])))
doc.unlink()
# Create the png
img = cairo.ImageSurface(
cairo.FORMAT_ARGB32, width * scale, height * scale)
ctx = cairo.Context(img)
ctx.scale(scale, scale)
handler = rsvg.Handle(None, str(svg_data))
handler.render_cairo(ctx)
img.write_to_png(output_file)
print("{} ==> {}".format(svg_file, output_file))
示例3: __init__
# 需要导入模块: import rsvg [as 别名]
# 或者: from rsvg import Handle [as 别名]
def __init__(self, x, y, rsvg_handle, **kwargs):
super(SvgItem, self).__init__(**kwargs)
assert isinstance(rsvg_handle, rsvg.Handle)
self.x = x
self.y = y
self.sx = 1.0
self.sy = 1.0
self.handle = rsvg_handle
self.width = self.handle.props.width
self.height = self.handle.props.height
self.custom_width = None
self.custom_height = None
示例4: rsvg_handle_factory
# 需要导入模块: import rsvg [as 别名]
# 或者: from rsvg import Handle [as 别名]
def rsvg_handle_factory(base_file_name):
try:
return _rsvg_cache[base_file_name]
except KeyError:
full_path = os.path.join(os.path.dirname(__file__), 'resource', base_file_name)
rsvg_handle = rsvg.Handle(full_path)
_rsvg_cache[base_file_name] = rsvg_handle
return rsvg_handle