r15032 by fschmid - AI-Importer: using real mesh gradients now.

scribus-commit scribus-commit at lists.scribus.net
Sat May 1 21:10:24 CEST 2010


Revision: 15032
Author: fschmid
Date: 2010-05-01T19:04:45.056708Z
Commit message: AI-Importer: using real mesh gradients now.

Changeset: 
M  /trunk/Scribus/scribus/plugins/import/ai/importai.cpp
M  /trunk/Scribus/scribus/plugins/import/ai/importai.h

Diffs:
Index: scribus/plugins/import/ai/importai.cpp
===================================================================
--- scribus/plugins/import/ai/importai.cpp	(revision 15031)
+++ scribus/plugins/import/ai/importai.cpp	(revision 15032)
@@ -1946,54 +1946,48 @@
 		{
 			if (Cdata.contains("/Mesh"))
 			{
-				QList<PageItem*> gElements;
-				groupStack.push(gElements);
 				meshMode = true;
 				meshNodeCounter = 0;
-				accumColorC = 0.0;
-				accumColorM = 0.0;
-				accumColorY = 0.0;
-				accumColorK = 0.0;
 				meshColorMode = 0;
-			//	meshBoundingPath = QPainterPath();
 			}
 			if (Cdata.contains("/End"))
 			{
 				meshMode = false;
-				if (groupStack.count() != 0)
+				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None, true);
+				ite = m_Doc->Items->at(z);
+				for (int x = 0; x < meshGradientArray.count(); x++)
 				{
-					QList<PageItem*> gElements = groupStack.pop();
-					tmpSel->clear();
-					if (gElements.count() > 0)
+					for (int y = 0; y < meshGradientArray[x].count(); y++)
 					{
-						for (int dre = 0; dre < gElements.count(); ++dre)
-						{
-							tmpSel->addItem(gElements.at(dre), true);
-						}
-						m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
-						ite = tmpSel->itemAt(0);
-					/*	if (!meshBoundingPath.isEmpty())
-						{
-							ite = tmpSel->itemAt(0);
-							clipCoords.fromQPainterPath(meshBoundingPath);
-							clipCoords.translate(m_Doc->currentPage()->xOffset()-ite->xPos(), m_Doc->currentPage()->yOffset()-ite->yPos());
-							ite->PoLine = clipCoords.copy();
-							ite->PoLine.translate(baseX, baseY);
-						} */
-						if (patternMode)
-							PatternElements.append(ite);
-						else
-							Elements.append(ite);
+						meshGradientArray[x][y].moveRel(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
 					}
-					if (groupStack.count() != 0)
+				}
+				ite->meshGradientArray = meshGradientArray;
+				ite->GrType = 11;
+				ite->meshToShape();
+				for (int grow = 0; grow < ite->meshGradientArray.count(); grow++)
+				{
+					for (int gcol = 0; gcol < ite->meshGradientArray[grow].count(); gcol++)
 					{
-						for (int as = 0; as < tmpSel->count(); ++as)
-						{
-							groupStack.top().append(tmpSel->itemAt(as));
-						}
+						meshPoint mp = ite->meshGradientArray[grow][gcol];
+						ite->setMeshPointColor(grow, gcol, mp.colorName, mp.shade, mp.transparency);
 					}
-					tmpSel->clear();
 				}
+				ite->setFillShade(CurrFillShade);
+				ite->setLineShade(CurrFillShade);
+				ite->setFillEvenOdd(fillRule);
+				ite->setFillTransparency(1.0 - Opacity);
+				ite->setLineTransparency(1.0 - Opacity);
+				ite->setLineEnd(CapStyle);
+				ite->setLineJoin(JoinStyle);
+				if (importerFlags & LoadSavePlugin::lfCreateDoc)
+					ite->setLocked(itemLocked);
+				if (patternMode)
+					PatternElements.append(ite);
+				else
+					Elements.append(ite);
+				if (groupStack.count() != 0)
+					groupStack.top().append(ite);
 			}
 		}
 		else if (command == "X#")
