def _path(self, node): self.path = self.canvas.beginPath() self.path.moveTo(**utils.attr_get(node, ['x', 'y'])) for child_node in node.childNodes: if child_node.nodeType == node.ELEMENT_NODE: if child_node.localName == 'moveto': vals = utils.text_get(child_node).split() self.path.moveTo(utils.unit_get(vals[0]), utils.unit_get(vals[1])) elif child_node.localName == 'curvesto': vals = utils.text_get(child_node).split() while len(vals) > 5: pos = [] while len(pos) < 6: pos.append(utils.unit_get(vals.pop(0))) self.path.curveTo(*pos) elif (child_node.nodeType == node.TEXT_NODE): # Not sure if I must merge all TEXT_NODE ? data = child_node.data.split() while len(data) > 1: x = utils.unit_get(data.pop(0)) y = utils.unit_get(data.pop(0)) self.path.lineTo(x, y) if (not node.hasAttribute('close')) or \ utils.bool_get(node.getAttribute('close')): self.path.close() self.canvas.drawPath(self.path, **utils.attr_get(node, [], {'fill': 'bool', 'stroke': 'bool'}))
def _lines(self, node): line_str = utils.text_get(node).split() lines = [] while len(line_str) > 3: lines.append([utils.unit_get(l) for l in line_str[0:4]]) line_str = line_str[4:] self.canvas.lines(lines)
def _curves(self, node): line_str = utils.text_get(node).split() while len(line_str) > 7: self.canvas.bezier(*[utils.unit_get(l) for l in line_str[0:8]]) line_str = line_str[8:]