r16162 by fschmid - Unified ScriXmlDoc and the scribus150format plugin, they share now the XML read/write code.

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 26 00:36:56 CET 2010


Author: fschmid
Date: Sat Dec 25 23:36:56 2010
New Revision: 16162

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16162
Log:
Unified ScriXmlDoc and the scribus150format plugin, they share now the XML read/write code.

Modified:
    trunk/Scribus/scribus/loadsaveplugin.cpp
    trunk/Scribus/scribus/loadsaveplugin.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
    trunk/Scribus/scribus/scribusXml.cpp
    trunk/Scribus/scribus/scribusXml.h

Modified: trunk/Scribus/scribus/loadsaveplugin.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/loadsaveplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/loadsaveplugin.cpp (original)
+++ trunk/Scribus/scribus/loadsaveplugin.cpp Sat Dec 25 23:36:56 2010
@@ -214,6 +214,11 @@
 bool LoadSavePlugin::savePalette(const QString & fileName)
 {
 	return false;
+}
+
+QString LoadSavePlugin::saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData)
+{
+	return "";
 }
 
 bool LoadSavePlugin::loadPalette(const QString & fileName)
@@ -449,6 +454,11 @@
 	return (plug && save) ? plug->savePalette(fileName) : false;
 }
 
+QString FileFormat::saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData) const
+{
+	return (plug && save) ? plug->saveElements(xp, yp, wp, hp, selection, prevData) : "";
+}
+
 bool FileFormat::loadElements(const QString & data, QString fileDir, int toLayer, double Xp_in, double Yp_in, bool loc) const
 {
 	return (plug && load) ? plug->loadElements(data, fileDir, toLayer, Xp_in, Yp_in, loc) : false;

Modified: trunk/Scribus/scribus/loadsaveplugin.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/loadsaveplugin.h
==============================================================================
--- trunk/Scribus/scribus/loadsaveplugin.h (original)
+++ trunk/Scribus/scribus/loadsaveplugin.h Sat Dec 25 23:36:56 2010
@@ -87,6 +87,7 @@
 		// Save the requested format to the requested path.
 		virtual bool saveFile(const QString & fileName, const FileFormat & fmt);
 		virtual bool savePalette(const QString & fileName);
+		virtual QString saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData);
 
 		// Return last file saved, this may be the last fileName argument passed to saveFile(),
 		// a temporary file name or an empty string if last call to saveFile() could not create
@@ -200,6 +201,7 @@
 		// Save a file with this format
 		bool saveFile(const QString & fileName) const;
 		bool savePalette(const QString & fileName) const;
+		QString saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData) const;
 		// Get last saved file
 		QString lastSavedFile(void) const;
 		

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h Sat Dec 25 23:36:56 2010
@@ -12,6 +12,7 @@
 #include "scfonts.h"
 #include "scribusstructs.h"
 #include "styles/styleset.h"
+#include "selection.h"
 
 #include <QMap>
 #include <QString>
@@ -45,6 +46,7 @@
 		virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
 		virtual bool saveFile(const QString & fileName, const FileFormat & fmt);
 		virtual bool savePalette(const QString & fileName);
+		virtual QString saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData);
 		virtual bool loadPalette(const QString & fileName);
 		virtual bool loadElements(const QString & data, QString fileDir, int toLayer, double Xp_in, double Yp_in, bool loc);
 		virtual void addToMainWindowMenu(ScribusMainWindow *) {};
@@ -66,6 +68,7 @@
 			ItemSelectionFrame  = 2,
 			ItemSelectionPattern= 3,
 			ItemSelectionGroup  = 4,
+			ItemSelectionElements = 5,
 		};
 
 		class ItemInfo
@@ -121,8 +124,8 @@
 		void writeLinestyles(ScXmlStreamWriter& docu);
 		void writeJavascripts(ScXmlStreamWriter& docu);
 		void writeBookmarks(ScXmlStreamWriter& docu);
