コード例 #1
0
ファイル: document.py プロジェクト: PyCManager/baseui
 def getBrushFromState(self, path=None):
     brushcolour = self.state.get('fill', 'black').strip()
     type, details = paintValue.parseString(brushcolour)
     if type == "URL":
         url, fallback = details
         element = self.resolveURL(url)
         if not element:
             if fallback:
                 type, details = fallback
             else:
                 r, g, b, = 0, 0, 0
         else:
             if element.tag == '{http://www.w3.org/2000/svg}linearGradient':
                 box = path.GetBox()
                 x, y, w, h = box.Get()
                 return wx.GraphicsRenderer.GetDefaultRenderer(
                 ).CreateLinearGradientBrush(x, y, x + w, y + h,
                                             wx.Colour(0, 0, 255, 128),
                                             wx.RED)
             elif element.tag == '{http://www.w3.org/2000/svg}radialGradient':
                 box = path.GetBox()
                 x, y, w, h = box.Get()
                 print w
                 mx = wx.GraphicsRenderer.GetDefaultRenderer().CreateMatrix(
                     x, y, w, h)
                 cx, cy = mx.TransformPoint(0.5, 0.5)
                 fx, fy = cx, cy
                 return wx.GraphicsRenderer.GetDefaultRenderer(
                 ).CreateRadialGradientBrush(cx, cy, fx, fy,
                                             (max(w, h)) / 2,
                                             wx.Colour(0, 0, 255,
                                                       128), wx.RED)
             else:
                 #invlid gradient specified
                 return wx.NullBrush
         r, g, b = 0, 0, 0
     if type == 'CURRENTCOLOR':
         type, details = paintValue.parseString(
             self.state.get('color', 'none'))
     if type == 'RGB':
         r, g, b = details
     elif type == "NONE":
         return wx.NullBrush
     opacity = self.state.get('fill-opacity',
                              self.state.get('opacity', '1'))
     opacity = float(opacity)
     opacity = min(max(opacity, 0.0), 1.0)
     a = 255 * opacity
     #using try/except block instead of
     #just setdefault because the wxBrush and wxColour would
     #be created every time anyway in order to pass them,
     #defeating the purpose of the cache
     try:
         return SVGDocument.brushCache[(r, g, b, a)]
     except KeyError:
         return SVGDocument.brushCache.setdefault(
             (r, g, b, a), wx.Brush(wx.Colour(r, g, b, a)))
コード例 #2
0
ファイル: document.py プロジェクト: 9153200/Software
 def getBrushFromState(self, path = None):
     brushcolour = self.state.get('fill', 'black').strip()
     type, details = paintValue.parseString(brushcolour)
     if type == "URL":
         url, fallback = details
         element = self.resolveURL(url)
         if not element:
             if fallback:
                 type, details = fallback
             else:
                 r, g, b, = 0, 0, 0
         else:
             if element.tag == '{http://www.w3.org/2000/svg}linearGradient':
                 box = path.GetBox()
                 x, y, w, h = box.Get()
                 return wx.GraphicsRenderer.GetDefaultRenderer().CreateLinearGradientBrush(
                     x, y, x+w, y+h, wx.Colour(0, 0, 255, 128), wx.RED
                 )
             elif element.tag == '{http://www.w3.org/2000/svg}radialGradient':
                 box = path.GetBox()
                 x, y, w, h = box.Get()
                 #print w
                 mx = wx.GraphicsRenderer.GetDefaultRenderer().CreateMatrix(x, y, w, h)
                 cx, cy = mx.TransformPoint(0.5, 0.5)
                 fx, fy = cx, cy
                 return wx.GraphicsRenderer.GetDefaultRenderer().CreateRadialGradientBrush(
                     cx, cy,
                     fx, fy,
                     (max(w, h))/2,
                     wx.Colour(0, 0, 255, 128), wx.RED
                 )
             else:
                 #invlid gradient specified
                 return wx.NullBrush
         r, g, b  = 0, 0, 0
     if type == 'CURRENTCOLOR':
         type, details = paintValue.parseString(self.state.get('color', 'none'))
     if type == 'RGB':
         r, g, b = details
     elif type == "NONE":
         return wx.NullBrush
     opacity = self.state.get('fill-opacity', self.state.get('opacity', '1'))
     opacity = float(opacity)
     opacity = min(max(opacity, 0.0), 1.0)
     a = 255 * opacity
     #using try/except block instead of
     #just setdefault because the wxBrush and wxColour would
     #be created every time anyway in order to pass them,
     #defeating the purpose of the cache
     try:
         return SVGDocument.brushCache[(r, g, b, a)]
     except KeyError:
         return SVGDocument.brushCache.setdefault((r, g, b, a), wx.Brush(wx.Colour(r, g, b, a)))
