r15100 by fschmid - AI-Importer: fixed various issues and crashes when importing Symbols.

scribus-commit scribus-commit at lists.scribus.net
Sat May 22 12:30:29 CEST 2010


Revision: 15100
Author: fschmid
Date: 2010-05-22T10:27:00.726243Z
Commit message: AI-Importer: fixed various issues and crashes when importing Symbols.

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

Diffs:
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 15099)
+++ scribus/scribusdoc.cpp	(revision 15100)
@@ -11195,156 +11195,156 @@
 
 const PageItem * ScribusDoc::itemSelection_GroupObjects(bool changeLock, bool lock, Selection* customSelection)
 {
-		Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
-		if (itemSelection->count() < 1)
-			return NULL;
-		int objectsLayer = itemSelection->objectsLayer();
-		if (objectsLayer == -1)
-			return NULL;
-		PageItem *currItem;
-		PageItem* bb;
-		double x, y, w, h;
-		uint selectedItemCount=itemSelection->count();
-		QString tooltip = Um::ItemsInvolved + "\n";
-		if (selectedItemCount > Um::ItemsInvolvedLimit)
-			tooltip = Um::ItemsInvolved2 + "\n";
-		if (changeLock)
+	Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
+	if (itemSelection->count() < 1)
+		return NULL;
+	int objectsLayer = itemSelection->objectsLayer();
+	if (objectsLayer == -1)
+		return NULL;
+	PageItem *currItem;
+	PageItem* bb;
+	double x, y, w, h;
+	uint selectedItemCount=itemSelection->count();
+	QString tooltip = Um::ItemsInvolved + "\n";
+	if (selectedItemCount > Um::ItemsInvolvedLimit)
+		tooltip = Um::ItemsInvolved2 + "\n";
+	if (changeLock)
+	{
+		uint lockedCount=0;
+		for (uint a=0; a<selectedItemCount; ++a)
 		{
-			uint lockedCount=0;
+			if (itemSelection->itemAt(a)->locked())
+				++lockedCount;
+		}
+		if (lockedCount!=0 && lockedCount!=selectedItemCount)
+		{
 			for (uint a=0; a<selectedItemCount; ++a)
 			{
-				if (itemSelection->itemAt(a)->locked())
-					++lockedCount;
-			}
-			if (lockedCount!=0 && lockedCount!=selectedItemCount)
-			{
-				for (uint a=0; a<selectedItemCount; ++a)
+				currItem = itemSelection->itemAt(a);
+				if (currItem->locked())
 				{
-					currItem = itemSelection->itemAt(a);
-					if (currItem->locked())
+					for (uint c=0; c < selectedItemCount; ++c)
 					{
-						for (uint c=0; c < selectedItemCount; ++c)
-						{
-							bb = itemSelection->itemAt(c);
-							bb->setLocked(lock);
-							if (m_ScMW && ScCore->usingGUI())
-								m_ScMW->scrActions["itemLock"]->setChecked(lock);
-							if (selectedItemCount <= Um::ItemsInvolvedLimit)
-								tooltip += "\t" + currItem->getUName() + "\n";
-						}
+						bb = itemSelection->itemAt(c);
+						bb->setLocked(lock);
+						if (m_ScMW && ScCore->usingGUI())
+							m_ScMW->scrActions["itemLock"]->setChecked(lock);
+						if (selectedItemCount <= Um::ItemsInvolvedLimit)
+							tooltip += "\t" + currItem->getUName() + "\n";
 					}
 				}
 			}
 		}
-		itemSelection->getVisualGroupRect(&x, &y, &w, &h);
-		uint lowestItem = 999999;
-		uint highestItem = 0;
-		for (uint a=0; a<selectedItemCount; ++a)
+	}
+	itemSelection->getVisualGroupRect(&x, &y, &w, &h);
+	uint lowestItem = 999999;
+	uint highestItem = 0;
+	for (uint a=0; a<selectedItemCount; ++a)
+	{
+		currItem = itemSelection->itemAt(a);
+		currItem->gXpos = currItem->xPos() - x;
+		currItem->gYpos = currItem->yPos() - y;
+		currItem->gWidth = w;
+		currItem->gHeight = h;
+		lowestItem = qMin(lowestItem, currItem->ItemNr);
+		highestItem = qMax(highestItem, currItem->ItemNr);
+	}
+	double minx =  std::numeric_limits<double>::max();
+	double miny =  std::numeric_limits<double>::max();
+	double maxx = -std::numeric_limits<double>::max();
+	double maxy = -std::numeric_limits<double>::max();
+	for (uint ep = 0; ep < selectedItemCount; ++ep)
+	{
+		PageItem* currItem = itemSelection->itemAt(ep);
+		double x1, x2, y1, y2;
+		currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+		minx = qMin(minx, x1);
+		miny = qMin(miny, y1);
+		maxx = qMax(maxx, x2);
+		maxy = qMax(maxy, y2);
+/*
+		double lw = 0.0;
+		if (currItem->lineColor() != CommonStrings::None)
+			lw = currItem->lineWidth() / 2.0;
+		if (currItem->rotation() != 0)
 		{
-			currItem = itemSelection->itemAt(a);
-			currItem->gXpos = currItem->xPos() - x;
-			currItem->gYpos = currItem->yPos() - y;
-			currItem->gWidth = w;
-			currItem->gHeight = h;
-			lowestItem = qMin(lowestItem, currItem->ItemNr);
-			highestItem = qMax(highestItem, currItem->ItemNr);
-		}
-		double minx =  std::numeric_limits<double>::max();
-		double miny =  std::numeric_limits<double>::max();
-		double maxx = -std::numeric_limits<double>::max();
-		double maxy = -std::numeric_limits<double>::max();
-		for (uint ep = 0; ep < selectedItemCount; ++ep)
-		{
-			PageItem* currItem = itemSelection->itemAt(ep);
-			double x1, x2, y1, y2;
-			currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
-			minx = qMin(minx, x1);
-			miny = qMin(miny, y1);
-			maxx = qMax(maxx, x2);
-			maxy = qMax(maxy, y2);
-/*
-			double lw = 0.0;
-			if (currItem->lineColor() != CommonStrings::None)
-				lw = currItem->lineWidth() / 2.0;
-			if (currItem->rotation() != 0)
+			FPointArray pb;
+			pb.resize(0);
+			pb.addPoint(FPoint(currItem->xPos()-lw, currItem->yPos()-lw));
+			pb.addPoint(FPoint(currItem->width()+lw*2.0, -lw, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
+			pb.addPoint(FPoint(currItem->width()+lw*2.0, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
+			pb.addPoint(FPoint(-lw, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
+			for (uint pc = 0; pc < 4; ++pc)
 			{
-				FPointArray pb;
-				pb.resize(0);
-				pb.addPoint(FPoint(currItem->xPos()-lw, currItem->yPos()-lw));
-				pb.addPoint(FPoint(currItem->width()+lw*2.0, -lw, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
-				pb.addPoint(FPoint(currItem->width()+lw*2.0, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
-				pb.addPoint(FPoint(-lw, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
-				for (uint pc = 0; pc < 4; ++pc)
-				{
-					minx = qMin(minx, pb.point(pc).x());
-					miny = qMin(miny, pb.point(pc).y());
-					maxx = qMax(maxx, pb.point(pc).x());
-					maxy = qMax(maxy, pb.point(pc).y());
-				}
+				minx = qMin(minx, pb.point(pc).x());
+				miny = qMin(miny, pb.point(pc).y());
+				maxx = qMax(maxx, pb.point(pc).x());
+				maxy = qMax(maxy, pb.point(pc).y());
 			}
-			else
-			{
-				minx = qMin(minx, currItem->xPos()-lw);
-				miny = qMin(miny, currItem->yPos()-lw);
-				maxx = qMax(maxx, currItem->xPos()-lw + currItem->width()+lw*2.0);
-				maxy = qMax(maxy, currItem->yPos()-lw + currItem->height()+lw*2.0);
-			}
-*/
 		}
-		double gx = minx;
-		double gy = miny;
-		double gw = maxx - minx;
-		double gh = maxy - miny;
-		PageItem *high = Items->at(highestItem);
-		undoManager->setUndoEnabled(false);
-		int z = itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, docPrefsData.itemToolPrefs.shapeFillColor, docPrefsData.itemToolPrefs.shapeLineColor, true);
-		PageItem *groupItem = Items->takeAt(z);
-		Items->insert(lowestItem, groupItem);
-		groupItem->setItemName( tr("Group%1").arg(GroupCounter));
-		groupItem->AutoName = false;
-		groupItem->isGroupControl = true;
-		groupItem->groupsLastItem = high;
-		groupItem->LayerID = objectsLayer;
-		undoManager->setUndoEnabled(true);
-
-		QMap<int, uint> ObjOrder;
-		for (uint c = 0; c < selectedItemCount; ++c)
+		else
 		{
-			currItem = itemSelection->itemAt(c);
-			ObjOrder.insert(currItem->ItemNr, c);
-			int d = Items->indexOf(currItem);
-			Items->takeAt(d);
+			minx = qMin(minx, currItem->xPos()-lw);
+			miny = qMin(miny, currItem->yPos()-lw);
+			maxx = qMax(maxx, currItem->xPos()-lw + currItem->width()+lw*2.0);
+			maxy = qMax(maxy, currItem->yPos()-lw + currItem->height()+lw*2.0);
 		}