-		void writeColors(ScXmlStreamWriter& docu);
-		void writeGradients(ScXmlStreamWriter & docu);
+		void writeColors(ScXmlStreamWriter& docu, bool part = false);
+		void writeGradients(ScXmlStreamWriter & docu, bool part = false);
 		void writeHyphenatorLists(ScXmlStreamWriter& docu);
 		void writePStyles(ScXmlStreamWriter& docu);
 		void writeCStyles(ScXmlStreamWriter& docu);
@@ -138,7 +141,7 @@
 		void writeTOC(ScXmlStreamWriter& docu);
 		void writePageSets(ScXmlStreamWriter& docu);
 		void writeSections(ScXmlStreamWriter& docu);
-		void writePatterns(ScXmlStreamWriter& docu, const QString& baseDir);
+		void writePatterns(ScXmlStreamWriter& docu, const QString& baseDir, bool part = false, Selection* selection = 0);
 		void writeContent(ScXmlStreamWriter& docu, const QString& baseDir);
 
 		void WritePages(ScribusDoc *doc, ScXmlStreamWriter& docu, QProgressBar *dia2, uint maxC, bool master);

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp Sat Dec 25 23:36:56 2010
@@ -14,6 +14,7 @@
 #include "commonstrings.h"
 #include "ui/missing.h"
 #include "prefsmanager.h"
+#include "resourcecollection.h"
 #include "scconfig.h"
 #include "scpattern.h"
 #include "scribusdoc.h"
@@ -35,6 +36,56 @@
 #include <QDataStream>
 
 #include "scxmlstreamwriter.h"
+
+QString Scribus150Format::saveElements(double xp, double yp, double wp, double hp, Selection* selection, QByteArray &prevData)
+{
+	QString fileDir = QDir::homePath();
+	QString documentStr;
+	documentStr.reserve(524288);
+	ScXmlStreamWriter writer(&documentStr);
+	writer.setAutoFormatting(true);
+	writer.writeStartElement("SCRIBUSELEMUTF8");
+	writer.writeAttribute("XP", xp);
+	writer.writeAttribute("YP", yp);
+	writer.writeAttribute("W", wp);
+	writer.writeAttribute("H", hp);
+	writer.writeAttribute("COUNT",   selection->count());
+	writer.writeAttribute("Version", QString(VERSION));
+	writer.writeAttribute("previewData", QString(prevData));
+	writeColors(writer, true);
+	writeGradients(writer, true);
+	ResourceCollection lists;
+	QList<PageItem*> emG;
+	for (int cor = 0; cor < selection->count(); ++cor)
+	{
+		selection->itemAt(cor)->getNamedResources(lists);
+		emG.append(selection->itemAt(cor));
+	}
+	QList<QString>::Iterator it;
+	QList<QString> names = lists.styleNames();
+	for (it = names.begin(); it != names.end(); ++it)
+	{
+		putPStyle(writer, m_Doc->paragraphStyles().get(*it), "STYLE");
+	}
+	names = lists.charStyleNames();
+	for (it = names.begin(); it != names.end(); ++it)
+	{
+		writer.writeStartElement("CHARSTYLE");
+		putNamedCStyle(writer, m_Doc->charStyles().get(*it));
+		writer.writeEndElement();
+	}
+/*	names = lists.lineStyleNames();
+	for (it = names.begin(); it != names.end(); ++it)
+	{
+		writeLinestyles(writer, true, *it);
+	} */
+	writeLinestyles(writer);
+	writePatterns(writer, fileDir, true, selection);
+	WriteObjects(m_Doc, writer, fileDir, 0, 0, ItemSelectionElements, &emG);
+	writer.writeEndElement();
+	writer.writeEndDocument();
+	return documentStr;
+}
 
 bool Scribus150Format::savePalette(const QString & fileName)
 {
@@ -269,7 +320,6 @@
 	docu.writeAttribute("calligrapicPenStyle", m_Doc->itemToolPrefs().calligrapicPenStyle);
 
 	writeCheckerProfiles(docu);
-	writeLinestyles(docu);
 	writeJavascripts(docu);
 	writeBookmarks(docu);
 	writeColors(docu);
@@ -277,6 +327,7 @@
 	writeHyphenatorLists(docu);
 	writePStyles(docu);
 	writeCStyles(docu);
+	writeLinestyles(docu);
 	writeLayers(docu);
 	writePrintOptions(docu);
 	writePdfOptions(docu);
@@ -417,10 +468,15 @@
 }
 
 
