diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index ce05b82d..321c311f 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -83,7 +83,7 @@ class SVGExporter(Exporter): return bytes(xml) else: with open(fileName, 'w') as fh: - fh.write(xml) + fh.write(xml.encode('UTF-8')) xmlHeader = """\ @@ -171,8 +171,16 @@ def _generateItemSvg(item, nodes=None, root=None): doc = xml.parseString(xmlStr) else: childs = item.childItems() - tr = itemTransform(item, root) + tr = itemTransform(item, item.scene()) + ## offset to corner of root item + if isinstance(root, QtGui.QGraphicsScene): + rootPos = QtCore.QPoint(0,0) + else: + rootPos = root.scenePos() + tr2 = QtGui.QTransform() + tr2.translate(-rootPos.x(), -rootPos.y()) + tr = tr * tr2 #print item, pg.SRTTransform(tr) #tr.translate(item.pos().x(), item.pos().y()) @@ -239,17 +247,23 @@ def _generateItemSvg(item, nodes=None, root=None): nodes[name] = g1 g1.setAttribute('id', name) - ## If this item clips its children, we need to take car of that. + ## If this item clips its children, we need to take care of that. childGroup = g1 ## add children directly to this node unless we are clipping if not isinstance(item, QtGui.QGraphicsScene): ## See if this item clips its children if int(item.flags() & item.ItemClipsChildrenToShape) > 0: ## Generate svg for just the path - if isinstance(root, QtGui.QGraphicsScene): - path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape())) - else: - path = QtGui.QGraphicsPathItem(root.mapToParent(item.mapToItem(root, item.shape()))) - pathNode = _generateItemSvg(path, root=root).getElementsByTagName('path')[0] + #if isinstance(root, QtGui.QGraphicsScene): + #path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape())) + #else: + #path = QtGui.QGraphicsPathItem(root.mapToParent(item.mapToItem(root, item.shape()))) + path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape())) + item.scene().addItem(path) + try: + pathNode = _generateItemSvg(path, root=root).getElementsByTagName('path')[0] + finally: + item.scene().removeItem(path) + ## and for the clipPath element clip = name + '_clip' clipNode = g1.ownerDocument.createElement('clipPath') @@ -294,7 +308,10 @@ def correctCoordinates(node, item): elif ch.tagName == 'path': removeTransform = True newCoords = '' - for c in ch.getAttribute('d').strip().split(' '): + oldCoords = ch.getAttribute('d').strip() + if oldCoords == '': + continue + for c in oldCoords.split(' '): x,y = c.split(',') if x[0].isalpha(): t = x[0] @@ -317,8 +334,6 @@ def correctCoordinates(node, item): #fs = c[1]-c[2] #fs = (fs**2).sum()**0.5 #ch.setAttribute('font-size', str(fs)) - else: - print('warning: export not implemented for SVG tag %s (from item %s)' % (ch.tagName, item)) ## correct line widths if needed if removeTransform and ch.getAttribute('vector-effect') != 'non-scaling-stroke': diff --git a/pyqtgraph/graphicsItems/ArrowItem.py b/pyqtgraph/graphicsItems/ArrowItem.py index 153ea712..22d0065b 100644 --- a/pyqtgraph/graphicsItems/ArrowItem.py +++ b/pyqtgraph/graphicsItems/ArrowItem.py @@ -54,3 +54,8 @@ class ArrowItem(QtGui.QGraphicsPathItem): def paint(self, p, *args): p.setRenderHint(QtGui.QPainter.Antialiasing) QtGui.QGraphicsPathItem.paint(self, p, *args) + + def shape(self): + #if not self.opts['pxMode']: + #return QtGui.QGraphicsPathItem.shape(self) + return self.path \ No newline at end of file diff --git a/pyqtgraph/graphicsItems/GraphicsItem.py b/pyqtgraph/graphicsItems/GraphicsItem.py index 6a0825dd..34fd4bd7 100644 --- a/pyqtgraph/graphicsItems/GraphicsItem.py +++ b/pyqtgraph/graphicsItems/GraphicsItem.py @@ -496,4 +496,4 @@ class GraphicsItem(object): #self._exportOpts['antialias'] = True else: self._exportOpts = False - \ No newline at end of file + diff --git a/pyqtgraph/graphicsItems/TextItem.py b/pyqtgraph/graphicsItems/TextItem.py index b5666f6e..911057f4 100644 --- a/pyqtgraph/graphicsItems/TextItem.py +++ b/pyqtgraph/graphicsItems/TextItem.py @@ -115,9 +115,10 @@ class TextItem(UIGraphicsItem): self.viewRangeChanged() self.lastTransform = tr - p.setPen(self.border) - p.setBrush(self.fill) - p.setRenderHint(p.Antialiasing, True) - p.drawPolygon(self.textItem.mapToParent(self.textItem.boundingRect())) + if self.border.style() != QtCore.Qt.NoPen or self.fill.style() != QtCore.Qt.NoBrush: + p.setPen(self.border) + p.setBrush(self.fill) + p.setRenderHint(p.Antialiasing, True) + p.drawPolygon(self.textItem.mapToParent(self.textItem.boundingRect())) \ No newline at end of file