1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8                           importxar.cpp  -  description
9                              -------------------
10     begin                : Wed Nov 25 2009
11     copyright            : (C) 2009 by Franz Schmid
12     email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 
15 #include <QByteArray>
16 #include <QCursor>
17 #include <QDrag>
18 #include <QFile>
19 #include <QMimeData>
20 #include <QRegExp>
21 #include <QTextCodec>
22 #include <QDebug>
23 #include "qtiocompressor.h"
24 
25 #include <cstdlib>
26 
27 #include "importxar.h"
28 
29 
30 #include "loadsaveplugin.h"
31 #include "pageitem_imageframe.h"
32 #include "pageitem_polygon.h"
33 #include "pageitem_polyline.h"
34 #include "pagesize.h"
35 #include "prefscontext.h"
36 #include "prefsfile.h"
37 #include "prefsmanager.h"
38 #include "prefstable.h"
39 #include "rawimage.h"
40 #include "scclocale.h"
41 #include "sccolorengine.h"
42 #include "scconfig.h"
43 #include "scmimedata.h"
44 #include "scpaths.h"
45 #include "scpattern.h"
46 #include "scribusXml.h"
47 #include "scribuscore.h"
48 #include "scribusdoc.h"
49 #include "scribusview.h"
50 #include "sctextstream.h"
51 #include "selection.h"
52 #include "ui/customfdialog.h"
53 #include "ui/missing.h"
54 #include "ui/multiprogressdialog.h"
55 #include "ui/propertiespalette.h"
56 #include "undomanager.h"
57 #include "util.h"
58 #include "util_formats.h"
59 #include "util_math.h"
60 
XarPlug(ScribusDoc * doc,int flags)61 XarPlug::XarPlug(ScribusDoc* doc, int flags)
62 {
63 	tmpSel=new Selection(this, false);
64 	m_Doc=doc;
65 	importerFlags = flags;
66 	interactive = (flags & LoadSavePlugin::lfInteractive);
67 	progressDialog = nullptr;
68 }
69 
readColors(const QString & fileName,ColorList & colors)70 bool XarPlug::readColors(const QString& fileName, ColorList & colors)
71 {
72 	progressDialog = nullptr;
73 	bool success = false;
74 	importedColors.clear();
75 	QFile f(fileName);
76 	if (f.open(QIODevice::ReadOnly))
77 	{
78 		QDataStream ts(&f);
79 		ts.setByteOrder(QDataStream::LittleEndian);
80 		quint32 id;
81 		ts >> id;
82 		if (id != 0x41524158)
83 			return false;
84 		ts >> id;
85 		if (id != 0x0A0DA3A3)
86 			return false;
87 		m_Doc = new ScribusDoc();
88 		m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
89 		m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
90 		m_Doc->addPage(0);
91 		m_Doc->setGUI(false, ScCore->primaryMainWindow(), nullptr);
92 		m_Doc->setLoading(true);
93 		m_Doc->DoDrawing = false;
94 		m_Doc->scMW()->setScriptRunning(true);
95 		m_Doc->PageColors.clear();
96 		while (!ts.atEnd())
97 		{
98 			quint32 opCode, dataLen;
99 			ts >> opCode;
100 			ts >> dataLen;
101 			if (opCode == 30)
102 			{
103 				ts.skipRawData(dataLen);
104 				QtIOCompressor compressor(ts.device(), 6, 1);
105 				compressor.setStreamFormat(QtIOCompressor::RawZipFormat);
106 				compressor.open(QIODevice::ReadOnly);
107 				QDataStream tsc(&compressor);
108 				tsc.setByteOrder(QDataStream::LittleEndian);
109 				while (!tsc.atEnd())
110 				{
111 					tsc >> opCode;
112 					tsc >> dataLen;
113 					recordCounter++;
114 					if (opCode == 31)
115 					{
116 						tsc.skipRawData(dataLen);
117 						break;
118 					}
119 					if (opCode == 51)
120 						handleComplexColor(tsc);
121 					else
122 						tsc.skipRawData(dataLen);
123 				}
124 				ts.skipRawData(dataLen+1);
125 			}
126 			else
127 			{
128 				if (opCode == 51)
129 					handleComplexColor(ts);
130 				else
131 					ts.skipRawData(dataLen);
132 			}
133 		}
134 		f.close();
135 		if (m_Doc->PageColors.count() != 0)
136 		{
137 			ColorList::Iterator it;
138 			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
139 			{
140 				if (!it.key().startsWith("FromXara"))
141 				{
142 					success = true;
143 					colors.insert(it.key(), it.value());
144 				}
145 			}
146 		}
147 		m_Doc->scMW()->setScriptRunning(false);
148 		m_Doc->setLoading(false);
149 		delete m_Doc;
150 	}
151 	return success;
152 }
153 
readThumbnail(const QString & fName)154 QImage XarPlug::readThumbnail(const QString& fName)
155 {
156 	progressDialog = nullptr;
157 	QImage image = QImage();
158 	QFile f(fName);
159 	if (f.open(QIODevice::ReadOnly))
160 	{
161 		QDataStream ts(&f);
162 		ts.setByteOrder(QDataStream::LittleEndian);
163 		quint32 id;
164 		ts >> id;
165 		if (id != 0x41524158)
166 			return image;
167 		ts >> id;
168 		if (id != 0x0A0DA3A3)
169 			return image;
170 		while (!ts.atEnd())
171 		{
172 			quint32 opCode, dataLen;
173 			ts >> opCode;
174 			ts >> dataLen;
175 			if (opCode == 30)
176 			{
177 				ts.skipRawData(dataLen);
178 				QtIOCompressor compressor(ts.device(), 6, 1);
179 				compressor.setStreamFormat(QtIOCompressor::RawZipFormat);
180 				compressor.open(QIODevice::ReadOnly);
181 				QDataStream tsc(&compressor);
182 				tsc.setByteOrder(QDataStream::LittleEndian);
183 				while (!tsc.atEnd())
184 				{
185 					tsc >> opCode;
186 					tsc >> dataLen;
187 					recordCounter++;
188 					if (opCode == 31)
189 					{
190 						tsc.skipRawData(dataLen);
191 						break;
192 					}
193 					if ((opCode == 61) || (opCode == 62) || (opCode == 63))
194 					{
195 						QByteArray data;
196 						data.resize(dataLen);
197 						tsc.readRawData(data.data(), dataLen);
198 						image.loadFromData(data);
199 					}
200 					else if (opCode == 45)
201 						handleSpreadInfo(tsc);
202 					else
203 						tsc.skipRawData(dataLen);
204 				}
205 				ts.skipRawData(dataLen+1);
206 			}
207 			else
208 			{
209 				if ((opCode == 61) || (opCode == 62) || (opCode == 63))
210 				{
211 					QByteArray data;
212 					data.resize(dataLen);
213 					ts.readRawData(data.data(), dataLen);
214 					image.loadFromData(data);
215 				}
216 				else if (opCode == 45)
217 					handleSpreadInfo(ts);
218 				else
219 					ts.skipRawData(dataLen);
220 			}
221 		}
222 		f.close();
223 	}
224 	image.setText("XSize", QString("%1").arg(docWidth));
225 	image.setText("YSize", QString("%1").arg(docHeight));
226 	return image;
227 }
228 
import(const QString & fNameIn,const TransactionSettings & trSettings,int flags,bool showProgress)229 bool XarPlug::import(const QString& fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
230 {
231 	const QString& fName = fNameIn;
232 	bool success = false;
233 	interactive = (flags & LoadSavePlugin::lfInteractive);
234 	importerFlags = flags;
235 	cancel = false;
236 	double x, y, b, h;
237 	bool ret = false;
238 	QFileInfo fi = QFileInfo(fName);
239 	if ( !ScCore->usingGUI() )
240 	{
241 		interactive = false;
242 		showProgress = false;
243 	}
244 	if ( showProgress )
245 	{
246 		ScribusMainWindow* mw=(m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW();
247 		progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
248 		QStringList barNames, barTexts;
249 		barNames << "GI";
250 		barTexts << tr("Analyzing File:");
251 		QList<bool> barsNumeric;
252 		barsNumeric << false;
253 		progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
254 		progressDialog->setOverallTotalSteps(3);
255 		progressDialog->setOverallProgress(0);
256 		progressDialog->setProgress("GI", 0);
257 		progressDialog->show();
258 		connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
259 		qApp->processEvents();
260 	}
261 	else
262 		progressDialog = nullptr;
263 /* Set default Page to size defined in Preferences */
264 	x = 0.0;
265 	y = 0.0;
266 	b = 0.0;
267 	h = 0.0;
268 	if (progressDialog)
269 	{
270 		progressDialog->setOverallProgress(1);
271 		qApp->processEvents();
272 	}
273 //	parseHeader(fName, x, y, b, h);
274 	if (b == 0.0)
275 		b = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth;
276 	if (h == 0.0)
277 		h = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight;
278 	docWidth = b;
279 	docHeight = h;
280 	baseX = 0;
281 	baseY = 0;
282 	pagecount = 1;
283 	if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
284 	{
285 		m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
286 		m_Doc->addPage(0);
287 		m_Doc->view()->addPage(0, true);
288 		baseX = -x;
289 		baseY = -y;
290 	}
291 	else
292 	{
293 		if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
294 		{
295 			m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
296 			ScCore->primaryMainWindow()->HaveNewDoc();
297 			ret = true;
298 			baseX = m_Doc->currentPage()->xOffset() - x;
299 			baseY = m_Doc->currentPage()->yOffset() - y;
300 		}
301 	}
302 	if ((!ret) && (interactive))
303 	{
304 		baseX = m_Doc->currentPage()->xOffset() - x;
305 		baseY = m_Doc->currentPage()->yOffset() - y;
306 	}
307 	if ((ret) || (!interactive))
308 	{
309 		if (docWidth > docHeight)
310 			m_Doc->setPageOrientation(1);
311 		else
312 			m_Doc->setPageOrientation(0);
313 		m_Doc->setPageSize("Custom");
314 	}
315 	if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
316 		m_Doc->view()->deselectItems();
317 	Elements.clear();
318 	m_Doc->setLoading(true);
319 	m_Doc->DoDrawing = false;
320 	if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
321 		m_Doc->view()->updatesOn(false);
322 	m_Doc->scMW()->setScriptRunning(true);
323 	qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
324 	QString CurDirP = QDir::currentPath();
325 	QDir::setCurrent(fi.path());
326 	if (convert(fName))
327 	{
328 		tmpSel->clear();
329 		QDir::setCurrent(CurDirP);
330 		if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
331 			m_Doc->groupObjectsList(Elements);
332 		m_Doc->DoDrawing = true;
333 		m_Doc->scMW()->setScriptRunning(false);
334 		m_Doc->setLoading(false);
335 		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
336 		if ((Elements.count() > 0) && (!ret) && (interactive))
337 		{
338 			if (flags & LoadSavePlugin::lfScripted)
339 			{
340 				bool loadF = m_Doc->isLoading();
341 				m_Doc->setLoading(false);
342 				m_Doc->changed();
343 				m_Doc->setLoading(loadF);
344 				if (!(flags & LoadSavePlugin::lfLoadAsPattern))
345 				{
346 					m_Doc->m_Selection->delaySignalsOn();
347 					for (int dre=0; dre<Elements.count(); ++dre)
348 					{
349 						m_Doc->m_Selection->addItem(Elements.at(dre), true);
350 					}
351 					m_Doc->m_Selection->delaySignalsOff();
352 					m_Doc->m_Selection->setGroupRect();
353 					if (m_Doc->view() != nullptr)
354 						m_Doc->view()->updatesOn(true);
355 				}
356 			}
357 			else
358 			{
359 				m_Doc->DragP = true;
360 				m_Doc->DraggedElem = nullptr;
361 				m_Doc->DragElements.clear();
362 				m_Doc->m_Selection->delaySignalsOn();
363 				for (int dre=0; dre<Elements.count(); ++dre)
364 				{
365 					tmpSel->addItem(Elements.at(dre), true);
366 				}
367 				tmpSel->setGroupRect();
368 				ScElemMimeData* md = ScriXmlDoc::writeToMimeData(m_Doc, tmpSel);
369 				m_Doc->itemSelection_DeleteItem(tmpSel);
370 				m_Doc->view()->updatesOn(true);
371 				if (importedColors.count() != 0)
372 				{
373 					for (int cd = 0; cd < importedColors.count(); cd++)
374 					{
375 						m_Doc->PageColors.remove(importedColors[cd]);
376 					}
377 				}
378 				if (importedPatterns.count() != 0)
379 				{
380 					for (int cd = 0; cd < importedPatterns.count(); cd++)
381 					{
382 						m_Doc->docPatterns.remove(importedPatterns[cd]);
383 					}
384 				}
385 				m_Doc->m_Selection->delaySignalsOff();
386 				// We must copy the TransationSettings object as it is owned
387 				// by handleObjectImport method afterwards
388 				TransactionSettings* transacSettings = new TransactionSettings(trSettings);
389 				m_Doc->view()->handleObjectImport(md, transacSettings);
390 				m_Doc->DragP = false;
391 				m_Doc->DraggedElem = nullptr;
392 				m_Doc->DragElements.clear();
393 			}
394 		}
395 		else
396 		{
397 			m_Doc->changed();
398 			m_Doc->reformPages();
399 			m_Doc->view()->updatesOn(true);
400 			if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (!activeLayer.isEmpty()))
401 				m_Doc->setActiveLayer(activeLayer);
402 		}
403 		success = true;
404 	}
405 	else
406 	{
407 		QDir::setCurrent(CurDirP);
408 		m_Doc->DoDrawing = true;
409 		m_Doc->scMW()->setScriptRunning(false);
410 		if (!(flags & LoadSavePlugin::lfLoadAsPattern))
411 			m_Doc->view()->updatesOn(true);
412 		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
413 	}
414 	if (interactive)
415 		m_Doc->setLoading(false);
416 	//CB If we have a gui we must refresh it if we have used the progressbar
417 	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
418 	{
419 		if ((showProgress) && (!interactive))
420 			m_Doc->view()->DrawNew();
421 	}
422 	qApp->restoreOverrideCursor();
423 	return success;
424 }
425 
~XarPlug()426 XarPlug::~XarPlug()
427 {
428 	delete progressDialog;
429 	delete tmpSel;
430 }
431 
parseHeader(const QString & fName,double & x,double & y,double & b,double & h)432 void XarPlug::parseHeader(const QString& fName, double &x, double &y, double &b, double &h)
433 {
434 	QFile f(fName);
435 	if (f.open(QIODevice::ReadOnly))
436 	{
437 		QDataStream ts(&f);
438 		ts.device()->seek(512);
439 		qint16 pgX, pgY, pgW, pgH, dummy;
440 		ts >> dummy >> pgX >> pgY >> pgW >> pgH;
441 		h = pgW - pgX;
442 		b = pgH - pgY;
443 		x = pgY;
444 		y = pgX;
445 		f.close();
446 //		qDebug() << "W" << b << "H" << h;
447 	}
448 }
449 
convert(const QString & fn)450 bool XarPlug::convert(const QString& fn)
451 {
452 	Coords.resize(0);
453 	Coords.svgInit();
454 	imageData.resize(0);
455 	importedColors.clear();
456 	importedPatterns.clear();
457 	firstLayer = true;
458 	inTextLine = false;
459 	inTextBlock = false;
460 	recordPath = false;
461 	activeLayer = "";
462 	currentLayer = 0;
463 	XarColor color;
464 	color.colorType = 0;
465 	color.colorModel = 2;
466 	color.colorRef = 0;
467 	color.component1 = 0;
468 	color.component2 = 0;
469 	color.component3 = 0;
470 	color.component1 = 0;
471 	color.name = CommonStrings::None;
472 	XarColorMap.insert(-1, color);
473 	if (!m_Doc->PageColors.contains("Black"))
474 	{
475 		m_Doc->PageColors.insert("Black", ScColor(0, 0, 0, 255));
476 		importedColors.append("Black");
477 	}
478 	color.name = "Black";
479 	XarColorMap.insert(-2, color);
480 	if (!m_Doc->PageColors.contains("White"))
481 	{
482 		m_Doc->PageColors.insert("White", ScColor(0, 0, 0, 0));
483 		importedColors.append("White");
484 	}
485 	color.name = "White";
486 	XarColorMap.insert(-3, color);
487 	if (!m_Doc->PageColors.contains("Red"))
488 	{
489 		m_Doc->PageColors.insert("Red", ScColor(255, 0, 0));
490 		importedColors.append("Red");
491 	}
492 	color.name = "Red";
493 	XarColorMap.insert(-4, color);
494 	if (!m_Doc->PageColors.contains("Green"))
495 	{
496 		m_Doc->PageColors.insert("Green", ScColor(255, 0, 255, 0));
497 		importedColors.append("Green");
498 	}
499 	color.name = "Green";
500 	XarColorMap.insert(-5, color);
501 	if (!m_Doc->PageColors.contains("Blue"))
502 	{
503 		m_Doc->PageColors.insert("Blue", ScColor(0, 0, 255));
504 		importedColors.append("Blue");
505 	}
506 	color.name = "Blue";
507 	XarColorMap.insert(-6, color);
508 	if (!m_Doc->PageColors.contains("Cyan"))
509 	{
510 		m_Doc->PageColors.insert("Cyan", ScColor(255, 0, 0, 0));
511 		importedColors.append("Cyan");
512 	}
513 	color.name = "Cyan";
514 	XarColorMap.insert(-7, color);
515 	if (!m_Doc->PageColors.contains("Magenta"))
516 	{
517 		m_Doc->PageColors.insert("Magenta", ScColor(0, 255, 0, 0));
518 		importedColors.append("Magenta");
519 	}
520 	color.name = "Magenta";
521 	XarColorMap.insert(-8, color);
522 	if (!m_Doc->PageColors.contains("Yellow"))
523 	{
524 		m_Doc->PageColors.insert("Yellow", ScColor(0, 0, 255, 0));
525 		importedColors.append("Yellow");
526 	}
527 	color.name = "Yellow";
528 	XarColorMap.insert(-9, color);
529 	ignoreableTags << 2 << 40 << 41 << 43 << 46 << 47 << 53 << 61 << 62 << 63 << 80 << 90 << 91 << 92 << 93 << 111;
530 //	ignoreableTags << 2150 << 2151 << 2205 << 2900 << 2901;
531 	ignoreableTags << 2205 << 2900 << 2901;
532 	ignoreableTags << 4031 << 4081 << 4082 << 4083 << 4087 << 4102 << 4103 << 4104 << 4105 << 4106 << 4107 << 4108 << 4109;
533 	ignoreableTags << 4110 << 4111 << 4112 << 4113 << 4114 << 4115 << 4116 << 4124;
534 	if (progressDialog)
535 	{
536 		progressDialog->setOverallProgress(2);
537 		progressDialog->setLabel("GI", tr("Generating Items"));
538 		qApp->processEvents();
539 	}
540 	QFile f(fn);
541 	if (f.open(QIODevice::ReadOnly))
542 	{
543 		int fSize = (int) f.size();
544 		if (progressDialog)
545 		{
546 			progressDialog->setTotalSteps("GI", fSize);
547 			qApp->processEvents();
548 		}
549 		QDataStream ts(&f);
550 		ts.setByteOrder(QDataStream::LittleEndian);
551 		parseXar(ts);
552 		if (Elements.count() == 0)
553 		{
554 			if (importedColors.count() != 0)
555 			{
556 				for (int cd = 0; cd < importedColors.count(); cd++)
557 				{
558 					m_Doc->PageColors.remove(importedColors[cd]);
559 				}
560 			}
561 			if (importedPatterns.count() != 0)
562 			{
563 				for (int cd = 0; cd < importedPatterns.count(); cd++)
564 				{
565 					m_Doc->docPatterns.remove(importedPatterns[cd]);
566 				}
567 			}
568 		}
569 		f.close();
570 	}
571 	if (progressDialog)
572 		progressDialog->close();
573 	return true;
574 }
575 
parseXar(QDataStream & ts)576 void XarPlug::parseXar(QDataStream &ts)
577 {
578 	XarStyle *gc = new XarStyle;
579 	m_gc.push( gc );
580 	quint32 id;
581 	ts >> id;
582 	if (id != 0x41524158)
583 		return;
584 	ts >> id;
585 	if (id != 0x0A0DA3A3)
586 		return;
587 	recordCounter = 0;
588 	while (!ts.atEnd())
589 	{
590 		quint32 opCode, dataLen;
591 		ts >> opCode;
592 		ts >> dataLen;
593 		recordCounter++;
594 		if (opCode == 30)
595 		{
596 			ts.skipRawData(dataLen);
597 			QtIOCompressor compressor(ts.device(), 6, 1);
598 			compressor.setStreamFormat(QtIOCompressor::RawZipFormat);
599 			compressor.open(QIODevice::ReadOnly);
600 			QDataStream tsc(&compressor);
601 			tsc.setByteOrder(QDataStream::LittleEndian);
602 			while (!tsc.atEnd())
603 			{
604 				tsc >> opCode;
605 				tsc >> dataLen;
606 				recordCounter++;
607 				if (opCode == 31)
608 				{
609 					tsc.skipRawData(dataLen);
610 					break;
611 				}
612 				handleTags(opCode, dataLen, tsc);
613 			}
614 			ts.skipRawData(dataLen+1);
615 		}
616 		else
617 			handleTags(opCode, dataLen, ts);
618 		if (progressDialog)
619 		{
620 			progressDialog->setProgress("GI", ts.device()->pos());
621 			qApp->processEvents();
622 		}
623 	}
624 }
625 
handleTags(quint32 tag,quint32 dataLen,QDataStream & ts)626 void XarPlug::handleTags(quint32 tag, quint32 dataLen, QDataStream &ts)
627 {
628 	XarStyle *gc = m_gc.top();
629 	bool closed = false;
630 	if (ignoreableTags.contains(tag))
631 	{
632 		ts.skipRawData(dataLen);
633 		return;
634 	}
635 //	qDebug() << QString("OpCode: %1 Data Len %2").arg(tag).arg(dataLen, 8, 16, QLatin1Char('0'));
636 	if (tag == 0)
637 	{
638 		popGraphicContext();
639 //		delete( m_gc.pop() );
640 //		qDebug() << "Stack dropped to" << m_gc.count();
641 	}
642 	else if (tag == 1)
643 	{
644 		addGraphicContext();
645 //		qDebug() << "Stack pushed to" << m_gc.count();
646 	}
647 	else if (tag == 10)
648 		addToAtomic(dataLen, ts);
649 	else if (tag == 45)
650 		handleSpreadInfo(ts);
651 	else if (tag == 44)
652 	{
653 		handleFirstPage(ts);
654 		ts.skipRawData(dataLen);
655 	}
656 	else if (tag == 4131)
657 	{
658 		handlePage(ts);
659 		ts.skipRawData(dataLen);
660 	}
661 	else if (tag == 48)
662 		handleLayerInfo(ts);
663 	else if (tag == 50)
664 		handleColorRGB(ts);
665 	else if (tag == 51)
666 		handleComplexColor(ts);
667 /*	else if ((tag == 61) || (tag == 62) || (tag == 63))
668 	{
669 		QImage image;
670 		QByteArray data;
671 		data.resize(dataLen);
672 		ts.readRawData(data.data(), dataLen);
673 		image.loadFromData(data);
674 		int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, image.width(), image.height(), 0, m_Doc->itemToolPrefs().imageFillColor, CommonStrings::None);
675 		PageItem *ite = m_Doc->Items->at(z);
676 		ite->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_xar_XXXXXX.png");
677 		ite->tempImageFile->open();
678 		QString fileName = getLongPathName(ite->tempImageFile->fileName());
679 		ite->tempImageFile->close();
680 		ite->isInlineImage = true;
681 		image.save(fileName, "PNG");
682 		ite->moveBy(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
683 		m_Doc->LoadPict(fileName, z);
684 		ite->setImageScalingMode(false, false);
685 		ite->ClipEdited = true;
686 		ite->FrameType = 3;
687 		ite->setFillShade(CurrFillShade);
688 		ite->setLineShade(CurrStrokeShade);
689 		FPoint wh = getMaxClipF(&ite->PoLine);
690 		ite->setWidthHeight(wh.x(),wh.y());
691 		ite->setTextFlowMode(PageItem::TextFlowDisabled);
692 		m_Doc->AdjustItemSize(ite);
693 		ite->OldB2 = ite->width();
694 		ite->OldH2 = ite->height();
695 		ite->updateClip();
696 		Elements.append(ite);
697 	} */
698 	else if ((tag == 67) || (tag == 68) || (tag == 71))
699 		defineBitmap(ts, dataLen, tag);
700 	else if (tag == 104)
701 		createGroupItem();
702 	else if (tag == 112)
703 		createGuideLine(ts);
704 	else if (tag == 114)
705 	{
706 		closed = handlePathRel(ts, dataLen);
707 		if (closed)
708 			createPolygonItem(1);
709 		else
710 			createPolylineItem(1);
711 	}
712 	else if (tag == 115)
713 	{
714 		closed = handlePathRel(ts, dataLen);
715 		if (closed)
716 			createPolygonItem(0);
717 		else
718 			createPolylineItem(0);
719 	}
720 	else if (tag == 116)
721 	{
722 		closed = handlePathRel(ts, dataLen);
723 		if (closed)
724 			createPolygonItem(2);
725 		else
726 			createPolylineItem(2);
727 	}
728 //	else if (tag == 118)
729 //		createSimilarItem(ts);
730 	else if (tag == 150)
731 		handleFlatFill(ts);
732 	else if (tag == 151)
733 		handleLineColor(ts);
734 	else if (tag == 152)
735 		handleLineWidth(ts);
736 	else if (tag == 153)
737 		handleSimpleGradient(ts, dataLen, true);
738 	else if (tag == 154)
739 		handleSimpleGradient(ts, dataLen, false);
740 	else if (tag == 155)
741 		handleSimpleGradientElliptical(ts, dataLen);
742 	else if (tag == 157)
743 		handleBitmapFill(ts, dataLen);
744 	else if (tag == 158)
745 		handleContoneBitmapFill(ts, dataLen);
746 	else if (tag == 166)
747 		handleFlatFillTransparency(ts);
748 	else if (tag == 167)
749 		handleSimpleGradientTransparency(ts, dataLen, true);
750 	else if (tag == 168)
751 		handleSimpleGradientTransparency(ts, dataLen, false);
752 	else if (tag == 169)
753 		handleEllipticalGradientTransparency(ts, dataLen);
754 	else if (tag == 171)
755 		handleBitmapTransparency(ts, dataLen);
756 	else if (tag == 173)
757 		handleFlatLineTransparency(ts);
758 	else if ((tag == 174) || (tag == 175))
759 		handleLineEnd(ts);
760 	else if (tag == 176)
761 		handleLineJoin(ts);
762 	else if (tag == 178)
763 		handleFillRule(ts);
764 	else if (tag == 190)
765 		gc->FillCol = CommonStrings::None;
766 	else if (tag == 191)
767 		gc->FillCol = "Black";
768 	else if (tag == 192)
769 		gc->FillCol = "White";
770 	else if (tag == 193)
771 		gc->StrokeCol = CommonStrings::None;
772 	else if (tag == 194)
773 		gc->StrokeCol = "Black";
774 	else if (tag == 195)
775 		gc->StrokeCol = "White";
776 	else if (tag == 198)
777 		handleBitmap(ts);
778 	else if (tag == 200)
779 		handleSimpleDiamondGradient(ts, dataLen);
780 	else if (tag == 204)
781 		handleFourColorGradient(ts);
782 	else if (tag == 1000)
783 		createRectangleItem(ts, true);
784 	else if (tag == 1100)
785 		createRectangleItem(ts);
786 	else if (tag == 1901)
787 		handleQuickShapeSimple(ts, dataLen);
788 	else if ((tag == 2000) || (tag == 2001))
789 		defineTextFontFace(ts, dataLen);
790 	else if (tag == 2100)
791 		startSimpleText(ts, dataLen);
792 	else if (tag == 2101)
793 		startComplexText(ts, dataLen);
794 	else if (tag == 2110)
795 		startSimplePathText(ts, dataLen, 0);
796 	else if (tag == 2111)
797 		startSimplePathText(ts, dataLen, 1);
798 	else if (tag == 2112)
799 		startSimplePathText(ts, dataLen, 2);
800 	else if (tag == 2113)
801 		startSimplePathText(ts, dataLen, 3);
802 	else if (tag == 2114)
803 		startComplexPathText(ts, dataLen, 0);
804 	else if (tag == 2115)
805 		startComplexPathText(ts, dataLen, 1);
806 	else if (tag == 2116)
807 		startComplexPathText(ts, dataLen, 2);
808 	else if (tag == 2117)
809 		startComplexPathText(ts, dataLen, 3);
810 	else if (tag == 2150)
811 		handleTextWrap(ts);
812 	else if (tag == 2151)
813 		handleTextIndent(ts);
814 	else if (tag == 2200)
815 		startTextLine();
816 	else if (tag == 2201)
817 		handleTextString(ts, dataLen);
818 	else if (tag == 2202)
819 		handleTextChar(ts);
820 	else if (tag == 2203)
821 		endTextLine();
822 	else if (tag == 2204)
823 		handleTextKerning(ts);
824 	else if (tag == 2206)
825 		handleLineInfo(ts);
826 	else if ((tag == 2902) || (tag == 2903) || (tag == 2904))
827 		handleTextAlignment(tag);
828 	else if (tag == 2906)
829 		handleTextFontSize(ts);
830 	else if (tag == 2907)
831 		handleTextFont(ts);
832 	else if (tag == 2908)
833 	{
834 		gc->FontBold = true;
835 		if (textLines.count() > 0)
836 		{
837 			if (textLines.last().textData.count() > 0)
838 				textLines.last().textData.last().FontBold = gc->FontBold;
839 		}
840 	}
841 	else if (tag == 2909)
842 	{
843 		gc->FontBold = false;
844 		if (textLines.count() > 0)
845 		{
846 			if (textLines.last().textData.count() > 0)
847 				textLines.last().textData.last().FontBold = gc->FontBold;
848 		}
849 	}
850 	else if (tag == 2910)
851 	{
852 		gc->FontItalic = true;
853 		if (textLines.count() > 0)
854 		{
855 			if (textLines.last().textData.count() > 0)
856 				textLines.last().textData.last().FontItalic = gc->FontItalic;
857 		}
858 	}
859 	else if (tag == 2911)
860 	{
861 		gc->FontItalic = false;
862 		if (textLines.count() > 0)
863 		{
864 			if (textLines.last().textData.count() > 0)
865 				textLines.last().textData.last().FontItalic = gc->FontItalic;
866 		}
867 	}
868 	else if (tag == 2912)
869 	{
870 		gc->FontUnderline = true;
871 		if (textLines.count() > 0)
872 		{
873 			if (textLines.last().textData.count() > 0)
874 				textLines.last().textData.last().FontUnderline = gc->FontUnderline;
875 		}
876 	}
877 	else if (tag == 2913)
878 	{
879 		gc->FontUnderline = false;
880 		if (textLines.count() > 0)
881 		{
882 			if (textLines.last().textData.count() > 0)
883 				textLines.last().textData.last().FontUnderline = gc->FontUnderline;
884 		}
885 	}
886 	else if (tag == 2918)
887 		handleTextTracking(ts);
888 	else if (tag == 2919)
889 		handleTextAspectRatio(ts);
890 	else if (tag == 2920)
891 		handleTextBaseline(ts);
892 	else if (tag == 4075)
893 		handleMultiGradient(ts, true);
894 	else if (tag == 4076)
895 		handleMultiGradient(ts, false);
896 	else if (tag == 4077)
897 		handleMultiGradientElliptical(ts);
898 	else if (tag == 4079)
899 		handleBrushItem(ts);
900 	else if (tag == 4080)
901 		createBrushItem(ts);
902 	else if (tag == 4084)
903 		createClipItem();
904 	else if (tag == 4085)
905 		finishClip();
906 	else if (tag == 4088)
907 		handleMultiDiamondGradient(ts);
908 	else if (tag == 4121)
909 		handleSimpleGradientSkewed(ts, dataLen);
910 	else if (tag == 4122)
911 		handleMultiGradientSkewed(ts);
912 	else if (tag == 4123)
913 		handleSimpleGradientTransparencySkewed(ts, dataLen);
914 	else
915 	{
916 /*		if (m_gc.count() > 3)
917 		{
918 		//	if ((tag > 1999) && (tag < 3000))
919 				qDebug() << QString("Unhandled OpCode: %1 Data Len %2").arg(tag).arg(dataLen, 8, 16, QLatin1Char('0'));
920 		} */
921 	//	qDebug() << QString("Unhandled OpCode: %1 Data Len %2").arg(tag).arg(dataLen, 8, 16, QLatin1Char('0'));
922 		ts.skipRawData(dataLen);
923 	}
924 }
925 
createGuideLine(QDataStream & ts)926 void XarPlug::createGuideLine(QDataStream &ts)
927 {
928 	quint8 flags;
929 	qint32 position;
930 	ts >> flags;
931 	ts >> position;
932 	double gpos = position / 1000.0;
933 	if (importerFlags & LoadSavePlugin::lfCreateDoc)
934 	{
935 		if (flags == 1)
936 			m_Doc->currentPage()->guides.addHorizontal(docHeight - gpos, GuideManagerCore::Standard);
937 		else
938 			m_Doc->currentPage()->guides.addVertical(gpos, GuideManagerCore::Standard);
939 	}
940 }
941 
handleTextFontSize(QDataStream & ts)942 void XarPlug::handleTextFontSize(QDataStream &ts)
943 {
944 	quint32 size;
945 	ts >> size;
946 	XarStyle *gc = m_gc.top();
947 	gc->FontSize = size / 1000.0;
948 	if (textLines.count() > 0)
949 	{
950 		if (textLines.last().textData.count() > 0)
951 			textLines.last().textData.last().FontSize = gc->FontSize;
952 	}
953 //	qDebug() << "Font Size" << gc->FontSize;
954 }
955 
defineTextFontFace(QDataStream & ts,quint32 dataLen)956 void XarPlug::defineTextFontFace(QDataStream &ts, quint32 dataLen)
957 {
958 	quint32 bytesRead = 0;
959 	quint16 charC = 0;
960 	ts >> charC;
961 	bytesRead += 2;
962 	QString FullFontName = "";
963 	while (charC != 0)
964 	{
965 		FullFontName += QChar(charC);
966 		ts >> charC;
967 		bytesRead += 2;
968 	}
969 	charC = 0;
970 	ts >> charC;
971 	bytesRead += 2;
972 	QString TypeFaceName = "";
973 	while (charC != 0)
974 	{
975 		TypeFaceName += QChar(charC);
976 		ts >> charC;
977 		bytesRead += 2;
978 	}
979 	ts.skipRawData(dataLen - bytesRead);
980 	fontRef.insert(recordCounter, TypeFaceName);
981 //	qDebug() << "Define Font" << FullFontName << TypeFaceName;
982 }
983 
handleTextFont(QDataStream & ts)984 void XarPlug::handleTextFont(QDataStream &ts)
985 {
986 	XarStyle *gc = m_gc.top();
987 	qint32 val;
988 	ts >> val;
989 	if (val > -1)
990 	{
991 		if (fontRef.contains(val))
992 			gc->FontFamily = fontRef[val];
993 		if (textLines.count() > 0)
994 		{
995 			if (textLines.last().textData.count() > 0)
996 				textLines.last().textData.last().FontFamily = gc->FontFamily;
997 		}
998 	}
999 //	qDebug() << "Using Font" << gc->FontFamily;
1000 }
1001 
handleTextString(QDataStream & ts,quint32 dataLen)1002 void XarPlug::handleTextString(QDataStream &ts, quint32 dataLen)
1003 {
1004 	quint32 l = dataLen / 2;
1005 	quint16 val;
1006 	XarStyle *gc = m_gc.top();
1007 	XarText text;
1008 	text.itemText = "";
1009 	QString iText = "";
1010 	for (quint32 a = 0; a < l; a++)
1011 	{
1012 		ts >> val;
1013 		iText += QChar(val);
1014 	}
1015 	text.FontFamily = gc->FontFamily;
1016 	text.FontSize = gc->FontSize;
1017 	text.FontStretch = gc->FontStretch;
1018 	text.FontKerning = gc->FontKerning;
1019 	text.FontBold = gc->FontBold;
1020 	text.FontUnderline = gc->FontUnderline;
1021 	text.FontItalic = gc->FontItalic;
1022 	text.FillCol = gc->FillCol;
1023 	text.FillOpacity = gc->FillOpacity;
1024 	text.FillBlend = gc->FillBlend;
1025 	text.StrokeOpacity = gc->StrokeOpacity;
1026 	text.LWidth = gc->LWidth;
1027 	text.StrokeCol = gc->StrokeCol;
1028 	text.PLineJoin = gc->PLineJoin;
1029 	text.PLineEnd = gc->PLineEnd;
1030 	text.fillPattern = gc->fillPattern;
1031 	text.patternScaleX = gc->patternScaleX;
1032 	text.patternScaleY = gc->patternScaleY;
1033 	text.patternOffsetX = gc->patternOffsetX;
1034 	text.patternOffsetY = gc->patternOffsetY;
1035 	text.patternRotation = gc->patternRotation;
1036 	text.patternSkewX = gc->patternSkewX;
1037 	text.patternSkewY = gc->patternSkewY;
1038 	text.FillGradientType = gc->FillGradientType;
1039 	text.FillGradient = gc->FillGradient;
1040 	text.GradFillX1 = gc->GradFillX1;
1041 	text.GradFillY1 = gc->GradFillY1;
1042 	text.GradFillX2 = gc->GradFillX2;
1043 	text.GradFillY2 = gc->GradFillY2;
1044 	text.GrControl1 = gc->GrControl1;
1045 	text.GrControl2 = gc->GrControl2;
1046 	text.GrControl3 = gc->GrControl3;
1047 	text.GrControl4 = gc->GrControl4;
1048 	text.GrControl5 = gc->GrControl5;
1049 	text.GrScale = gc->GrScale;
1050 	text.GrSkew = gc->GrSkew;
1051 	text.GrColorP1 = gc->GrColorP1;
1052 	text.GrColorP2 = gc->GrColorP2;
1053 	text.GrColorP3 = gc->GrColorP3;
1054 	text.GrColorP4 = gc->GrColorP4;
1055 	text.GradMask = gc->GradMask;
1056 	text.MaskGradient = gc->MaskGradient;
1057 	text.GradMaskX1 = gc->GradMaskX1;
1058 	text.GradMaskY1 = gc->GradMaskY1;
1059 	text.GradMaskX2 = gc->GradMaskX2;
1060 	text.GradMaskY2 = gc->GradMaskY2;
1061 	text.GradMaskScale = gc->GradMaskScale;
1062 	text.GradMaskSkew = gc->GradMaskSkew;
1063 	text.patternMaskScaleX = gc->patternMaskScaleX;
1064 	text.patternMaskScaleY = gc->patternMaskScaleY;
1065 	text.patternMaskOffsetX = gc->patternMaskOffsetX;
1066 	text.patternMaskOffsetY = gc->patternMaskOffsetY;
1067 	text.patternMaskRotation = gc->patternMaskRotation;
1068 	text.patternMaskSkewX = gc->patternMaskSkewX;
1069 	text.patternMaskSkewY = gc->patternMaskSkewY;
1070 	text.maskPattern = gc->maskPattern;
1071 	QStringList txtList = iText.split(QChar(0x0D));
1072 	for (int b = 0; b < txtList.count(); b++)
1073 	{
1074 		text.itemText = txtList[b];
1075 		if (b >= 1)
1076 		{
1077 			XarTextLine lin;
1078 			textLines.append(lin);
1079 		}
1080 		textLines.last().textData.append(text);
1081 	}
1082 //	qDebug() << "String" << iText;
1083 }
1084 
handleTextChar(QDataStream & ts)1085 void XarPlug::handleTextChar(QDataStream &ts)
1086 {
1087 	quint16 val;
1088 	ts >> val;
1089 	XarStyle *gc = m_gc.top();
1090 	XarText text;
1091 	text.itemText = QChar(val);
1092 	text.FontFamily = gc->FontFamily;
1093 	text.FontSize = gc->FontSize;
1094 	text.FontStretch = gc->FontStretch;
1095 	text.FontKerning = gc->FontKerning;
1096 	text.FontBold = gc->FontBold;
1097 	text.FontUnderline = gc->FontUnderline;
1098 	text.FontItalic = gc->FontItalic;
1099 	text.FillCol = gc->FillCol;
1100 	text.FillOpacity = gc->FillOpacity;
1101 	text.FillBlend = gc->FillBlend;
1102 	text.StrokeOpacity = gc->StrokeOpacity;
1103 	text.LWidth = gc->LWidth;
1104 	text.StrokeCol = gc->StrokeCol;
1105 	text.PLineJoin = gc->PLineJoin;
1106 	text.PLineEnd = gc->PLineEnd;
1107 	text.fillPattern = gc->fillPattern;
1108 	text.patternScaleX = gc->patternScaleX;
1109 	text.patternScaleY = gc->patternScaleY;
1110 	text.patternOffsetX = gc->patternOffsetX;
1111 	text.patternOffsetY = gc->patternOffsetY;
1112 	text.patternRotation = gc->patternRotation;
1113 	text.patternSkewX = gc->patternSkewX;
1114 	text.patternSkewY = gc->patternSkewY;
1115 	text.FillGradientType = gc->FillGradientType;
1116 	text.FillGradient = gc->FillGradient;
1117 	text.GradFillX1 = gc->GradFillX1;
1118 	text.GradFillY1 = gc->GradFillY1;
1119 	text.GradFillX2 = gc->GradFillX2;
1120 	text.GradFillY2 = gc->GradFillY2;
1121 	text.GrControl1 = gc->GrControl1;
1122 	text.GrControl2 = gc->GrControl2;
1123 	text.GrControl3 = gc->GrControl3;
1124 	text.GrControl4 = gc->GrControl4;
1125 	text.GrControl5 = gc->GrControl5;
1126 	text.GrScale = gc->GrScale;
1127 	text.GrSkew = gc->GrSkew;
1128 	text.GrColorP1 = gc->GrColorP1;
1129 	text.GrColorP2 = gc->GrColorP2;
1130 	text.GrColorP3 = gc->GrColorP3;
1131 	text.GrColorP4 = gc->GrColorP4;
1132 	text.GradMask = gc->GradMask;
1133 	text.MaskGradient = gc->MaskGradient;
1134 	text.GradMaskX1 = gc->GradMaskX1;
1135 	text.GradMaskY1 = gc->GradMaskY1;
1136 	text.GradMaskX2 = gc->GradMaskX2;
1137 	text.GradMaskY2 = gc->GradMaskY2;
1138 	text.GradMaskScale = gc->GradMaskScale;
1139 	text.GradMaskSkew = gc->GradMaskSkew;
1140 	text.patternMaskScaleX = gc->patternMaskScaleX;
1141 	text.patternMaskScaleY = gc->patternMaskScaleY;
1142 	text.patternMaskOffsetX = gc->patternMaskOffsetX;
1143 	text.patternMaskOffsetY = gc->patternMaskOffsetY;
1144 	text.patternMaskRotation = gc->patternMaskRotation;
1145 	text.patternMaskSkewX = gc->patternMaskSkewX;
1146 	text.patternMaskSkewY = gc->patternMaskSkewY;
1147 	text.maskPattern = gc->maskPattern;
1148 	textLines.last().textData.append(text);
1149 //	qDebug() << "Char" << QChar(val);
1150 }
1151 
handleTextWrap(QDataStream & ts)1152 void XarPlug::handleTextWrap(QDataStream &ts)
1153 {
1154 	quint8 flags;
1155 	qint32 width;
1156 	ts >> width >> flags;
1157 	XarStyle *gc = m_gc.top();
1158 	gc->LineWidth2 = width / 1000.0;
1159 //	qDebug() << "Line Width" << gc->LineWidth;
1160 }
1161 
handleTextIndent(QDataStream & ts)1162 void XarPlug::handleTextIndent(QDataStream &ts)
1163 {
1164 	qint32 left, right;
1165 	ts >> left >> right;
1166 	XarStyle *gc = m_gc.top();
1167 	gc->TextLeftIndent = left / 1000.0;
1168 }
1169 
handleLineInfo(QDataStream & ts)1170 void XarPlug::handleLineInfo(QDataStream &ts)
1171 {
1172 	qint32 width, height, spacing;
1173 	ts >> width >> height >> spacing;
1174 	XarStyle *gc = m_gc.top();
1175 	gc->LineHeight = -spacing / 1000.0;
1176 	gc->LineWidth = width / 1000.0;
1177 //	qDebug() << "Line Width old" << gc->LineWidth;
1178 }
1179 
handleTextAlignment(quint32 tag)1180 void XarPlug::handleTextAlignment(quint32 tag)
1181 {
1182 	XarStyle *gc = m_gc.top();
1183 	if (tag == 2902)
1184 		gc->TextAlignment = 0;
1185 	else if (tag == 2903)
1186 		gc->TextAlignment = 1;
1187 	else if (tag == 2904)
1188 		gc->TextAlignment = 2;
1189 //	qDebug() << "Line Alignment" << gc->TextAlignment;
1190 }
1191 
handleTextTracking(QDataStream & ts)1192 void XarPlug::handleTextTracking(QDataStream &ts)
1193 {
1194 	qint32 val;
1195 	ts >> val;
1196 //	qDebug() << "Tracking" << val;
1197 }
1198 
handleTextKerning(QDataStream & ts)1199 void XarPlug::handleTextKerning(QDataStream &ts)
1200 {
1201 	qint32 valX, valY;
1202 	ts >> valX >> valY;
1203 	XarStyle *gc = m_gc.top();
1204 	gc->FontKerning = valX / 1000.0;
1205 	if (textLines.count() > 0)
1206 	{
1207 		if (textLines.last().textData.count() > 0)
1208 			textLines.last().textData.last().FontKerning = gc->FontKerning;
1209 	}
1210 //	qDebug() << "Kerning" << valX / 1000.0 << valY / 1000.0;
1211 }
1212 
handleTextAspectRatio(QDataStream & ts)1213 void XarPlug::handleTextAspectRatio(QDataStream &ts)
1214 {
1215 	quint32 val;
1216 	ts >> val;
1217 	double scaleX = decodeFixed16(val);
1218 	XarStyle *gc = m_gc.top();
1219 	gc->FontStretch = scaleX;
1220 	if (textLines.count() > 0)
1221 	{
1222 		if (textLines.last().textData.count() > 0)
1223 			textLines.last().textData.last().FontStretch = gc->FontStretch;
1224 	}
1225 //	qDebug() << "Aspect Ratio" << scaleX;
1226 }
1227 
handleTextBaseline(QDataStream & ts)1228 void XarPlug::handleTextBaseline(QDataStream &ts)
1229 {
1230 	qint32 val;
1231 	ts >> val;
1232 	TextY += val / 1000.0;
1233 }
1234 
startTextLine()1235 void XarPlug::startTextLine()
1236 {
1237 	inTextLine = true;
1238 	XarTextLine lin;
1239 	textLines.append(lin);
1240 //	qDebug() << "Start Line";
1241 }
1242 
endTextLine()1243 void XarPlug::endTextLine()
1244 {
1245 	XarStyle *gc = m_gc.top();
1246 //	TextY += gc->LineHeight;
1247 	QPainterPath painterPath;
1248 	double xpos = 0;
1249 	if (isPathText)
1250 	{
1251 		if (!textPath.empty())
1252 		{
1253 			QPainterPath guidePath = textPath.toQPainterPath(false);
1254 			for (int a = 0; a < textLines.count(); a++)
1255 			{
1256 				XarTextLine txLin = textLines[a];
1257 				TextY += gc->LineHeight;
1258 				xpos = 0;
1259 				for (int c = 0; c < txLin.textData.count(); c++)
1260 				{
1261 					XarText txDat = txLin.textData[c];
1262 					xpos += txDat.FontKerning * (txDat.FontSize  * 72.0 / 96.0);
1263 					txDat.FontSize *= 10;
1264 					QFont textFont = QFont(txDat.FontFamily, txDat.FontSize);
1265 					if (txDat.FontSize >= 1)
1266 						textFont.setPixelSize(txDat.FontSize);
1267 					else
1268 						textFont.setPointSizeF(txDat.FontSize * 72.0 / 96.0);
1269 					textFont.setBold(txDat.FontBold);
1270 					textFont.setItalic(txDat.FontItalic);
1271 					textFont.setUnderline(txDat.FontUnderline);
1272 					textFont.setStretch(txDat.FontStretch * 100);
1273 					for (int b = 0; b < txDat.itemText.count(); b++)
1274 					{
1275 						painterPath = QPainterPath();
1276 						QString ch = txDat.itemText.at(b);
1277 						painterPath.addText( 0, 0, textFont, ch);
1278 						QTransform txS;
1279 						txS.scale(0.1, 0.1);
1280 						painterPath = txS.map(painterPath);
1281 						double currPerc;
1282 						currPerc = guidePath.percentAtLength(xpos);
1283 						if ((pathTextType == 2) || (pathTextType == 3))
1284 							currPerc = guidePath.percentAtLength(guidePath.length() - xpos);
1285 						double currAngle = guidePath.angleAtPercent(currPerc);
1286 						if (currAngle <= 180.0)
1287 							currAngle *= -1.0;
1288 						else
1289 							currAngle = 360.0 - currAngle;
1290 						QPointF currPoint = guidePath.pointAtPercent(currPerc);
1291 						QTransform pre;
1292 						if (pathTextType > 0)
1293 						{
1294 							if (pathTextType == 1)
1295 								pre.scale(-1.0, 1.0);
1296 							else if (pathTextType == 2)
1297 								pre.scale(1.0, -1.0);
1298 							else if (pathTextType == 3)
1299 								pre.scale(-1.0, -1.0);
1300 							painterPath = pre.map(painterPath);
1301 						}
1302 						QTransform mat;
1303 						mat.translate(currPoint.x(), currPoint.y());
1304 						mat.rotate(currAngle);
1305 						mat.rotate(textRotation);
1306 						double tSkew = 0;
1307 						if (textSkew == M_PI / 2.0)
1308 							tSkew = 1;
1309 						else if (textSkew == M_PI)
1310 							tSkew = 0;
1311 						else if (textSkew == M_PI + M_PI / 2.0)
1312 							tSkew = -1;
1313 						else if (textSkew == 2.0 * M_PI)
1314 							tSkew = 0;
1315 						else
1316 						tSkew = tan(textSkew);
1317 						mat.shear(-tSkew, 0);
1318 						painterPath = mat.map(painterPath);
1319 						painterPath = textMatrix.map(painterPath);
1320 						xpos += QFontMetricsF(textFont).horizontalAdvance(ch) / 10.0;
1321 						Coords.resize(0);
1322 						Coords.fromQPainterPath(painterPath);
1323 						QPointF np = textMatrix.map(QPointF(TextX, TextY));
1324 						Coords.translate(np.x(), np.y());
1325 						if (!Coords.empty())
1326 						{
1327 							int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, txDat.FillCol, CommonStrings::None);
1328 							PageItem *item = m_Doc->Items->at(z);
1329 							item->PoLine = Coords.copy();
1330 							item->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
1331 							item->ClipEdited = true;
1332 							item->FrameType = 3;
1333 							FPoint wh = getMaxClipF(&item->PoLine);
1334 							item->setWidthHeight(wh.x(),wh.y());
1335 							item->setTextFlowMode(PageItem::TextFlowDisabled);
1336 							m_Doc->adjustItemSize(item);
1337 							Elements.append(item);
1338 							item->setFillColor(txDat.FillCol);
1339 							item->setFillTransparency(txDat.FillOpacity);
1340 							item->setFillBlendmode(txDat.FillBlend);
1341 							item->setLineTransparency(txDat.StrokeOpacity);
1342 							item->setLineWidth(txDat.LWidth);
1343 							item->setLineColor(txDat.StrokeCol);
1344 							item->setLineJoin(txDat.PLineJoin);
1345 							item->setLineEnd(txDat.PLineEnd);
1346 							if (!txDat.fillPattern.isEmpty())
1347 							{
1348 								item->setPattern(txDat.fillPattern);
1349 								item->setPatternTransform(txDat.patternScaleX, txDat.patternScaleY, txDat.patternOffsetX, txDat.patternOffsetY, txDat.patternRotation, txDat.patternSkewX, txDat.patternSkewY);
1350 								item->GrType = Gradient_Pattern;
1351 							}
1352 							if ((txDat.FillGradientType == Gradient_Linear) || (txDat.FillGradientType == Gradient_Radial))
1353 							{
1354 								item->GrType = txDat.FillGradientType;
1355 								item->fill_gradient = txDat.FillGradient;
1356 								item->setGradientVector(txDat.GradFillX1 - item->xPos(), txDat.GradFillY1 - item->yPos(), txDat.GradFillX2 - item->xPos(), txDat.GradFillY2 - item->yPos(), txDat.GradFillX1 - item->xPos(), txDat.GradFillY1 - item->yPos(), txDat.GrScale, txDat.GrSkew);
1357 							}
1358 							if (txDat.FillGradientType == Gradient_4Colors)
1359 							{
1360 								item->GrType = txDat.FillGradientType;
1361 								item->set4ColorGeometry(FPoint(0, 0), FPoint(item->width(), 0), FPoint(item->width(), item->height()), FPoint(0, item->height()));
1362 								item->set4ColorColors(txDat.GrColorP1, txDat.GrColorP2, txDat.GrColorP3, txDat.GrColorP4);
1363 							}
1364 							if (txDat.FillGradientType == Gradient_Diamond)
1365 							{
1366 								item->GrType = txDat.FillGradientType;
1367 								item->fill_gradient = txDat.FillGradient;
1368 								FPoint p = FPoint(item->xPos(), item->yPos());
1369 								item->setDiamondGeometry(txDat.GrControl1 - p, txDat.GrControl2 - p, txDat.GrControl3 - p, txDat.GrControl4 - p, txDat.GrControl5 - p);
1370 							}
1371 							if (txDat.GradMask > 0)
1372 							{
1373 								item->GrMask = txDat.GradMask;
1374 								if ((item->GrMask == 1) || (item->GrMask == 2))
1375 								{
1376 									item->mask_gradient = txDat.MaskGradient;
1377 									item->setMaskVector(txDat.GradMaskX1 - item->xPos(), txDat.GradMaskY1 - item->yPos(), txDat.GradMaskX2 - item->xPos(), txDat.GradMaskY2 - item->yPos(), txDat.GradMaskX1 - item->xPos(), txDat.GradMaskY1 - item->yPos(), txDat.GradMaskScale, txDat.GradMaskSkew);
1378 								}
1379 								else
1380 								{
1381 									item->setMaskTransform(txDat.patternMaskScaleX, txDat.patternMaskScaleY, txDat.patternMaskOffsetX, txDat.patternMaskOffsetY, txDat.patternMaskRotation, txDat.patternMaskSkewX, txDat.patternMaskSkewY);
1382 									item->setPatternMask(txDat.maskPattern);
1383 								}
1384 							}
1385 						}
1386 					}
1387 				}
1388 			}
1389 		}
1390 	}
1391 	else
1392 	{
1393 		for (int a = 0; a < textLines.count(); a++)
1394 		{
1395 			XarTextLine txLin = textLines[a];
1396 			TextY += gc->LineHeight;
1397 			xpos = 0;
1398 			for (int b = 0; b < txLin.textData.count(); b++)
1399 			{
1400 				XarText txDat = txLin.textData[b];
1401 				painterPath = QPainterPath();
1402 				QFont textFont = QFont(txDat.FontFamily, txDat.FontSize);
1403 				xpos += txDat.FontKerning * txDat.FontSize;
1404 				txDat.FontSize *= 10;
1405 				if (txDat.FontSize >= 1)
1406 					textFont.setPixelSize(txDat.FontSize);
1407 				else
1408 					textFont.setPointSizeF(txDat.FontSize * 72.0 / 96.0);
1409 				textFont.setBold(txDat.FontBold);
1410 				textFont.setItalic(txDat.FontItalic);
1411 				textFont.setUnderline(txDat.FontUnderline);
1412 				textFont.setStretch(txDat.FontStretch * 100);
1413 				painterPath.addText( 0, 0, textFont, txDat.itemText);
1414 				QTransform txS;
1415 				txS.scale(0.1, 0.1);
1416 				painterPath = txS.map(painterPath);
1417 				Coords.resize(0);
1418 				Coords.fromQPainterPath(painterPath);
1419 				Coords.translate(xpos, 0);
1420 				Coords.map(textMatrix);
1421 				Coords.translate(TextX, TextY);
1422 				if (gc->TextAlignment == 1)
1423 				{
1424 					double dist = (qMax(gc->LineWidth, gc->LineWidth2) - (QFontMetricsF(textFont).horizontalAdvance(txDat.itemText) / 10.0)) / 2.0;
1425 					Coords.translate(dist, 0);
1426 				}
1427 				else if (gc->TextAlignment == 2)
1428 				{
1429 					double dist = qMax(gc->LineWidth, gc->LineWidth2) - (QFontMetricsF(textFont).horizontalAdvance(txDat.itemText) / 10.0);
1430 					Coords.translate(dist, 0);
1431 				}
1432 				if (!Coords.empty())
1433 				{
1434 					int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, gc->FillCol, CommonStrings::None);
1435 					PageItem *item = m_Doc->Items->at(z);
1436 					item->PoLine = Coords.copy();
1437 					item->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
1438 					item->ClipEdited = true;
1439 					item->FrameType = 3;
1440 					FPoint wh = getMaxClipF(&item->PoLine);
1441 					item->setWidthHeight(wh.x(),wh.y());
1442 					item->setTextFlowMode(PageItem::TextFlowDisabled);
1443 					m_Doc->adjustItemSize(item);
1444 					Elements.append(item);
1445 					item->setFillColor(txDat.FillCol);
1446 					item->setFillTransparency(txDat.FillOpacity);
1447 					item->setFillBlendmode(txDat.FillBlend);
1448 					item->setLineTransparency(txDat.StrokeOpacity);
1449 					item->setLineWidth(txDat.LWidth);
1450 					item->setLineColor(txDat.StrokeCol);
1451 					item->setLineJoin(txDat.PLineJoin);
1452 					item->setLineEnd(txDat.PLineEnd);
1453 					if (!txDat.fillPattern.isEmpty())
1454 					{
1455 						item->setPattern(txDat.fillPattern);
1456 						item->setPatternTransform(txDat.patternScaleX, txDat.patternScaleY, txDat.patternOffsetX, txDat.patternOffsetY, txDat.patternRotation, txDat.patternSkewX, txDat.patternSkewY);
1457 						item->GrType = Gradient_Pattern;
1458 					}
1459 					if ((txDat.FillGradientType == Gradient_Linear) || (txDat.FillGradientType == Gradient_Radial))
1460 					{
1461 						item->GrType = txDat.FillGradientType;
1462 						item->fill_gradient = txDat.FillGradient;
1463 						item->setGradientVector(txDat.GradFillX1 - item->xPos(), txDat.GradFillY1 - item->yPos(), txDat.GradFillX2 - item->xPos(), txDat.GradFillY2 - item->yPos(), txDat.GradFillX1 - item->xPos(), txDat.GradFillY1 - item->yPos(), txDat.GrScale, txDat.GrSkew);
1464 					}
1465 					if (txDat.FillGradientType == Gradient_4Colors)
1466 					{
1467 						item->GrType = txDat.FillGradientType;
1468 						item->set4ColorGeometry(FPoint(0, 0), FPoint(item->width(), 0), FPoint(item->width(), item->height()), FPoint(0, item->height()));
1469 						item->set4ColorColors(txDat.GrColorP1, txDat.GrColorP2, txDat.GrColorP3, txDat.GrColorP4);
1470 					}
1471 					if (txDat.FillGradientType == Gradient_Diamond)
1472 					{
1473 						item->GrType = txDat.FillGradientType;
1474 						item->fill_gradient = txDat.FillGradient;
1475 						FPoint p = FPoint(item->xPos(), item->yPos());
1476 						item->setDiamondGeometry(txDat.GrControl1 - p, txDat.GrControl2 - p, txDat.GrControl3 - p, txDat.GrControl4 - p, txDat.GrControl5 - p);
1477 					}
1478 					if (txDat.GradMask > 0)
1479 					{
1480 						item->GrMask = txDat.GradMask;
1481 						if ((item->GrMask == GradMask_Linear) || (item->GrMask == GradMask_Radial))
1482 						{
1483 							item->mask_gradient = txDat.MaskGradient;
1484 							item->setMaskVector(txDat.GradMaskX1 - item->xPos(), txDat.GradMaskY1 - item->yPos(), txDat.GradMaskX2 - item->xPos(), txDat.GradMaskY2 - item->yPos(), txDat.GradMaskX1 - item->xPos(), txDat.GradMaskY1 - item->yPos(), txDat.GradMaskScale, txDat.GradMaskSkew);
1485 						}
1486 						else
1487 						{
1488 							item->setMaskTransform(txDat.patternMaskScaleX, txDat.patternMaskScaleY, txDat.patternMaskOffsetX, txDat.patternMaskOffsetY, txDat.patternMaskRotation, txDat.patternMaskSkewX, txDat.patternMaskSkewY);
1489 							item->setPatternMask(txDat.maskPattern);
1490 						}
1491 					}
1492 				}
1493 				xpos += QFontMetricsF(textFont).horizontalAdvance(txDat.itemText) / 10.0;
1494 			}
1495 		}
1496 	}
1497 	textLines.clear();
1498 	inTextLine = false;
1499 //	qDebug() << "End of Line, new Y-Pos" << TextY;
1500 }
1501 
startSimpleText(QDataStream & ts,quint32 dataLen)1502 void XarPlug::startSimpleText(QDataStream &ts, quint32 dataLen)
1503 {
1504 	quint32 flag;
1505 	double textX, textY;
1506 	readCoords(ts, textX, textY);
1507 	if (dataLen > 8)
1508 		ts >> flag;
1509 	TextX = textX;
1510 	TextY = docHeight - textY;
1511 	textRotation = 0;
1512 	textSkew = 0;
1513 	textMatrix = QTransform();
1514 	textLines.clear();
1515 	textPath.resize(0);
1516 	isPathText = false;
1517 	inTextBlock = true;
1518 	pathGcStackIndex = m_gc.count();
1519 //	qDebug() << "Simple Text at" << textX << docHeight - textY;
1520 }
1521 
startComplexText(QDataStream & ts,quint32 dataLen)1522 void XarPlug::startComplexText(QDataStream &ts, quint32 dataLen)
1523 {
1524 	quint32 flag;
1525 	quint32 scX, skX, skY, scY;
1526 	double transX, transY;
1527 	ts >> scX >> skX >> skY >> scY;
1528 	readCoords(ts, transX, transY);
1529 	double scaleX = decodeFixed16(scX);
1530 	double scaleY = decodeFixed16(scY);
1531 	double skewX = decodeFixed16(skX);
1532 	double skewY = decodeFixed16(skY);
1533 	if (dataLen > 24)
1534 		ts >> flag;
1535 	TextX = transX;
1536 	TextY = docHeight - transY;
1537 	textRotation = 0;
1538 	textSkew = 0;
1539 	textMatrix = QTransform(scaleX, -skewX, -skewY, scaleY, 0, 0);
1540 	textLines.clear();
1541 	textPath.resize(0);
1542 	isPathText = false;
1543 	inTextBlock = true;
1544 	pathGcStackIndex = m_gc.count();
1545 //	qDebug() << "Complex Text at" << transX << docHeight - transY << "Matrix" << scaleX << skewX << skewY << scaleY;
1546 }
1547 
startSimplePathText(QDataStream & ts,quint32 dataLen,int type)1548 void XarPlug::startSimplePathText(QDataStream &ts, quint32 dataLen, int type)
1549 {
1550 	quint32 flag;
1551 	double textX, textY;
1552 	readCoords(ts, textX, textY);
1553 	if (dataLen > 8)
1554 		ts >> flag;
1555 	TextX = 0;
1556 	TextY = 0;
1557 	textRotation = 0;
1558 	textSkew = 0;
1559 	textMatrix = QTransform();
1560 	textLines.clear();
1561 	textPath.resize(0);
1562 	isPathText = true;
1563 	inTextBlock = true;
1564 	recordPath = true;
1565 	pathTextType = type;
1566 	pathGcStackIndex = m_gc.count();
1567 //	qDebug() << "Path Text at" << textX << textY << "Type" << type;
1568 }
1569 
startComplexPathText(QDataStream & ts,quint32 dataLen,int type)1570 void XarPlug::startComplexPathText(QDataStream &ts, quint32 dataLen, int type)
1571 {
1572 	quint32 flag;
1573 	quint32 scX, skX, skY, scY;
1574 	double transX, transY;
1575 	ts >> scX >> skX >> skY >> scY;
1576 	readCoords(ts, transX, transY);
1577 	double scaleX = decodeFixed16(scX);
1578 	double scaleY = decodeFixed16(scY);
1579 	double skewX = decodeFixed16(skX);
1580 	double skewY = decodeFixed16(skY);
1581 	quint32 tRot, tSk;
1582 	ts >> tRot >> tSk;
1583 	textRotation = decodeFixed16(tRot);
1584 	textSkew = decodeFixed16(tSk);
1585 //	textSkew = (qint32)tSk;
1586 	if (dataLen > 32)
1587 		ts >> flag;
1588 	TextX = 0;
1589 	TextY = 0;
1590 	textMatrix = QTransform(scaleX, -skewX, -skewY, scaleY, 0, 0);
1591 	textLines.clear();
1592 	textPath.resize(0);
1593 	isPathText = true;
1594 	inTextBlock = true;
1595 	recordPath = true;
1596 	pathTextType = type;
1597 	pathGcStackIndex = m_gc.count();
1598 //	qDebug() << "Path Text Matrix" << scaleX << -skewX << -skewY << scaleY << transX << -transY << "Skew" << (qint32)tSk << "Skew" << textSkew << "Type" << type;
1599 }
1600 
handleFillRule(QDataStream & ts)1601 void XarPlug::handleFillRule(QDataStream &ts)
1602 {
1603 	quint8 val;
1604 	ts >> val;
1605 	XarStyle *gc = m_gc.top();
1606 	gc->fillRule = (val != 0);
1607 }
1608 
handleLineEnd(QDataStream & ts)1609 void XarPlug::handleLineEnd(QDataStream &ts)
1610 {
1611 	quint8 val;
1612 	ts >> val;
1613 	XarStyle *gc = m_gc.top();
1614 	if (val == 0)
1615 		gc->PLineEnd = Qt::FlatCap;
1616 	else if (val == 1)
1617 		gc->PLineEnd = Qt::RoundCap;
1618 	else if (val == 2)
1619 		gc->PLineEnd = Qt::SquareCap;
1620 	if (textLines.count() > 0)
1621 	{
1622 		if (textLines.last().textData.count() > 0)
1623 			textLines.last().textData.last().PLineEnd = gc->PLineEnd;
1624 	}
1625 }
1626 
handleLineJoin(QDataStream & ts)1627 void XarPlug::handleLineJoin(QDataStream &ts)
1628 {
1629 	quint8 val;
1630 	ts >> val;
1631 	XarStyle *gc = m_gc.top();
1632 	if (val == 0)
1633 		gc->PLineJoin = Qt::MiterJoin;
1634 	else if (val == 1)
1635 		gc->PLineJoin = Qt::RoundJoin;
1636 	else if (val == 2)
1637 		gc->PLineJoin = Qt::BevelJoin;
1638 	if (textLines.count() > 0)
1639 	{
1640 		if (textLines.last().textData.count() > 0)
1641 			textLines.last().textData.last().PLineJoin = gc->PLineJoin;
1642 	}
1643 }
1644 
handleQuickShapeSimple(QDataStream & ts,quint32 dataLen)1645 void XarPlug::handleQuickShapeSimple(QDataStream &ts, quint32 dataLen)
1646 {
1647 	XarStyle *gc = m_gc.top();
1648 	quint32 bytesRead = 0;
1649 	double minorAxisX, minorAxisY, majorAxisX, majorAxisY;
1650 	quint16 numSides = 0;
1651 	quint8 flags;
1652 	ts >> flags;
1653 	bytesRead++;
1654 	ts >> numSides;
1655 	bytesRead += 2;
1656 	readCoords(ts, majorAxisX, majorAxisY);
1657 	bytesRead += 8;
1658 	readCoords(ts, minorAxisX, minorAxisY);
1659 	bytesRead += 8;
1660 	quint32 scX, skX, skY, scY;
1661 	double transX, transY;
1662 	ts >> scX >> skX >> skY >> scY;
1663 	readCoords(ts, transX, transY);
1664 	bytesRead += 24;
1665 	double scaleX = decodeFixed16(scX);
1666 	double scaleY = decodeFixed16(scY);
1667 	double skewX = decodeFixed16(skX);
1668 	double skewY = decodeFixed16(skY);
1669 	double r1, r2, r3, r4;
1670 	ts >> r1 >> r2 >> r3 >> r4;
1671 	bytesRead += 32;
1672 //	qDebug() << "Regular Polygon";
1673 //	qDebug() << "Sides" << numSides;
1674 //	qDebug() << "MajorAxis" << majorAxisX << majorAxisY;
1675 //	qDebug() << "MinorAxis" << minorAxisX << minorAxisY;
1676 //	qDebug() << "Matrix" << scaleX << skewX << skewY << scaleY << transX << transY;
1677 //	qDebug() << "Radii" << r1 << r2 << r3 << r4;
1678 //	qDebug() << "Flags" << flags;
1679 //	qDebug() << "Bytes read" << bytesRead << "of" << dataLen;
1680 	ts.skipRawData(dataLen - bytesRead);
1681 	int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
1682 	double w = distance(minorAxisX, minorAxisY);
1683 	double h = distance(majorAxisX, majorAxisY);
1684 	Coords.resize(0);
1685 	Coords.svgInit();
1686 	QPainterPath path;
1687 	if (flags & 1)
1688 		path.addEllipse(QPointF(0,0), w, h);
1689 	else
1690 		path = regularPolygonPath(w * 2, h * 2, numSides, flags & 2, r1, -90 + (360.0 / double(numSides)) / 2.0, 0);
1691 	Coords.fromQPainterPath(path);
1692 	if (!(flags & 1))
1693 		Coords.translate(-w, -h);
1694 	QTransform matrix(scaleX, -skewX, -skewY, scaleY, 0, 0);
1695 	Coords.map(matrix);
1696 	Coords.translate(transX, -transY);
1697 	Coords.translate(0, docHeight);
1698 	finishItem(z);
1699 //	PageItem *ite = m_Doc->Items->at(z);
1700 //	qDebug() << "Item" << ite->itemName();
1701 }
1702 
handleFlatFillTransparency(QDataStream & ts)1703 void XarPlug::handleFlatFillTransparency(QDataStream &ts)
1704 {
1705 	quint8 transVal, transType;
1706 	ts >> transVal >> transType;
1707 	XarStyle *gc = m_gc.top();
1708 	if (transType > 0)
1709 	{
1710 		gc->FillOpacity = transVal / 255.0;
1711 		gc->FillBlend = convertBlendMode(transType);
1712 		gc->GradMask = 0;
1713 		if (textLines.count() > 0)
1714 		{
1715 			if (textLines.last().textData.count() > 0)
1716 			{
1717 				textLines.last().textData.last().FillOpacity = gc->FillOpacity;
1718 				textLines.last().textData.last().FillBlend = gc->FillBlend;
1719 				textLines.last().textData.last().GradMask = gc->GradMask;
1720 			}
1721 		}
1722 	}
1723 }
1724 
handleSimpleGradientTransparency(QDataStream & ts,quint32 dataLen,bool linear)1725 void XarPlug::handleSimpleGradientTransparency(QDataStream &ts, quint32 dataLen, bool linear)
1726 {
1727 	XarStyle *gc = m_gc.top();
1728 	double blx, bly, brx, bry;
1729 	quint8 transStart, transEnd, transType;
1730 	readCoords(ts, blx, bly);
1731 	readCoords(ts, brx, bry);
1732 	ts >> transStart >> transEnd >> transType;
1733 	gc->FillBlend = convertBlendMode(transType);
1734 	if (dataLen == 35)
1735 	{
1736 		double p, p1;
1737 		ts >> p >> p1;
1738 	}
1739 	if (linear)
1740 	{
1741 		gc->GradMask = 1;
1742 		gc->MaskGradient = VGradient(VGradient::linear);
1743 	}
1744 	else
1745 	{
1746 		gc->GradMask = 2;
1747 		gc->MaskGradient = VGradient(VGradient::radial);
1748 	}
1749 	gc->MaskGradient.clearStops();
1750 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 0.0, 0.5, 1.0 - transStart / 255.0, "Black", 100 );
1751 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 1.0, 0.5, 1.0 - transEnd / 255.0, "Black", 100 );
1752 	gc->GradMaskX1 = blx + baseX + m_Doc->currentPage()->xOffset();
1753 	gc->GradMaskY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
1754 	gc->GradMaskX2 = brx + baseX + m_Doc->currentPage()->xOffset();
1755 	gc->GradMaskY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
1756 	if (textLines.count() > 0)
1757 	{
1758 		if (textLines.last().textData.count() > 0)
1759 		{
1760 			textLines.last().textData.last().GradMask = gc->GradMask;
1761 			textLines.last().textData.last().MaskGradient = gc->MaskGradient;
1762 			textLines.last().textData.last().GradMaskX1 = gc->GradMaskX1;
1763 			textLines.last().textData.last().GradMaskY1 = gc->GradMaskY1;
1764 			textLines.last().textData.last().GradMaskX2 = gc->GradMaskX2;
1765 			textLines.last().textData.last().GradMaskY2 = gc->GradMaskY2;
1766 			textLines.last().textData.last().GradMaskScale = gc->GradMaskScale;
1767 			textLines.last().textData.last().GradMaskSkew = gc->GradMaskSkew;
1768 		}
1769 	}
1770 }
1771 
handleSimpleGradientTransparencySkewed(QDataStream & ts,quint32 dataLen)1772 void XarPlug::handleSimpleGradientTransparencySkewed(QDataStream &ts, quint32 dataLen)
1773 {
1774 	XarStyle *gc = m_gc.top();
1775 	double blx, bly, brx, bry, tlx, tly;
1776 	quint8 transStart, transEnd, transType;
1777 	readCoords(ts, blx, bly);
1778 	readCoords(ts, brx, bry);
1779 	readCoords(ts, tlx, tly);
1780 	ts >> transStart >> transEnd >> transType;
1781 	gc->FillBlend = convertBlendMode(transType);
1782 	if (dataLen == 43)
1783 	{
1784 		double p, p1;
1785 		ts >> p >> p1;
1786 	}
1787 	gc->MaskGradient = VGradient(VGradient::linear);
1788 	gc->MaskGradient.clearStops();
1789 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 0.0, 0.5, 1.0 - transStart / 255.0, "Black", 100 );
1790 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 1.0, 0.5, 1.0 - transEnd / 255.0, "Black", 100 );
1791 	double distX = distance(brx - blx, bry - bly);
1792 	double distY = distance(tlx - blx, tly - bly);
1793 	double rotB = xy2Deg(brx - blx, bry - bly);
1794 	double rotS = xy2Deg(tlx - blx, tly - bly);
1795 	gc->GradMaskScale = distY / distX;
1796 	gc->GradMaskSkew = rotS - 90 - rotB;
1797 	gc->GradMaskX1 = blx + baseX + m_Doc->currentPage()->xOffset();
1798 	gc->GradMaskY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
1799 	gc->GradMaskX2 = brx + baseX + m_Doc->currentPage()->xOffset();
1800 	gc->GradMaskY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
1801 	gc->GradMask = 1;
1802 	if (textLines.count() > 0)
1803 	{
1804 		if (textLines.last().textData.count() > 0)
1805 		{
1806 			textLines.last().textData.last().GradMask = gc->GradMask;
1807 			textLines.last().textData.last().MaskGradient = gc->MaskGradient;
1808 			textLines.last().textData.last().GradMaskX1 = gc->GradMaskX1;
1809 			textLines.last().textData.last().GradMaskY1 = gc->GradMaskY1;
1810 			textLines.last().textData.last().GradMaskX2 = gc->GradMaskX2;
1811 			textLines.last().textData.last().GradMaskY2 = gc->GradMaskY2;
1812 			textLines.last().textData.last().GradMaskScale = gc->GradMaskScale;
1813 			textLines.last().textData.last().GradMaskSkew = gc->GradMaskSkew;
1814 		}
1815 	}
1816 }
1817 
handleEllipticalGradientTransparency(QDataStream & ts,quint32 dataLen)1818 void XarPlug::handleEllipticalGradientTransparency(QDataStream &ts, quint32 dataLen)
1819 {
1820 	XarStyle *gc = m_gc.top();
1821 	double blx, bly, brx, bry, tlx, tly;
1822 	quint8 transStart, transEnd, transType;
1823 	readCoords(ts, blx, bly);
1824 	readCoords(ts, tlx, tly);
1825 	readCoords(ts, brx, bry);
1826 	ts >> transStart >> transEnd >> transType;
1827 	gc->FillBlend = convertBlendMode(transType);
1828 	if (dataLen == 43)
1829 	{
1830 		double p, p1;
1831 		ts >> p >> p1;
1832 	}
1833 	gc->MaskGradient = VGradient(VGradient::radial);
1834 	gc->MaskGradient.clearStops();
1835 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 0.0, 0.5, 1.0 - transStart / 255.0, "Black", 100 );
1836 	gc->MaskGradient.addStop( ScColorEngine::getRGBColor(m_Doc->PageColors["Black"], m_Doc), 1.0, 0.5, 1.0 - transEnd / 255.0, "Black", 100 );
1837 	double distX = distance(brx - blx, bry - bly);
1838 	double distY = distance(tlx - blx, tly - bly);
1839 	double rotB = xy2Deg(brx - blx, bry - bly);
1840 	double rotS = xy2Deg(tlx - blx, tly - bly);
1841 	gc->GradMaskScale = distY / distX;
1842 	gc->GradMaskSkew = rotS - 90 - rotB;
1843 	gc->GradMaskX1 = blx + baseX + m_Doc->currentPage()->xOffset();
1844 	gc->GradMaskY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
1845 	gc->GradMaskX2 = brx + baseX + m_Doc->currentPage()->xOffset();
1846 	gc->GradMaskY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
1847 	gc->GradMask = 2;
1848 	if (textLines.count() > 0)
1849 	{
1850 		if (textLines.last().textData.count() > 0)
1851 		{
1852 			textLines.last().textData.last().GradMask = gc->GradMask;
1853 			textLines.last().textData.last().MaskGradient = gc->MaskGradient;
1854 			textLines.last().textData.last().GradMaskX1 = gc->GradMaskX1;
1855 			textLines.last().textData.last().GradMaskY1 = gc->GradMaskY1;
1856 			textLines.last().textData.last().GradMaskX2 = gc->GradMaskX2;
1857 			textLines.last().textData.last().GradMaskY2 = gc->GradMaskY2;
1858 			textLines.last().textData.last().GradMaskScale = gc->GradMaskScale;
1859 			textLines.last().textData.last().GradMaskSkew = gc->GradMaskSkew;
1860 		}
1861 	}
1862 }
1863 
handleBitmapTransparency(QDataStream & ts,quint32 dataLen)1864 void XarPlug::handleBitmapTransparency(QDataStream &ts, quint32 dataLen)
1865 {
1866 	XarStyle *gc = m_gc.top();
1867 	qint32 bref;
1868 	double blx, bly, brx, bry, tlx, tly;
1869 	quint8 transStart, transEnd, transType;
1870 	readCoords(ts, blx, bly);
1871 	readCoords(ts, brx, bry);
1872 	readCoords(ts, tlx, tly);
1873 	ts >> transStart >> transEnd >> transType;
1874 	ts >> bref;
1875 	gc->FillBlend = convertBlendMode(transType);
1876 	if (dataLen == 47)
1877 	{
1878 		double p, p1;
1879 		ts >> p >> p1;
1880 	}
1881 	double distX = distance(brx - blx, bry - bly);
1882 	double distY = distance(tlx - blx, tly - bly);
1883 	double rotB = xy2Deg(brx - blx, bry - bly);
1884 	double rotS = xy2Deg(tlx - blx, tly - bly);
1885 	if (patternRef.contains(bref))
1886 	{
1887 		QString imgNam = m_Doc->docPatterns[patternRef[bref]].items.at(0)->externalFile();
1888 		QImage image;
1889 		image.load(imgNam);
1890 		int h = image.height();
1891 		int w = image.width();
1892 		int k;
1893 		int ts = transStart;
1894 		int te = transEnd;
1895 		QRgb *s;
1896 		QRgb r;
1897 		for (int yi = 0; yi < h; ++yi)
1898 		{
1899 			s = (QRgb*)(image.scanLine( yi ));
1900 			for (int xi = 0; xi < w; ++xi)
1901 			{
1902 				r = *s;
1903 				k = qMin(qRound(0.3 * qRed(r) + 0.59 * qGreen(r) + 0.11 * qBlue(r)), 255);
1904 				if (qAlpha(r) == 0)
1905 					k = 255;
1906 				k = qBound(ts, k, te);
1907 				*s = qRgba(qRed(r), qGreen(r), qBlue(r), 255 - k);
1908 				s++;
1909 			}
1910 		}
1911 		ScPattern pat = ScPattern();
1912 		pat.setDoc(m_Doc);
1913 		PageItem* newItem = new PageItem_ImageFrame(m_Doc, 0, 0, 1, 1, 0, CommonStrings::None, CommonStrings::None);
1914 		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_xar_XXXXXX.png");
1915 		tempFile->setAutoRemove(false);
1916 		tempFile->open();
1917 		QString fileName = getLongPathName(tempFile->fileName());
1918 		tempFile->close();
1919 		delete tempFile;
1920 		newItem->isTempFile = true;
1921 		newItem->isInlineImage = true;
1922 		image.setDotsPerMeterY(2834);
1923 		image.setDotsPerMeterX(2834);
1924 		image.save(fileName, "PNG");
1925 		if (newItem->loadImage(fileName, false, 72, false))
1926 		{
1927 			pat.width = image.width();
1928 			pat.height = image.height();
1929 			pat.scaleX = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
1930 			pat.scaleY = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
1931 			pat.pattern = newItem->pixm.qImage().copy();
1932 			newItem->setWidth(pat.pattern.width());
1933 			newItem->setHeight(pat.pattern.height());
1934 			newItem->SetRectFrame();
1935 			newItem->gXpos = 0.0;
1936 			newItem->gYpos = 0.0;
1937 			newItem->gWidth = pat.pattern.width();
1938 			newItem->gHeight = pat.pattern.height();
1939 			pat.items.append(newItem);
1940 		}
1941 		QString patternName = patternRef[bref]+"_"+newItem->itemName();
1942 		patternName = patternName.trimmed().simplified().replace(" ", "_");
1943 		m_Doc->addPattern(patternName, pat);
1944 		importedPatterns.append(patternName);
1945 		gc->maskPattern = patternName;
1946 		gc->patternMaskScaleX = distX / pat.width * 100;
1947 		gc->patternMaskScaleY = distY / pat.height * 100;
1948 		gc->patternMaskOffsetX = 0.0;
1949 		gc->patternMaskOffsetY = 0.0;
1950 		gc->patternMaskRotation = -rotB;
1951 		gc->patternMaskSkewX = rotS - 90 - rotB;
1952 		gc->patternMaskSkewY = 0.0;
1953 		gc->GradMask = 3;
1954 		if (textLines.count() > 0)
1955 		{
1956 			if (textLines.last().textData.count() > 0)
1957 			{
1958 				textLines.last().textData.last().GradMask = gc->GradMask;
1959 				textLines.last().textData.last().maskPattern = gc->maskPattern;
1960 				textLines.last().textData.last().patternMaskScaleX = gc->patternMaskScaleX;
1961 				textLines.last().textData.last().patternMaskScaleY = gc->patternMaskScaleY;
1962 				textLines.last().textData.last().patternMaskOffsetX = gc->patternMaskOffsetX;
1963 				textLines.last().textData.last().patternMaskOffsetY = gc->patternMaskOffsetY;
1964 				textLines.last().textData.last().patternMaskRotation = gc->patternMaskRotation;
1965 				textLines.last().textData.last().patternMaskSkewX = gc->patternMaskSkewX;
1966 				textLines.last().textData.last().patternMaskSkewY = gc->patternMaskSkewY;
1967 			}
1968 		}
1969 	}
1970 }
1971 
convertBlendMode(int val)1972 int XarPlug::convertBlendMode(int val)
1973 {
1974 	int ret = 0;
1975 	if (val == 2)
1976 		ret = 6;
1977 	else if (val == 3)
1978 		ret = 10;
1979 	else if (val == 5)
1980 		ret = 13;
1981 	else if (val == 7)
1982 		ret = 7;
1983 	else if (val == 9)
1984 		ret = 15;
1985 	else if (val == 10)
1986 		ret = 12;
1987 	else
1988 		ret = 0;
1989 	return ret;
1990 }
1991 
handleSimpleGradientElliptical(QDataStream & ts,quint32 dataLen)1992 void XarPlug::handleSimpleGradientElliptical(QDataStream &ts, quint32 dataLen)
1993 {
1994 	XarStyle *gc = m_gc.top();
1995 	double blx, bly, brx, bry, tlx, tly;
1996 	qint32 colRef1, colRef2;
1997 	readCoords(ts, blx, bly);
1998 	readCoords(ts, tlx, tly);
1999 	readCoords(ts, brx, bry);
2000 	ts >> colRef1 >> colRef2;
2001 	if (dataLen == 48)
2002 	{
2003 		double p, p1;
2004 		ts >> p >> p1;
2005 	}
2006 	gc->FillGradient = VGradient(VGradient::linear);
2007 	gc->FillGradient.clearStops();
2008 	QString gCol1 = "Black";
2009 	QString gCol2 = "Black";
2010 	if (XarColorMap.contains(colRef1))
2011 		gCol1 = XarColorMap[colRef1].name;
2012 	if (XarColorMap.contains(colRef2))
2013 		gCol2 = XarColorMap[colRef2].name;
2014 	if (gCol1 != CommonStrings::None)
2015 	{
2016 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2017 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2018 	}
2019 	else
2020 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2021 	if (gCol2 != CommonStrings::None)
2022 	{
2023 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2024 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2025 	}
2026 	else
2027 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2028 	gc->FillGradientType = 7;
2029 	double distX = distance(brx - blx, bry - bly);
2030 	double distY = distance(tlx - blx, tly - bly);
2031 	double rotB = xy2Deg(brx - blx, bry - bly);
2032 	double rotS = xy2Deg(tlx - blx, tly - bly);
2033 	gc->GrScale = distY / distX;
2034 	gc->GrSkew = rotS - 90 - rotB;
2035 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2036 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2037 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2038 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2039 	if (textLines.count() > 0)
2040 	{
2041 		if (textLines.last().textData.count() > 0)
2042 		{
2043 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2044 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2045 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2046 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2047 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2048 			textLines.last().textData.last().GrScale = gc->GrScale;
2049 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2050 		}
2051 	}
2052 }
2053 
handleMultiGradientElliptical(QDataStream & ts)2054 void XarPlug::handleMultiGradientElliptical(QDataStream &ts)
2055 {
2056 	XarStyle *gc = m_gc.top();
2057 	double blx, bly, brx, bry, tlx, tly;
2058 	qint32 colRef1, colRef2;
2059 	readCoords(ts, blx, bly);
2060 	readCoords(ts, tlx, tly);
2061 	readCoords(ts, brx, bry);
2062 	ts >> colRef1 >> colRef2;
2063 	gc->FillGradient = VGradient(VGradient::linear);
2064 	gc->FillGradient.clearStops();
2065 	QString gCol1 = "Black";
2066 	QString gCol2 = "Black";
2067 	if (XarColorMap.contains(colRef1))
2068 		gCol1 = XarColorMap[colRef1].name;
2069 	if (XarColorMap.contains(colRef2))
2070 		gCol2 = XarColorMap[colRef2].name;
2071 	if (gCol1 != CommonStrings::None)
2072 	{
2073 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2074 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2075 	}
2076 	else
2077 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2078 	quint32 numCols;
2079 	ts >> numCols;
2080 	for (uint a = 0; a < numCols; a++)
2081 	{
2082 		double cpos;
2083 		qint32 colRef;
2084 		ts >> cpos;
2085 		ts >> colRef;
2086 		QString gCol = "Black";
2087 		if (XarColorMap.contains(colRef))
2088 			gCol = XarColorMap[colRef].name;
2089 		if (gCol != CommonStrings::None)
2090 		{
2091 			const ScColor& gradC = m_Doc->PageColors[gCol];
2092 			gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), cpos, 0.5, 1.0, gCol, 100 );
2093 		}
2094 		else
2095 			gc->FillGradient.addStop( QColor(255, 255, 255, 0), cpos, 0.5, 0.0, gCol, 100 );
2096 	}
2097 	if (gCol2 != CommonStrings::None)
2098 	{
2099 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2100 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2101 	}
2102 	else
2103 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2104 	gc->FillGradientType = 7;
2105 	double distX = distance(brx - blx, bry - bly);
2106 	double distY = distance(tlx - blx, tly - bly);
2107 	double rotB = xy2Deg(brx - blx, bry - bly);
2108 	double rotS = xy2Deg(tlx - blx, tly - bly);
2109 	gc->GrScale = distY / distX;
2110 	gc->GrSkew = rotS - 90 - rotB;
2111 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2112 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2113 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2114 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2115 	if (textLines.count() > 0)
2116 	{
2117 		if (textLines.last().textData.count() > 0)
2118 		{
2119 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2120 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2121 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2122 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2123 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2124 			textLines.last().textData.last().GrScale = gc->GrScale;
2125 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2126 		}
2127 	}
2128 }
2129 
handleMultiGradientSkewed(QDataStream & ts)2130 void XarPlug::handleMultiGradientSkewed(QDataStream &ts)
2131 {
2132 	XarStyle *gc = m_gc.top();
2133 	double blx, bly, brx, bry, tlx, tly;
2134 	qint32 colRef1, colRef2;
2135 	readCoords(ts, blx, bly);
2136 	readCoords(ts, brx, bry);
2137 	readCoords(ts, tlx, tly);
2138 	ts >> colRef1 >> colRef2;
2139 	gc->FillGradient = VGradient(VGradient::linear);
2140 	gc->FillGradient.clearStops();
2141 	QString gCol1 = "Black";
2142 	QString gCol2 = "Black";
2143 	if (XarColorMap.contains(colRef1))
2144 		gCol1 = XarColorMap[colRef1].name;
2145 	if (XarColorMap.contains(colRef2))
2146 		gCol2 = XarColorMap[colRef2].name;
2147 	if (gCol1 != CommonStrings::None)
2148 	{
2149 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2150 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2151 	}
2152 	else
2153 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2154 	quint32 numCols;
2155 	ts >> numCols;
2156 	for (uint a = 0; a < numCols; a++)
2157 	{
2158 		double cpos;
2159 		qint32 colRef;
2160 		ts >> cpos;
2161 		ts >> colRef;
2162 		QString gCol = "Black";
2163 		if (XarColorMap.contains(colRef))
2164 			gCol = XarColorMap[colRef].name;
2165 		if (gCol != CommonStrings::None)
2166 		{
2167 			const ScColor& gradC = m_Doc->PageColors[gCol];
2168 			gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), cpos, 0.5, 1.0, gCol, 100 );
2169 		}
2170 		else
2171 			gc->FillGradient.addStop( QColor(255, 255, 255, 0), cpos, 0.5, 0.0, gCol, 100 );
2172 	}
2173 	if (gCol2 != CommonStrings::None)
2174 	{
2175 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2176 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2177 	}
2178 	else
2179 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2180 	gc->FillGradientType = 6;
2181 	double distX = distance(brx - blx, bry - bly);
2182 	double distY = distance(tlx - blx, tly - bly);
2183 	double rotB = xy2Deg(brx - blx, bry - bly);
2184 	double rotS = xy2Deg(tlx - blx, tly - bly);
2185 	gc->GrScale = distY / distX;
2186 	gc->GrSkew = rotS - 90 - rotB;
2187 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2188 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2189 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2190 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2191 	if (textLines.count() > 0)
2192 	{
2193 		if (textLines.last().textData.count() > 0)
2194 		{
2195 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2196 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2197 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2198 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2199 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2200 			textLines.last().textData.last().GrScale = gc->GrScale;
2201 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2202 		}
2203 	}
2204 }
2205 
handleMultiGradient(QDataStream & ts,bool linear)2206 void XarPlug::handleMultiGradient(QDataStream &ts, bool linear)
2207 {
2208 	XarStyle *gc = m_gc.top();
2209 	double blx, bly, brx, bry;
2210 	qint32 colRef1, colRef2;
2211 	readCoords(ts, blx, bly);
2212 	readCoords(ts, brx, bry);
2213 	ts >> colRef1 >> colRef2;
2214 	gc->FillGradient = VGradient(VGradient::linear);
2215 	gc->FillGradient.clearStops();
2216 	QString gCol1 = "Black";
2217 	QString gCol2 = "Black";
2218 	if (XarColorMap.contains(colRef1))
2219 		gCol1 = XarColorMap[colRef1].name;
2220 	if (XarColorMap.contains(colRef2))
2221 		gCol2 = XarColorMap[colRef2].name;
2222 	if (gCol1 != CommonStrings::None)
2223 	{
2224 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2225 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2226 	}
2227 	else
2228 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2229 	quint32 numCols;
2230 	ts >> numCols;
2231 	for (uint a = 0; a < numCols; a++)
2232 	{
2233 		double cpos;
2234 		qint32 colRef;
2235 		ts >> cpos;
2236 		ts >> colRef;
2237 		QString gCol = "Black";
2238 		if (XarColorMap.contains(colRef))
2239 			gCol = XarColorMap[colRef].name;
2240 		if (gCol != CommonStrings::None)
2241 		{
2242 			const ScColor& gradC = m_Doc->PageColors[gCol];
2243 			gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), cpos, 0.5, 1.0, gCol, 100 );
2244 		}
2245 		else
2246 			gc->FillGradient.addStop( QColor(255, 255, 255, 0), cpos, 0.5, 0.0, gCol, 100 );
2247 	}
2248 	if (gCol2 != CommonStrings::None)
2249 	{
2250 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2251 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2252 	}
2253 	else
2254 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2255 	if (linear)
2256 		gc->FillGradientType = 6;
2257 	else
2258 		gc->FillGradientType = 7;
2259 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2260 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2261 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2262 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2263 	gc->GrScale = 1.0;
2264 	gc->GrSkew = 0;
2265 	if (textLines.count() > 0)
2266 	{
2267 		if (textLines.last().textData.count() > 0)
2268 		{
2269 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2270 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2271 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2272 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2273 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2274 			textLines.last().textData.last().GrScale = gc->GrScale;
2275 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2276 		}
2277 	}
2278 }
2279 
handleSimpleGradientSkewed(QDataStream & ts,quint32 dataLen)2280 void XarPlug::handleSimpleGradientSkewed(QDataStream &ts, quint32 dataLen)
2281 {
2282 	XarStyle *gc = m_gc.top();
2283 	double blx, bly, brx, bry, tlx, tly;
2284 	qint32 colRef1, colRef2;
2285 	readCoords(ts, blx, bly);
2286 	readCoords(ts, brx, bry);
2287 	readCoords(ts, tlx, tly);
2288 	ts >> colRef1 >> colRef2;
2289 	if (dataLen == 48)
2290 	{
2291 		double p, p1;
2292 		ts >> p >> p1;
2293 	}
2294 	gc->FillGradient = VGradient(VGradient::linear);
2295 	gc->FillGradient.clearStops();
2296 	QString gCol1 = "Black";
2297 	QString gCol2 = "Black";
2298 	if (XarColorMap.contains(colRef1))
2299 		gCol1 = XarColorMap[colRef1].name;
2300 	if (XarColorMap.contains(colRef2))
2301 		gCol2 = XarColorMap[colRef2].name;
2302 	if (gCol1 != CommonStrings::None)
2303 	{
2304 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2305 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2306 	}
2307 	else
2308 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2309 	if (gCol2 != CommonStrings::None)
2310 	{
2311 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2312 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2313 	}
2314 	else
2315 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2316 	gc->FillGradientType = 6;
2317 	double distX = distance(brx - blx, bry - bly);
2318 	double distY = distance(tlx - blx, tly - bly);
2319 	double rotB = xy2Deg(brx - blx, bry - bly);
2320 	double rotS = xy2Deg(tlx - blx, tly - bly);
2321 	gc->GrScale = distY / distX;
2322 	gc->GrSkew = rotS - 90 - rotB;
2323 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2324 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2325 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2326 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2327 	if (textLines.count() > 0)
2328 	{
2329 		if (textLines.last().textData.count() > 0)
2330 		{
2331 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2332 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2333 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2334 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2335 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2336 			textLines.last().textData.last().GrScale = gc->GrScale;
2337 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2338 		}
2339 	}
2340 }
2341 
handleSimpleGradient(QDataStream & ts,quint32 dataLen,bool linear)2342 void XarPlug::handleSimpleGradient(QDataStream &ts, quint32 dataLen, bool linear)
2343 {
2344 	XarStyle *gc = m_gc.top();
2345 	double blx, bly, brx, bry;
2346 	qint32 colRef1, colRef2;
2347 	readCoords(ts, blx, bly);
2348 	readCoords(ts, brx, bry);
2349 	ts >> colRef1 >> colRef2;
2350 	if (dataLen == 40)
2351 	{
2352 		double p, p1;
2353 		ts >> p >> p1;
2354 	}
2355 	gc->FillGradient = VGradient(VGradient::linear);
2356 	gc->FillGradient.clearStops();
2357 	QString gCol1 = "Black";
2358 	QString gCol2 = "Black";
2359 	if (XarColorMap.contains(colRef1))
2360 		gCol1 = XarColorMap[colRef1].name;
2361 	if (XarColorMap.contains(colRef2))
2362 		gCol2 = XarColorMap[colRef2].name;
2363 	if (gCol1 != CommonStrings::None)
2364 	{
2365 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2366 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2367 	}
2368 	else
2369 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2370 	if (gCol2 != CommonStrings::None)
2371 	{
2372 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2373 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2374 	}
2375 	else
2376 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2377 	if (linear)
2378 		gc->FillGradientType = 6;
2379 	else
2380 		gc->FillGradientType = 7;
2381 	gc->GradFillX1 = blx + baseX + m_Doc->currentPage()->xOffset();
2382 	gc->GradFillY1 = (docHeight - bly) + baseY + m_Doc->currentPage()->yOffset();
2383 	gc->GradFillX2 = brx + baseX + m_Doc->currentPage()->xOffset();
2384 	gc->GradFillY2 = (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset();
2385 	gc->GrScale = 1.0;
2386 	gc->GrSkew = 0;
2387 	if (textLines.count() > 0)
2388 	{
2389 		if (textLines.last().textData.count() > 0)
2390 		{
2391 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2392 			textLines.last().textData.last().GradFillX1 = gc->GradFillX1;
2393 			textLines.last().textData.last().GradFillY1 = gc->GradFillY1;
2394 			textLines.last().textData.last().GradFillX2 = gc->GradFillX2;
2395 			textLines.last().textData.last().GradFillY2 = gc->GradFillY2;
2396 			textLines.last().textData.last().GrScale = gc->GrScale;
2397 			textLines.last().textData.last().GrSkew = gc->GrSkew;
2398 		}
2399 	}
2400 }
2401 
handleMultiDiamondGradient(QDataStream & ts)2402 void XarPlug::handleMultiDiamondGradient(QDataStream &ts)
2403 {
2404 	XarStyle *gc = m_gc.top();
2405 	double btx, bty, brx, bry, bcx, bcy;
2406 	qint32 colRef1, colRef2;
2407 	readCoords(ts, bcx, bcy);
2408 	readCoords(ts, brx, bry);
2409 	readCoords(ts, btx, bty);
2410 	ts >> colRef1 >> colRef2;
2411 	gc->FillGradient = VGradient(VGradient::linear);
2412 	gc->FillGradient.clearStops();
2413 	QString gCol1 = "Black";
2414 	QString gCol2 = "Black";
2415 	if (XarColorMap.contains(colRef1))
2416 		gCol1 = XarColorMap[colRef1].name;
2417 	if (XarColorMap.contains(colRef2))
2418 		gCol2 = XarColorMap[colRef2].name;
2419 	if (gCol1 != CommonStrings::None)
2420 	{
2421 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2422 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2423 	}
2424 	else
2425 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2426 	quint32 numCols;
2427 	ts >> numCols;
2428 	for (uint a = 0; a < numCols; a++)
2429 	{
2430 		double cpos;
2431 		qint32 colRef;
2432 		ts >> cpos;
2433 		ts >> colRef;
2434 		QString gCol = "Black";
2435 		if (XarColorMap.contains(colRef))
2436 			gCol = XarColorMap[colRef].name;
2437 		if (gCol != CommonStrings::None)
2438 		{
2439 			const ScColor& gradC = m_Doc->PageColors[gCol];
2440 			gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), cpos, 0.5, 1.0, gCol, 100 );
2441 		}
2442 		else
2443 			gc->FillGradient.addStop( QColor(255, 255, 255, 0), cpos, 0.5, 0.0, gCol, 100 );
2444 	}
2445 	if (gCol2 != CommonStrings::None)
2446 	{
2447 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2448 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2449 	}
2450 	else
2451 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2452 	gc->FillGradientType = 10;
2453 	gc->GrControl5 = FPoint(bcx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bcy) + baseY + m_Doc->currentPage()->yOffset());
2454 	QPointF cen = QPointF(bcx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bcy) + baseY + m_Doc->currentPage()->yOffset());
2455 	QPointF rig = QPointF(brx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset());
2456 	QPointF top = QPointF(btx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bty) + baseY + m_Doc->currentPage()->yOffset());
2457 	QLineF rVec = QLineF(cen, rig);
2458 	QLineF tVec = QLineF(cen, top);
2459 	QLineF rNVec = tVec.translated(rVec.dx(), rVec.dy());
2460 	QPointF intRT = rNVec.p2();
2461 	gc->GrControl2 = FPoint(intRT.x(), intRT.y());
2462 	QLineF vg4 = QLineF(cen, intRT);
2463 	vg4.setAngle(vg4.angle()+180);
2464 	gc->GrControl4 = FPoint(vg4.x2(), vg4.y2());
2465 	QLineF tNVec = tVec.translated(-rVec.dx(), -rVec.dy());
2466 	QPointF intLT = tNVec.p2();
2467 	gc->GrControl1 = FPoint(intLT.x(), intLT.y());
2468 	QLineF vg3 = QLineF(cen, intLT);
2469 	vg3.setAngle(vg3.angle()+180);
2470 	gc->GrControl3 = FPoint(vg3.x2(), vg3.y2());
2471 	if (textLines.count() > 0)
2472 	{
2473 		if (textLines.last().textData.count() > 0)
2474 		{
2475 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2476 			textLines.last().textData.last().GrControl1 = gc->GrControl1;
2477 			textLines.last().textData.last().GrControl2 = gc->GrControl2;
2478 			textLines.last().textData.last().GrControl3 = gc->GrControl3;
2479 			textLines.last().textData.last().GrControl4 = gc->GrControl4;
2480 			textLines.last().textData.last().GrControl5 = gc->GrControl5;
2481 		}
2482 	}
2483 }
2484 
handleSimpleDiamondGradient(QDataStream & ts,quint32 dataLen)2485 void XarPlug::handleSimpleDiamondGradient(QDataStream &ts, quint32 dataLen)
2486 {
2487 	XarStyle *gc = m_gc.top();
2488 	double btx, bty, brx, bry, bcx, bcy;
2489 	qint32 colRef1, colRef2;
2490 	readCoords(ts, bcx, bcy);
2491 	readCoords(ts, brx, bry);
2492 	readCoords(ts, btx, bty);
2493 	ts >> colRef1 >> colRef2;
2494 	if (dataLen == 48)
2495 	{
2496 		double p, p1;
2497 		ts >> p >> p1;
2498 	}
2499 	gc->FillGradient = VGradient(VGradient::linear);
2500 	gc->FillGradient.clearStops();
2501 	QString gCol1 = "Black";
2502 	QString gCol2 = "Black";
2503 	if (XarColorMap.contains(colRef1))
2504 		gCol1 = XarColorMap[colRef1].name;
2505 	if (XarColorMap.contains(colRef2))
2506 		gCol2 = XarColorMap[colRef2].name;
2507 	if (gCol1 != CommonStrings::None)
2508 	{
2509 		const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2510 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC1, m_Doc), 0.0, 0.5, 1.0, gCol1, 100 );
2511 	}
2512 	else
2513 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 0.0, 0.5, 0.0, gCol1, 100 );
2514 	if (gCol2 != CommonStrings::None)
2515 	{
2516 		const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2517 		gc->FillGradient.addStop( ScColorEngine::getRGBColor(gradC2, m_Doc), 1.0, 0.5, 1.0, gCol2, 100 );
2518 	}
2519 	else
2520 		gc->FillGradient.addStop( QColor(255, 255, 255, 0), 1.0, 0.5, 0.0, gCol2, 100 );
2521 	gc->FillGradientType = 10;
2522 	gc->GrControl5 = FPoint(bcx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bcy) + baseY + m_Doc->currentPage()->yOffset());
2523 	QPointF cen = QPointF(bcx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bcy) + baseY + m_Doc->currentPage()->yOffset());
2524 	QPointF rig = QPointF(brx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bry) + baseY + m_Doc->currentPage()->yOffset());
2525 	QPointF top = QPointF(btx + baseX + m_Doc->currentPage()->xOffset(), (docHeight - bty) + baseY + m_Doc->currentPage()->yOffset());
2526 	QLineF rVec = QLineF(cen, rig);
2527 	QLineF tVec = QLineF(cen, top);
2528 	QLineF rNVec = tVec.translated(rVec.dx(), rVec.dy());
2529 	QPointF intRT = rNVec.p2();
2530 	gc->GrControl2 = FPoint(intRT.x(), intRT.y());
2531 	QLineF vg4 = QLineF(cen, intRT);
2532 	vg4.setAngle(vg4.angle()+180);
2533 	gc->GrControl4 = FPoint(vg4.x2(), vg4.y2());
2534 	QLineF tNVec = tVec.translated(-rVec.dx(), -rVec.dy());
2535 	QPointF intLT = tNVec.p2();
2536 	gc->GrControl1 = FPoint(intLT.x(), intLT.y());
2537 	QLineF vg3 = QLineF(cen, intLT);
2538 	vg3.setAngle(vg3.angle()+180);
2539 	gc->GrControl3 = FPoint(vg3.x2(), vg3.y2());
2540 	if (textLines.count() > 0)
2541 	{
2542 		if (textLines.last().textData.count() > 0)
2543 		{
2544 			textLines.last().textData.last().FillGradient = gc->FillGradient;
2545 			textLines.last().textData.last().GrControl1 = gc->GrControl1;
2546 			textLines.last().textData.last().GrControl2 = gc->GrControl2;
2547 			textLines.last().textData.last().GrControl3 = gc->GrControl3;
2548 			textLines.last().textData.last().GrControl4 = gc->GrControl4;
2549 			textLines.last().textData.last().GrControl5 = gc->GrControl5;
2550 		}
2551 	}
2552 }
2553 
handleFourColorGradient(QDataStream & ts)2554 void XarPlug::handleFourColorGradient(QDataStream &ts)
2555 {
2556 	XarStyle *gc = m_gc.top();
2557 	double b1x, b1y, b2x, b2y, b3x, b3y;
2558 	qint32 colRef1, colRef2, colRef3, colRef4;
2559 	readCoords(ts, b1x, b1y);
2560 	readCoords(ts, b2x, b2y);
2561 	readCoords(ts, b3x, b3y);
2562 	ts >> colRef1 >> colRef3 >> colRef4 >> colRef3;
2563 	gc->GrColorP1 = "Black";
2564 	gc->GrColorP2 = "Black";
2565 	gc->GrColorP3 = "Black";
2566 	gc->GrColorP4 = "Black";
2567 	if (XarColorMap.contains(colRef1))
2568 		gc->GrColorP1 = XarColorMap[colRef1].name;
2569 	if (XarColorMap.contains(colRef2))
2570 		gc->GrColorP2 = XarColorMap[colRef2].name;
2571 	if (XarColorMap.contains(colRef3))
2572 		gc->GrColorP3 = XarColorMap[colRef3].name;
2573 	if (XarColorMap.contains(colRef4))
2574 		gc->GrColorP4 = XarColorMap[colRef4].name;
2575 	gc->FillGradientType = 9;
2576 	if (textLines.count() > 0)
2577 	{
2578 		if (textLines.last().textData.count() > 0)
2579 		{
2580 			textLines.last().textData.last().FillGradientType = gc->FillGradientType;
2581 			textLines.last().textData.last().GrColorP1 = gc->GrColorP1;
2582 			textLines.last().textData.last().GrColorP2 = gc->GrColorP2;
2583 			textLines.last().textData.last().GrColorP3 = gc->GrColorP3;
2584 			textLines.last().textData.last().GrColorP4 = gc->GrColorP4;
2585 		}
2586 	}
2587 }
2588 
handleBitmapFill(QDataStream & ts,quint32 dataLen)2589 void XarPlug::handleBitmapFill(QDataStream &ts, quint32 dataLen)
2590 {
2591 	XarStyle *gc = m_gc.top();
2592 	qint32 bref;
2593 	double blx, bly, brx, bry, tlx, tly;
2594 	readCoords(ts, blx, bly);
2595 	readCoords(ts, brx, bry);
2596 	readCoords(ts, tlx, tly);
2597 	ts >> bref;
2598 	if (dataLen == 44)
2599 	{
2600 		double p, p1;
2601 		ts >> p >> p1;
2602 	}
2603 	double distX = distance(brx - blx, bry - bly);
2604 	double distY = distance(tlx - blx, tly - bly);
2605 	double rotB = xy2Deg(brx - blx, bry - bly);
2606 	double rotS = xy2Deg(tlx - blx, tly - bly);
2607 	if (patternRef.contains(bref))
2608 	{
2609 		ScPattern pat = m_Doc->docPatterns[patternRef[bref]];
2610 		gc->fillPattern = patternRef[bref];
2611 		gc->patternScaleX = distX / pat.width * 100;
2612 		gc->patternScaleY = distY / pat.height * 100;
2613 		gc->patternOffsetX = 0.0;
2614 		gc->patternOffsetY = 0.0;
2615 		gc->patternRotation = -rotB;
2616 		double skewX = rotS - 90 - rotB;
2617 		double a;
2618 		if (skewX == 90)
2619 			a = 1;
2620 		else if (skewX == 180)
2621 			a = 0;
2622 		else if (skewX == 270)
2623 			a = -1;
2624 		else if (skewX == 360)
2625 			a = 0;
2626 		else
2627 			a = tan(M_PI / 180.0 * skewX);
2628 		gc->patternSkewX = tan(a);
2629 		gc->patternSkewY = 0.0;
2630 		if (textLines.count() > 0)
2631 		{
2632 			if (textLines.last().textData.count() > 0)
2633 			{
2634 				textLines.last().textData.last().fillPattern = gc->fillPattern;
2635 				textLines.last().textData.last().patternScaleX = gc->patternScaleX;
2636 				textLines.last().textData.last().patternScaleY = gc->patternScaleY;
2637 				textLines.last().textData.last().patternOffsetX = gc->patternOffsetX;
2638 				textLines.last().textData.last().patternOffsetY = gc->patternOffsetY;
2639 				textLines.last().textData.last().patternRotation = gc->patternRotation;
2640 				textLines.last().textData.last().patternSkewX = gc->patternSkewX;
2641 				textLines.last().textData.last().patternSkewY = gc->patternSkewY;
2642 			}
2643 		}
2644 	}
2645 }
2646 
handleContoneBitmapFill(QDataStream & ts,quint32 dataLen)2647 void XarPlug::handleContoneBitmapFill(QDataStream &ts, quint32 dataLen)
2648 {
2649 	XarStyle *gc = m_gc.top();
2650 	qint32 bref, colRef1, colRef2;
2651 	double blx, bly, brx, bry, tlx, tly;
2652 	readCoords(ts, blx, bly);
2653 	readCoords(ts, brx, bry);
2654 	readCoords(ts, tlx, tly);
2655 	ts >> colRef1 >> colRef2;
2656 	ts >> bref;
2657 	if (dataLen == 52)
2658 	{
2659 		double p, p1;
2660 		ts >> p >> p1;
2661 	}
2662 	QString gCol1 = "Black";
2663 	QString gCol2 = "Black";
2664 	if (XarColorMap.contains(colRef1))
2665 		gCol1 = XarColorMap[colRef1].name;
2666 	if (XarColorMap.contains(colRef2))
2667 		gCol2 = XarColorMap[colRef2].name;
2668 	if (gCol1 == CommonStrings::None)
2669 		gCol1 = "White";
2670 	if (gCol2 == CommonStrings::None)
2671 		gCol2 = "White";
2672 	const ScColor& gradC1 = m_Doc->PageColors[gCol1];
2673 	QColor startC = ScColorEngine::getRGBColor(gradC1, m_Doc);
2674 	const ScColor& gradC2 = m_Doc->PageColors[gCol2];
2675 	QColor endC = ScColorEngine::getRGBColor(gradC2, m_Doc);
2676 	double distX = distance(brx - blx, bry - bly);
2677 	double distY = distance(tlx - blx, tly - bly);
2678 	double rotB = xy2Deg(brx - blx, bry - bly);
2679 	double rotS = xy2Deg(tlx - blx, tly - bly);
2680 	if (patternRef.contains(bref))
2681 	{
2682 		QString imgNam = m_Doc->docPatterns[patternRef[bref]].items.at(0)->externalFile();
2683 		QImage image;
2684 		image.load(imgNam);
2685 		int h = image.height();
2686 		int w = image.width();
2687 		int k;
2688 		int rS, gS, bS, rE, gE, bE, rR1, gR1, bR1, rR2, gR2, bR2;
2689 		startC.getRgb(&rS, &gS, &bS);
2690 		endC.getRgb(&rE, &gE, &bE);
2691 		QRgb *s;
2692 		QRgb r;
2693 		for (int yi = 0; yi < h; ++yi)
2694 		{
2695 			s = (QRgb*)(image.scanLine( yi ));
2696 			for (int xi = 0; xi < w; ++xi)
2697 			{
2698 				r = *s;
2699 				k = qMin(qRound(0.3 * qRed(r) + 0.59 * qGreen(r) + 0.11 * qBlue(r)), 255);
2700 				rR1 = qMin((rS * k) >> 8, 255);
2701 				gR1 = qMin((gS * k) >> 8, 255);
2702 				bR1 = qMin((bS * k) >> 8, 255);
2703 				rR2 = qMin((rE * k) >> 8, 255);
2704 				gR2 = qMin((gE * k) >> 8, 255);
2705 				bR2 = qMin((bE * k) >> 8, 255);
2706 				*s = qRgba(qMin(rR1+rR2, 255), qMin(gR1+gR2, 255), qMin(bR1+bR2, 255), qAlpha(r));
2707 				s++;
2708 			}
2709 		}
2710 		ScPattern pat = ScPattern();
2711 		pat.setDoc(m_Doc);
2712 		PageItem* newItem = new PageItem_ImageFrame(m_Doc, 0, 0, 1, 1, 0, CommonStrings::None, CommonStrings::None);
2713 		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_xar_XXXXXX.png");
2714 		tempFile->setAutoRemove(false);
2715 		tempFile->open();
2716 		QString fileName = getLongPathName(tempFile->fileName());
2717 		tempFile->close();
2718 		delete tempFile;
2719 		newItem->isTempFile = true;
2720 		newItem->isInlineImage = true;
2721 		image.setDotsPerMeterY(2834);
2722 		image.setDotsPerMeterX(2834);
2723 		image.save(fileName, "PNG");
2724 		if (newItem->loadImage(fileName, false, 72, false))
2725 		{
2726 			pat.width = image.width();
2727 			pat.height = image.height();
2728 			pat.scaleX = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
2729 			pat.scaleY = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
2730 			pat.pattern = newItem->pixm.qImage().copy();
2731 			newItem->setWidth(pat.pattern.width());
2732 			newItem->setHeight(pat.pattern.height());
2733 			newItem->SetRectFrame();
2734 			newItem->gXpos = 0.0;
2735 			newItem->gYpos = 0.0;
2736 			newItem->gWidth = pat.pattern.width();
2737 			newItem->gHeight = pat.pattern.height();
2738 			pat.items.append(newItem);
2739 		}
2740 		QString patternName = patternRef[bref]+"_"+newItem->itemName();
2741 		patternName = patternName.trimmed().simplified().replace(" ", "_");
2742 		m_Doc->addPattern(patternName, pat);
2743 		importedPatterns.append(patternName);
2744 		gc->fillPattern = patternName;
2745 		gc->patternScaleX = distX / pat.width * 100;
2746 		gc->patternScaleY = distY / pat.height * 100;
2747 		gc->patternOffsetX = 0.0;
2748 		gc->patternOffsetY = 0.0;
2749 		gc->patternRotation = -rotB;
2750 		double skewX = rotS - 90 - rotB;
2751 		double a;
2752 		if (skewX == 90)
2753 			a = 1;
2754 		else if (skewX == 180)
2755 			a = 0;
2756 		else if (skewX == 270)
2757 			a = -1;
2758 		else if (skewX == 360)
2759 			a = 0;
2760 		else
2761 			a = tan(M_PI / 180.0 * skewX);
2762 		gc->patternSkewX = tan(a);
2763 		gc->patternSkewY = 0.0;
2764 		if (textLines.count() > 0)
2765 		{
2766 			if (textLines.last().textData.count() > 0)
2767 			{
2768 				textLines.last().textData.last().fillPattern = gc->fillPattern;
2769 				textLines.last().textData.last().patternScaleX = gc->patternScaleX;
2770 				textLines.last().textData.last().patternScaleY = gc->patternScaleY;
2771 				textLines.last().textData.last().patternOffsetX = gc->patternOffsetX;
2772 				textLines.last().textData.last().patternOffsetY = gc->patternOffsetY;
2773 				textLines.last().textData.last().patternRotation = gc->patternRotation;
2774 				textLines.last().textData.last().patternSkewX = gc->patternSkewX;
2775 				textLines.last().textData.last().patternSkewY = gc->patternSkewY;
2776 			}
2777 		}
2778 	}
2779 }
2780 
handleBitmap(QDataStream & ts)2781 void XarPlug::handleBitmap(QDataStream &ts)
2782 {
2783 	XarStyle *gc = m_gc.top();
2784 	qint32 bref;
2785 	double blx, bly, brx, bry, tlx, tly, trix, triy;
2786 	readCoords(ts, blx, bly);
2787 	readCoords(ts, brx, bry);
2788 	readCoords(ts, tlx, tly);
2789 	readCoords(ts, trix, triy);
2790 	ts >> bref;
2791 	Coords.resize(0);
2792 	Coords.svgInit();
2793 	Coords.svgMoveTo(blx, docHeight - bly);
2794 	Coords.svgLineTo(brx, docHeight - bry);
2795 	Coords.svgLineTo(tlx, docHeight - tly);
2796 	Coords.svgLineTo(trix, docHeight - triy);
2797 	Coords.svgClosePath();
2798 	int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
2799 	finishItem(z);
2800 	PageItem *ite = m_Doc->Items->at(z);
2801 	if (patternRef.contains(bref))
2802 	{
2803 		QString imgNam = m_Doc->docPatterns[patternRef[bref]].items.at(0)->externalFile();
2804 		QImage image;
2805 		image.load(imgNam);
2806 		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_xar_XXXXXX.png");
2807 		tempFile->setAutoRemove(false);
2808 		tempFile->open();
2809 		QString fileName = getLongPathName(tempFile->fileName());
2810 		tempFile->close();
2811 		delete tempFile;
2812 		ite->isTempFile = true;
2813 		ite->isInlineImage = true;
2814 		image.save(fileName, "PNG");
2815 		m_Doc->loadPict(fileName, ite);
2816 		ite->setImageScalingMode(false, false);
2817 	}
2818 }
2819 
defineBitmap(QDataStream & ts,quint32 dataLen,quint32 tag)2820 void XarPlug::defineBitmap(QDataStream &ts, quint32 dataLen, quint32 tag)
2821 {
2822 	quint32 bytesRead = 0;
2823 	quint16 charC = 0;
2824 	ts >> charC;
2825 	bytesRead += 2;
2826 	QString XarName = "";
2827 	while (charC != 0)
2828 	{
2829 		XarName += QChar(charC);
2830 		ts >> charC;
2831 		bytesRead += 2;
2832 	}
2833 	if (tag == 71)
2834 	{
2835 		quint8 palcount, r, g, b;
2836 		ts >> palcount;
2837 		bytesRead++;
2838 		for (int a = 0; a < palcount + 1; a++)
2839 		{
2840 			ts >> r;
2841 			ts >> g;
2842 			ts >> b;
2843 			bytesRead += 3;
2844 		}
2845 	}
2846 	imageData.resize(dataLen - bytesRead);
2847 	ts.readRawData(imageData.data(), dataLen - bytesRead);
2848 	QImage image;
2849 	if (image.loadFromData(imageData))
2850 	{
2851 		bool rawAlpha = image.hasAlphaChannel();
2852 		image = image.convertToFormat(QImage::Format_ARGB32);
2853 		if ((tag == 68) && (rawAlpha))
2854 		{
2855 			int h = image.height();
2856 			int w = image.width();
2857 			QRgb *s;
2858 			QRgb r;
2859 			for (int yi = 0; yi < h; ++yi)
2860 			{
2861 				s = (QRgb*)(image.scanLine( yi ));
2862 				for (int xi = 0; xi < w; ++xi)
2863 				{
2864 					r = *s;
2865 					*s = qRgba(qRed(r), qGreen(r), qBlue(r), 255 - qAlpha(r));
2866 					s++;
2867 				}
2868 			}
2869 		}
2870 		ScPattern pat = ScPattern();
2871 		pat.setDoc(m_Doc);
2872 		PageItem* newItem = new PageItem_ImageFrame(m_Doc, 0, 0, 1, 1, 0, CommonStrings::None, CommonStrings::None);
2873 		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_xar_XXXXXX.png");
2874 		tempFile->setAutoRemove(false);
2875 		tempFile->open();
2876 		QString fileName = getLongPathName(tempFile->fileName());
2877 		tempFile->close();
2878 		delete tempFile;
2879 		newItem->isTempFile = true;
2880 		newItem->isInlineImage = true;
2881 		image.setDotsPerMeterY(2834);
2882 		image.setDotsPerMeterX(2834);
2883 		image.save(fileName, "PNG");
2884 		if (newItem->loadImage(fileName, false, 72, false))
2885 		{
2886 			pat.width = image.width();
2887 			pat.height = image.height();
2888 			pat.scaleX = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
2889 			pat.scaleY = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale;
2890 			pat.pattern = newItem->pixm.qImage().copy();
2891 			newItem->setWidth(pat.pattern.width());
2892 			newItem->setHeight(pat.pattern.height());
2893 			newItem->SetRectFrame();
2894 			newItem->gXpos = 0.0;
2895 			newItem->gYpos = 0.0;
2896 			newItem->gWidth = pat.pattern.width();
2897 			newItem->gHeight = pat.pattern.height();
2898 			pat.items.append(newItem);
2899 		}
2900 		QString patternName = "Pattern_"+newItem->itemName();
2901 		patternName = patternName.trimmed().simplified().replace(" ", "_");
2902 		m_Doc->addPattern(patternName, pat);
2903 		importedPatterns.append(patternName);
2904 		patternRef.insert(recordCounter, patternName);
2905 	}
2906 }
2907 
handleLineColor(QDataStream & ts)2908 void XarPlug::handleLineColor(QDataStream &ts)
2909 {
2910 	XarStyle *gc = m_gc.top();
2911 	qint32 val;
2912 	ts >> val;
2913 	if (XarColorMap.contains(val))
2914 	{
2915 		gc->StrokeCol = XarColorMap[val].name;
2916 		if (textLines.count() > 0)
2917 		{
2918 			if (textLines.last().textData.count() > 0)
2919 				textLines.last().textData.last().StrokeCol = gc->StrokeCol;
2920 		}
2921 	}
2922 }
2923 
handleLineWidth(QDataStream & ts)2924 void XarPlug::handleLineWidth(QDataStream &ts)
2925 {
2926 	XarStyle *gc = m_gc.top();
2927 	quint32 val;
2928 	ts >> val;
2929 	gc->LWidth = val / 1000.0;
2930 	if (textLines.count() > 0)
2931 	{
2932 		if (textLines.last().textData.count() > 0)
2933 			textLines.last().textData.last().LWidth = gc->LWidth;
2934 	}
2935 }
2936 
handleFlatLineTransparency(QDataStream & ts)2937 void XarPlug::handleFlatLineTransparency(QDataStream &ts)
2938 {
2939 	quint8 transVal, transType;
2940 	ts >> transVal >> transType;
2941 	XarStyle *gc = m_gc.top();
2942 	if (transType > 0)
2943 	{
2944 		gc->StrokeOpacity = transVal / 255.0;
2945 		if (textLines.count() > 0)
2946 		{
2947 			if (textLines.last().textData.count() > 0)
2948 				textLines.last().textData.last().StrokeOpacity = gc->StrokeOpacity;
2949 		}
2950 	}
2951 }
2952 
handleFlatFill(QDataStream & ts)2953 void XarPlug::handleFlatFill(QDataStream &ts)
2954 {
2955 	XarStyle *gc = m_gc.top();
2956 	qint32 val;
2957 	ts >> val;
2958 	if (XarColorMap.contains(val))
2959 	{
2960 		gc->FillCol = XarColorMap[val].name;
2961 		if (textLines.count() > 0)
2962 		{
2963 			if (textLines.last().textData.count() > 0)
2964 				textLines.last().textData.last().FillCol = gc->FillCol;
2965 		}
2966 	}
2967 }
2968 
createRectangleItem(QDataStream & ts,bool ellipse)2969 void XarPlug::createRectangleItem(QDataStream &ts, bool ellipse)
2970 {
2971 	XarStyle *gc = m_gc.top();
2972 	double centerX, centerY, majorAxis, minorAxis;
2973 	readCoords(ts, centerX, centerY);
2974 	readCoords(ts, majorAxis, minorAxis);
2975 	int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
2976 	Coords.resize(0);
2977 	Coords.svgInit();
2978 	QPainterPath path;
2979 	if (ellipse)
2980 		path.addEllipse(QPointF(majorAxis, minorAxis), majorAxis, minorAxis);
2981 	else
2982 		path = regularPolygonPath(majorAxis, minorAxis, 4, false, 0, 45, 0);
2983 	Coords.fromQPainterPath(path);
2984 	Coords.translate(-majorAxis / 2.0, -minorAxis / 2.0);
2985 	Coords.translate(centerX, -centerY);
2986 	Coords.translate(0, docHeight);
2987 	finishItem(z);
2988 }
2989 
createSimilarItem(QDataStream & ts)2990 void XarPlug::createSimilarItem(QDataStream &ts)
2991 {
2992 	XarStyle *gc = m_gc.top();
2993 	qint32 val;
2994 	ts >> val;
2995 	quint32 scX, skX, skY, scY;
2996 	double transX, transY;
2997 	ts >> scX >> skX >> skY >> scY;
2998 	readCoords(ts, transX, transY);
2999 	double scaleX = decodeFixed16(scX);
3000 	double scaleY = decodeFixed16(scY);
3001 	double skewX = decodeFixed16(skX);
3002 	double skewY = decodeFixed16(skY);
3003 	if ((pathMap.contains(val)) && (scX != 0) && (scY != 0))
3004 	{
3005 		PageItem* newItem;
3006 		int z = -1;
3007 		PageItem* ite = pathMap[val];
3008 		if (ite->realItemType() == PageItem::ImageFrame)
3009 			z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
3010 		else if (ite->realItemType() == PageItem::Polygon)
3011 			z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
3012 		else
3013 			z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
3014 		if (z > -1)
3015 		{
3016 			newItem = m_Doc->Items->at(z);
3017 			Coords = ite->PoLine.copy();
3018 			QTransform matrix(-scaleX, skewX, -skewY, scaleY, 0, 0);
3019 			Coords.map(matrix);
3020 			Coords.translate(transX, transY);
3021 			Coords.translate(ite->xPos(), ite->yPos());
3022 //			Coords.translate(0, docHeight);
3023 			newItem->PoLine = Coords.copy();
3024 //		QTransform matrix(scaleX, skewX, skewY, scaleY, 0, 0);
3025 //		ite->PoLine.map(matrix);
3026 //		ite->PoLine.translate(transX * scaleX, -transY * scaleY);
3027 			newItem->ClipEdited = true;
3028 			newItem->FrameType = 3;
3029 			FPoint wh = getMaxClipF(&newItem->PoLine);
3030 			newItem->setWidthHeight(wh.x(),wh.y());
3031 			newItem->setTextFlowMode(PageItem::TextFlowDisabled);
3032 			m_Doc->adjustItemSize(newItem);
3033 			Elements.append(newItem);
3034 			XarStyle *gc = m_gc.top();
3035 			gc->Elements.append(newItem);
3036 		}
3037 //		qDebug() << "Similar Item" << ite->itemName() << " -> " << newItem->itemName() << scX << skewX << skewY << scaleY << transX << transY;
3038 	}
3039 }
3040 
createPolygonItem(int type)3041 void XarPlug::createPolygonItem(int type)
3042 {
3043 	int z = -1;
3044 	XarStyle *gc = m_gc.top();
3045 	if (type == 0)
3046 		z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, CommonStrings::None, gc->StrokeCol);
3047 	else if (type == 1)
3048 		z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, CommonStrings::None);
3049 	else if (type == 2)
3050 		z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
3051 	else
3052 		return;
3053 	finishItem(z);
3054 }
3055 
createPolylineItem(int type)3056 void XarPlug::createPolylineItem(int type)
3057 {
3058 	int z = -1;
3059 	XarStyle *gc = m_gc.top();
3060 	if (type == 0)
3061 		z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, CommonStrings::None, gc->StrokeCol);
3062 	else if (type == 1)
3063 		z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, CommonStrings::None);
3064 	else if (type == 2)
3065 		z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, gc->LWidth, gc->FillCol, gc->StrokeCol);
3066 	else
3067 		return;
3068 	finishItem(z);
3069 //	PageItem *ite = m_Doc->Items->at(z);
3070 //	qDebug() << "Item" << ite->itemName() << type;
3071 }
3072 
handleBrushItem(QDataStream & ts)3073 void XarPlug::handleBrushItem(QDataStream &ts)
3074 {
3075 	quint32 handle;
3076 	qint32 spacing, offsetX, offsetY;
3077 	quint8 flags;
3078 	double rotate, scale;
3079 	ts >> handle;
3080 	ts >> spacing;
3081 	ts >> flags;
3082 	ts >> rotate;
3083 	ts >> offsetX >> offsetY;
3084 	ts >> scale;
3085 	ScPattern pat = m_Doc->docPatterns[brushRef[handle]];
3086 	XarStyle *gc = m_gc.top();
3087 	gc->strokePattern = brushRef[handle];
3088 	gc->patternScaleXS = scale * 100;
3089 	gc->patternScaleYS = scale * 100;
3090 	gc->patternOffsetXS = offsetX / 1000.0;
3091 	gc->patternOffsetYS = offsetY / 1000.0;
3092 	gc->patternRotationS = 0.0;
3093 	gc->patternSkewX = 0.0;
3094 	gc->patternSkewY = 0.0;
3095 	gc->patternSpace = (spacing / 1000.0) / static_cast<double>(m_Doc->docPatterns[brushRef[handle]].width);
3096 	gc->patternStrokePath = true;
3097 }
3098 
createBrushItem(QDataStream & ts)3099 void XarPlug::createBrushItem(QDataStream &ts)
3100 {
3101 	quint32 idNr;
3102 	ts >> idNr;
3103 	XarGroup gg;
3104 	gg.index = Elements.count();
3105 	gg.gcStackDepth = m_gc.count();
3106 	gg.clipping = false;
3107 	gg.idNr = idNr;
3108 	gg.isBrush = true;
3109 	int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None);
3110 	PageItem *neu = m_Doc->Items->at(z);
3111 	gg.groupItem = neu;
3112 	Elements.append(neu);
3113 	XarStyle *gc = m_gc.top();
3114 	gc->Elements.append(neu);
3115 	groupStack.push(gg);
3116 }
3117 
createGroupItem()3118 void XarPlug::createGroupItem()
3119 {
3120 	XarGroup gg;
3121 	gg.index = Elements.count();
3122 	gg.gcStackDepth = m_gc.count();
3123 	gg.clipping = false;
3124 	gg.idNr = 0;
3125 	gg.isBrush = false;
3126 	int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None);
3127 	PageItem *neu = m_Doc->Items->at(z);
3128 	gg.groupItem = neu;
3129 	Elements.append(neu);
3130 	XarStyle *gc = m_gc.top();
3131 	gc->Elements.append(neu);
3132 	groupStack.push(gg);
3133 }
3134 
createClipItem()3135 void XarPlug::createClipItem()
3136 {
3137 	XarGroup gg;
3138 	gg.index = Elements.count();
3139 	gg.gcStackDepth = m_gc.count();
3140 	gg.clipping = true;
3141 	gg.idNr = 0;
3142 	gg.isBrush = false;
3143 	int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None);
3144 	PageItem *neu = m_Doc->Items->at(z);
3145 	gg.groupItem = neu;
3146 	Elements.append(neu);
3147 	XarStyle *gc = m_gc.top();
3148 	gc->Elements.append(neu);
3149 	groupStack.push(gg);
3150 }
3151 
finishClip()3152 void XarPlug::finishClip()
3153 {
3154 	if (groupStack.count() > 0)
3155 		groupStack.top().clipping = false;
3156 }
3157 
finishItem(int z)3158 void XarPlug::finishItem(int z)
3159 {
3160 	XarStyle *gc = m_gc.top();
3161 	PageItem *ite = m_Doc->Items->at(z);
3162 	ite->PoLine = Coords.copy();
3163 	if (recordPath)
3164 		textPath = ite->PoLine.copy();
3165 	ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
3166 	ite->ClipEdited = true;
3167 	ite->FrameType = 3;
3168 	FPoint wh = getMaxClipF(&ite->PoLine);
3169 	ite->setWidthHeight(wh.x(),wh.y());
3170 	ite->setTextFlowMode(PageItem::TextFlowDisabled);
3171 	m_Doc->adjustItemSize(ite);
3172 	if (groupStack.count() > 0)
3173 	{
3174 		XarGroup gg = groupStack.top();
3175 		if (gg.clipping)
3176 		{
3177 			if (clipCoords.empty())
3178 			{
3179 				gc->clipPath = ite->PoLine.copy();
3180 				gc->clipPath.translate(ite->xPos(), ite->yPos());
3181 			}
3182 			else
3183 			{
3184 				gc->clipPath.setMarker();
3185 				gc->clipPath.putPoints(gc->clipPath.size(), ite->PoLine.size(), ite->PoLine);
3186 				m_Doc->Items->removeLast();
3187 				delete ite;
3188 				return;
3189 			}
3190 		}
3191 	}
3192 	Elements.append(ite);
3193 	gc->Elements.append(ite);
3194 	pathMap.insert(recordCounter, ite);
3195 //	qDebug() << "Item" << ite->itemName();
3196 }
3197 
handlePathRel(QDataStream & ts,quint32 len)3198 bool XarPlug::handlePathRel(QDataStream &ts, quint32 len)
3199 {
3200 	quint32 count = len / 9;
3201 	qint32 x, y;
3202 	quint8  verb, val;
3203 	double co1 = 0.0;
3204 	double co2 = 0.0;
3205 	double cx1 = 0.0;
3206 	double cy1 = 0.0;
3207 	double cx2 = 0.0;
3208 	double cy2 = 0.0;
3209 	double cx3 = 0.0;
3210 	double cy3 = 0.0;
3211 	FPoint currentPoint, startPoint;
3212 	int bezCount = 0;
3213 	bool closed = false;
3214 	bool wasFirst = true;
3215 	Coords.resize(0);
3216 	Coords.svgInit();
3217 	for (uint a = 0; a < count; a++)
3218 	{
3219 		ts >> verb;
3220 		ts >> val;
3221 		x = val;
3222 		ts >> val;
3223 		y = val;
3224 		ts >> val;
3225 		x = (x << 8) | val;
3226 		ts >> val;
3227 		y = (y << 8) | val;
3228 		ts >> val;
3229 		x = (x << 8) | val;
3230 		ts >> val;
3231 		y = (y << 8) | val;
3232 		ts >> val;
3233 		x = (x << 8) | val;
3234 		ts >> val;
3235 		y = (y << 8) | val;
3236 		co1 = x / 1000.0;
3237 		co2 = y / 1000.0;
3238 		switch (verb)
3239 		{
3240 			case 6:
3241 				if (wasFirst)
3242 				{
3243 					Coords.svgMoveTo(co1, docHeight - co2);
3244 					currentPoint = FPoint(co1, co2);
3245 					wasFirst = false;
3246 				}
3247 				else
3248 				{
3249 					currentPoint = FPoint(currentPoint.x() - co1, currentPoint.y() - co2);
3250 					Coords.svgMoveTo(currentPoint.x(), docHeight - currentPoint.y());
3251 				}
3252 				startPoint = currentPoint;
3253 				break;
3254 			case 2:
3255 			case 3:
3256 				currentPoint = FPoint(currentPoint.x() - co1, currentPoint.y() - co2);
3257 				Coords.svgLineTo(currentPoint.x(), docHeight - currentPoint.y());
3258 				if (verb == 3)
3259 				{
3260 					closed = true;
3261 					Coords.svgClosePath();
3262 					currentPoint = startPoint;
3263 				}
3264 				break;
3265 			case 4:
3266 			case 5:
3267 				if (bezCount == 0)
3268 				{
3269 					cx1 = currentPoint.x() - co1;
3270 					cy1 = currentPoint.y() - co2;
3271 					currentPoint = FPoint(cx1, cy1);
3272 					bezCount++;
3273 				}
3274 				else if (bezCount == 1)
3275 				{
3276 					cx2 = currentPoint.x() - co1;
3277 					cy2 = currentPoint.y() - co2;
3278 					currentPoint = FPoint(cx2, cy2);
3279 					bezCount++;
3280 				}
3281 				else if (bezCount == 2)
3282 				{
3283 					cx3 = currentPoint.x() - co1;
3284 					cy3 = currentPoint.y() - co2;
3285 					currentPoint = FPoint(cx3, cy3);
3286 					Coords.svgCurveToCubic(cx1, docHeight - cy1, cx2, docHeight - cy2, cx3, docHeight - cy3);
3287 					if (verb == 5)
3288 					{
3289 						closed = true;
3290 						Coords.svgClosePath();
3291 						currentPoint = startPoint;
3292 					}
3293 					bezCount = 0;
3294 				}
3295 				break;
3296 		}
3297 	}
3298 	return closed;
3299 }
3300 
handleLayerInfo(QDataStream & ts)3301 void XarPlug::handleLayerInfo(QDataStream &ts)
3302 {
3303 	quint16 charC = 0;
3304 	quint8 layerFlags;
3305 	ts >> layerFlags;
3306 	ts >> charC;
3307 	QString XarName = "";
3308 	while (charC != 0)
3309 	{
3310 		XarName += QChar(charC);
3311 		ts >> charC;
3312 	}
3313 	if (importerFlags & LoadSavePlugin::lfCreateDoc)
3314 	{
3315 		if (!firstLayer)
3316 		{
3317 			QStringList newNames;
3318 			m_Doc->orderedLayerList(&newNames);
3319 			if (!newNames.contains(XarName))
3320 				currentLayer = m_Doc->addLayer(XarName, true);
3321 		}
3322 		else
3323 			m_Doc->changeLayerName(currentLayer, XarName);
3324 		m_Doc->setLayerVisible(currentLayer, layerFlags & 1);
3325 		m_Doc->setLayerLocked(currentLayer, layerFlags & 2);
3326 		m_Doc->setLayerPrintable(currentLayer, layerFlags & 4);
3327 		firstLayer = false;
3328 		if (layerFlags & 8)
3329 			activeLayer = XarName;
3330 	}
3331 }
3332 
handleSpreadInfo(QDataStream & ts)3333 void XarPlug::handleSpreadInfo(QDataStream &ts)
3334 {
3335 	quint32 pgWidth, pgHeight, margin, bleed;
3336 	quint8 spreadFlags;
3337 	ts >> pgWidth >> pgHeight >> margin >> bleed;
3338 	ts >> spreadFlags;
3339 	double w = pgWidth / 1000.0;
3340 	double h = pgHeight / 1000.0;
3341 	docWidth = w;
3342 	docHeight = h;
3343 //	double m = margin / 1000.0;
3344 //	double b = bleed / 1000.0;
3345 //	qDebug() << "Spread Info Width" << w << "Height" << h << "Margin" << m << "Bleed" << b;
3346 	if (importerFlags & LoadSavePlugin::lfCreateDoc)
3347 	{
3348 		m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 1, 0, false, false);
3349 		m_Doc->setPageSize("Custom");
3350 		m_Doc->currentPage()->setSize("Custom");
3351 		m_Doc->currentPage()->setInitialHeight(docHeight);
3352 		m_Doc->currentPage()->setInitialWidth(docWidth);
3353 		m_Doc->currentPage()->setHeight(docHeight);
3354 		m_Doc->currentPage()->setWidth(docWidth);
3355 		m_Doc->currentPage()->initialMargins.set(0, 0, 0, 0);
3356 		m_Doc->reformPages(true);
3357 	}
3358 }
3359 
handleFirstPage(QDataStream & ts)3360 void XarPlug::handleFirstPage(QDataStream &ts)
3361 {
3362 	qDebug() << "Page Record";
3363 }
3364 
handlePage(QDataStream & ts)3365 void XarPlug::handlePage(QDataStream &ts)
3366 {
3367 	if (importerFlags & LoadSavePlugin::lfCreateDoc)
3368 	{
3369 		m_Doc->addPage(pagecount);
3370 		m_Doc->currentPage()->setSize("Custom");
3371 		m_Doc->currentPage()->setInitialHeight(docHeight);
3372 		m_Doc->currentPage()->setInitialWidth(docWidth);
3373 		m_Doc->currentPage()->setHeight(docHeight);
3374 		m_Doc->currentPage()->setWidth(docWidth);
3375 		m_Doc->currentPage()->initialMargins.set(0, 0, 0, 0);
3376 		m_Doc->currentPage()->setMasterPageNameNormal();
3377 		m_Doc->view()->addPage(pagecount, true);
3378 		pagecount++;
3379 	//	baseX = m_Doc->currentPage()->xOffset();
3380 	//	baseY = m_Doc->currentPage()->yOffset();
3381 	}
3382 }
3383 
handleComplexColor(QDataStream & ts)3384 void XarPlug::handleComplexColor(QDataStream &ts)
3385 {
3386 	QString tmpName = CommonStrings::None;
3387 	ScColor tmp;
3388 	ColorList::Iterator it;
3389 	quint8 Rc, Gc, Bc, colorModel, colorType;
3390 	quint16 charC = 0;
3391 	quint32 EntryIndex, component1, component2, component3, component4;
3392 	qint32 colorRef;
3393 	ts >> Rc >> Gc >> Bc >> colorModel >> colorType;
3394 	ts >> EntryIndex;
3395 	ts >> colorRef;
3396 	ts >> component1 >> component2 >> component3 >> component4;
3397 	ts >> charC;
3398 	QString XarName = "";
3399 	while (charC != 0)
3400 	{
3401 		XarName += QChar(charC);
3402 		ts >> charC;
3403 	}
3404 /*	QString colM = "";
3405 	switch (colorModel)
3406 	{
3407 		case 2:
3408 			colM = "RGB";
3409 			break;
3410 		case 3:
3411 			colM = "CMYK";
3412 			break;
3413 		case 4:
3414 			colM = "HSV";
3415 			break;
3416 		case 5:
3417 			colM = "Gray";
3418 			break;
3419 	}
3420 	QString colT = "";
3421 	switch (colorType)
3422 	{
3423 		case 0:
3424 			colT = "Normal";
3425 			break;
3426 		case 1:
3427 			colT = "Spot";
3428 			break;
3429 		case 2:
3430 			colT = "Tint";
3431 			break;
3432 		case 3:
3433 			colT = "Linked";
3434 			break;
3435 		case 4:
3436 			colT = "Shade";
3437 			break;
3438 	} */
3439 	double c1 = decodeColorComponent(component1);
3440 	double c2 = decodeColorComponent(component2);
3441 	double c3 = decodeColorComponent(component3);
3442 	double c4 = decodeColorComponent(component4);
3443 //	qDebug() << "Record" << recordCounter << "Complex Color" << XarName << colM << colT << colorRef;
3444 //	qDebug() << "\t\tComponents" << c1 << c2 << c3 << c4;
3445 	if ((!XarName.isEmpty()) && ((XarName == "White") || (XarName == "Black") || (m_Doc->PageColors.contains(XarName))))
3446 		tmpName = XarName;
3447 	else
3448 	{
3449 		QColor c = QColor(Rc, Gc, Bc);
3450 		if ((colorType == 0) || (colorType == 1))
3451 		{
3452 			if (colorModel == 3)
3453 			{
3454 				tmp.setColorF(c1, c2, c3, c4);
3455 				if (colorType == 1)
3456 					tmp.setSpotColor(true);
3457 				else
3458 					tmp.setSpotColor(false);
3459 				tmp.setRegistrationColor(false);
3460 				if (XarName.isEmpty())
3461 					tmpName = "FromXara" + c.name();
3462 				else
3463 					tmpName = XarName;
3464 				QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
3465 				if (fNam == tmpName)
3466 					importedColors.append(tmpName);
3467 				tmpName = fNam;
3468 			}
3469 			else
3470 			{
3471 				tmp.setRgbColor(Rc, Gc, Bc);
3472 				tmp.setSpotColor(false);
3473 				tmp.setRegistrationColor(false);
3474 				if (XarName.isEmpty())
3475 					tmpName = "FromXara"+c.name();
3476 				else
3477 					tmpName = XarName;
3478 				QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
3479 				if (fNam == tmpName)
3480 					importedColors.append(tmpName);
3481 				tmpName = fNam;
3482 			}
3483 		}
3484 		else
3485 		{
3486 			tmp.setRgbColor(Rc, Gc, Bc);
3487 			tmp.setSpotColor(false);
3488 			tmp.setRegistrationColor(false);
3489 			if (XarName.isEmpty())
3490 				tmpName = "FromXara"+c.name();
3491 			else
3492 				tmpName = XarName;
3493 			QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
3494 			if (fNam == tmpName)
3495 				importedColors.append(tmpName);
3496 			tmpName = fNam;
3497 		}
3498 	}
3499 	XarColor color;
3500 	color.colorType = colorType;
3501 	color.colorModel = colorModel;
3502 	color.colorRef = colorRef;
3503 	color.component1 = c1;
3504 	color.component2 = c2;
3505 	color.component3 = c3;
3506 	color.component1 = c4;
3507 	color.name = tmpName;
3508 	XarColorMap.insert(recordCounter, color);
3509 }
3510 
handleColorRGB(QDataStream & ts)3511 void XarPlug::handleColorRGB(QDataStream &ts)
3512 {
3513 	QString tmpName = CommonStrings::None;
3514 	ScColor tmp;
3515 	quint8 Rc, Gc, Bc;
3516 	ts >> Rc >> Gc >> Bc;
3517 	QColor c = QColor(Rc, Gc, Bc);
3518 	tmp.setRgbColor(Rc, Gc, Bc);
3519 	tmp.setSpotColor(false);
3520 	tmp.setRegistrationColor(false);
3521 	tmpName = "FromXara"+c.name();
3522 	QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
3523 	if (fNam == tmpName)
3524 		importedColors.append(tmpName);
3525 	tmpName = fNam;
3526 	XarColor color;
3527 	color.colorType = 0;
3528 	color.colorModel = 2;
3529 	color.colorRef = 0;
3530 	color.component1 = 0;
3531 	color.component2 = 0;
3532 	color.component3 = 0;
3533 	color.component1 = 0;
3534 	color.name = tmpName;
3535 	XarColorMap.insert(recordCounter, color);
3536 }
3537 
decodeColorComponent(quint32 data)3538 double XarPlug::decodeColorComponent(quint32 data)
3539 {
3540 	double ret = 0.0;
3541 	char man = (data & 0xFF000000) >> 24;
3542 	if (man >= 0)
3543 	{
3544 		ret = (data & 0x00FFFFFF) / 16777215.0;
3545 		ret = (ret + man);
3546 	}
3547 	else
3548 	{
3549 		ret = (~data & 0x00FFFFFF) / 16777215.0;
3550 		ret = (ret + ~man) * -1;
3551 	}
3552 	return ret;
3553 }
3554 
decodeFixed16(quint32 data)3555 double XarPlug::decodeFixed16(quint32 data)
3556 {
3557 	double ret = 0.0;
3558 	qint16 man = (data & 0xFFFF0000) >> 16;
3559 	if (man >= 0)
3560 	{
3561 		ret = (data & 0x0000FFFF) / 65536.0;
3562 		ret = (ret + man);
3563 	}
3564 	else
3565 	{
3566 		ret = (~data & 0x0000FFFF) / 65536.0;
3567 		ret = (ret + ~man) * -1;
3568 	}
3569 	return ret;
3570 }
3571 
readCoords(QDataStream & ts,double & x,double & y)3572 void XarPlug::readCoords(QDataStream &ts, double &x, double &y)
3573 {
3574 	qint32 xc, yc;
3575 	ts >> xc >> yc;
3576 	x = xc / 1000.0;
3577 	y = yc / 1000.0;
3578 }
3579 
addToAtomic(quint32 dataLen,QDataStream & ts)3580 void XarPlug::addToAtomic(quint32 dataLen, QDataStream &ts)
3581 {
3582 	quint32 l = dataLen / 4;
3583 	quint32 val;
3584 	for (quint32 a = 0; a < l; a++)
3585 	{
3586 		ts >> val;
3587 		atomicTags.append(val);
3588 	}
3589 }
3590 
addGraphicContext()3591 void XarPlug::addGraphicContext()
3592 {
3593 /*	XarStyle *gc2 = m_gc.top();
3594 	XarStyle *gc = new XarStyle;
3595 	if ( m_gc.top() )
3596 		*gc = *( m_gc.top() );
3597 	m_gc.push( gc );
3598 	if (gc2->Elements.count() > 0)
3599 		gc2->Elements.removeLast(); */
3600 	XarStyle *gc2 = m_gc.top();
3601 	XarStyle *gc = new XarStyle;
3602 	if ( m_gc.top() )
3603 		*gc = *( m_gc.top() );
3604 	m_gc.push( gc );
3605 	if (gc2->Elements.count() > 0)
3606 	{
3607 		PageItem* ite = gc2->Elements.last();
3608 		gc->Elements.clear();
3609 		gc->Elements.append(ite);
3610 		gc2->Elements.removeLast();
3611 	}
3612 }
3613 
popGraphicContext()3614 void XarPlug::popGraphicContext()
3615 {
3616 	XarStyle *gc = m_gc.pop();
3617 	if (pathGcStackIndex == m_gc.count())
3618 	{
3619 		inTextBlock = false;
3620 		recordPath = false;
3621 		pathGcStackIndex = 0;
3622 	}
3623 	if (groupStack.count() > 0)
3624 	{
3625 		XarGroup gg = groupStack.top();
3626 		if (gg.gcStackDepth == m_gc.count())
3627 		{
3628 			groupStack.pop();
3629 			if (gg.index + 1 == Elements.count())
3630 			{
3631 				Elements.removeLast();
3632 				m_Doc->Items->removeLast();
3633 				gc->Elements.removeAll(gg.groupItem);
3634 				delete gg.groupItem;
3635 			}
3636 			else
3637 			{
3638 				double minx =  std::numeric_limits<double>::max();
3639 				double miny =  std::numeric_limits<double>::max();
3640 				double maxx = -std::numeric_limits<double>::max();
3641 				double maxy = -std::numeric_limits<double>::max();
3642 				PageItem* groupItem = Elements.at(gg.index);
3643 				for (int a = gg.index+1; a < Elements.count(); ++a)
3644 				{
3645 					PageItem* currItem = Elements.at(a);
3646 					groupItem->groupItemList.append(currItem);
3647 					currItem->Parent = groupItem;
3648 					double x1, x2, y1, y2;
3649 					currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
3650 					minx = qMin(minx, x1);
3651 					miny = qMin(miny, y1);
3652 					maxx = qMax(maxx, x2);
3653 					maxy = qMax(maxy, y2);
3654 				}
3655 				groupItem->setXYPos(minx, miny, true);
3656 				groupItem->setWidthHeight(maxx - minx, maxy - miny, true);
3657 				groupItem->groupWidth = groupItem->width();
3658 				groupItem->groupHeight = groupItem->height();
3659 				groupItem->SetRectFrame();
3660 				groupItem->ClipEdited = true;
3661 				groupItem->FrameType = 3;
3662 				groupItem->setTextFlowMode(PageItem::TextFlowDisabled);
3663 				groupItem->setItemName( tr("Group%1").arg(m_Doc->GroupCounter));
3664 				if (!gc->clipPath.empty())
3665 				{
3666 					groupItem->PoLine = gc->clipPath.copy();
3667 					groupItem->PoLine.translate(-minx + baseX, -miny + baseY);
3668 					FPoint wh = getMaxClipF(&groupItem->PoLine);
3669 					groupItem->setWidthHeight(wh.x(),wh.y());
3670 					m_Doc->adjustItemSize(groupItem);
3671 				}
3672 				groupItem->AutoName = false;
3673 				groupItem->setFillTransparency(0);
3674 				groupItem->setLineTransparency(0);
3675 				m_Doc->GroupCounter++;
3676 				if (gg.isBrush)
3677 				{
3678 					m_Doc->DoDrawing = true;
3679 					QImage tmpImg = groupItem->DrawObj_toImage(qMin(qMax(groupItem->width(), groupItem->height()), 500.0));
3680 					ScPattern pat = ScPattern();
3681 					pat.setDoc(m_Doc);
3682 					pat.width = groupItem->width();
3683 					pat.height = groupItem->height();
3684 					pat.pattern = tmpImg;
3685 					pat.items.append(groupItem);
3686 					m_Doc->Items->removeAll(groupItem);
3687 					Elements.removeAll(groupItem);
3688 					QString patternName = "Pattern_"+groupItem->itemName();
3689 					patternName = patternName.trimmed().simplified().replace(" ", "_");
3690 					m_Doc->addPattern(patternName, pat);
3691 					importedPatterns.append(patternName);
3692 					m_Doc->DoDrawing = false;
3693 					brushRef.insert(gg.idNr, patternName);
3694 				}
3695 				for (int a = 0; a < groupItem->groupItemList.count(); ++a)
3696 				{
3697 					PageItem* currItem = groupItem->groupItemList.at(a);
3698 					currItem->gXpos = currItem->xPos() - groupItem->xPos();
3699 					currItem->gYpos = currItem->yPos() - groupItem->yPos();
3700 					currItem->Parent = groupItem;
3701 					m_Doc->Items->removeAll(currItem);
3702 					Elements.removeAll(currItem);
3703 				}
3704 			}
3705 		}
3706 	}
3707 	if (gc->Elements.count() > 0)
3708 	{
3709 		for (int a = 0; a < gc->Elements.count(); a++)
3710 		{
3711 			PageItem *item = gc->Elements.at(a);
3712 			if (item->isGroup())
3713 				continue;
3714 			if (!item->asPolyLine())
3715 			{
3716 				item->setFillColor(gc->FillCol);
3717 				item->setFillTransparency(gc->FillOpacity);
3718 				item->setFillBlendmode(gc->FillBlend);
3719 			}
3720 			item->setLineTransparency(gc->StrokeOpacity);
3721 			item->setLineWidth(gc->LWidth);
3722 			item->setLineColor(gc->StrokeCol);
3723 			item->setLineJoin(gc->PLineJoin);
3724 			item->setLineEnd(gc->PLineEnd);
3725 			item->setFillEvenOdd(gc->fillRule);
3726 			if (!gc->fillPattern.isEmpty())
3727 			{
3728 				item->setPattern(gc->fillPattern);
3729 				item->setPatternTransform(gc->patternScaleX, gc->patternScaleY, gc->patternOffsetX, gc->patternOffsetY, gc->patternRotation, gc->patternSkewX, gc->patternSkewY);
3730 				item->GrType = Gradient_Pattern;
3731 			}
3732 			if ((gc->FillGradientType == Gradient_Linear) || (gc->FillGradientType == Gradient_Radial))
3733 			{
3734 				item->GrType = gc->FillGradientType;
3735 				item->fill_gradient = gc->FillGradient;
3736 				item->setGradientVector(gc->GradFillX1 - item->xPos(), gc->GradFillY1 - item->yPos(), gc->GradFillX2 - item->xPos(), gc->GradFillY2 - item->yPos(), gc->GradFillX1 - item->xPos(), gc->GradFillY1 - item->yPos(), gc->GrScale, gc->GrSkew);
3737 			}
3738 			if (gc->FillGradientType == Gradient_4Colors)
3739 			{
3740 				item->GrType = gc->FillGradientType;
3741 				item->set4ColorGeometry(FPoint(0, 0), FPoint(item->width(), 0), FPoint(item->width(), item->height()), FPoint(0, item->height()));
3742 				item->set4ColorColors(gc->GrColorP1, gc->GrColorP2, gc->GrColorP3, gc->GrColorP4);
3743 			}
3744 			if (gc->FillGradientType == Gradient_Diamond)
3745 			{
3746 				item->GrType = gc->FillGradientType;
3747 				item->fill_gradient = gc->FillGradient;
3748 				FPoint p = FPoint(item->xPos(), item->yPos());
3749 				item->setDiamondGeometry(gc->GrControl1 - p, gc->GrControl2 - p, gc->GrControl3 - p, gc->GrControl4 - p, gc->GrControl5 - p);
3750 			}
3751 			if (gc->GradMask > 0)
3752 			{
3753 				item->GrMask = gc->GradMask;
3754 				if ((item->GrMask == GradMask_Linear) || (item->GrMask == GradMask_Radial))
3755 				{
3756 					item->mask_gradient = gc->MaskGradient;
3757 					item->setMaskVector(gc->GradMaskX1 - item->xPos(), gc->GradMaskY1 - item->yPos(), gc->GradMaskX2 - item->xPos(), gc->GradMaskY2 - item->yPos(), gc->GradMaskX1 - item->xPos(), gc->GradMaskY1 - item->yPos(), gc->GradMaskScale, gc->GradMaskSkew);
3758 				}
3759 				else
3760 				{
3761 					item->setMaskTransform(gc->patternMaskScaleX, gc->patternMaskScaleY, gc->patternMaskOffsetX, gc->patternMaskOffsetY, gc->patternMaskRotation, gc->patternMaskSkewX, gc->patternMaskSkewY);
3762 					item->setPatternMask(gc->maskPattern);
3763 				}
3764 			}
3765 			if (!gc->strokePattern.isEmpty())
3766 			{
3767 				item->setStrokePatternToPath(gc->patternStrokePath);
3768 				item->setStrokePattern(gc->strokePattern);
3769 				item->setStrokePatternTransform(gc->patternScaleXS, gc->patternScaleYS, gc->patternOffsetXS, gc->patternOffsetYS, gc->patternRotationS, gc->patternSkewXS, gc->patternSkewYS, gc->patternSpace);
3770 			}
3771 		}
3772 	}
3773 	delete gc;
3774 }
3775