r22926 by jghali - createCustomLineStyle() : check that specified color effectively exists in document

scribus-commit scribus-commit at lists.scribus.net
Wed Apr 3 21:34:01 UTC 2019


Author: jghali
Date: Wed Apr  3 21:34:01 2019
New Revision: 22926

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22926
Log:
createCustomLineStyle() : check that specified color effectively exists in document

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22926&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp	Wed Apr  3 21:34:01 2019
@@ -214,50 +214,66 @@
 	}
 
 	multiLine ml;
-	for (int i = 0; i < PyList_Size(obj); i++) {
+	const ColorList& docColors = ScCore->primaryMainWindow()->doc->PageColors;
+
+	for (int i = 0; i < PyList_Size(obj); i++)
+	{
 		PyObject *line = PyList_GetItem(obj, i);
-		if (!PyDict_Check(line)) {
+		if (!PyDict_Check(line))
+		{
 			PyErr_SetString(PyExc_TypeError, "elements of list must be Dictionary.");
 			return nullptr;
 		}
 		struct SingleLine sl;
 		PyObject *val;
+
 		val = PyDict_GetItemString(line, "Color");
-		if (val) {
+		if (val)
 			sl.Color = PyString_AsString(val);
-		} else 
-			sl.Color = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineColor;;
+		else 
+			sl.Color = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineColor;
+
 		val = PyDict_GetItemString(line, "Dash");
-		if (val) {
+		if (val)
 			sl.Dash = PyInt_AsLong(val);
-		} else 
+		else 
 			sl.Dash = Qt::SolidLine;
+
 		val = PyDict_GetItemString(line, "LineEnd");
-		if (val) {
+		if (val)
 			sl.LineEnd = PyInt_AsLong(val);
-		} else 
+		else 
 			sl.LineEnd = Qt::FlatCap;
+
 		val = PyDict_GetItemString(line, "LineJoin");
-		if (val) {
+		if (val)
 			sl.LineJoin = PyInt_AsLong(val);
-		} else 
+		else 
 			sl.LineJoin = Qt::MiterJoin;
+
 		val = PyDict_GetItemString(line, "Shade");
-		if (val) {
+		if (val)
 			sl.Shade = PyInt_AsLong(val);
-		} else 
+		else 
 			sl.Shade = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineColorShade;
+
 		val = PyDict_GetItemString(line, "Width");
-		if (val) {
+		if (val)
 			sl.Width = PyFloat_AsDouble(val);
-		} else 
+		else 
 			sl.Width = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineWidth;
 
 		val = PyDict_GetItemString(line, "Shortcut");
-		if (val) {
+		if (val)
 			ml.shortcut = PyString_AsString(val);
-		} else 
+		else 
 			ml.shortcut = "";
+
+		if (!docColors.contains(sl.Color))
+		{
+			PyErr_SetString(PyExc_ValueError, QObject::tr("Specified color is not available in document.", "python error").toLocal8Bit().constData());
+			return nullptr;
+		}
 		ml.push_back(sl);
 	}
 	if (!ml.empty())




More information about the scribus-commit mailing list