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