-void Scribus150Format::writeColors(ScXmlStreamWriter & docu) 
+void Scribus150Format::writeColors(ScXmlStreamWriter & docu, bool part) 
 {	
 	ColorList::Iterator itc;
-	for (itc = m_Doc->PageColors.begin(); itc != m_Doc->PageColors.end(); ++itc)
+	ColorList usedColors;
+	if (part)
+		m_Doc->getUsedColors(usedColors);
+	else
+		usedColors = m_Doc->PageColors;
+	for (itc = usedColors.begin(); itc != usedColors.end(); ++itc)
 	{
 		docu.writeEmptyElement("COLOR");
 		docu.writeAttribute("NAME",itc.key());
@@ -434,10 +490,15 @@
 	
 }
 
-void Scribus150Format::writeGradients(ScXmlStreamWriter & docu)
+void Scribus150Format::writeGradients(ScXmlStreamWriter & docu, bool part)
 {
 	QMap<QString, VGradient>::Iterator itGrad;
-	for (itGrad = m_Doc->docGradients.begin(); itGrad != m_Doc->docGradients.end(); ++itGrad)
+	QMap<QString, VGradient> gradMap;
+	if (part)
+		m_Doc->getUsedGradients(gradMap);
+	else
+		gradMap = m_Doc->docGradients;
+	for (itGrad = gradMap.begin(); itGrad != gradMap.end(); ++itGrad)
 	{
 		docu.writeStartElement("Gradient");
 		docu.writeAttribute("Name",itGrad.key());
@@ -911,9 +972,13 @@
 	docu.writeEndElement();
 }
 
-void Scribus150Format::writePatterns(ScXmlStreamWriter & docu, const QString& baseDir) 
-{
-	QStringList patterns = m_Doc->getPatternDependencyList(m_Doc->docPatterns.keys());
+void Scribus150Format::writePatterns(ScXmlStreamWriter & docu, const QString& baseDir, bool part, Selection* selection)
+{
+	QStringList patterns;
+	if (part)
+		patterns = m_Doc->getPatternDependencyList(m_Doc->getUsedPatternsSelection(selection));
+	else
+		patterns = m_Doc->getPatternDependencyList(m_Doc->docPatterns.keys());
 	for (int a = 0; a < patterns.count(); a++)
 	{
 		docu.writeStartElement("Pattern");
@@ -1161,6 +1226,7 @@
 			break;
 		case ItemSelectionGroup:
 		case ItemSelectionPattern:
+		case ItemSelectionElements:
 			items = some_items;
 			break;
 		default:
@@ -1191,6 +1257,19 @@
 			case ItemSelectionPattern:
 				docu.writeStartElement("PatternItem");
 				break;
+			case ItemSelectionElements:
+				docu.writeStartElement("ITEM");
+				break;
+		}
+		if (master == ItemSelectionElements)
+		{
+			docu.writeAttribute("XPOS", item->xPos() - doc->currentPage()->xOffset());
+			docu.writeAttribute("YPOS", item->yPos() - doc->currentPage()->yOffset());
+		}
+		else
+		{
+			docu.writeAttribute("XPOS", item->xPos());
+			docu.writeAttribute("YPOS", item->yPos());
 		}
 		SetItemProps(docu, item, baseDir, true);
 		docu.writeAttribute("OnMasterPage", item->OnMasterPage);
@@ -1558,8 +1637,8 @@
 	if (newFormat)
 		docu.writeAttribute("OwnPage", item->OwnPage);
 	docu.writeAttribute("PTYPE",item->realItemType());
-	docu.writeAttribute("XPOS",item->xPos());
-	docu.writeAttribute("YPOS",item->yPos());
+//	docu.writeAttribute("XPOS",item->xPos());
+//	docu.writeAttribute("YPOS",item->yPos());
 	docu.writeAttribute("WIDTH",item->width());
 	docu.writeAttribute("HEIGHT",item->height());
 	docu.writeAttribute("RADRECT",item->cornerRadius());

Modified: trunk/Scribus/scribus/scribusXml.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/scribusXml.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusXml.cpp (original)
+++ trunk/Scribus/scribus/scribusXml.cpp Sat Dec 25 23:36:56 2010
@@ -70,7 +70,7 @@
 ScriXmlDoc::ScriXmlDoc()
 {
 }
-
+#if 0
 void ScriXmlDoc::SetItemProps(ScXmlStreamWriter& writer, ScribusDoc *doc, PageItem* item, const QString& baseDir, bool newFormat)
 {
 	double xf, yf;
@@ -322,7 +322,7 @@
 	writer.writeAttribute("startArrowScale", item->startArrowScale());
 	writer.writeAttribute("endArrowScale"  , item->endArrowScale());
 }
-
+#endif
 bool ScriXmlDoc::ReadElemHeader(QString file, bool isFile, double *x, double *y, double *w, double *h)
 {
 	QString ff = "";
@@ -409,6 +409,100 @@
 	return false;
 }
 
+QString ScriXmlDoc::WriteElem(ScribusDoc *doc, Selection* selection)
+{
+	if (selection->count()==0)
+		return "";
+	double xp, yp, wp, hp;
+	QString tmp, tmpy;
+	PageItem *item;
+	QString documentStr = "";
+	item = selection->itemAt(0);
+	QList<PageItem*> emG;
+	emG.clear();
+	for (int cor = 0; cor < selection->count(); ++cor)
+	{
+		emG.append(selection->itemAt(cor));
+	}
+	double selectionWidth = 0;
+	double selectionHeight = 0;
+	if (selection->isMultipleSelection())
+	{
+		double gx, gy, gw, gh;
+		selection->getGroupRect(&gx, &gy, &gw, &gh);
+		xp = gx - doc->currentPage()->xOffset();
+		yp = gy - doc->currentPage()->yOffset();
+		wp = gw;
+		hp = gh;
+		selection->getVisualGroupRect(&gx, &gy, &selectionWidth, &selectionHeight);
+	}
+	else
+	{
+		if (item->rotation() != 0)
+		{
+			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();
+			double xpo = item->xPos() - doc->currentPage()->xOffset();
+			double ypo = item->yPos() - doc->currentPage()->yOffset();
+			FPointArray pb(4);
+			pb.setPoint(0, FPoint(xpo, ypo));
+			pb.setPoint(1, FPoint(item->width(), 0.0, xpo, ypo, item->rotation(), 1.0, 1.0));
+			pb.setPoint(2, FPoint(item->width(), item->height(), xpo, ypo, item->rotation(), 1.0, 1.0));
+			pb.setPoint(3, FPoint(0.0, item->height(), xpo, ypo, item->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());
+			}
+			wp = maxx - minx;
+			hp = maxy - miny;
+		}
+		else
+		{
+			wp = item->width();
+			hp = item->height();
+		}
+		selectionWidth = item->visualWidth();
+		selectionHeight = item->visualHeight();
+		xp = item->xPos() - doc->currentPage()->xOffset();
+		yp = item->yPos() - doc->currentPage()->yOffset();
+	}
+	double scaleI = 50.0 / qMax(selectionWidth, selectionHeight);
+	QImage retImg = QImage(50, 50, QImage::Format_ARGB32_Premultiplied);
+	retImg.fill( qRgba(0, 0, 0, 0) );
+	ScPainter *painter = new ScPainter(&retImg, retImg.width(), retImg.height(), 1, 0);
+	painter->setZoomFactor(scaleI);
+	for (int em = 0; em < emG.count(); ++em)
+	{
+		PageItem* embedded = emG.at(em);
+		painter->save();
+		double x = embedded->xPos();
+		double y = embedded->yPos();
+		embedded->setXYPos(embedded->xPos()- doc->currentPage()->xOffset() - xp, embedded->yPos()- doc->currentPage()->yOffset() - yp, true);
+		embedded->invalid = true;
+		embedded->DrawObj(painter, QRectF());
+		embedded->setXYPos(x, y, true);
+		painter->restore();
+	}
+	delete painter;
+	QBuffer buffer;
+	buffer.open(QIODevice::WriteOnly);
+	retImg.save(&buffer, "PNG");
+	QByteArray ba = buffer.buffer().toBase64();
+	buffer.close();
+	const FileFormat *fmt = LoadSavePlugin::getFormatById(FORMATID_SLA150EXPORT);
+	if (fmt)
+	{
+		fmt->setupTargets(doc, 0, doc->scMW(), 0, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts));
+		documentStr = fmt->saveElements(xp, yp, wp, hp, selection, ba);
+	}
+	return documentStr;
+}
+#if 0
 QString ScriXmlDoc::WriteElem(ScribusDoc *doc, Selection* selection)
 {
 	if (selection->count()==0)
@@ -735,7 +829,6 @@
 	writer.writeEndDocument();
 	return documentStr;
 }
-
 void ScriXmlDoc::WriteObject(ScXmlStreamWriter& writer, ScribusDoc *doc, PageItem *item, const QString& baseDir, QMap<int, int> &UsedMapped2Saved)
 {
 	QString text, tmp, tmpy;
@@ -1272,3 +1365,4 @@
 
 	writer.writeEndElement();
 }
+#endif

Modified: trunk/Scribus/scribus/scribusXml.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16162&path=/trunk/Scribus/scribus/scribusXml.h
==============================================================================
--- trunk/Scribus/scribus/scribusXml.h (original)
+++ trunk/Scribus/scribus/scribusXml.h Sat Dec 25 23:36:56 2010
@@ -27,7 +27,7 @@
 
 #include <QXmlStreamAttributes>
 #include <QXmlStreamReader>
-#include <QXmlStreamWriter>
+//#include <QXmlStreamWriter>
 class PageItem;
 class PrefsManager;
 class SCFonts;
@@ -53,7 +53,7 @@
 	bool ReadElem(QString fileName, SCFonts &avail, ScribusDoc *doc, double Xp, double Yp, bool Fi, bool loc, QMap<QString,QString> &FontSub);
 	bool ReadElemToLayer(QString fileName, SCFonts &avail, ScribusDoc *doc, double Xp, double Yp, bool Fi, bool loc, QMap<QString,QString> &FontSub, int toLayer);
 	QString WriteElem(ScribusDoc *doc, Selection *selection);
-	
+/*
 protected:
 	void SetItemProps(ScXmlStreamWriter& writer, ScribusDoc *doc, PageItem* item, const QString& baseDir, bool newFormat);
 	void WriteObject (ScXmlStreamWriter& writer, ScribusDoc *doc, PageItem *item, const QString& baseDir, QMap<int, int> &UsedMapped2Saved);
@@ -61,6 +61,7 @@
 	void WriteLegacyCStyle (ScXmlStreamWriter& writer, const CharStyle& style);
 	void WriteCStyle (ScXmlStreamWriter& writer, const CharStyle& style);
 	void WritePStyle (ScXmlStreamWriter& writer, const ParagraphStyle& style, const QString& nodeName);
+*/
 };
 
 #endif // _SCRIBUS_CONFIG_




More information about the scribus-commit mailing list