~glitter-team/glitter/trunk

« back to all changes in this revision

Viewing changes to glitter/svg_image.py

  • Committer: Jan Jokela
  • Date: 2008-12-10 22:18:59 UTC
  • Revision ID: janjokela@gmail.com-20081210221859-zxr2ut255a7xu15x
Hi, Glitter here

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# !/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# Glitter Toolkit
 
5
        
 
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
 
7
__licenses__ = ["LICENSE.LGPL"]
 
8
__description__ = "A CairoTexture from a SVG"
 
9
 
 
10
import os
 
11
import sys
 
12
 
 
13
from cluttercairo import CairoTexture
 
14
import clutter
 
15
import cairo
 
16
import rsvg
 
17
 
 
18
class SVGImage(CairoTexture):
 
19
    """ Creates a CairoTexture based on a given SVG """
 
20
 
 
21
    def __init__(self, uri, width, height):
 
22
        
 
23
        """
 
24
        uri (str) -- source location (*.svg), standard uri format
 
25
        width (int) -- width in pixels
 
26
        height (int) -- height in pixels
 
27
        """
 
28
        
 
29
        CairoTexture.__init__(self, width, height)
 
30
        
 
31
        self.uri = uri
 
32
        self.width = width
 
33
        self.height = height
 
34
        
 
35
        if not os.path.exists(self.uri):
 
36
            raise AttributeError, 'invalid source uri: %s' % self.uri
 
37
        
 
38
        context = self.cairo_create()
 
39
        svg = rsvg.Handle(self.uri)
 
40
        matrix = cairo.Matrix((self.width * 1.0 / svg.props.width),0,0,(self.height * 1.0 / svg.props.height),0,0)
 
41
        context.transform(matrix)
 
42
        svg.render_cairo(context)
 
43
               
 
44
        context.close_path()
 
45
        
 
46
        context.stroke()
 
47
        del(context)
 
48
           
 
49