-		QList<uint> Oindex = ObjOrder.values();
-		for (int c = static_cast<int>(Oindex.count()-1); c > -1; c--)
-		{
-			Items->insert(lowestItem+1, itemSelection->itemAt(Oindex[c]));
+*/
 		}
+	double gx = minx;
+	double gy = miny;
+	double gw = maxx - minx;
+	double gh = maxy - miny;
+	PageItem *high = Items->at(highestItem);
+	undoManager->setUndoEnabled(false);
+	int z = itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, docPrefsData.itemToolPrefs.shapeFillColor, docPrefsData.itemToolPrefs.shapeLineColor, true);
+	PageItem *groupItem = Items->takeAt(z);
+	Items->insert(lowestItem, groupItem);
+	groupItem->setItemName( tr("Group%1").arg(GroupCounter));
+	groupItem->AutoName = false;
+	groupItem->isGroupControl = true;
+	groupItem->groupsLastItem = high;
+	groupItem->LayerID = objectsLayer;
+	undoManager->setUndoEnabled(true);
 
-		renumberItemsInListOrder();
-		itemSelection->prependItem(groupItem);
-		selectedItemCount=itemSelection->count();
-		SimpleState *ss = new SimpleState(Um::Group, tooltip);
-		ss->set("GROUP", "group");
-		ss->set("itemcount", selectedItemCount);
+	QMap<int, uint> ObjOrder;
+	for (uint c = 0; c < selectedItemCount; ++c)
+	{
+		currItem = itemSelection->itemAt(c);
+		ObjOrder.insert(currItem->ItemNr, c);
+		int d = Items->indexOf(currItem);
+		Items->takeAt(d);
+	}
+	QList<uint> Oindex = ObjOrder.values();
+	for (int c = static_cast<int>(Oindex.count()-1); c > -1; c--)
+	{
+		Items->insert(lowestItem+1, itemSelection->itemAt(Oindex[c]));
+	}
 
