r24818 by jghali - #16730: Incomplete import of SVG 1.0 file

scribus-commit scribus-commit at lists.scribus.net
Sun Jan 23 13:58:57 UTC 2022


Author: jghali
Date: Sun Jan 23 13:58:57 2022
New Revision: 24818

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24818
Log:
#16730: Incomplete import of SVG 1.0 file

Modified:
    trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
    trunk/Scribus/scribus/plugins/import/svg/svgplugin.h

Modified: trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24818&path=/trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp	Sun Jan 23 13:58:57 2022
@@ -14,6 +14,7 @@
 #include <QMimeData>
 #include <QPainterPath>
 #include <QRegExp>
+#include <QStack>
 #include <QTemporaryFile>
 
 #include "svgplugin.h"
@@ -358,6 +359,36 @@
 	return success;
 }
 
+QMap<QString, QDomElement> SVGPlug::buildNodeMap(const QDomElement &e)
+{
+	const QString idAttribute("id");
+	QMap<QString, QDomElement> nodeMap;
+
+	QStack<QDomElement> elementStack;
+	elementStack.push(e);
+
+	while (!elementStack.isEmpty())
+	{
+		QDomElement domElem = elementStack.pop();
+
+		for (QDomNode n = domElem.firstChild(); !n.isNull(); n = n.nextSibling())
+		{
+			QDomElement e = n.toElement();
+			if (e.isNull())
+				continue;
+
+			QString id = e.attribute(idAttribute);
+			if (!id.isEmpty())
+				nodeMap.insert(id, e);
+
+			if (e.hasChildNodes())
+				elementStack.push(e);
+		}
+	}
+
+	return nodeMap;
+}
+
 void SVGPlug::convert(const TransactionSettings& trSettings, int flags)
 {
 	bool ret = false;
@@ -404,6 +435,7 @@
 	if (!m_Doc->PageColors.contains("Black"))
 		m_Doc->PageColors.insert("Black", ScColor(0, 0, 0, 255));
 	m_gc.push(gc);
+
 	viewTransformX = 0;
 	viewTransformY = 0;
 	viewScaleX = 1;
@@ -428,7 +460,10 @@
 			m_gc.top()->matrix = matrix;
 		}
 	}
+
+	m_nodeMap = buildNodeMap(docElem);
 	Elements += parseDoc(docElem);
+
 	if (flags & LoadSavePlugin::lfCreateDoc)
 	{
 		m_Doc->documentInfo().setTitle(docTitle);
@@ -1058,12 +1093,7 @@
 			continue;
 		QString STag2 = parseTagName(b);
 		if (STag2 == "g")
-		{
-			QString id = b.attribute("id", "");
-			if (!id.isEmpty())
-				m_nodeMap.insert(id, b);
 			parseDefs(b);
-		}
 		else if (STag2 == "linearGradient" || STag2 == "radialGradient")
 			parseGradient(b);
 		else if (STag2 == "clipPath")
@@ -1074,12 +1104,6 @@
 			parseMarker(b);
 		else if (STag2 == "filter")
 			parseFilter(b);
-		else if (b.hasAttribute("id"))
-		{
-			QString id = b.attribute("id");
-			if (!id.isEmpty())
-				m_nodeMap.insert(id, b);
-		}
 	}
 }
 
@@ -1382,8 +1406,7 @@
 QList<PageItem*> SVGPlug::parseElement(const QDomElement &e)
 {
 	QList<PageItem*> GElements;
-	if (e.hasAttribute("id"))
-		m_nodeMap.insert(e.attribute("id"), e);
+
 	QString STag = parseTagName(e);
 	if (STag.startsWith("svg:"))
 		STag = STag.mid(4, - 1);
@@ -2900,8 +2923,7 @@
 
 void SVGPlug::parseFilter(const QDomElement &b)
 {
-	QString id = b.attribute("id", "");
-	QString origName = id;
+	QString id = b.attribute("id", QString());
 	if (id.isEmpty())
 		return;
 
@@ -2912,7 +2934,6 @@
 	if (child.isNull() || (child.tagName() != "feBlend"))
 	{
 		filters.insert(id, fspec);
-		m_nodeMap.insert(origName, b);
 		return;
 	}
 
@@ -2929,7 +2950,6 @@
 		fspec.blendMode = 4;
 
 	filters.insert(id, fspec);
-	m_nodeMap.insert(origName, b);
 }
 
 void SVGPlug::parseMarker(const QDomElement &b)
@@ -2982,7 +3002,6 @@
 		importedPattTrans.insert(origName, id);
 		markers.insert(id, mark);
 	}
-	m_nodeMap.insert(origName, b);
 	delete (m_gc.pop());
 }
 
@@ -3002,7 +3021,7 @@
 		}
 		gradhelper.reference = href;
 	}
-	QString id = b.attribute("id", "");
+	QString id = b.attribute("id", QString());
 	QString origName = id;
 	if (!id.isEmpty())
 	{
@@ -3037,7 +3056,6 @@
 			importedPatterns.append(id);
 			importedPattTrans.insert(origName, id);
 		}
-		m_nodeMap.insert(origName, b);
 		QString transf = b.attribute("patternTransform");
 		if (!transf.isEmpty())
 		{

Modified: trunk/Scribus/scribus/plugins/import/svg/svgplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24818&path=/trunk/Scribus/scribus/plugins/import/svg/svgplugin.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/svg/svgplugin.h	(original)
+++ trunk/Scribus/scribus/plugins/import/svg/svgplugin.h	Sun Jan 23 13:58:57 2022
@@ -286,6 +286,8 @@
 	void parsePattern(const QDomElement &b);
 	void parseGradient( const QDomElement &e );
 
+	QMap<QString, QDomElement> buildNodeMap(const QDomElement &e);
+
 	QDomDocument inpdoc;
 	QString docDesc;
 	QString docTitle;




More information about the scribus-commit mailing list