r20477 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Tue Oct 20 19:06:41 UTC 2015
Author: jghali
Date: Tue Oct 20 19:06:41 2015
New Revision: 20477
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20477
Log:
#13435: blend modes not imported from SVG file
Modified:
branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.cpp
branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.h
Modified: branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20477&path=/branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.cpp Tue Oct 20 19:06:41 2015
@@ -501,7 +501,10 @@
{
SvgStyle *gc = new SvgStyle;
if ( m_gc.top() )
+ {
*gc = *( m_gc.top() );
+ gc->filter.clear(); // filter is not inheritable
+ }
m_gc.push( gc );
}
@@ -673,6 +676,14 @@
}
}
}
+ if (!gc->filter.isEmpty())
+ {
+ if (filters.contains(gc->filter))
+ {
+ filterSpec filter = filters[gc->filter];
+ item->setFillBlendmode(filter.blendMode);
+ }
+ }
}
bool SVGPlug::isIgnorableNode( const QDomElement &e )
@@ -824,6 +835,8 @@
parseClipPath(b);
else if (STag2 == "pattern")
parsePattern(b);
+ else if (STag2 == "filter")
+ parseFilter(b);
else if ( b.hasAttribute("id") )
{
QString id = b.attribute("id");
@@ -903,6 +916,28 @@
QMap<QString, FPointArray>::iterator it = m_clipPaths.find(key);
if (it != m_clipPaths.end())
clipPath = it.value().copy();
+ }
+ }
+}
+
+void SVGPlug::parseFilterAttr(const QDomElement &e, PageItem* item)
+{
+ QString filterName;
+ if (e.hasAttribute("filter"))
+ {
+ QString attr = e.attribute("filter");
+ if (attr.startsWith( "url("))
+ {
+ unsigned int start = attr.indexOf("#") + 1;
+ unsigned int end = attr.lastIndexOf(")");
+ filterName = attr.mid(start, end - start);
+ if (filterName.isEmpty())
+ return;
+ }
+ if (filters.contains(filterName))
+ {
+ filterSpec spec = filters[filterName];
+ item->setFillBlendmode(spec.blendMode);
}
}
}
@@ -957,6 +992,7 @@
if (gc->clipPath.size() != 0)
clipPath = gc->clipPath.copy();
}
+ parseFilterAttr(e, neu);
if (gElements.count() == 0 || (gElements.count() < 2 && (clipPath.size() == 0) && (gc->Opacity == 1.0)))
{
// Unfortunately we have to take the long route here, or we risk crash on undo/redo
@@ -2294,6 +2330,15 @@
QMap<QString, FPointArray>::iterator it = m_clipPaths.find(key);
if (it != m_clipPaths.end())
obj->clipPath = it.value().copy();
+ }
+ }
+ else if (command == "filter")
+ {
+ if (params.startsWith( "url("))
+ {
+ unsigned int start = params.indexOf("#") + 1;
+ unsigned int end = params.lastIndexOf(")");
+ obj->filter = params.mid(start, end - start);
}
}
else if( !isIgnorableNodeName(command) )
@@ -2359,6 +2404,8 @@
parsePA( obj, "text-anchor", e.attribute( "text-anchor" ) );
if( !e.attribute( "text-decoration" ).isEmpty() )
parsePA( obj, "text-decoration", e.attribute( "text-decoration" ) );
+ if( !e.attribute( "filter" ).isEmpty() )
+ parsePA( obj, "filter", e.attribute( "filter" ) );
QString style = e.attribute( "style" ).simplified();
QStringList substyles = style.split(';', QString::SkipEmptyParts);
for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
@@ -2429,6 +2476,40 @@
}
if (gradient->gradientValid)
gradient->gradient.filterStops();
+}
+
+void SVGPlug::parseFilter(const QDomElement &b)
+{
+ QString id = b.attribute("id", "");
+ QString origName = id;
+ if (id.isEmpty())
+ return;
+
+ filterSpec fspec;
+ fspec.blendMode = 0;
+
+ QDomElement child = b.firstChildElement();
+ if (child.isNull() || (child.tagName() != "feBlend"))
+ {
+ filters.insert(id, fspec);
+ m_nodeMap.insert(origName, b);
+ return;
+ }
+
+ QString blendModeStr = child.attribute("mode");
+ if (blendModeStr == "normal")
+ fspec.blendMode = 0;
+ if (blendModeStr == "darken")
+ fspec.blendMode = 1;
+ if (blendModeStr == "lighten")
+ fspec.blendMode = 2;
+ if (blendModeStr == "multiply")
+ fspec.blendMode = 3;
+ if (blendModeStr == "screen")
+ fspec.blendMode = 4;
+
+ filters.insert(id, fspec);
+ m_nodeMap.insert(origName, b);
}
void SVGPlug::parsePattern(const QDomElement &b)
Modified: branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20477&path=/branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/import/svg/svgplugin.h Tue Oct 20 19:06:41 2015
@@ -179,6 +179,7 @@
QString textAnchor;
QString textDecoration;
FPointArray clipPath;
+ QString filter;
};
class SVGPlug : public QObject
@@ -209,6 +210,7 @@
void parseDefs(const QDomElement &e);
void parseClipPath(const QDomElement &e);
void parseClipPathAttr(const QDomElement &e, FPointArray& clipPath);
+ void parseFilterAttr(const QDomElement &e, PageItem* item);
QList<PageItem*> parseA(const QDomElement &e);
QList<PageItem*> parseGroup(const QDomElement &e);
QList<PageItem*> parseElement(const QDomElement &e);
@@ -241,6 +243,7 @@
void parsePA( SvgStyle *obj, const QString &command, const QString ¶ms );
void parseStyle( SvgStyle *obj, const QDomElement &e );
void parseColorStops(GradientHelper *gradient, const QDomElement &e);
+ void parseFilter(const QDomElement &b);
void parsePattern(const QDomElement &b);
void parseGradient( const QDomElement &e );
FPoint GetMaxClipO(FPointArray Clip);
@@ -271,6 +274,11 @@
QMap<QString, QString> importedPattTrans;
double inGroupXOrigin;
double inGroupYOrigin;
+ struct filterSpec
+ {
+ int blendMode;
+ };
+ QMap<QString, filterSpec> filters;
};
#endif
More information about the scribus-commit
mailing list