~charclo-michael/+junk/messing-with-glitter

« back to all changes in this revision

Viewing changes to src/glitter/cairo_svg.py

  • Committer: Michael Charclo
  • Date: 2008-05-22 16:30:02 UTC
  • Revision ID: charclo.michael@gmail.com-20080522163002-2r6jrh1006gotfvt
Forgot to add some files.

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 clutter
 
11
import cairo
 
12
import rsvg
 
13
from clutter.cluttercairo import CairoTexture
 
14
 
 
15
class SVGTexture(CairoTexture):
 
16
    """ Creates a CairoTexture based on a given SVG """
 
17
 
 
18
    def __init__(self, uri, width, height):
 
19
        
 
20
        CairoTexture.__init__(self, width, height)
 
21
        
 
22
        self.uri = uri
 
23
        self.width = width
 
24
        self.height = height
 
25
        
 
26
        #self.svg_context = cairo.svg.Context()
 
27
        self.context = self.cairo_create()
 
28
        
 
29
        #print rsvg.Handle
 
30
        #print 'loading file'
 
31
        self.svg = rsvg.Handle(self.uri)
 
32
        #print 'rendering'
 
33
        self.matrix = cairo.Matrix((self.width * 1.0 / self.svg.props.width),0,0,(self.height * 1.0 / self.svg.props.height),0,0)
 
34
        #print self.svg.props.width, self.svg.props.height, self.svg.props.em, self.svg.props.ex
 
35
        self.context.transform(self.matrix)
 
36
        self.svg.render_cairo(self.context)
 
37
               
 
38
        self.context.close_path()
 
39
        
 
40
        self.context.stroke() 
 
41
        #print 'done'
 
42
        del(self.context)
 
43
        
 
44
    def resize(self, width, height):
 
45
        
 
46
        pass        
 
47