r14231 by fschmid - Remaining parts of the framework for gradient strokes (Load, Save etc....)

scribus-commit scribus-commit at lists.scribus.net
Mon Oct 26 16:41:02 CET 2009


Revision: 14231
Author: fschmid
Date: 2009-10-26T11:51:17.523189Z
Commit message: Remaining parts of the framework for gradient strokes (Load, Save etc....)

Changeset: 
M  /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
M  /trunk/Scribus/scribus/scribusXml.cpp
M  /trunk/Scribus/scribus/plugins/picbrowser/picturebrowser.cpp
M  /trunk/Scribus/scribus/pageitem_desaxe.cpp
M  /trunk/Scribus/scribus/scribusview.cpp
M  /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
M  /trunk/Scribus/scribus/scribusstructs.h

Diffs:
Index: scribus/scribusXml.cpp
===================================================================
--- scribus/scribusXml.cpp	(revision 14230)
+++ scribus/scribusXml.cpp	(revision 14231)
@@ -194,6 +194,15 @@
 			OB->GrShade2 = attrAsInt(attrs, "GRSHADE2", 100);
 		}
 	}
+	OB->GrTypeStroke = attrAsInt(attrs, "GRTYPS"  , 0);
+	OB->stroke_gradient.clearStops();
+	if (OB->GrTypeStroke > 0)
+	{
+		OB->GrStrokeStartX = attrAsDbl(attrs, "GRSTARTXS", 0.0);
+		OB->GrStrokeStartY = attrAsDbl(attrs, "GRSTARTYS", 0.0);
+		OB->GrStrokeEndX   = attrAsDbl(attrs, "GRENDXS", 0.0);
+		OB->GrStrokeEndY   = attrAsDbl(attrs, "GRENDYS", 0.0);
+	}
 	OB->Rot        = attrAsDbl(attrs, "ROT", 0.0);
 	OB->PLineArt   = Qt::PenStyle    ( attrAsInt(attrs, "PLINEART", 0) );
 	OB->PLineEnd   = Qt::PenCapStyle ( attrAsInt(attrs, "PLINEEND", 0) );
@@ -550,6 +559,7 @@
 	writer.writeAttribute("SHADE"    ,item->fillShade());
 	writer.writeAttribute("SHADE2"   ,item->lineShade());
 	writer.writeAttribute("GRTYP"    ,item->GrType);
+	writer.writeAttribute("GRTYPS"   ,item->GrTypeStroke);
 	writer.writeAttribute("ROT"      ,item->rotation());
 	writer.writeAttribute("PLINEART" ,item->PLineArt);
 	writer.writeAttribute("PLINEEND" ,item->PLineEnd);
@@ -1213,6 +1223,7 @@
 	double patternOffsetXS;
 	double patternOffsetYS;
 	double patternRotationS;
+	QString gradNameS;
 	while(!sReader.atEnd() && !sReader.hasError())
 	{
 		sReader.readNext();
@@ -1233,6 +1244,7 @@
 			OB.isBookmark      = attrAsInt(attrs, "BOOKMARK");
 			OB.NamedLStyle     = attrAsString(attrs, "NAMEDLST", "");
 			gradName           = attrAsString(attrs, "GRNAME", "");
+			gradNameS          = attrAsString(attrs, "GRNAMES", "");
 			isGroupControl     = attrAsBool(attrs, "isGroupControl", false);
 			doOverprint        = attrAsBool(attrs, "doOverprint", false);
 			groupsLastItem     = attrAsInt (attrs, "groupsLastItem", 0);
@@ -1397,6 +1409,16 @@
 			OB.GrColor   = "";
 			OB.GrColor2  = "";
 		}
