Пример #1
0
void Serializer::serializeObjects(const Selection& selection, SaxHandler& outputhandler)
{
	Xml_attr attr;
	UniqueID handler( & outputhandler );
	handler.beginDoc();
	handler.begin("SCRIBUSFRAGMENT", attr);
	ScribusDoc* doc = selection.itemAt(0)->doc();
	
	
	QMap<QString,int>::Iterator itf;
	for (itf = doc->UsedFonts.begin(); itf != doc->UsedFonts.end(); ++itf)
	{
		attr["name"] = itf.key();
		handler.beginEnd("font", attr);
	}
	
	ColorList usedColors;
	doc->getUsedColors(usedColors, false);
	ColorList::Iterator itc;
	for (itc = usedColors.begin(); itc != usedColors.end(); ++itc)
	{
		Xml_attr cattr;
		cattr["name"] = itc.key();
		if (doc->PageColors[itc.key()].getColorModel() == colorModelRGB)
			cattr["RGB"] = doc->PageColors[itc.key()].nameRGB();
		else
			cattr["CMYK"] = doc->PageColors[itc.key()].nameCMYK();
		cattr["Spot"] = toXMLString(doc->PageColors[itc.key()].isSpotColor());
		cattr["Register"] = toXMLString(doc->PageColors[itc.key()].isRegistrationColor());
		handler.beginEnd("color", cattr);
	}
	
	ResourceCollection lists;
	for (int i=0; i < doc->Items->count(); ++i)
		doc->Items->at(i)->getNamedResources(lists);
	
	QList<QString>::Iterator it;
	QList<QString> names = lists.styleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->paragraphStyles().get(*it).saxx(handler);

	names = lists.charStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->charStyles().get(*it).saxx(handler);
	
	names = lists.lineStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
	{
		Xml_attr multiattr;
		multiattr["Name"] = *it;
		handler.begin("MultiLine", multiattr);		
		multiLine ml = doc->MLineStyles[*it];
		
		multiLine::Iterator itMU2;
		for (itMU2 = ml.begin(); itMU2 != ml.end(); ++itMU2)
		{
			Xml_attr lineattr;
			lineattr["Color"] = (*itMU2).Color;
			lineattr["Shade"] = toXMLString((*itMU2).Shade);
			lineattr["Dash"] = toXMLString((*itMU2).Dash);
			lineattr["LineEnd"] = toXMLString((*itMU2).LineEnd);
			lineattr["LineJoin"] = toXMLString((*itMU2).LineJoin);
			lineattr["Width"] = toXMLString((*itMU2).Width);
			handler.beginEnd("SubLine", lineattr);
		}
		handler.end("MultiLine");
	}

	/*	names = lists.patterns();
	for (it = names.begin(); it != names.end(); ++it)
		doc->patterns[*it].saxx(handler);
*/
/*
	QStringList patterns = doc->getUsedPatternsSelection((Selection*)&selection);
	for (int c = 0; c < patterns.count(); ++c)
	{
		ScPattern& pa = doc->docPatterns[patterns[c]];
		Xml_attr cattr;
		cattr["Name"] = patterns[c];
		cattr["scaleX"] = toXMLString(pa.scaleX);
		cattr["scaleY"] = toXMLString(pa.scaleY);
		cattr["width"] = toXMLString(pa.width);
		cattr["height"] = toXMLString(pa.height);
		cattr["xoffset"] = toXMLString(pa.xoffset);
		cattr["yoffset"] = toXMLString(pa.yoffset);
		handler.begin("Pattern", cattr);
		for (int o = 0; o < pa.items.count(); o++)
		{
			pa.items.at(o)->saxx(handler);
		}
		handler.end("Pattern");
	}
*/
	for (int i=0; i < doc->Items->count(); ++i)
	{
		int k = selection.findItem(doc->Items->at(i));
		if (k >=0)
			doc->Items->at(i)->saxx(handler);
	}

	handler.end("SCRIBUSFRAGMENT");
	handler.endDoc();
}
Пример #2
0
bool ScPrintEngine_PS::print(ScribusDoc& doc, PrintOptions& options)
{
	bool retw = false;
	ColorList usedColors;
	QMap<QString, QMap<uint, FPointArray> > usedFonts;
	QString filename(options.filename);
	doc.getUsedFonts(usedFonts);
	doc.getUsedColors(usedColors);
	PrefsManager *prefsManager = PrefsManager::instance();
	PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, usedFonts, usedColors, options.includePDFMarks, options.useSpotColors);
	if (dd != NULL)
	{
		if (!options.toFile)
			filename = prefsManager->preferencesLocation()+"/tmp.ps";
		bool PSfile = dd->PS_set_file(filename);
		filename = QDir::toNativeSeparators(filename);
		if (PSfile)
		{
			// Write the PS to a file
			int psCreationRetVal=dd->CreatePS(&doc, options);
			if (psCreationRetVal!=0)
			{
				QFile::remove(filename);
				if (psCreationRetVal==2)
					return true;
				else
				{
					m_errorMessage = dd->errorMessage();
					return false;
				}
			}
			if (options.prnEngine != PostScript3 && ScCore->haveGS())
			{
				// use gs to convert our PS to a lower version
				QString tmp;
				QStringList opts;
				opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc.pageWidth)) );
				opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc.pageHeight)) );
				convertPS2PS(filename, filename + ".tmp", opts, options.prnEngine);
				moveFile( filename + ".tmp", filename );
			}
			if (!options.toFile)
			{
				// print and delete the PS file
				QByteArray cmd;
				if (options.useAltPrintCommand)
				{
					cmd += options.printerCommand;
					cmd += " ";
					cmd += filename;
					system(cmd.data());
				}
				else
				{
					QByteArray cc;
					cmd += "lpr -P '";
					cmd += options.printer;
					cmd += "'";
					if (options.copies > 1)
						cmd += " -#" + cc.setNum(options.copies);
					cmd += options.printerOptions;
					cmd += " "+filename;
					system(cmd.data());
				}
// Disabled that for now, as kprinter won't work otherwise
// leaving that file around doesn't harm, as it will be overwritten the next time.
//				unlink(filename);
			}
			retw = true;
		}
		else
			retw = false;
		delete dd;
	}
	return retw;
}