コード例 #3
0
ファイル: document.py プロジェクト: burnpanck/enable
 def getBrushFromState(self, path=None):
     brushcolour = self.state.get('fill', 'black').strip()
     type, details = paintValue.parseString(brushcolour)
     if type == "URL":
         url, fallback = details
         url = urlparse.urlunsplit(url)
         try:
             element = self.dereference(url)
         except ParseError:
             element = None
         if element is None:
             if fallback:
                 type, details = fallback
             else:
                 r, g, b, = 0, 0, 0
         else:
             # The referencing tag controls the kind of gradient. Mostly,
             # it's just the stops that are pulled from the referenced
             # gradient tag.
             element_tag = element.tag
             if element_tag not in (SVG.linearGradient, SVG.radialGradient):
                 if '}' in element_tag:
                     element_tag[element_tag.find('}')+1:]
                 warnings.warn("<%s> not implemented" % element_tag)
                 return self.renderer.NullBrush
             href = element.get(XLink.href, None)
             seen = set([element])
             # The attributes on the referencing element override those on the
             # referenced element.
             state = dict(element.items())
             while href is not None:
                 # Gradient is a reference.
                 element = self.dereference(href)
                 if element in seen:
                     # FIXME: if they are loaded from another file, will element
                     # identity work correctly?
                     raise ValueError("Element referred to by %r is a "
                         "circular reference." % href)
                 seen.add(element)
                 #new_state = dict(element.items())
                 #new_state.update(state)
                 #state = new_state
                 href = element.get(XLink.href, None)
             spreadMethod = state.get('spreadMethod', 'pad')
             transforms = self.createTransformOpsFromNode(state,
                 'gradientTransform')
             if not transforms:
                 transforms = []
             units = state.get('gradientUnits', 'objectBoundingBox')
             stops = self.parseStops(element)
             if stops.size == 0:
                 return self.renderer.NullBrush
             if element_tag == SVG.linearGradient:
                 x1 = attrAsFloat(state, 'x1', '0%')
                 y1 = attrAsFloat(state, 'y1', '0%')
                 x2 = attrAsFloat(state, 'x2', '100%')
                 y2 = attrAsFloat(state, 'y2', '0%')
                 return self.renderer.createLinearGradientBrush(x1,y1,x2,y2,
                     stops, spreadMethod=spreadMethod, transforms=transforms,
                     units=units)
             elif element_tag == SVG.radialGradient:
                 cx = attrAsFloat(state, 'cx', '50%')
                 cy = attrAsFloat(state, 'cy', '50%')
                 r = attrAsFloat(state, 'r', '50%')
                 fx = attrAsFloat(state, 'fx', state.get('cx', '50%'))
                 fy = attrAsFloat(state, 'fy', state.get('cy', '50%'))
                 return self.renderer.createRadialGradientBrush(cx,cy, r, stops,
                     fx,fy, spreadMethod=spreadMethod, transforms=transforms,
                     units=units)
             else:
                 #invlid gradient specified
                 return self.renderer.NullBrush
         r,g,b  = 0,0,0
     if type == 'CURRENTCOLOR':
         type, details = paintValue.parseString(self.state.get('color', 'none'))
     if type == 'RGB':
         r,g,b = details
     elif type == "NONE":
         #print 'returning null brush'
         return self.renderer.NullBrush
     opacity = self.state.get('fill-opacity', self.state.get('opacity', '1'))
     opacity = float(opacity)
     opacity = min(max(opacity, 0.0), 1.0)
     a = 255 * opacity
     #using try/except block instead of
     #just setdefault because the brush and colour would
     #be created every time anyway in order to pass them,
     #defeating the purpose of the cache
     try:
         brush = self.brushCache[(r,g,b,a)]
     except KeyError:
         brush = self.brushCache.setdefault((r,g,b,a), self.renderer.createBrush((r,g,b,a)))
     return brush