def getPenFromState(self): pencolour = self.state.get('stroke', 'none') if pencolour == 'currentColor': pencolour = self.state.get('color', 'none') if pencolour == 'transparent': return wx.TRANSPARENT_PEN if pencolour == 'none': return wx.NullPen type, value = colourValue.parseString(pencolour) if type == 'URL': warnings.warn("Color servers for stroking not implemented") return wx.NullPen else: if value[:3] == (-1, -1, -1): return wx.NullPen pen = wx.Pen(wx.Colour(*value)) width = self.state.get('stroke-width') if width: width, units = values.length.parseString(width) pen.SetWidth(width) capmap = { 'butt':wx.CAP_BUTT, 'round':wx.CAP_ROUND, 'square':wx.CAP_PROJECTING } joinmap = { 'miter':wx.JOIN_MITER, 'round':wx.JOIN_ROUND, 'bevel':wx.JOIN_BEVEL } pen.SetCap(capmap.get(self.state.get('stroke-linecap', None), wx.CAP_BUTT)) pen.SetJoin(joinmap.get(self.state.get('stroke-linejoin', None), wx.JOIN_MITER)) return wx.GraphicsRenderer_GetDefaultRenderer().CreatePen(pen)
def getPenFromState(self): pencolour = self.state.get('stroke', 'none') if pencolour == 'currentColor': pencolour = self.state.get('color', 'none') if pencolour == 'transparent': return self.renderer.TransparentPen if pencolour == 'none': return self.renderer.NullPen type, value = colourValue.parseString(pencolour) if type == 'URL': warnings.warn("Color servers for stroking not implemented") return self.renderer.NullPen else: if value[:3] == (-1, -1, -1): return self.renderer.NullPen pen = self.renderer.createPen(value) width = self.state.get('stroke-width') if width: width, units = values.length.parseString(width) pen.SetWidth(width) stroke_dasharray = self.state.get('stroke-dasharray', 'none') if stroke_dasharray != 'none': stroke_dasharray = map(valueToPixels, stroke_dasharray.replace(',', ' ').split()) if len(stroke_dasharray) % 2: # Repeat to get an even array. stroke_dasharray = stroke_dasharray * 2 stroke_dashoffset = valueToPixels(self.state.get('stroke-dashoffset', '0')) self.renderer.setPenDash(pen, stroke_dasharray, stroke_dashoffset) pen.SetCap(self.renderer.caps.get(self.state.get('stroke-linecap', None), self.renderer.caps['butt'])) pen.SetJoin(self.renderer.joins.get(self.state.get('stroke-linejoin', None), self.renderer.joins['miter'])) return self.renderer.createNativePen(pen)
def parseStops(self, element): """ Parse the color stops from a gradient definition. """ stops = [] gradient_state = self.getLocalState(element) for stop in element: if stop.tag != SVG.stop: warnings.warn("Skipping non-<stop> element <%s> in <%s>" % (stop.tag, element.tag)) continue stopstate = self.getLocalState(stop, gradient_state) offset = fractionalValue(stop.get('offset')) offset = max(min(offset, 1.0), 0.0) default_opacity = '1' color = stopstate.get('stop-color', 'black') if color in ['inherit', 'currentColor']: # Try looking up in the gradient element itself. # FIXME: Look farther up? color = stopstate.get('color', 'black') elif color == 'none': color = 'black' default_opacity = '0' type, color = colourValue.parseString(color) if type == 'URL': warnings.warn("Color servers for gradients not implemented") elif color[:3] == (-1, -1, -1): # FIXME: is this right? color = (0.0, 0.0, 0.0, 0.0) opacity = stopstate.get('stop-opacity', default_opacity) if opacity == 'inherit': # FIXME: what value to inherit? opacity = '1' opacity = float(opacity) row = (offset, color[0]/255., color[1]/255., color[2]/255., opacity) stops.append(row) stops.sort() if len(stops) == 0: return numpy.array([]) if stops[0][0] > 0.0: stops.insert(0, (0.0,) + stops[0][1:]) if stops[-1][0] < 1.0: stops.append((1.0,) + stops[-1][1:]) return numpy.transpose(stops)
def getPenFromState(self): pencolour = self.state.get('stroke', 'none') if pencolour == 'currentColor': pencolour = self.state.get('color', 'none') if pencolour == 'transparent': return wx.TRANSPARENT_PEN if pencolour == 'none': return wx.NullPen type, value = colourValue.parseString(pencolour) if type == 'URL': warnings.warn("Color servers for stroking not implemented") return wx.NullPen else: if value[:3] == (-1, -1, -1): return wx.NullPen pen = wx.Pen(wx.Colour(*value)) width = self.state.get('stroke-width') if width: width, units = values.length.parseString(width) pen.SetWidth(width) capmap = { 'butt': wx.CAP_BUTT, 'round': wx.CAP_ROUND, 'square': wx.CAP_PROJECTING } joinmap = { 'miter': wx.JOIN_MITER, 'round': wx.JOIN_ROUND, 'bevel': wx.JOIN_BEVEL } pen.SetCap( capmap.get(self.state.get('stroke-linecap', None), wx.CAP_BUTT)) pen.SetJoin( joinmap.get(self.state.get('stroke-linejoin', None), wx.JOIN_MITER)) return wx.GraphicsRenderer_GetDefaultRenderer().CreatePen(pen)