-		for (uint a=0; a<selectedItemCount; ++a)
-		{
-			currItem = itemSelection->itemAt(a);
-			currItem->Groups.push(GroupCounter);
-			ss->set(QString("item%1").arg(a), currItem->uniqueNr);
-		}
-		GroupCounter++;
-		regionsChanged()->update(QRectF(gx-5, gy-5, gw+10, gh+10));
-		emit docChanged();
-		if (m_ScMW && ScCore->usingGUI())
-		{
-			m_ScMW->scrActions["itemAttachTextToPath"]->setEnabled(false);
-			m_ScMW->scrActions["itemGroup"]->setEnabled(false);
-			m_ScMW->scrActions["itemUngroup"]->setEnabled(true);
-		}
-		undoManager->action(this, ss, Um::SelectionGroup, Um::IGroup);
-		return groupItem;
+	renumberItemsInListOrder();
+	itemSelection->prependItem(groupItem);
+	selectedItemCount=itemSelection->count();
+	SimpleState *ss = new SimpleState(Um::Group, tooltip);
+	ss->set("GROUP", "group");
+	ss->set("itemcount", selectedItemCount);
+
+	for (uint a=0; a<selectedItemCount; ++a)
+	{
+		currItem = itemSelection->itemAt(a);
+		currItem->Groups.push(GroupCounter);
+		ss->set(QString("item%1").arg(a), currItem->uniqueNr);
+	}
+	GroupCounter++;
+	regionsChanged()->update(QRectF(gx-5, gy-5, gw+10, gh+10));
+	emit docChanged();
+	if (m_ScMW && ScCore->usingGUI())
+	{
+		m_ScMW->scrActions["itemAttachTextToPath"]->setEnabled(false);
+		m_ScMW->scrActions["itemGroup"]->setEnabled(false);
+		m_ScMW->scrActions["itemUngroup"]->setEnabled(true);
+	}
+	undoManager->action(this, ss, Um::SelectionGroup, Um::IGroup);
+	return groupItem;
 }
 
 void ScribusDoc::itemSelection_UnGroupObjects(Selection* customSelection)