@@ -2007,11 +2001,22 @@
 			mVals >> mKey;
 			if (mKey == "Size")
 			{
+				meshGradientArray.clear();
 				int ans = cmdLine.indexOf("[");
 				int ens = cmdLine.lastIndexOf("]");
 				QString sizeVals = cmdLine.mid(ans+1, ens-ans-1);
 				ScTextStream mVals2(&sizeVals, QIODevice::ReadOnly);
 				mVals2 >> meshXSize >> meshYSize;
+				for (int mgr = 0; mgr < meshYSize+1; mgr++)
+				{
+					QList<meshPoint> ml;
+					for (int mgc = 0; mgc < meshXSize+1; mgc++)
+					{
+						meshPoint mp;
+						ml.append(mp);
+					}
+					meshGradientArray.append(ml);
+				}
 			}
 			if (mKey == "P")
 			{
@@ -2020,10 +2025,6 @@
 				QString posVals = cmdLine.mid(ans+1, ens-ans-1);
 				ScTextStream mVals3(&posVals, QIODevice::ReadOnly);
 				mVals3 >> currentMeshXPos >> currentMeshYPos;
-				accumColorC = 0.0;
-				accumColorM = 0.0;
-				accumColorY = 0.0;
-				accumColorK = 0.0;
 			}
 			if (mKey == "CS")
 			{
@@ -2034,12 +2035,59 @@
 			}
 			if (mKey == "E")
 			{
+				int indY = meshYSize - currentMeshYPos - 1;
+				int indX = currentMeshXPos;
+				FPoint p2 = FPoint(meshNode1PointX, meshNode1PointY);
+				FPoint p1 = FPoint(meshNode2PointX, meshNode2PointY);
+				FPoint p4 = FPoint(meshNode3PointX, meshNode3PointY);
+				FPoint p3 = FPoint(meshNode4PointX, meshNode4PointY);
+				meshGradientArray[indY+1][indX+1].gridPoint   = FPoint(meshNode2PointX, meshNode2PointY);
+				meshGradientArray[indY+1][indX+1].controlTop  = FPoint(meshNode2Control2X, meshNode2Control2Y);
+				meshGradientArray[indY+1][indX+1].controlLeft = FPoint(meshNode2Control1X, meshNode2Control1Y);
+				meshGradientArray[indY+1][indX+1].colorName = meshColor2;
+				meshGradientArray[indY+1][indX+1].shade = 100;
+				meshGradientArray[indY+1][indX+1].transparency = 1.0;
+				meshGradientArray[indY+1][indX].gridPoint    = FPoint(meshNode1PointX, meshNode1PointY);
+				meshGradientArray[indY+1][indX].controlRight = FPoint(meshNode1Control2X, meshNode1Control2Y);
+				meshGradientArray[indY+1][indX].controlTop   = FPoint(meshNode1Control1X, meshNode1Control1Y);
+				meshGradientArray[indY+1][indX].colorName = meshColor1;
+				meshGradientArray[indY+1][indX].shade = 100;
+				meshGradientArray[indY+1][indX].transparency = 1.0;
+				meshGradientArray[indY][indX].gridPoint     = FPoint(meshNode4PointX, meshNode4PointY);
+				meshGradientArray[indY][indX].controlBottom = FPoint(meshNode4Control2X, meshNode4Control2Y);
+				meshGradientArray[indY][indX].controlRight  = FPoint(meshNode4Control1X, meshNode4Control1Y);
+				meshGradientArray[indY][indX].colorName = meshColor4;
+				meshGradientArray[indY][indX].shade = 100;
+				meshGradientArray[indY][indX].transparency = 1.0;
+				meshGradientArray[indY][indX+1].gridPoint     = FPoint(meshNode3PointX, meshNode3PointY);
+				meshGradientArray[indY][indX+1].controlLeft   = FPoint(meshNode3Control2X, meshNode3Control2Y);
+				meshGradientArray[indY][indX+1].controlBottom = FPoint(meshNode3Control1X, meshNode3Control1Y);
+				meshGradientArray[indY][indX+1].colorName = meshColor3;
+				meshGradientArray[indY][indX+1].shade = 100;
+				meshGradientArray[indY][indX+1].transparency = 1.0;
+				meshNodeCounter = 0;
+			}
+			if (mKey == "N")
+			{
+				double cVal, mVal, yVal, kVal, coorX1, coorY1, coorX2, coorY2, coorX3, coorY3;
+				int dummy;
+				meshNodeCounter++;
+				int ans = cmdLine.indexOf("[");
+				int ens = cmdLine.lastIndexOf("]");
+				QString nodeVals = cmdLine.mid(ans+1, ens-ans-1);
+				ScTextStream mVals4(&nodeVals, QIODevice::ReadOnly);
+				kVal = 0.0;
+				if (meshColorMode == 0)
+					mVals4 >> cVal >> mVal >> yVal >> kVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
+				else
+					mVals4 >> cVal >> mVal >> yVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
+				QString nodeColor;
 				ScColor tmpColor;
 				ColorList::Iterator it;
-				int Cc = qRound((accumColorC / 4.0) * 255);
-				int Mc = qRound((accumColorM / 4.0) * 255);
-				int Yc = qRound((accumColorY / 4.0) * 255);
-				int Kc = qRound((accumColorK / 4.0) * 255);
+				int Cc = qRound(cVal * 255);
+				int Mc = qRound(mVal * 255);
+				int Yc = qRound(yVal * 255);
+				int Kc = qRound(kVal * 255);
 				int hC, hM, hY, hK;
 				bool found = false;
 				if (meshColorMode == 0)
@@ -2052,7 +2100,7 @@
 							it.value().getCMYK(&hC, &hM, &hY, &hK);
 							if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
 							{
-								CurrColorFill = it.key();
+								nodeColor = it.key();
 								found = true;
 								break;
 							}
@@ -2069,7 +2117,7 @@
 							it.value().getRGB(&hC, &hM, &hY);
 							if ((Cc == hC) && (Mc == hM) && (Yc == hY))
 							{
-								CurrColorFill = it.key();
+								nodeColor = it.key();
 								found = true;
 								break;
 							}
@@ -2082,64 +2130,8 @@
 					tmpColor.setRegistrationColor(false);
 					QString namPrefix = "FromAI";
 					m_Doc->PageColors.insert(namPrefix+tmpColor.name(), tmpColor);
-					CurrColorFill = namPrefix+tmpColor.name();
+					nodeColor = namPrefix+tmpColor.name();
 				}