+		if (inItem && sReader.isStartElement() && tagName == "S_CSTOP")
+		{
+			QString name = attrAsString(attrs, "NAME", "");
+			double ramp  = attrAsDbl(attrs, "RAMP", 0.0);
+			int shade    = attrAsInt(attrs, "SHADE", 100);
+			double opa   = attrAsDbl(attrs, "TRANS", 1.0);
+			OB.stroke_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
+			OB.GrColor   = "";
+			OB.GrColor2  = "";
+		}
 		if (inItem && sReader.isStartElement() && tagName == "Tabs")
 		{
 			ParagraphStyle::TabRecord tb;
@@ -1446,6 +1468,7 @@
 			view->PasteItem(&OB, true, true, false);
 			PageItem* Neu = doc->Items->at(doc->Items->count()-1);
 			Neu->setGradient(gradName);
+			Neu->setStrokeGradient(gradNameS);
 			Neu->doOverprint = doOverprint;
 			Neu->setStrokePattern(StrokePattern);
 			Neu->setStrokePatternTransform(patternScaleXS, patternScaleYS, patternOffsetXS, patternOffsetYS, patternRotationS);
@@ -1617,6 +1640,13 @@
 	QByteArray inlineImageData;
 	QString inlineImageExt;
 	QString gradName;
+	QString StrokePattern;
+	double patternScaleXS;
+	double patternScaleYS;
+	double patternOffsetXS;
+	double patternOffsetYS;
+	double patternRotationS;
+	QString gradNameS;
 	int lowResType = 1;
 	int actualPageNumber = 0;
 	while(!reader.atEnd() && !reader.hasError())
@@ -1638,6 +1668,13 @@
 			lowResType         = attrAsInt (attrs1, "ImageRes", 1);
 			actualPageNumber   = attrAsInt (attrs1, "Pagenumber", 0);
 			gradName           = attrAsString(attrs1, "GRNAME", "");
+			gradNameS          = attrAsString(attrs1, "GRNAMES", "");
+			StrokePattern = attrAsString(attrs, "patternS", "");
+			patternScaleXS   = attrAsDbl(attrs, "pScaleXS", 100.0);
+			patternScaleYS   = attrAsDbl(attrs, "pScaleYS", 100.0);
+			patternOffsetXS  = attrAsDbl(attrs, "pOffsetXS", 0.0);
+			patternOffsetYS  = attrAsDbl(attrs, "pOffsetYS", 0.0);
+			patternRotationS = attrAsDbl(attrs, "pRotationS", 0.0);
 			inlineF = attrAsBool(attrs1, "isInlineImage", false);
 			inlineImageData.resize(0);
 			QString dat = attrAsString(attrs1, "ImageData", "");
@@ -1726,6 +1763,16 @@
 			OB.GrColor   = "";
 			OB.GrColor2  = "";
 		}
+		if (tagName1 == "S_CSTOP" && reader.isStartElement())
+		{
+			QString name = attrs1.value("NAME").toString();
+			double ramp  = attrAsDbl(attrs1, "RAMP", 0.0);
+			int shade    = attrAsInt(attrs1, "SHADE", 100);
+			double opa   = attrAsDbl(attrs1, "TRANS", 1.0);
+			OB.stroke_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
+			OB.GrColor   = "";
+			OB.GrColor2  = "";
+		}
 		if (tagName1=="Tabs" && reader.isStartElement())
 		{
 			ParagraphStyle::TabRecord tb;
@@ -1769,6 +1816,9 @@
 			PageItem* Neu = doc->Items->at(doc->Items->count()-1);
 			Neu->doOverprint = doOverprint;
 			Neu->setGradient(gradName);
+			Neu->setStrokeGradient(gradNameS);
+			Neu->setStrokePattern(StrokePattern);
+			Neu->setStrokePatternTransform(patternScaleXS, patternScaleYS, patternOffsetXS, patternOffsetYS, patternRotationS);
 			Neu->setXYPos(Neu->xPos() - doc->currentPage()->xOffset(), Neu->yPos() - doc->currentPage()->yOffset(), true);
 			storyText.setDefaultStyle(Neu->itemText.defaultStyle());
 			Neu->itemText = storyText;
@@ -2290,6 +2340,13 @@
 		writer.writeAttribute("GRENDX"  , item->GrEndX);
 		writer.writeAttribute("GRENDY"  , item->GrEndY);
 	}
