Rev 17199 | Rev 17206 | 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> |
||
22 | #include <QDebug> |
||
23 | |||
17203 | jghali | 24 | #if defined(_MSC_VER) |
25 | #define _USE_MATH_DEFINES |
||
26 | #endif |
||
27 | |||
17199 | fschmid | 28 | #include <cstdlib> |
29 | #include <climits> |
||
30 | #include <limits> |
||
31 | |||
32 | #include "commonstrings.h" |
||
17203 | jghali | 33 | |
17199 | fschmid | 34 | #include "importidml.h" |
35 | #include "loadsaveplugin.h" |
||
36 | #include "pagesize.h" |
||
37 | #include "prefscontext.h" |
||
38 | #include "prefsfile.h" |
||
39 | #include "prefsmanager.h" |
||
40 | #include "prefstable.h" |
||
41 | #include "rawimage.h" |
||
42 | #include "scclocale.h" |
||
43 | #include "sccolorengine.h" |
||
44 | #include "scconfig.h" |
||
45 | #include "scmimedata.h" |
||
46 | #include "scpaths.h" |
||
47 | #include "scribus.h" |
||
48 | #include "scribusXml.h" |
||
49 | #include "scribuscore.h" |
||
50 | #include "sctextstream.h" |
||
51 | #include "selection.h" |
||
52 | #include "undomanager.h" |
||
53 | #include "util.h" |
||
54 | #include "util_formats.h" |
||
55 | #include "util_icon.h" |
||
56 | #include "util_math.h" |
||
57 | |||
17203 | jghali | 58 | #include "ui/customfdialog.h" |
59 | #include "ui/missing.h" |
||
60 | #include "ui/multiprogressdialog.h" |
||
61 | #include "ui/propertiespalette.h" |
||
62 | |||
17199 | fschmid | 63 | extern SCRIBUS_API ScribusQApp * ScQApp; |
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); |
||
71 | progressDialog = NULL; |
||
72 | } |
||
73 | |||
74 | QString IdmlPlug::getNodeValue(QDomNode &baseNode, QString path) |
||
75 | { |
||
76 | QString ret = ""; |
||
77 | QStringList pathParts = path.split("/", QString::SkipEmptyParts); |
||
78 | QDomNode n = baseNode.namedItem(pathParts[0]); |
||
79 | bool fail = false; |
||
80 | if (!n.isNull()) |
||
81 | { |
||
82 | for (int a = 1; a < pathParts.count(); a++) |
||
83 | { |
||
84 | n = n.namedItem(pathParts[a]); |
||
85 | if (n.isNull()) |
||
86 | { |
||
87 | fail = true; |
||
88 | break; |
||
89 | } |
||
90 | } |
||
91 | if (!fail) |
||
92 | { |
||
93 | QDomElement e = n.toElement(); |
||
94 | if (!e.isNull()) |
||
95 | ret = e.text(); |
||
96 | } |
||
97 | } |
||
98 | return ret; |
||
99 | } |
||
100 | |||
101 | QImage IdmlPlug::readThumbnail(QString fName) |
||
102 | { |
||
103 | QImage tmp; |
||
104 | QByteArray f, f2; |
||
105 | if ( !QFile::exists(fName) ) |
||
106 | return QImage(); |
||
107 | fun = new FileUnzip(fName); |
||
108 | QString designMap = fun->getFile("designmap.xml"); |
||
109 | if (!designMap.isNull()) |
||
110 | { |
||
111 | loadRawText(designMap, f); |
||
112 | delete fun; |
||
113 | if(!designMapDom.setContent(f)) |
||
114 | return QImage(); |
||
115 | QDomElement docElem = designMapDom.documentElement(); |
||
116 | QString metaD = getNodeValue(docElem, "MetadataPacketPreference/Properties/Contents"); |
||
117 | QDomDocument rdfD; |
||
118 | rdfD.setContent(metaD); |
||
119 | QDomElement docElemR = rdfD.documentElement(); |
||
120 | for(QDomNode drawPag = docElemR.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling() ) |
||
121 | { |
||
122 | QDomElement dpg = drawPag.toElement(); |
||
123 | if (dpg.tagName() == "rdf:RDF") |
||
124 | { |
||
125 | for(QDomNode drawPag2 = dpg.firstChild(); !drawPag2.isNull(); drawPag2 = drawPag2.nextSibling() ) |
||
126 | { |
||
127 | QDomElement dpg2 = drawPag2.toElement(); |
||
128 | if (dpg2.hasAttribute("xmlns:xmpGImg")) |
||
129 | { |
||
130 | QByteArray imgD = getNodeValue(dpg2, "xmp:Thumbnails/rdf:Alt/rdf:li/xmpGImg:image").toLatin1(); |
||
131 | QByteArray inlineImageData = QByteArray::fromBase64(imgD); |
||
132 | tmp.loadFromData(inlineImageData); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | return tmp; |
||
139 | } |
||
140 | /* |
||
141 | |||
142 | QFileInfo fi = QFileInfo(fName); |
||
143 | baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/")); |
||
144 | double b, h; |
||
145 | parseHeader(fName, b, h); |
||
146 | if (b == 0.0) |
||
147 | b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth; |
||
148 | if (h == 0.0) |
||
149 | h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight; |
||
150 | docWidth = b; |
||
151 | docHeight = h; |
||
152 | progressDialog = NULL; |
||
153 | m_Doc = new ScribusDoc(); |
||
154 | m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom"); |
||
155 | m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false); |
||
156 | m_Doc->addPage(0); |
||
157 | m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0); |
||
158 | baseX = m_Doc->currentPage()->xOffset(); |
||
159 | baseY = m_Doc->currentPage()->yOffset(); |
||
160 | Elements.clear(); |
||
161 | m_Doc->setLoading(true); |
||
162 | m_Doc->DoDrawing = false; |
||
163 | m_Doc->scMW()->setScriptRunning(true); |
||
164 | QString CurDirP = QDir::currentPath(); |
||
165 | QDir::setCurrent(fi.path()); |
||
166 | if (convert(fName)) |
||
167 | { |
||
168 | tmpSel->clear(); |
||
169 | QDir::setCurrent(CurDirP); |
||
170 | if (Elements.count() > 1) |
||
171 | m_Doc->groupObjectsList(Elements); |
||
172 | m_Doc->DoDrawing = true; |
||
173 | m_Doc->m_Selection->delaySignalsOn(); |
||
174 | QImage tmpImage; |
||
175 | if (Elements.count() > 0) |
||
176 | { |
||
177 | for (int dre=0; dre<Elements.count(); ++dre) |
||
178 | { |
||
179 | tmpSel->addItem(Elements.at(dre), true); |
||
180 | } |
||
181 | tmpSel->setGroupRect(); |
||
182 | double xs = tmpSel->width(); |
||
183 | double ys = tmpSel->height(); |
||
184 | tmpImage = Elements.at(0)->DrawObj_toImage(500); |
||
185 | tmpImage.setText("XSize", QString("%1").arg(xs)); |
||
186 | tmpImage.setText("YSize", QString("%1").arg(ys)); |
||
187 | } |
||
188 | m_Doc->scMW()->setScriptRunning(false); |
||
189 | m_Doc->setLoading(false); |
||
190 | m_Doc->m_Selection->delaySignalsOff(); |
||
191 | delete m_Doc; |
||
192 | return tmpImage; |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | QDir::setCurrent(CurDirP); |
||
197 | m_Doc->DoDrawing = true; |
||
198 | m_Doc->scMW()->setScriptRunning(false); |
||
199 | delete m_Doc; |
||
200 | } |
||
201 | return QImage(); |
||
202 | } |
||
203 | */ |
||
204 | |||
205 | bool IdmlPlug::readColors(const QString& fNameIn, ColorList & colors) |
||
206 | { |
||
207 | bool success = false; |
||
208 | importedColors.clear(); |
||
209 | m_Doc = new ScribusDoc(); |
||
210 | m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom"); |
||
211 | m_Doc->setPage(1, 1, 0, 0, 0, 0, 0, 0, false, false); |
||
212 | m_Doc->addPage(0); |
||
213 | m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0); |
||
214 | QByteArray f; |
||
215 | fun = new FileUnzip(fNameIn); |
||
216 | QString designMap = fun->getFile("designmap.xml"); |
||
217 | if (!designMap.isNull()) |
||
218 | { |
||
219 | loadRawText(designMap, f); |
||
220 | if(designMapDom.setContent(f)) |
||
221 | { |
||
222 | QDomElement docElem = designMapDom.documentElement(); |
||
223 | for(QDomNode drawPag = docElem.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling() ) |
||
224 | { |
||
225 | QDomElement dpg = drawPag.toElement(); |
||
226 | if (dpg.tagName() == "idPkg:Graphic") |
||
227 | { |
||
228 | if (!parseGraphicsXML(dpg)) |
||
229 | { |
||
230 | delete fun; |
||
231 | return false; |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | delete fun; |
||
238 | if (importedColors.count() != 0) |
||
239 | { |
||
240 | colors = m_Doc->PageColors; |
||
241 | success = true; |
||
242 | } |
||
243 | delete m_Doc; |
||
244 | return success; |
||
245 | } |
||
246 | |||
247 | bool IdmlPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress) |
||
248 | { |
||
249 | QString fName = fNameIn; |
||
250 | bool success = false; |
||
251 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
252 | importerFlags = flags; |
||
253 | cancel = false; |
||
254 | bool ret = false; |
||
255 | firstLayer = true; |
||
256 | firstPage = true; |
||
257 | pagecount = 1; |
||
258 | QFileInfo fi = QFileInfo(fName); |
||
259 | if ( !ScCore->usingGUI() ) |
||
260 | { |
||
261 | interactive = false; |
||
262 | showProgress = false; |
||
263 | } |
||
264 | baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/")); |
||
265 | if ( showProgress ) |
||
266 | { |
||
267 | ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW(); |
||
268 | progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw ); |
||
269 | QStringList barNames, barTexts; |
||
270 | barNames << "GI"; |
||
271 | barTexts << tr("Analyzing File:"); |
||
272 | QList<bool> barsNumeric; |
||
273 | barsNumeric << false; |
||
274 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
275 | progressDialog->setOverallTotalSteps(3); |
||
276 | progressDialog->setOverallProgress(0); |
||
277 | progressDialog->setProgress("GI", 0); |
||
278 | progressDialog->show(); |
||
279 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
||
280 | qApp->processEvents(); |
||
281 | } |
||
282 | else |
||
283 | progressDialog = NULL; |
||
284 | if (progressDialog) |
||
285 | { |
||
286 | progressDialog->setOverallProgress(1); |
||
287 | qApp->processEvents(); |
||
288 | } |
||
289 | /* Set default Page to size defined in Preferences */ |
||
290 | docWidth = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth; |
||
291 | docHeight = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight; |
||
292 | baseX = 0; |
||
293 | baseY = 0; |
||
294 | if (!interactive || (flags & LoadSavePlugin::lfInsertPage)) |
||
295 | { |
||
296 | m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false); |
||
297 | m_Doc->addPage(0); |
||
298 | m_Doc->view()->addPage(0, true); |
||
299 | baseX = 0; |
||
300 | baseY = 0; |
||
301 | } |
||
302 | else |
||
303 | { |
||
304 | if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc)) |
||
305 | { |
||
306 | m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true); |
||
307 | ScCore->primaryMainWindow()->HaveNewDoc(); |
||
308 | ret = true; |
||
309 | baseX = 0; |
||
310 | baseY = 0; |
||
311 | baseX = m_Doc->currentPage()->xOffset(); |
||
312 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
313 | } |
||
314 | } |
||
315 | if ((!ret) && (interactive)) |
||
316 | { |
||
317 | baseX = m_Doc->currentPage()->xOffset(); |
||
318 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
319 | } |
||
320 | if ((ret) || (!interactive)) |
||
321 | { |
||
322 | if (docWidth > docHeight) |
||
323 | m_Doc->setPageOrientation(1); |
||
324 | else |
||
325 | m_Doc->setPageOrientation(0); |
||
326 | m_Doc->setPageSize("Custom"); |
||
327 | } |
||
328 | Elements.clear(); |
||
329 | m_Doc->setLoading(true); |
||
330 | m_Doc->DoDrawing = false; |
||
331 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
332 | m_Doc->view()->updatesOn(false); |
||
333 | m_Doc->scMW()->setScriptRunning(true); |
||
334 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
||
335 | QString CurDirP = QDir::currentPath(); |
||
336 | QDir::setCurrent(fi.path()); |
||
337 | if (convert(fName)) |
||
338 | { |
||
339 | tmpSel->clear(); |
||
340 | QDir::setCurrent(CurDirP); |
||
341 | if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc))) |
||
342 | m_Doc->groupObjectsList(Elements); |
||
343 | m_Doc->DoDrawing = true; |
||
344 | m_Doc->scMW()->setScriptRunning(false); |
||
345 | m_Doc->setLoading(false); |
||
346 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
347 | if ((Elements.count() > 0) && (!ret) && (interactive)) |
||
348 | { |
||
349 | if (flags & LoadSavePlugin::lfScripted) |
||
350 | { |
||
351 | bool loadF = m_Doc->isLoading(); |
||
352 | m_Doc->setLoading(false); |
||
353 | m_Doc->changed(); |
||
354 | m_Doc->setLoading(loadF); |
||
355 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
356 | { |
||
357 | m_Doc->m_Selection->delaySignalsOn(); |
||
358 | for (int dre=0; dre<Elements.count(); ++dre) |
||
359 | { |
||
360 | m_Doc->m_Selection->addItem(Elements.at(dre), true); |
||
361 | } |
||
362 | m_Doc->m_Selection->delaySignalsOff(); |
||
363 | m_Doc->m_Selection->setGroupRect(); |
||
364 | m_Doc->view()->updatesOn(true); |
||
365 | } |
||
366 | } |
||
367 | else |
||
368 | { |
||
369 | m_Doc->DragP = true; |
||
370 | m_Doc->DraggedElem = 0; |
||
371 | m_Doc->DragElements.clear(); |
||
372 | m_Doc->m_Selection->delaySignalsOn(); |
||
373 | for (int dre=0; dre<Elements.count(); ++dre) |
||
374 | { |
||
375 | tmpSel->addItem(Elements.at(dre), true); |
||
376 | } |
||
377 | tmpSel->setGroupRect(); |
||
378 | ScriXmlDoc *ss = new ScriXmlDoc(); |
||
379 | ScElemMimeData* md = new ScElemMimeData(); |
||
380 | md->setScribusElem(ss->WriteElem(m_Doc, tmpSel)); |
||
381 | delete ss; |
||
382 | m_Doc->itemSelection_DeleteItem(tmpSel); |
||
383 | m_Doc->view()->updatesOn(true); |
||
384 | m_Doc->m_Selection->delaySignalsOff(); |
||
385 | // We must copy the TransationSettings object as it is owned |
||
386 | // by handleObjectImport method afterwards |
||
387 | TransactionSettings* transacSettings = new TransactionSettings(trSettings); |
||
388 | m_Doc->view()->handleObjectImport(md, transacSettings); |
||
389 | m_Doc->DragP = false; |
||
390 | m_Doc->DraggedElem = 0; |
||
391 | m_Doc->DragElements.clear(); |
||
392 | } |
||
393 | } |
||
394 | else |
||
395 | { |
||
396 | m_Doc->changed(); |
||
397 | m_Doc->reformPages(); |
||
398 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
399 | m_Doc->view()->updatesOn(true); |
||
400 | } |
||
401 | success = true; |
||
402 | } |
||
403 | else |
||
404 | { |
||
405 | QDir::setCurrent(CurDirP); |
||
406 | m_Doc->DoDrawing = true; |
||
407 | m_Doc->scMW()->setScriptRunning(false); |
||
408 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
409 | m_Doc->view()->updatesOn(true); |
||
410 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
411 | } |
||
412 | if (interactive) |
||
413 | m_Doc->setLoading(false); |
||
414 | //CB If we have a gui we must refresh it if we have used the progressbar |
||
415 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
416 | { |
||
417 | if ((showProgress) && (!interactive)) |
||
418 | m_Doc->view()->DrawNew(); |
||
419 | } |
||
420 | return success; |
||
421 | } |
||
422 | |||
423 | IdmlPlug::~IdmlPlug() |
||
424 | { |
||
425 | if (progressDialog) |
||
426 | delete progressDialog; |
||
427 | delete tmpSel; |
||
428 | } |
||
429 | |||
430 | bool IdmlPlug::convert(QString fn) |
||
431 | { |
||
432 | Coords.resize(0); |
||
433 | Coords.svgInit(); |
||
434 | importedColors.clear(); |
||
435 | def_fillColor = CommonStrings::None; |
||
436 | def_strokeColor = CommonStrings::None; |
||
437 | def_fillGradient = ""; |
||
438 | def_Blendmode = 0; |
||
439 | def_fillBlendmode = 0; |
||
440 | def_strokeBlendmode = 0; |
||
441 | def_fillTint = 100; |
||
442 | def_strokeTint = 100; |
||
443 | def_lineWidth = 0; |
||
444 | def_Opacity = 0.0; |
||
445 | def_fillOpacity = 0.0; |
||
446 | def_strokeOpacity = 0.0; |
||
447 | def_gradientAngle = 0.0; |
||
448 | def_gradientLen = 0.0; |
||
449 | def_gradientX = 0.0; |
||
450 | def_gradientY = 0.0; |
||
451 | if(progressDialog) |
||
452 | { |
||
453 | progressDialog->setOverallProgress(2); |
||
454 | progressDialog->setLabel("GI", tr("Generating Items")); |
||
455 | qApp->processEvents(); |
||
456 | } |
||
457 | colorTranslate.insert("Swatch/None", CommonStrings::None); |
||
458 | bool retVal = true; |
||
459 | bool firstSpread = true; |
||
460 | QByteArray f; |
||
461 | fun = new FileUnzip(fn); |
||
462 | QString designMap = fun->getFile("designmap.xml"); |
||
463 | if (!designMap.isNull()) |
||
464 | { |
||
465 | loadRawText(designMap, f); |
||
466 | if(designMapDom.setContent(f)) |
||
467 | { |
||
468 | QDomElement docElem = designMapDom.documentElement(); |
||
469 | QString activeLayer = docElem.attribute("ActiveLayer"); |
||
470 | for(QDomNode drawPag = docElem.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling() ) |
||
471 | { |
||
472 | QDomElement dpg = drawPag.toElement(); |
||
473 | if (dpg.tagName() == "Layer") |
||
474 | { |
||
475 | QString layerSelf = dpg.attribute("Self"); |
||
476 | QString layerName = dpg.attribute("Name"); |
||
477 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
478 | { |
||
479 | int currentLayer = 0; |
||
480 | if (!firstLayer) |
||
481 | currentLayer = m_Doc->addLayer(layerName); |
||
482 | else |
||
483 | m_Doc->changeLayerName(currentLayer, layerName); |
||
484 | m_Doc->setLayerVisible(currentLayer, (dpg.attribute("Visible") == "true")); |
||
485 | m_Doc->setLayerLocked(currentLayer, (dpg.attribute("Locked") == "true")); |
||
486 | m_Doc->setLayerPrintable(currentLayer, (dpg.attribute("Printable") == "true")); |
||
487 | m_Doc->setLayerFlow(currentLayer, (dpg.attribute("IgnoreWrap","") == "true")); |
||
488 | } |
||
489 | layerTranslate.insert(layerSelf, layerName); |
||
490 | firstLayer = false; |
||
491 | } |
||
492 | if (dpg.tagName() == "idPkg:Graphic") |
||
493 | { |
||
494 | if (!parseGraphicsXML(dpg)) |
||
495 | { |
||
496 | retVal = false; |
||
497 | break; |
||
498 | } |
||
499 | } |
||
500 | if (dpg.tagName() == "idPkg:Styles") |
||
501 | { |
||
502 | if (!parseStylesXML(dpg)) |
||
503 | { |
||
504 | retVal = false; |
||
505 | break; |
||
506 | } |
||
507 | } |
||
508 | if (dpg.tagName() == "idPkg:Preferences") |
||
509 | { |
||
510 | if (!parsePreferencesXML(dpg)) |
||
511 | { |
||
512 | retVal = false; |
||
513 | break; |
||
514 | } |
||
515 | } |
||
516 | if (dpg.tagName() == "idPkg:MasterSpread") |
||
517 | MasterSpreads.append(dpg.attribute("src")); |
||
518 | if (dpg.tagName() == "idPkg:Spread") |
||
519 | { |
||
520 | if (!(importerFlags & LoadSavePlugin::lfCreateDoc)) |
||
521 | { |
||
522 | if (firstSpread) |
||
523 | { |
||
524 | parseSpreadXML(dpg); |
||
525 | firstSpread = false; |
||
526 | } |
||
527 | } |
||
528 | else if (!parseSpreadXML(dpg)) |
||
529 | { |
||
530 | retVal = false; |
||
531 | break; |
||
532 | } |
||
533 | } |
||
534 | if (dpg.tagName() == "idPkg:Story") |
||
535 | { |
||
536 | if (!parseStoryXML(dpg)) |
||
537 | { |
||
538 | retVal = false; |
||
539 | break; |
||
540 | } |
||
541 | } |
||
542 | } |
||
543 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
544 | { |
||
545 | if (layerTranslate.contains(activeLayer)) |
||
546 | activeLayer = layerTranslate[activeLayer]; |
||
547 | else |
||
548 | activeLayer = m_Doc->layerName(0); |
||
549 | m_Doc->setActiveLayer(activeLayer); |
||
550 | } |
||
551 | } |
||
552 | } |
||
553 | delete fun; |
||
554 | if (progressDialog) |
||
555 | progressDialog->close(); |
||
556 | return retVal; |
||
557 | } |
||
558 | |||
559 | bool IdmlPlug::parseGraphicsXML(const QDomElement& grElem) |
||
560 | { |
||
561 | QDomElement grNode; |
||
562 | QDomDocument grMapDom; |
||
563 | if (grElem.hasAttribute("src")) |
||
564 | { |
||
565 | QByteArray f2; |
||
566 | loadRawText(fun->getFile(grElem.attribute("src")), f2); |
||
567 | if(grMapDom.setContent(f2)) |
||
568 | grNode = grMapDom.documentElement(); |
||
569 | else |
||
570 | return false; |
||
571 | } |
||
572 | else |
||
573 | { |
||
574 | if (grElem.hasChildNodes()) |
||
575 | grNode = grElem; |
||
576 | else |
||
577 | return false; |
||
578 | } |
||
579 | for (QDomNode n = grNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
580 | { |
||
581 | QDomElement e = n.toElement(); |
||
582 | if (e.tagName() == "Color") |
||
583 | { |
||
584 | QString colorSelf = e.attribute("Self"); |
||
585 | QString colorName = e.attribute("Self").remove(0, 6); |
||
586 | QString colorData = e.attribute("ColorValue"); |
||
587 | QString colorSpace = e.attribute("Space"); |
||
588 | QString colorModel = e.attribute("Model"); |
||
589 | if (colorSpace == "CMYK") |
||
590 | { |
||
591 | double c, m, y, k; |
||
592 | ScColor tmp; |
||
593 | ScTextStream Code(&colorData, QIODevice::ReadOnly); |
||
594 | Code >> c >> m >> y >> k; |
||
595 | tmp.setColor(qRound(c * 2.55), qRound(m * 2.55), qRound(y * 2.55), qRound(k * 2.55)); |
||
596 | tmp.setSpotColor(colorModel == "Spot"); |
||
597 | tmp.setRegistrationColor(colorModel == "Registration"); |
||
598 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, tmp); |
||
599 | if (fNam == colorName) |
||
600 | importedColors.append(fNam); |
||
601 | colorTranslate.insert(colorSelf, fNam); |
||
602 | } |
||
603 | else if (colorSpace == "RGB") |
||
604 | { |
||
605 | int r, g, b; |
||
606 | ScColor tmp; |
||
607 | ScTextStream Code(&colorData, QIODevice::ReadOnly); |
||
608 | Code >> r >> g >> b; |
||
609 | tmp.setColorRGB(r, g, b); |
||
610 | tmp.setSpotColor(false); |
||
611 | tmp.setRegistrationColor(false); |
||
612 | QString fNam = m_Doc->PageColors.tryAddColor(colorName, tmp); |
||
613 | if (fNam == colorName) |
||
614 | importedColors.append(fNam); |
||
615 | colorTranslate.insert(colorSelf, fNam); |
||
616 | } |
||
617 | } |
||
618 | if (e.tagName() == "Gradient") |
||
619 | { |
||
620 | QString grSelf = e.attribute("Self"); |
||
621 | QString grName = e.attribute("Self").remove(0, 9); |
||
622 | int grTyp = (e.attribute("Type") == "Linear") ? 6 : 7; |
||
623 | VGradient currentGradient = VGradient(VGradient::linear); |
||
624 | currentGradient.clearStops(); |
||
625 | for(QDomNode gr = e.firstChild(); !gr.isNull(); gr = gr.nextSibling() ) |
||
626 | { |
||
627 | QDomElement grs = gr.toElement(); |
||
628 | if (grs.tagName() == "GradientStop") |
||
629 | { |
||
630 | QString stopName = grs.attribute("StopColor"); |
||
631 | double stop = grs.attribute("Location", "0.0").toDouble(); |
||
632 | if (colorTranslate.contains(stopName)) |
||
633 | stopName = colorTranslate[stopName]; |
||
634 | else |
||
635 | stopName = "Black"; |
||
636 | const ScColor& gradC = m_Doc->PageColors[stopName]; |
||
637 | currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop / 100.0, 0.5, 1.0, stopName, 100 ); |
||
638 | } |
||
639 | } |
||
640 | if (m_Doc->addGradient(grName, currentGradient)) |
||
641 | importedGradients.append(grName); |
||
642 | gradientTranslate.insert(grSelf, grName); |
||
643 | gradientTypeMap.insert(grSelf, grTyp); |
||
644 | } |
||
645 | } |
||
646 | return true; |
||
647 | } |
||
648 | |||
649 | bool IdmlPlug::parseStylesXML(const QDomElement& sElem) |
||
650 | { |
||
651 | QDomElement sNode; |
||
652 | QDomDocument sMapDom; |
||
653 | if (sElem.hasAttribute("src")) |
||
654 | { |
||
655 | QByteArray f2; |
||
656 | loadRawText(fun->getFile(sElem.attribute("src")), f2); |
||
657 | if(sMapDom.setContent(f2)) |
||
658 | sNode = sMapDom.documentElement(); |
||
659 | else |
||
660 | return false; |
||
661 | } |
||
662 | else |
||
663 | { |
||
664 | if (sElem.hasChildNodes()) |
||
665 | sNode = sElem; |
||
666 | else |
||
667 | return false; |
||
668 | } |
||
669 | for (QDomNode n = sNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
670 | { |
||
671 | QDomElement e = n.toElement(); |
||
672 | if (e.tagName() == "RootParagraphStyleGroup") |
||
673 | { |
||
674 | for(QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling() ) |
||
675 | { |
||
676 | QDomElement itpg = it.toElement(); |
||
677 | if (itpg.tagName() == "ParagraphStyle") |
||
678 | parseParagraphStyle(itpg); |
||
679 | else if (itpg.tagName() == "ParagraphStyleGroup") |
||
680 | { |
||
681 | for(QDomNode its = itpg.firstChild(); !its.isNull(); its = its.nextSibling() ) |
||
682 | { |
||
683 | QDomElement itp = its.toElement(); |
||
684 | if (itp.tagName() == "ParagraphStyle") |
||
685 | parseParagraphStyle(itp); |
||
686 | } |
||
687 | } |
||
688 | } |
||
689 | } |
||
690 | } |
||
691 | return true; |
||
692 | } |
||
693 | |||
694 | void IdmlPlug::parseParagraphStyle(const QDomElement& styleElem) |
||
695 | { |
||
696 | ParagraphStyle newStyle; |
||
697 | newStyle.erase(); |
||
698 | newStyle.setName(styleElem.attribute("Name")); |
||
699 | newStyle.setDefaultStyle(false); |
||
700 | newStyle.setParent(CommonStrings::DefaultParagraphStyle); |
||
701 | QString fontName = m_Doc->itemToolPrefs().textFont; |
||
702 | QString fontBaseName = ""; |
||
703 | QString fontStyle = styleElem.attribute("FontStyle", ""); |
||
704 | for(QDomNode itp = styleElem.firstChild(); !itp.isNull(); itp = itp.nextSibling() ) |
||
705 | { |
||
706 | QDomElement itpr = itp.toElement(); |
||
707 | if (itpr.tagName() == "Properties") |
||
708 | { |
||
709 | for(QDomNode itpp = itpr.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling() ) |
||
710 | { |
||
711 | QDomElement i = itpp.toElement(); |
||
712 | if (i.tagName() == "AppliedFont") |
||
713 | fontBaseName = i.text(); |
||
714 | else if (i.tagName() == "BasedOn") |
||
715 | { |
||
716 | QString parentStyle = i.text(); |
||
717 | if (styleTranslate.contains(parentStyle)) |
||
718 | parentStyle = styleTranslate[parentStyle]; |
||
719 | if (m_Doc->styleExists(parentStyle)) |
||
720 | newStyle.setParent(parentStyle); |
||
721 | } |
||
722 | } |
||
723 | } |
||
724 | } |
||
725 | if ((!fontBaseName.isEmpty()) && (!fontStyle.isEmpty())) |
||
726 | fontName = constructFontName(fontBaseName, fontStyle); |
||
727 | newStyle.charStyle().setFont((*m_Doc->AllFonts)[fontName]); |
||
728 | int pointSize = qRound(styleElem.attribute("PointSize", "12").toDouble() * 10); |
||
729 | if (pointSize > 0) |
||
730 | newStyle.charStyle().setFontSize(pointSize); |
||
731 | QString fillColor = styleElem.attribute("FillColor"); |
||
732 | if (colorTranslate.contains(fillColor)) |
||
733 | newStyle.charStyle().setFillColor(colorTranslate[fillColor]); |
||
734 | if (styleElem.hasAttribute("FillTint")) |
||
735 | { |
||
736 | int fillTint = styleElem.attribute("FillTint", "100").toInt(); |
||
737 | if (fillTint != -1) |
||
738 | newStyle.charStyle().setFillShade(fillTint); |
||
739 | } |
||
740 | |||
741 | newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); |
||
742 | if (styleElem.hasAttribute("LeftIndent")) |
||
743 | newStyle.setLeftMargin(styleElem.attribute("LeftIndent", "0").toDouble()); |
||
744 | if (styleElem.hasAttribute("FirstLineIndent")) |
||
745 | newStyle.setFirstIndent(styleElem.attribute("FirstLineIndent", "0").toDouble()); |
||
746 | if (styleElem.hasAttribute("RightIndent")) |
||
747 | newStyle.setRightMargin(styleElem.attribute("RightIndent", "0").toDouble()); |
||
748 | if (styleElem.hasAttribute("SpaceBefore")) |
||
749 | newStyle.setGapBefore(styleElem.attribute("SpaceBefore", "0").toDouble()); |
||
750 | if (styleElem.hasAttribute("SpaceAfter")) |
||
751 | newStyle.setGapAfter(styleElem.attribute("SpaceAfter", "0").toDouble()); |
||
752 | if (styleElem.hasAttribute("DropCapCharacters")) |
||
753 | { |
||
754 | newStyle.setHasDropCap(styleElem.attribute("DropCapCharacters", "0").toInt() != 0); |
||
755 | if (styleElem.hasAttribute("DropCapLines")) |
||
756 | newStyle.setDropCapLines(styleElem.attribute("DropCapLines", "2").toInt()); |
||
757 | } |
||
758 | QString align = styleElem.attribute("Justification", "LeftAlign"); |
||
759 | if (align == "LeftAlign") |
||
760 | newStyle.setAlignment(ParagraphStyle::Leftaligned); |
||
761 | else if (align == "CenterAlign") |
||
762 | newStyle.setAlignment(ParagraphStyle::Centered); |
||
763 | else if (align == "RightAlign") |
||
764 | newStyle.setAlignment(ParagraphStyle::Rightaligned); |
||
765 | else if ((align == "LeftJustified") || (align == "CenterJustified") || (align == "RightJustified")) |
||
766 | newStyle.setAlignment(ParagraphStyle::Justified); |
||
767 | else if (align == "FullyJustified") |
||
768 | newStyle.setAlignment(ParagraphStyle::Extended); |
||
769 | StyleSet<ParagraphStyle>tmp; |
||
770 | tmp.create(newStyle); |
||
771 | m_Doc->redefineStyles(tmp, false); |
||
772 | styleTranslate.insert(styleElem.attribute("Self"), styleElem.attribute("Name")); |
||
773 | } |
||
774 | |||
775 | bool IdmlPlug::parsePreferencesXML(const QDomElement& prElem) |
||
776 | { |
||
777 | QDomElement prNode; |
||
778 | QDomDocument prMapDom; |
||
779 | if (prElem.hasAttribute("src")) |
||
780 | { |
||
781 | QByteArray f2; |
||
782 | loadRawText(fun->getFile(prElem.attribute("src")), f2); |
||
783 | if(prMapDom.setContent(f2)) |
||
784 | prNode = prMapDom.documentElement(); |
||
785 | else |
||
786 | return false; |
||
787 | } |
||
788 | else |
||
789 | { |
||
790 | if (prElem.hasChildNodes()) |
||
791 | prNode = prElem; |
||
792 | else |
||
793 | return false; |
||
794 | } |
||
795 | double topMargin = m_Doc->marginsVal().Top; |
||
796 | double leftMargin = m_Doc->marginsVal().Left; |
||
797 | double rightMargin = m_Doc->marginsVal().Right; |
||
798 | double bottomMargin = m_Doc->marginsVal().Bottom; |
||
799 | double pgCols = m_Doc->PageSp; |
||
800 | double pgGap = m_Doc->PageSpa; |
||
801 | double bleedTop = m_Doc->bleeds()->Top; |
||
802 | double bleedLeft = m_Doc->bleeds()->Left; |
||
803 | double bleedRight = m_Doc->bleeds()->Right; |
||
804 | double bleedBottom = m_Doc->bleeds()->Bottom; |
||
805 | facingPages = false; |
||
806 | for (QDomNode n = prNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
807 | { |
||
808 | QDomElement e = n.toElement(); |
||
809 | if (e.tagName() == "DocumentPreference") |
||
810 | { |
||
811 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
812 | { |
||
813 | docWidth = e.attribute("PageWidth").toDouble(); |
||
814 | docHeight = e.attribute("PageHeight").toDouble(); |
||
815 | bleedTop = e.attribute("DocumentBleedTopOffset").toDouble(); |
||
816 | bleedLeft = e.attribute("DocumentBleedInsideOrLeftOffset").toDouble(); |
||
817 | bleedRight = e.attribute("DocumentBleedOutsideOrRightOffset").toDouble(); |
||
818 | bleedBottom = e.attribute("DocumentBleedBottomOffset").toDouble(); |
||
819 | facingPages = (e.attribute("FacingPages","") == "true") ? 1 : 0; |
||
820 | } |
||
821 | } |
||
822 | if (e.tagName() == "MarginPreference") |
||
823 | { |
||
824 | topMargin = e.attribute("Top").toDouble(); |
||
825 | leftMargin = e.attribute("Left").toDouble(); |
||
826 | rightMargin = e.attribute("Right").toDouble(); |
||
827 | bottomMargin = e.attribute("Bottom").toDouble(); |
||
828 | pgCols = e.attribute("ColumnCount").toDouble(); |
||
829 | pgGap = e.attribute("ColumnGutter").toDouble(); |
||
830 | } |
||
831 | if (e.tagName() == "TransparencyDefaultContainerObject") |
||
832 | { |
||
833 | for(QDomNode it = e.firstChild(); !it.isNull(); it = it.nextSibling() ) |
||
834 | { |
||
835 | QDomElement itpg = it.toElement(); |
||
836 | for(QDomNode itp = itpg.firstChild(); !itp.isNull(); itp = itp.nextSibling() ) |
||
837 | { |
||
838 | QDomElement itpr = itp.toElement(); |
||
839 | if (itpr.tagName() == "TransparencySetting") |
||
840 | { |
||
841 | def_Opacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
842 | def_Blendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
843 | } |
||
844 | if (itpr.tagName() == "StrokeTransparencySetting") |
||
845 | { |
||
846 | def_strokeOpacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
847 | def_strokeBlendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
848 | } |
||
849 | if (itpr.tagName() == "FillTransparencySetting") |
||
850 | { |
||
851 | def_fillOpacity = 1.0 - (itpr.attribute("Opacity", "100").toDouble() / 100.0); |
||
852 | def_fillBlendmode = convertBlendMode(itpr.attribute("BlendMode", "Normal")); |
||
853 | } |
||
854 | } |
||
855 | } |
||
856 | } |
||
857 | if (e.tagName() == "PageItemDefault") |
||
858 | { |
||
859 | QString strokeColor = e.attribute("StrokeColor"); |
||
860 | if (colorTranslate.contains(strokeColor)) |
||
861 | def_strokeColor = colorTranslate[strokeColor]; |
||
862 | QString fillColor = e.attribute("FillColor"); |
||
863 | if (colorTranslate.contains(fillColor)) |
||
864 | def_fillColor = colorTranslate[fillColor]; |
||
865 | else |
||
866 | { |
||
867 | if (gradientTranslate.contains(fillColor)) |
||
868 | { |
||
869 | def_fillGradient = gradientTranslate[fillColor]; |
||
870 | } |
||
871 | } |
||
872 | int fillShade = e.attribute("FillTint", "100").toInt(); |
||
873 | if (fillShade != -1) |
||
874 | def_fillTint = fillShade; |
||
875 | else |
||
876 | def_fillTint = 100; |
||
877 | int strokeShade = e.attribute("StrokeTint", "100").toInt(); |
||
878 | if (strokeShade != -1) |
||
879 | def_strokeTint = strokeShade; |
||
880 | else |
||
881 | def_strokeTint = 100; |
||
882 | def_lineWidth = e.attribute("StrokeWeight", "0").toDouble(); |
||
883 | QString fillGStart = e.attribute("GradientFillStart", "0 0"); |
||
884 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
885 | Code >> def_gradientX >> def_gradientY; |
||
886 | def_gradientLen = e.attribute("GradientFillLength", "0").toDouble(); |
||
887 | def_gradientAngle = e.attribute("GradientFillAngle", "0").toDouble(); |
||
888 | } |
||
889 | } |
||
890 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
891 | { |
||
892 | m_Doc->setPage(docWidth, docHeight, topMargin, leftMargin, rightMargin, bottomMargin, pgCols, pgGap, false, facingPages); |
||
893 | m_Doc->setPageSize("Custom"); |
||
894 | m_Doc->bleeds()->set(bleedTop, bleedLeft, bleedBottom, bleedRight); |
||
895 | m_Doc->currentPage()->m_pageSize = "Custom"; |
||
896 | m_Doc->currentPage()->setInitialHeight(docHeight); |
||
897 | m_Doc->currentPage()->setInitialWidth(docWidth); |
||
898 | m_Doc->currentPage()->setHeight(docHeight); |
||
899 | m_Doc->currentPage()->setWidth(docWidth); |
||
900 | m_Doc->currentPage()->initialMargins.Top = topMargin; |
||
901 | m_Doc->currentPage()->initialMargins.Bottom = bottomMargin; |
||
902 | m_Doc->currentPage()->initialMargins.Left = leftMargin; |
||
903 | m_Doc->currentPage()->initialMargins.Right = rightMargin; |
||
904 | m_Doc->reformPages(true); |
||
905 | baseX = m_Doc->currentPage()->xOffset(); |
||
906 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
907 | } |
||
908 | return true; |
||
909 | } |
||
910 | |||
911 | bool IdmlPlug::parseSpreadXML(const QDomElement& spElem) |
||
912 | { |
||
913 | QDomElement spNode; |
||
914 | QDomDocument spMapDom; |
||
915 | if (spElem.hasAttribute("src")) |
||
916 | { |
||
917 | QByteArray f2; |
||
918 | loadRawText(fun->getFile(spElem.attribute("src")), f2); |
||
919 | if(spMapDom.setContent(f2)) |
||
920 | spNode = spMapDom.documentElement(); |
||
921 | else |
||
922 | return false; |
||
923 | } |
||
924 | else |
||
925 | { |
||
926 | if (spElem.hasChildNodes()) |
||
927 | spNode = spElem; |
||
928 | else |
||
929 | return false; |
||
930 | } |
||
931 | for (QDomNode n = spNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
932 | { |
||
933 | QDomElement e = n.toElement(); |
||
934 | if (e.tagName() == "Spread") |
||
935 | { |
||
936 | for(QDomNode sp = e.firstChild(); !sp.isNull(); sp = sp.nextSibling() ) |
||
937 | { |
||
938 | QDomElement spe = sp.toElement(); |
||
939 | if (spe.tagName() == "Page") |
||
940 | { |
||
941 | if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (!firstPage)) |
||
942 | { |
||
943 | m_Doc->addPage(pagecount); |
||
944 | m_Doc->currentPage()->MPageNam = CommonStrings::trMasterPageNormal; |
||
945 | m_Doc->view()->addPage(pagecount, true); |
||
946 | pagecount++; |
||
947 | } |
||
948 | baseX = m_Doc->currentPage()->xOffset(); |
||
949 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
950 | firstPage = false; |
||
951 | } |
||
952 | } |
||
953 | if ((facingPages) && (pagecount % 2 == 0)) |
||
954 | { |
||
955 | baseX = m_Doc->currentPage()->xOffset() + m_Doc->currentPage()->width(); |
||
956 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
957 | } |
||
958 | if (!facingPages) |
||
959 | { |
||
960 | baseX = m_Doc->currentPage()->xOffset() + m_Doc->currentPage()->width() / 2.0; |
||
961 | baseY = m_Doc->currentPage()->yOffset() + m_Doc->currentPage()->height() / 2.0; |
||
962 | } |
||
963 | for(QDomNode sp = e.firstChild(); !sp.isNull(); sp = sp.nextSibling() ) |
||
964 | { |
||
965 | QDomElement spe = sp.toElement(); |
||
966 | if ((spe.tagName() == "Rectangle") || (spe.tagName() == "Oval") || (spe.tagName() == "GraphicLine") || (spe.tagName() == "Polygon") || (spe.tagName() == "TextFrame") || (spe.tagName() == "Group") || (spe.tagName() == "Button")) |
||
967 | { |
||
968 | QList<PageItem*> el = parseItemXML(spe); |
||
969 | for (int ec = 0; ec < el.count(); ++ec) |
||
970 | { |
||
971 | m_Doc->Items->append(el.at(ec)); |
||
972 | Elements.append(el.at(ec)); |
||
973 | } |
||
974 | } |
||
975 | } |
||
976 | } |
||
977 | } |
||
978 | return true; |
||
979 | } |
||
980 | |||
981 | QList<PageItem*> IdmlPlug::parseItemXML(const QDomElement& itElem, QTransform pTrans) |
||
982 | { |
||
983 | QList<PageItem*> GElements; |
||
984 | FPointArray GCoords; |
||
985 | GCoords.resize(0); |
||
986 | GCoords.svgInit(); |
||
987 | QString itemTrans = itElem.attribute("ItemTransform"); |
||
988 | ScTextStream list(&itemTrans, QIODevice::ReadOnly); |
||
989 | double a, b, c, d, e, f; |
||
990 | list >> a >> b >> c >> d >> e >> f; |
||
991 | /* Adding the values directly */ |
||
992 | QTransform transformation(a, b, c, d, e, f); |
||
993 | QString itemName = itElem.attribute("Self"); |
||
994 | QString fillColor = itElem.attribute("FillColor"); |
||
995 | QString fillGradient = ""; |
||
996 | int fillGradientTyp = 6; |
||
997 | if (colorTranslate.contains(fillColor)) |
||
998 | fillColor = colorTranslate[fillColor]; |
||
999 | else |
||
1000 | { |
||
1001 | if (gradientTranslate.contains(fillColor)) |
||
1002 | { |
||
1003 | fillGradientTyp = gradientTypeMap[fillColor]; |
||
1004 | fillGradient = gradientTranslate[fillColor]; |
||
1005 | } |
||
1006 | else |
||
1007 | fillColor = def_fillColor; |
||
1008 | } |
||
1009 | QString fillGStart = itElem.attribute("GradientFillStart", QString("%1 %2").arg(def_gradientX).arg(def_gradientY)); |
||
1010 | ScTextStream Code(&fillGStart, QIODevice::ReadOnly); |
||
1011 | double gstX, gstY, gLen, gAngle; |
||
1012 | Code >> gstX >> gstY; |
||
1013 | gLen = itElem.attribute("GradientFillLength", QString("%1").arg(def_gradientLen)).toDouble(); |
||
1014 | gAngle = itElem.attribute("GradientFillAngle", QString("%1").arg(def_gradientAngle)).toDouble(); |
||
1015 | QString strokeColor = itElem.attribute("StrokeColor"); |
||
1016 | if (colorTranslate.contains(strokeColor)) |
||
1017 | strokeColor = colorTranslate[strokeColor]; |
||
1018 | else |
||
1019 | strokeColor = def_strokeColor; |
||
1020 | double lineWidth = itElem.attribute("StrokeWeight", QString("%1").arg(def_lineWidth)).toDouble(); |
||
1021 | int fillShade = itElem.attribute("FillTint", QString("%1").arg(def_fillTint)).toInt(); |
||
1022 | int strokeShade = itElem.attribute("StrokeTint", QString("%1").arg(def_strokeTint)).toInt(); |
||
1023 | QString forLayer = itElem.attribute("ItemLayer"); |
||
1024 | if (layerTranslate.contains(forLayer)) |
||
1025 | forLayer = layerTranslate[forLayer]; |
||
1026 | else |
||
1027 | forLayer = m_Doc->layerName(0); |
||
1028 | int layerNum = 0; |
||
1029 | ScLayers::iterator itend = m_Doc->Layers.end(); |
||
1030 | ScLayers::iterator it; |
||
1031 | for (it = m_Doc->Layers.begin(); it != itend; ++it) |
||
1032 | { |
||
1033 | if (it->Name == forLayer) |
||
1034 | { |
||
1035 | layerNum = it->ID; |
||
1036 | break; |
||
1037 | } |
||
1038 | } |
||
1039 | bool isOpen = false; |
||
1040 | bool isGroup = false; |
||
1041 | bool realGroup = false; |
||
1042 | bool isImage = false; |
||
1043 | if (itElem.tagName() == "Group") |
||
1044 | realGroup = true; |
||
1045 | double Opacity = def_Opacity; |
||
1046 | int blendMode = def_Blendmode; |
||
1047 | QString imageType = ""; |
||
1048 | QByteArray imageData = ""; |
||
1049 | QTransform imageTransform; |
||
1050 | for(QDomNode it = itElem.firstChild(); !it.isNull(); it = it.nextSibling() ) |
||
1051 | { |
||
1052 | QDomElement ite = it.toElement(); |
||
1053 | if (ite.tagName() == "Properties") |
||
1054 | { |
||
1055 | for(QDomNode itp = ite.firstChild(); !itp.isNull(); itp = itp.nextSibling() ) |
||
1056 | { |
||
1057 | QDomElement itpg = itp.toElement(); |
||
1058 | if (itpg.tagName() == "PathGeometry") |
||
1059 | { |
||
1060 | for(QDomNode itg = itpg.firstChild(); !itg.isNull(); itg = itg.nextSibling() ) |
||
1061 | { |
||
1062 | QDomElement itgg = itg.toElement(); |
||
1063 | if (itgg.tagName() == "GeometryPathType") |
||
1064 | { |
||
1065 | isOpen = (itgg.attribute("PathOpen") == "true" ? true : false); |
||
1066 | for(QDomNode itpp = itgg.firstChild(); !itpp.isNull(); itpp = itpp.nextSibling() ) |
||
1067 | { |
||
1068 | QDomElement itpa = itpp.toElement(); |
||
1069 | if (itpa.tagName() == "PathPointArray") |
||
1070 | { |
||
1071 | bool firstPoint = true; |
||
1072 | QPointF firstBezPoint; |
||
1073 | QPointF firstAncPoint; |
||
1074 | QList<QPointF> pointList; |
||
1075 | for(QDomNode itpap = itpa.firstChild(); !itpap.isNull(); itpap = itpap.nextSibling() ) |
||
1076 | { |
||
1077 | QDomElement itpo = itpap.toElement(); |
||
1078 | if (itpo.tagName() == "PathPointType") |
||
1079 | { |
||
1080 | double x1, y1, x2, y2, x3, y3; |
||
1081 | QString anchor = itpo.attribute("Anchor"); |
||
1082 | QString lDir = itpo.attribute("LeftDirection"); |
||
1083 | QString rDir = itpo.attribute("RightDirection"); |
||
1084 | ScTextStream an(&anchor, QIODevice::ReadOnly); |
||
1085 | an >> x1 >> y1; |
||
1086 | QPointF aP = QPointF(x1, y1); |
||
1087 | ScTextStream lr(&lDir, QIODevice::ReadOnly); |
||
1088 | lr >> x2 >> y2; |
||
1089 | QPointF lP = QPointF(x2, y2); |
||
1090 | ScTextStream rr(&rDir, QIODevice::ReadOnly); |
||
1091 | rr >> x3 >> y3; |
||
1092 | QPointF rP = QPointF(x3, y3); |
||
1093 | |||
1094 | if (firstPoint) |
||
1095 | { |
||
1096 | firstBezPoint = lP; |
||
1097 | firstAncPoint = aP; |
||
1098 | pointList.append(aP); |
||
1099 | pointList.append(rP); |
||
1100 | firstPoint = false; |
||
1101 | } |
||
1102 | else |
||
1103 | { |
||
1104 | if (itElem.tagName() == "GraphicLine") |
||
1105 | { |
||
1106 | pointList.append(lP); |
||
1107 | pointList.append(aP); |
||
1108 | } |
||
1109 | else |
||
1110 | { |
||
1111 | pointList.append(lP); |
||
1112 | pointList.append(aP); |
||
1113 | pointList.append(rP); |
||
1114 | } |
||
1115 | } |
||
1116 | } |
||
1117 | } |
||
1118 | if (itElem.tagName() == "GraphicLine") |
||
1119 | { |
||
1120 | if (pointList.count() > 1) |
||
1121 | { |
||
1122 | GCoords.svgMoveTo(pointList[0].x(), pointList[0].y()); |
||
1123 | QPointF p1 = pointList[1]; |
||
1124 | QPointF p2 = pointList[2]; |
||
1125 | QPointF p3 = pointList[3]; |
||
1126 | GCoords.svgCurveToCubic(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y()); |
||
1127 | } |
||
1128 | } |
||
1129 | else |
||
1130 | { |
||
1131 | if (isOpen) |
||
1132 | pointList.removeLast(); |
||
1133 | else |
||
1134 | { |
||
1135 | pointList.append(firstBezPoint); |
||
1136 | pointList.append(firstAncPoint); |
||
1137 | } |
||
1138 | if (pointList.count() > 1) |
||
1139 | { |
||
1140 | GCoords.svgMoveTo(pointList[0].x(), pointList[0].y()); |
||
1141 | for (int a = 1; a < pointList.count(); a += 3) |
||
1142 | { |
||
1143 | QPointF p1 = pointList[a]; |
||
1144 | QPointF p2 = pointList[a+1]; |
||
1145 | QPointF p3 = pointList[a+2]; |
||
1146 | GCoords.svgCurveToCubic(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y()); |
||
1147 | } |
||
1148 | } |
||
1149 | } |
||
1150 | } |
||
1151 | } |
||
1152 | GCoords.svgClosePath(); |
||
1153 | } |
||
1154 | } |
||
1155 | } |
||
1156 | } |
||
1157 | } |
||
1158 | else if ((ite.tagName() == "Rectangle") || (ite.tagName() == "Oval") || (ite.tagName() == "GraphicLine") || (ite.tagName() == "Polygon") || (ite.tagName() == "TextFrame") || (ite.tagName() == "Group") || (ite.tagName() == "Button")) |
||
1159 | { |
||
1160 | isGroup = true; |
||
1161 | QList<PageItem*> el = parseItemXML(ite, transformation * pTrans); |
||
1162 | for (int ec = 0; ec < el.count(); ++ec) |
||
1163 | { |
||
1164 | GElements.append(el.at(ec)); |
||
1165 | } |
||
1166 | } |
||
1167 | else if (ite.tagName() == "TransparencySetting") |
||
1168 | { |
||
1169 | for(QDomNode itp = ite.firstChild(); !itp.isNull(); itp = itp.nextSibling() ) |
||
1170 | { |
||
1171 | QDomElement itpg = itp.toElement(); |
||
1172 | if (itpg.tagName() == "BlendingSetting") |
||
1173 | { |
||
1174 | Opacity = 1.0 - (itpg.attribute("Opacity", "100").toDouble() / 100.0); |
||
1175 | blendMode = convertBlendMode(itpg.attribute("BlendMode", "Normal")); |
||
1176 | } |
||
1177 | } |
||
1178 | } |
||
1179 | else if ((ite.tagName() == "Image") || (ite.tagName() == "EPS") || (ite.tagName() == "PDF") || (ite.tagName() == "PICT")) |
||
1180 | { |
||
1181 | imageType = ite.attribute("ImageTypeName"); |
||
1182 | isImage = true; |
||
1183 | QString imageTrans = ite.attribute("ItemTransform", "1 0 0 1 0 0"); |
||
1184 | ScTextStream list(&imageTrans, QIODevice::ReadOnly); |
||
1185 | double a, b, c, d, e, f; |
||
1186 | list >> a >> b >> c >> d >> e >> f; |
||
1187 | imageTransform = QTransform(a, b, c, d, e, f); |
||
1188 | for(QDomNode itp = ite.firstChild(); !itp.isNull(); itp = itp.nextSibling() ) |
||
1189 | { |
||
1190 | QDomElement itpg = itp.toElement(); |
||
1191 | if (itpg.tagName() == "Properties") |
||
1192 | imageData = QByteArray::fromBase64(getNodeValue(itpg, "Contents").toLatin1()); |
||
1193 | } |
||
1194 | } |
||
1195 | else if (ite.tagName() == "WMF") |
||
1196 | { |
||
1197 | qDebug() << "WMF"; |
||
1198 | } |
||
1199 | else if (ite.tagName() == "ImportedPage") |
||
1200 | { |
||
1201 | qDebug() << "ImportedPage"; |
||
1202 | } |
||
1203 | } |
||
1204 | if (GCoords.size() > 0) |
||
1205 | { |
||
1206 | int z; |
||
1207 | QTransform finalMat = transformation * pTrans; |
||
1208 | double scX, scY, rot, dx, dy; |
||
1209 | getTransformValuesFromMatrix(finalMat, scX, scY, rot, dx, dy); |
||
1210 | FPoint grOffset(getMinClipF(&GCoords)); |
||
1211 | if (isGroup) |
||
1212 | { |
||
1213 | QString pre = ""; |
||
1214 | FPointArray gClip; |
||
1215 | if (!realGroup) |
||
1216 | { |
||
1217 | pre = "Group_"; |
||
1218 | if (!fillGradient.isEmpty()) |
||
1219 | fillColor = CommonStrings::None; |
||
1220 | if (itElem.tagName() == "TextFrame") |
||
1221 | { |
||
1222 | z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1223 | QString story = itElem.attribute("ParentStory"); |
||
1224 | if (!storyMap.contains(story)) |
||
1225 | { |
||
1226 | storyMap.insert(story, m_Doc->Items->at(z)); |
||
1227 | } |
||
1228 | } |
||
1229 | else if (isImage) |
||
1230 | { |
||
1231 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1232 | } |
||
1233 | else |
||
1234 | { |
||
1235 | if (isOpen) |
||
1236 | z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1237 | else |
||
1238 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1239 | } |
||
1240 | PageItem* item = m_Doc->Items->at(z); |
||
1241 | item->PoLine = GCoords.copy(); |
||
1242 | item->ClipEdited = true; |
||
1243 | item->FrameType = 3; |
||
1244 | item->setFillShade(fillShade); |
||
1245 | item->setLineShade(strokeShade); |
||
1246 | item->setFillEvenOdd(false); |
||
1247 | if (!fillGradient.isEmpty()) |
||
1248 | { |
||
1249 | QLineF gradientVector = QLineF(gstX, gstY, gstX+1, gstY); |
||
1250 | gradientVector.setLength(gLen); |
||
1251 | gradientVector.setAngle(gAngle); |
||
1252 | gradientVector.translate(-grOffset.x(), -grOffset.y()); |
||
1253 | item->setGradientVector(gradientVector.x1(), gradientVector.y1(), gradientVector.x2(), gradientVector.y2(), gradientVector.x1(), gradientVector.y1(), 1, 0); |
||
1254 | item->setGradient(fillGradient); |
||
1255 | item->setGradientType(fillGradientTyp); |
||
1256 | } |
||
1257 | FPoint wh = getMaxClipF(&item->PoLine); |
||
1258 | item->setWidthHeight(wh.x(),wh.y()); |
||
1259 | item->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1260 | m_Doc->AdjustItemSize(item); |
||
1261 | item->moveBy(dx, dy, true); |
||
1262 | item->setRotation(-rot, true); |
||
1263 | item->OldB2 = item->width(); |
||
1264 | item->OldH2 = item->height(); |
||
1265 | item->updateClip(); |
||
1266 | item->setItemName(itemName); |
||
1267 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1268 | item->setLayer(layerNum); |
||
1269 | if ((itElem.tagName() == "Rectangle") && (itElem.attribute("CornerOption") == "RoundedCorner")) |
||
1270 | { |
||
1271 | item->SetRectFrame(); |
||
1272 | item->setCornerRadius(itElem.attribute("CornerRadius", "0").toDouble()); |
||
1273 | item->SetFrameRound(); |
||
1274 | gClip = item->PoLine.copy(); |
||
1275 | } |
||
1276 | item->OwnPage = m_Doc->OnPage(item); |
||
1277 | GElements.prepend(m_Doc->Items->takeAt(z)); |
||
1278 | } |
||
1279 | z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None, true); |
||
1280 | PageItem *itemg = m_Doc->Items->at(z); |
||
1281 | itemg->PoLine = GCoords.copy(); |
||
1282 | itemg->ClipEdited = true; |
||
1283 | itemg->FrameType = 3; |
||
1284 | FPoint wh = getMaxClipF(&itemg->PoLine); |
||
1285 | itemg->setWidthHeight(wh.x(),wh.y()); |
||
1286 | itemg->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1287 | m_Doc->AdjustItemSize(itemg, true); |
||
1288 | itemg->moveBy(dx, dy, true); |
||
1289 | itemg->setRotation(-rot, true); |
||
1290 | itemg->OldB2 = itemg->width(); |
||
1291 | itemg->OldH2 = itemg->height(); |
||
1292 | if (!gClip.isEmpty()) |
||
1293 | itemg->PoLine = gClip.copy(); |
||
1294 | itemg->updateClip(); |
||
1295 | itemg->setItemName(pre+itemName); |
||
1296 | itemg->setFillTransparency(Opacity); |
||
1297 | itemg->setLineTransparency(Opacity); |
||
1298 | itemg->setLineBlendmode(blendMode); |
||
1299 | itemg->setFillBlendmode(blendMode); |
||
1300 | itemg->setFillEvenOdd(false); |
||
1301 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1302 | itemg->setLayer(layerNum); |
||
1303 | itemg->OwnPage = m_Doc->OnPage(itemg); |
||
1304 | m_Doc->Items->takeAt(z); |
||
1305 | m_Doc->groupObjectsToItem(itemg, GElements); |
||
1306 | } |
||
1307 | else |
||
1308 | { |
||
1309 | if (!fillGradient.isEmpty()) |
||
1310 | fillColor = CommonStrings::None; |
||
1311 | if (itElem.tagName() == "TextFrame") |
||
1312 | { |
||
1313 | z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1314 | QString story = itElem.attribute("ParentStory"); |
||
1315 | if (!storyMap.contains(story)) |
||
1316 | { |
||
1317 | storyMap.insert(story, m_Doc->Items->at(z)); |
||
1318 | } |
||
1319 | } |
||
1320 | else if (isImage) |
||
1321 | { |
||
1322 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1323 | } |
||
1324 | else |
||
1325 | { |
||
1326 | if (isOpen) |
||
1327 | z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1328 | else |
||
1329 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, lineWidth, fillColor, strokeColor, true); |
||
1330 | } |
||
1331 | PageItem* item = m_Doc->Items->at(z); |
||
1332 | item->PoLine = GCoords.copy(); |
||
1333 | item->ClipEdited = true; |
||
1334 | item->FrameType = 3; |
||
1335 | item->setFillShade(fillShade); |
||
1336 | item->setLineShade(strokeShade); |
||
1337 | item->setFillTransparency(Opacity); |
||
1338 | item->setLineTransparency(Opacity); |
||
1339 | item->setLineBlendmode(blendMode); |
||
1340 | item->setFillBlendmode(blendMode); |
||
1341 | item->setFillEvenOdd(false); |
||
1342 | if (!fillGradient.isEmpty()) |
||
1343 | { |
||
1344 | QLineF gradientVector = QLineF(gstX, gstY, gstX+1, gstY); |
||
1345 | gradientVector.setLength(gLen); |
||
1346 | gradientVector.setAngle(gAngle); |
||
1347 | gradientVector.translate(-grOffset.x(), -grOffset.y()); |
||
1348 | item->setGradientVector(gradientVector.x1(), gradientVector.y1(), gradientVector.x2(), gradientVector.y2(), gradientVector.x1(), gradientVector.y1(), 1, 0); |
||
1349 | item->setGradient(fillGradient); |
||
1350 | item->setGradientType(fillGradientTyp); |
||
1351 | } |
||
1352 | FPoint wh = getMaxClipF(&item->PoLine); |
||
1353 | item->setWidthHeight(wh.x(),wh.y()); |
||
1354 | item->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1355 | m_Doc->AdjustItemSize(item); |
||
1356 | item->moveBy(dx, dy, true); |
||
1357 | item->setRotation(-rot, true); |
||
1358 | item->OldB2 = item->width(); |
||
1359 | item->OldH2 = item->height(); |
||
1360 | item->updateClip(); |
||
1361 | item->setItemName(itemName); |
||
1362 | item->OwnPage = m_Doc->OnPage(item); |
||
1363 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1364 | item->setLayer(layerNum); |
||
1365 | if ((itElem.tagName() == "Rectangle") && (itElem.attribute("CornerOption") == "RoundedCorner")) |
||
1366 | { |
||
1367 | item->SetRectFrame(); |
||
1368 | item->setCornerRadius(itElem.attribute("CornerRadius", "0").toDouble()); |
||
1369 | item->SetFrameRound(); |
||
1370 | } |
||
1371 | if ((isImage) && (imageData.count() > 0)) |
||
1372 | { |
||
1373 | QString imgExt = ""; |
||
1374 | if (imageType.contains("EPS", Qt::CaseInsensitive)) |
||
1375 | imgExt = "eps"; |
||
1376 | else if (imageType.contains("GIF", Qt::CaseInsensitive)) |
||
1377 | imgExt = "gif"; |
||
1378 | else if (imageType.contains("JPEG", Qt::CaseInsensitive)) |
||
1379 | imgExt = "jpg"; |
||
1380 | else if (imageType.contains("PDF", Qt::CaseInsensitive)) |
||
1381 | imgExt = "pdf"; |
||
1382 | else if (imageType.contains("PICT", Qt::CaseInsensitive)) |
||
1383 | imgExt = "pict"; |
||
1384 | else if (imageType.contains("PNG", Qt::CaseInsensitive)) |
||
1385 | imgExt = "png"; |
||
1386 | else if (imageType.contains("PSD", Qt::CaseInsensitive)) |
||
1387 | imgExt = "psd"; |
||
1388 | else if (imageType.contains("TIFF", Qt::CaseInsensitive)) |
||
1389 | imgExt = "tif"; |
||
1390 | item->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_idml_XXXXXX." + imgExt); |
||
1391 | if (item->tempImageFile->open()) |
||
1392 | { |
||
1393 | QString fileName = getLongPathName(item->tempImageFile->fileName()); |
||
1394 | if (!fileName.isEmpty()) |
||
1395 | { |
||
1396 | double scXi, scYi, roti, dxi, dyi; |
||
1397 | getTransformValuesFromMatrix(imageTransform, scXi, scYi, roti, dxi, dyi); |
||
1398 | item->tempImageFile->write(imageData); |
||
1399 | item->tempImageFile->close(); |
||
1400 | item->isInlineImage = true; |
||
1401 | item->ScaleType = true; |
||
1402 | item->AspectRatio = true; |
||
1403 | m_Doc->loadPict(fileName, item); |
||
1404 | item->setImageXYScale(scXi / item->pixm.imgInfo.xres * 72, scYi / item->pixm.imgInfo.xres * 72); |
||
1405 | item->setImageXYOffset(0, 0); |
||
1406 | item->setImageRotation(0); |
||
1407 | } |
||
1408 | } |
||
1409 | } |
||
1410 | GElements.append(m_Doc->Items->takeAt(z)); |
||
1411 | } |
||
1412 | } |
||
1413 | else |
||
1414 | { |
||
1415 | if (GElements.count() > 0) |
||
1416 | { |
||
1417 | double minx = std::numeric_limits<double>::max(); |
||
1418 | double miny = std::numeric_limits<double>::max(); |
||
1419 | double maxx = -std::numeric_limits<double>::max(); |
||
1420 | double maxy = -std::numeric_limits<double>::max(); |
||
1421 | for (int ep = 0; ep < GElements.count(); ++ep) |
||
1422 | { |
||
1423 | PageItem* currItem = GElements.at(ep); |
||
1424 | double x1, x2, y1, y2; |
||
1425 | currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2); |
||
1426 | minx = qMin(minx, x1); |
||
1427 | miny = qMin(miny, y1); |
||
1428 | maxx = qMax(maxx, x2); |
||
1429 | maxy = qMax(maxy, y2); |
||
1430 | } |
||
1431 | double gx = minx; |
||
1432 | double gy = miny; |
||
1433 | double gw = maxx - minx; |
||
1434 | double gh = maxy - miny; |
||
1435 | int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, gx, gy, gw, gh, 0, CommonStrings::None, CommonStrings::None, true); |
||
1436 | PageItem *item = m_Doc->Items->at(z); |
||
1437 | item->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1438 | m_Doc->AdjustItemSize(item); |
||
1439 | item->OldB2 = item->width(); |
||
1440 | item->OldH2 = item->height(); |
||
1441 | item->updateClip(); |
||
1442 | item->setItemName(itemName); |
||
1443 | item->setFillTransparency(Opacity); |
||
1444 | item->setLineTransparency(Opacity); |
||
1445 | item->setLineBlendmode(blendMode); |
||
1446 | item->setFillBlendmode(blendMode); |
||
1447 | item->setFillEvenOdd(false); |
||
1448 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
1449 | item->setLayer(layerNum); |
||
1450 | item->OwnPage = m_Doc->OnPage(item); |
||
1451 | m_Doc->Items->takeAt(z); |
||
1452 | m_Doc->groupObjectsToItem(item, GElements); |
||
1453 | } |
||
1454 | } |
||
1455 | return GElements; |
||
1456 | } |
||
1457 | |||
1458 | bool IdmlPlug::parseStoryXML(const QDomElement& stElem) |
||
1459 | { |
||
1460 | QDomElement stNode; |
||
1461 | QDomDocument stMapDom; |
||
1462 | if (stElem.hasAttribute("src")) |
||
1463 | { |
||
1464 | QByteArray f2; |
||
1465 | loadRawText(fun->getFile(stElem.attribute("src")), f2); |
||
1466 | if(stMapDom.setContent(f2)) |
||
1467 | stNode = stMapDom.documentElement(); |
||
1468 | else |
||
1469 | return false; |
||
1470 | } |
||
1471 | else |
||
1472 | { |
||
1473 | if (stElem.hasChildNodes()) |
||
1474 | stNode = stElem; |
||
1475 | else |
||
1476 | return false; |
||
1477 | } |
||
1478 | for (QDomNode n = stNode.firstChild(); !n.isNull(); n = n.nextSibling() ) |
||
1479 | { |
||
1480 | QDomElement e = n.toElement(); |
||
1481 | QString storyName = e.attribute("Self"); |
||
1482 | PageItem *item = NULL; |
||
1483 | if (!storyMap.contains(storyName)) |
||
1484 | return true; |
||
1485 | item = storyMap[storyName]; |
||
1486 | if (e.tagName() == "Story") |
||
1487 | { |
||
1488 | for(QDomNode st = e.firstChild(); !st.isNull(); st = st.nextSibling() ) |
||
1489 | { |
||
1490 | QDomElement ste = st.toElement(); |
||
1491 | if (ste.tagName() == "ParagraphStyleRange") |
||
1492 | { |
||
1493 | QString pStyle = CommonStrings::DefaultParagraphStyle; |
||
1494 | if (ste.hasAttribute("AppliedParagraphStyle")) |
||
1495 | { |
||
1496 | pStyle = ste.attribute("AppliedParagraphStyle"); |
||
1497 | if (styleTranslate.contains(pStyle)) |
||
1498 | pStyle = styleTranslate[pStyle]; |
||
1499 | } |
||
1500 | ParagraphStyle newStyle; |
||
1501 | newStyle.setParent(pStyle); |
||
1502 | ParagraphStyle ttx = m_Doc->paragraphStyle(pStyle); |
||
1503 | QString fontBase = ttx.charStyle().font().family(); |
||
1504 | QString fontStyle = ttx.charStyle().font().style(); |
||
1505 | // Apply possible override of paragraph style |
||
1506 | if (ste.hasAttribute("LeftIndent")) |
||
1507 | newStyle.setLeftMargin(ste.attribute("LeftIndent", "0").toDouble()); |
||
1508 | if (ste.hasAttribute("FirstLineIndent")) |
||
1509 | newStyle.setFirstIndent(ste.attribute("FirstLineIndent", "0").toDouble()); |
||
1510 | if (ste.hasAttribute("RightIndent")) |
||
1511 | newStyle.setRightMargin(ste.attribute("RightIndent", "0").toDouble()); |
||
1512 | if (ste.hasAttribute("SpaceBefore")) |
||
1513 | newStyle.setGapBefore(ste.attribute("SpaceBefore", "0").toDouble()); |
||
1514 | if (ste.hasAttribute("SpaceAfter")) |
||
1515 | newStyle.setGapAfter(ste.attribute("SpaceAfter", "0").toDouble()); |
||
1516 | if (ste.hasAttribute("DropCapCharacters")) |
||
1517 | { |
||
1518 | newStyle.setHasDropCap(ste.attribute("DropCapCharacters", "0").toInt() != 0); |
||
1519 | if (ste.hasAttribute("DropCapLines")) |
||
1520 | newStyle.setDropCapLines(ste.attribute("DropCapLines", "2").toInt()); |
||
1521 | } |
||
1522 | if (ste.hasAttribute("Justification")) |
||
1523 | { |
||
1524 | QString align = ste.attribute("Justification", "LeftAlign"); |
||
1525 | if (align == "LeftAlign") |
||
1526 | newStyle.setAlignment(ParagraphStyle::Leftaligned); |
||
1527 | else if (align == "CenterAlign") |
||
1528 | newStyle.setAlignment(ParagraphStyle::Centered); |
||
1529 | else if (align == "RightAlign") |
||
1530 | newStyle.setAlignment(ParagraphStyle::Rightaligned); |
||
1531 | else if ((align == "LeftJustified") || (align == "CenterJustified") || (align == "RightJustified")) |
||
1532 | newStyle.setAlignment(ParagraphStyle::Justified); |
||
1533 | else if (align == "FullyJustified") |
||
1534 | newStyle.setAlignment(ParagraphStyle::Extended); |
||
1535 | } |
||
1536 | for(QDomNode stc = ste.firstChild(); !stc.isNull(); stc = stc.nextSibling() ) |
||
1537 | { |
||
1538 | QString data = ""; |
||
1539 | int posC = item->itemText.length(); |
||
1540 | QDomElement stt = stc.toElement(); |
||
1541 | if (stt.tagName() == "CharacterStyleRange") |
||
1542 | { |
||
1543 | bool hasChangedFont = false; |
||
1544 | for(QDomNode stcp = stt.firstChild(); !stcp.isNull(); stcp = stcp.nextSibling() ) |
||
1545 | { |
||
1546 | QDomElement sp = stcp.toElement(); |
||
1547 | if (sp.tagName() == "Properties") |
||
1548 | { |
||
1549 | for(QDomNode spa = sp.firstChild(); !spa.isNull(); spa = spa.nextSibling() ) |
||
1550 | { |
||
1551 | QDomElement spf = spa.toElement(); |
||
1552 | if (spf.tagName() == "AppliedFont") |
||
1553 | { |
||
1554 | fontBase = spf.text(); |
||
1555 | hasChangedFont = true; |
||
1556 | } |
||
1557 | } |
||
1558 | } |
||
1559 | } |
||
1560 | for(QDomNode stch = stt.firstChild(); !stch.isNull(); stch = stch.nextSibling() ) |
||
1561 | { |
||
1562 | QDomElement s = stch.toElement(); |
||
1563 | if (s.tagName() == "Content") |
||
1564 | { |
||
1565 | QString ch = s.text(); |
||
1566 | if (!ch.isEmpty()) |
||
1567 | data += s.text(); |
||
1568 | else |
||
1569 | data += " "; |
||
1570 | } |
||
1571 | else if (s.tagName() == "Br") |
||
1572 | data += SpecialChars::LINEBREAK; |
||
1573 | } |
||
1574 | // Apply possible override of character style |
||
1575 | CharStyle nstyle = newStyle.charStyle(); |
||
1576 | if (stt.hasAttribute("FontStyle")) |
||
1577 | { |
||
1578 | fontStyle = stt.attribute("FontStyle", ""); |
||
1579 | hasChangedFont = true; |
||
1580 | } |
||
1581 | if (hasChangedFont) |
||
1582 | { |
||
1583 | if ((!fontBase.isEmpty()) && (!fontStyle.isEmpty())) |
||
1584 | { |
||
1585 | QString fontName = constructFontName(fontBase, fontStyle); |
||
1586 | nstyle.setFont((*m_Doc->AllFonts)[fontName]); |
||
1587 | } |
||
1588 | } |
||
1589 | if (stt.hasAttribute("PointSize")) |
||
1590 | { |
||
1591 | int pointSize = qRound(stt.attribute("PointSize", "12").toDouble() * 10); |
||
1592 | if (pointSize > 0) |
||
1593 | nstyle.setFontSize(pointSize); |
||
1594 | } |
||
1595 | if (stt.hasAttribute("FillColor")) |
||
1596 | { |
||
1597 | QString fillColor = stt.attribute("FillColor"); |
||
1598 | if (colorTranslate.contains(fillColor)) |
||
1599 | nstyle.setFillColor(colorTranslate[fillColor]); |
||
1600 | } |
||
1601 | if (stt.hasAttribute("FillTint")) |
||
1602 | { |
||
1603 | int fillTint = stt.attribute("FillTint", "100").toInt(); |
||
1604 | if (fillTint != -1) |
||
1605 | nstyle.setFillShade(fillTint); |
||
1606 | } |
||
1607 | item->itemText.insertChars(posC, data); |
||
1608 | item->itemText.applyStyle(posC, newStyle); |
||
1609 | item->itemText.applyCharStyle(posC, data.length(), nstyle); |
||
1610 | } |
||
1611 | } |
||
1612 | int posT = item->itemText.length(); |
||
1613 | item->itemText.insertChars(posT, SpecialChars::PARSEP); |
||
1614 | item->itemText.applyStyle(posT, newStyle); |
||
1615 | } |
||
1616 | } |
||
1617 | } |
||
1618 | } |
||
1619 | return true; |
||
1620 | } |
||
1621 | |||
1622 | int IdmlPlug::convertBlendMode(QString blendName) |
||
1623 | { |
||
1624 | int mode = 0; |
||
1625 | if (blendName == "Normal") |
||
1626 | mode = 0; |
||
1627 | else if (blendName == "Darken") |
||
1628 | mode = 1; |
||
1629 | else if (blendName == "Lighten") |
||
1630 | mode = 2; |
||
1631 | else if (blendName == "Multiply") |
||
1632 | mode = 3; |
||
1633 | else if (blendName == "Screen") |
||
1634 | mode = 4; |
||
1635 | else if (blendName == "Overlay") |
||
1636 | mode = 5; |
||
1637 | else if (blendName == "HardLight") |
||
1638 | mode = 6; |
||
1639 | else if (blendName == "SoftLight") |
||
1640 | mode = 7; |
||
1641 | else if (blendName == "Difference") |
||
1642 | mode = 8; |
||
1643 | else if (blendName == "Exclusion") |
||
1644 | mode = 9; |
||
1645 | else if (blendName == "ColorDodge") |
||
1646 | mode = 10; |
||
1647 | else if (blendName == "ColorBurn") |
||
1648 | mode = 11; |
||
1649 | else if (blendName == "Hue") |
||
1650 | mode = 12; |
||
1651 | else if (blendName == "Saturation") |
||
1652 | mode = 13; |
||
1653 | else if (blendName == "Color") |
||
1654 | mode = 14; |
||
1655 | else if (blendName == "Luminosity") |
||
1656 | mode = 15; |
||
1657 | return mode; |
||
1658 | } |
||
1659 | |||
1660 | QString IdmlPlug::constructFontName(QString fontBaseName, QString fontStyle) |
||
1661 | { |
||
1662 | QString fontName; |
||
1663 | if ((!fontBaseName.isEmpty()) && (!fontStyle.isEmpty())) |
||
1664 | { |
||
1665 | fontName = fontBaseName + " " + fontStyle; |
||
1666 | bool found = false; |
||
1667 | QString family = fontName; |
||
1668 | SCFontsIterator it(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts); |
||
1669 | for ( ; it.hasNext(); it.next()) |
||
1670 | { |
||
1671 | if ((fontBaseName == it.current().family()) && (fontStyle == it.current().style())) |
||
1672 | found = true; |
||
1673 | } |
||
1674 | if (found) |
||
1675 | fontName = family; |
||
1676 | else |
||
1677 | { |
||
1678 | if (importerFlags & LoadSavePlugin::lfCreateThumbnail) |
||
1679 | fontName = PrefsManager::instance()->appPrefs.itemToolPrefs.textFont; |
||
1680 | else |
||
1681 | { |
||
1682 | if (!PrefsManager::instance()->appPrefs.fontPrefs.GFontSub.contains(family)) |
||
1683 | { |
||
1684 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
1685 | MissingFont *dia = new MissingFont(0, family, m_Doc); |
||
1686 | dia->exec(); |
||
1687 | fontName = dia->getReplacementFont(); |
||
1688 | delete dia; |
||
1689 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
||
1690 | PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family] = fontName; |
||
1691 | } |
||
1692 | else |
||
1693 | fontName = PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family]; |
||
1694 | } |
||
1695 | } |
||
1696 | } |
||
1697 | return fontName; |
||
1698 | } |