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 -------------------
9 begin : Mon Dez 30 2013
10 copyright : (C) 2013 by Franz Schmid
11 email : Franz.Schmid@altmuehlnet.de
12 ***************************************************************************/
13
14
15 #if 0
16 #include <QByteArray>
17 #include <QCursor>
18 #include <QDrag>
19 #include <QFile>
20 #include <QList>
21 #include <QMessageBox>
22 #include <QMimeData>
23 #include <QRegExp>
24 #include <QStack>
25 #include <QDebug>
26
27 #include <cstdlib>
28 #include "importpages.h"
29 #include "../revenge/rawpainter.h"
30 #include <libetonyek/libetonyek.h>
31 #include <boost/shared_ptr.hpp>
32
33 #include "commonstrings.h"
34 #include "ui/customfdialog.h"
35 #include "fileloader.h"
36 #include "loadsaveplugin.h"
37 #include "ui/missing.h"
38 #include "ui/multiprogressdialog.h"
39 #include "pagesize.h"
40 #include "prefscontext.h"
41 #include "prefsfile.h"
42 #include "prefsmanager.h"
43 #include "prefstable.h"
44 #include "ui/propertiespalette.h"
45 #include "rawimage.h"
46 #include "scclocale.h"
47 #include "sccolorengine.h"
48 #include "scconfig.h"
49 #include "scmimedata.h"
50 #include "scpaths.h"
51 #include "scpattern.h"
52 #include "scribus.h"
53 #include "scribusXml.h"
54 #include "scribuscore.h"
55 #include "scribusview.h"
56 #include "sctextstream.h"
57 #include "selection.h"
58 #include "undomanager.h"
59 #include "util.h"
60 #include "util_formats.h"
61 #include "util_math.h"
62
63 extern SCRIBUS_API ScribusQApp * ScQApp;
64
65 PagesPlug::PagesPlug(ScribusDoc* doc, int flags) :
66 baseX(0.0),
67 baseY(0.0),
68 docWidth(0.0),
69 docHeight(0.0),
70 cancel(false),
71 firstPage(false),
72 pagecount(0),
73 mpagecount(0),
74 topMargin(0.0),
75 leftMargin(0.0),
76 rightMargin(0.0),
77 bottomMargin(0.0),
78 pgCols(0.0),
79 pgGap(0.0)
80 {
81 tmpSel=new Selection(this, false);
82 m_Doc=doc;
83 importerFlags = flags;
84 interactive = (flags & LoadSavePlugin::lfInteractive);
85 progressDialog = nullptr;
86 }
87
88 QImage PagesPlug::readThumbnail(QString fName)
89 {
90 QFileInfo fi = QFileInfo(fName);
91 double b, h;
92 b = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth;
93 h = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight;
94 docWidth = b;
95 docHeight = h;
96 progressDialog = nullptr;
97 m_Doc = new ScribusDoc();
98 m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
99 m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
100 m_Doc->addPage(0);
101 m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
102 baseX = m_Doc->currentPage()->xOffset();
103 baseY = m_Doc->currentPage()->yOffset();
104 Elements.clear();
105 m_Doc->setLoading(true);
106 m_Doc->DoDrawing = false;
107 m_Doc->scMW()->setScriptRunning(true);
108 QString CurDirP = QDir::currentPath();
109 QDir::setCurrent(fi.path());
110 if (convert(fName))
111 {
112 tmpSel->clear();
113 QDir::setCurrent(CurDirP);
114 if (Elements.count() > 1)
115 m_Doc->groupObjectsList(Elements);
116 m_Doc->DoDrawing = true;
117 m_Doc->m_Selection->delaySignalsOn();
118 QImage tmpImage;
119 if (Elements.count() > 0)
120 {
121 for (int dre=0; dre<Elements.count(); ++dre)
122 {
123 tmpSel->addItem(Elements.at(dre), true);
124 }
125 tmpSel->setGroupRect();
126 double xs = tmpSel->width();
127 double ys = tmpSel->height();
128 tmpImage = Elements.at(0)->DrawObj_toImage(500);
129 tmpImage.setText("XSize", QString("%1").arg(xs));
130 tmpImage.setText("YSize", QString("%1").arg(ys));
131 }
132 m_Doc->scMW()->setScriptRunning(false);
133 m_Doc->setLoading(false);
134 m_Doc->m_Selection->delaySignalsOff();
135 delete m_Doc;
136 return tmpImage;
137 }
138 else
139 {
140 QDir::setCurrent(CurDirP);
141 m_Doc->DoDrawing = true;
142 m_Doc->scMW()->setScriptRunning(false);
143 delete m_Doc;
144 }
145 return QImage();
146 }
147
148 bool PagesPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
149 {
150 QString fName = fNameIn;
151 bool success = false;
152 interactive = (flags & LoadSavePlugin::lfInteractive);
153 importerFlags = flags;
154 cancel = false;
155 double b, h;
156 bool ret = false;
157 QFileInfo fi = QFileInfo(fName);
158 if ( !ScCore->usingGUI() )
159 {
160 interactive = false;
161 showProgress = false;
162 }
163 if ( showProgress )
164 {
165 ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
166 progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
167 QStringList barNames, barTexts;
168 barNames << "GI";
169 barTexts << tr("Analyzing File:");
170 QList<bool> barsNumeric;
171 barsNumeric << false;
172 progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
173 progressDialog->setOverallTotalSteps(3);
174 progressDialog->setOverallProgress(0);
175 progressDialog->setProgress("GI", 0);
176 progressDialog->show();
177 connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
178 qApp->processEvents();
179 }
180 else
181 progressDialog = nullptr;
182 /* Set default Page to size defined in Preferences */
183 b = 0.0;
184 h = 0.0;
185 if (progressDialog)
186 {
187 progressDialog->setOverallProgress(1);
188 qApp->processEvents();
189 }
190 if (b == 0.0)
191 b = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth;
192 if (h == 0.0)
193 h = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight;
194 docWidth = b;
195 docHeight = h;
196 baseX = 0;
197 baseY = 0;
198 if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
199 {
200 m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
201 m_Doc->addPage(0);
202 m_Doc->view()->addPage(0, true);
203 baseX = 0;
204 baseY = 0;
205 }
206 else
207 {
208 if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
209 {
210 m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
211 ScCore->primaryMainWindow()->HaveNewDoc();
212 ret = true;
213 baseX = 0;
214 baseY = 0;
215 baseX = m_Doc->currentPage()->xOffset();
216 baseY = m_Doc->currentPage()->yOffset();
217 }
218 }
219 if ((!ret) && (interactive))
220 {
221 baseX = m_Doc->currentPage()->xOffset();
222 baseY = m_Doc->currentPage()->yOffset();
223 }
224 if ((ret) || (!interactive))
225 {
226 if (docWidth > docHeight)
227 m_Doc->setPageOrientation(1);
228 else
229 m_Doc->setPageOrientation(0);
230 m_Doc->setPageSize("Custom");
231 }
232 if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
233 m_Doc->view()->Deselect();
234 Elements.clear();
235 m_Doc->setLoading(true);
236 m_Doc->DoDrawing = false;
237 if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
238 m_Doc->view()->updatesOn(false);
239 m_Doc->scMW()->setScriptRunning(true);
240 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
241 QString CurDirP = QDir::currentPath();
242 QDir::setCurrent(fi.path());
243 if (convert(fName))
244 {
245 tmpSel->clear();
246 QDir::setCurrent(CurDirP);
247 if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
248 m_Doc->groupObjectsList(Elements);
249 m_Doc->DoDrawing = true;
250 m_Doc->scMW()->setScriptRunning(false);
251 m_Doc->setLoading(false);
252 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
253 if ((Elements.count() > 0) && (!ret) && (interactive))
254 {
255 if (flags & LoadSavePlugin::lfScripted)
256 {
257 bool loadF = m_Doc->isLoading();
258 m_Doc->setLoading(false);
259 m_Doc->changed();
260 m_Doc->setLoading(loadF);
261 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
262 {
263 m_Doc->m_Selection->delaySignalsOn();
264 for (int dre=0; dre<Elements.count(); ++dre)
265 {
266 m_Doc->m_Selection->addItem(Elements.at(dre), true);
267 }
268 m_Doc->m_Selection->delaySignalsOff();
269 m_Doc->m_Selection->setGroupRect();
270 if (m_Doc->view() != nullptr)
271 m_Doc->view()->updatesOn(true);
272 }
273 }
274 else
275 {
276 m_Doc->DragP = true;
277 m_Doc->DraggedElem = 0;
278 m_Doc->DragElements.clear();
279 m_Doc->m_Selection->delaySignalsOn();
280 for (int dre=0; dre<Elements.count(); ++dre)
281 {
282 tmpSel->addItem(Elements.at(dre), true);
283 }
284 tmpSel->setGroupRect();
285 ScElemMimeData* md = ScriXmlDoc::writeToMimeData(m_Doc, tmpSel);
286 m_Doc->itemSelection_DeleteItem(tmpSel);
287 m_Doc->view()->updatesOn(true);
288 if (importedPatterns.count() != 0)
289 {
290 for (int cd = 0; cd < importedPatterns.count(); cd++)
291 {
292 m_Doc->docPatterns.remove(importedPatterns[cd]);
293 }
294 }
295 if (importedColors.count() != 0)
296 {
297 for (int cd = 0; cd < importedColors.count(); cd++)
298 {
299 m_Doc->PageColors.remove(importedColors[cd]);
300 }
301 }
302 m_Doc->m_Selection->delaySignalsOff();
303 // We must copy the TransationSettings object as it is owned
304 // by handleObjectImport method afterwards
305 TransactionSettings* transacSettings = new TransactionSettings(trSettings);
306 m_Doc->view()->handleObjectImport(md, transacSettings);
307 m_Doc->DragP = false;
308 m_Doc->DraggedElem = 0;
309 m_Doc->DragElements.clear();
310 }
311 }
312 else
313 {
314 m_Doc->changed();
315 m_Doc->reformPages();
316 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
317 m_Doc->view()->updatesOn(true);
318 }
319 success = true;
320 }
321 else
322 {
323 QDir::setCurrent(CurDirP);
324 m_Doc->DoDrawing = true;
325 m_Doc->scMW()->setScriptRunning(false);
326 m_Doc->view()->updatesOn(true);
327 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
328 }
329 if (interactive)
330 m_Doc->setLoading(false);
331 //CB If we have a gui we must refresh it if we have used the progressbar
332 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
333 {
334 if ((showProgress) && (!interactive))
335 m_Doc->view()->DrawNew();
336 }
337 qApp->restoreOverrideCursor();
338 return success;
339 }
340
341 PagesPlug::~PagesPlug()
342 {
343 if (progressDialog)
344 delete progressDialog;
345 delete tmpSel;
346 }
347
348 using boost::shared_ptr;
349 using libetonyek::EtonyekDocument;
350
351 bool PagesPlug::convert(QString fn)
352 {
353 importedColors.clear();
354 importedPatterns.clear();
355
356 QFile file(fn);
357 if (!file.exists())
358 {
359 qDebug() << "File " << QFile::encodeName(fn).data() << " does not exist";
360 return false;
361 }
362
363 shared_ptr<librevenge::RVNGInputStream> input;
364 if (librevenge::RVNGDirectoryStream::isDirectory(QFile::encodeName(fn).data()))
365 input.reset(new librevenge::RVNGDirectoryStream(QFile::encodeName(fn).data()));
366 else
367 input.reset(new librevenge::RVNGFileStream(QFile::encodeName(fn).data()));
368 EtonyekDocument::Type type = EtonyekDocument::TYPE_UNKNOWN;
369 const EtonyekDocument::Confidence confidence = EtonyekDocument::isSupported(input.get(), &type);
370 if ((EtonyekDocument::CONFIDENCE_NONE == confidence) || (EtonyekDocument::TYPE_PAGES != type))
371 {
372 qDebug() << "ERROR: Unsupported file format!";
373 return false;
374 }
375 if (EtonyekDocument::CONFIDENCE_SUPPORTED_PART == confidence)
376 input.reset(librevenge::RVNGDirectoryStream::createForParent(QFile::encodeName(fn).data()));
377 RawPainterPres painter(m_Doc, baseX, baseY, docWidth, docHeight, importerFlags, &Elements, &importedColors, &importedPatterns, tmpSel, "pages");
378 if (!EtonyekDocument::parse(input.get(), &painter))
379 {
380 qDebug() << "ERROR: Import failed!";
381 if (progressDialog)
382 progressDialog->close();
383 if (importerFlags & LoadSavePlugin::lfCreateDoc)
384 {
385 ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
386 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
387 QMessageBox::warning(mw, CommonStrings::trWarning, tr("Parsing failed!\n\nPlease submit your file (if possible) to the\nDocument Liberation Project http://www.documentliberation.org"), 1, 0, 0);
388 qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
389 }
390 return false;
391 }
392 if (Elements.count() == 0)
393 {
394 if (importedColors.count() != 0)
395 {
396 for (int cd = 0; cd < importedColors.count(); cd++)
397 {
398 m_Doc->PageColors.remove(importedColors[cd]);
399 }
400 }
401 if (importedPatterns.count() != 0)
402 {
403 for (int cd = 0; cd < importedPatterns.count(); cd++)
404 {
405 m_Doc->docPatterns.remove(importedPatterns[cd]);
406 }
407 }
408 }
409 if (progressDialog)
410 progressDialog->close();
411 return true;
412 }
413 #else
414
415 #include <QByteArray>
416 #include <QCursor>
417 #include <QDrag>
418 #include <QFile>
419 #include <QList>
420 #include <QMimeData>
421 #include <QRegExp>
422 #include <QStack>
423 #include <QUrl>
424 #include <QDebug>
425
426 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
427 #define _USE_MATH_DEFINES
428 #endif
429
430 #include <cstdlib>
431 #include <climits>
432 #include <limits>
433
434 #include "commonstrings.h"
435
436 #include "importpages.h"
437
438
439 #include "loadsaveplugin.h"
440 #include "pageitem_table.h"
441 #include "pagesize.h"
442 #include "prefscontext.h"
443 #include "prefsfile.h"
444 #include "prefsmanager.h"
445 #include "prefstable.h"
446 #include "qtiocompressor.h"
447 #include "rawimage.h"
448 #include "scclocale.h"
449 #include "sccolorengine.h"
450 #include "scconfig.h"
451 #include "scmimedata.h"
452 #include "scpaths.h"
453 #include "scribusXml.h"
454 #include "scribuscore.h"
455 #include "scribusdoc.h"
456 #include "scribusview.h"
457 #include "sctextstream.h"
458 #include "selection.h"
459 #include "third_party/zip/scribus_zip.h"
460 #include "ui/customfdialog.h"
461 #include "ui/missing.h"
462 #include "ui/multiprogressdialog.h"
463 #include "ui/propertiespalette.h"
464 #include "undomanager.h"
465 #include "util.h"
466 #include "util_formats.h"
467 #include "util_math.h"
468
PagesPlug(ScribusDoc * doc,int flags)469 PagesPlug::PagesPlug(ScribusDoc* doc, int flags)
470 : baseX(0.0),
471 baseY(0.0),
472 docWidth(0.0),
473 docHeight(0.0),
474 m_Doc(doc),
475 importerFlags(flags),
476 progressDialog(nullptr),
477 cancel(false),
478 firstPage(false),
479 pagecount(0),
480 mpagecount(0),
481 topMargin(0.0),
482 leftMargin(0.0),
483 rightMargin(0.0),
484 bottomMargin(0.0),
485 pgCols(0.0),
486 pgGap(0.0),
487 uz(nullptr)
488 {
489 tmpSel = new Selection(this, false);
490 interactive = (flags & LoadSavePlugin::lfInteractive);
491 }
492
readThumbnail(const QString & fName)493 QImage PagesPlug::readThumbnail(const QString& fName)
494 {
495 QImage tmp;
496 if (!QFile::exists(fName))
497 return QImage();
498 progressDialog = nullptr;
499 uz = new ScZipHandler();
500 if (!uz->open(fName))
501 {
502 delete uz;
503 if (progressDialog)
504 progressDialog->close();
505 return QImage();
506 }
507 if (uz->contains("QuickLook/Thumbnail.jpg"))
508 {
509 QByteArray im;
510 if (!uz->read("QuickLook/Thumbnail.jpg", im))
511 return QImage();
512 tmp = QImage::fromData(im);
513 QDomDocument designMapDom;
514 QByteArray f;
515 int xs = 0;
516 int ys = 0;
517 if (uz->contains("index.xml"))
518 {
519 if (uz->read("index.xml", f))
520 {
521 if (designMapDom.setContent(f))
522 {
523 QDomElement docElem = designMapDom.documentElement();
524 for (QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
525 {
526 if (drawPag.tagName() == "sl:slprint-info")
527 {
528 xs = drawPag.attribute("sl:page-width", "0").toInt();
529 ys = drawPag.attribute("sl:page-height", "0").toInt();
530 }
531 }
532 }
533 }
534 }
535 tmp.setText("XSize", QString("%1").arg(xs));
536 tmp.setText("YSize", QString("%1").arg(ys));
537 }
538 /* else
539 {
540 QFileInfo fi = QFileInfo(fName);
541 baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
542 docWidth = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth;
543 docHeight = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight;
544 m_Doc = new ScribusDoc();
545 m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
546 m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
547 m_Doc->addPage(0);
548 m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
549 baseX = m_Doc->currentPage()->xOffset();
550 baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0;
551 Elements.clear();
552 m_Doc->setLoading(true);
553 m_Doc->DoDrawing = false;
554 m_Doc->scMW()->setScriptRunning(true);
555 QString CurDirP = QDir::currentPath();
556 QDir::setCurrent(fi.path());
557 importedColors.clear();
558 importedPatterns.clear();
559 conversionFactor = 72.0 / 96.0;
560 loadedFonts.clear();
561 linkTargets.clear();
562 linkSources.clear();
563 if (uz->contains("FixedDocSeq.fdseq"))
564 parseDocSequence("FixedDocSeq.fdseq");
565 else if (uz->contains("FixedDocumentSequence.fdseq"))
566 parseDocSequence("FixedDocumentSequence.fdseq");
567 if (Elements.count() > 0)
568 {
569 tmpSel->clear();
570 QDir::setCurrent(CurDirP);
571 if (Elements.count() > 1)
572 m_Doc->groupObjectsList(Elements);
573 m_Doc->DoDrawing = true;
574 m_Doc->m_Selection->delaySignalsOn();
575 if (Elements.count() > 0)
576 {
577 for (int dre=0; dre<Elements.count(); ++dre)
578 {
579 tmpSel->addItem(Elements.at(dre), true);
580 }
581 tmpSel->setGroupRect();
582 double xs = tmpSel->width();
583 double ys = tmpSel->height();
584 tmp = Elements.at(0)->DrawObj_toImage(500);
585 tmp.setText("XSize", QString("%1").arg(xs));
586 tmp.setText("YSize", QString("%1").arg(ys));
587 }
588 m_Doc->scMW()->setScriptRunning(false);
589 m_Doc->setLoading(false);
590 m_Doc->m_Selection->delaySignalsOff();
591 delete m_Doc;
592 }
593 else
594 {
595 QDir::setCurrent(CurDirP);
596 m_Doc->DoDrawing = true;
597 m_Doc->scMW()->setScriptRunning(false);
598 delete m_Doc;
599 }
600 }*/
601 uz->close();
602 delete uz;
603 return tmp;
604 }
605
import(const QString & fNameIn,const TransactionSettings & trSettings,int flags,bool showProgress)606 bool PagesPlug::import(const QString& fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
607 {
608 bool success = false;
609 interactive = (flags & LoadSavePlugin::lfInteractive);
610 importerFlags = flags;
611 cancel = false;
612 bool ret = false;
613 firstPage = true;
614 pagecount = 1;
615 mpagecount = 0;
616 QFileInfo fi = QFileInfo(fNameIn);
617 if ( !ScCore->usingGUI() )
618 {
619 interactive = false;
620 showProgress = false;
621 }
622 if ( showProgress )
623 {
624 ScribusMainWindow* mw=(m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW();
625 progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
626 QStringList barNames("GI");
627 QStringList barTexts(tr("Analyzing File:"));
628 QList<bool> barsNumeric;
629 barsNumeric << false;
630 progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
631 progressDialog->setOverallTotalSteps(3);
632 progressDialog->setOverallProgress(0);
633 progressDialog->setProgress("GI", 0);
634 progressDialog->show();
635 connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
636 qApp->processEvents();
637 }
638 else
639 progressDialog = nullptr;
640 if (progressDialog)
641 {
642 progressDialog->setOverallProgress(1);
643 qApp->processEvents();
644 }
645 /* Set default Page to size defined in Preferences */
646 docWidth = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth;
647 docHeight = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight;
648 baseX = 0;
649 baseY = 0;
650 if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
651 {
652 m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
653 m_Doc->addPage(0);
654 m_Doc->view()->addPage(0, true);
655 baseX = 0;
656 baseY = 0;
657 }
658 else
659 {
660 if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
661 {
662 m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
663 ScCore->primaryMainWindow()->HaveNewDoc();
664 ret = true;
665 baseX = 0;
666 baseY = 0;
667 baseX = m_Doc->currentPage()->xOffset();
668 baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0;
669 }
670 }
671 if ((!ret) && (interactive))
672 {
673 baseX = m_Doc->currentPage()->xOffset();
674 baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0;
675 }
676 if ((ret) || (!interactive))
677 {
678 if (docWidth > docHeight)
679 m_Doc->setPageOrientation(1);
680 else
681 m_Doc->setPageOrientation(0);
682 m_Doc->setPageSize("Custom");
683 }
684 if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
685 m_Doc->view()->deselectItems();
686 Elements.clear();
687 m_Doc->setLoading(true);
688 m_Doc->DoDrawing = false;
689 if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr))
690 m_Doc->view()->updatesOn(false);
691 m_Doc->scMW()->setScriptRunning(true);
692 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
693 QString CurDirP = QDir::currentPath();
694 QDir::setCurrent(fi.path());
695 if (convert(fNameIn))
696 {
697 tmpSel->clear();
698 QDir::setCurrent(CurDirP);
699 if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
700 m_Doc->groupObjectsList(Elements);
701 m_Doc->DoDrawing = true;
702 m_Doc->scMW()->setScriptRunning(false);
703 m_Doc->setLoading(false);
704 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
705 if ((Elements.count() > 0) && (!ret) && (interactive))
706 {
707 if (flags & LoadSavePlugin::lfScripted)
708 {
709 bool loadF = m_Doc->isLoading();
710 m_Doc->setLoading(false);
711 m_Doc->changed();
712 m_Doc->setLoading(loadF);
713 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
714 {
715 m_Doc->m_Selection->delaySignalsOn();
716 for (int dre=0; dre<Elements.count(); ++dre)
717 {
718 m_Doc->m_Selection->addItem(Elements.at(dre), true);
719 }
720 m_Doc->m_Selection->delaySignalsOff();
721 m_Doc->m_Selection->setGroupRect();
722 if (m_Doc->view() != nullptr)
723 m_Doc->view()->updatesOn(true);
724 }
725 }
726 else
727 {
728 m_Doc->DragP = true;
729 m_Doc->DraggedElem = nullptr;
730 m_Doc->DragElements.clear();
731 m_Doc->m_Selection->delaySignalsOn();
732 for (int dre=0; dre<Elements.count(); ++dre)
733 {
734 tmpSel->addItem(Elements.at(dre), true);
735 }
736 tmpSel->setGroupRect();
737 ScElemMimeData* md = ScriXmlDoc::writeToMimeData(m_Doc, tmpSel);
738 m_Doc->itemSelection_DeleteItem(tmpSel);
739 m_Doc->view()->updatesOn(true);
740 if ((importedColors.count() != 0) && (!((flags & LoadSavePlugin::lfKeepGradients) || (flags & LoadSavePlugin::lfKeepColors) || (flags & LoadSavePlugin::lfKeepPatterns))))
741 {
742 for (int cd = 0; cd < importedColors.count(); cd++)
743 {
744 m_Doc->PageColors.remove(importedColors[cd]);
745 }
746 }
747 if ((importedPatterns.count() != 0) && (!(flags & LoadSavePlugin::lfKeepPatterns)))
748 {
749 for (int cd = 0; cd < importedPatterns.count(); cd++)
750 {
751 m_Doc->docPatterns.remove(importedPatterns[cd]);
752 }
753 }
754 m_Doc->m_Selection->delaySignalsOff();
755 // We must copy the TransationSettings object as it is owned
756 // by handleObjectImport method afterwards
757 TransactionSettings* transacSettings = new TransactionSettings(trSettings);
758 m_Doc->view()->handleObjectImport(md, transacSettings);
759 m_Doc->DragP = false;
760 m_Doc->DraggedElem = nullptr;
761 m_Doc->DragElements.clear();
762 }
763 }
764 else
765 {
766 m_Doc->changed();
767 m_Doc->reformPages();
768 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
769 m_Doc->view()->updatesOn(true);
770 }
771 success = true;
772 }
773 else
774 {
775 QDir::setCurrent(CurDirP);
776 m_Doc->DoDrawing = true;
777 m_Doc->scMW()->setScriptRunning(false);
778 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
779 m_Doc->view()->updatesOn(true);
780 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
781 success = false;
782 }
783 if (interactive)
784 m_Doc->setLoading(false);
785 //CB If we have a gui we must refresh it if we have used the progressbar
786 if (!(flags & LoadSavePlugin::lfLoadAsPattern))
787 {
788 if ((showProgress) && (!interactive))
789 m_Doc->view()->DrawNew();
790 }
791 qApp->restoreOverrideCursor();
792 return success;
793 }
794
~PagesPlug()795 PagesPlug::~PagesPlug()
796 {
797 delete progressDialog;
798 delete tmpSel;
799 }
800
convert(const QString & fn)801 bool PagesPlug::convert(const QString& fn)
802 {
803 importedColors.clear();
804 importedPatterns.clear();
805 m_StyleSheets.clear();
806 m_currentStyleSheet.clear();
807 if (progressDialog)
808 {
809 progressDialog->setOverallProgress(2);
810 progressDialog->setLabel("GI", tr("Generating Items"));
811 qApp->processEvents();
812 }
813
814 uz = new ScZipHandler();
815 if (!uz->open(fn))
816 {
817 delete uz;
818 if (progressDialog)
819 progressDialog->close();
820 return false;
821 }
822 bool retVal = false;
823 if (uz->contains("index.xml"))
824 retVal = parseDocReference("index.xml", false);
825 else if (uz->contains("index.xml.gz"))
826 retVal = parseDocReference("index.xml.gz", true);
827 uz->close();
828 delete uz;
829 if (progressDialog)
830 progressDialog->close();
831 return retVal;
832 }
833
parseDocReference(const QString & designMap,bool compressed)834 bool PagesPlug::parseDocReference(const QString& designMap, bool compressed)
835 {
836 QByteArray f;
837 QDomDocument designMapDom;
838 if (!uz->read(designMap, f))
839 return false;
840 if (compressed)
841 {
842 QTemporaryFile *tmpFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_zip_XXXXXX.dat");
843 if (tmpFile == nullptr)
844 return false;
845 tmpFile->open();
846 QString fname = getLongPathName(tmpFile->fileName());
847 tmpFile->write(f);
848 tmpFile->close();
849 QFile file(fname);
850 QtIOCompressor compressor(&file);
851 compressor.setStreamFormat(QtIOCompressor::GzipFormat);
852 compressor.open(QIODevice::ReadOnly);
853 f = compressor.readAll();
854 compressor.close();
855 if (f.isEmpty())
856 {
857 delete tmpFile;
858 return false;
859 }
860 delete tmpFile;
861 }
862 QString errorMsg = "";
863 int errorLine = 0;
864 int errorColumn = 0;
865 if (!designMapDom.setContent(f, &errorMsg, &errorLine, &errorColumn))
866 {
867 qDebug() << "Error loading File" << errorMsg << "at Line" << errorLine << "Column" << errorColumn;
868 return false;
869 }
870 papersize = "Custom";
871 QDomElement docElem = designMapDom.documentElement();
872 for (QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
873 {
874 if (drawPag.tagName() == "sl:slprint-info")
875 {
876 docWidth = drawPag.attribute("sl:page-width", "0").toDouble();
877 docHeight = drawPag.attribute("sl:page-height", "0").toDouble();
878 for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement())
879 {
880 if (sp.tagName() == "sf:page-margins")
881 {
882 topMargin = sp.attribute("sf:top", "0").toDouble();
883 leftMargin = sp.attribute("sf:left", "0").toDouble();
884 rightMargin = sp.attribute("sf:right", "0").toDouble();
885 bottomMargin = sp.attribute("sf:bottom", "0").toDouble();
886 pgCols = m_Doc->PageSp;
887 pgGap = m_Doc->PageSpa;
888 }
889 }
890 if (importerFlags & LoadSavePlugin::lfCreateDoc)
891 {
892 m_Doc->setPage(docWidth, docHeight, topMargin, leftMargin, rightMargin, bottomMargin, pgCols, pgGap, false, false);
893 m_Doc->setPageSize(papersize);
894 m_Doc->currentPage()->setSize(papersize);
895 m_Doc->currentPage()->setInitialHeight(docHeight);
896 m_Doc->currentPage()->setInitialWidth(docWidth);
897 m_Doc->currentPage()->setHeight(docHeight);
898 m_Doc->currentPage()->setWidth(docWidth);
899 m_Doc->currentPage()->initialMargins.setTop(topMargin);
900 m_Doc->currentPage()->initialMargins.setBottom(bottomMargin);
901 m_Doc->currentPage()->initialMargins.setLeft(leftMargin);
902 m_Doc->currentPage()->initialMargins.setRight(rightMargin);
903 m_Doc->reformPages(true);
904 }
905 baseX = m_Doc->currentPage()->xOffset();
906 baseY = m_Doc->currentPage()->yOffset();
907 }
908 else if (drawPag.tagName() == "sl:section-prototypes")
909 {
910 for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement())
911 {
912 if (sp.tagName() == "sl:prototype")
913 {
914 QString pageNam = sp.attribute("sl:name");
915 if (!pageNam.isEmpty())
916 {
917 if (importerFlags & LoadSavePlugin::lfCreateDoc)
918 {
919 m_Doc->setMasterPageMode(true);
920 ScPage *oldCur = m_Doc->currentPage();
921 ScPage *addedPage = m_Doc->addMasterPage(mpagecount, pageNam);
922 m_Doc->setCurrentPage(addedPage);
923 addedPage->clearMasterPageName();
924 m_Doc->view()->addPage(mpagecount, true);
925 baseX = addedPage->xOffset();
926 baseY = addedPage->yOffset();
927 mpagecount++;
928 for (QDomElement spd = sp.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement())
929 {
930 if (spd.tagName() == "sl:stylesheet")
931 {
932 parseStyleSheets(spd);
933 m_currentStyleSheet = spd.attribute("sfa:ID");
934 }
935 else if (spd.tagName() == "sl:drawables")
936 {
937 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
938 {
939 if (spe.tagName() == "sl:page-group")
940 parsePageReference(spe);
941 }
942 }
943 }
944 m_Doc->setCurrentPage(oldCur);
945 m_Doc->setMasterPageMode(false);
946 }
947 }
948 }
949 }
950 }
951 else if (drawPag.tagName() == "sl:stylesheet")
952 {
953 parseStyleSheets(drawPag);
954 m_currentStyleSheet = drawPag.attribute("sfa:ID");
955 }
956 else if (drawPag.tagName() == "sl:drawables")
957 {
958 for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement())
959 {
960 if (sp.tagName() == "sl:page-group")
961 {
962 qDebug() << "Reading Page" << sp.attribute("sl:page");
963 if (importerFlags & LoadSavePlugin::lfCreateDoc)
964 {
965 if (firstPage)
966 {
967 topMargin = m_Doc->marginsVal().top();
968 leftMargin = m_Doc->marginsVal().left();
969 rightMargin = m_Doc->marginsVal().right();
970 bottomMargin = m_Doc->marginsVal().bottom();
971 m_Doc->setPage(docWidth, docHeight, topMargin, leftMargin, rightMargin, bottomMargin, m_Doc->PageSp, m_Doc->PageSpa, false, false);
972 m_Doc->setPageSize("Custom");
973 m_Doc->currentPage()->setSize("Custom");
974 m_Doc->currentPage()->setInitialHeight(docHeight);
975 m_Doc->currentPage()->setInitialWidth(docWidth);
976 m_Doc->currentPage()->setHeight(docHeight);
977 m_Doc->currentPage()->setWidth(docWidth);
978 m_Doc->currentPage()->initialMargins.setTop(topMargin);
979 m_Doc->currentPage()->initialMargins.setBottom(bottomMargin);
980 m_Doc->currentPage()->initialMargins.setLeft(leftMargin);
981 m_Doc->currentPage()->initialMargins.setRight(rightMargin);
982 m_Doc->reformPages(true);
983 }
984 else
985 {
986 m_Doc->addPage(pagecount);
987 m_Doc->currentPage()->setSize("Custom");
988 m_Doc->currentPage()->setInitialHeight(docHeight);
989 m_Doc->currentPage()->setInitialWidth(docWidth);
990 m_Doc->currentPage()->setHeight(docHeight);
991 m_Doc->currentPage()->setWidth(docWidth);
992 m_Doc->currentPage()->initialMargins.setTop(topMargin);
993 m_Doc->currentPage()->initialMargins.setBottom(bottomMargin);
994 m_Doc->currentPage()->initialMargins.setLeft(leftMargin);
995 m_Doc->currentPage()->initialMargins.setRight(rightMargin);
996 m_Doc->currentPage()->setMasterPageNameNormal();
997 m_Doc->view()->addPage(pagecount, true);
998 pagecount++;
999 }
1000 }
1001 firstPage = false;
1002 baseX = m_Doc->currentPage()->xOffset();
1003 baseY = m_Doc->currentPage()->yOffset();
1004 parsePageReference(sp);
1005 }
1006 }
1007 }
1008 else if (drawPag.tagName() == "sf:text-storage")
1009 {
1010 for (QDomElement spf = drawPag.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1011 {
1012 if (spf.tagName() == "sf:stylesheet-ref")
1013 {
1014 m_currentStyleSheet = spf.attribute("sfa:IDREF");
1015 }
1016 else if (spf.tagName() == "sf:text-body")
1017 {
1018 // int txPage = 0;
1019 StoryText itemText;
1020 itemText.clear();
1021 itemText.setDoc(m_Doc);
1022 int posC = 0;
1023 QString pStyle = CommonStrings::DefaultParagraphStyle;
1024 ParagraphStyle newStyle;
1025 newStyle.setDefaultStyle(false);
1026 newStyle.setParent(pStyle);
1027 ParagraphStyle ttx = m_Doc->paragraphStyle(pStyle);
1028 CharStyle nstyle = ttx.charStyle();
1029 newStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
1030 newStyle.setLineSpacing(nstyle.fontSize() / 10.0);
1031 itemText.setDefaultStyle(newStyle);
1032 for (QDomElement spg = spf.firstChildElement(); !spg.isNull(); spg = spg.nextSiblingElement())
1033 {
1034 // if (spg.tagName() == "sf:container-hint")
1035 // {
1036 // txPage = spg.attribute("sf:page-index").toInt();
1037 // }
1038 // else
1039 if (spg.tagName() == "sf:p")
1040 {
1041 ParagraphStyle tmpStyle = newStyle;
1042 if (!spg.attribute("sf:style").isEmpty())
1043 {
1044 if (m_Doc->styleExists(spg.attribute("sf:style")))
1045 tmpStyle = m_Doc->paragraphStyle(spg.attribute("sf:style"));
1046 else
1047 {
1048 tmpStyle.setName(spg.attribute("sf:style"));
1049 applyParagraphAttrs(tmpStyle, tmpStyle.charStyle(), spg.attribute("sf:style"));
1050 StyleSet<ParagraphStyle>tmp;
1051 tmp.create(tmpStyle);
1052 m_Doc->redefineStyles(tmp, false);
1053 }
1054 }
1055 int totalCount = 0;
1056 if (spg.hasChildNodes())
1057 {
1058 for (QDomElement sph = spg.firstChildElement(); !sph.isNull(); sph = sph.nextSiblingElement())
1059 {
1060 totalCount += sph.text().length();
1061 // if (sph.tagName() == "sf:container-hint")
1062 // {
1063 // txPage = sph.attribute("sf:page-index").toInt();
1064 // }
1065 }
1066 }
1067 int count = spg.text().length();
1068 QString tgText = spg.text();
1069 tgText = tgText.left(count - totalCount);
1070 if (tgText.length() > 0)
1071 {
1072 itemText.insertChars(posC, tgText);
1073 itemText.applyStyle(posC, tmpStyle);
1074 itemText.applyCharStyle(posC, count - totalCount, tmpStyle.charStyle());
1075 posC = itemText.length();
1076 }
1077 if (spg.hasChildNodes())
1078 {
1079 for (QDomElement sph = spg.firstChildElement(); !sph.isNull(); sph = sph.nextSiblingElement())
1080 {
1081 if (sph.tagName() == "sf:span")
1082 {
1083 CharStyle tmpCStyle = tmpStyle.charStyle();
1084 applyCharAttrs(tmpCStyle, sph.attribute("sf:style"));
1085 int count = sph.text().length();
1086 if (count > 0)
1087 {
1088 itemText.insertChars(posC, sph.text());
1089 itemText.applyStyle(posC, tmpStyle);
1090 itemText.applyCharStyle(posC, count, tmpCStyle);
1091 posC = itemText.length();
1092 }
1093 }
1094 }
1095 }
1096 itemText.insertChars(posC, SpecialChars::PARSEP);
1097 itemText.applyStyle(posC, tmpStyle);
1098 posC = itemText.length();
1099 }
1100 }
1101 }
1102 }
1103 }
1104 }
1105 return true;
1106 }
1107
parseStyleSheets(QDomElement & drawPag)1108 void PagesPlug::parseStyleSheets(QDomElement &drawPag)
1109 {
1110 QString sheetName = drawPag.attribute("sfa:ID");
1111 StyleSheet styleSH;
1112 for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement())
1113 {
1114 if ((sp.tagName() == "sf:styles") || (sp.tagName() == "sf:anon-styles"))
1115 {
1116 for (QDomElement spd = sp.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement())
1117 {
1118 if (spd.tagName() == "sf:characterstyle")
1119 {
1120 ChrStyle currStyle;
1121 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1122 {
1123 if (spe.tagName() == "sf:property-map")
1124 {
1125 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1126 {
1127 if (spf.tagName() == "sf:fontSize")
1128 {
1129 QDomElement spg = spf.firstChildElement();
1130 if (!spg.isNull())
1131 {
1132 if (spg.tagName() == "sf:number")
1133 currStyle.fontSize = AttributeValue(spg.attribute("sfa:number", "1"));
1134 }
1135 }
1136 else if (spf.tagName() == "sf:fontName")
1137 {
1138 QDomElement spg = spf.firstChildElement();
1139 if (!spg.isNull())
1140 {
1141 if (spg.tagName() == "sf:string")
1142 currStyle.fontName = AttributeValue(spg.attribute("sfa:string"));
1143 }
1144 }
1145 else if (spf.tagName() == "sf:fontColor")
1146 {
1147 QDomElement spg = spf.firstChildElement();
1148 if (!spg.isNull())
1149 {
1150 if (spg.tagName() == "sf:color")
1151 {
1152 QString type = spg.attribute("xsi:type");
1153 if (type == "sfa:calibrated-white-color-type")
1154 {
1155 // currStyle.fontColor = AttributeValue("White");
1156 QColor c;
1157 double w = spg.attribute("sfa:w", "1").toDouble();
1158 c.setRgbF(w, w, w);
1159 ScColor tmp;
1160 tmp.fromQColor(c);
1161 tmp.setSpotColor(false);
1162 tmp.setRegistrationColor(false);
1163 QString newColorName = "FromPages"+c.name();
1164 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1165 if (fNam == newColorName)
1166 importedColors.append(newColorName);
1167 currStyle.fontColor = AttributeValue(fNam);
1168 }
1169 else if (type == "sfa:calibrated-rgb-color-type")
1170 {
1171 double r = spg.attribute("sfa:r", "1").toDouble();
1172 double g = spg.attribute("sfa:g", "1").toDouble();
1173 double b = spg.attribute("sfa:b", "1").toDouble();
1174 ScColor tmp;
1175 tmp.setRgbColorF(r, g, b);
1176 tmp.setSpotColor(false);
1177 tmp.setRegistrationColor(false);
1178 QString newColorName = "FromPages" + tmp.name();
1179 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1180 if (fNam == newColorName)
1181 importedColors.append(newColorName);
1182 currStyle.fontColor = AttributeValue(fNam);
1183 }
1184 else if (type == "sfa:device-cmyk-color-type")
1185 {
1186 double c = spg.attribute("sfa:c", "1").toDouble();
1187 double m = spg.attribute("sfa:m", "1").toDouble();
1188 double y = spg.attribute("sfa:y", "1").toDouble();
1189 double k = spg.attribute("sfa:k", "1").toDouble();
1190 ScColor tmp;
1191 tmp.setColorF(c, m, y, k);
1192 tmp.setSpotColor(false);
1193 tmp.setRegistrationColor(false);
1194 QString newColorName = "FromPages"+tmp.name();
1195 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1196 if (fNam == newColorName)
1197 importedColors.append(newColorName);
1198 currStyle.fontColor = AttributeValue(fNam);
1199 }
1200 }
1201 }
1202 }
1203 }
1204 }
1205 }
1206 if (!spd.attribute("sf:parent-ident").isEmpty())
1207 currStyle.parentStyle = AttributeValue(spd.attribute("sf:parent-ident"));
1208 QString id = spd.attribute("sfa:ID");
1209 QString i = spd.attribute("sf:ident");
1210 QString i2 = spd.attribute("sf:name");
1211 if (!id.isEmpty())
1212 styleSH.m_chrStyles.insert(id, currStyle);
1213 else if (!i.isEmpty())
1214 styleSH.m_chrStyles.insert(i, currStyle);
1215 else if (!i2.isEmpty())
1216 styleSH.m_chrStyles.insert(i2, currStyle);
1217 }
1218 if (spd.tagName() == "sf:paragraphstyle")
1219 {
1220 ParStyle currStyle;
1221 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1222 {
1223 if (spe.tagName() == "sf:property-map")
1224 {
1225 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1226 {
1227 if (spf.tagName() == "sf:fontSize")
1228 {
1229 QDomElement spg = spf.firstChildElement();
1230 if (!spg.isNull())
1231 {
1232 if (spg.tagName() == "sf:number")
1233 currStyle.fontSize = AttributeValue(spg.attribute("sfa:number", "1"));
1234 }
1235 }
1236 else if (spf.tagName() == "sf:fontName")
1237 {
1238 QDomElement spg = spf.firstChildElement();
1239 if (!spg.isNull())
1240 {
1241 if (spg.tagName() == "sf:string")
1242 currStyle.fontName = AttributeValue(spg.attribute("sfa:string"));
1243 }
1244 }
1245 else if (spf.tagName() == "sf:alignment")
1246 {
1247 QDomElement spg = spf.firstChildElement();
1248 if (!spg.isNull())
1249 {
1250 if (spg.tagName() == "sf:number")
1251 currStyle.justification = AttributeValue(spg.attribute("sfa:number", "1"));
1252 }
1253 }
1254 else if (spf.tagName() == "sf:fontColor")
1255 {
1256 QDomElement spg = spf.firstChildElement();
1257 if (!spg.isNull())
1258 {
1259 if (spg.tagName() == "sf:color")
1260 {
1261 QString type = spg.attribute("xsi:type");
1262 if (type == "sfa:calibrated-white-color-type")
1263 {
1264 // currStyle.fontColor = AttributeValue("White");
1265 QColor c;
1266 double w = spg.attribute("sfa:w", "1").toDouble();
1267 c.setRgbF(w, w, w);
1268 ScColor tmp;
1269 tmp.fromQColor(c);
1270 tmp.setSpotColor(false);
1271 tmp.setRegistrationColor(false);
1272 QString newColorName = "FromPages"+c.name();
1273 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1274 if (fNam == newColorName)
1275 importedColors.append(newColorName);
1276 currStyle.fontColor = AttributeValue(fNam);
1277 }
1278 else if (type == "sfa:calibrated-rgb-color-type")
1279 {
1280 double r = spg.attribute("sfa:r", "1").toDouble();
1281 double g = spg.attribute("sfa:g", "1").toDouble();
1282 double b = spg.attribute("sfa:b", "1").toDouble();
1283 ScColor tmp;
1284 tmp.setRgbColorF(r, g, b);
1285 tmp.setSpotColor(false);
1286 tmp.setRegistrationColor(false);
1287 QString newColorName = "FromPages" + tmp.name();
1288 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1289 if (fNam == newColorName)
1290 importedColors.append(newColorName);
1291 currStyle.fontColor = AttributeValue(fNam);
1292 }
1293 else if (type == "sfa:device-cmyk-color-type")
1294 {
1295 double c = spg.attribute("sfa:c", "1").toDouble();
1296 double m = spg.attribute("sfa:m", "1").toDouble();
1297 double y = spg.attribute("sfa:y", "1").toDouble();
1298 double k = spg.attribute("sfa:k", "1").toDouble();
1299 ScColor tmp;
1300 tmp.setColorF(c, m, y, k);
1301 tmp.setSpotColor(false);
1302 tmp.setRegistrationColor(false);
1303 QString newColorName = "FromPages" + tmp.name();
1304 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1305 if (fNam == newColorName)
1306 importedColors.append(newColorName);
1307 currStyle.fontColor = AttributeValue(fNam);
1308 }
1309 }
1310 }
1311 }
1312 }
1313 }
1314 }
1315 if (!spd.attribute("sf:parent-ident").isEmpty())
1316 currStyle.parentStyle = AttributeValue(spd.attribute("sf:parent-ident"));
1317 QString id = spd.attribute("sfa:ID");
1318 QString i = spd.attribute("sf:ident");
1319 QString i2 = spd.attribute("sf:name");
1320 if (!id.isEmpty())
1321 styleSH.m_parStyles.insert(id, currStyle);
1322 else if (!i.isEmpty())
1323 styleSH.m_parStyles.insert(i, currStyle);
1324 else if (!i2.isEmpty())
1325 styleSH.m_parStyles.insert(i2, currStyle);
1326 }
1327 else if (spd.tagName() == "sf:layoutstyle")
1328 {
1329 LayoutStyle currStyle;
1330 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1331 {
1332 if (spe.tagName() == "sf:property-map")
1333 {
1334 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1335 {
1336 if (spf.tagName() == "sf:padding")
1337 {
1338 QDomElement spg = spf.firstChildElement();
1339 if (!spg.isNull())
1340 {
1341 if (spg.tagName() == "sf:padding")
1342 {
1343 currStyle.Extra = AttributeValue(spg.attribute("sf:left", "0"));
1344 currStyle.RExtra = AttributeValue(spg.attribute("sf:right", "0"));
1345 currStyle.TExtra = AttributeValue(spg.attribute("sf:top", "0"));
1346 currStyle.BExtra = AttributeValue(spg.attribute("sf:bottom", "0"));
1347 }
1348 }
1349 }
1350 }
1351 }
1352 }
1353 if (!spd.attribute("sf:parent-ident").isEmpty())
1354 currStyle.parentStyle = AttributeValue(spd.attribute("sf:parent-ident"));
1355 QString id = spd.attribute("sfa:ID");
1356 QString i = spd.attribute("sf:ident");
1357 QString i2 = spd.attribute("sf:name");
1358 if (!id.isEmpty())
1359 styleSH.m_layoutStyles.insert(id, currStyle);
1360 else if (!i.isEmpty())
1361 styleSH.m_layoutStyles.insert(i, currStyle);
1362 else if (!i2.isEmpty())
1363 styleSH.m_layoutStyles.insert(i2, currStyle);
1364 }
1365 else if (spd.tagName() == "sf:graphic-style")
1366 {
1367 ObjStyle currStyle;
1368 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1369 {
1370 if (spe.tagName() == "sf:property-map")
1371 {
1372 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1373 {
1374 if (spf.tagName() == "sf:stroke")
1375 {
1376 QDomElement spg = spf.firstChildElement();
1377 if (!spg.isNull())
1378 {
1379 if (spg.tagName() == "sf:stroke")
1380 {
1381 currStyle.LineW = AttributeValue(spg.attribute("sf:width", "1"));
1382 if (spg.hasAttribute("sf:cap"))
1383 currStyle.CapStyle = AttributeValue(spg.attribute("sf:cap"));
1384 if (spg.hasAttribute("sf:join"))
1385 currStyle.JoinStyle = AttributeValue(spg.attribute("sf:join"));
1386 QDomElement sph = spg.firstChildElement();
1387 if (!sph.isNull())
1388 {
1389 if (sph.tagName() == "sf:color")
1390 {
1391 QString type = sph.attribute("xsi:type");
1392 currStyle.strokeOpacity = AttributeValue(QString("%1").arg(1.0 - sph.attribute("sfa:a", "1").toDouble()));
1393 if (type == "sfa:calibrated-white-color-type")
1394 {
1395 // currStyle.CurrColorStroke = AttributeValue("White");
1396 QColor c;
1397 double w = sph.attribute("sfa:w", "1").toDouble();
1398 c.setRgbF(w, w, w);
1399 ScColor tmp;
1400 tmp.fromQColor(c);
1401 tmp.setSpotColor(false);
1402 tmp.setRegistrationColor(false);
1403 QString newColorName = "FromPages"+c.name();
1404 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1405 if (fNam == newColorName)
1406 importedColors.append(newColorName);
1407 currStyle.CurrColorStroke = AttributeValue(fNam);
1408 }
1409 else if (type == "sfa:calibrated-rgb-color-type")
1410 {
1411 double r = sph.attribute("sfa:r", "1").toDouble();
1412 double g = sph.attribute("sfa:g", "1").toDouble();
1413 double b = sph.attribute("sfa:b", "1").toDouble();
1414 ScColor tmp;
1415 tmp.setRgbColorF(r, g, b);
1416 tmp.setSpotColor(false);
1417 tmp.setRegistrationColor(false);
1418 QString newColorName = "FromPages" + tmp.name();
1419 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1420 if (fNam == newColorName)
1421 importedColors.append(newColorName);
1422 currStyle.CurrColorStroke = AttributeValue(fNam);
1423 }
1424 else if (type == "sfa:device-cmyk-color-type")
1425 {
1426 double c = sph.attribute("sfa:c", "1").toDouble();
1427 double m = sph.attribute("sfa:m", "1").toDouble();
1428 double y = sph.attribute("sfa:y", "1").toDouble();
1429 double k = sph.attribute("sfa:k", "1").toDouble();
1430 ScColor tmp;
1431 tmp.setColorF(c, m, y, k);
1432 tmp.setSpotColor(false);
1433 tmp.setRegistrationColor(false);
1434 QString newColorName = "FromPages"+tmp.name();
1435 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1436 if (fNam == newColorName)
1437 importedColors.append(newColorName);
1438 currStyle.CurrColorStroke = AttributeValue(fNam);
1439 }
1440 }
1441 }
1442 }
1443 }
1444 }
1445 else if (spf.tagName() == "sf:fill")
1446 {
1447 QDomElement spg = spf.firstChildElement();
1448 if (!spg.isNull())
1449 {
1450 if (spg.tagName() == "sf:color")
1451 {
1452 QString type = spg.attribute("xsi:type");
1453 currStyle.fillOpacity = AttributeValue(QString("%1").arg(1.0 - spg.attribute("sfa:a", "1").toDouble()));
1454 if (type == "sfa:calibrated-white-color-type")
1455 {
1456 // currStyle.CurrColorFill = AttributeValue("White");
1457 QColor c;
1458 double w = spg.attribute("sfa:w", "1").toDouble();
1459 c.setRgbF(w, w, w);
1460 ScColor tmp;
1461 tmp.fromQColor(c);
1462 tmp.setSpotColor(false);
1463 tmp.setRegistrationColor(false);
1464 QString newColorName = "FromPages"+c.name();
1465 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1466 if (fNam == newColorName)
1467 importedColors.append(newColorName);
1468 currStyle.CurrColorFill = AttributeValue(fNam);
1469 }
1470 else if (type == "sfa:calibrated-rgb-color-type")
1471 {
1472 double r = spg.attribute("sfa:r", "1").toDouble();
1473 double g = spg.attribute("sfa:g", "1").toDouble();
1474 double b = spg.attribute("sfa:b", "1").toDouble();
1475 ScColor tmp;
1476 tmp.setRgbColorF(r, g, b);
1477 tmp.setSpotColor(false);
1478 tmp.setRegistrationColor(false);
1479 QString newColorName = "FromPages" + tmp.name();
1480 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1481 if (fNam == newColorName)
1482 importedColors.append(newColorName);
1483 currStyle.CurrColorFill = AttributeValue(fNam);
1484 }
1485 else if (type == "sfa:device-cmyk-color-type")
1486 {
1487 double c = spg.attribute("sfa:c", "1").toDouble();
1488 double m = spg.attribute("sfa:m", "1").toDouble();
1489 double y = spg.attribute("sfa:y", "1").toDouble();
1490 double k = spg.attribute("sfa:k", "1").toDouble();
1491 ScColor tmp;
1492 tmp.setColorF(c, m, y, k);
1493 tmp.setSpotColor(false);
1494 tmp.setRegistrationColor(false);
1495 QString newColorName = "FromPages"+tmp.name();
1496 QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
1497 if (fNam == newColorName)
1498 importedColors.append(newColorName);
1499 currStyle.CurrColorFill = AttributeValue(fNam);
1500 }
1501 }
1502 else if (spg.tagName() == "sf:null")
1503 currStyle.CurrColorFill = AttributeValue(CommonStrings::None);
1504 }
1505 }
1506 else if (spf.tagName() == "sf:opacity")
1507 {
1508 QDomElement spg = spf.firstChildElement();
1509 if (!spg.isNull())
1510 {
1511 if (spg.tagName() == "sf:number")
1512 currStyle.opacity = AttributeValue(QString("%1").arg(1.0 - spg.attribute("sfa:number", "1").toDouble()));
1513 }
1514 }
1515 }
1516 }
1517 }
1518 if (!spd.attribute("sf:parent-ident").isEmpty())
1519 currStyle.parentStyle = AttributeValue(spd.attribute("sf:parent-ident"));
1520 QString id = spd.attribute("sfa:ID");
1521 QString i = spd.attribute("sf:ident");
1522 QString i2 = spd.attribute("sf:name");
1523 if (!id.isEmpty())
1524 styleSH.m_objStyles.insert(id, currStyle);
1525 else if (!i.isEmpty())
1526 styleSH.m_objStyles.insert(i, currStyle);
1527 else if (!i2.isEmpty())
1528 styleSH.m_objStyles.insert(i2, currStyle);
1529 }
1530 }
1531 }
1532 }
1533 m_StyleSheets.insert(sheetName, styleSH);
1534 }
1535
parsePageReference(QDomElement & drawPag)1536 void PagesPlug::parsePageReference(QDomElement &drawPag)
1537 {
1538 for (QDomElement draw = drawPag.firstChildElement(); !draw.isNull(); draw = draw.nextSiblingElement())
1539 {
1540 PageItem* retObj = parseObjReference(draw);
1541 if (retObj != nullptr)
1542 {
1543 m_Doc->Items->append(retObj);
1544 Elements.append(retObj);
1545 }
1546 }
1547 }
1548
parseObjReference(QDomElement & draw)1549 PageItem* PagesPlug::parseObjReference(QDomElement &draw)
1550 {
1551 ObjState obState;
1552 StoryText itemText;
1553 itemText.clear();
1554 itemText.setDoc(m_Doc);
1555 int z = -1;
1556 PageItem *retObj = nullptr;
1557 if (draw.tagName() == "sf:group")
1558 {
1559 QList<PageItem*> GElements;
1560 for (QDomElement spd = draw.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement())
1561 {
1562 if (spd.tagName() == "sf:geometry")
1563 {
1564 obState.rotation = spd.attribute("sf:angle", "0").toDouble();
1565 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1566 {
1567 if (spe.tagName() == "sf:position")
1568 {
1569 obState.xPos = spe.attribute("sfa:x", "0").toDouble();
1570 obState.yPos = spe.attribute("sfa:y", "0").toDouble();
1571 }
1572 else if (spe.tagName() == "sf:size")
1573 {
1574 obState.width = spe.attribute("sfa:w", "0").toDouble();
1575 obState.height = spe.attribute("sfa:h", "0").toDouble();
1576 }
1577 }
1578 }
1579 else if ((spd.tagName() == "sf:media") || (spd.tagName() == "sf:drawable-shape") || (spd.tagName() == "sf:group"))
1580 {
1581 PageItem* ite = parseObjReference(spd);
1582 if (ite != nullptr)
1583 GElements.append(ite);
1584 }
1585 }
1586 if (GElements.count() > 0)
1587 {
1588 QTransform m;
1589 m.translate(obState.width / 2.0, obState.height / 2.0);
1590 m.rotate(-obState.rotation);
1591 m.translate(-obState.width / 2.0, -obState.height / 2.0);
1592 QPolygonF po;
1593 po.append(QPointF(0, 0));
1594 po.append(QPointF(obState.width, 0));
1595 po.append(QPointF(obState.width, obState.height));
1596 po.append(QPointF(0, obState.height));
1597 po = m.map(po);
1598 QRectF br = po.boundingRect();
1599 po.translate(-br.x(), -br.y());
1600 po.translate(obState.xPos, obState.yPos);
1601 for (int ep = 0; ep < GElements.count(); ++ep)
1602 {
1603 GElements.at(ep)->moveBy(po[0].x(), po[0].y(), true);
1604 }
1605 z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX + po[0].x(), baseY + po[0].y(), obState.width, obState.height, 0, CommonStrings::None, CommonStrings::None);
1606 retObj = m_Doc->Items->at(z);
1607 retObj->ClipEdited = true;
1608 retObj->FrameType = 3;
1609 retObj->setFillEvenOdd(false);
1610 retObj->OldB2 = retObj->width();
1611 retObj->OldH2 = retObj->height();
1612 retObj->updateClip();
1613 m_Doc->groupObjectsToItem(retObj, GElements);
1614 retObj->setRotation(-obState.rotation, true);
1615 retObj->OwnPage = m_Doc->OnPage(retObj);
1616 m_Doc->GroupOnPage(retObj);
1617 m_Doc->Items->removeLast();
1618 }
1619 }
1620 else if ((draw.tagName() == "sf:media") || (draw.tagName() == "sf:drawable-shape"))
1621 {
1622 for (QDomElement spd = draw.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement())
1623 {
1624 if (spd.tagName() == "sf:geometry")
1625 {
1626 obState.rotation = spd.attribute("sf:angle", "0").toDouble();
1627 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1628 {
1629 if (spe.tagName() == "sf:position")
1630 {
1631 obState.xPos = spe.attribute("sfa:x", "0").toDouble();
1632 obState.yPos = spe.attribute("sfa:y", "0").toDouble();
1633 }
1634 else if (spe.tagName() == "sf:size")
1635 {
1636 obState.width = spe.attribute("sfa:w", "0").toDouble();
1637 obState.height = spe.attribute("sfa:h", "0").toDouble();
1638 }
1639 }
1640 }
1641 else if (spd.tagName() == "sf:style")
1642 {
1643 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1644 {
1645 if (spe.tagName() == "sf:graphic-style-ref")
1646 {
1647 obState.styleRef = spe.attribute("sfa:IDREF");
1648 }
1649 }
1650 }
1651 else if (spd.tagName() == "sf:path")
1652 {
1653 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1654 {
1655 if ((spe.tagName() == "sf:bezier-path") || (spe.tagName() == "sf:editable-bezier-path"))
1656 {
1657 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1658 {
1659 if (spf.tagName() == "sf:bezier")
1660 {
1661 QString pdata = spf.attribute("sfa:path");
1662 if (!pdata.isEmpty())
1663 {
1664 Coords.resize(0);
1665 Coords.svgInit();
1666 obState.currentPathClosed = Coords.parseSVG(pdata);
1667 obState.currentPath = Coords.toQPainterPath(!obState.currentPathClosed);
1668 }
1669 }
1670 }
1671 }
1672 }
1673 }
1674 else if (spd.tagName() == "sf:wrap")
1675 {
1676 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1677 {
1678 if (spe.tagName() == "sf:path")
1679 {
1680 QString pdata = spe.attribute("sfa:path");
1681 if (!pdata.isEmpty())
1682 {
1683 Coords.resize(0);
1684 Coords.svgInit();
1685 obState.currentPathClosed = Coords.parseSVG(pdata);
1686 obState.clipPath = Coords.toQPainterPath(!obState.currentPathClosed);
1687 }
1688 }
1689 }
1690 }
1691 else if (spd.tagName() == "sf:content")
1692 {
1693 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1694 {
1695 if (spe.tagName() == "sf:image-media")
1696 {
1697 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1698 {
1699 if (spf.tagName() == "sf:filtered-image")
1700 {
1701 for (QDomElement spg = spf.firstChildElement(); !spg.isNull(); spg = spg.nextSiblingElement())
1702 {
1703 if (spg.tagName() == "sf:unfiltered")
1704 {
1705 for (QDomElement sph = spg.firstChildElement(); !sph.isNull(); sph = sph.nextSiblingElement())
1706 {
1707 if (sph.tagName() == "sf:data")
1708 {
1709 obState.imagePath = sph.attribute("sf:path");
1710 }
1711 }
1712 }
1713 }
1714 }
1715 }
1716 }
1717 }
1718 }
1719 else if (spd.tagName() == "sf:text")
1720 {
1721 obState.layoutStyleRef = spd.attribute("sf:layoutstyle");
1722 for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement())
1723 {
1724 if (spe.tagName() == "sf:text-storage")
1725 {
1726 for (QDomElement spf = spe.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement())
1727 {
1728 if (spf.tagName() == "sf:text-body")
1729 {
1730 int posC = 0;
1731 QString pStyle = CommonStrings::DefaultParagraphStyle;
1732 ParagraphStyle newStyle;
1733 newStyle.setDefaultStyle(false);
1734 newStyle.setParent(pStyle);
1735 ParagraphStyle ttx = m_Doc->paragraphStyle(pStyle);
1736 CharStyle nstyle = ttx.charStyle();
1737 newStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
1738 newStyle.setLineSpacing(nstyle.fontSize() / 10.0);
1739 itemText.setDefaultStyle(newStyle);
1740 for (QDomElement spg = spf.firstChildElement(); !spg.isNull(); spg = spg.nextSiblingElement())
1741 {
1742 if (spg.tagName() == "sf:p")
1743 {
1744 ParagraphStyle tmpStyle = newStyle;
1745 if (!spg.attribute("sf:style").isEmpty())
1746 {
1747 if (m_Doc->styleExists(spg.attribute("sf:style")))
1748 tmpStyle = m_Doc->paragraphStyle(spg.attribute("sf:style"));
1749 else
1750 {
1751 tmpStyle.setName(spg.attribute("sf:style"));
1752 applyParagraphAttrs(tmpStyle, tmpStyle.charStyle(), spg.attribute("sf:style"));
1753 StyleSet<ParagraphStyle>tmp;
1754 tmp.create(tmpStyle);
1755 m_Doc->redefineStyles(tmp, false);
1756 }
1757 }
1758 int totalCount = 0;
1759 if (spg.hasChildNodes())
1760 {
1761 for (QDomElement sph = spg.firstChildElement(); !sph.isNull(); sph = sph.nextSiblingElement())
1762 {
1763 totalCount += sph.text().length();
1764 }
1765 }
1766 int count = spg.text().length();
1767 QString tgText = spg.text();
1768 tgText = tgText.left(count - totalCount);
1769 if (tgText.length() > 0)
1770 {
1771 itemText.insertChars(posC, tgText);
1772 itemText.applyStyle(posC, tmpStyle);
1773 itemText.applyCharStyle(posC, count - totalCount, tmpStyle.charStyle());
1774 posC = itemText.length();
1775 }
1776 if (spg.hasChildNodes())
1777 {
1778 for (QDomElement sph = spg.firstChildElement(); !sph.isNull(); sph = sph.nextSiblingElement())
1779 {
1780 if (sph.tagName() == "sf:span")
1781 {
1782 CharStyle tmpCStyle = tmpStyle.charStyle();
1783 applyCharAttrs(tmpCStyle, sph.attribute("sf:style"));
1784 int count = sph.text().length();
1785 if (count > 0)
1786 {
1787 itemText.insertChars(posC, sph.text());
1788 itemText.applyStyle(posC, tmpStyle);
1789 itemText.applyCharStyle(posC, count, tmpCStyle);
1790 posC = itemText.length();
1791 }
1792 }
1793 }
1794 }
1795 itemText.insertChars(posC, SpecialChars::PARSEP);
1796 itemText.applyStyle(posC, tmpStyle);
1797 posC = itemText.length();
1798 }
1799 }
1800 }
1801 }
1802 }
1803 }
1804 }
1805 }
1806 if (draw.tagName() == "sf:media")
1807 {
1808 QTransform m;
1809 m.translate(obState.width / 2.0, obState.height / 2.0);
1810 m.rotate(-obState.rotation);
1811 m.translate(-obState.width / 2.0, -obState.height / 2.0);
1812 QPolygonF po;
1813 po.append(QPointF(0, 0));
1814 po.append(QPointF(obState.width, 0));
1815 po.append(QPointF(obState.width, obState.height));
1816 po.append(QPointF(0, obState.height));
1817 po = m.map(po);
1818 QRectF br = po.boundingRect();
1819 po.translate(-br.x(), -br.y());
1820 po.translate(obState.xPos, obState.yPos);
1821 z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Rectangle, baseX + po[0].x(), baseY + po[0].y(), obState.width, obState.height, obState.LineW, obState.CurrColorFill, obState.CurrColorStroke);
1822 retObj = m_Doc->Items->at(z);
1823 if (!obState.clipPath.isEmpty())
1824 {
1825 QRectF br2 = obState.clipPath.boundingRect();
1826 QTransform m;
1827 m.translate(br2.x(), br2.y());
1828 m.translate(br2.width() / 2.0, br2.height() / 2.0);
1829 m.rotate(obState.rotation);
1830 m.translate(-br2.width() / 2.0, -br2.height() / 2.0);
1831 obState.clipPath = m.map(obState.clipPath);
1832 FPointArray pa;
1833 pa.fromQPainterPath(obState.clipPath, true);
1834 QRectF clipRect = obState.clipPath.boundingRect();
1835 FPoint tp2(clipRect.left(), clipRect.top());
1836 pa.translate(-tp2.x(), -tp2.y());
1837 pa.translate(-(clipRect.width() - obState.width) / 2.0, -(clipRect.height() - obState.height) / 2.0);
1838 retObj->ContourLine = pa;
1839 retObj->setTextFlowMode(PageItem::TextFlowUsesContourLine);
1840 }
1841 retObj->setRotation(-obState.rotation, true);
1842 finishItem(retObj, obState);
1843 retObj = m_Doc->Items->takeAt(z);
1844 if (!obState.imagePath.isEmpty())
1845 {
1846 QByteArray f;
1847 if (uz->read(obState.imagePath, f))
1848 {
1849 QFileInfo fi(obState.imagePath);
1850 QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pages_XXXXXX." + fi.suffix());
1851 tempFile->setAutoRemove(false);
1852 if (tempFile->open())
1853 {
1854 QString fileName = getLongPathName(tempFile->fileName());
1855 if (!fileName.isEmpty())
1856 {
1857 tempFile->write(f);
1858 tempFile->close();
1859 retObj->isInlineImage = true;
1860 retObj->isTempFile = true;
1861 retObj->AspectRatio = false;
1862 retObj->ScaleType = false;
1863 m_Doc->loadPict(fileName, retObj);
1864 retObj->adjustPictScale();
1865 }
1866 }
1867 delete tempFile;
1868 }
1869 }
1870 }
1871 else if (draw.tagName() == "sf:drawable-shape")
1872 {
1873 QTransform m;
1874 m.translate(obState.width / 2.0, obState.height / 2.0);
1875 m.rotate(-obState.rotation);
1876 m.translate(-obState.width / 2.0, -obState.height / 2.0);
1877 QPolygonF po;
1878 po.append(QPointF(0, 0));
1879 po.append(QPointF(obState.width, 0));
1880 po.append(QPointF(obState.width, obState.height));
1881 po.append(QPointF(0, obState.height));
1882 po = m.map(po);
1883 QRectF br = po.boundingRect();
1884 po.translate(-br.x(), -br.y());
1885 po.translate(obState.xPos, obState.yPos);
1886 if (itemText.length() > 0)
1887 z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, baseX + po[0].x(), baseY + po[0].y(), obState.width, obState.height, obState.LineW, obState.CurrColorFill, obState.CurrColorStroke);
1888 else if (obState.currentPathClosed)
1889 z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX + po[0].x(), baseY + po[0].y(), obState.width, obState.height, obState.LineW, obState.CurrColorFill, obState.CurrColorStroke);
1890 else
1891 z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX + po[0].x(), baseY + po[0].y(), obState.width, obState.height, obState.LineW, obState.CurrColorFill, obState.CurrColorStroke);
1892 retObj = m_Doc->Items->at(z);
1893 if (!obState.currentPath.isEmpty())
1894 {
1895 retObj->ClipEdited = true;
1896 retObj->FrameType = 3;
1897 FPointArray pa;
1898 pa.fromQPainterPath(obState.currentPath, !obState.currentPathClosed);
1899 retObj->PoLine = pa;
1900 }
1901 else
1902 retObj->SetRectFrame();
1903 retObj->setRotation(-obState.rotation, true);
1904 if (itemText.length() > 0)
1905 {
1906 retObj->itemText.append(itemText);
1907 retObj->itemText.trim();
1908 }
1909 finishItem(retObj, obState);
1910 retObj = m_Doc->Items->takeAt(z);
1911 }
1912 }
1913 return retObj;
1914 }
1915
addClip(PageItem * retObj,ObjState & obState)1916 PageItem* PagesPlug::addClip(PageItem* retObj, ObjState &obState)
1917 {
1918 if (!obState.clipPath.isEmpty())
1919 {
1920 int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None);
1921 PageItem *itemg = m_Doc->Items->at(z);
1922 itemg->PoLine.fromQPainterPath(obState.clipPath);
1923 FPoint wh = getMaxClipF(&itemg->PoLine);
1924 itemg->setWidthHeight(wh.x(),wh.y());
1925 m_Doc->adjustItemSize(itemg, true);
1926 itemg->ClipEdited = true;
1927 itemg->FrameType = 3;
1928 itemg->setFillEvenOdd(false);
1929 itemg->OldB2 = itemg->width();
1930 itemg->OldH2 = itemg->height();
1931 itemg->updateClip();
1932 itemg->OwnPage = m_Doc->OnPage(itemg);
1933 itemg->ContourLine = itemg->PoLine.copy();
1934 QList<PageItem*> GElements;
1935 GElements.append(retObj);
1936 m_Doc->groupObjectsToItem(itemg, GElements);
1937 m_Doc->resizeGroupToContents(itemg);
1938 m_Doc->GroupOnPage(itemg);
1939 retObj = itemg;
1940 m_Doc->Items->removeLast();
1941 }
1942 return retObj;
1943 }
1944
applyParagraphAttrs(ParagraphStyle & newStyle,CharStyle & tmpCStyle,const QString & pAttrs)1945 void PagesPlug::applyParagraphAttrs(ParagraphStyle &newStyle, CharStyle &tmpCStyle, const QString& pAttrs)
1946 {
1947 if (!m_StyleSheets.contains(m_currentStyleSheet))
1948 return;
1949 StyleSheet currSH = m_StyleSheets[m_currentStyleSheet];
1950 if (currSH.m_parStyles.contains(pAttrs))
1951 {
1952 ParStyle actStyle;
1953 ParStyle currStyle = currSH.m_parStyles[pAttrs];
1954 QStringList parents;
1955 while (currStyle.parentStyle.valid)
1956 {
1957 if (currSH.m_parStyles.contains(currStyle.parentStyle.value))
1958 {
1959 parents.prepend(currStyle.parentStyle.value);
1960 currStyle = currSH.m_parStyles[currStyle.parentStyle.value];
1961 }
1962 else
1963 break;
1964 }
1965 parents.append(pAttrs);
1966 if (!parents.isEmpty())
1967 {
1968 for (int p = 0; p < parents.count(); p++)
1969 {
1970 currStyle = currSH.m_parStyles[parents[p]];
1971 if (currStyle.fontName.valid)
1972 actStyle.fontName = AttributeValue(currStyle.fontName.value);
1973 if (currStyle.fontSize.valid)
1974 actStyle.fontSize = AttributeValue(currStyle.fontSize.value);
1975 if (currStyle.fontColor.valid)
1976 actStyle.fontColor = AttributeValue(currStyle.fontColor.value);
1977 if (currStyle.justification.valid)
1978 actStyle.justification = AttributeValue(currStyle.justification.value);
1979 }
1980 }
1981 if (actStyle.fontName.valid)
1982 qDebug() << "Font" << actStyle.fontName.value;
1983 // textMarginLeft = actStyle.fontName.value;
1984 if (actStyle.fontSize.valid)
1985 tmpCStyle.setFontSize(actStyle.fontSize.value.toInt() * 10);
1986 if (actStyle.fontColor.valid)
1987 tmpCStyle.setFillColor(actStyle.fontColor.value);
1988 if (actStyle.justification.valid)
1989 {
1990 if (actStyle.justification.value == "0")
1991 newStyle.setAlignment(ParagraphStyle::LeftAligned);
1992 else if (actStyle.justification.value == "1")
1993 newStyle.setAlignment(ParagraphStyle::RightAligned);
1994 else if (actStyle.justification.value == "2")
1995 newStyle.setAlignment(ParagraphStyle::Centered);
1996 else if (actStyle.justification.value == "3")
1997 newStyle.setAlignment(ParagraphStyle::Justified);
1998 else if (actStyle.justification.value == "4")
1999 newStyle.setAlignment(ParagraphStyle::Extended);
2000 }
2001 }
2002 }
2003
applyCharAttrs(CharStyle & tmpCStyle,const QString & pAttrs)2004 void PagesPlug::applyCharAttrs(CharStyle &tmpCStyle, const QString& pAttrs)
2005 {
2006 if (!m_StyleSheets.contains(m_currentStyleSheet))
2007 return;
2008 StyleSheet currSH = m_StyleSheets[m_currentStyleSheet];
2009 if (currSH.m_chrStyles.contains(pAttrs))
2010 {
2011 ChrStyle actStyle;
2012 ChrStyle currStyle = currSH.m_chrStyles[pAttrs];
2013 QStringList parents;
2014 while (currStyle.parentStyle.valid)
2015 {
2016 if (currSH.m_chrStyles.contains(currStyle.parentStyle.value))
2017 {
2018 parents.prepend(currStyle.parentStyle.value);
2019 currStyle = currSH.m_chrStyles[currStyle.parentStyle.value];
2020 }
2021 else
2022 break;
2023 }
2024 parents.append(pAttrs);
2025 if (!parents.isEmpty())
2026 {
2027 for (int p = 0; p < parents.count(); p++)
2028 {
2029 currStyle = currSH.m_chrStyles[parents[p]];
2030 if (currStyle.fontName.valid)
2031 actStyle.fontName = AttributeValue(currStyle.fontName.value);
2032 if (currStyle.fontSize.valid)
2033 actStyle.fontSize = AttributeValue(currStyle.fontSize.value);
2034 if (currStyle.fontColor.valid)
2035 actStyle.fontColor = AttributeValue(currStyle.fontColor.value);
2036 }
2037 }
2038 if (actStyle.fontName.valid)
2039 qDebug() << "Font" << actStyle.fontName.value;
2040 // if (actStyle.fontName.valid)
2041 // textMarginLeft = actStyle.fontName.value;
2042 if (actStyle.fontSize.valid)
2043 tmpCStyle.setFontSize(actStyle.fontSize.value.toInt() * 10);
2044 if (actStyle.fontColor.valid)
2045 tmpCStyle.setFillColor(actStyle.fontColor.value);
2046 if (actStyle.backColor.valid)
2047 tmpCStyle.setBackColor(actStyle.backColor.value);
2048 }
2049 }
2050
finishItem(PageItem * item,ObjState & obState)2051 void PagesPlug::finishItem(PageItem* item, ObjState &obState)
2052 {
2053 item->ClipEdited = true;
2054 item->FrameType = 3;
2055 item->setFillEvenOdd(false);
2056 item->OldB2 = item->width();
2057 item->OldH2 = item->height();
2058 item->updateClip();
2059 item->OwnPage = m_Doc->OnPage(item);
2060 if (m_StyleSheets.contains(m_currentStyleSheet))
2061 {
2062 StyleSheet currSH = m_StyleSheets[m_currentStyleSheet];
2063 if (!obState.layoutStyleRef.isEmpty())
2064 {
2065 if (currSH.m_layoutStyles.contains(obState.layoutStyleRef))
2066 {
2067 LayoutStyle actStyle;
2068 LayoutStyle currStyle = currSH.m_layoutStyles[obState.layoutStyleRef];
2069 QStringList parents;
2070 while (currStyle.parentStyle.valid)
2071 {
2072 if (currSH.m_layoutStyles.contains(currStyle.parentStyle.value))
2073 {
2074 parents.prepend(currStyle.parentStyle.value);
2075 currStyle = currSH.m_layoutStyles[currStyle.parentStyle.value];
2076 }
2077 else
2078 break;
2079 }
2080 parents.append(obState.layoutStyleRef);
2081 double textMarginLeft = 0.0;
2082 double textMarginRight = 0.0;
2083 double textMarginTop = 0.0;
2084 double textMarginBottom = 0.0;
2085 double textColumnGap = 0.0;
2086 int textColumnCount = 1;
2087 if (!parents.isEmpty())
2088 {
2089 for (int p = 0; p < parents.count(); p++)
2090 {
2091 currStyle = currSH.m_layoutStyles[parents[p]];
2092 if (currStyle.Extra.valid)
2093 actStyle.Extra = AttributeValue(currStyle.Extra.value);
2094 if (currStyle.RExtra.valid)
2095 actStyle.RExtra = AttributeValue(currStyle.RExtra.value);
2096 if (currStyle.TExtra.valid)
2097 actStyle.TExtra = AttributeValue(currStyle.TExtra.value);
2098 if (currStyle.BExtra.valid)
2099 actStyle.BExtra = AttributeValue(currStyle.BExtra.value);
2100 if (currStyle.TextColumnGutter.valid)
2101 actStyle.TextColumnGutter = AttributeValue(currStyle.TextColumnGutter.value);
2102 if (currStyle.TextColumnCount.valid)
2103 actStyle.TextColumnCount = AttributeValue(currStyle.TextColumnCount.value);
2104 }
2105 }
2106 if (actStyle.Extra.valid)
2107 textMarginLeft = actStyle.Extra.value.toDouble();
2108 if (actStyle.RExtra.valid)
2109 textMarginRight = actStyle.RExtra.value.toDouble();
2110 if (actStyle.TExtra.valid)
2111 textMarginTop = actStyle.TExtra.value.toDouble();
2112 if (actStyle.BExtra.valid)
2113 textMarginBottom = actStyle.BExtra.value.toDouble();
2114 if (actStyle.TextColumnGutter.valid)
2115 textColumnGap = actStyle.TextColumnGutter.value.toDouble();
2116 if (actStyle.TextColumnCount.valid)
2117 textColumnCount = actStyle.TextColumnCount.value.toInt();
2118 item->setTextToFrameDist(textMarginLeft, textMarginRight, textMarginTop, textMarginBottom);
2119 item->setColumns(textColumnCount);
2120 item->setColumnGap(textColumnGap);
2121 }
2122 }
2123 if (!obState.styleRef.isEmpty())
2124 {
2125 if (currSH.m_objStyles.contains(obState.styleRef))
2126 {
2127 ObjStyle actStyle;
2128 ObjStyle currStyle = currSH.m_objStyles[obState.styleRef];
2129 QStringList parents;
2130 while (currStyle.parentStyle.valid)
2131 {
2132 if (currSH.m_objStyles.contains(currStyle.parentStyle.value))
2133 {
2134 parents.prepend(currStyle.parentStyle.value);
2135 currStyle = currSH.m_objStyles[currStyle.parentStyle.value];
2136 }
2137 else
2138 break;
2139 }
2140 parents.append(obState.styleRef);
2141 if (!parents.isEmpty())
2142 {
2143 for (int p = 0; p < parents.count(); p++)
2144 {
2145 currStyle = currSH.m_objStyles[parents[p]];
2146 if (currStyle.CurrColorFill.valid)
2147 actStyle.CurrColorFill = AttributeValue(currStyle.CurrColorFill.value);
2148 if (currStyle.CurrColorStroke.valid)
2149 actStyle.CurrColorStroke = AttributeValue(currStyle.CurrColorStroke.value);
2150 if (currStyle.fillOpacity.valid)
2151 actStyle.fillOpacity = AttributeValue(currStyle.fillOpacity.value);
2152 if (currStyle.strokeOpacity.valid)
2153 actStyle.strokeOpacity = AttributeValue(currStyle.strokeOpacity.value);
2154 if (currStyle.opacity.valid)
2155 actStyle.opacity = AttributeValue(currStyle.opacity.value);
2156 if (currStyle.LineW.valid)
2157 actStyle.LineW = AttributeValue(currStyle.LineW.value);
2158 if (currStyle.CapStyle.valid)
2159 actStyle.CapStyle = AttributeValue(currStyle.CapStyle.value);
2160 if (currStyle.JoinStyle.valid)
2161 actStyle.JoinStyle = AttributeValue(currStyle.JoinStyle.value);
2162 }
2163 }
2164 if (actStyle.CurrColorFill.valid)
2165 item->setFillColor(actStyle.CurrColorFill.value);
2166 if (actStyle.CurrColorStroke.valid)
2167 item->setLineColor(actStyle.CurrColorStroke.value);
2168 if (actStyle.fillOpacity.valid)
2169 item->setFillTransparency(actStyle.fillOpacity.value.toDouble());
2170 if (actStyle.strokeOpacity.valid)
2171 item->setLineTransparency(actStyle.strokeOpacity.value.toDouble());
2172 if (actStyle.LineW.valid)
2173 item->setLineWidth(actStyle.LineW.value.toDouble());
2174 if (actStyle.CapStyle.valid)
2175 {
2176 if (actStyle.CapStyle.value == "butt")
2177 item->setLineEnd(Qt::FlatCap);
2178 else if (actStyle.CapStyle.value == "round")
2179 item->setLineEnd(Qt::RoundCap);
2180 else if (actStyle.CapStyle.value == "square")
2181 item->setLineEnd(Qt::SquareCap);
2182 else
2183 item->setLineEnd(Qt::FlatCap);
2184 }
2185 if (actStyle.JoinStyle.valid)
2186 {
2187 if (actStyle.JoinStyle.value == "miter")
2188 item->setLineJoin(Qt::MiterJoin);
2189 else if (actStyle.JoinStyle.value == "round")
2190 item->setLineJoin(Qt::RoundJoin);
2191 else if (actStyle.JoinStyle.value == "bevel")
2192 item->setLineJoin(Qt::BevelJoin);
2193 else
2194 item->setLineJoin(Qt::MiterJoin);
2195 }
2196 }
2197 }
2198 }
2199 /* double xp = item->xPos() - m_Doc->currentPage()->xOffset();
2200 double yp = item->yPos() - m_Doc->currentPage()->yOffset();
2201 if (obState.fillGradientTyp != 0)
2202 {
2203 item->fill_gradient = obState.currentGradient;
2204 item->setGradientVector(obState.gradientStart.x() - xp, obState.gradientStart.y() - yp, obState.gradientEnd.x() - xp, obState.gradientEnd.y() - yp, obState.gradientFocus.x() - xp, obState.gradientFocus.y() - yp, obState.gradientScale, 0);
2205 item->setGradientType(obState.fillGradientTyp);
2206 }
2207 else if (!obState.patternName.isEmpty())
2208 {
2209 item->setPattern(obState.patternName);
2210 item->GrType = Gradient_Pattern;
2211 }
2212 if (obState.maskTyp != 0)
2213 {
2214 item->setMaskGradient(obState.gradientMask);
2215 item->setMaskVector(obState.maskStart.x() - xp, obState.maskStart.y() - yp, obState.maskEnd.x() - xp, obState.maskEnd.y() - yp, obState.maskFocus.x() - xp, obState.maskFocus.y() - yp, obState.maskScale, 0);
2216 item->setMaskType(obState.maskTyp);
2217 }
2218 if (!obState.patternMask.isEmpty())
2219 {
2220 item->setPatternMask(obState.patternMask);
2221 item->setMaskType(obState.maskTyp);
2222 }
2223 if (obState.strokeTyp != 0)
2224 {
2225 item->setStrokeGradient(obState.gradientStroke);
2226 item->setStrokeGradientVector(obState.strokeStart.x() - xp, obState.strokeStart.y() - yp, obState.strokeEnd.x() - xp, obState.strokeEnd.y() - yp, obState.strokeFocus.x() - xp, obState.strokeFocus.y() - yp, obState.strokeScale, 0);
2227 item->setStrokeGradientType(obState.strokeTyp);
2228 }
2229 if (!obState.patternStroke.isEmpty())
2230 {
2231 item->GrTypeStroke = Gradient_Pattern;
2232 item->setStrokePattern(obState.patternStroke);
2233 }
2234 if (!obState.DashPattern.isEmpty())
2235 {
2236 item->setDashOffset(obState.DashOffset);
2237 QVector<double> pattern(obState.DashPattern.count());
2238 for (int i = 0; i < obState.DashPattern.count(); ++i)
2239 {
2240 pattern[i] = obState.DashPattern[i] * obState.LineW;
2241 }
2242 item->setDashes(pattern);
2243 }*/
2244 }
2245 #endif
2246