r19513 by jghali - more resilient behavior against broken patterns

scribus-commit scribus-commit at lists.scribus.net
Fri Sep 19 21:49:08 UTC 2014


Author: jghali
Date: Fri Sep 19 21:49:07 2014
New Revision: 19513

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19513
Log:
more resilient behavior against broken patterns

Modified:
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19513&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Fri Sep 19 21:49:07 2014
@@ -1741,7 +1741,8 @@
 			{
 				if (GrType == 8)
 				{
-					if ((patternVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternVal)))
+					ScPattern *pattern = m_Doc->checkedPattern(patternVal);
+					if (!pattern)
 					{
 						p->fill_gradient = VGradient(VGradient::linear);
 						p->fill_gradient.setRepeatMethod(GrExtend);
@@ -1763,7 +1764,7 @@
 					}
 					else
 					{
-						p->setPattern(&m_Doc->docPatterns[patternVal], patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY, patternMirrorX, patternMirrorY);
+						p->setPattern(pattern, patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY, patternMirrorX, patternMirrorY);
 						p->setFillMode(ScPainter::Pattern);
 					}
 				}
@@ -1884,11 +1885,10 @@
 			}
 			else if ((GrMask == 3) || (GrMask == 6) || (GrMask == 7) || (GrMask == 8))
 			{
-				if ((patternMaskVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternMaskVal)))
-					p->setMaskMode(0);
-				else
+				ScPattern *patternMask = m_Doc->checkedPattern(patternMaskVal);
+				if (patternMask)
 				{
-					p->setPatternMask(&m_Doc->docPatterns[patternMaskVal], patternMaskScaleX, patternMaskScaleY, patternMaskOffsetX, patternMaskOffsetY, patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
+					p->setPatternMask(patternMask, patternMaskScaleX, patternMaskScaleY, patternMaskOffsetX, patternMaskOffsetY, patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
 					if (GrMask == 3)
 						p->setMaskMode(2);
 					else if (GrMask == 6)
@@ -1897,6 +1897,10 @@
 						p->setMaskMode(5);
 					else
 						p->setMaskMode(6);
+				}
+				else
+				{
+					p->setMaskMode(0);
 				}
 			}
 			else
@@ -1968,7 +1972,8 @@
 					p->setupPolygon(&PoLine);
 				if (NamedLStyle.isEmpty())
 				{
-					if ((!patternStrokeVal.isEmpty()) && (m_Doc->docPatterns.contains(patternStrokeVal)))
+					ScPattern *strokePattern = m_Doc->checkedPattern(patternStrokeVal);
+					if (strokePattern)
 					{
 						if (patternStrokePath)
 						{
@@ -1977,7 +1982,7 @@
 						}
 						else
 						{
-							p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation, patternStrokeSkewX, patternStrokeSkewY, patternStrokeMirrorX, patternStrokeMirrorY);
+							p->setPattern(strokePattern, patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation, patternStrokeSkewX, patternStrokeSkewY, patternStrokeMirrorX, patternStrokeMirrorY);
 							p->setStrokeMode(ScPainter::Pattern);
 							p->strokePath();
 						}
@@ -9557,9 +9562,10 @@
 	{
 		if (NamedLStyle.isEmpty())
 		{
-			if ((!patternStrokeVal.isEmpty()) && (m_Doc->docPatterns.contains(patternStrokeVal)))
+			ScPattern *strokePattern = m_Doc->checkedPattern(patternStrokeVal);
+			if (strokePattern)
 			{
-				p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation, patternStrokeSkewX, patternStrokeSkewY, patternStrokeMirrorX, patternStrokeMirrorY);
+				p->setPattern(strokePattern, patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation, patternStrokeSkewX, patternStrokeSkewY, patternStrokeMirrorX, patternStrokeMirrorY);
 				p->setFillMode(ScPainter::Pattern);
 				p->fillPath();
 			}

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19513&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Fri Sep 19 21:49:07 2014
@@ -3825,6 +3825,18 @@
 	return true;
 }
 
+ScPattern* ScribusDoc::checkedPattern(QString &name)
+{
+	if (name.isEmpty() || !docPatterns.contains(name))
+		return 0;
+	ScPattern* pattern = &docPatterns[name];
+	if (pattern->width <= 0 || pattern->height <= 0)
+		return 0;
+	if (pattern->getPattern()->isNull())
+		return 0;
+	return pattern;
+}
+
 void ScribusDoc::setPatterns(QHash<QString, ScPattern> &patterns)
 {
 	docPatterns.clear();
@@ -3998,7 +4010,6 @@
 		return QStringList();
 	ScPattern *pat = &docPatterns[pattern];
 	QStringList pats;
-	pats.clear();
 	for (int c = 0; c < pat->items.count(); ++c)
 	{
 		QList<PageItem*> allItems;

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19513&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Fri Sep 19 21:49:07 2014
@@ -713,6 +713,10 @@
 	*/
 	bool addPattern(QString &name, ScPattern& pattern);
 	void setPatterns(QHash<QString, ScPattern> &patterns);
+	/*!
+	* @brief Check pattern with specified name and return it if valid
+	*/
+	ScPattern* checkedPattern(QString &name);
 	/*!
 	* @brief Builds a QStringList of the patterns used within the document
 	*/




More information about the scribus-commit mailing list