r16887 by jghali - fix incorrect svg parsing when svg tags are prefixed with svg namespace

scribus-commit scribus-commit at lists.scribus.net
Fri Oct 7 23:52:10 UTC 2011


Author: jghali
Date: Fri Oct  7 23:52:10 2011
New Revision: 16887

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16887
Log:
fix incorrect svg parsing when svg tags are prefixed with svg namespace

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

Modified: branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16887&path=/branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.cpp Fri Oct  7 23:52:10 2011
@@ -812,15 +812,15 @@
 		parseStyle( &svgStyle, b );
 		if ( !svgStyle.Display) 
 			continue;
-		QString STag2 = b.tagName();
-		if ( STag2 == "g" )
+		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" )
+		else if (STag2 == "linearGradient" || STag2 == "radialGradient")
 			parseGradient( b );
 		else if (STag2 == "clipPath")
 			parseClipPath(b);
@@ -1041,53 +1041,53 @@
 	QList<PageItem*> GElements;
 	if (e.hasAttribute("id"))
 		m_nodeMap.insert(e.attribute("id"), e);
-	QString STag = e.tagName();
-	if ( STag == "g" )
+	QString STag = parseTagName(e);
+	if (STag == "g")
 	{
 		GElements = parseGroup( e );
 		return GElements;
 	}
-	if ( STag == "defs" )
+	if (STag == "defs")
 		parseDefs(e);
-	else if ( STag == "a" )
+	else if (STag == "a")
 		GElements = parseA(e);
-	else if ( STag == "switch" )
+	else if (STag == "switch")
 		GElements = parseSwitch(e);
-	else if ( STag == "symbol" )
+	else if (STag == "symbol")
 		GElements = parseSymbol(e);
-	else if ( STag == "use" )
+	else if (STag == "use")
 		GElements = parseUse(e);
-	else if ( STag == "linearGradient" || STag == "radialGradient" )
+	else if (STag == "linearGradient" || STag == "radialGradient" )
 		parseGradient( e );
-	else if ( STag == "rect" )
+	else if (STag == "rect")
 		GElements = parseRect(e);
-	else if ( STag == "ellipse" )
+	else if (STag == "ellipse")
 		GElements = parseEllipse(e);
-	else if ( STag == "circle" )
+	else if (STag == "circle")
 		GElements = parseCircle(e);
-	else if ( STag == "line" )
+	else if (STag == "line")
 		GElements = parseLine(e);
-	else if ( STag == "path" )
+	else if (STag == "path")
 		GElements = parsePath(e);
-	else if ( STag == "polyline" || e.tagName() == "polygon" )
+	else if (STag == "polyline" || STag == "polygon")
 		GElements = parsePolyline(e);
-	else if ( STag == "text" )
+	else if (STag == "text")
 		GElements = parseText(e);
-	else if ( STag == "clipPath" )
+	else if (STag == "clipPath")
 		parseClipPath(e);
-	else if ( STag == "desc" )
+	else if (STag == "desc")
 	{
 		if (groupLevel == 1)
 			docDesc = e.text();
 	}
-	else if ( STag == "title" )
+	else if (STag == "title")
 	{
 		if (groupLevel == 1)
 			docTitle = e.text();
 	}
-	else if ( STag == "image" )
+	else if (STag == "image")
 		GElements = parseImage(e);
-/*	else if ( STag == "i:pgf" )
+/*	else if (STag == "i:pgf")
 	{
 		QByteArray cdat;
 		QByteArray ddat;
@@ -1160,7 +1160,7 @@
 /*	else if( STag == "image" )
 		GElements = parseImage(e);
 	} */
-	else if (!isIgnorableNodeName(STag) )
+	else if (!isIgnorableNodeName(STag))
 	{
 		// warn if unsupported SVG feature are encountered
 		if (!m_unsupportedFeatures.contains(STag))
@@ -1334,10 +1334,10 @@
 	QString points = e.attribute( "points" );
 	if (!points.isEmpty())
 	{
-		QString STag = e.tagName();
+		QString tagName = parseTagName(e);
 		points = points.simplified().replace(',', " ");
 		QStringList pointList = points.split( ' ', QString::SkipEmptyParts );
-		if (( e.tagName() == "polygon" ) && (pointList.count() > 4))
+		if ((tagName == "polygon" ) && (pointList.count() > 4))
 			z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol, true);
 		else
 			z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol, true);