Index: scribus/plugins/import/ai/importai.cpp
===================================================================
--- scribus/plugins/import/ai/importai.cpp	(revision 15099)
+++ scribus/plugins/import/ai/importai.cpp	(revision 15100)
@@ -1583,9 +1583,10 @@
 				symT.translate(x2, y2);
 				QPointF pos1 = importedSymbols[currentSymbolName];
 				pos1 = symT.map(pos1);
-				pos1 += QPointF(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
 				double xp = pos1.x();
-				double yp = docHeight - pos1.y();
+				double yp = pos1.y();
+				xp += m_Doc->currentPage()->xOffset();
+				yp += m_Doc->currentPage()->yOffset();
 				int z = m_Doc->itemAdd(PageItem::Symbol, PageItem::Unspecified, baseX + xp, baseY + yp, 1, 1, 0, CommonStrings::None, CommonStrings::None, true);
 				PageItem *b = m_Doc->Items->at(z);
 				b->LayerID = m_Doc->activeLayer();
@@ -1598,12 +1599,12 @@
 				double xoffset = 0.0, yoffset = 0.0;
 			//	if (rotation != 0.0)
 			//	{
-					double temp = -b->height();
-					xoffset = sin(rotation) * temp;
-					yoffset = cos(rotation) * temp;
+					double temp = b->height();
+					xoffset = sin(-rotation) * temp;
+					yoffset = cos(-rotation) * temp;
 			//	}
 				b->setXPos(xp + xoffset);
-				b->setYPos(yp + yoffset + b->height());
+				b->setYPos(yp + yoffset);
 				b->setRotation(rotation * 180 / M_PI);
 				b->setTextFlowMode(PageItem::TextFlowDisabled);
 				b->setFillTransparency(1.0 - Opacity);
@@ -2653,34 +2654,44 @@
 						currItem->AutoName = false;
 						m_Doc->DoDrawing = true;
 						QImage tmpImg = currItem->DrawObj_toImage();
-						QImage retImg = QImage(qRound(patternX2 - patternX1), qRound(patternY2 - patternY1), QImage::Format_ARGB32_Premultiplied);
-						retImg.fill( qRgba(255, 255, 255, 0) );
-						QPainter p;
-						p.begin(&retImg);
-						if (PatternElements.count() > 1)
-							p.drawImage(qRound(-patternX1), qRound(-patternY1), tmpImg);
-						else
-							p.drawImage(0, 0, tmpImg);
-						p.end();
-						pat.pattern = retImg;
-	//					pat.pattern = currItem->DrawObj_toImage();
-						m_Doc->DoDrawing = false;
-						//			pat.width = currItem->gWidth;
-						//			pat.height = currItem->gHeight;
-						pat.width = patternX2 - patternX1;
-						pat.height = patternY2 - patternY1;
-						pat.xoffset = -patternX1;
-						pat.yoffset = -patternY1;
+						if (!tmpImg.isNull())
+						{
+							QImage retImg = QImage(qRound(patternX2 - patternX1), qRound(patternY2 - patternY1), QImage::Format_ARGB32_Premultiplied);
+							retImg.fill( qRgba(255, 255, 255, 0) );
+							QPainter p;
+							p.begin(&retImg);
+							if (PatternElements.count() > 1)
+								p.drawImage(qRound(-patternX1), qRound(-patternY1), tmpImg);
+							else
+								p.drawImage(0, 0, tmpImg);
+							p.end();
+							pat.pattern = retImg;
+		//					pat.pattern = currItem->DrawObj_toImage();
+							m_Doc->DoDrawing = false;
+							//			pat.width = currItem->gWidth;
+							//			pat.height = currItem->gHeight;
+							pat.width = patternX2 - patternX1;
+							pat.height = patternY2 - patternY1;
+							pat.xoffset = -patternX1;
+							pat.yoffset = -patternY1;
+							for (int as = 0; as < tmpSel->count(); ++as)
+							{
+								PageItem* Neu = tmpSel->itemAt(as);
+								Neu->moveBy(-patternX1, -patternY1, true);
+								Neu->gXpos -= patternX1;
+								Neu->gYpos -= patternY1;
+								pat.items.append(Neu);
+							}
+							m_Doc->addPattern(currentPatternDefName, pat);
+							importedPatterns.append(currentPatternDefName);
+						}
+					}
+					if (groupStack.count() != 0)
+					{
 						for (int as = 0; as < tmpSel->count(); ++as)
 						{
-							PageItem* Neu = tmpSel->itemAt(as);
-							Neu->moveBy(-patternX1, -patternY1, true);
-							Neu->gXpos -= patternX1;
-							Neu->gYpos -= patternY1;
-							pat.items.append(Neu);
+							groupStack.top().removeAll(tmpSel->itemAt(as));
 						}
-						m_Doc->addPattern(currentPatternDefName, pat);
-						importedPatterns.append(currentPatternDefName);
 					}
 					m_Doc->itemSelection_DeleteItem(tmpSel);
 				}
