r15202 by jghali - #9180 : fix crash when selecting frame after modifying text in story editor

scribus-commit scribus-commit at lists.scribus.net
Wed Jun 16 23:50:52 CEST 2010


Revision: 15202
Author: jghali
Date: 2010-06-16T21:45:37.774513Z
Commit message: #9180 : fix crash when selecting frame after modifying text in story editor

Changeset: 
M  /trunk/Scribus/scribus/scpainter.cpp
M  /trunk/Scribus/scribus/scpainterex_cairo.cpp
M  /trunk/Scribus/scribus/plugins/svgexplugin/svgexplugin.cpp

Diffs:
Index: scribus/scpainterex_cairo.cpp
===================================================================
--- scribus/scpainterex_cairo.cpp	(revision 15201)
+++ scribus/scpainterex_cairo.cpp	(revision 15202)
@@ -457,12 +457,18 @@
 	FPoint p2( gradient.vector().x(), gradient.vector().y() );
 	cairo_pattern_t *pat = cairo_pattern_create_linear (p1.x(), p1.y(), p2.x(), p2.y());	
 
+	bool   isFirst  = true;
+	double lastStop = 0.0;
 	for( uint index = 0 ; index < gradient.Stops(); index++)
 	{
 		stop  = colorStops.at(index);
+		if ((lastStop == stop->rampPoint) && (!isFirst))
+			continue;
+		isFirst = false;
 		color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
 		color.getRgbF(&r, &g, &b);
 		cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+		lastStop = stop->rampPoint;
 	}
 
 	cairo_set_source (m_cr, pat);
@@ -486,12 +492,18 @@
 
 	cairo_pattern_t* pat = cairo_pattern_create_radial (pc.x(), pc.y(), 0.1, pc.x(), pc.y(), rad);	
 
+	bool   isFirst  = true;
+	double lastStop = 0.0;
 	for( uint index = 0 ; index < gradient.Stops() ; index++)
 	{
 		stop  = colorStops.at(index);
+		if ((lastStop == stop->rampPoint) && (!isFirst))
+			continue;
+		isFirst = false;
 		color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
 		color.getRgbF(&r, &g, &b);
 		cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+		lastStop = stop->rampPoint;
 	}
 	
 	cairo_set_source (m_cr, pat);