-				meshNodeCounter = 0;
-				Coords.resize(0);
-				Coords.svgInit();
-				Coords.svgMoveTo(meshNode1PointX, meshNode1PointY);
-				Coords.svgCurveToCubic(meshNode1Control2X, meshNode1Control2Y, meshNode2Control1X, meshNode2Control1Y, meshNode2PointX, meshNode2PointY);
-				Coords.svgCurveToCubic(meshNode2Control2X, meshNode2Control2Y, meshNode3Control1X, meshNode3Control1Y, meshNode3PointX, meshNode3PointY);
-				Coords.svgCurveToCubic(meshNode3Control2X, meshNode3Control2Y, meshNode4Control1X, meshNode4Control1Y, meshNode4PointX, meshNode4PointY);
-				Coords.svgCurveToCubic(meshNode4Control2X, meshNode4Control2Y, meshNode1Control1X, meshNode1Control1Y, meshNode1PointX, meshNode1PointY);
-				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, CurrColorFill, CurrColorFill, true);
-				ite = m_Doc->Items->at(z);
-				ite->PoLine = Coords.copy();
-			//	QPainterPath tmpPath = Coords.toQPainterPath(true);
-			//	meshBoundingPath = meshBoundingPath.united(tmpPath);
-				ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
-				ite->ClipEdited = true;
-				ite->FrameType = 3;
-				ite->setFillShade(CurrFillShade);
-				ite->setLineShade(CurrFillShade);
-				ite->setFillEvenOdd(fillRule);
-				ite->setFillTransparency(1.0 - Opacity);
-				ite->setLineTransparency(1.0 - Opacity);
-				ite->setLineEnd(CapStyle);
-				ite->setLineJoin(JoinStyle);
-				if (importerFlags & LoadSavePlugin::lfCreateDoc)
-					ite->setLocked(itemLocked);
-				FPoint wh = getMaxClipF(&ite->PoLine);
-				ite->setWidthHeight(wh.x(),wh.y());
-				ite->setTextFlowMode(PageItem::TextFlowDisabled);
-				m_Doc->AdjustItemSize(ite);
-				if (patternMode)
-					PatternElements.append(ite);
-				else
-					Elements.append(ite);
-				if (groupStack.count() != 0)
-					groupStack.top().append(ite);
-				Coords.resize(0);
-				Coords.svgInit();
-			}
-			if (mKey == "N")
-			{
-				double cVal, mVal, yVal, kVal, coorX1, coorY1, coorX2, coorY2, coorX3, coorY3;
-				int dummy;
-				meshNodeCounter++;
-				int ans = cmdLine.indexOf("[");
-				int ens = cmdLine.lastIndexOf("]");
-				QString nodeVals = cmdLine.mid(ans+1, ens-ans-1);
-				ScTextStream mVals4(&nodeVals, QIODevice::ReadOnly);
-				kVal = 0.0;
-				if (meshColorMode == 0)
-					mVals4 >> cVal >> mVal >> yVal >> kVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
-				else
-					mVals4 >> cVal >> mVal >> yVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
-				accumColorC += cVal;
-				accumColorM += mVal;
-				accumColorY += yVal;
-				accumColorK += kVal;
 				if (meshNodeCounter == 1)
 				{
 					meshNode1PointX = coorX1 - docX;
@@ -2148,6 +2140,7 @@
 					meshNode1Control2Y = docHeight - (coorY2 - docY);
 					meshNode1Control1X = coorX3 - docX;
 					meshNode1Control1Y = docHeight - (coorY3 - docY);
+					meshColor1 = nodeColor;
 				}
 				if (meshNodeCounter == 2)
 				{
@@ -2157,6 +2150,7 @@
 					meshNode2Control2Y = docHeight - (coorY2 - docY);
 					meshNode2Control1X = coorX3 - docX;
 					meshNode2Control1Y = docHeight - (coorY3 - docY);
+					meshColor2 = nodeColor;
 				}
 				if (meshNodeCounter == 3)
 				{
@@ -2166,6 +2160,7 @@
 					meshNode3Control2Y = docHeight - (coorY2 - docY);
 					meshNode3Control1X = coorX3 - docX;
 					meshNode3Control1Y = docHeight - (coorY3 - docY);
+					meshColor3 = nodeColor;
 				}
 				if (meshNodeCounter == 4)
 				{
@@ -2175,6 +2170,7 @@
 					meshNode4Control2Y = docHeight - (coorY2 - docY);
 					meshNode4Control1X = coorX3 - docX;
 					meshNode4Control1Y = docHeight - (coorY3 - docY);
+					meshColor4 = nodeColor;
 				}
 			}
 		}
Index: scribus/plugins/import/ai/importai.h
===================================================================
--- scribus/plugins/import/ai/importai.h	(revision 15031)
+++ scribus/plugins/import/ai/importai.h	(revision 15032)
@@ -15,6 +15,7 @@
 #include "pluginapi.h"
 
 #include "fpointarray.h"
+#include "mesh.h"
 #include "sccolor.h"
 #include "text/storytext.h"
 #include "vgradient.h"
@@ -172,9 +173,8 @@
 	double meshNode4PointX, meshNode4PointY;
 	double meshNode4Control1X, meshNode4Control1Y;
 	double meshNode4Control2X, meshNode4Control2Y;
-	double accumColorC, accumColorM, accumColorY, accumColorK;
 	QString meshColor1, meshColor2, meshColor3, meshColor4;
-//	QPainterPath meshBoundingPath;
+	QList<QList<meshPoint> > meshGradientArray;
 	QString docCreator;
 	QString docDate;
 	QString docTime;




More information about the scribus-commit mailing list