Rev 25069 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
17199 | fschmid | 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 : Sat Jan 14 2012 |
||
10 | copyright : (C) 2012 by Franz Schmid |
||
11 | email : Franz.Schmid@altmuehlnet.de |
||
12 | ***************************************************************************/ |
||
13 | |||
14 | #include <QByteArray> |
||
15 | #include <QCursor> |
||
23619 | jghali | 16 | #include <QDebug> |
17199 | fschmid | 17 | #include <QDrag> |
18 | #include <QFile> |
||
19 | #include <QList> |
||
20 | #include <QMimeData> |
||
23619 | jghali | 21 | #include <QScopedPointer> |
17199 | fschmid | 22 | #include <QStack> |
17209 | fschmid | 23 | #include <QUrl> |
17199 | fschmid | 24 | |
17539 | jghali | 25 | #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES) |
17203 | jghali | 26 | #define _USE_MATH_DEFINES |
27 | #endif |
||
28 | |||
17199 | fschmid | 29 | #include <cstdlib> |
30 | #include <climits> |
||
31 | #include <limits> |
||
32 | |||
19093 | craig | 33 | #include "importidml.h" |
34 | |||
17199 | fschmid | 35 | #include "commonstrings.h" |
23392 | jghali | 36 | #include "guidemanagercore.h" |
17199 | fschmid | 37 | #include "loadsaveplugin.h" |
17349 | fschmid | 38 | #include "pageitem_table.h" |
17199 | fschmid | 39 | #include "pagesize.h" |
40 | #include "prefscontext.h" |
||
41 | #include "prefsfile.h" |
||
42 | #include "prefsmanager.h" |
||
43 | #include "prefstable.h" |
||
44 | #include "rawimage.h" |
||
45 | #include "scclocale.h" |
||
46 | #include "sccolorengine.h" |
||
47 | #include "scconfig.h" |
||
48 | #include "scmimedata.h" |
||
49 | #include "scpaths.h" |
||
50 | #include "scribusXml.h" |
||
51 | #include "scribuscore.h" |
||
19093 | craig | 52 | #include "scribusdoc.h" |
53 | #include "scribusview.h" |
||
17199 | fschmid | 54 | #include "sctextstream.h" |
55 | #include "selection.h" |
||
19093 | craig | 56 | #include "ui/customfdialog.h" |
57 | #include "ui/missing.h" |
||
58 | #include "ui/multiprogressdialog.h" |
||
59 | #include "ui/propertiespalette.h" |
||
17199 | fschmid | 60 | #include "undomanager.h" |
61 | #include "util.h" |
||
62 | #include "util_formats.h" |
||
63 | #include "util_math.h" |
||
64 | |||
65 | IdmlPlug::IdmlPlug(ScribusDoc* doc, int flags) |
||
66 | { |
||
67 | tmpSel = new Selection(this, false); |
||
68 | m_Doc = doc; |
||
69 | importerFlags = flags; |
||
70 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
22527 | craig | 71 | progressDialog = nullptr; |
23619 | jghali | 72 | m_zip = nullptr; |
17199 | fschmid | 73 | } |
74 | |||
22635 | craig | 75 | QString IdmlPlug::getNodeValue(QDomNode &baseNode, const QString& path) |
17199 | fschmid | 76 | { |
23619 | jghali | 77 | QString ret; |
24202 | craig | 78 | QStringList pathParts = path.split("/", Qt::SkipEmptyParts); |
17199 | fschmid | 79 | QDomNode n = baseNode.namedItem(pathParts[0]); |
23619 | jghali | 80 | if (n.isNull()) |
81 | return QString(); |
||
82 | |||
17199 | fschmid | 83 | bool fail = false; |
23619 | jghali | 84 | for (int a = 1; a < pathParts.count(); a++) |
17199 | fschmid | 85 | { |
23619 | jghali | 86 | n = n.namedItem(pathParts[a]); |
87 | if (n.isNull()) |
||
17199 | fschmid | 88 | { |
23619 | jghali | 89 | fail = true; |
90 | break; |
||
17199 | fschmid | 91 | } |
92 | } |
||
23619 | jghali | 93 | if (!fail) |
94 | { |
||
95 | QDomElement e = n.toElement(); |
||
96 | if (!e.isNull()) |
||
97 | ret = e.text(); |
||
98 | } |
||
17199 | fschmid | 99 | return ret; |
100 | } |
||
101 | |||
22635 | craig | 102 | QImage IdmlPlug::readThumbnail(const QString& fName) |
17199 | fschmid | 103 | { |
104 | QImage tmp; |
||
17222 | fschmid | 105 | QByteArray f; |
17199 | fschmid | 106 | if ( !QFile::exists(fName) ) |
107 | return QImage(); |
||
17222 | fschmid | 108 | QFileInfo fi = QFileInfo(fName); |
109 | QString ext = fi.suffix().toLower(); |
||
110 | if (ext == "idml") |
||
111 | { |
||
23619 | jghali | 112 | m_zip = new ScZipHandler(); |
113 | if (!m_zip->open(fName)) |
||
18913 | fschmid | 114 | { |
23619 | jghali | 115 | delete m_zip; |
116 | m_zip = nullptr; |
||
18913 | fschmid | 117 | return QImage(); |
118 | } |
||
23619 | jghali | 119 | if (m_zip->contains("designmap.xml")) |
120 | m_zip->read("designmap.xml", f); |
||
121 | delete m_zip; |
||
122 | m_zip = nullptr; |
||
17222 | fschmid | 123 | } |
124 | else if (ext == "idms") |
||
125 | { |
||
18913 | fschmid | 126 | loadRawText(fName, f); |
17222 | fschmid | 127 | } |
23619 | jghali | 128 | |
129 | if (f.isEmpty()) |
||
130 | return QImage(); |
||
131 | |||
132 | if (!designMapDom.setContent(f)) |
||
133 | return QImage(); |
||
134 | |||
135 | bool found = false; |
||
136 | QDomElement docElem = designMapDom.documentElement(); |
||
137 | QString metaD = getNodeValue(docElem, "MetadataPacketPreference/Properties/Contents"); |
||
138 | QDomDocument rdfD; |
||
139 | rdfD.setContent(metaD); |
||
140 | QDomElement docElemR = rdfD.documentElement(); |
||
141 | for (QDomNode drawPag = docElemR.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling()) |
||
17199 | fschmid | 142 | { |
23619 | jghali | 143 | QDomElement dpg = drawPag.toElement(); |
144 | if (dpg.tagName() == "rdf:RDF") |
||
17199 | fschmid | 145 | { |
23619 | jghali | 146 | for (QDomNode drawPag2 = dpg.firstChild(); !drawPag2.isNull(); drawPag2 = drawPag2.nextSibling()) |
17199 | fschmid | 147 | { |
23619 | jghali | 148 | QDomElement dpg2 = drawPag2.toElement(); |
149 | if (dpg2.hasAttribute("xmlns:xmpGImg")) |
||
17199 | fschmid | 150 | { |
23619 | jghali | 151 | QByteArray imgD = getNodeValue(dpg2, "xmp:Thumbnails/rdf:Alt/rdf:li/xmpGImg:image").toLatin1(); |
152 | QByteArray inlineImageData = QByteArray::fromBase64(imgD); |
||
153 | tmp.loadFromData(inlineImageData); |
||
154 | found = true; |
||
17199 | fschmid | 155 | } |
156 | } |
||
157 | } |
||
23619 | jghali | 158 | } |
159 | if (!found) |
||
160 | { |
||
161 | progressDialog = nullptr; |
||
162 | QFileInfo fi = QFileInfo(fName); |
||
163 | baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/")); |
||
164 | docWidth = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth; |
||
165 | docHeight = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight; |
||
166 | m_Doc = new ScribusDoc(); |
||
167 | m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom"); |
||
168 | m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false); |
||
169 | m_Doc->addPage(0); |
||
170 | m_Doc->setGUI(false, ScCore->primaryMainWindow(), nullptr); |
||
171 | baseX = m_Doc->currentPage()->xOffset(); |
||
172 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
173 | Elements.clear(); |
||
174 | m_Doc->setLoading(true); |
||
175 | m_Doc->DoDrawing = false; |
||
176 | m_Doc->scMW()->setScriptRunning(true); |
||
177 | QString CurDirP = QDir::currentPath(); |
||
178 | QDir::setCurrent(fi.path()); |
||
179 | if (convert(fName)) |
||
17199 | fschmid | 180 | { |
23619 | jghali | 181 | tmpSel->clear(); |
182 | QDir::setCurrent(CurDirP); |
||
183 | if (Elements.count() > 1) |
||
184 | m_Doc->groupObjectsList(Elements); |
||
185 | m_Doc->DoDrawing = true; |
||
186 | m_Doc->m_Selection->delaySignalsOn(); |
||
187 | QImage tmpImage; |
||
188 | if (Elements.count() > 0) |
||
17199 | fschmid | 189 | { |
23619 | jghali | 190 | for (int dre=0; dre<Elements.count(); ++dre) |
17267 | fschmid | 191 | { |
23619 | jghali | 192 | tmpSel->addItem(Elements.at(dre), true); |
17267 | fschmid | 193 | } |
23619 | jghali | 194 | tmpSel->setGroupRect(); |
195 | double xs = tmpSel->width(); |
||
196 | double ys = tmpSel->height(); |
||
197 | tmpImage = Elements.at(0)->DrawObj_toImage(500); |
||
198 | tmpImage.setText("XSize", QString("%1").arg(xs)); |
||
199 | tmpImage.setText("YSize", QString("%1").arg(ys)); |
||
17199 | fschmid | 200 | } |
22609 | craig | 201 | m_Doc->scMW()->setScriptRunning(false); |
23619 | jghali | 202 | m_Doc->setLoading(false); |
203 | m_Doc->m_Selection->delaySignalsOff(); |
||
22609 | craig | 204 | delete m_Doc; |
23619 | jghali | 205 | return tmpImage; |
17199 | fschmid | 206 | } |
23619 | jghali | 207 | QDir::setCurrent(CurDirP); |
208 | m_Doc->DoDrawing = true; |
||
209 | m_Doc->scMW()->setScriptRunning(false); |
||
210 | delete m_Doc; |
||
17199 | fschmid | 211 | } |
17267 | fschmid | 212 | return tmp; |
17199 | fschmid | 213 | } |
214 | |||
23705 | craig | 215 | bool IdmlPlug::readColors(const QString& fileName, ColorList & colors) |
17199 | fschmid | 216 | { |
217 | bool success = false; |
||
218 | importedColors.clear(); |
||
23619 | jghali | 219 | |
17199 | fschmid | 220 | QByteArray f; |
23705 | craig | 221 | QFileInfo fi = QFileInfo(fileName); |
17222 | fschmid | 222 | QString ext = fi.suffix().toLower(); |
223 | if (ext == "idml") |
||
224 | { |
||
23619 | jghali | 225 | m_zip = new ScZipHandler(); |
23705 | craig | 226 | if (!m_zip->open(fileName)) |
18913 | fschmid | 227 | { |
23619 | jghali | 228 | delete m_zip; |
229 | m_zip = nullptr; |
||
18913 | fschmid | 230 | return false; |
231 | } |
||
23619 | jghali | 232 | if (m_zip->contains("designmap.xml")) |
233 | m_zip->read("designmap.xml", f); |
||
17222 | fschmid | 234 | } |
235 | else if (ext == "idms") |
||
236 | { |
||
23705 | craig | 237 | loadRawText(fileName, f); |
17222 | fschmid | 238 | } |
23619 | jghali | 239 | |
240 | if (f.isEmpty()) |
||
17199 | fschmid | 241 | { |
23619 | jghali | 242 | delete m_zip; |
243 | m_zip = nullptr; |
||
244 | return false; |
||
245 | } |
||
246 | |||
247 | if (!designMapDom.setContent(f)) |
||
248 | { |
||
249 | delete m_zip; |
||
250 | m_zip = nullptr; |
||
251 | return false; |
||
252 | } |
||
253 | |||
254 | m_Doc = new ScribusDoc(); |
||
255 | m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom"); |
||
256 | m_Doc->setPage(1, 1, 0, 0, 0, 0, 0, 0, false, false); |
||
257 | m_Doc->addPage(0); |
||
258 | m_Doc->setGUI(false, ScCore->primaryMainWindow(), nullptr); |
||
259 | |||
260 | QDomElement docElem = designMapDom.documentElement(); |
||
261 | if (ext == "idms") |
||
262 | { |
||
263 | parseGraphicsXMLNode(docElem); |
||
264 | } |
||
265 | else |
||
266 | { |
||
267 | for (QDomNode drawPag = docElem.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling()) |
||
17199 | fschmid | 268 | { |
23619 | jghali | 269 | QDomElement dpg = drawPag.toElement(); |
270 | if (dpg.tagName() == "idPkg:Graphic") |
||
17199 | fschmid | 271 | { |
23619 | jghali | 272 | if (!parseGraphicsXML(dpg)) |
17199 | fschmid | 273 | { |
23619 | jghali | 274 | delete m_zip; |
275 | m_zip = nullptr; |
||
276 | return false; |
||
17199 | fschmid | 277 | } |
278 | } |
||
279 | } |
||
280 | } |
||
23619 | jghali | 281 | |
282 | delete m_zip; |
||
283 | m_zip = nullptr; |
||
284 | |||
17199 | fschmid | 285 | if (importedColors.count() != 0) |
286 | { |
||
287 | colors = m_Doc->PageColors; |
||
288 | success = true; |
||
289 | } |
||
290 | delete m_Doc; |
||
291 | return success; |
||
292 | } |
||
293 | |||
22635 | craig | 294 | bool IdmlPlug::import(const QString& fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress) |
17199 | fschmid | 295 | { |
296 | bool success = false; |
||
297 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
298 | importerFlags = flags; |
||
299 | cancel = false; |
||
300 | bool ret = false; |
||
301 | firstLayer = true; |
||
302 | firstPage = true; |
||
303 | pagecount = 1; |
||
17222 | fschmid | 304 | mpagecount = 0; |
22635 | craig | 305 | QFileInfo fi = QFileInfo(fNameIn); |
23619 | jghali | 306 | if (!ScCore->usingGUI()) |
17199 | fschmid | 307 | { |
308 | interactive = false; |
||
309 | showProgress = false; |
||
310 | } |
||
311 | baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/")); |
||
23619 | jghali | 312 | if (showProgress) |
17199 | fschmid | 313 | { |
22609 | craig | 314 | ScribusMainWindow* mw=(m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW(); |
17199 | fschmid | 315 | progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw ); |
316 | QStringList barNames, barTexts; |
||
317 | barNames << "GI"; |
||
318 | barTexts << tr("Analyzing File:"); |
||
319 | QList<bool> barsNumeric; |
||
320 | barsNumeric << false; |
||
321 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
322 | progressDialog->setOverallTotalSteps(3); |
||
323 | progressDialog->setOverallProgress(0); |
||
324 | progressDialog->setProgress("GI", 0); |
||
325 | progressDialog->show(); |
||
326 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
||
327 | qApp->processEvents(); |
||
328 | } |
||
329 | else |
||
22527 | craig | 330 | progressDialog = nullptr; |
17199 | fschmid | 331 | if (progressDialog) |
332 | { |
||
333 | progressDialog->setOverallProgress(1); |
||
334 | qApp->processEvents(); |
||
335 | } |
||
336 | /* Set default Page to size defined in Preferences */ |
||
23060 | craig | 337 | docWidth = PrefsManager::instance().appPrefs.docSetupPrefs.pageWidth; |
338 | docHeight = PrefsManager::instance().appPrefs.docSetupPrefs.pageHeight; |
||
17199 | fschmid | 339 | baseX = 0; |
340 | baseY = 0; |
||
341 | if (!interactive || (flags & LoadSavePlugin::lfInsertPage)) |
||
342 | { |
||
343 | m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false); |
||
344 | m_Doc->addPage(0); |
||
345 | m_Doc->view()->addPage(0, true); |
||
346 | baseX = 0; |
||
347 | baseY = 0; |
||
348 | } |
||
349 | else |
||
350 | { |
||
351 | if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc)) |
||
352 | { |
||
353 | m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true); |
||
354 | ScCore->primaryMainWindow()->HaveNewDoc(); |
||
355 | ret = true; |
||
356 | baseX = 0; |
||
357 | baseY = 0; |
||
358 | baseX = m_Doc->currentPage()->xOffset(); |
||
359 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
360 | } |
||
361 | } |
||
362 | if ((!ret) && (interactive)) |
||
363 | { |
||
364 | baseX = m_Doc->currentPage()->xOffset(); |
||
365 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
366 | } |
||
367 | if ((ret) || (!interactive)) |
||
368 | { |
||
369 | if (docWidth > docHeight) |
||
370 | m_Doc->setPageOrientation(1); |
||
371 | else |
||
372 | m_Doc->setPageOrientation(0); |
||
373 | m_Doc->setPageSize("Custom"); |
||
374 | } |
||
22527 | craig | 375 | if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr)) |
23390 | craig | 376 | m_Doc->view()->deselectItems(); |
17199 | fschmid | 377 | Elements.clear(); |
378 | m_Doc->setLoading(true); |
||
379 | m_Doc->DoDrawing = false; |
||
22527 | craig | 380 | if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr)) |
17199 | fschmid | 381 | m_Doc->view()->updatesOn(false); |
382 | m_Doc->scMW()->setScriptRunning(true); |
||
18181 | fschmid | 383 | qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); |
17199 | fschmid | 384 | QString CurDirP = QDir::currentPath(); |
385 | QDir::setCurrent(fi.path()); |
||
22635 | craig | 386 | if (convert(fNameIn)) |
17199 | fschmid | 387 | { |
388 | tmpSel->clear(); |
||
389 | QDir::setCurrent(CurDirP); |
||
390 | if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc))) |
||
391 | m_Doc->groupObjectsList(Elements); |
||
392 | m_Doc->DoDrawing = true; |
||
393 | m_Doc->scMW()->setScriptRunning(false); |
||
394 | m_Doc->setLoading(false); |
||
395 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
396 | if ((Elements.count() > 0) && (!ret) && (interactive)) |
||
397 | { |
||
398 | if (flags & LoadSavePlugin::lfScripted) |
||
399 | { |
||
400 | bool loadF = m_Doc->isLoading(); |
||
401 | m_Doc->setLoading(false); |
||
402 | m_Doc->changed(); |
||
403 | m_Doc->setLoading(loadF); |
||
404 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
405 | { |
||
406 | m_Doc->m_Selection->delaySignalsOn(); |
||
407 | for (int dre=0; dre<Elements.count(); ++dre) |
||
408 | { |
||
409 | m_Doc->m_Selection->addItem(Elements.at(dre), true); |
||
410 | } |
||
411 | m_Doc->m_Selection->delaySignalsOff(); |
||
412 | m_Doc->m_Selection->setGroupRect(); |
||
22527 | craig | 413 | if (m_Doc->view() != nullptr) |
19856 | fschmid | 414 | m_Doc->view()->updatesOn(true); |
17199 | fschmid | 415 | } |
416 | } |
||
417 | else |
||
418 | { |
||
419 | m_Doc->DragP = true; |
||
22609 | craig | 420 | m_Doc->DraggedElem = nullptr; |
17199 | fschmid | 421 | m_Doc->DragElements.clear(); |
422 | m_Doc->m_Selection->delaySignalsOn(); |
||
423 | for (int dre=0; dre<Elements.count(); ++dre) |
||
424 | { |
||
425 | tmpSel->addItem(Elements.at(dre), true); |
||
426 | } |
||
427 | tmpSel->setGroupRect(); |
||
22686 | jghali | 428 | ScElemMimeData* md = ScriXmlDoc::writeToMimeData(m_Doc, tmpSel); |
17199 | fschmid | 429 | m_Doc->itemSelection_DeleteItem(tmpSel); |
430 | m_Doc->view()->updatesOn(true); |
||
431 | m_Doc->m_Selection->delaySignalsOff(); |
||
432 | // We must copy the TransationSettings object as it is owned |
||
433 | // by handleObjectImport method afterwards |
||
434 | TransactionSettings* transacSettings = new TransactionSettings(trSettings); |
||
435 | m_Doc->view()->handleObjectImport(md, transacSettings); |
||
436 | m_Doc->DragP = false; |
||
22609 | craig | 437 | m_Doc->DraggedElem = nullptr; |
17199 | fschmid | 438 | m_Doc->DragElements.clear(); |
439 | } |
||
440 | } |
||
441 | else |
||
442 | { |
||
443 | m_Doc->changed(); |
||
444 | m_Doc->reformPages(); |
||
445 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
446 | m_Doc->view()->updatesOn(true); |
||
447 | } |
||
448 | success = true; |
||
449 | } |
||
450 | else |
||
451 | { |
||
452 | QDir::setCurrent(CurDirP); |
||
453 | m_Doc->DoDrawing = true; |
||
454 | m_Doc->scMW()->setScriptRunning(false); |
||
455 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
456 | m_Doc->view()->updatesOn(true); |
||
457 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
458 | } |
||
459 | if (interactive) |
||
460 | m_Doc->setLoading(false); |
||
461 | //CB If we have a gui we must refresh it if we have used the progressbar |
||
462 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
463 | { |
||
464 | if ((showProgress) && (!interactive)) |
||
465 | m_Doc->view()->DrawNew(); |
||
466 | } |
||
18181 | fschmid | 467 | qApp->restoreOverrideCursor(); |
17199 | fschmid | 468 | return success; |
469 | } |
||
470 | |||
471 | IdmlPlug::~IdmlPlug() |
||
472 | { |
||
22609 | craig | 473 | delete progressDialog; |
17199 | fschmid | 474 | delete tmpSel; |
475 | } |
||
476 | |||
22609 | craig | 477 | bool IdmlPlug::convert(const QString& fn) |
17199 | fschmid | 478 | { |
479 | Coords.resize(0); |
||
480 | Coords.svgInit(); |
||
481 | importedColors.clear(); |
||
482 | def_fillColor = CommonStrings::None; |
||
483 | def_strokeColor = CommonStrings::None; |
||
484 | def_fillGradient = ""; |
||
17232 | fschmid | 485 | def_strokeGradient = ""; |
17199 | fschmid | 486 | def_Blendmode = 0; |
487 | def_fillBlendmode = 0; |
||
488 | def_strokeBlendmode = 0; |
||
489 | def_fillTint = 100; |
||
490 | def_strokeTint = 100; |
||
491 | def_lineWidth = 0; |
||
492 | def_Opacity = 0.0; |
||
493 | def_fillOpacity = 0.0; |
||
494 | def_strokeOpacity = 0.0; |
||
495 | def_gradientAngle = 0.0; |
||
496 | def_gradientLen = 0.0; |
||
497 | def_gradientX = 0.0; |
||
498 | def_gradientY = 0.0; |
||
17232 | fschmid | 499 | def_gradientStrokeStartX = 0; |
500 | def_gradientStrokeStartY = 0; |
||
501 | def_gradientStrokeLength = 0; |
||
502 | def_gradientStrokeAngle = 0; |
||
17239 | fschmid | 503 | def_Extra = 0; |
504 | def_TExtra = 0; |
||
505 | def_BExtra = 0; |
||
506 | def_RExtra = 0; |
||
17206 | fschmid | 507 | def_TextFlow = PageItem::TextFlowDisabled; |
17239 | fschmid | 508 | def_TextColumnCount = 1; |
509 | def_TextColumnGutter = 0; |
||
510 | def_TextColumnFixedWidth = 0; |
||
18401 | fschmid | 511 | def_LeftLineEnd = "None"; |
512 | def_RightLineEnd = "None"; |
||
17209 | fschmid | 513 | frameLinks.clear(); |
514 | frameTargets.clear(); |
||
515 | importedColors.clear(); |
||
516 | colorTranslate.clear(); |
||
517 | importedGradients.clear(); |
||
518 | gradientTranslate.clear(); |
||
519 | gradientTypeMap.clear(); |
||
520 | layerTranslate.clear(); |
||
521 | storyMap.clear(); |
||
522 | styleTranslate.clear(); |
||
523 | charStyleTranslate.clear(); |
||
17210 | fschmid | 524 | ObjectStyles.clear(); |
22721 | jghali | 525 | if (progressDialog) |
17199 | fschmid | 526 | { |
527 | progressDialog->setOverallProgress(2); |
||
528 | progressDialog->setLabel("GI", tr("Generating Items")); |
||
529 | qApp->processEvents(); |
||
530 | } |
||
531 | colorTranslate.insert("Swatch/None", CommonStrings::None); |
||
532 | bool retVal = true; |
||
533 | bool firstSpread = true; |
||
23619 | jghali | 534 | |
17199 | fschmid | 535 | QByteArray f; |
17222 | fschmid | 536 | QFileInfo fi = QFileInfo(fn); |
537 | QString ext = fi.suffix().toLower(); |
||
538 | if (ext == "idml") |
||
539 | { |
||
23619 | jghali | 540 | m_zip = new ScZipHandler(); |
541 | if (!m_zip->open(fn)) |
||
18913 | fschmid | 542 | { |
23619 | jghali | 543 | delete m_zip; |
544 | m_zip = nullptr; |
||
18913 | fschmid | 545 | return false; |
546 | } |
||
23619 | jghali | 547 | if (m_zip->contains("designmap.xml")) |
548 | m_zip->read("designmap.xml", f); |
||
17222 | fschmid | 549 | } |
550 | else if (ext == "idms") |
||
551 | { |
||
18913 | fschmid | 552 | loadRawText(fn, f); |
17222 | fschmid | 553 | } |
23619 | jghali | 554 | |
555 | if (f.isEmpty()) |
||
17199 | fschmid | 556 | { |
23619 | jghali | 557 | if (progressDialog) |
558 | progressDialog->close(); |
||
559 | delete m_zip; |
||
560 | m_zip = nullptr; |
||
561 | return false; |
||
562 | } |
||
563 | |||
564 | if (!designMapDom.setContent(f)) |
||
565 | { |
||
566 | if (progressDialog) |
||
567 | progressDialog->close(); |
||
568 | delete m_zip; |
||
569 | m_zip = nullptr; |
||
570 | return false; |
||
571 | } |
||
572 | |||
573 | QDomElement docElem = designMapDom.documentElement(); |
||
574 | QString activeLayer = docElem.attribute("ActiveLayer"); |
||
575 | if (ext == "idms") |
||
576 | { |
||
577 | for (QDomNode drawPag = docElem.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling()) |
||
17199 | fschmid | 578 | { |
23619 | jghali | 579 | QDomElement dpg = drawPag.toElement(); |
580 | if (dpg.tagName() == "Layer") |
||
17199 | fschmid | 581 | { |
23619 | jghali | 582 | QString layerSelf = dpg.attribute("Self"); |
583 | QString layerName = dpg.attribute("Name"); |
||
584 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
17199 | fschmid | 585 | { |
23619 | jghali | 586 | int currentLayer = 0; |
587 | if (!firstLayer) |
||
588 | currentLayer = m_Doc->addLayer(layerName); |
||
589 | else |
||
590 | m_Doc->changeLayerName(currentLayer, layerName); |
||
591 | m_Doc->setLayerVisible(currentLayer, (dpg.attribute("Visible") == "true")); |
||
592 | m_Doc->setLayerLocked(currentLayer, (dpg.attribute("Locked") == "true")); |
||
593 | m_Doc->setLayerPrintable(currentLayer, (dpg.attribute("Printable") == "true")); |
||
594 | m_Doc->setLayerFlow(currentLayer, (dpg.attribute("IgnoreWrap","") == "true")); |
||
595 | } |
||
596 | layerTranslate.insert(layerSelf, layerName); |
||
597 | firstLayer = false; |
||
598 | } |
||
599 | } |
||
600 | parseFontsXMLNode(docElem); |
||
601 | parseGraphicsXMLNode(docElem); |
||
602 | parseStylesXMLNode(docElem); |
||
603 | parsePreferencesXMLNode(docElem); |
||
604 | parseSpreadXMLNode(docElem); |
||
605 | parseStoryXMLNode(docElem); |
||
606 | } |
||
607 | else |
||
608 | { |
||
609 | for (QDomNode drawPag = docElem.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling()) |
||
610 | { |
||
611 | QDomElement dpg = drawPag.toElement(); |
||
612 | if (dpg.tagName() == "Layer") |
||
613 | { |
||
614 | QString layerSelf = dpg.attribute("Self"); |
||
615 | QString layerName = dpg.attribute("Name"); |
||
616 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
617 | { |
||
618 | int currentLayer = 0; |
||
619 | if (!firstLayer) |
||
620 | currentLayer = m_Doc->addLayer(layerName); |
||
621 | else |
||
622 | m_Doc->changeLayerName(currentLayer, layerName); |
||
623 | m_Doc->setLayerVisible(currentLayer, (dpg.attribute("Visible") == "true")); |
||
624 | m_Doc->setLayerLocked(currentLayer, (dpg.attribute("Locked") == "true")); |
||
625 | m_Doc->setLayerPrintable(currentLayer, (dpg.attribute("Printable") == "true")); |
||
626 | m_Doc->setLayerFlow(currentLayer, (dpg.attribute("IgnoreWrap","") == "true")); |
||
627 | } |
||
628 | layerTranslate.insert(layerSelf, layerName); |
||
629 | firstLayer = false; |
||
630 | } |
||
631 | if (dpg.tagName() == "idPkg:Fonts") |
||
632 | { |
||
633 | if (!parseFontsXML(dpg)) |
||
634 | { |
||
635 | retVal = false; |
||
636 | break; |
||
637 | } |
||
638 | } |
||
639 | if (dpg.tagName() == "idPkg:Graphic") |
||
640 | { |
||
641 | if (!parseGraphicsXML(dpg)) |
||
642 | { |
||
643 | retVal = false; |
||
644 | break; |
||
645 | } |
||
646 | } |
||
647 | if (dpg.tagName() == "idPkg:Styles") |
||
648 | { |
||
649 | if (!parseStylesXML(dpg)) |
||
650 | { |
||
651 | retVal = false; |
||
652 | break; |
||
653 | } |
||
654 | } |
||
655 | if (dpg.tagName() == "idPkg:Preferences") |
||
656 | { |
||
657 | if (!parsePreferencesXML(dpg)) |
||
658 | { |
||
659 | retVal = false; |
||
660 | break; |
||
661 | } |
||
662 | } |
||
663 | if (dpg.tagName() == "idPkg:MasterSpread") |
||
664 | { |
||
665 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
666 | { |
||
667 | if (!parseSpreadXML(dpg)) |
||
17199 | fschmid | 668 | { |
23619 | jghali | 669 | retVal = false; |
670 | break; |
||
17199 | fschmid | 671 | } |
672 | } |
||
17222 | fschmid | 673 | } |
23619 | jghali | 674 | if (dpg.tagName() == "idPkg:Spread") |
17222 | fschmid | 675 | { |
23619 | jghali | 676 | if (!(importerFlags & LoadSavePlugin::lfCreateDoc)) |
17199 | fschmid | 677 | { |
23619 | jghali | 678 | if (firstSpread) |
17199 | fschmid | 679 | { |
23619 | jghali | 680 | parseSpreadXML(dpg); |
681 | firstSpread = false; |
||
17199 | fschmid | 682 | } |
683 | } |
||
23619 | jghali | 684 | else if (!parseSpreadXML(dpg)) |
685 | { |
||
686 | retVal = false; |
||
687 | break; |
||
688 | } |
||
17199 | fschmid | 689 | } |
23619 | jghali | 690 | if (dpg.tagName() == "idPkg:Story") |
17209 | fschmid | 691 | { |
23619 | jghali | 692 | if (!parseStoryXML(dpg)) |
17209 | fschmid | 693 | { |
23619 | jghali | 694 | retVal = false; |
695 | break; |
||
17209 | fschmid | 696 | } |
697 | } |
||
17199 | fschmid | 698 | } |
699 | } |
||
23619 | jghali | 700 | if (!frameLinks.isEmpty()) |
701 | { |
||
702 | QMap<PageItem*, QString>::Iterator lc; |
||
703 | for (lc = frameLinks.begin(); lc != frameLinks.end(); ++lc) |
||
704 | { |
||
705 | PageItem *Its = lc.key(); |
||
706 | PageItem *Itn = frameTargets[lc.value()]; |
||
707 | if (Its->canBeLinkedTo(Itn)) |
||
708 | Its->link(Itn); |
||
709 | } |
||
710 | } |
||
711 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
712 | { |
||
713 | if (layerTranslate.contains(activeLayer)) |
||
714 | activeLayer = layerTranslate[activeLayer]; |
||
715 | else |
||
716 | activeLayer = m_Doc->layerName(0); |
||
717 | m_Doc->setActiveLayer(activeLayer); |
||
718 | } |
||
719 | |||
720 | delete m_zip; |
||
721 | m_zip = nullptr; |
||
722 | |||
17199 | fschmid | 723 | if (progressDialog) |
724 | progressDialog->close(); |
||
725 | return retVal; |
||
726 | } |
||
727 | |||
18348 | fschmid | 728 | bool IdmlPlug::parseFontsXML(const QDomElement& grElem) |
729 | { |
||
730 | QDomElement grNode; |
||
731 | QDomDocument grMapDom; |
||
732 | if (grElem.hasAttribute("src")) |
||
733 | { |
||
734 | QByteArray f2; |
||
23619 | jghali | 735 | m_zip->read(grElem.attribute("src"), f2); |
736 | if (!grMapDom.setContent(f2)) |
||
18348 | fschmid | 737 | return false; |
23619 | jghali | 738 | grNode = grMapDom.documentElement(); |
18348 | fschmid | 739 | } |
740 | else |
||
741 | { |
||
23619 | jghali | 742 | if (!grElem.hasChildNodes()) |
18348 | fschmid | 743 | return false; |
23619 | jghali | 744 | grNode = grElem; |
18348 | fschmid | 745 | } |
746 | parseFontsXMLNode(grNode); |
||
747 | return true; |
||
748 | } |
||
749 | |||
750 | void IdmlPlug::parseFontsXMLNode(const QDomElement& grNode) |
||
751 | { |
||
752 | for (QDomNode n = grNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
753 | { |
||
754 | QDomElement e = n.toElement(); |
||
755 | if (e.tagName() == "FontFamily") |
||
756 | { |
||
757 | QString family = e.attribute("Name"); |
||
758 | QMap<QString, QString> styleMap; |
||
22723 | jghali | 759 | for (QDomNode gr = e.firstChild(); !gr.isNull(); gr = gr.nextSibling()) |
18348 | fschmid | 760 | { |
761 | QDomElement grs = gr.toElement(); |
||
762 | if (grs.tagName() == "Font") |
||
763 | { |
||
764 | QString styleName = grs.attribute("FontStyleName").remove("$ID/"); |
||
765 | QString postName = grs.attribute("PostScriptName").remove("$ID/"); |
||
766 | styleMap.insert(styleName, postName); |
||
767 | } |
||
768 | } |
||
769 | fontTranslateMap.insert(family, styleMap); |
||
770 | } |
||
771 | } |
||
772 | } |
||
773 | |||
17199 | fschmid | 774 | bool IdmlPlug::parseGraphicsXML(const QDomElement& grElem) |
775 | { |
||
776 | QDomElement grNode; |
||
777 | QDomDocument grMapDom; |
||
778 | if (grElem.hasAttribute("src")) |
||
779 | { |
||
780 | QByteArray f2; |
||
23619 | jghali | 781 | m_zip->read(grElem.attribute("src"), f2); |
782 | if (!grMapDom.setContent(f2)) |
||
17199 | fschmid | 783 | return false; |
23619 | jghali | 784 | grNode = grMapDom.documentElement(); |
17199 | fschmid | 785 | } |
786 | else |
||
787 | { |
||
23619 | jghali | 788 | if (!grElem.hasChildNodes()) |
17199 | fschmid | 789 | return false; |
23619 | jghali | 790 | grNode = grElem; |
17199 | fschmid | 791 | } |
17222 | fschmid | 792 | parseGraphicsXMLNode(grNode); |
793 | return true; |
||
794 | } |
||
795 | |||
796 | void IdmlPlug::parseGraphicsXMLNode(const QDomElement& grNode) |
||
18348 | fschmid | 797 | { |
17199 | fschmid | 798 | for (QDomNode n = grNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
799 | { |
||
800 | QDomElement e = n.toElement(); |
||
801 | if (e.tagName() == "Color") |
||
802 | { |
||
803 | QString colorSelf = e.attribute("Self"); |
||
804 | QString colorName = e.attribute("Self").remove(0, 6); |
||
805 | QString colorData = e.attribute("ColorValue"); |
||
806 | QString colorSpace = e.attribute("Space"); |
||
807 | QString colorModel = e.attribute("Model"); |
||
808 | if (colorSpace == "CMYK") |
||
809 | { |
||
810 | double c, m, y, k; |
||
811 | ScColor tmp; |
||
812 | ScTextStream Code(&colorData, QIODevice::ReadOnly); |
||
813 | Code >> c >> m >> y >> k; |
||
22212 | jghali | 814 | tmp.setColorF(c / 100.0, m / 100.0, y / 100.0, k / 100.0); |
17199 | fschmid | 815 | tmp.setSpotColor(colorModel == "Spot"); |
816 | tmp.setRegistrationColor(colorModel == "Registration"); |
||
817 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, tmp); |
||
818 | if (fNam == colorName) |
||
819 | importedColors.append(fNam); |
||
820 | colorTranslate.insert(colorSelf, fNam); |
||
821 | } |
||
822 | else if (colorSpace == "RGB") |
||
823 | { |
||
824 | int r, g, b; |
||
825 | ScColor tmp; |
||
826 | ScTextStream Code(&colorData, QIODevice::ReadOnly); |
||
827 | Code >> r >> g >> b; |
||
22212 | jghali | 828 | tmp.setRgbColor(r, g, b); |
17199 | fschmid | 829 | tmp.setSpotColor(false); |
830 | tmp.setRegistrationColor(false); |
||
831 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, tmp); |
||
832 | if (fNam == colorName) |
||
833 | importedColors.append(fNam); |
||
834 | colorTranslate.insert(colorSelf, fNam); |
||
835 | } |
||
22398 | jghali | 836 | else if (colorSpace == "LAB") |
837 | { |
||
838 | double L, a, b; |
||
839 | ScColor tmp; |
||
840 | ScTextStream Code(&colorData, QIODevice::ReadOnly); |
||
841 | Code >> L >> a >> b; |
||
842 | tmp.setLabColor(L, a, b); |
||
843 | tmp.setSpotColor(false); |
||
844 | tmp.setRegistrationColor(false); |
||
845 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, tmp); |
||
846 | if (fNam == colorName) |
||
847 | importedColors.append(fNam); |
||
848 | colorTranslate.insert(colorSelf, fNam); |
||
849 | } |
||
17199 | fschmid | 850 | } |
17232 | fschmid | 851 | else if (e.tagName() == "Gradient") |
17199 | fschmid | 852 | { |
853 | QString grSelf = e.attribute("Self"); |
||
854 | QString grName = e.attribute("Self").remove(0, 9); |
||
855 | int grTyp = (e.attribute("Type") == "Linear") ? 6 : 7; |
||
856 | VGradient currentGradient = VGradient(VGradient::linear); |
||
857 | currentGradient.clearStops(); |
||
22723 | jghali | 858 | for (QDomNode gr = e.firstChild(); !gr.isNull(); gr = gr.nextSibling()) |
17199 | fschmid | 859 | { |
860 | QDomElement grs = gr.toElement(); |
||
861 | if (grs.tagName() == "GradientStop") |
||
862 | { |
||
863 | QString stopName = grs.attribute("StopColor"); |
||
864 | double stop = grs.attribute("Location", "0.0").toDouble(); |
||
865 | if (colorTranslate.contains(stopName)) |
||
866 | stopName = colorTranslate[stopName]; |
||
867 | else |
||
868 | stopName = "Black"; |
||
869 | const ScColor& gradC = m_Doc->PageColors[stopName]; |
||
870 | currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop / 100.0, 0.5, 1.0, stopName, 100 ); |
||
871 | } |
||
872 | } |
||
873 | if (m_Doc->addGradient(grName, currentGradient)) |
||
874 | importedGradients.append(grName); |
||
875 | gradientTranslate.insert(grSelf, grName); |
||
876 | gradientTypeMap.insert(grSelf, grTyp); |
||
877 | } |
||
17232 | fschmid | 878 | else if (e.tagName() == "Tint") |
879 | { |
||
880 | QString colorSelf = e.attribute("Self"); |
||
881 | QString colorName = e.attribute("Self").remove(0, 5); |
||
882 | QString baseName = e.attribute("BaseColor", "Black"); |
||
883 | double tint = e.attribute("TintValue", "100").toDouble() / 100.0; |
||
884 | if (colorTranslate.contains(baseName)) |
||
885 | { |
||
886 | ScColor tmp = m_Doc->PageColors[colorTranslate[baseName]]; |
||
887 | ScColor res; |
||
888 | if (tmp.getColorModel() == colorModelCMYK) |
||
889 | { |
||
22212 | jghali | 890 | double c, m, y, k; |
17232 | fschmid | 891 | tmp.getCMYK(&c, &m, &y, &k); |
22212 | jghali | 892 | res.setColorF(c * tint, m * tint, y * tint, k * tint); |
17232 | fschmid | 893 | } |
894 | else |
||
895 | { |
||
22212 | jghali | 896 | double r, g, b; |
17232 | fschmid | 897 | tmp.getRGB(&r, &g, &b); |
22212 | jghali | 898 | res.setRgbColorF(r * tint, g * tint, b * tint); |
17232 | fschmid | 899 | } |
900 | res.setSpotColor(false); |
||
901 | res.setRegistrationColor(false); |
||
902 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, res); |
||
903 | if (fNam == colorName) |
||
904 | importedColors.append(fNam); |
||
905 | colorTranslate.insert(colorSelf, fNam); |
||
906 | } |
||
907 | } |
||
17199 | fschmid | 908 | } |
909 | } |
||
910 | |||
911 | bool IdmlPlug::parseStylesXML(const QDomElement& sElem) |
||
912 | { |
||
913 | QDomElement sNode; |
||
914 | QDomDocument sMapDom; |
||
915 | if (sElem.hasAttribute("src")) |
||
916 | { |
||
917 | QByteArray f2; |
||
23619 | jghali | 918 | m_zip->read(sElem.attribute("src"), f2); |
919 | if (!sMapDom.setContent(f2)) |
||
17199 | fschmid | 920 | return false; |
23619 | jghali | 921 | sNode = sMapDom.documentElement(); |
17199 | fschmid | 922 | } |
923 | else |
||
924 | { |
||
23619 | jghali | 925 | if (!sElem.hasChildNodes()) |
17199 | fschmid | 926 | return false; |
23619 | jghali | 927 | sNode = sElem; |
17199 | fschmid | 928 | } |
17222 | fschmid | 929 | parseStylesXMLNode(sNode); |
930 | return true; |
||
931 | } |
||
932 | |||
933 | void IdmlPlug::parseStylesXMLNode(const QDomElement& sNode) |
||
934 | { |
||
17199 | fschmid | 935 | for (QDomNode n = sNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
936 | { |
||
937 | QDomElement e = n.toElement(); |
||
17208 | fschmid | 938 | if (e.tagName() == "RootCharacterStyleGroup") |
939 | { |
||
22723 | jghali | 940 | for (QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling()) |
17208 | fschmid | 941 | { |
942 | QDomElement itpg = it.toElement(); |
||
943 | if (itpg.tagName() == "CharacterStyle") |
||
944 | parseCharacterStyle(itpg); |
||
945 | else if (itpg.tagName() == "CharacterStyleGroup") |
||
946 | { |
||
22723 | jghali | 947 | for (QDomNode its = itpg.firstChild(); !its.isNull(); its = its.nextSibling()) |
17208 | fschmid | 948 | { |
949 | QDomElement itp = its.toElement(); |
||
950 | if (itp.tagName() == "CharacterStyle") |
||
951 | parseCharacterStyle(itp); |
||
952 | } |
||
953 | } |
||
954 | } |
||
955 | } |
||
17199 | fschmid | 956 | if (e.tagName() == "RootParagraphStyleGroup") |
957 | { |
||
22723 | jghali | 958 | for (QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling()) |
17199 | fschmid | 959 | { |
960 | QDomElement itpg = it.toElement(); |
||
961 | if (itpg.tagName() == "ParagraphStyle") |
||
962 | parseParagraphStyle(itpg); |
||
963 | else if (itpg.tagName() == "ParagraphStyleGroup") |
||
964 | { |
||
22723 | jghali | 965 | for (QDomNode its = itpg.firstChild(); !its.isNull(); its = its.nextSibling()) |
17199 | fschmid | 966 | { |
967 | QDomElement itp = its.toElement(); |
||
968 | if (itp.tagName() == "ParagraphStyle") |
||
969 | parseParagraphStyle(itp); |
||
970 | } |
||
971 | } |
||
972 | } |
||
973 | } |
||
17210 | fschmid | 974 | if (e.tagName() == "RootObjectStyleGroup") |
975 | { |
||
22723 | jghali | 976 | for (QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling()) |
17210 | fschmid | 977 | { |
978 | QDomElement itpg = it.toElement(); |
||
979 | if (itpg.tagName() == "ObjectStyle") |
||
980 | parseObjectStyle(itpg); |
||
981 | else if (itpg.tagName() == "ObjectStyleGroup") |
||
982 | { |
||
22723 | jghali | 983 | for (QDomNode its = itpg.firstChild(); !its.isNull(); its = its.nextSibling()) |
17210 | fschmid | 984 | { |
985 | QDomElement itp = its.toElement(); |
||
986 | if (itp.tagName() == "ObjectStyle") |
||
987 | parseObjectStyle(itp); |
||
988 | } |
||
989 | } |
||
990 | } |
||
991 | } |
||
17199 | fschmid | 992 | } |
993 | } |
||
994 | |||
17210 | fschmid | 995 | void IdmlPlug::parseObjectStyle(const QDomElement& styleElem) |
996 | { |
||
997 | ObjectStyle nstyle; |
||
998 | nstyle.fillColor = def_fillColor; |
||
999 | nstyle.strokeColor = def_strokeColor; |
||
1000 | nstyle.fillGradient = ""; |
||
1001 | nstyle.gradientFillStart = QPointF(def_gradientX, def_gradientY); |
||
1002 | nstyle.gradientFillLength = def_gradientLen; |
||
1003 | nstyle.gradientFillAngle = def_gradientAngle; |
||
17232 | fschmid | 1004 | nstyle.strokeGradient = ""; |
1005 | nstyle.gradientStrokeStart = QPointF(def_gradientStrokeStartX, def_gradientStrokeStartY); |
||
1006 | nstyle.gradientStrokeLength = def_gradientStrokeLength; |
||
1007 | nstyle.gradientStrokeAngle = def_gradientStrokeAngle; |
||
17210 | fschmid | 1008 | nstyle.lineWidth = def_lineWidth; |
1009 | nstyle.fillTint = def_fillTint; |
||
1010 | nstyle.strokeTint = def_strokeTint; |
||
1011 | nstyle.Opacity = def_Opacity; |
||
1012 | nstyle.blendMode = def_Blendmode; |
||
1013 | nstyle.parentStyle = ""; |
||
17239 | fschmid | 1014 | nstyle.Extra = def_Extra; |
1015 | nstyle.TExtra = def_TExtra; |
||
1016 | nstyle.BExtra = def_BExtra; |
||
1017 | nstyle.RExtra = def_RExtra; |
||
1018 | nstyle.TextColumnCount = def_TextColumnCount; |
||
1019 | nstyle.TextColumnGutter = def_TextColumnGutter; |
||
1020 | nstyle.TextFlow = def_TextFlow; |
||
18401 | fschmid | 1021 | nstyle.LeftLineEnd = def_LeftLineEnd; |
1022 | nstyle.RightLineEnd = def_RightLineEnd; |
||
22723 | jghali | 1023 | for (QDomNode itp = styleElem.firstChild(); !itp.isNull(); itp = itp.nextSibling()) |
17210 | fschmid | 1024 | { |
1025 | QDomElement itpr = itp.toElement(); |
||
1026 | if (itpr.tagName() == "Properties") |
||
1027 | { |
||
22723 | jghali | 1028 | for (QDomNode itpp = itpr.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
17210 | fschmid | 1029 | { |
1030 | QDomElement i = itpp.toElement(); |
||
1031 | if (i.tagName() == "BasedOn") |
||
1032 | { |
||
1033 | QString ps = i.text(); |
||
1034 | if (ps != "$ID/[None]") |
||
1035 | nstyle.parentStyle = ps; |
||
1036 | } |
||
1037 | } |
||
1038 | } |
||
17239 | fschmid | 1039 | if (itpr.tagName() == "TextWrapPreference") |
1040 | { |
||
1041 | if (itpr.hasAttribute("TextWrapMode")) |
||
1042 | { |
||
1043 | if (itpr.attribute("TextWrapMode") == "None") |
||
1044 | nstyle.TextFlow = PageItem::TextFlowDisabled; |
||
1045 | else if (itpr.attribute("TextWrapMode") == "BoundingBoxTextWrap") |
||
1046 | nstyle.TextFlow = PageItem::TextFlowUsesBoundingBox; |
||
1047 | else if (itpr.attribute("TextWrapMode") == "Contour") |
||
1048 | nstyle.TextFlow = PageItem::TextFlowUsesFrameShape; |
||
1049 | } |
||
1050 | } |
||
1051 | else if (itpr.tagName() == "TextFramePreference") |
||
1052 | { |
||
1053 | if (itpr.hasAttribute("TextColumnCount")) |
||
1054 | nstyle.TextColumnCount = itpr.attribute("TextColumnCount").toInt(); |
||
1055 | if (itpr.hasAttribute("TextColumnGutter")) |
||
1056 | nstyle.TextColumnGutter = itpr.attribute("TextColumnGutter").toDouble(); |
||
1057 | if (itpr.hasAttribute("TextColumnFixedWidth")) |
||
1058 | nstyle.TextColumnFixedWidth = itpr.attribute("TextColumnFixedWidth").toDouble(); |
||
22723 | jghali | 1059 | for (QDomNode itpp = itpr.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
17239 | fschmid | 1060 | { |
1061 | QDomElement i = itpp.toElement(); |
||
1062 | if (i.tagName() == "Properties") |
||
1063 | { |
||
22723 | jghali | 1064 | for (QDomNode it = i.firstChild(); !it.isNull(); it = it.nextSibling()) |
17239 | fschmid | 1065 | { |
1066 | QDomElement itx = it.toElement(); |
||
1067 | if (itx.tagName() == "InsetSpacing") |
||
1068 | { |
||
1069 | if (itx.attribute("type") == "unit") |
||
1070 | nstyle.Extra = nstyle.TExtra = nstyle.BExtra = nstyle.RExtra = itx.text().toDouble(); |
||
1071 | else if (itx.attribute("type") == "list") |
||
1072 | { |
||
1073 | int cc = 0; |
||
22723 | jghali | 1074 | for (QDomNode ity = itx.firstChild(); !ity.isNull(); ity = ity.nextSibling()) |
17239 | fschmid | 1075 | { |
1076 | QDomElement itxx = ity.toElement(); |
||
1077 | if (itxx.tagName() == "ListItem") |
||
1078 | { |
||
1079 | double val = itxx.text().toDouble(); |
||
1080 | if (cc == 0) |
||
1081 | nstyle.Extra = val; |
||
1082 | else if (cc == 1) |
||
1083 | nstyle.TExtra = val; |
||
1084 | else if (cc == 2) |
||
1085 | nstyle.RExtra = val; |
||
1086 | else if (cc == 3) |
||
1087 | nstyle.BExtra = val; |
||
1088 | cc++; |
||
1089 | } |
||
1090 | } |
||
1091 | } |
||
1092 | } |
||
1093 | } |
||
1094 | } |
||
1095 | } |
||
1096 | } |
||
17210 | fschmid | 1097 | } |
1098 | if (styleElem.hasAttribute("StrokeColor")) |
||
1099 | { |
||
17232 | fschmid | 1100 | QString strokeColor = styleElem.attribute("StrokeColor"); |
1101 | if (colorTranslate.contains(strokeColor)) |
||
1102 | nstyle.strokeColor = colorTranslate[strokeColor]; |
||
1103 | else |
||
1104 | { |
||
1105 | if (gradientTranslate.contains(strokeColor)) |
||
1106 | nstyle.strokeGradient = gradientTranslate[strokeColor]; |
||
1107 | } |
||
17210 | fschmid | 1108 | } |
1109 | if (styleElem.hasAttribute("FillColor")) |
||
1110 | { |
||
1111 | QString fillColor = styleElem.attribute("FillColor"); |
||
1112 | if (colorTranslate.contains(fillColor)) |
||
1113 | nstyle.fillColor = colorTranslate[fillColor]; |
||
1114 | else |
||
1115 | { |
||
1116 | if (gradientTranslate.contains(fillColor)) |
||
1117 | nstyle.fillGradient = gradientTranslate[fillColor]; |
||
1118 | } |
||
1119 | } |
||
1120 | if (styleElem.hasAttribute("FillTint")) |
||
1121 | { |
||
1122 | int fillShade = styleElem.attribute("FillTint").toInt(); |
||
1123 | if (fillShade != -1) |
||
1124 | nstyle.fillTint = fillShade; |
||
1125 | } |
||
1126 | if (styleElem.hasAttribute("StrokeTint")) |
||
1127 | { |
||
1128 | int strokeShade = styleElem.attribute("StrokeTint").toInt(); |
||
1129 | if (strokeShade != -1) |
||
1130 | nstyle.strokeTint = strokeShade; |
||
1131 | } |
||
1132 | if (styleElem.hasAttribute("StrokeWeight")) |
||
1133 | nstyle.lineWidth = styleElem.attribute("StrokeWeight", "0").toDouble(); |
||
1134 | if (styleElem.hasAttribute("GradientFillStart")) |
||
1135 | { |
||
1136 | QString fillGStart = styleElem.attribute("GradientFillStart"); |
||
1137 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1138 | double gstX, gstY; |
||
1139 | Code >> gstX >> gstY; |
||
1140 | nstyle.gradientFillStart = QPointF(gstX, gstY); |
||
1141 | } |
||
1142 | if (styleElem.hasAttribute("GradientFillLength")) |
||
1143 | nstyle.gradientFillLength = styleElem.attribute("GradientFillLength").toDouble(); |
||
1144 | if (styleElem.hasAttribute("GradientFillAngle")) |
||
1145 | nstyle.gradientFillAngle = styleElem.attribute("GradientFillAngle").toDouble(); |
||
17232 | fschmid | 1146 | if (styleElem.hasAttribute("GradientStrokeStart")) |
1147 | { |
||
1148 | QString fillGStart = styleElem.attribute("GradientStrokeStart"); |
||
1149 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1150 | double gstX, gstY; |
||
1151 | Code >> gstX >> gstY; |
||
1152 | nstyle.gradientStrokeStart = QPointF(gstX, gstY); |
||
1153 | } |
||
1154 | if (styleElem.hasAttribute("GradientStrokeLength")) |
||
1155 | nstyle.gradientStrokeLength = styleElem.attribute("GradientStrokeLength").toDouble(); |
||
1156 | if (styleElem.hasAttribute("GradientStrokeAngle")) |
||
1157 | nstyle.gradientStrokeAngle = styleElem.attribute("GradientStrokeAngle").toDouble(); |
||
18401 | fschmid | 1158 | if (styleElem.hasAttribute("RightLineEnd")) |
1159 | nstyle.RightLineEnd = styleElem.attribute("RightLineEnd"); |
||
1160 | if (styleElem.hasAttribute("LeftLineEnd")) |
||
1161 | nstyle.LeftLineEnd = styleElem.attribute("LeftLineEnd"); |
||
17210 | fschmid | 1162 | QString itemName = styleElem.attribute("Self"); |
1163 | ObjectStyles.insert(itemName, nstyle); |
||
1164 | } |
||
1165 | |||
17208 | fschmid | 1166 | void IdmlPlug::parseCharacterStyle(const QDomElement& styleElem) |
1167 | { |
||
1168 | CharStyle newStyle; |
||
1169 | newStyle.setDefaultStyle(false); |
||
17268 | fschmid | 1170 | newStyle.setName(styleElem.attribute("Name").remove("$ID/")); |
17208 | fschmid | 1171 | newStyle.setParent(CommonStrings::DefaultCharacterStyle); |
1172 | QString fontName = m_Doc->itemToolPrefs().textFont; |
||
25070 | craig | 1173 | QString fontBaseName; |
17208 | fschmid | 1174 | QString fontStyle = styleElem.attribute("FontStyle", ""); |
22723 | jghali | 1175 | for (QDomNode itp = styleElem.firstChild(); !itp.isNull(); itp = itp.nextSibling()) |
17208 | fschmid | 1176 | { |
1177 | QDomElement itpr = itp.toElement(); |
||
1178 | if (itpr.tagName() == "Properties") |
||
1179 | { |
||
22723 | jghali | 1180 | for (QDomNode itpp = itpr.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
17208 | fschmid | 1181 | { |
1182 | QDomElement i = itpp.toElement(); |
||
1183 | if (i.tagName() == "AppliedFont") |
||
1184 | fontBaseName = i.text(); |
||
1185 | else if (i.tagName() == "BasedOn") |
||
1186 | { |
||
17268 | fschmid | 1187 | QString parentStyle = i.text().remove("$ID/"); |
17208 | fschmid | 1188 | if (charStyleTranslate.contains(parentStyle)) |
1189 | parentStyle = charStyleTranslate[parentStyle]; |
||
1190 | if (m_Doc->styleExists(parentStyle)) |
||
1191 | newStyle.setParent(parentStyle); |
||
1192 | } |
||
1193 | } |
||
1194 | } |
||
1195 | } |
||
1196 | if ((!fontBaseName.isEmpty()) && (!fontStyle.isEmpty())) |
||
1197 | fontName = constructFontName(fontBaseName, fontStyle); |
||
1198 | newStyle.setFont((*m_Doc->AllFonts)[fontName]); |
||
1199 | readCharStyleAttributes(newStyle, styleElem); |
||
1200 | StyleSet<CharStyle> temp; |
||
1201 | temp.create(newStyle); |
||
1202 | m_Doc->redefineCharStyles(temp, false); |
||
17268 | fschmid | 1203 | charStyleTranslate.insert(styleElem.attribute("Self").remove("$ID/"), styleElem.attribute("Name").remove("$ID/")); |
17208 | fschmid | 1204 | } |
1205 | |||
17199 | fschmid | 1206 | void IdmlPlug::parseParagraphStyle(const QDomElement& styleElem) |
1207 | { |
||
1208 | ParagraphStyle newStyle; |
||
1209 | newStyle.erase(); |
||
17208 | fschmid | 1210 | newStyle.setDefaultStyle(false); |
17268 | fschmid | 1211 | newStyle.setName(styleElem.attribute("Name").remove("$ID/")); |
17199 | fschmid | 1212 | newStyle.setParent(CommonStrings::DefaultParagraphStyle); |
1213 | QString fontName = m_Doc->itemToolPrefs().textFont; |
||
25070 | craig | 1214 | QString fontBaseName; |
17199 | fschmid | 1215 | QString fontStyle = styleElem.attribute("FontStyle", ""); |
17208 | fschmid | 1216 | newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); |
22723 | jghali | 1217 | for (QDomNode itp = styleElem.firstChild(); !itp.isNull(); itp = itp.nextSibling()) |
17199 | fschmid | 1218 | { |
1219 | QDomElement itpr = itp.toElement(); |
||
1220 | if (itpr.tagName() == "Properties") |
||
1221 | { |
||
22723 | jghali | 1222 | for (QDomNode itpp = itpr.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
17199 | fschmid | 1223 | { |
1224 | QDomElement i = itpp.toElement(); |
||
1225 | if (i.tagName() == "AppliedFont") |
||
1226 | fontBaseName = i.text(); |
||
1227 | else if (i.tagName() == "BasedOn") |
||
1228 | { |
||
17268 | fschmid | 1229 | QString parentStyle = i.text().remove("$ID/"); |
17199 | fschmid | 1230 | if (styleTranslate.contains(parentStyle)) |
1231 | parentStyle = styleTranslate[parentStyle]; |
||
18347 | fschmid | 1232 | else |
1233 | { |
||
1234 | QString pSty = parentStyle.remove("ParagraphStyle/"); |
||
1235 | if (styleParents.contains(pSty)) |
||
1236 | styleParents[pSty].append(newStyle.name()); |
||
1237 | else |
||
1238 | styleParents.insert(pSty, QStringList() << newStyle.name()); |
||
1239 | } |
||
17199 | fschmid | 1240 | if (m_Doc->styleExists(parentStyle)) |
1241 | newStyle.setParent(parentStyle); |
||
1242 | } |
||
17208 | fschmid | 1243 | else if (i.tagName() == "Leading") |
1244 | { |
||
1245 | if (i.attribute("type") == "unit") |
||
1246 | { |
||
1247 | int lead = i.text().toDouble(); |
||
1248 | if (lead != 0) |
||
1249 | { |
||
1250 | newStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing); |
||
1251 | newStyle.setLineSpacing(lead); |
||
1252 | } |
||
1253 | } |
||
1254 | } |
||
18346 | fschmid | 1255 | else if (i.tagName() == "TabList") |
1256 | { |
||
1257 | QList<ParagraphStyle::TabRecord> tbs; |
||
1258 | newStyle.resetTabValues(); |
||
22723 | jghali | 1259 | for (QDomNode tabl = i.firstChild(); !tabl.isNull(); tabl = tabl.nextSibling()) |
18346 | fschmid | 1260 | { |
1261 | QDomElement ta = tabl.toElement(); |
||
1262 | if (ta.tagName() == "ListItem") |
||
1263 | { |
||
1264 | ParagraphStyle::TabRecord tb; |
||
22723 | jghali | 1265 | for (QDomNode tal = ta.firstChild(); !tal.isNull(); tal = tal.nextSibling()) |
18346 | fschmid | 1266 | { |
1267 | QDomElement tab = tal.toElement(); |
||
1268 | QString tabVal = tab.text(); |
||
1269 | if (tab.tagName() == "Alignment") |
||
1270 | { |
||
1271 | tb.tabType = 0; |
||
1272 | if (tabVal == "LeftAlign") |
||
1273 | tb.tabType = 0; |
||
1274 | else if (tabVal == "CenterAlign") |
||
1275 | tb.tabType = 4; |
||
1276 | else if (tabVal == "RightAlign") |
||
1277 | tb.tabType = 1; |
||
1278 | else if (tabVal == "Spreadsheet") |
||
1279 | tb.tabType = 3; |
||
1280 | } |
||
1281 | else if (tab.tagName() == "Position") |
||
1282 | { |
||
1283 | tb.tabPosition = tabVal.toDouble(); |
||
1284 | } |
||
1285 | else if (tab.tagName() == "Leader") |
||
1286 | { |
||
1287 | tb.tabFillChar = tabVal.isEmpty() ? QChar() : tabVal[0]; |
||
1288 | } |
||
1289 | else if (tab.tagName() == "AlignmentCharacter") |
||
1290 | { |
||
1291 | if (tb.tabType == 3) |
||
1292 | { |
||
1293 | if (tabVal.startsWith(",")) |
||
1294 | tb.tabType = 4; |
||
1295 | } |
||
1296 | } |
||
1297 | } |
||
1298 | tbs.append(tb); |
||
1299 | |||
1300 | } |
||
1301 | } |
||
1302 | if (tbs.count() > 0) |
||
1303 | newStyle.setTabValues(tbs); |
||
1304 | } |
||
17199 | fschmid | 1305 | } |
1306 | } |
||
1307 | } |
||
1308 | if ((!fontBaseName.isEmpty()) && (!fontStyle.isEmpty())) |
||
1309 | fontName = constructFontName(fontBaseName, fontStyle); |
||
1310 | newStyle.charStyle().setFont((*m_Doc->AllFonts)[fontName]); |
||
17208 | fschmid | 1311 | readCharStyleAttributes(newStyle.charStyle(), styleElem); |
1312 | readParagraphStyleAttributes(newStyle, styleElem); |
||
17199 | fschmid | 1313 | StyleSet<ParagraphStyle>tmp; |
1314 | tmp.create(newStyle); |
||
1315 | m_Doc->redefineStyles(tmp, false); |
||
17268 | fschmid | 1316 | styleTranslate.insert(styleElem.attribute("Self").remove("$ID/"), styleElem.attribute("Name").remove("$ID/")); |
18347 | fschmid | 1317 | if (styleParents.contains(newStyle.name())) |
1318 | { |
||
1319 | QStringList desList = styleParents[newStyle.name()]; |
||
1320 | for (int a = 0; a < desList.count(); a++) |
||
1321 | { |
||
1322 | ParagraphStyle old = m_Doc->paragraphStyle(desList[a]); |
||
1323 | old.setParent(newStyle.name()); |
||
1324 | StyleSet<ParagraphStyle>tmp2; |
||
1325 | tmp2.create(old); |
||
1326 | m_Doc->redefineStyles(tmp2, false); |
||
1327 | } |
||
1328 | } |
||
17199 | fschmid | 1329 | } |
1330 | |||
1331 | bool IdmlPlug::parsePreferencesXML(const QDomElement& prElem) |
||
1332 | { |
||
1333 | QDomElement prNode; |
||
1334 | QDomDocument prMapDom; |
||
1335 | if (prElem.hasAttribute("src")) |
||
1336 | { |
||
1337 | QByteArray f2; |
||
23619 | jghali | 1338 | m_zip->read(prElem.attribute("src"), f2); |
1339 | if (!prMapDom.setContent(f2)) |
||
17199 | fschmid | 1340 | return false; |
23619 | jghali | 1341 | prNode = prMapDom.documentElement(); |
17199 | fschmid | 1342 | } |
1343 | else |
||
1344 | { |
||
23619 | jghali | 1345 | if (!prElem.hasChildNodes()) |
17199 | fschmid | 1346 | return false; |
23619 | jghali | 1347 | prNode = prElem; |
17199 | fschmid | 1348 | } |
17222 | fschmid | 1349 | parsePreferencesXMLNode(prNode); |
1350 | return true; |
||
1351 | } |
||
1352 | |||
1353 | void IdmlPlug::parsePreferencesXMLNode(const QDomElement& prNode) |
||
1354 | { |
||
19831 | craig | 1355 | double topMargin = m_Doc->marginsVal().top(); |
1356 | double leftMargin = m_Doc->marginsVal().left(); |
||
1357 | double rightMargin = m_Doc->marginsVal().right(); |
||
1358 | double bottomMargin = m_Doc->marginsVal().bottom(); |
||
17199 | fschmid | 1359 | double pgCols = m_Doc->PageSp; |
1360 | double pgGap = m_Doc->PageSpa; |
||
19831 | craig | 1361 | double bleedTop = m_Doc->bleeds()->top(); |
1362 | double bleedLeft = m_Doc->bleeds()->left(); |
||
1363 | double bleedRight = m_Doc->bleeds()->right(); |
||
1364 | double bleedBottom = m_Doc->bleeds()->bottom(); |
||
17199 | fschmid | 1365 | facingPages = false; |
1366 | for (QDomNode n = prNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
1367 | { |
||
1368 | QDomElement e = n.toElement(); |
||
1369 | if (e.tagName() == "DocumentPreference") |
||
1370 | { |
||
1371 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1372 | { |
||
1373 | docWidth = e.attribute("PageWidth").toDouble(); |
||
1374 | docHeight = e.attribute("PageHeight").toDouble(); |
||
1375 | bleedTop = e.attribute("DocumentBleedTopOffset").toDouble(); |
||
1376 | bleedLeft = e.attribute("DocumentBleedInsideOrLeftOffset").toDouble(); |
||
1377 | bleedRight = e.attribute("DocumentBleedOutsideOrRightOffset").toDouble(); |
||
1378 | bleedBottom = e.attribute("DocumentBleedBottomOffset").toDouble(); |
||
22609 | craig | 1379 | facingPages = e.attribute("FacingPages","") == "true"; |
17199 | fschmid | 1380 | } |
1381 | } |
||
1382 | if (e.tagName() == "MarginPreference") |
||
1383 | { |
||
1384 | topMargin = e.attribute("Top").toDouble(); |
||
1385 | leftMargin = e.attribute("Left").toDouble(); |
||
1386 | rightMargin = e.attribute("Right").toDouble(); |
||
1387 | bottomMargin = e.attribute("Bottom").toDouble(); |
||
1388 | pgCols = e.attribute("ColumnCount").toDouble(); |
||
1389 | pgGap = e.attribute("ColumnGutter").toDouble(); |
||
1390 | } |
||
1391 | if (e.tagName() == "TransparencyDefaultContainerObject") |
||
1392 | { |
||
22723 | jghali | 1393 | for (QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling()) |
17199 | fschmid | 1394 | { |
1395 | QDomElement itpg = it.toElement(); |
||
22723 | jghali | 1396 | for (QDomNode itp = itpg.firstChild(); !itp.isNull(); itp = itp.nextSibling()) |
17199 | fschmid | 1397 | { |
1398 | QDomElement itpr = itp.toElement(); |
||
1399 | if (itpr.tagName() == "TransparencySetting") |
||
1400 | { |
||
1401 | def_Opacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
1402 | def_Blendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
1403 | } |
||
1404 | if (itpr.tagName() == "StrokeTransparencySetting") |
||
1405 | { |
||
1406 | def_strokeOpacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
1407 | def_strokeBlendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
1408 | } |
||
1409 | if (itpr.tagName() == "FillTransparencySetting") |
||
1410 | { |
||
1411 | def_fillOpacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
1412 | def_fillBlendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
1413 | } |
||
1414 | } |
||
1415 | } |
||
1416 | } |
||
1417 | if (e.tagName() == "PageItemDefault") |
||
1418 | { |
||
1419 | QString strokeColor = e.attribute("StrokeColor"); |
||
1420 | if (colorTranslate.contains(strokeColor)) |
||
1421 | def_strokeColor = colorTranslate[strokeColor]; |
||
17232 | fschmid | 1422 | else |
1423 | { |
||
1424 | if (gradientTranslate.contains(strokeColor)) |
||
1425 | { |
||
1426 | def_strokeGradient = gradientTranslate[strokeColor]; |
||
1427 | } |
||
1428 | } |
||
1429 | QString strokeGStart = e.attribute("GradientStrokeStart", "0 0"); |
||
1430 | ScTextStream Code2(&strokeGStart, QIODevice::ReadOnly); |
||
1431 | Code2 >> def_gradientStrokeStartX >> def_gradientStrokeStartY; |
||
1432 | def_gradientStrokeLength = e.attribute("GradientStrokeLength", "0").toDouble(); |
||
1433 | def_gradientStrokeAngle = e.attribute("GradientStrokeAngle", "0").toDouble(); |
||
1434 | int strokeShade = e.attribute("StrokeTint", "100").toInt(); |
||
1435 | if (strokeShade != -1) |
||
1436 | def_strokeTint = strokeShade; |
||
1437 | else |
||
1438 | def_strokeTint = 100; |
||
17199 | fschmid | 1439 | QString fillColor = e.attribute("FillColor"); |
1440 | if (colorTranslate.contains(fillColor)) |
||
1441 | def_fillColor = colorTranslate[fillColor]; |
||
1442 | else |
||
1443 | { |
||
1444 | if (gradientTranslate.contains(fillColor)) |
||
1445 | { |
||
1446 | def_fillGradient = gradientTranslate[fillColor]; |
||
1447 | } |
||
1448 | } |
||
17232 | fschmid | 1449 | QString fillGStart = e.attribute("GradientFillStart", "0 0"); |
1450 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1451 | Code >> def_gradientX >> def_gradientY; |
||
1452 | def_gradientLen = e.attribute("GradientFillLength", "0").toDouble(); |
||
1453 | def_gradientAngle = e.attribute("GradientFillAngle", "0").toDouble(); |
||
17199 | fschmid | 1454 | int fillShade = e.attribute("FillTint", "100").toInt(); |
1455 | if (fillShade != -1) |
||
1456 | def_fillTint = fillShade; |
||
1457 | else |
||
1458 | def_fillTint = 100; |
||
1459 | def_lineWidth = e.attribute("StrokeWeight", "0").toDouble(); |
||
18401 | fschmid | 1460 | if (e.hasAttribute("RightLineEnd")) |
1461 | def_RightLineEnd = e.attribute("RightLineEnd"); |
||
1462 | if (e.hasAttribute("LeftLineEnd")) |
||
1463 | def_LeftLineEnd = e.attribute("LeftLineEnd"); |
||
17199 | fschmid | 1464 | } |
17206 | fschmid | 1465 | if (e.tagName() == "TextWrapPreference") |
1466 | { |
||
1467 | if (e.attribute("TextWrapMode") == "None") |
||
1468 | def_TextFlow = PageItem::TextFlowDisabled; |
||
1469 | else if (e.attribute("TextWrapMode") == "BoundingBoxTextWrap") |
||
1470 | def_TextFlow = PageItem::TextFlowUsesBoundingBox; |
||
1471 | else if (e.attribute("TextWrapMode") == "Contour") |
||
1472 | def_TextFlow = PageItem::TextFlowUsesFrameShape; |
||
1473 | } |
||
17239 | fschmid | 1474 | if (e.tagName() == "TextFramePreference") |
1475 | { |
||
1476 | if (e.hasAttribute("TextColumnCount")) |
||
1477 | def_TextColumnCount = e.attribute("TextColumnCount").toInt(); |
||
1478 | if (e.hasAttribute("TextColumnGutter")) |
||
1479 | def_TextColumnGutter = e.attribute("TextColumnGutter").toDouble(); |
||
1480 | if (e.hasAttribute("TextColumnFixedWidth")) |
||
1481 | def_TextColumnFixedWidth = e.attribute("TextColumnFixedWidth").toDouble(); |
||
22723 | jghali | 1482 | for (QDomNode itpp = e.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
17239 | fschmid | 1483 | { |
1484 | QDomElement i = itpp.toElement(); |
||
1485 | if (i.tagName() == "Properties") |
||
1486 | { |
||
22723 | jghali | 1487 | for (QDomNode it = i.firstChild(); !it.isNull(); it = it.nextSibling()) |
17239 | fschmid | 1488 | { |
1489 | QDomElement itx = it.toElement(); |
||
1490 | if (itx.tagName() == "InsetSpacing") |
||
1491 | { |
||
1492 | if (itx.attribute("type") == "unit") |
||
1493 | def_Extra = def_TExtra = def_BExtra = def_RExtra = itx.text().toDouble(); |
||
1494 | else if (itx.attribute("type") == "list") |
||
1495 | { |
||
1496 | int cc = 0; |
||
22723 | jghali | 1497 | for (QDomNode ity = itx.firstChild(); !ity.isNull(); ity = ity.nextSibling()) |
17239 | fschmid | 1498 | { |
1499 | QDomElement itxx = ity.toElement(); |
||
1500 | if (itxx.tagName() == "ListItem") |
||
1501 | { |
||
1502 | double val = itxx.text().toDouble(); |
||
1503 | if (cc == 0) |
||
1504 | def_Extra = val; |
||
1505 | else if (cc == 1) |
||
1506 | def_TExtra = val; |
||
1507 | else if (cc == 2) |
||
1508 | def_RExtra = val; |
||
1509 | else if (cc == 3) |
||
1510 | def_BExtra = val; |
||
1511 | cc++; |
||
1512 | } |
||
1513 | } |
||
1514 | } |
||
1515 | } |
||
1516 | } |
||
1517 | } |
||
1518 | } |
||
1519 | } |
||
17199 | fschmid | 1520 | } |
1521 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1522 | { |
||
1523 | m_Doc->setPage(docWidth, docHeight, topMargin, leftMargin, rightMargin, bottomMargin, pgCols, pgGap, false, facingPages); |
||
1524 | m_Doc->setPageSize("Custom"); |
||
1525 | m_Doc->bleeds()->set(bleedTop, bleedLeft, bleedBottom, bleedRight); |
||
23129 | craig | 1526 | m_Doc->currentPage()->setSize("Custom"); |
17199 | fschmid | 1527 | m_Doc->currentPage()->setInitialHeight(docHeight); |
1528 | m_Doc->currentPage()->setInitialWidth(docWidth); |
||
1529 | m_Doc->currentPage()->setHeight(docHeight); |
||
1530 | m_Doc->currentPage()->setWidth(docWidth); |
||
19831 | craig | 1531 | m_Doc->currentPage()->initialMargins.setTop(topMargin); |
1532 | m_Doc->currentPage()->initialMargins.setBottom(bottomMargin); |
||
1533 | m_Doc->currentPage()->initialMargins.setLeft(leftMargin); |
||
1534 | m_Doc->currentPage()->initialMargins.setRight(rightMargin); |
||
17199 | fschmid | 1535 | m_Doc->reformPages(true); |
1536 | baseX = m_Doc->currentPage()->xOffset(); |
||
1537 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
1538 | } |
||
1539 | } |
||
1540 | |||
1541 | bool IdmlPlug::parseSpreadXML(const QDomElement& spElem) |
||
1542 | { |
||
1543 | QDomElement spNode; |
||
1544 | QDomDocument spMapDom; |
||
1545 | if (spElem.hasAttribute("src")) |
||
1546 | { |
||
1547 | QByteArray f2; |
||
23619 | jghali | 1548 | m_zip->read(spElem.attribute("src"), f2); |
1549 | if (!spMapDom.setContent(f2)) |
||
17199 | fschmid | 1550 | return false; |
23619 | jghali | 1551 | spNode = spMapDom.documentElement(); |
17199 | fschmid | 1552 | } |
1553 | else |
||
1554 | { |
||
23619 | jghali | 1555 | if (!spElem.hasChildNodes()) |
17199 | fschmid | 1556 | return false; |
23619 | jghali | 1557 | spNode = spElem; |
17199 | fschmid | 1558 | } |
17222 | fschmid | 1559 | parseSpreadXMLNode(spNode); |
1560 | return true; |
||
1561 | } |
||
1562 | |||
1563 | void IdmlPlug::parseSpreadXMLNode(const QDomElement& spNode) |
||
1564 | { |
||
22723 | jghali | 1565 | for (QDomNode n = spNode.firstChild(); !n.isNull(); n = n.nextSibling()) |
17199 | fschmid | 1566 | { |
1567 | QDomElement e = n.toElement(); |
||
1568 | if (e.tagName() == "Spread") |
||
1569 | { |
||
22723 | jghali | 1570 | for (QDomNode sp = e.firstChild(); !sp.isNull(); sp = sp.nextSibling()) |
17199 | fschmid | 1571 | { |
1572 | QDomElement spe = sp.toElement(); |
||
1573 | if (spe.tagName() == "Page") |
||
1574 | { |
||
1575 | if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (!firstPage)) |
||
1576 | { |
||
1577 | m_Doc->addPage(pagecount); |
||
23129 | craig | 1578 | m_Doc->currentPage()->setMasterPageNameNormal(); |
1579 | m_Doc->currentPage()->setSize("Custom"); |
||
17262 | fschmid | 1580 | m_Doc->currentPage()->setInitialHeight(docHeight); |
1581 | m_Doc->currentPage()->setInitialWidth(docWidth); |
||
1582 | m_Doc->currentPage()->setHeight(docHeight); |
||
1583 | m_Doc->currentPage()->setWidth(docWidth); |
||
17199 | fschmid | 1584 | m_Doc->view()->addPage(pagecount, true); |
1585 | pagecount++; |
||
1586 | } |
||
1587 | baseX = m_Doc->currentPage()->xOffset(); |
||
1588 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
1589 | firstPage = false; |
||
18399 | fschmid | 1590 | if ((importerFlags & LoadSavePlugin::lfCreateDoc) && spe.hasAttribute("AppliedMaster")) |
18400 | fschmid | 1591 | { |
1592 | QString mSpr = spe.attribute("AppliedMaster"); |
||
1593 | if (masterSpreads.contains(mSpr)) |
||
1594 | { |
||
1595 | QString mp = CommonStrings::trMasterPageNormal; |
||
1596 | if (facingPages) |
||
1597 | { |
||
1598 | if ((pagecount % 2 == 0) && (masterSpreads[mSpr].count() > 0)) |
||
1599 | mp = mSpr + "_" + masterSpreads[mSpr][0]; |
||
1600 | if ((pagecount % 2 == 1) && (masterSpreads[mSpr].count() > 1)) |
||
1601 | mp = mSpr + "_" + masterSpreads[mSpr][1]; |
||
1602 | } |
||
1603 | else |
||
1604 | { |
||
1605 | if ((masterSpreads[mSpr].count() > 0)) |
||
1606 | mp = mSpr + "_" + masterSpreads[mSpr][0]; |
||
1607 | } |
||
1608 | m_Doc->applyMasterPage(mp, m_Doc->currentPageNumber()); |
||
1609 | } |
||
1610 | } |
||
23392 | jghali | 1611 | for (QDomNode pageNode = spe.firstChild(); !pageNode.isNull(); pageNode = pageNode.nextSibling()) |
1612 | { |
||
1613 | QDomElement pageElement = pageNode.toElement(); |
||
1614 | if (pageElement.tagName() == "Guide" && pageElement.hasAttribute("Location") && pageElement.hasAttribute("Orientation")) |
||
1615 | { |
||
1616 | bool convOk = false; |
||
1617 | double location = pageElement.attribute("Location").toDouble(&convOk); |
||
1618 | if (!convOk) |
||
1619 | continue; |
||
1620 | QString orientation = pageElement.attribute("Orientation"); |
||
1621 | if (orientation == "Horizontal") |
||
1622 | m_Doc->currentPage()->guides.addHorizontal(location, GuideManagerCore::Standard); |
||
1623 | else if (pageElement.attribute("Orientation") == "Vertical") |
||
1624 | m_Doc->currentPage()->guides.addVertical(location, GuideManagerCore::Standard); |
||
1625 | } |
||
1626 | } |
||
17199 | fschmid | 1627 | } |
1628 | } |
||
1629 | if ((facingPages) && (pagecount % 2 == 0)) |
||
1630 | { |
||
1631 | baseX = m_Doc->currentPage()->xOffset() + m_Doc->currentPage()->width(); |
||
1632 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
1633 | } |
||
1634 | if (!facingPages) |
||
1635 | { |
||
1636 | baseX = m_Doc->currentPage()->xOffset() + m_Doc->currentPage()->width() / 2.0; |
||
1637 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
1638 | } |
||
22723 | jghali | 1639 | for (QDomNode sp = e.firstChild(); !sp.isNull(); sp = sp.nextSibling()) |
17199 | fschmid | 1640 | { |
1641 | QDomElement spe = sp.toElement(); |
||
1642 | if ((spe.tagName() == "Rectangle") || (spe.tagName() == "Oval") || (spe.tagName() == "GraphicLine") || (spe.tagName() == "Polygon") || (spe.tagName() == "TextFrame") || (spe.tagName() == "Group") || (spe.tagName() == "Button")) |
||
1643 | { |
||
1644 | QList<PageItem*> el = parseItemXML(spe); |
||
1645 | for (int ec = 0; ec < el.count(); ++ec) |
||
1646 | { |
||
1647 | m_Doc->Items->append(el.at(ec)); |
||
1648 | Elements.append(el.at(ec)); |
||
1649 | } |
||
1650 | } |
||
1651 | } |
||
1652 | } |
||
18399 | fschmid | 1653 | else if (e.tagName() == "MasterSpread") |
17222 | fschmid | 1654 | { |
1655 | m_Doc->setMasterPageMode(true); |
||
18399 | fschmid | 1656 | QString pageNam = e.attribute("Self"); |
18400 | fschmid | 1657 | QStringList pages; |
18401 | fschmid | 1658 | ScPage *oldCur = m_Doc->currentPage(); |
22723 | jghali | 1659 | for (QDomNode sp = e.firstChild(); !sp.isNull(); sp = sp.nextSibling()) |
17222 | fschmid | 1660 | { |
1661 | QDomElement spe = sp.toElement(); |
||
1662 | if (spe.tagName() == "Page") |
||
1663 | { |
||
18401 | fschmid | 1664 | QString itemTrans = spe.attribute("ItemTransform"); |
1665 | ScTextStream list(&itemTrans, QIODevice::ReadOnly); |
||
1666 | double a, b, c, d, e1, f; |
||
1667 | list >> a >> b >> c >> d >> e1 >> f; |
||
1668 | /* Adding the values directly */ |
||
1669 | QTransform transformation(a, b, c, d, e1, f); |
||
1670 | ScPage *addedPage = m_Doc->addMasterPage(mpagecount, pageNam + "_" + spe.attribute("Self")); |
||
1671 | m_Doc->setCurrentPage(addedPage); |
||
18400 | fschmid | 1672 | pages.append(spe.attribute("Self")); |
23129 | craig | 1673 | addedPage->clearMasterPageName(); |
17222 | fschmid | 1674 | m_Doc->view()->addPage(mpagecount, true); |
18401 | fschmid | 1675 | baseX = addedPage->xOffset(); |
1676 | baseY = addedPage->yOffset() + addedPage->height() / 2.0; |
||
1677 | if (!facingPages) |
||
1678 | baseX = addedPage->xOffset() + addedPage->width() / 2.0; |
||
1679 | else |
||
1680 | baseX = addedPage->xOffset() - transformation.dx(); |
||
22723 | jghali | 1681 | for (QDomNode spp = e.firstChild(); !spp.isNull(); spp = spp.nextSibling()) |
18401 | fschmid | 1682 | { |
1683 | QDomElement spe = spp.toElement(); |
||
1684 | if ((spe.tagName() == "Rectangle") || (spe.tagName() == "Oval") || (spe.tagName() == "GraphicLine") || (spe.tagName() == "Polygon") || (spe.tagName() == "TextFrame") || (spe.tagName() == "Group") || (spe.tagName() == "Button")) |
||
1685 | { |
||
1686 | QList<PageItem*> el = parseItemXML(spe); |
||
1687 | for (int ec = 0; ec < el.count(); ++ec) |
||
1688 | { |
||
1689 | PageItem* ite = el.at(ec); |
||
1690 | int pgi = m_Doc->OnPage(ite); |
||
1691 | if (pgi != -1) |
||
1692 | { |
||
1693 | m_Doc->Items->append(ite); |
||
1694 | Elements.append(ite); |
||
1695 | } |
||
1696 | } |
||
1697 | } |
||
1698 | } |
||
17222 | fschmid | 1699 | mpagecount++; |
1700 | } |
||
1701 | } |
||
18400 | fschmid | 1702 | masterSpreads.insert(pageNam, pages); |
18401 | fschmid | 1703 | m_Doc->setCurrentPage(oldCur); |
17222 | fschmid | 1704 | m_Doc->setMasterPageMode(false); |
18399 | fschmid | 1705 | } |
17199 | fschmid | 1706 | } |
1707 | } |
||
1708 | |||
22635 | craig | 1709 | QList<PageItem*> IdmlPlug::parseItemXML(const QDomElement& itElem, const QTransform& pTrans) |
17199 | fschmid | 1710 | { |
1711 | QList<PageItem*> GElements; |
||
1712 | FPointArray GCoords; |
||
1713 | GCoords.resize(0); |
||
1714 | GCoords.svgInit(); |
||
1715 | QString itemTrans = itElem.attribute("ItemTransform"); |
||
1716 | ScTextStream list(&itemTrans, QIODevice::ReadOnly); |
||
1717 | double a, b, c, d, e, f; |
||
1718 | list >> a >> b >> c >> d >> e >> f; |
||
1719 | /* Adding the values directly */ |
||
1720 | QTransform transformation(a, b, c, d, e, f); |
||
1721 | QString itemName = itElem.attribute("Self"); |
||
17210 | fschmid | 1722 | QString fillColor = def_fillColor; |
25070 | craig | 1723 | QString fillGradient; |
17210 | fschmid | 1724 | double gstX = def_gradientX; |
1725 | double gstY = def_gradientY; |
||
1726 | double gLen = def_gradientLen; |
||
1727 | double gAngle = def_gradientAngle; |
||
17199 | fschmid | 1728 | int fillGradientTyp = 6; |
17210 | fschmid | 1729 | QString strokeColor = def_strokeColor; |
25070 | craig | 1730 | QString strokeGradient; |
17232 | fschmid | 1731 | double gstSX = def_gradientStrokeStartX; |
1732 | double gstSY = def_gradientStrokeStartY; |
||
1733 | double gSLen = def_gradientStrokeLength; |
||
1734 | double gSAngle = def_gradientStrokeAngle; |
||
1735 | int strokeGradientTyp = 6; |
||
17210 | fschmid | 1736 | double lineWidth = def_lineWidth; |
1737 | int fillShade = def_fillTint; |
||
1738 | int strokeShade = def_strokeTint; |
||
24705 | jghali | 1739 | double opacity = def_Opacity; |
17210 | fschmid | 1740 | int blendMode = def_Blendmode; |
17239 | fschmid | 1741 | double Extra = def_Extra; |
1742 | double TExtra = def_TExtra; |
||
1743 | double BExtra = def_BExtra; |
||
1744 | double RExtra = def_RExtra; |
||
24705 | jghali | 1745 | int textColumnCount = def_TextColumnCount; |
1746 | double textColumnGutter = def_TextColumnGutter; |
||
19728 | fschmid | 1747 | //double TextColumnFixedWidth = def_TextColumnFixedWidth; |
24705 | jghali | 1748 | QString leftLineEnd = def_LeftLineEnd; |
1749 | QString rightLineEnd = def_RightLineEnd; |
||
18289 | fschmid | 1750 | QString imageFit = "None"; |
17239 | fschmid | 1751 | PageItem::TextFlowMode textFlow = def_TextFlow; |
17210 | fschmid | 1752 | if (itElem.hasAttribute("AppliedObjectStyle")) |
17199 | fschmid | 1753 | { |
17210 | fschmid | 1754 | QString os = itElem.attribute("AppliedObjectStyle"); |
17349 | fschmid | 1755 | if (os != "n") |
17199 | fschmid | 1756 | { |
17349 | fschmid | 1757 | ObjectStyle nstyle; |
1758 | nstyle.fillColor = def_fillColor; |
||
1759 | nstyle.strokeColor = def_strokeColor; |
||
1760 | nstyle.fillGradient = ""; |
||
1761 | nstyle.gradientFillStart = QPointF(def_gradientX, def_gradientY); |
||
1762 | nstyle.gradientFillLength = def_gradientLen; |
||
1763 | nstyle.gradientFillAngle = def_gradientAngle; |
||
1764 | nstyle.strokeGradient = ""; |
||
1765 | nstyle.gradientStrokeStart = QPointF(def_gradientStrokeStartX, def_gradientStrokeStartY); |
||
1766 | nstyle.gradientStrokeAngle = def_gradientStrokeAngle; |
||
1767 | nstyle.gradientStrokeLength = def_gradientStrokeLength; |
||
1768 | nstyle.lineWidth = def_lineWidth; |
||
1769 | nstyle.fillTint = def_fillTint; |
||
1770 | nstyle.strokeTint = def_strokeTint; |
||
1771 | nstyle.Opacity = def_Opacity; |
||
1772 | nstyle.blendMode = def_Blendmode; |
||
1773 | nstyle.Extra = def_Extra; |
||
1774 | nstyle.TExtra = def_TExtra; |
||
1775 | nstyle.BExtra = def_BExtra; |
||
1776 | nstyle.RExtra = def_RExtra; |
||
1777 | nstyle.TextColumnCount = def_TextColumnCount; |
||
1778 | nstyle.TextColumnGutter = def_TextColumnGutter; |
||
1779 | nstyle.TextColumnFixedWidth = def_TextColumnFixedWidth; |
||
1780 | nstyle.TextFlow = def_TextFlow; |
||
1781 | nstyle.parentStyle = ""; |
||
1782 | resolveObjectStyle(nstyle, os); |
||
1783 | fillColor = nstyle.fillColor; |
||
1784 | if (!nstyle.fillGradient.isEmpty()) |
||
1785 | { |
||
1786 | fillGradient = nstyle.fillGradient; |
||
1787 | fillGradientTyp = gradientTypeMap[fillColor]; |
||
1788 | } |
||
1789 | gstX = nstyle.gradientFillStart.x(); |
||
1790 | gstY = nstyle.gradientFillStart.y(); |
||
1791 | gLen = nstyle.gradientFillLength; |
||
1792 | gAngle = nstyle.gradientFillAngle; |
||
1793 | strokeColor = nstyle.strokeColor; |
||
1794 | if (!nstyle.strokeGradient.isEmpty()) |
||
1795 | { |
||
1796 | strokeGradient = nstyle.strokeGradient; |
||
1797 | strokeGradientTyp = gradientTypeMap[strokeColor]; |
||
1798 | } |
||
1799 | gstSX = nstyle.gradientStrokeStart.x(); |
||
1800 | gstSY = nstyle.gradientStrokeStart.y(); |
||
1801 | gSLen = nstyle.gradientStrokeLength; |
||
1802 | gSAngle = nstyle.gradientStrokeAngle; |
||
1803 | lineWidth = nstyle.lineWidth; |
||
1804 | fillShade = nstyle.fillTint; |
||
1805 | strokeShade = nstyle.strokeTint; |
||
24705 | jghali | 1806 | opacity = nstyle.Opacity; |
17349 | fschmid | 1807 | blendMode = nstyle.blendMode; |
1808 | Extra = nstyle.Extra; |
||
1809 | TExtra = nstyle.TExtra; |
||
1810 | BExtra = nstyle.BExtra; |
||
1811 | RExtra = nstyle.RExtra; |
||
24705 | jghali | 1812 | textColumnCount = nstyle.TextColumnCount; |
1813 | textColumnGutter = nstyle.TextColumnGutter; |
||
19728 | fschmid | 1814 | // TextColumnFixedWidth = nstyle.TextColumnFixedWidth; |
17349 | fschmid | 1815 | textFlow = nstyle.TextFlow; |
24705 | jghali | 1816 | leftLineEnd = nstyle.LeftLineEnd; |
1817 | rightLineEnd = nstyle.RightLineEnd; |
||
17199 | fschmid | 1818 | } |
17210 | fschmid | 1819 | } |
1820 | if (itElem.hasAttribute("FillColor")) |
||
1821 | { |
||
1822 | fillColor = itElem.attribute("FillColor"); |
||
1823 | if (colorTranslate.contains(fillColor)) |
||
1824 | fillColor = colorTranslate[fillColor]; |
||
17199 | fschmid | 1825 | else |
17210 | fschmid | 1826 | { |
1827 | if (gradientTranslate.contains(fillColor)) |
||
1828 | { |
||
1829 | fillGradientTyp = gradientTypeMap[fillColor]; |
||
1830 | fillGradient = gradientTranslate[fillColor]; |
||
1831 | } |
||
1832 | } |
||
17199 | fschmid | 1833 | } |
17210 | fschmid | 1834 | if (itElem.hasAttribute("GradientFillStart")) |
1835 | { |
||
1836 | QString fillGStart = itElem.attribute("GradientFillStart"); |
||
1837 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1838 | Code >> gstX >> gstY; |
||
1839 | gLen = itElem.attribute("GradientFillLength").toDouble(); |
||
1840 | gAngle = itElem.attribute("GradientFillAngle").toDouble(); |
||
1841 | } |
||
1842 | if (itElem.hasAttribute("StrokeColor")) |
||
1843 | { |
||
17232 | fschmid | 1844 | strokeColor = itElem.attribute("StrokeColor"); |
1845 | if (colorTranslate.contains(strokeColor)) |
||
1846 | strokeColor = colorTranslate[strokeColor]; |
||
1847 | else |
||
1848 | { |
||
1849 | if (gradientTranslate.contains(strokeColor)) |
||
1850 | { |
||
1851 | strokeGradientTyp = gradientTypeMap[strokeColor]; |
||
1852 | strokeGradient = gradientTranslate[strokeColor]; |
||
1853 | } |
||
1854 | } |
||
17210 | fschmid | 1855 | } |
17232 | fschmid | 1856 | if (itElem.hasAttribute("GradientStrokeStart")) |
1857 | { |
||
1858 | QString fillGStart = itElem.attribute("GradientStrokeStart"); |
||
1859 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1860 | Code >> gstSX >> gstSY; |
||
1861 | gSLen = itElem.attribute("GradientStrokeLength").toDouble(); |
||
1862 | gSAngle = itElem.attribute("GradientStrokeAngle").toDouble(); |
||
1863 | } |
||
17210 | fschmid | 1864 | if (itElem.hasAttribute("StrokeWeight")) |
1865 | lineWidth = itElem.attribute("StrokeWeight").toDouble(); |
||
1866 | if (itElem.hasAttribute("FillTint")) |
||
17349 | fschmid | 1867 | { |
1868 | if (itElem.attribute("FillTint").toInt() != -1) |
||
1869 | fillShade = itElem.attribute("FillTint").toInt(); |
||
1870 | } |
||
1871 | if (fillShade < 0) |
||
1872 | fillShade = 100; |
||
17210 | fschmid | 1873 | if (itElem.hasAttribute("StrokeTint")) |
17349 | fschmid | 1874 | { |
1875 | if (itElem.attribute("StrokeTint").toInt() != -1) |
||
1876 | strokeShade = itElem.attribute("StrokeTint").toInt(); |
||
1877 | } |
||
1878 | if (strokeShade < 0) |
||
1879 | strokeShade = 100; |
||
18401 | fschmid | 1880 | if (itElem.hasAttribute("RightLineEnd")) |
24705 | jghali | 1881 | rightLineEnd = itElem.attribute("RightLineEnd"); |
18401 | fschmid | 1882 | if (itElem.hasAttribute("LeftLineEnd")) |
24705 | jghali | 1883 | leftLineEnd = itElem.attribute("LeftLineEnd"); |
17199 | fschmid | 1884 | QString forLayer = itElem.attribute("ItemLayer"); |
1885 | if (layerTranslate.contains(forLayer)) |
||
1886 | forLayer = layerTranslate[forLayer]; |
||
1887 | else |
||
1888 | forLayer = m_Doc->layerName(0); |
||
1889 | int layerNum = 0; |
||
1890 | ScLayers::iterator itend = m_Doc->Layers.end(); |
||
1891 | ScLayers::iterator it; |
||
1892 | for (it = m_Doc->Layers.begin(); it != itend; ++it) |
||
1893 | { |
||
1894 | if (it->Name == forLayer) |
||
1895 | { |
||
1896 | layerNum = it->ID; |
||
1897 | break; |
||
1898 | } |
||
1899 | } |
||
1900 | bool isOpen = false; |
||
1901 | bool isGroup = false; |
||
1902 | bool realGroup = false; |
||
1903 | bool isImage = false; |
||
17206 | fschmid | 1904 | bool isPathText = false; |
17199 | fschmid | 1905 | if (itElem.tagName() == "Group") |
1906 | realGroup = true; |
||
25070 | craig | 1907 | QString imageType; |
1908 | QByteArray imageData; |
||
1909 | QString imageFileName; |
||
17199 | fschmid | 1910 | QTransform imageTransform; |
20043 | fschmid | 1911 | double imageDX = 0; |
1912 | double imageDY = 0; |
||
25070 | craig | 1913 | QString storyForPath; |
17206 | fschmid | 1914 | int pathTextType = 0; |
17262 | fschmid | 1915 | double pathTextStart = 0; |
22723 | jghali | 1916 | for (QDomNode it = itElem.firstChild(); !it.isNull(); it = it.nextSibling()) |
17199 | fschmid | 1917 | { |
1918 | QDomElement ite = it.toElement(); |
||
1919 | if (ite.tagName() == "Properties") |
||
1920 | { |
||
22723 | jghali | 1921 | for (QDomNode itp = ite.firstChild(); !itp.isNull(); itp = itp.nextSibling()) |
17199 | fschmid | 1922 | { |
1923 | QDomElement itpg = itp.toElement(); |
||
24701 | jghali | 1924 | if (itpg.tagName() != "PathGeometry") |
1925 | continue; |
||
1926 | |||
1927 | for (QDomNode itg = itpg.firstChild(); !itg.isNull(); itg = itg.nextSibling()) |
||
17199 | fschmid | 1928 | { |
24701 | jghali | 1929 | QDomElement itgg = itg.toElement(); |
1930 | if (itgg.tagName() != "GeometryPathType") |
||
1931 | continue; |
||
1932 | |||
1933 | isOpen = (itgg.attribute("PathOpen") == "true"); |
||
1934 | for (QDomNode itpp = itgg.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling()) |
||
17199 | fschmid | 1935 | { |
24701 | jghali | 1936 | QDomElement itpa = itpp.toElement(); |
1937 | if (itpa.tagName() != "PathPointArray") |
||
1938 | continue; |
||
1939 | |||
1940 | bool firstPoint = true; |
||
1941 | QPointF firstBezPoint; |
||
1942 | QPointF firstAncPoint; |
||
1943 | QList<QPointF> pointList; |
||
1944 | for (QDomNode itpap = itpa.firstChild(); !itpap.isNull(); itpap = itpap.nextSibling()) |
||
17199 | fschmid | 1945 | { |
24701 | jghali | 1946 | QDomElement itpo = itpap.toElement(); |
1947 | if (itpo.tagName() != "PathPointType") |
||
1948 | continue; |
||
1949 | |||
1950 | double x1, y1, x2, y2, x3, y3; |
||
1951 | QString anchor = itpo.attribute("Anchor"); |
||
1952 | QString lDir = itpo.attribute("LeftDirection"); |
||
1953 | QString rDir = itpo.attribute("RightDirection"); |
||
1954 | ScTextStream an(&anchor, QIODevice::ReadOnly); |
||
1955 | an >> x1 >> y1; |
||
1956 | QPointF aP = QPointF(x1, y1); |
||
1957 | ScTextStream lr(&lDir, QIODevice::ReadOnly); |
||
1958 | lr >> x2 >> y2; |
||
1959 | QPointF lP = QPointF(x2, y2); |
||
1960 | ScTextStream rr(&rDir, QIODevice::ReadOnly); |
||
1961 | rr >> x3 >> y3; |
||
1962 | QPointF rP = QPointF(x3, y3); |
||
1963 | |||
1964 | if (firstPoint) |
||
17199 | fschmid | 1965 | { |
24701 | jghali | 1966 | firstBezPoint = lP; |
1967 | firstAncPoint = aP; |
||
1968 | pointList.append(aP); |
||
1969 | pointList.append(rP); |
||
1970 | firstPoint = false; |
||
1971 | } |
||
1972 | else |
||
1973 | { |
||
1974 | if (itElem.tagName() == "GraphicLine") |
||
17199 | fschmid | 1975 | { |
24701 | jghali | 1976 | pointList.append(lP); |
1977 | pointList.append(aP); |
||
17199 | fschmid | 1978 | } |
24701 | jghali | 1979 | else |
1980 | { |
||
1981 | pointList.append(lP); |
||
1982 | pointList.append(aP); |
||
1983 | pointList.append(rP); |
||
1984 | } |
||
17199 | fschmid | 1985 | } |
1986 | } |
||
24701 | jghali | 1987 | if (itElem.tagName() == "GraphicLine") |
1988 | { |
||
1989 | if (pointList.count() > 1) |
||
1990 | { |
||
1991 | GCoords.svgMoveTo(pointList[0].x(), pointList[0].y()); |
||
1992 | QPointF p1 = pointList[1]; |
||
1993 | QPointF p2 = pointList[2]; |
||
1994 | QPointF p3 = pointList[3]; |
||
1995 | GCoords.svgCurveToCubic(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y()); |
||
1996 | } |
||
1997 | } |
||
1998 | else if (pointList.count() > 0) |
||
1999 | { |
||
2000 | if (isOpen) |
||
2001 | { |
||
2002 | pointList.removeLast(); |
||
2003 | } |
||
2004 | else |
||
2005 | { |
||
2006 | pointList.append(firstBezPoint); |
||
2007 | pointList.append(firstAncPoint); |
||
2008 | } |
||
2009 | if (pointList.count() > 1) |
||
2010 | { |
||
2011 | GCoords.svgMoveTo(pointList[0].x(), pointList[0].y()); |
||
2012 | for (int a = 1; a < pointList.count(); a += 3) |
||
2013 | { |
||
2014 | QPointF p1 = pointList[a]; |
||
2015 | QPointF p2 = pointList[a + 1]; |
||
2016 | QPointF p3 = pointList[a + 2]; |
||
2017 | GCoords.svgCurveToCubic(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y()); |
||
2018 | } |
||
2019 | } |
||
2020 | } |
||
17199 | fschmid | 2021 | } |
24701 | jghali | 2022 | if (!isOpen) |
2023 | GCoords.svgClosePath(); |
||
17199 | fschmid | 2024 | } |
2025 | } |
||
2026 | } |
||
2027 | else if ((ite.tagName() == "Rectangle") || (ite.tagName() == "Oval") || (ite.tagName() == "GraphicLine") || (ite.tagName() == "Polygon") || (ite.tagName() == "TextFrame") || (ite.tagName() == "Group") || (ite.tagName() == "Button")) |
||
2028 | { |
||
2029 | isGroup = true; |
||
2030 |