Index: scribus/scpainter.cpp
===================================================================
--- scribus/scpainter.cpp	(revision 15201)
+++ scribus/scpainter.cpp	(revision 15202)
@@ -1716,6 +1716,8 @@
 			}
 			else
 			{
+				bool   isFirst = true;
+				double rampPoint, lastPoint = 0.0;
 				double x1 = fill_gradient.origin().x();
 				double y1 = fill_gradient.origin().y();
 				double x2 = fill_gradient.vector().x();
@@ -1733,6 +1735,10 @@
 				for( int offset = 0 ; offset < colorStops.count() ; offset++ )
 				{
 					qStopColor = colorStops[ offset ]->color;
+					rampPoint  = colorStops[ offset ]->rampPoint;
+					if ((lastPoint == rampPoint) && (!isFirst))
+						continue;
+					isFirst = false;
 					int h, s, v, sneu, vneu;
 					int shad = colorStops[offset]->shade;
 					qStopColor.getHsv(&h, &s, &v);
@@ -1743,6 +1749,7 @@
 					double r, g, b;
 					qStopColor.getRgbF(&r, &g, &b);
 					cairo_pattern_add_color_stop_rgba (pat, colorStops[ offset ]->rampPoint, r, g, b, a);
+					lastPoint = rampPoint;
 				}
 				cairo_matrix_t matrix;
 				QTransform qmatrix;
@@ -1909,6 +1916,8 @@
 		{
 			cairo_push_group(m_cr);
 			cairo_pattern_t *pat;
+			bool   isFirst = true;
+			double rampPoint, lastPoint = 0.0;
 			double x1 = stroke_gradient.origin().x();
 			double y1 = stroke_gradient.origin().y();
 			double x2 = stroke_gradient.vector().x();
@@ -1926,6 +1935,10 @@
 			for( int offset = 0 ; offset < colorStops.count() ; offset++ )
 			{
 				qStopColor = colorStops[ offset ]->color;
+				rampPoint  = colorStops[ offset ]->rampPoint;
+				if ((lastPoint == rampPoint) && (!isFirst))
+					continue;
+				isFirst = false;
 				int h, s, v, sneu, vneu;
 				int shad = colorStops[offset]->shade;
 				qStopColor.getHsv(&h, &s, &v);
@@ -1935,7 +1948,8 @@
 				double a = colorStops[offset]->opacity;
 				double r, g, b;
 				qStopColor.getRgbF(&r, &g, &b);
-				cairo_pattern_add_color_stop_rgba (pat, colorStops[ offset ]->rampPoint, r, g, b, a);
+				cairo_pattern_add_color_stop_rgba (pat, rampPoint, r, g, b, a);
+				lastPoint = rampPoint;
 			}
 			cairo_matrix_t matrix;
 			QTransform qmatrix;
@@ -2106,6 +2120,8 @@
 		else if (fillMode == 2)
 		{
 			QGradient pat;
+			bool   isFirst = true;
+			double rampPoint, lastPoint = 0.0;
 			double x1 = fill_gradient.origin().x();
 			double y1 = fill_gradient.origin().y();
 			double x2 = fill_gradient.vector().x();
@@ -2121,6 +2137,10 @@
 			for( int offset = 0 ; offset < colorStops.count() ; offset++ )
 			{
 				qStopColor = colorStops[ offset ]->color;
+				rampPoint  = colorStops[ offset ]->rampPoint;
+				if ((lastPoint == rampPoint) && (!isFirst))
+					continue;
+				isFirst = false;
 				int h, s, v, sneu, vneu;
 				int shad = colorStops[offset]->shade;
 				qStopColor.getHsv(&h, &s, &v);
@@ -2128,7 +2148,8 @@
 				vneu = 255 - ((255 - v) * shad / 100);
 				qStopColor.setHsv(h, sneu, vneu);
 				qStopColor.setAlphaF(colorStops[offset]->opacity);
-				pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor);
+				pat.setColorAt(rampPoint, qStopColor);
+				lastPoint = rampPoint;
 			}
 			QTransform qmatrix;
 			if (fill_gradient.type() == VGradient::radial)
@@ -2438,6 +2459,8 @@
 		else if (strokeMode == 2)
 		{
 			QGradient pat;
+			bool   isFirst = true;
+			double rampPoint, lastPoint = 0.0;
 			double x1 = stroke_gradient.origin().x();
 			double y1 = stroke_gradient.origin().y();
 			double x2 = stroke_gradient.vector().x();
@@ -2453,6 +2476,9 @@
 			for( int offset = 0 ; offset < colorStops.count() ; offset++ )
 			{
 				qStopColor = colorStops[ offset ]->color;
+				if ((lastPoint == rampPoint) && (!isFirst))
+					continue;
+				isFirst = false;
 				int h, s, v, sneu, vneu;
 				int shad = colorStops[offset]->shade;
 				qStopColor.getHsv(&h, &s, &v);
@@ -2460,7 +2486,8 @@
 				vneu = 255 - ((255 - v) * shad / 100);
 				qStopColor.setHsv(h, sneu, vneu);
 				qStopColor.setAlphaF(colorStops[offset]->opacity);
-				pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor);
+				pat.setColorAt(rampPoint, qStopColor);
+				lastPoint == rampPoint;
 			}
 			QTransform qmatrix;
 			if (stroke_gradient.type() == VGradient::radial)
Index: scribus/plugins/svgexplugin/svgexplugin.cpp
===================================================================
--- scribus/plugins/svgexplugin/svgexplugin.cpp	(revision 15201)
+++ scribus/plugins/svgexplugin/svgexplugin.cpp	(revision 15202)
@@ -1450,17 +1450,25 @@
 					grad.setAttribute("x2", FToStr(Item->GrStrokeEndX));
 					grad.setAttribute("y2", FToStr(Item->GrStrokeEndY));
 				}
+				bool   isFirst = true;
+				double actualStop = 0.0, lastStop = 0.0;
 				QList<VColorStop*> cstops = Item->stroke_gradient.colorStops();
 				for (uint cst = 0; cst < Item->stroke_gradient.Stops(); ++cst)
 				{
-					QDomElement itcl = docu.createElement("stop");
-					itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
-					if (cstops.at(cst)->name == CommonStrings::None)
-						itcl.setAttribute("stop-opacity", FToStr(0));
-					else
-						itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
-					itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
-					grad.appendChild(itcl);
+					actualStop = cstops.at(cst)->rampPoint;
+					if ((actualStop != lastStop) || (isFirst))
+					{
+						QDomElement itcl = docu.createElement("stop");
+						itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
+						if (cstops.at(cst)->name == CommonStrings::None)
+							itcl.setAttribute("stop-opacity", FToStr(0));
+						else
+							itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
+						itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
+						grad.appendChild(itcl);
+						lastStop = actualStop;
+						isFirst  = false;
+					}
 				}
 				grad.setAttribute("id", "Grad"+IToStr(GradCount));
 				grad.setAttribute("gradientUnits", "userSpaceOnUse");
@@ -1605,17 +1613,25 @@
 					grad.setAttribute("x2", FToStr(Item->GrStrokeEndX));
 					grad.setAttribute("y2", FToStr(Item->GrStrokeEndY));
 				}