@@ -1364,7 +1364,7 @@
 				ite->PoLine.svgLineTo(x, y);
 			}
 		}
-		if (( STag == "polygon" ) && (pointList.count() > 4))
+		if (( tagName == "polygon" ) && (pointList.count() > 4))
 			ite->PoLine.svgClosePath();
 		else
 			ite->convertTo(PageItem::PolyLine);
@@ -1418,7 +1418,7 @@
 		getTextChunkWidth(e, chunkWidth);
 	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling())
 	{
-		if (n.isElement() && (n.toElement().tagName() == "tspan"))
+		if (n.isElement() && (parseTagName(n.toElement()) == "tspan"))
 		{
 			QList<PageItem*> el = parseTextSpan(n.toElement(), currentPos, chunkWidth);
 			for (int ec = 0; ec < el.count(); ++ec)
@@ -1448,7 +1448,7 @@
 	}
 	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling())
 	{
-		if (n.isElement() && (n.toElement().tagName() == "tspan"))
+		if (n.isElement() && (n.toElement().localName() == "tspan"))
 		{
 			QList<PageItem*> el = parseTextSpan(n.toElement(), currentPos, chunkW);
 			for (int ec = 0; ec < el.count(); ++ec)
@@ -1513,7 +1513,7 @@
 	for (QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling())
 	{
 		QDomElement de = n.toElement();
-		QString STag = de.tagName();
+		QString STag = parseTagName(de);
 		if (STag == "foreignObject")
 		{
 			if (de.hasAttribute("xlink:href"))
@@ -1576,7 +1576,7 @@
 	if (it != m_nodeMap.end())
 	{
 		QDomElement elem = it.value().toElement();
-		if( elem.tagName() == "symbol" )
+		if (parseTagName(elem) == "symbol" )
 			UElements = parseGroup(elem);
 		else
 			UElements = parseElement(elem);
@@ -1694,7 +1694,7 @@
 	QDomNode c = e.firstChild();
 	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling())
 	{
-		if (n.isElement() && (n.toElement().tagName() == "tspan"))
+		if (n.isElement() && (parseTagName(n.toElement()) == "tspan"))
 		{
 			QDomElement elem = n.toElement();
 			if (elem.hasAttribute("x") || elem.hasAttribute("y"))
@@ -2382,7 +2382,7 @@
 	{
 		opa = 1.0;
 		QDomElement stop = n.toElement();
-		if(stop.tagName() == "stop")
+		if (parseTagName(stop) == "stop")
 		{
 			QString temp = stop.attribute( "offset" );
 			if( temp.contains( '%' ) )
@@ -2544,7 +2544,8 @@
 		}
 		gradhelper.reference = href;
 	}
-	if (e.tagName() == "linearGradient")
+	QString tagName = parseTagName(e);
+	if (tagName == "linearGradient")
 	{
 		if (e.hasAttribute("x1"))
 		{
@@ -2629,6 +2630,14 @@
 	m_gradients.insert(e.attribute("id"), gradhelper);
 }
 
+QString SVGPlug::parseTagName(const QDomElement& element)
+{
+	QString tagName(element.tagName());
+	if (tagName.startsWith("svg:"))
+		return tagName.mid(4, -1);
+	return tagName;
+}
+
 SVGPlug::~SVGPlug()
 {
 	delete tmpSel;

Modified: branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16887&path=/branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.h
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.h (original)
+++ branches/Version135/Scribus/scribus/plugins/import/svg/svgplugin.h Fri Oct  7 23:52:10 2011
@@ -236,6 +236,7 @@
 	QColor  parseColorN( const QString &rgbColor );
 	QString parseColor( const QString &s );
 	QString parseIccColor( const QString &s );
+	QString parseTagName( const QDomElement &e );
 	void parsePA( SvgStyle *obj, const QString &command, const QString &params );
 	void parseStyle( SvgStyle *obj, const QDomElement &e );
 	void parseColorStops(GradientHelper *gradient, const QDomElement &e);




More information about the scribus-commit mailing list