void QSvgTinyDocument::draw(QPainter *p, const QString &id, const QRectF &bounds) { QSvgNode *node = scopeNode(id); if (!node) { qDebug("Couldn't find node %s. Skipping rendering.", qPrintable(id)); return; } if (m_time.isNull()) { m_time.start(); } if (node->displayMode() == QSvgNode::NoneMode) return; p->save(); const QRectF elementBounds = node->transformedBounds(); mapSourceToTarget(p, bounds, elementBounds); QTransform originalTransform = p->worldTransform(); //XXX set default style on the painter QPen pen(Qt::NoBrush, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); pen.setMiterLimit(4); p->setPen(pen); p->setBrush(Qt::black); p->setRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::SmoothPixmapTransform); QStack<QSvgNode*> parentApplyStack; QSvgNode *parent = node->parent(); while (parent) { parentApplyStack.push(parent); parent = parent->parent(); } for (int i = parentApplyStack.size() - 1; i >= 0; --i) parentApplyStack[i]->applyStyle(p, m_states); // Reset the world transform so that our parents don't affect // the position QTransform currentTransform = p->worldTransform(); p->setWorldTransform(originalTransform); node->draw(p, m_states); p->setWorldTransform(currentTransform); for (int i = 0; i < parentApplyStack.size(); ++i) parentApplyStack[i]->revertStyle(p, m_states); //p->fillRect(bounds.adjusted(-5, -5, 5, 5), QColor(0, 0, 255, 100)); p->restore(); }
void QSvgTinyDocument::draw(QPainter *p, const QString &id, const QRectF &boundingWindow) { QSvgNode *node = scopeNode(id); if (!node) { qDebug("Couldn't find node %s. Skipping rendering.", qPrintable(id)); return; } p->save(); QMatrix matx = QMatrix(); QRectF bounds = node->transformedBounds(matx); adjustWindowBounds(p, boundingWindow, bounds); matx = p->worldMatrix(); //XXX set default style on the painter p->setPen(Qt::NoPen); p->setBrush(Qt::black); p->setRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::SmoothPixmapTransform); QStack<QSvgNode*> parentApplyStack; QQueue<QSvgNode*> parentRevertQueue; QSvgNode *parent = node->parent(); while (parent) { parentApplyStack.push(parent); parentRevertQueue.enqueue(parent); parent = parent->parent(); } foreach(QSvgNode *par, parentApplyStack) { par->applyStyle(p); }