@@ -2717,6 +2728,20 @@
 			currentPatternDefName = "";
 			break;
 		}
+		else if (tmp.contains("BeginRaster") && (tmp.startsWith("%")))
+		{
+			while (!ts.atEnd())
+			{
+				tmp = readLinefromDataStream(ts);
+				if (tmp.contains("EndRaster"))
+					break;
+				if(progressDialog)
+				{
+					progressDialog->setProgress("GI", ts.device()->pos());
+					qApp->processEvents();
+				}
+			}
+		}
 		else
 			processData(tmp);
 	}
@@ -2765,17 +2790,27 @@
 					currItem->AutoName = false;
 					m_Doc->DoDrawing = true;
 					pat.pattern = currItem->DrawObj_toImage();
-					pat.width = currItem->gWidth;
-					pat.height = currItem->gHeight;
-					m_Doc->DoDrawing = false;
+					if (!pat.pattern.isNull())
+					{
+						pat.width = currItem->gWidth;
+						pat.height = currItem->gHeight;
+						m_Doc->DoDrawing = false;
+						for (int as = 0; as < tmpSel->count(); ++as)
+						{
+							PageItem* Neu = tmpSel->itemAt(as);
+							pat.items.append(Neu);
+						}
+						importedPatterns.append(currentPatternDefName);
+						importedSymbols.insert(currentPatternDefName, QPointF(currItem->xPos(), currItem->yPos()+currItem->height()));
+						m_Doc->addPattern(currentPatternDefName, pat);
+					}
+				}
+				if (groupStack.count() != 0)
+				{
 					for (int as = 0; as < tmpSel->count(); ++as)
 					{
-						PageItem* Neu = tmpSel->itemAt(as);
-						pat.items.append(Neu);
+						groupStack.top().removeAll(tmpSel->itemAt(as));
 					}
-					importedPatterns.append(currentPatternDefName);
-					importedSymbols.insert(currentPatternDefName, QPointF(currItem->xPos(), currItem->yPos()+currItem->height()));
-					m_Doc->addPattern(currentPatternDefName, pat);
 				}
 				m_Doc->itemSelection_DeleteItem(tmpSel);
 			}