+	if (item->GrTypeStroke > 0)
+	{
+		writer.writeAttribute("GRSTARTXS", item->GrStrokeStartX);
+		writer.writeAttribute("GRSTARTYS", item->GrStrokeStartY);
+		writer.writeAttribute("GRENDXS"  , item->GrStrokeEndX);
+		writer.writeAttribute("GRENDYS"  , item->GrStrokeEndY);
+	}
 
 	if (item->effectsInUse.count() != 0)
 	{
@@ -2361,6 +2418,24 @@
 				writer.writeAttribute("GRNAME"  , item->gradient());
 		}
 	}
+	if (item->GrTypeStroke > 0)
+	{
+		if (item->strokeGradient().isEmpty())
+		{
+			QList<VColorStop*> cstops = item->stroke_gradient.colorStops();
+			for (uint cst = 0; cst < item->stroke_gradient.Stops(); ++cst)
+			{
+				writer.writeStartElement("S_CSTOP");
+				writer.writeAttribute("RAMP" , cstops.at(cst)->rampPoint);
+				writer.writeAttribute("NAME" , cstops.at(cst)->name);
+				writer.writeAttribute("SHADE", cstops.at(cst)->shade);
+				writer.writeAttribute("TRANS", cstops.at(cst)->opacity);
+				writer.writeEndElement();
+			}
+		}
+		else
+			writer.writeAttribute("GRNAMES"  , item->strokeGradient());
+	}
 	if (!item->strokePattern().isEmpty())
 	{
 		writer.writeAttribute("patternS", item->strokePattern());
Index: scribus/scribusstructs.h
===================================================================
--- scribus/scribusstructs.h	(revision 14230)
+++ scribus/scribusstructs.h	(revision 14231)
@@ -85,6 +85,12 @@
 	double GrStartY;
 	double GrEndX;
 	double GrEndY;
+	VGradient stroke_gradient;
+	int GrTypeStroke;
+	double GrStrokeStartX;
+	double GrStrokeStartY;
+	double GrStrokeEndX;
+	double GrStrokeEndY;
 	QString TxtStroke;
 	QString TxtFill;
 	int ShTxtStroke;
Index: scribus/scribusview.cpp
===================================================================
--- scribus/scribusview.cpp	(revision 14230)
+++ scribus/scribusview.cpp	(revision 14231)
@@ -3866,6 +3866,16 @@
 			currItem->updateGradientVectors();
 		}
 	}
+	if (Buffer->GrTypeStroke >0)
+	{
+		currItem->stroke_gradient = Buffer->stroke_gradient;
+		currItem->GrTypeStroke = Buffer->GrTypeStroke;
+		currItem->GrStrokeStartX = Buffer->GrStrokeStartX;
+		currItem->GrStrokeStartY = Buffer->GrStrokeStartY;
+		currItem->GrStrokeEndX = Buffer->GrStrokeEndX;
+		currItem->GrStrokeEndY = Buffer->GrStrokeEndY;
+		currItem->updateGradientVectors();
+	}
 	currItem->setObjectAttributes(&(Buffer->pageItemAttributes));
 	if (resize)
 		Doc->setRedrawBounding(currItem);
Index: scribus/plugins/picbrowser/picturebrowser.cpp
===================================================================
--- scribus/plugins/picbrowser/picturebrowser.cpp	(revision 14230)
+++ scribus/plugins/picbrowser/picturebrowser.cpp	(revision 14231)
@@ -229,6 +229,7 @@
 
 	QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::IMAGESIMGFRAME, 0));
 	nameFilters = formatD.split(" ", QString::SkipEmptyParts);
+	nameFilters.append("*.svg");
 
 //filter/search setup
 	connect ( filterTargetCombobox, SIGNAL ( currentIndexChanged ( int ) ), this, SLOT ( filterTargetComboboxChanged ( int ) ) );
Index: scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	(revision 14230)
+++ scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	(revision 14231)
@@ -1187,6 +1187,15 @@
 		}
 		if (!item->gradient().isEmpty())
 			docu.writeAttribute("GRNAME", item->gradient());
