def make_shape_element(cls, shape, ctf, parent_key): group = etree.Element("g") group.set("id", shape.symbol + "shape") for e in shape.edges: # line colors linecolors = e.get_colors_from_category('l') for i, lineColor in zip(xrange(len(linecolors)), linecolors): allpath = [] pathElm = Path('line') path = cls._reverse(e.get_path(i, 'line')) if len(path) > 0: if len(e.colors) > 0: allpath.extend(path) pathElm.set("stroke-width", str(e.lineWidths[i])) pathElm.set("stroke", LUtil.rgb_to_hex(lineColor['l'])) merged_allpath_list = cls._merge_path(allpath) all_data = "" for merged_allpath in merged_allpath_list: data = cls._path_data(merged_allpath) all_data += data if len(all_data) > 0: pathElm.set("d", all_data) group.append(pathElm) # solid colors solidcolors = e.get_colors_from_category('s') for i, color in zip(xrange(len(solidcolors)), solidcolors): allpath = [] path = e.get_path(i, 'left') if len(path) > 0: allpath.extend(path) path = cls._reverse(e.get_path(i, 'right')) if len(path) > 0: allpath.extend(path) merged_allpath_list = cls._merge_path(allpath) pathElm = Path() clr = color['s'] for colorTransform in ctf: if isinstance(clr, tuple): clr = PUtil.colortrans(shape.symbol, color['s'], colorTransform) clr = PUtil.colortrans(parent_key, clr, colorTransform) else: # gradient opacity = PUtil.colortrans_only_alpha(parent_key, colorTransform)/256 if opacity > 0.0: pathElm.set("fill-opacity", str(opacity)) if isinstance(clr, tuple): pathElm.set("fill", LUtil.rgb_to_hex(clr)) if clr[3] < 256: opacity = float(clr[3])/256 if opacity > 0.0: pathElm.set("fill-opacity", str(opacity)) else: pathElm.set("fill", clr) all_data = "" for merged_allpath in merged_allpath_list: data = cls._path_data(merged_allpath) all_data += data if len(all_data) > 0: pathElm.set("d", all_data) group.append(pathElm) if len(ctf) > 0: ctf.pop(0) return group
def __init__(self, clr, position, attrib=None, nsmap=None, **_extra): super(Stop, self).__init__(attrib=None, nsmap=None, **_extra) self.tag = 'stop' self.set('stop-color' , LUtil.rgb_to_hex(clr)) self.set('stop-opacity', str(float(clr[3]/255))) self.set('offset' , str(float(position)/255))