+				bool   isFirst = true;
+				double actualStop = 0.0, lastStop = 0.0;
 				QList<VColorStop*> cstops = Item->stroke_gradient.colorStops();
 				for (uint cst = 0; cst < Item->stroke_gradient.Stops(); ++cst)
 				{
-					QDomElement itcl = docu.createElement("stop");
-					itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
-					if (cstops.at(cst)->name == CommonStrings::None)
-						itcl.setAttribute("stop-opacity", FToStr(0));
-					else
-						itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
-					itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
-					grad.appendChild(itcl);
+					actualStop = cstops.at(cst)->rampPoint;
+					if ((actualStop != lastStop) || (isFirst))
+					{
+						QDomElement itcl = docu.createElement("stop");
+						itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
+						if (cstops.at(cst)->name == CommonStrings::None)
+							itcl.setAttribute("stop-opacity", FToStr(0));
+						else
+							itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
+						itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
+						grad.appendChild(itcl);
+						lastStop = actualStop;
+						isFirst  = false;
+					}
 				}
 				grad.setAttribute("id", "Grad"+IToStr(GradCount));
 				grad.setAttribute("gradientUnits", "userSpaceOnUse");
@@ -1889,17 +1905,25 @@
 				grad.setAttribute("gradientTransform", MatrixToStr(qmatrix));
 				grad.setAttribute("id", "Grad"+IToStr(GradCount));
 				grad.setAttribute("gradientUnits", "userSpaceOnUse");
+				bool   isFirst = true;
+				double actualStop = 0.0, lastStop = 0.0;
 				QList<VColorStop*> cstops = Item->fill_gradient.colorStops();
 				for (uint cst = 0; cst < Item->fill_gradient.Stops(); ++cst)
 				{
-					QDomElement itcl = docu.createElement("stop");
-					itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
-					if (cstops.at(cst)->name == CommonStrings::None)
-						itcl.setAttribute("stop-opacity", FToStr(0));
-					else
-						itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
-					itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
-					grad.appendChild(itcl);
+					actualStop = cstops.at(cst)->rampPoint;
+					if ((actualStop != lastStop) || (isFirst))
+					{
+						QDomElement itcl = docu.createElement("stop");
+						itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
+						if (cstops.at(cst)->name == CommonStrings::None)
+							itcl.setAttribute("stop-opacity", FToStr(0));
+						else
+							itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
+						itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
+						grad.appendChild(itcl);
+						lastStop = actualStop;
+						isFirst  = false;
+					}
 				}
 				globalDefs.appendChild(grad);
 				fill = "fill:url(#Grad"+IToStr(GradCount)+");";
@@ -2195,17 +2219,25 @@
 			grad.setAttribute("x2", FToStr(Item->GrStrokeEndX));
 			grad.setAttribute("y2", FToStr(Item->GrStrokeEndY));
 		}
+		bool   isFirst = true;
+		double actualStop = 0.0, lastStop = 0.0;
 		QList<VColorStop*> cstops = Item->stroke_gradient.colorStops();
 		for (uint cst = 0; cst < Item->stroke_gradient.Stops(); ++cst)
 		{
-			QDomElement itcl = docu.createElement("stop");
-			itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
-			if (cstops.at(cst)->name == CommonStrings::None)
-				itcl.setAttribute("stop-opacity", FToStr(0));
-			else
-				itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
-			itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
-			grad.appendChild(itcl);
+			actualStop = cstops.at(cst)->rampPoint;
+			if ((actualStop != lastStop) || (isFirst))
+			{
+				QDomElement itcl = docu.createElement("stop");
+				itcl.setAttribute("offset", FToStr(cstops.at(cst)->rampPoint*100)+"%");
+				if (cstops.at(cst)->name == CommonStrings::None)
+					itcl.setAttribute("stop-opacity", FToStr(0));
+				else
+					itcl.setAttribute("stop-opacity", FToStr(cstops.at(cst)->opacity));
+				itcl.setAttribute("stop-color", SetColor(cstops.at(cst)->name, cstops.at(cst)->shade));
+				grad.appendChild(itcl);
+				lastStop = actualStop;
+				isFirst  = false;
+			}
 		}
 		double gradientSkew;
 		if (Item->GrStrokeSkew == 90)




More information about the scribus-commit mailing list