~ubuntu-branches/ubuntu/trusty/python-enable/trusty

« back to all changes in this revision

Viewing changes to enthought/savage/svg/backends/wx/renderer.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2010-02-28 14:56:36 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100228145636-9ghfhe3uy37tt3q6
Tags: 3.3.0-1
* New upstream release
* Bump Standards-Version to 3.8.4
* Switch to source format 3.0
* Update patches/freetype2.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import copy
1
2
import numpy
2
3
import warnings
3
4
import wx
4
5
 
5
6
from enthought.savage.svg.backends.null.null_renderer import NullRenderer
6
7
 
 
8
 
 
9
def _fixup_path_methods(path):
 
10
    def _new_add_rounded_rectangle(self, x, y, w, h, rx, ry):
 
11
        r = numpy.sqrt(rx*rx + ry*ry)
 
12
        self.AddRoundedRectangle(x, y, w, h, r)
 
13
 
 
14
    path.__class__.AddRoundedRectangleEx = _new_add_rounded_rectangle
 
15
 
7
16
class AbstractGradientBrush(object):
8
17
    """ Abstract base class for gradient brushes so they can be detected easily.
9
18
    """
16
25
        """
17
26
        x0, y0, w, h = bbox
18
27
        gc.concat_ctm(((w, 0, 0), (0, h, 0), (x0, y0, 1)))
19
 
 
 
28
        
20
29
class Renderer(NullRenderer):
21
30
 
22
31
    NullBrush = wx.NullBrush
92
101
        if len(stops) > 2:
93
102
            warnings.warn("Wx only supports 2 gradient stops, but %d were specified" % len(stops))
94
103
 
95
 
 
96
 
 
97
104
        def convert_stop(stop):
98
105
            offset, red, green, blue, opacity = stop
99
106
            color = wx.Colour(red*255, green*255, blue*255, opacity*255)
100
107
            return offset, color
101
108
 
102
109
        start_offset, start_color = convert_stop(stops[0])
103
 
        end_offset, end_color = convert_stop(stops[1])
 
110
        end_offset, end_color = convert_stop(stops[-1])
104
111
 
105
112
        if fx is None:
106
113
            fx = cx
107
114
        if fy is None:
108
115
            fy = cy
109
 
 
 
116
                        
110
117
        wx_renderer = wx.GraphicsRenderer.GetDefaultRenderer()
111
 
        return wx_renderer.CreateRadialGradientBrush(cx, cy, fx, fy, r,
 
118
        return wx_renderer.CreateRadialGradientBrush(fx, fy, cx, cy, r,
112
119
                                                     start_color, end_color)
113
120
 
114
121
    @staticmethod
129
136
 
130
137
    @staticmethod
131
138
    def makePath():
132
 
        return wx.GraphicsRenderer_GetDefaultRenderer().CreatePath()
 
139
        path = wx.GraphicsRenderer_GetDefaultRenderer().CreatePath()
 
140
        _fixup_path_methods(path)
 
141
        return path
133
142
 
134
143
    @staticmethod
135
144
    def popState(*args):
201
210
        #rather than the top as with our API. This function
202
211
        #will measure and then re-orient the text as needed.
203
212
        w, h = context.GetTextExtent(text)
 
213
        
 
214
        if anchor != 'start':
 
215
            if anchor == 'middle':
 
216
                x -= w/2.0
 
217
            elif anchor == 'end':
 
218
                x -= w
 
219
        
204
220
        y -= h
205
221
        context.DrawText(text, x, y)
206
222