@@ -2783,6 +2818,20 @@
 			currentPatternDefName = "";
 			break;
 		}
+		else if (tmp.contains("BeginRaster") && (tmp.startsWith("%")))
+		{
+			while (!ts.atEnd())
+			{
+				tmp = readLinefromDataStream(ts);
+				if (tmp.contains("EndRaster"))
+					break;
+				if(progressDialog)
+				{
+					progressDialog->setProgress("GI", ts.device()->pos());
+					qApp->processEvents();
+				}
+			}
+		}
 		else
 		{
 			processData(tmp);
@@ -3105,6 +3154,62 @@
 			qApp->processEvents();
 		}
 	}
+	else if (tmp.contains("BeginRaster") && (tmp.startsWith("%")))
+	{
+		while (!ts.atEnd())
+		{
+			tmp = readLinefromDataStream(ts);
+			if (tmp.contains("EndRaster"))
+				break;
+			if(progressDialog)
+			{
+				progressDialog->setProgress("GI", ts.device()->pos());
+				qApp->processEvents();
+			}
+		}
+	}
+	else if (tmp.startsWith("BeginSVGFilter"))
+	{
+		while (!ts.atEnd())
+		{
+			tmp = removeAIPrefix(readLinefromDataStream(ts));
+			if (tmp.startsWith("EndSVGFilter"))
+				break;
+			if(progressDialog)
+			{
+				progressDialog->setProgress("GI", ts.device()->pos());
+				qApp->processEvents();
+			}
+		}
+	}
+	else if (tmp.startsWith("BeginArtStyles"))
+	{
+		while (!ts.atEnd())
+		{
+			tmp = removeAIPrefix(readLinefromDataStream(ts));
+			if (tmp.startsWith("EndArtStyles"))
+				break;
+			if(progressDialog)
+			{
+				progressDialog->setProgress("GI", ts.device()->pos());
+				qApp->processEvents();
+			}
+		}
+	}
+	else if (tmp.startsWith("BeginPluginObject"))
+	{
+		while (!ts.atEnd())
+		{
+			tmp = removeAIPrefix(readLinefromDataStream(ts));
+			if (tmp.startsWith("EndPluginObject"))
+				break;
+			if(progressDialog)
+			{
+				progressDialog->setProgress("GI", ts.device()->pos());
+				qApp->processEvents();
+			}
+		}
+	}
 	else if (tmp.startsWith("BeginLayer"))
 	{
 		while (!ts.atEnd())




More information about the scribus-commit mailing list