+		if (!item->strokeGradient().isEmpty())
+			docu.writeAttribute("GRNAMES", item->strokeGradient());
+		if (item->GrTypeStroke > 0)
+		{
+			docu.writeAttribute("GRSTARTXS", item->GrStrokeStartX);
+			docu.writeAttribute("GRSTARTYS", item->GrStrokeStartY);
+			docu.writeAttribute("GRENDXS", item->GrStrokeEndX);
+			docu.writeAttribute("GRENDYS", item->GrStrokeEndY);
+		}
 		if (!item->strokePattern().isEmpty())
 		{
 			docu.writeAttribute("patternS", item->strokePattern());
@@ -1266,6 +1275,18 @@
 				docu.writeAttribute("TRANS", cstops.at(cst)->opacity);
 			}
 		}
+		if ((item->GrTypeStroke > 0) && (item->strokeGradient().isEmpty()))
+		{
+			QList<VColorStop*> cstops = item->stroke_gradient.colorStops();
+			for (uint cst = 0; cst < item->stroke_gradient.Stops(); ++cst)
+			{
+				docu.writeEmptyElement("S_CSTOP");
+				docu.writeAttribute("RAMP", cstops.at(cst)->rampPoint);
+				docu.writeAttribute("NAME", cstops.at(cst)->name);
+				docu.writeAttribute("SHADE", cstops.at(cst)->shade);
+				docu.writeAttribute("TRANS", cstops.at(cst)->opacity);
+			}
+		}
 		
 		if (item->asLatexFrame())
 		{
@@ -1431,6 +1452,7 @@
 	docu.writeAttribute("SHADE",item->fillShade());
 	docu.writeAttribute("SHADE2",item->lineShade());
 	docu.writeAttribute("GRTYP",item->GrType);
+	docu.writeAttribute("GRTYPS",item->GrTypeStroke);
 	docu.writeAttribute("ROT",item->rotation());
 	docu.writeAttribute("PLINEART",item->PLineArt);
 	docu.writeAttribute("PLINEEND", item->PLineEnd);
Index: scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 14230)
+++ scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 14231)
@@ -1770,6 +1770,14 @@
 			double opa   = tAtt.valueAsDouble("TRANS", 1.0);
 			newItem->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
 		}
+		if (tName == "S_CSTOP")
+		{
+			QString name = tAtt.valueAsString("NAME");
+			double ramp  = tAtt.valueAsDouble("RAMP", 0.0);
+			int shade    = tAtt.valueAsInt("SHADE", 100);
+			double opa   = tAtt.valueAsDouble("TRANS", 1.0);
+			newItem->stroke_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
+		}
 
 		if (tName == "ITEXT")
 			readItemText(newItem, tAtt, lastStyle);
@@ -2799,6 +2807,15 @@
 	double patternOffsetY  = attrs.valueAsDouble("pOffsetYS", 0.0);
 	double patternRotation = attrs.valueAsDouble("pRotationS", 0.0);
 	currItem->setStrokePatternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
+	currItem->GrTypeStroke = attrs.valueAsInt("GRTYPS", 0);
+	currItem->GrStrokeStartX = attrs.valueAsDouble("GRSTARTXS", 0.0);
+	currItem->GrStrokeStartY = attrs.valueAsDouble("GRSTARTYS", 0.0);
+	currItem->GrStrokeEndX   = attrs.valueAsDouble("GRENDXS", 0.0);
+	currItem->GrStrokeEndY   = attrs.valueAsDouble("GRENDYS", 0.0);
+	QString GrNameS = "";
+	GrNameS = attrs.valueAsString("GRNAMES","");
+	if (!GrNameS.isEmpty())
+		currItem->setStrokeGradient(GrNameS);
 	//currItem->setRedrawBounding();
 	//currItem->OwnPage = view->OnPage(currItem);
 	UndoManager::instance()->setUndoEnabled(true);
Index: scribus/pageitem_desaxe.cpp
===================================================================
--- scribus/pageitem_desaxe.cpp	(revision 14230)
+++ scribus/pageitem_desaxe.cpp	(revision 14231)
@@ -310,6 +310,29 @@
 			}
 			handler.end("Gradient");
 		}
+		if (GrTypeStroke > 0)
+		{
+			Xml_attr gradientV;
+			gradientV.insert("GRTYPES", toXMLString(GrTypeStroke));
+			gradientV.insert("GRSTARTXS", toXMLString(GrStrokeStartX));
+			gradientV.insert("GRSTARTYS", toXMLString(GrStrokeStartY));
+			gradientV.insert("GRENDXS", toXMLString(GrStrokeEndX));
+			gradientV.insert("GRENDYS", toXMLString(GrStrokeEndY));
+			gradientV.insert("GRNAMES", toXMLString(strokeGradient()));
+			handler.begin("GradientS", gradientV);
+			QList<VColorStop*> cstops = fill_gradient.colorStops();
+			for (uint cst = 0; cst < const_cast<VGradient&>(fill_gradient).Stops(); ++cst) //FIXME make const
+			{
+				Xml_attr itcl;
+				itcl.insert("RAMP", toXMLString(cstops.at(cst)->rampPoint));
+				itcl.insert("NAME", cstops.at(cst)->name);
+				itcl.insert("SHADE", toXMLString(cstops.at(cst)->shade));
+				itcl.insert("TRANS", toXMLString(cstops.at(cst)->opacity));
+				handler.begin("S_CStop",itcl);
+				handler.end("S_CStop");
+			}
+			handler.end("GradientS");
+		}
 	}
 	
 	// TODO: PI attributes...
@@ -517,17 +540,30 @@
 			// item->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
 			item->fill_gradient.addStop( QColor(150, 100, 50) , ramp, 0.5, opa, name, shade);
 		}
-		if (tagName=="Gradient")
+		if (tagName=="S_CStop")
 		{
+//			ScribusDoc* doc = this->dig->lookup<ScribusDoc>("<scribusdoc>");
 			PageItem* item = this->dig->top<PageItem>();
-			item->GrType = parseInt(attr["GRTYPE"]);
-			item->GrStartX = parseDouble(attr["GRSTARTX"]);
-			item->GrStartY = parseDouble(attr["GRSTARTY"]);
-			item->GrEndX = parseDouble(attr["GRENDX"]);
-			item->GrEndY = parseDouble(attr["GRENDY"]);
-			item->setGradient(attr["GRNAME"]);
-			item->fill_gradient.clearStops();
+			QString name = attr["NAME"];
+			double ramp = parseDouble(attr["RAMP"]);
+			int shade = parseInt(attr["SHADE"]);
+			double opa = parseDouble(attr["TRANS"]);
+			// Hack : at this stage, colors may still not exists in document and SetColor would create it, 
+			// so use the dummy brown and update manually gradient colors in Serializer
+			// item->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
+			item->stroke_gradient.addStop( QColor(150, 100, 50) , ramp, 0.5, opa, name, shade);
 		}
+		if (tagName=="GradientS")
+		{
+			PageItem* item = this->dig->top<PageItem>();
+			item->GrTypeStroke = parseInt(attr["GRTYPES"]);
+			item->GrStrokeStartX = parseDouble(attr["GRSTARTXS"]);
+			item->GrStrokeStartY = parseDouble(attr["GRSTARTYS"]);
+			item->GrStrokeEndX = parseDouble(attr["GRENDXS"]);
+			item->GrStrokeEndY = parseDouble(attr["GRENDYS"]);
+			item->setStrokeGradient(attr["GRNAMES"]);
+			item->stroke_gradient.clearStops();
+		}
 	}
 };
 
@@ -836,6 +872,10 @@
 	Xml_string gradientPrefix(Digester::concat(itemPrefix, "Gradient"));
 	ruleset.addRule(gradientPrefix, gradient);
 	ruleset.addRule(Digester::concat(gradientPrefix, "CStop"), gradient);
+	Gradient gradientS;
+	Xml_string gradientPrefixS(Digester::concat(itemPrefix, "GradientS"));
+	ruleset.addRule(gradientPrefixS, gradientS);
+	ruleset.addRule(Digester::concat(gradientPrefixS, "S_CStop"), gradientS);
 		
 	ImageEffectsAndLayers effectsAndLayers;
 	ruleset.addRule(Digester::concat(itemPrefix, "ImageEffect"), effectsAndLayers);




More information about the scribus-commit mailing list