Rev 19734 | Rev 19831 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
13971 | jghali | 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 | #include "scribus150format.h" |
||
8 | #include "scribus150formatimpl.h" |
||
9 | |||
10 | #include "../../formatidlist.h" |
||
11 | #include "commonstrings.h" |
||
12 | #include "ui/missing.h" |
||
13 | #include "hyphenator.h" |
||
17798 | craig | 14 | #include "langmgr.h" |
17826 | craig | 15 | #include "notesstyles.h" |
13971 | jghali | 16 | #include "pageitem_latexframe.h" |
17826 | craig | 17 | #include "pageitem_noteframe.h" |
13971 | jghali | 18 | #include "prefsmanager.h" |
18906 | fschmid | 19 | #include "qtiocompressor.h" |
13971 | jghali | 20 | #include "scclocale.h" |
21 | #include "scconfig.h" |
||
22 | #include "sccolorengine.h" |
||
23 | #include "scpattern.h" |
||
24 | #include "scribuscore.h" |
||
25 | #include "scribusdoc.h" |
||
19093 | craig | 26 | |
13971 | jghali | 27 | #include "sctextstream.h" |
28 | #include "scxmlstreamreader.h" |
||
29 | #include "undomanager.h" |
||
30 | #include "units.h" |
||
31 | #include "util.h" |
||
32 | #include "util_math.h" |
||
33 | #include "util_color.h" |
||
17826 | craig | 34 | #include "util_text.h" |
13971 | jghali | 35 | #ifdef HAVE_OSG |
36 | #include "pageitem_osgframe.h" |
||
37 | #endif |
||
16863 | craig | 38 | #include "pageitem_table.h" |
16191 | fschmid | 39 | #include "pageitem_regularpolygon.h" |
16215 | fschmid | 40 | #include "pageitem_arc.h" |
16311 | fschmid | 41 | #include "pageitem_spiral.h" |
17826 | craig | 42 | #include "pagestructs.h" |
17982 | jghali | 43 | |
44 | #include <QApplication> |
||
45 | #include <QByteArray> |
||
13971 | jghali | 46 | #include <QCursor> |
47 | // #include <QDebug> |
||
48 | #include <QFileInfo> |
||
49 | #include <QList> |
||
17982 | jghali | 50 | #include <QScopedPointer> |
13971 | jghali | 51 | |
52 | // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods |
||
53 | // do. That documentatation is not duplicated here. |
||
54 | // Please don't implement the functionality of your plugin here; do that |
||
55 | // in scribus150formatimpl.h and scribus150formatimpl.cpp . |
||
56 | |||
57 | Scribus150Format::Scribus150Format() : |
||
58 | LoadSavePlugin() |
||
59 | { |
||
60 | // Set action info in languageChange, so we only have to do |
||
61 | // it in one place. This includes registering file formats. |
||
18254 | fschmid | 62 | registerFormats(); |
13971 | jghali | 63 | languageChange(); |
64 | } |
||
65 | |||
66 | Scribus150Format::~Scribus150Format() |
||
67 | { |
||
68 | unregisterAll(); |
||
18254 | fschmid | 69 | } |
13971 | jghali | 70 | |
71 | void Scribus150Format::languageChange() |
||
72 | { |
||
18254 | fschmid | 73 | FileFormat* fmt = getFormatByID(FORMATID_SLA150IMPORT); |
74 | fmt->trName = tr("Scribus 1.5.0+ Document"); |
||
75 | fmt->filter = fmt->trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)"; |
||
13971 | jghali | 76 | } |
77 | |||
78 | const QString Scribus150Format::fullTrName() const |
||
79 | { |
||
16105 | fschmid | 80 | return QObject::tr("Scribus 1.5.0+ Support"); |
13971 | jghali | 81 | } |
82 | |||
83 | const ScActionPlugin::AboutData* Scribus150Format::getAboutData() const |
||
84 | { |
||
85 | AboutData* about = new AboutData; |
||
86 | Q_CHECK_PTR(about); |
||
87 | about->authors = QString::fromUtf8( |
||
88 | "Franz Schmid <franz@scribus.info>, " |
||
89 | "The Scribus Team"); |
||
16105 | fschmid | 90 | about->shortDescription = tr("Scribus 1.5.0+ File Format Support"); |
91 | about->description = tr("Allows Scribus to read Scribus 1.5.0 and higher formatted files."); |
||
13971 | jghali | 92 | // about->version |
93 | // about->releaseDate |
||
94 | // about->copyright |
||
95 | about->license = "GPL"; |
||
96 | return about; |
||
97 | } |
||
98 | |||
99 | void Scribus150Format::deleteAboutData(const AboutData* about) const |
||
100 | { |
||
101 | Q_ASSERT(about); |
||
102 | delete about; |
||
103 | } |
||
104 | |||
105 | void Scribus150Format::registerFormats() |
||
106 | { |
||
107 | FileFormat fmt(this); |
||
108 | fmt.trName = tr("Scribus 1.5.0+ Document"); |
||
109 | fmt.formatId = FORMATID_SLA150IMPORT; |
||
110 | fmt.load = true; |
||
111 | fmt.save = true; |
||
14792 | fschmid | 112 | fmt.colorReading = true; |
13971 | jghali | 113 | fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)"; |
114 | fmt.mimeTypes = QStringList(); |
||
115 | fmt.mimeTypes.append("application/x-scribus"); |
||
14792 | fschmid | 116 | fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz"; |
13971 | jghali | 117 | fmt.priority = 64; |
118 | registerFormat(fmt); |
||
119 | } |
||
120 | |||
121 | bool Scribus150Format::fileSupported(QIODevice* /* file */, const QString & fileName) const |
||
122 | { |
||
123 | QByteArray docBytes(""); |
||
124 | if(fileName.right(2) == "gz") |
||
125 | { |
||
18906 | fschmid | 126 | QFile file(fileName); |
127 | QtIOCompressor compressor(&file); |
||
128 | compressor.setStreamFormat(QtIOCompressor::GzipFormat); |
||
129 | compressor.open(QIODevice::ReadOnly); |
||
130 | docBytes = compressor.read(1024); |
||
131 | compressor.close(); |
||
132 | if (docBytes.isEmpty()) |
||
13971 | jghali | 133 | return false; |
134 | } |
||
135 | else |
||
136 | { |
||
137 | // Not gzip encoded, just load it |
||
138 | loadRawText(fileName, docBytes); |
||
139 | } |
||
16105 | fschmid | 140 | QRegExp regExp150("Version=\"1.5.[0-9]"); |
13971 | jghali | 141 | int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW "); |
16105 | fschmid | 142 | if (startElemPos >= 0) |
143 | { |
||
144 | bool is150 = ( regExp150.indexIn(docBytes.mid(startElemPos, 64)) >= 0 ); |
||
145 | return is150; |
||
146 | } |
||
147 | return false; |
||
13971 | jghali | 148 | } |
149 | |||
17982 | jghali | 150 | QIODevice* Scribus150Format::slaReader(const QString & fileName) |
13971 | jghali | 151 | { |
17982 | jghali | 152 | if (!fileSupported(0, fileName)) |
153 | return NULL; |
||
154 | |||
155 | QIODevice* ioDevice = 0; |
||
13971 | jghali | 156 | if(fileName.right(2) == "gz") |
157 | { |
||
18906 | fschmid | 158 | aFile.setFileName(fileName); |
159 | QtIOCompressor *compressor = new QtIOCompressor(&aFile); |
||
160 | compressor->setStreamFormat(QtIOCompressor::GzipFormat); |
||
161 | if (!compressor->open(QIODevice::ReadOnly)) |
||
13971 | jghali | 162 | { |
18906 | fschmid | 163 | delete compressor; |
17982 | jghali | 164 | return NULL; |
13971 | jghali | 165 | } |
18906 | fschmid | 166 | ioDevice = compressor; |
13971 | jghali | 167 | } |
168 | else |
||
169 | { |
||
17982 | jghali | 170 | ioDevice = new QFile(fileName); |
171 | if (!ioDevice->open(QIODevice::ReadOnly)) |
||
172 | { |
||
173 | delete ioDevice; |
||
174 | return NULL; |
||
175 | } |
||
13971 | jghali | 176 | } |
17982 | jghali | 177 | return ioDevice; |
13971 | jghali | 178 | } |
179 | |||
180 | void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces) |
||
181 | { |
||
182 | getNewReplacement=false; |
||
183 | getReplacedFonts.clear(); |
||
184 | } |
||
185 | |||
16105 | fschmid | 186 | bool Scribus150Format::loadElements(const QString & data, QString fileDir, int toLayer, double Xp_in, double Yp_in, bool loc) |
187 | { |
||
188 | ParagraphStyle vg; |
||
16943 | fschmid | 189 | isNewFormat = false; |
16105 | fschmid | 190 | LayerToPaste = toLayer; |
191 | Xp = Xp_in; |
||
192 | Yp = Yp_in; |
||
18477 | fschmid | 193 | GrX = 0.0; |
194 | GrY = 0.0; |
||
16105 | fschmid | 195 | |
16943 | fschmid | 196 | QMap<int,PageItem*> TableID; |
197 | QMap<int,PageItem*> TableIDM; |
||
198 | QMap<int,PageItem*> TableIDF; |
||
16105 | fschmid | 199 | QList<PageItem*> TableItems; |
200 | QList<PageItem*> TableItemsM; |
||
201 | QList<PageItem*> TableItemsF; |
||
16931 | fschmid | 202 | QMap<int,PageItem*> WeldID; |
16926 | fschmid | 203 | QList<PageItem*> WeldItems; |
16105 | fschmid | 204 | QStack< QList<PageItem*> > groupStack; |
205 | QStack< QList<PageItem*> > groupStackF; |
||
206 | QStack< QList<PageItem*> > groupStackM; |
||
207 | QStack< QList<PageItem*> > groupStackP; |
||
208 | QStack<int> groupStack2; |
||
209 | |||
210 | itemRemap.clear(); |
||
211 | itemNext.clear(); |
||
212 | itemCount = 0; |
||
213 | itemRemapM.clear(); |
||
214 | itemNextM.clear(); |
||
215 | itemCountM = 0; |
||
216 | itemRemapF.clear(); |
||
217 | itemNextF.clear(); |
||
218 | |||
19742 | jghali | 219 | FrameItems.clear(); |
16105 | fschmid | 220 | TableItems.clear(); |
221 | TableID.clear(); |
||
222 | TableItemsM.clear(); |
||
223 | TableIDM.clear(); |
||
224 | TableItemsF.clear(); |
||
225 | TableIDF.clear(); |
||
16926 | fschmid | 226 | WeldItems.clear(); |
227 | WeldID.clear(); |
||
16105 | fschmid | 228 | |
229 | bool firstElement = true; |
||
230 | bool success = true; |
||
231 | |||
232 | ScXmlStreamReader reader(data); |
||
233 | ScXmlStreamAttributes attrs; |
||
234 | while(!reader.atEnd() && !reader.hasError()) |
||
235 | { |
||
236 | QXmlStreamReader::TokenType tType = reader.readNext(); |
||
237 | if (tType != QXmlStreamReader::StartElement) |
||
238 | continue; |
||
239 | QStringRef tagName = reader.name(); |
||
240 | attrs = reader.scAttributes(); |
||
241 | |||
242 | if (firstElement) |
||
243 | { |
||
244 | if (tagName == "SCRIBUSELEM" || tagName == "SCRIBUSELEMUTF8") |
||
245 | { |
||
246 | if (!loc) |
||
247 | { |
||
248 | GrX = attrs.valueAsDouble("XP"); |
||
249 | GrY = attrs.valueAsDouble("YP"); |
||
250 | } |
||
251 | } |
||
252 | else |
||
253 | { |
||
254 | success = false; |
||
255 | break; |
||
256 | } |
||
257 | firstElement = false; |
||
258 | } |
||
259 | // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file... |
||
260 | if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None) |
||
261 | { |
||
262 | success = readColor(m_Doc->PageColors, attrs); |
||
263 | if (!success) break; |
||
264 | } |
||
265 | if (tagName == "Gradient") |
||
266 | { |
||
267 | VGradient gra; |
||
268 | QString grName = attrs.valueAsString("Name"); |
||
269 | success = readGradient(m_Doc, gra, reader); |
||
19103 | fschmid | 270 | if (!success) |
271 | break; |
||
272 | gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad))); |
||
16105 | fschmid | 273 | if (!grName.isEmpty()) |
274 | { |
||
275 | m_Doc->docGradients.insert(grName, gra); |
||
276 | } |
||
277 | } |
||
278 | if (tagName == "STYLE") |
||
279 | { |
||
16531 | jghali | 280 | readParagraphStyle(m_Doc, reader, vg); |
16105 | fschmid | 281 | StyleSet<ParagraphStyle>tmp; |
282 | tmp.create(vg); |
||
283 | m_Doc->redefineStyles(tmp, false); |
||
284 | } |
||
285 | if (tagName == "CHARSTYLE") |
||
286 | { |
||
19544 | jghali | 287 | CharStyle cstyle; |
16105 | fschmid | 288 | StyleSet<CharStyle> temp; |
19544 | jghali | 289 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
290 | readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle); |
||
291 | temp.create(cstyle); |
||
16105 | fschmid | 292 | m_Doc->redefineCharStyles(temp, false); |
293 | } |
||
17318 | fschmid | 294 | if (tagName == "TableStyle") |
295 | { |
||
296 | TableStyle tstyle; |
||
297 | readTableStyle(m_Doc, reader, tstyle); |
||
298 | StyleSet<TableStyle> temp; |
||
299 | temp.create(tstyle); |
||
300 | m_Doc->redefineTableStyles(temp, false); |
||
301 | } |
||
302 | if (tagName == "CellStyle") |
||
303 | { |
||
304 | CellStyle tstyle; |
||
305 | readCellStyle(m_Doc, reader, tstyle); |
||
306 | StyleSet<CellStyle> temp; |
||
307 | temp.create(tstyle); |
||
308 | m_Doc->redefineCellStyles(temp, false); |
||
309 | } |
||
16105 | fschmid | 310 | if (tagName == "Arrows") |
311 | { |
||
312 | success = readArrows(m_Doc, attrs); |
||
313 | if (!success) break; |
||
314 | } |
||
315 | if (tagName == "MultiLine") |
||
316 | { |
||
317 | multiLine ml; |
||
318 | QString mlName = attrs.valueAsString("Name"); |
||
319 | success = readMultiline(ml, reader); |
||
320 | if (!success) break; |
||
321 | if (!mlName.isEmpty()) |
||
322 | { |
||
323 | m_Doc->MLineStyles.insert(mlName, ml); |
||
324 | } |
||
325 | } |
||
17147 | fschmid | 326 | if ((tagName == "ITEM") || (tagName == "FRAMEOBJECT")) |
16105 | fschmid | 327 | { |
328 | ItemInfo itemInfo; |
||
329 | success = readObject(m_Doc, reader, itemInfo, fileDir, true); |
||
330 | if (!success) |
||
331 | break; |
||
16943 | fschmid | 332 | if (isNewFormat) |
16105 | fschmid | 333 | { |
334 | if (itemInfo.nextItem != -1) |
||
16943 | fschmid | 335 | itemNext[itemInfo.itemID] = itemInfo.nextItem; |
336 | if (itemInfo.item->isTableItem) |
||
337 | TableItems.append(itemInfo.item); |
||
338 | if (itemInfo.isWeldFlag) |
||
339 | WeldItems.append(itemInfo.item); |
||
16105 | fschmid | 340 | } |
16943 | fschmid | 341 | else |
16105 | fschmid | 342 | { |
16943 | fschmid | 343 | // first of linked chain? |
16105 | fschmid | 344 | if (tagName == "ITEM") |
345 | { |
||
16943 | fschmid | 346 | if (itemInfo.nextItem != -1) |
347 | itemNext[itemInfo.ownNr] = itemInfo.nextItem; |
||
16105 | fschmid | 348 | } |
16943 | fschmid | 349 | if (itemInfo.item->isTableItem) |
16926 | fschmid | 350 | { |
16943 | fschmid | 351 | if (tagName == "ITEM") |
352 | { |
||
353 | TableItems.append(itemInfo.item); |
||
354 | TableID.insert(itemInfo.ownLink, itemInfo.item); |
||
355 | } |
||
16926 | fschmid | 356 | } |
16943 | fschmid | 357 | if (itemInfo.isWeldFlag) |
358 | { |
||
359 | if (tagName == "ITEM") |
||
360 | { |
||
361 | WeldItems.append(itemInfo.item); |
||
362 | WeldID.insert(itemInfo.ownWeld, itemInfo.item); |
||
363 | } |
||
364 | } |
||
16926 | fschmid | 365 | } |
16105 | fschmid | 366 | if (groupStack.count() > 0) |
367 | { |
||
368 | groupStack.top().append(itemInfo.item); |
||
16943 | fschmid | 369 | while (static_cast<int>(itemInfo.ownNr) == groupStack2.top()) |
16105 | fschmid | 370 | { |
371 | if ((tagName == "PAGEOBJECT") || (tagName == "ITEM")) |
||
372 | groupStackP.push(groupStack.pop()); |
||
373 | else if (tagName == "FRAMEOBJECT") |
||
374 | groupStackF.push(groupStack.pop()); |
||
375 | else |
||
376 | groupStackM.push(groupStack.pop()); |
||
377 | groupStack2.pop(); |
||
16233 | fschmid | 378 | if (groupStack2.count() == 0) |
379 | break; |
||
16105 | fschmid | 380 | } |
381 | } |
||
16113 | fschmid | 382 | if (itemInfo.isGroupFlag) |
16105 | fschmid | 383 | { |
384 | QList<PageItem*> GroupItems; |
||
385 | GroupItems.append(itemInfo.item); |
||
386 | groupStack.push(GroupItems); |
||
16943 | fschmid | 387 | groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr); |
16105 | fschmid | 388 | } |
389 | } |
||
390 | if (tagName == "Pattern") |
||
391 | { |
||
392 | success = readPattern(m_Doc, reader, fileDir); |
||
393 | if (!success) break; |
||
394 | } |
||
17826 | craig | 395 | if (tagName == "NotesStyles") |
396 | { |
||
397 | success = readNotesStyles(m_Doc, reader); |
||
398 | if (!success) break; |
||
399 | } |
||
400 | if (tagName == "NotesFrames") |
||
401 | { |
||
402 | success = readNotesFrames(reader); |
||
403 | if (!success) break; |
||
404 | } |
||
405 | if (tagName == "Notes") |
||
406 | { |
||
407 | success = readNotes(m_Doc, reader); |
||
408 | if (!success) break; |
||
409 | } |
||
410 | if (tagName == "Marks") |
||
411 | { |
||
412 | success = readMarks(m_Doc, reader); |
||
413 | if (!success) break; |
||
414 | } |
||
16105 | fschmid | 415 | } |
416 | if (reader.hasError()) |
||
417 | { |
||
418 | setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber()); |
||
419 | return false; |
||
420 | } |
||
16943 | fschmid | 421 | if (isNewFormat) |
16105 | fschmid | 422 | { |
16943 | fschmid | 423 | if (TableItems.count() != 0) |
16105 | fschmid | 424 | { |
16943 | fschmid | 425 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
426 | { |
||
427 | PageItem* ta = TableItems.at(ttc); |
||
428 | if (ta->TopLinkID != -1) |
||
429 | ta->TopLink = LinkID[ta->TopLinkID]; |
||
430 | else |
||
431 | ta->TopLink = 0; |
||
432 | if (ta->LeftLinkID != -1) |
||
433 | ta->LeftLink = LinkID[ta->LeftLinkID]; |
||
434 | else |
||
435 | ta->LeftLink = 0; |
||
436 | if (ta->RightLinkID != -1) |
||
437 | ta->RightLink = LinkID[ta->RightLinkID]; |
||
438 | else |
||
439 | ta->RightLink = 0; |
||
440 | if (ta->BottomLinkID != -1) |
||
441 | ta->BottomLink = LinkID[ta->BottomLinkID]; |
||
442 | else |
||
443 | ta->BottomLink = 0; |
||
444 | } |
||
16105 | fschmid | 445 | } |
16943 | fschmid | 446 | if (WeldItems.count() != 0) |
16105 | fschmid | 447 | { |
16943 | fschmid | 448 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
449 | { |
||
450 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 451 | for (int i = 0; i < ta->weldList.count(); ++i) |
16943 | fschmid | 452 | { |
453 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
||
17745 | jghali | 454 | ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0); |
455 | if (ta->weldList[i].weldItem == NULL) |
||
456 | ta->weldList.removeAt(i--); |
||
16943 | fschmid | 457 | } |
458 | } |
||
16105 | fschmid | 459 | } |
16943 | fschmid | 460 | if (itemNext.count() != 0) |
16105 | fschmid | 461 | { |
16943 | fschmid | 462 | QMap<int,int>::Iterator lc; |
463 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
464 | { |
||
465 | if (lc.value() >= 0) |
||
466 | { |
||
467 | PageItem * Its = LinkID[lc.key()]; |
||
468 | PageItem * Itn = LinkID[lc.value()]; |
||
469 | if (!Its->testLinkCandidate(Itn)) |
||
470 | { |
||
471 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
472 | continue; |
||
473 | } |
||
474 | Its->link(Itn); |
||
475 | } |
||
476 | } |
||
16105 | fschmid | 477 | } |
478 | } |
||
16943 | fschmid | 479 | else |
16926 | fschmid | 480 | { |
16943 | fschmid | 481 | if (TableItemsF.count() != 0) |
16926 | fschmid | 482 | { |
16943 | fschmid | 483 | for (int ttc = 0; ttc < TableItemsF.count(); ++ttc) |
16926 | fschmid | 484 | { |
16943 | fschmid | 485 | PageItem* ta = TableItemsF.at(ttc); |
486 | if (ta->TopLinkID != -1) |
||
487 | ta->TopLink = TableIDF[ta->TopLinkID]; |
||
488 | else |
||
489 | ta->TopLink = 0; |
||
490 | if (ta->LeftLinkID != -1) |
||
491 | ta->LeftLink = TableIDF[ta->LeftLinkID]; |
||
492 | else |
||
493 | ta->LeftLink = 0; |
||
494 | if (ta->RightLinkID != -1) |
||
495 | ta->RightLink = TableIDF[ta->RightLinkID]; |
||
496 | else |
||
497 | ta->RightLink = 0; |
||
498 | if (ta->BottomLinkID != -1) |
||
499 | ta->BottomLink = TableIDF[ta->BottomLinkID]; |
||
500 | else |
||
501 | ta->BottomLink = 0; |
||
16926 | fschmid | 502 | } |
503 | } |
||
16943 | fschmid | 504 | if (TableItemsM.count() != 0) |
16105 | fschmid | 505 | { |
16943 | fschmid | 506 | for (int ttc = 0; ttc < TableItemsM.count(); ++ttc) |
16105 | fschmid | 507 | { |
16943 | fschmid | 508 | PageItem* ta = TableItemsM.at(ttc); |
509 | if (ta->TopLinkID != -1) |
||
510 | ta->TopLink = TableIDM[ta->TopLinkID]; |
||
511 | else |
||
512 | ta->TopLink = 0; |
||
513 | if (ta->LeftLinkID != -1) |
||
514 | ta->LeftLink = TableIDM[ta->LeftLinkID]; |
||
515 | else |
||
516 | ta->LeftLink = 0; |
||
517 | if (ta->RightLinkID != -1) |
||
518 | ta->RightLink = TableIDM[ta->RightLinkID]; |
||
519 | else |
||
520 | ta->RightLink = 0; |
||
521 | if (ta->BottomLinkID != -1) |
||
522 | ta->BottomLink = TableIDM[ta->BottomLinkID]; |
||
523 | else |
||
524 | ta->BottomLink = 0; |
||
525 | } |
||
526 | } |
||
527 | if (TableItems.count() != 0) |
||
528 | { |
||
529 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
||
530 | { |
||
531 | PageItem* ta = TableItems.at(ttc); |
||
532 | if (ta->TopLinkID != -1) |
||
533 | ta->TopLink = TableID[ta->TopLinkID]; |
||
534 | else |
||
535 | ta->TopLink = 0; |
||
536 | if (ta->LeftLinkID != -1) |
||
537 | ta->LeftLink = TableID[ta->LeftLinkID]; |
||
538 | else |
||
539 | ta->LeftLink = 0; |
||
540 | if (ta->RightLinkID != -1) |
||
541 | ta->RightLink = TableID[ta->RightLinkID]; |
||
542 | else |
||
543 | ta->RightLink = 0; |
||
544 | if (ta->BottomLinkID != -1) |
||
545 | ta->BottomLink = TableID[ta->BottomLinkID]; |
||
546 | else |
||
547 | ta->BottomLink = 0; |
||
548 | } |
||
549 | } |
||
550 | if (WeldItems.count() != 0) |
||
551 | { |
||
552 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
||
553 | { |
||
554 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 555 | for (int i = 0 ; i < ta->weldList.count(); ++i) |
16105 | fschmid | 556 | { |
16943 | fschmid | 557 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
17745 | jghali | 558 | ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0); |
559 | if (ta->weldList[i].weldItem == NULL) |
||
560 | ta->weldList.removeAt(i--); |
||
16105 | fschmid | 561 | } |
562 | } |
||
563 | } |
||
16943 | fschmid | 564 | // reestablish textframe links |
565 | if (itemNext.count() != 0) |
||
566 | { |
||
567 | QMap<int,int>::Iterator lc; |
||
568 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
569 | { |
||
570 | if (lc.value() >= 0) |
||
571 | { |
||
572 | PageItem * Its = m_Doc->DocItems.at(lc.key()); |
||
573 | PageItem * Itn = m_Doc->DocItems.at(lc.value()); |
||
574 | if (!Its->testLinkCandidate(Itn)) |
||
575 | { |
||
576 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
577 | continue; |
||
578 | } |
||
579 | Its->link(Itn); |
||
580 | } |
||
581 | } |
||
582 | } |
||
16105 | fschmid | 583 | } |
584 | if (groupStackP.count() > 0) |
||
585 | { |
||
586 | while (groupStackP.count() > 0) |
||
587 | { |
||
17417 | fschmid | 588 | bool isTableIt = false; |
16105 | fschmid | 589 | QList<PageItem*> gpL = groupStackP.pop(); |
590 | PageItem* gItem = gpL.takeFirst(); |
||
591 | for (int id = 0; id < gpL.count(); id++) |
||
592 | { |
||
593 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 594 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 595 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
596 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 597 | cItem->Parent = gItem; |
16105 | fschmid | 598 | if (gItem->rotation() != 0) |
599 | { |
||
600 | QTransform ma; |
||
601 | ma.rotate(-gItem->rotation()); |
||
602 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
603 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
604 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
605 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
606 | } |
||
607 | m_Doc->DocItems.removeOne(cItem); |
||
608 | } |
||
18282 | jghali | 609 | bool converted = false; |
17417 | fschmid | 610 | if (isTableIt) |
18282 | jghali | 611 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems); |
612 | if (!converted) |
||
17417 | fschmid | 613 | gItem->groupItemList = gpL; |
16105 | fschmid | 614 | } |
615 | } |
||
616 | if (groupStackF.count() > 0) |
||
617 | { |
||
618 | while (groupStackF.count() > 0) |
||
619 | { |
||
17417 | fschmid | 620 | bool isTableIt = false; |
16105 | fschmid | 621 | QList<PageItem*> gpL = groupStackF.pop(); |
622 | PageItem* gItem = gpL.takeFirst(); |
||
623 | for (int id = 0; id < gpL.count(); id++) |
||
624 | { |
||
625 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 626 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 627 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
628 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 629 | cItem->Parent = gItem; |
16105 | fschmid | 630 | if (gItem->rotation() != 0) |
631 | { |
||
632 | QTransform ma; |
||
633 | ma.rotate(-gItem->rotation()); |
||
634 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
635 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
636 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
637 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
638 | } |
||
17407 | fschmid | 639 | m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem)); |
16105 | fschmid | 640 | } |
18282 | jghali | 641 | bool converted = false; |
17417 | fschmid | 642 | if (isTableIt) |
18282 | jghali | 643 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL); |
644 | if (!converted) |
||
17417 | fschmid | 645 | gItem->groupItemList = gpL; |
16105 | fschmid | 646 | } |
647 | } |
||
648 | if (groupStackM.count() > 0) |
||
649 | { |
||
650 | while (groupStackM.count() > 0) |
||
651 | { |
||
17417 | fschmid | 652 | bool isTableIt = false; |
16105 | fschmid | 653 | QList<PageItem*> gpL = groupStackM.pop(); |
654 | PageItem* gItem = gpL.takeFirst(); |
||
655 | for (int id = 0; id < gpL.count(); id++) |
||
656 | { |
||
657 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 658 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 659 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
660 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 661 | cItem->Parent = gItem; |
16105 | fschmid | 662 | if (gItem->rotation() != 0) |
663 | { |
||
664 | QTransform ma; |
||
665 | ma.rotate(-gItem->rotation()); |
||
666 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
667 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
668 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
669 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
670 | } |
||
671 | m_Doc->MasterItems.removeOne(cItem); |
||
672 | } |
||
18282 | jghali | 673 | bool converted = false; |
17417 | fschmid | 674 | if (isTableIt) |
18282 | jghali | 675 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems); |
676 | if (!converted) |
||
17417 | fschmid | 677 | gItem->groupItemList = gpL; |
16105 | fschmid | 678 | } |
679 | } |
||
680 | return true; |
||
681 | } |
||
682 | |||
16016 | fschmid | 683 | bool Scribus150Format::loadPalette(const QString & fileName) |
684 | { |
||
685 | if (m_Doc==0 || m_AvailableFonts==0) |
||
686 | { |
||
687 | Q_ASSERT(m_Doc==0 || m_AvailableFonts==0); |
||
688 | return false; |
||
689 | } |
||
690 | ParagraphStyle vg; |
||
16105 | fschmid | 691 | Xp = 0.0; |
692 | Yp = 0.0; |
||
693 | GrX = 0.0; |
||
694 | GrY = 0.0; |
||
16943 | fschmid | 695 | isNewFormat = false; |
16016 | fschmid | 696 | |
16943 | fschmid | 697 | QMap<int,PageItem*> TableID; |
698 | QMap<int,PageItem*> TableIDM; |
||
699 | QMap<int,PageItem*> TableIDF; |
||
16016 | fschmid | 700 | QList<PageItem*> TableItems; |
701 | QList<PageItem*> TableItemsM; |
||
702 | QList<PageItem*> TableItemsF; |
||
16931 | fschmid | 703 | QMap<int,PageItem*> WeldID; |
16926 | fschmid | 704 | QList<PageItem*> WeldItems; |
16105 | fschmid | 705 | QStack< QList<PageItem*> > groupStack; |
706 | QStack< QList<PageItem*> > groupStackF; |
||
707 | QStack< QList<PageItem*> > groupStackM; |
||
708 | QStack< QList<PageItem*> > groupStackP; |
||
709 | QStack<int> groupStack2; |
||
19104 | jghali | 710 | |
16016 | fschmid | 711 | QByteArray docBytes(""); |
712 | loadRawText(fileName, docBytes); |
||
713 | QString f = QString::fromUtf8(docBytes); |
||
714 | if (f.isEmpty()) |
||
715 | { |
||
716 | setFileReadError(); |
||
717 | return false; |
||
718 | } |
||
719 | QString fileDir = QFileInfo(fileName).absolutePath(); |
||
19104 | jghali | 720 | |
16016 | fschmid | 721 | if (m_mwProgressBar!=0) |
722 | { |
||
723 | m_mwProgressBar->setMaximum(f.length()); |
||
724 | m_mwProgressBar->setValue(0); |
||
725 | } |
||
19104 | jghali | 726 | |
16016 | fschmid | 727 | itemRemap.clear(); |
728 | itemNext.clear(); |
||
729 | itemCount = 0; |
||
730 | itemRemapM.clear(); |
||
731 | itemNextM.clear(); |
||
732 | itemCountM = 0; |
||
733 | itemRemapF.clear(); |
||
734 | itemNextF.clear(); |
||
735 | |||
736 | TableItems.clear(); |
||
737 | TableID.clear(); |
||
738 | TableItemsM.clear(); |
||
739 | TableIDM.clear(); |
||
740 | TableItemsF.clear(); |
||
741 | TableIDF.clear(); |
||
16926 | fschmid | 742 | WeldItems.clear(); |
16016 | fschmid | 743 | |
744 | m_Doc->GroupCounter = 1; |
||
745 | m_Doc->LastAuto = 0; |
||
16147 | fschmid | 746 | // m_Doc->PageColors.clear(); |
747 | // m_Doc->Layers.clear(); |
||
16016 | fschmid | 748 | |
749 | bool firstElement = true; |
||
750 | bool success = true; |
||
751 | int progress = 0; |
||
752 | |||
753 | ScXmlStreamReader reader(f); |
||
754 | ScXmlStreamAttributes attrs; |
||
755 | while(!reader.atEnd() && !reader.hasError()) |
||
756 | { |
||
757 | QXmlStreamReader::TokenType tType = reader.readNext(); |
||
758 | if (tType != QXmlStreamReader::StartElement) |
||
759 | continue; |
||
760 | QStringRef tagName = reader.name(); |
||
761 | attrs = reader.scAttributes(); |
||
762 | |||
763 | if (m_mwProgressBar != 0) |
||
764 | { |
||
765 | int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100); |
||
766 | if (newProgress != progress) |
||
767 | { |
||
768 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
769 | progress = newProgress; |
||
770 | } |
||
771 | } |
||
772 | |||
773 | if (firstElement) |
||
774 | { |
||
775 | if (tagName != "SCRIBUSCOLORS") |
||
776 | { |
||
777 | success = false; |
||
778 | break; |
||
779 | } |
||
780 | firstElement = false; |
||
781 | } |
||
782 | // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file... |
||
783 | if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None) |
||
784 | { |
||
785 | success = readColor(m_Doc->PageColors, attrs); |
||
786 | if (!success) break; |
||
787 | } |
||
788 | if (tagName == "Gradient") |
||
789 | { |
||
790 | VGradient gra; |
||
791 | QString grName = attrs.valueAsString("Name"); |
||
792 | success = readGradient(m_Doc, gra, reader); |
||
19103 | fschmid | 793 | if (!success) |
794 | break; |
||
795 | gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad))); |
||
16016 | fschmid | 796 | if (!grName.isEmpty()) |
797 | { |
||
798 | m_Doc->docGradients.insert(grName, gra); |
||
799 | } |
||
800 | } |
||
801 | if (tagName == "Arrows") |
||
802 | { |
||
803 | success = readArrows(m_Doc, attrs); |
||
804 | if (!success) break; |
||
805 | } |
||
806 | if (tagName == "MultiLine") |
||
807 | { |
||
808 | multiLine ml; |
||
809 | QString mlName = attrs.valueAsString("Name"); |
||
810 | success = readMultiline(ml, reader); |
||
811 | if (!success) break; |
||
812 | if (!mlName.isEmpty()) |
||
813 | { |
||
814 | m_Doc->MLineStyles.insert(mlName, ml); |
||
815 | } |
||
816 | } |
||
817 | if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT") |
||
818 | { |
||
819 | ItemInfo itemInfo; |
||
820 | success = readObject(m_Doc, reader, itemInfo, fileDir, false); |
||
821 | if (!success) break; |
||
822 | |||
16943 | fschmid | 823 | if (isNewFormat) |
16016 | fschmid | 824 | { |
825 | if (itemInfo.nextItem != -1) |
||
16943 | fschmid | 826 | itemNext[itemInfo.itemID] = itemInfo.nextItem; |
827 | if (itemInfo.item->isTableItem) |
||
828 | TableItems.append(itemInfo.item); |
||
829 | if (itemInfo.isWeldFlag) |
||
830 | WeldItems.append(itemInfo.item); |
||
16016 | fschmid | 831 | } |
16943 | fschmid | 832 | else |
16016 | fschmid | 833 | { |
16943 | fschmid | 834 | // first of linked chain? |
16016 | fschmid | 835 | if (tagName == "PAGEOBJECT") |
836 | { |
||
16943 | fschmid | 837 | if (itemInfo.nextItem != -1) |
838 | itemNext[itemInfo.ownNr] = itemInfo.nextItem; |
||
16016 | fschmid | 839 | } |
16943 | fschmid | 840 | else if (tagName == "MASTEROBJECT") |
16016 | fschmid | 841 | { |
16943 | fschmid | 842 | if (itemInfo.nextItem != -1) |
843 | itemNextM[itemInfo.ownNr] = itemInfo.nextItem; |
||
16016 | fschmid | 844 | } |
16943 | fschmid | 845 | if (itemInfo.item->isTableItem) |
16016 | fschmid | 846 | { |
16943 | fschmid | 847 | if (tagName == "PAGEOBJECT") |
848 | { |
||
849 | TableItems.append(itemInfo.item); |
||
850 | TableID.insert(itemInfo.ownLink, itemInfo.item); |
||
851 | } |
||
852 | else if (tagName == "FRAMEOBJECT") |
||
853 | { |
||
854 | TableItemsF.append(itemInfo.item); |
||
855 | TableIDF.insert(itemInfo.ownLink, itemInfo.item); |
||
856 | } |
||
857 | else |
||
858 | { |
||
859 | TableItemsM.append(itemInfo.item); |
||
860 | TableIDM.insert(itemInfo.ownLink, itemInfo.item); |
||
861 | } |
||
16016 | fschmid | 862 | } |
16943 | fschmid | 863 | if (itemInfo.isWeldFlag) |
864 | { |
||
865 | WeldItems.append(itemInfo.item); |
||
866 | WeldID.insert(itemInfo.ownWeld, itemInfo.item); |
||
867 | } |
||
16016 | fschmid | 868 | } |
16105 | fschmid | 869 | if (groupStack.count() > 0) |
16016 | fschmid | 870 | { |
16105 | fschmid | 871 | groupStack.top().append(itemInfo.item); |
16943 | fschmid | 872 | while (static_cast<int>(itemInfo.ownNr) == groupStack2.top()) |
16105 | fschmid | 873 | { |
874 | if (tagName == "PAGEOBJECT") |
||
875 | groupStackP.push(groupStack.pop()); |
||
876 | else if (tagName == "FRAMEOBJECT") |
||
877 | groupStackF.push(groupStack.pop()); |
||
878 | else |
||
879 | groupStackM.push(groupStack.pop()); |
||
880 | groupStack2.pop(); |
||
16233 | fschmid | 881 | if (groupStack2.count() == 0) |
882 | break; |
||
16105 | fschmid | 883 | } |
16016 | fschmid | 884 | } |
16113 | fschmid | 885 | if (itemInfo.isGroupFlag) |
16105 | fschmid | 886 | { |
887 | QList<PageItem*> GroupItems; |
||
888 | GroupItems.append(itemInfo.item); |
||
889 | groupStack.push(GroupItems); |
||
16943 | fschmid | 890 | groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr); |
16105 | fschmid | 891 | } |
16016 | fschmid | 892 | } |
893 | if (tagName == "Pattern") |
||
894 | { |
||
895 | success = readPattern(m_Doc, reader, fileDir); |
||
896 | if (!success) break; |
||
897 | } |
||
17826 | craig | 898 | if (tagName == "NotesStyles") |
899 | { |
||
900 | success = readNotesStyles(m_Doc, reader); |
||
901 | if (!success) break; |
||
902 | } |
||
903 | if (tagName == "NotesFrames") |
||
904 | { |
||
905 | success = readNotesFrames(reader); |
||
906 | if (!success) break; |
||
907 | } |
||
908 | if (tagName == "Notes") |
||
909 | { |
||
910 | success = readNotes(m_Doc, reader); |
||
911 | if (!success) break; |
||
912 | } |
||
913 | if (tagName == "Marks") |
||
914 | { |
||
915 | success = readMarks(m_Doc, reader); |
||
916 | if (!success) break; |
||
917 | } |
||
16016 | fschmid | 918 | } |
919 | |||
920 | if (reader.hasError()) |
||
921 | { |
||
922 | setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber()); |
||
923 | return false; |
||
924 | } |
||
16943 | fschmid | 925 | if (isNewFormat) |
16016 | fschmid | 926 | { |
16943 | fschmid | 927 | if (TableItems.count() != 0) |
16016 | fschmid | 928 | { |
16943 | fschmid | 929 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
930 | { |
||
931 | PageItem* ta = TableItems.at(ttc); |
||
932 | if (ta->TopLinkID != -1) |
||
933 | ta->TopLink = LinkID[ta->TopLinkID]; |
||
934 | else |
||
935 | ta->TopLink = 0; |
||
936 | if (ta->LeftLinkID != -1) |
||
937 | ta->LeftLink = LinkID[ta->LeftLinkID]; |
||
938 | else |
||
939 | ta->LeftLink = 0; |
||
940 | if (ta->RightLinkID != -1) |
||
941 | ta->RightLink = LinkID[ta->RightLinkID]; |
||
942 | else |
||
943 | ta->RightLink = 0; |
||
944 | if (ta->BottomLinkID != -1) |
||
945 | ta->BottomLink = LinkID[ta->BottomLinkID]; |
||
946 | else |
||
947 | ta->BottomLink = 0; |
||
948 | } |
||
16016 | fschmid | 949 | } |
16943 | fschmid | 950 | if (WeldItems.count() != 0) |
16016 | fschmid | 951 | { |
16943 | fschmid | 952 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
953 | { |
||
954 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 955 | for (int i = 0 ; i < ta->weldList.count(); ++i) |
16943 | fschmid | 956 | { |
957 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
||
17745 | jghali | 958 | ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0); |
959 | if (ta->weldList[i].weldItem == NULL) |
||
960 | ta->weldList.removeAt(i--); |
||
16943 | fschmid | 961 | } |
962 | } |
||
16016 | fschmid | 963 | } |
16943 | fschmid | 964 | if (itemNext.count() != 0) |
16016 | fschmid | 965 | { |
16943 | fschmid | 966 | QMap<int,int>::Iterator lc; |
967 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
968 | { |
||
969 | if (lc.value() >= 0) |
||
970 | { |
||
971 | PageItem * Its = LinkID[lc.key()]; |
||
972 | PageItem * Itn = LinkID[lc.value()]; |
||
973 | if (!Its->testLinkCandidate(Itn)) |
||
974 | { |
||
975 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
976 | continue; |
||
977 | } |
||
978 | Its->link(Itn); |
||
979 | } |
||
980 | } |
||
16016 | fschmid | 981 | } |
982 | } |
||
16943 | fschmid | 983 | else |
16926 | fschmid | 984 | { |
16943 | fschmid | 985 | if (TableItemsF.count() != 0) |
16926 | fschmid | 986 | { |
16943 | fschmid | 987 | for (int ttc = 0; ttc < TableItemsF.count(); ++ttc) |
16926 | fschmid | 988 | { |
16943 | fschmid | 989 | PageItem* ta = TableItemsF.at(ttc); |
990 | if (ta->TopLinkID != -1) |
||
991 | ta->TopLink = TableIDF[ta->TopLinkID]; |
||
992 | else |
||
993 | ta->TopLink = 0; |
||
994 | if (ta->LeftLinkID != -1) |
||
995 | ta->LeftLink = TableIDF[ta->LeftLinkID]; |
||
996 | else |
||
997 | ta->LeftLink = 0; |
||
998 | if (ta->RightLinkID != -1) |
||
999 | ta->RightLink = TableIDF[ta->RightLinkID]; |
||
1000 | else |
||
1001 | ta->RightLink = 0; |
||
1002 | if (ta->BottomLinkID != -1) |
||
1003 | ta->BottomLink = TableIDF[ta->BottomLinkID]; |
||
1004 | else |
||
1005 | ta->BottomLink = 0; |
||
16926 | fschmid | 1006 | } |
1007 | } |
||
16943 | fschmid | 1008 | if (TableItemsM.count() != 0) |
16016 | fschmid | 1009 | { |
16943 | fschmid | 1010 | for (int ttc = 0; ttc < TableItemsM.count(); ++ttc) |
16016 | fschmid | 1011 | { |
16943 | fschmid | 1012 | PageItem* ta = TableItemsM.at(ttc); |
1013 | if (ta->TopLinkID != -1) |
||
1014 | ta->TopLink = TableIDM[ta->TopLinkID]; |
||
1015 | else |
||
1016 | ta->TopLink = 0; |
||
1017 | if (ta->LeftLinkID != -1) |
||
1018 | ta->LeftLink = TableIDM[ta->LeftLinkID]; |
||
1019 | else |
||
1020 | ta->LeftLink = 0; |
||
1021 | if (ta->RightLinkID != -1) |
||
1022 | ta->RightLink = TableIDM[ta->RightLinkID]; |
||
1023 | else |
||
1024 | ta->RightLink = 0; |
||
1025 | if (ta->BottomLinkID != -1) |
||
1026 | ta->BottomLink = TableIDM[ta->BottomLinkID]; |
||
1027 | else |
||
1028 | ta->BottomLink = 0; |
||
1029 | } |
||
1030 | } |
||
1031 | if (TableItems.count() != 0) |
||
1032 | { |
||
1033 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
||
1034 | { |
||
1035 | PageItem* ta = TableItems.at(ttc); |
||
1036 | if (ta->TopLinkID != -1) |
||
1037 | ta->TopLink = TableID[ta->TopLinkID]; |
||
1038 | else |
||
1039 | ta->TopLink = 0; |
||
1040 | if (ta->LeftLinkID != -1) |
||
1041 | ta->LeftLink = TableID[ta->LeftLinkID]; |
||
1042 | else |
||
1043 | ta->LeftLink = 0; |
||
1044 | if (ta->RightLinkID != -1) |
||
1045 | ta->RightLink = TableID[ta->RightLinkID]; |
||
1046 | else |
||
1047 | ta->RightLink = 0; |
||
1048 | if (ta->BottomLinkID != -1) |
||
1049 | ta->BottomLink = TableID[ta->BottomLinkID]; |
||
1050 | else |
||
1051 | ta->BottomLink = 0; |
||
1052 | } |
||
1053 | } |
||
1054 | if (WeldItems.count() != 0) |
||
1055 | { |
||
1056 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
||
1057 | { |
||
1058 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 1059 | for (int i = 0 ; i < ta->weldList.count(); ++i) |
16016 | fschmid | 1060 | { |
16943 | fschmid | 1061 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
17745 | jghali | 1062 | ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0); |
1063 | if (ta->weldList[i].weldItem == NULL) |
||
1064 | ta->weldList.removeAt(i--); |
||
16016 | fschmid | 1065 | } |
1066 | } |
||
1067 | } |
||
16943 | fschmid | 1068 | // reestablish textframe links |
1069 | if (itemNext.count() != 0) |
||
16016 | fschmid | 1070 | { |
16943 | fschmid | 1071 | QMap<int,int>::Iterator lc; |
1072 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
16016 | fschmid | 1073 | { |
16943 | fschmid | 1074 | if (lc.value() >= 0) |
16016 | fschmid | 1075 | { |
16943 | fschmid | 1076 | PageItem * Its = m_Doc->DocItems.at(lc.key()); |
1077 | PageItem * Itn = m_Doc->DocItems.at(lc.value()); |
||
1078 | if (!Its->testLinkCandidate(Itn)) |
||
1079 | { |
||
1080 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
1081 | continue; |
||
1082 | } |
||
1083 | Its->link(Itn); |
||
16016 | fschmid | 1084 | } |
1085 | } |
||
1086 | } |
||
16943 | fschmid | 1087 | if (itemNextM.count() != 0) |
1088 | { |
||
1089 | QMap<int,int>::Iterator lc; |
||
1090 | for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc) |
||
1091 | { |
||
1092 | if (lc.value() >= 0) |
||
1093 | { |
||
1094 | PageItem * Its = m_Doc->MasterItems.at(lc.key()); |
||
1095 | PageItem * Itn = m_Doc->MasterItems.at(lc.value()); |
||
1096 | if (!Its->testLinkCandidate(Itn)) |
||
1097 | { |
||
1098 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
1099 | continue; |
||
1100 | } |
||
1101 | Its->link(Itn); |
||
1102 | } |
||
1103 | } |
||
1104 | } |
||
16016 | fschmid | 1105 | } |
16105 | fschmid | 1106 | if (groupStackP.count() > 0) |
1107 | { |
||
1108 | while (groupStackP.count() > 0) |
||
1109 | { |
||
17417 | fschmid | 1110 | bool isTableIt = false; |
16105 | fschmid | 1111 | QList<PageItem*> gpL = groupStackP.pop(); |
1112 | PageItem* gItem = gpL.takeFirst(); |
||
1113 | for (int id = 0; id < gpL.count(); id++) |
||
1114 | { |
||
1115 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1116 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1117 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1118 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1119 | cItem->Parent = gItem; |
16105 | fschmid | 1120 | if (gItem->rotation() != 0) |
1121 | { |
||
1122 | QTransform ma; |
||
1123 | ma.rotate(-gItem->rotation()); |
||
1124 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1125 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1126 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1127 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1128 | } |
||
1129 | m_Doc->DocItems.removeOne(cItem); |
||
1130 | } |
||
18282 | jghali | 1131 | bool converted = false; |
17417 | fschmid | 1132 | if (isTableIt) |
18282 | jghali | 1133 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems); |
1134 | if (!converted) |
||
17417 | fschmid | 1135 | gItem->groupItemList = gpL; |
16105 | fschmid | 1136 | } |
1137 | } |
||
1138 | if (groupStackF.count() > 0) |
||
1139 | { |
||
1140 | while (groupStackF.count() > 0) |
||
1141 | { |
||
17417 | fschmid | 1142 | bool isTableIt = false; |
16105 | fschmid | 1143 | QList<PageItem*> gpL = groupStackF.pop(); |
1144 | PageItem* gItem = gpL.takeFirst(); |
||
1145 | for (int id = 0; id < gpL.count(); id++) |
||
1146 | { |
||
1147 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1148 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1149 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1150 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1151 | cItem->Parent = gItem; |
16105 | fschmid | 1152 | if (gItem->rotation() != 0) |
1153 | { |
||
1154 | QTransform ma; |
||
1155 | ma.rotate(-gItem->rotation()); |
||
1156 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1157 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1158 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1159 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1160 | } |
||
17407 | fschmid | 1161 | m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem)); |
16105 | fschmid | 1162 | } |
18282 | jghali | 1163 | bool converted = false; |
17417 | fschmid | 1164 | if (isTableIt) |
18282 | jghali | 1165 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL); |
1166 | if (!converted) |
||
17417 | fschmid | 1167 | gItem->groupItemList = gpL; |
16105 | fschmid | 1168 | } |
1169 | } |
||
1170 | if (groupStackM.count() > 0) |
||
1171 | { |
||
1172 | while (groupStackM.count() > 0) |
||
1173 | { |
||
17417 | fschmid | 1174 | bool isTableIt = false; |
16105 | fschmid | 1175 | QList<PageItem*> gpL = groupStackM.pop(); |
1176 | PageItem* gItem = gpL.takeFirst(); |
||
1177 | for (int id = 0; id < gpL.count(); id++) |
||
1178 | { |
||
1179 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1180 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1181 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1182 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1183 | cItem->Parent = gItem; |
16105 | fschmid | 1184 | if (gItem->rotation() != 0) |
1185 | { |
||
1186 | QTransform ma; |
||
1187 | ma.rotate(-gItem->rotation()); |
||
1188 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1189 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1190 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1191 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1192 | } |
||
1193 | m_Doc->MasterItems.removeOne(cItem); |
||
1194 | } |
||
18282 | jghali | 1195 | bool converted = false; |
17417 | fschmid | 1196 | if (isTableIt) |
18282 | jghali | 1197 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems); |
1198 | if (!converted) |
||
17417 | fschmid | 1199 | gItem->groupItemList = gpL; |
16105 | fschmid | 1200 | } |
1201 | } |
||
16016 | fschmid | 1202 | |
1203 | if (m_Doc->Layers.count() == 0) |
||
1204 | m_Doc->Layers.newLayer( QObject::tr("Background") ); |
||
1205 | if (m_mwProgressBar!=0) |
||
1206 | { |
||
1207 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
1208 | m_mwProgressBar->reset(); |
||
1209 | } |
||
1210 | return true; |
||
1211 | } |
||
1212 | |||
13971 | jghali | 1213 | bool Scribus150Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */) |
1214 | { |
||
1215 | if (m_Doc==0 || m_AvailableFonts==0) |
||
1216 | { |
||
1217 | Q_ASSERT(m_Doc==0 || m_AvailableFonts==0); |
||
1218 | return false; |
||
1219 | } |
||
1220 | ParagraphStyle vg; |
||
16105 | fschmid | 1221 | Xp = 0.0; |
1222 | Yp = 0.0; |
||
1223 | GrX = 0.0; |
||
1224 | GrY = 0.0; |
||
13971 | jghali | 1225 | struct ScribusDoc::BookMa bok; |
1226 | QMap<int, ScribusDoc::BookMa> bookmarks; |
||
1227 | |||
16943 | fschmid | 1228 | isNewFormat = false; |
13971 | jghali | 1229 | |
16943 | fschmid | 1230 | QMap<int,PageItem*> TableID; |
1231 | QMap<int,PageItem*> TableIDM; |
||
1232 | QMap<int,PageItem*> TableIDF; |
||
13971 | jghali | 1233 | QList<PageItem*> TableItems; |
1234 | QList<PageItem*> TableItemsM; |
||
1235 | QList<PageItem*> TableItemsF; |
||
16931 | fschmid | 1236 | QMap<int,PageItem*> WeldID; |
16926 | fschmid | 1237 | QList<PageItem*> WeldItems; |
16105 | fschmid | 1238 | QStack< QList<PageItem*> > groupStack; |
1239 | QStack< QList<PageItem*> > groupStackF; |
||
1240 | QStack< QList<PageItem*> > groupStackM; |
||
1241 | QStack< QList<PageItem*> > groupStackP; |
||
1242 | QStack<int> groupStack2; |
||
13971 | jghali | 1243 | |
17826 | craig | 1244 | markeredItemsMap.clear(); |
1245 | markeredMarksMap.clear(); |
||
1246 | nsetRangeItemNamesMap.clear(); |
||
1247 | notesFramesData.clear(); |
||
1248 | notesMasterMarks.clear(); |
||
1249 | notesNSets.clear(); |
||
1250 | |||
17982 | jghali | 1251 | QScopedPointer<QIODevice> ioDevice(slaReader(fileName)); |
1252 | if (ioDevice.isNull()) |
||
14395 | jghali | 1253 | { |
1254 | setFileReadError(); |
||
13971 | jghali | 1255 | return false; |
14395 | jghali | 1256 | } |
13971 | jghali | 1257 | QString fileDir = QFileInfo(fileName).absolutePath(); |
1258 | int firstPage = 0; |
||
1259 | int layerToSetActive = 0; |
||
1260 | |||
1261 | if (m_mwProgressBar!=0) |
||
1262 | { |
||
17982 | jghali | 1263 | m_mwProgressBar->setMaximum(ioDevice->size()); |
13971 | jghali | 1264 | m_mwProgressBar->setValue(0); |
1265 | } |
||
1266 | // Stop autosave timer,it will be restarted only if doc has autosave feature is enabled |
||
1267 | if (m_Doc->autoSaveTimer->isActive()) |
||
1268 | m_Doc->autoSaveTimer->stop(); |
||
16105 | fschmid | 1269 | |
13971 | jghali | 1270 | itemRemap.clear(); |
1271 | itemNext.clear(); |
||
1272 | itemCount = 0; |
||
1273 | itemRemapM.clear(); |
||
1274 | itemNextM.clear(); |
||
1275 | itemCountM = 0; |
||
1276 | itemRemapF.clear(); |
||
1277 | itemNextF.clear(); |
||
1278 | |||
19742 | jghali | 1279 | FrameItems.clear(); |
13971 | jghali | 1280 | TableItems.clear(); |
1281 | TableID.clear(); |
||
1282 | TableItemsM.clear(); |
||
1283 | TableIDM.clear(); |
||
1284 | TableItemsF.clear(); |
||
1285 | TableIDF.clear(); |
||
16926 | fschmid | 1286 | WeldItems.clear(); |
1287 | WeldID.clear(); |
||
16943 | fschmid | 1288 | LinkID.clear(); |
13971 | jghali | 1289 | |
1290 | m_Doc->GroupCounter = 1; |
||
1291 | m_Doc->LastAuto = 0; |
||
1292 | m_Doc->PageColors.clear(); |
||
1293 | m_Doc->Layers.clear(); |
||
1294 | |||
1295 | bool firstElement = true; |
||
1296 | bool success = true; |
||
1297 | bool hasPageSets = false; |
||
1298 | int progress = 0; |
||
1299 | |||
17982 | jghali | 1300 | ScXmlStreamReader reader(ioDevice.data()); |
13971 | jghali | 1301 | ScXmlStreamAttributes attrs; |
1302 | while(!reader.atEnd() && !reader.hasError()) |
||
1303 | { |
||
1304 | QXmlStreamReader::TokenType tType = reader.readNext(); |
||
1305 | if (tType != QXmlStreamReader::StartElement) |
||
1306 | continue; |
||
1307 | QStringRef tagName = reader.name(); |
||
1308 | attrs = reader.scAttributes(); |
||
1309 | |||
1310 | if (m_mwProgressBar != 0) |
||
1311 | { |
||
17982 | jghali | 1312 | int newProgress = qRound(ioDevice->pos() / (double) ioDevice->size() * 100); |
13971 | jghali | 1313 | if (newProgress != progress) |
1314 | { |
||
1315 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
1316 | progress = newProgress; |
||
1317 | } |
||
1318 | } |
||
1319 | |||
1320 | if (firstElement) |
||
1321 | { |
||
1322 | if (tagName != "SCRIBUSUTF8NEW") |
||
1323 | { |
||
1324 | success = false; |
||
1325 | break; |
||
1326 | } |
||
1327 | firstElement = false; |
||
1328 | } |
||
1329 | if (tagName == "DOCUMENT") |
||
1330 | { |
||
1331 | readDocAttributes(m_Doc, attrs); |
||
1332 | layerToSetActive = attrs.valueAsInt("ALAYER", 0); |
||
15407 | craig | 1333 | if (m_Doc->pagePositioning() == 0) |
13971 | jghali | 1334 | firstPage = 0; |
1335 | else |
||
1336 | { |
||
1337 | if (attrs.valueAsInt("FIRSTLEFT", 0) == 1) |
||
1338 | firstPage = 0; |
||
1339 | else |
||
1340 | firstPage = 1; |
||
1341 | } |
||
1342 | if (attrs.hasAttribute("currentProfile")) |
||
1343 | { |
||
14971 | cbradney | 1344 | m_Doc->clearCheckerProfiles(); |
1345 | m_Doc->setCurCheckProfile(attrs.valueAsString("currentProfile")); |
||
13971 | jghali | 1346 | } |
1347 | } |
||
1348 | if (tagName == "CheckProfile") |
||
1349 | { |
||
1350 | success = readCheckProfile(m_Doc, attrs); |
||
1351 | if (!success) break; |
||
1352 | } |
||
1353 | if (tagName == "PageSets") |
||
1354 | { |
||
1355 | success = readPageSets(m_Doc, reader); |
||
1356 | if (!success) break; |
||
1357 | hasPageSets = true; |
||
1358 | } |
||
1359 | // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file... |
||
1360 | if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None) |
||
1361 | { |
||
1362 | success = readColor(m_Doc->PageColors, attrs); |
||
1363 | if (!success) break; |
||
1364 | } |
||
14150 | fschmid | 1365 | if (tagName == "Gradient") |
1366 | { |
||
1367 | VGradient gra; |
||
1368 | QString grName = attrs.valueAsString("Name"); |
||
1369 | success = readGradient(m_Doc, gra, reader); |
||
19103 | fschmid | 1370 | if (!success) |
1371 | break; |
||
1372 | gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad))); |
||
14150 | fschmid | 1373 | if (!grName.isEmpty()) |
1374 | { |
||
1375 | m_Doc->docGradients.insert(grName, gra); |
||
1376 | } |
||
1377 | } |
||
13971 | jghali | 1378 | if (tagName == "STYLE") |
1379 | { |
||
16531 | jghali | 1380 | readParagraphStyle(m_Doc, reader, vg); |
13971 | jghali | 1381 | StyleSet<ParagraphStyle>tmp; |
1382 | tmp.create(vg); |
||
1383 | m_Doc->redefineStyles(tmp, false); |
||
1384 | } |
||
1385 | if (tagName == "CHARSTYLE") |
||
1386 | { |
||
16531 | jghali | 1387 | CharStyle cstyle; |
16533 | jghali | 1388 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
1389 | readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle); |
||
13971 | jghali | 1390 | StyleSet<CharStyle> temp; |
16531 | jghali | 1391 | temp.create(cstyle); |
13971 | jghali | 1392 | m_Doc->redefineCharStyles(temp, false); |
1393 | } |
||
17318 | fschmid | 1394 | if (tagName == "TableStyle") |
1395 | { |
||
1396 | TableStyle tstyle; |
||
1397 | readTableStyle(m_Doc, reader, tstyle); |
||
1398 | StyleSet<TableStyle> temp; |
||
1399 | temp.create(tstyle); |
||
1400 | m_Doc->redefineTableStyles(temp, false); |
||
1401 | } |
||
1402 | if (tagName == "CellStyle") |
||
1403 | { |
||
1404 | CellStyle tstyle; |
||
1405 | readCellStyle(m_Doc, reader, tstyle); |
||
1406 | StyleSet<CellStyle> temp; |
||
1407 | temp.create(tstyle); |
||
1408 | m_Doc->redefineCellStyles(temp, false); |
||
1409 | } |
||
13971 | jghali | 1410 | if (tagName == "JAVA") |
1411 | { |
||
1412 | QString name = attrs.valueAsString("NAME"); |
||
1413 | if (!name.isEmpty()) |
||
1414 | m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT"); |
||
1415 | } |
||
1416 | if (tagName == "LAYERS") |
||
1417 | { |
||
1418 | ScLayer newLayer; |
||
1419 | readLayers(newLayer, attrs); |
||
1420 | m_Doc->Layers.append(newLayer); |
||
1421 | } |
||
1422 | if (tagName == "Arrows") |
||
1423 | { |
||
1424 | success = readArrows(m_Doc, attrs); |
||
1425 | if (!success) break; |
||
1426 | } |
||
1427 | if (tagName == "MultiLine") |
||
1428 | { |
||
1429 | multiLine ml; |
||
1430 | QString mlName = attrs.valueAsString("Name"); |
||
1431 | success = readMultiline(ml, reader); |
||
1432 | if (!success) break; |
||
1433 | if (!mlName.isEmpty()) |
||
1434 | { |
||
1435 | m_Doc->MLineStyles.insert(mlName, ml); |
||
1436 | } |
||
1437 | } |
||
1438 | if (tagName == "Bookmark") |
||
1439 | { |
||
1440 | int bmElem = 0; |
||
1441 | struct ScribusDoc::BookMa bookmark; |
||
1442 | success = readBookMark(bookmark, bmElem, attrs); |
||
1443 | if (!success) break; |
||
1444 | bookmarks.insert(bmElem, bookmark); |
||
1445 | } |
||
1446 | if (tagName == "PDF") |
||
1447 | { |
||
1448 | success = readPDFOptions(m_Doc, reader); |
||
1449 | if (!success) break; |
||
1450 | } |
||
1451 | if (tagName == "Printer") |
||
1452 | { |
||
1453 | success = readPrinterOptions(m_Doc, reader); |
||
1454 | if (!success) break; |
||
1455 | } |
||
1456 | if (tagName == "DocItemAttributes") |
||
1457 | { |
||
1458 | success = readDocItemAttributes(m_Doc, reader); |
||
1459 | if (!success) break; |
||
1460 | } |
||
1461 | if (tagName == "TablesOfContents") |
||
1462 | { |
||
1463 | success = readTableOfContents(m_Doc, reader); |
||
1464 | if (!success) break; |
||
1465 | } |
||
1466 | if (tagName == "Sections") |
||
1467 | { |
||
1468 | success = readSections(m_Doc, reader); |
||
1469 | if (!success) break; |
||
1470 | } |
||
1471 | if (tagName == "HYPHEN") |
||
1472 | { |
||
1473 | success = readHyphen(m_Doc, reader); |
||
1474 | if (!success) break; |
||
1475 | } |
||
1476 | if (tagName == "PAGE" || tagName == "MASTERPAGE") |
||
1477 | { |
||
1478 | success = readPage(m_Doc, reader); |
||
16105 | fschmid | 1479 | if (!success) |
1480 | break; |
||
13971 | jghali | 1481 | } |
1482 | if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT") |
||
1483 | { |
||
1484 | ItemInfo itemInfo; |
||
1485 | success = readObject(m_Doc, reader, itemInfo, fileDir, false); |
||
16105 | fschmid | 1486 | if (!success) |
1487 | break; |
||
13971 | jghali | 1488 | |
1489 | // first of linked chain? |
||
16943 | fschmid | 1490 | if (isNewFormat) |
13971 | jghali | 1491 | { |
1492 | if (itemInfo.nextItem != -1) |
||
16943 | fschmid | 1493 | itemNext[itemInfo.itemID] = itemInfo.nextItem; |
1494 | if (itemInfo.item->isTableItem) |
||
1495 | TableItems.append(itemInfo.item); |
||
1496 | if (itemInfo.isWeldFlag) |
||
1497 | WeldItems.append(itemInfo.item); |
||
13971 | jghali | 1498 | } |
16943 | fschmid | 1499 | else |
13971 | jghali | 1500 | { |
1501 | if (tagName == "PAGEOBJECT") |
||
1502 | { |
||
16943 | fschmid | 1503 | if (itemInfo.nextItem != -1) |
1504 | itemNext[itemInfo.ownNr] = itemInfo.nextItem; |
||
13971 | jghali | 1505 | } |
16943 | fschmid | 1506 | else if (tagName == "MASTEROBJECT") |
13971 | jghali | 1507 | { |
16943 | fschmid | 1508 | if (itemInfo.nextItem != -1) |
1509 | itemNextM[itemInfo.ownNr] = itemInfo.nextItem; |
||
13971 | jghali | 1510 | } |
16943 | fschmid | 1511 | if (itemInfo.item->isTableItem) |
13971 | jghali | 1512 | { |
16943 | fschmid | 1513 | if (tagName == "PAGEOBJECT") |
1514 | { |
||
1515 | TableItems.append(itemInfo.item); |
||
1516 | TableID.insert(itemInfo.ownLink, itemInfo.item); |
||
1517 | } |
||
1518 | else if (tagName == "FRAMEOBJECT") |
||
1519 | { |
||
1520 | TableItemsF.append(itemInfo.item); |
||
1521 | TableIDF.insert(itemInfo.ownLink, itemInfo.item); |
||
1522 | } |
||
1523 | else |
||
1524 | { |
||
1525 | TableItemsM.append(itemInfo.item); |
||
1526 | TableIDM.insert(itemInfo.ownLink, itemInfo.item); |
||
1527 | } |
||
13971 | jghali | 1528 | } |
16943 | fschmid | 1529 | |
1530 | if (itemInfo.isWeldFlag) |
||
1531 | { |
||
1532 | WeldItems.append(itemInfo.item); |
||
1533 | WeldID.insert(itemInfo.ownWeld, itemInfo.item); |
||
1534 | } |
||
13971 | jghali | 1535 | } |
16105 | fschmid | 1536 | if (groupStack.count() > 0) |
13971 | jghali | 1537 | { |
16105 | fschmid | 1538 | groupStack.top().append(itemInfo.item); |
16943 | fschmid | 1539 | while (static_cast<int>(itemInfo.ownNr) == groupStack2.top()) |
16105 | fschmid | 1540 | { |
1541 | if (tagName == "PAGEOBJECT") |
||
1542 | groupStackP.push(groupStack.pop()); |
||
1543 | else if (tagName == "FRAMEOBJECT") |
||
1544 | groupStackF.push(groupStack.pop()); |
||
1545 | else |
||
1546 | groupStackM.push(groupStack.pop()); |
||
1547 | groupStack2.pop(); |
||
16233 | fschmid | 1548 | if (groupStack2.count() == 0) |
1549 | break; |
||
16105 | fschmid | 1550 | } |
13971 | jghali | 1551 | } |
16113 | fschmid | 1552 | if (itemInfo.isGroupFlag) |
16105 | fschmid | 1553 | { |
1554 | QList<PageItem*> GroupItems; |
||
1555 | GroupItems.append(itemInfo.item); |
||
1556 | groupStack.push(GroupItems); |
||
16943 | fschmid | 1557 | groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr); |
16105 | fschmid | 1558 | } |
13971 | jghali | 1559 | } |
1560 | if (tagName == "Pattern") |
||
1561 | { |
||
1562 | success = readPattern(m_Doc, reader, fileDir); |
||
16105 | fschmid | 1563 | if (!success) |
1564 | break; |
||
13971 | jghali | 1565 | } |
17826 | craig | 1566 | if (tagName == "NotesStyles") |
1567 | { |
||
1568 | success = readNotesStyles(m_Doc, reader); |
||
1569 | if (!success) break; |
||
1570 | } |
||
1571 | if (tagName == "NotesFrames") |
||
1572 | { |
||
1573 | success = readNotesFrames(reader); |
||
1574 | if (!success) break; |
||
1575 | } |
||
1576 | if (tagName == "Notes") |
||
1577 | { |
||
1578 | success = readNotes(m_Doc, reader); |
||
1579 | if (!success) break; |
||
1580 | } |
||
1581 | if (tagName == "Marks") |
||
1582 | { |
||
1583 | success = readMarks(m_Doc, reader); |
||
1584 | if (!success) break; |
||
1585 | } |
||
13971 | jghali | 1586 | } |
1587 | |||
1588 | if (reader.hasError()) |
||
14392 | jghali | 1589 | { |
1590 | setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber()); |
||
13971 | jghali | 1591 | return false; |
14392 | jghali | 1592 | } |
13971 | jghali | 1593 | |
1594 | QMap<int, ScribusDoc::BookMa>::Iterator it; |
||
1595 | for (it = bookmarks.begin(); it != bookmarks.end(); ++it) |
||
1596 | { |
||
1597 | int elem = it.key(); |
||
1598 | if (elem < m_Doc->Items->count()) |
||
1599 | { |
||
1600 | ScribusDoc::BookMa bookmark = it.value(); |
||
1601 | bookmark.PageObject = m_Doc->Items->at(elem); |
||
1602 | m_Doc->BookMarks.append( bookmark ); |
||
1603 | } |
||
1604 | } |
||
1605 | |||
16943 | fschmid | 1606 | if (isNewFormat) |
13971 | jghali | 1607 | { |
16943 | fschmid | 1608 | if (TableItems.count() != 0) |
13971 | jghali | 1609 | { |
16943 | fschmid | 1610 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
1611 | { |
||
1612 | PageItem* ta = TableItems.at(ttc); |
||
1613 | if (ta->TopLinkID != -1) |
||
1614 | ta->TopLink = LinkID[ta->TopLinkID]; |
||
1615 | else |
||
1616 | ta->TopLink = 0; |
||
1617 | if (ta->LeftLinkID != -1) |
||
1618 | ta->LeftLink = LinkID[ta->LeftLinkID]; |
||
1619 | else |
||
1620 | ta->LeftLink = 0; |
||
1621 | if (ta->RightLinkID != -1) |
||
1622 | ta->RightLink = LinkID[ta->RightLinkID]; |
||
1623 | else |
||
1624 | ta->RightLink = 0; |
||
1625 | if (ta->BottomLinkID != -1) |
||
1626 | ta->BottomLink = LinkID[ta->BottomLinkID]; |
||
1627 | else |
||
1628 | ta->BottomLink = 0; |
||
1629 | } |
||
13971 | jghali | 1630 | } |
16943 | fschmid | 1631 | if (WeldItems.count() != 0) |
13971 | jghali | 1632 | { |
16943 | fschmid | 1633 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
1634 | { |
||
1635 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 1636 | for (int i = 0 ; i < ta->weldList.count(); ++i) |
16943 | fschmid | 1637 | { |
1638 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
||
17745 | jghali | 1639 | ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0); |
1640 | if (ta->weldList[i].weldItem == NULL) |
||
1641 | ta->weldList.removeAt(i--); |
||
16943 | fschmid | 1642 | } |
1643 | } |
||
13971 | jghali | 1644 | } |
16943 | fschmid | 1645 | if (itemNext.count() != 0) |
13971 | jghali | 1646 | { |
16943 | fschmid | 1647 | QMap<int,int>::Iterator lc; |
1648 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
1649 | { |
||
1650 | if (lc.value() >= 0) |
||
1651 | { |
||
1652 | PageItem * Its = LinkID[lc.key()]; |
||
1653 | PageItem * Itn = LinkID[lc.value()]; |
||
1654 | if (!Its->testLinkCandidate(Itn)) |
||
1655 | { |
||
1656 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
1657 | continue; |
||
1658 | } |
||
1659 | Its->link(Itn); |
||
1660 | } |
||
1661 | } |
||
13971 | jghali | 1662 | } |
1663 | } |
||
16943 | fschmid | 1664 | else |
16926 | fschmid | 1665 | { |
16943 | fschmid | 1666 | if (TableItemsF.count() != 0) |
16926 | fschmid | 1667 | { |
16943 | fschmid | 1668 | for (int ttc = 0; ttc < TableItemsF.count(); ++ttc) |
16926 | fschmid | 1669 | { |
16943 | fschmid | 1670 | PageItem* ta = TableItemsF.at(ttc); |
1671 | if (ta->TopLinkID != -1) |
||
1672 | ta->TopLink = TableIDF[ta->TopLinkID]; |
||
1673 | else |
||
1674 | ta->TopLink = 0; |
||
1675 | if (ta->LeftLinkID != -1) |
||
1676 | ta->LeftLink = TableIDF[ta->LeftLinkID]; |
||
1677 | else |
||
1678 | ta->LeftLink = 0; |
||
1679 | if (ta->RightLinkID != -1) |
||
1680 | ta->RightLink = TableIDF[ta->RightLinkID]; |
||
1681 | else |
||
1682 | ta->RightLink = 0; |
||
1683 | if (ta->BottomLinkID != -1) |
||
1684 | ta->BottomLink = TableIDF[ta->BottomLinkID]; |
||
1685 | else |
||
1686 | ta->BottomLink = 0; |
||
16926 | fschmid | 1687 | } |
1688 | } |
||
16943 | fschmid | 1689 | if (TableItemsM.count() != 0) |
1690 | { |
||
1691 | for (int ttc = 0; ttc < TableItemsM.count(); ++ttc) |
||
1692 | { |
||
1693 | PageItem* ta = TableItemsM.at(ttc); |
||
1694 | if (ta->TopLinkID != -1) |
||
1695 | ta->TopLink = TableIDM[ta->TopLinkID]; |
||
1696 | else |
||
1697 | ta->TopLink = 0; |
||
1698 | if (ta->LeftLinkID != -1) |
||
1699 | ta->LeftLink = TableIDM[ta->LeftLinkID]; |
||
1700 | else |
||
1701 | ta->LeftLink = 0; |
||
1702 | if (ta->RightLinkID != -1) |
||
1703 | ta->RightLink = TableIDM[ta->RightLinkID]; |
||
1704 | else |
||
1705 | ta->RightLink = 0; |
||
1706 | if (ta->BottomLinkID != -1) |
||
1707 | ta->BottomLink = TableIDM[ta->BottomLinkID]; |
||
1708 | else |
||
1709 | ta->BottomLink = 0; |
||
1710 | } |
||
1711 | } |
||
1712 | if (TableItems.count() != 0) |
||
1713 | { |
||
1714 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
||
1715 | { |
||
1716 | PageItem* ta = TableItems.at(ttc); |
||
1717 | if (ta->TopLinkID != -1) |
||
1718 | ta->TopLink = TableID[ta->TopLinkID]; |
||
1719 | else |
||
1720 | ta->TopLink = 0; |
||
1721 | if (ta->LeftLinkID != -1) |
||
1722 | ta->LeftLink = TableID[ta->LeftLinkID]; |
||
1723 | else |
||
1724 | ta->LeftLink = 0; |
||
1725 | if (ta->RightLinkID != -1) |
||
1726 | ta->RightLink = TableID[ta->RightLinkID]; |
||
1727 | else |
||
1728 | ta->RightLink = 0; |
||
1729 | if (ta->BottomLinkID != -1) |
||
1730 | ta->BottomLink = TableID[ta->BottomLinkID]; |
||
1731 | else |
||
1732 | ta->BottomLink = 0; |
||
1733 | } |
||
1734 | } |
||
1735 | if (WeldItems.count() != 0) |
||
1736 | { |
||
1737 | for (int ttc = 0; ttc < WeldItems.count(); ++ttc) |
||
1738 | { |
||
1739 | PageItem* ta = WeldItems.at(ttc); |
||
17745 | jghali | 1740 | for (int i = 0 ; i < ta->weldList.count(); ++i) |
16943 | fschmid | 1741 | { |
1742 | PageItem::weldingInfo wInf = ta->weldList.at(i); |
||
17745 | jghali | 1743 | ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0); |
1744 | if (ta->weldList[i].weldItem == NULL) |
||
1745 | ta->weldList.removeAt(i--); |
||
16943 | fschmid | 1746 | } |
1747 | } |
||
1748 | } |
||
1749 | if (itemNext.count() != 0) |
||
1750 | { |
||
1751 | QMap<int,int>::Iterator lc; |
||
1752 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
1753 | { |
||
1754 | if (lc.value() >= 0) |
||
1755 | { |
||
1756 | PageItem * Its = m_Doc->DocItems.at(lc.key()); |
||
1757 | PageItem * Itn = m_Doc->DocItems.at(lc.value()); |
||
1758 | if (!Its->testLinkCandidate(Itn)) |
||
1759 | { |
||
1760 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
1761 | continue; |
||
1762 | } |
||
1763 | Its->link(Itn); |
||
1764 | } |
||
1765 | } |
||
1766 | } |
||
1767 | if (itemNextM.count() != 0) |
||
1768 | { |
||
1769 | QMap<int,int>::Iterator lc; |
||
1770 | for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc) |
||
1771 | { |
||
1772 | if (lc.value() >= 0) |
||
1773 | { |
||
1774 | PageItem * Its = m_Doc->MasterItems.at(lc.key()); |
||
1775 | PageItem * Itn = m_Doc->MasterItems.at(lc.value()); |
||
1776 | if (!Its->testLinkCandidate(Itn)) |
||
1777 | { |
||
1778 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
1779 | continue; |
||
1780 | } |
||
1781 | Its->link(Itn); |
||
1782 | } |
||
1783 | } |
||
1784 | } |
||
16926 | fschmid | 1785 | } |
13971 | jghali | 1786 | //CB Add this in to set this in the file in memory. Its saved, why not load it. |
1787 | //Will of course be replaced by per page settings although we still probably need a document default |
||
1788 | if (!hasPageSets) |
||
1789 | { |
||
15407 | craig | 1790 | m_Doc->setPageSetFirstPage(m_Doc->pagePositioning(), firstPage); |
14924 | cbradney | 1791 | //->Prefs m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = firstPage; |
13971 | jghali | 1792 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble(); |
1793 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0; |
||
1794 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble(); |
||
1795 | } |
||
1796 | m_Doc->setActiveLayer(layerToSetActive); |
||
1797 | m_Doc->setMasterPageMode(false); |
||
1798 | m_Doc->reformPages(); |
||
17338 | jghali | 1799 | m_Doc->refreshGuides(); |
13971 | jghali | 1800 | |
19089 | jghali | 1801 | // #12282 : some docs have language dependent style names specified in style properties |
1802 | m_Doc->fixParagraphStyles(); |
||
1803 | m_Doc->fixNotesStyles(); |
||
1804 | |||
13971 | jghali | 1805 | if (m_Doc->Layers.count() == 0) |
1806 | m_Doc->Layers.newLayer( QObject::tr("Background") ); |
||
18394 | fschmid | 1807 | if (!EffVal.isEmpty()) |
1808 | { |
||
1809 | for (int pdoE = 0; pdoE < EffVal.count(); ++pdoE) |
||
1810 | { |
||
1811 | if (pdoE < m_Doc->Pages->count()) |
||
1812 | m_Doc->Pages->at(pdoE)->PresentVals = EffVal[pdoE]; |
||
1813 | } |
||
1814 | } |
||
13971 | jghali | 1815 | |
16105 | fschmid | 1816 | if (groupStackP.count() > 0) |
1817 | { |
||
1818 | while (groupStackP.count() > 0) |
||
1819 | { |
||
17417 | fschmid | 1820 | bool isTableIt = false; |
16105 | fschmid | 1821 | QList<PageItem*> gpL = groupStackP.pop(); |
1822 | PageItem* gItem = gpL.takeFirst(); |
||
1823 | for (int id = 0; id < gpL.count(); id++) |
||
1824 | { |
||
1825 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1826 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1827 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1828 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1829 | cItem->Parent = gItem; |
16105 | fschmid | 1830 | if (gItem->rotation() != 0) |
1831 | { |
||
1832 | QTransform ma; |
||
1833 | ma.rotate(-gItem->rotation()); |
||
1834 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1835 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1836 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1837 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1838 | } |
||
1839 | m_Doc->DocItems.removeOne(cItem); |
||
1840 | } |
||
18282 | jghali | 1841 | bool converted = false; |
17417 | fschmid | 1842 | if (isTableIt) |
18282 | jghali | 1843 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems); |
1844 | if (!converted) |
||
17417 | fschmid | 1845 | gItem->groupItemList = gpL; |
16105 | fschmid | 1846 | } |
1847 | } |
||
1848 | if (groupStackF.count() > 0) |
||
1849 | { |
||
1850 | while (groupStackF.count() > 0) |
||
1851 | { |
||
17417 | fschmid | 1852 | bool isTableIt = false; |
16105 | fschmid | 1853 | QList<PageItem*> gpL = groupStackF.pop(); |
1854 | PageItem* gItem = gpL.takeFirst(); |
||
1855 | for (int id = 0; id < gpL.count(); id++) |
||
1856 | { |
||
1857 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1858 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1859 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1860 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1861 | cItem->Parent = gItem; |
16105 | fschmid | 1862 | if (gItem->rotation() != 0) |
1863 | { |
||
1864 | QTransform ma; |
||
1865 | ma.rotate(-gItem->rotation()); |
||
1866 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1867 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1868 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1869 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1870 | } |
||
17407 | fschmid | 1871 | m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem)); |
16105 | fschmid | 1872 | } |
18282 | jghali | 1873 | bool converted = false; |
17417 | fschmid | 1874 | if (isTableIt) |
18282 | jghali | 1875 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL); |
1876 | if (!converted) |
||
17417 | fschmid | 1877 | gItem->groupItemList = gpL; |
16105 | fschmid | 1878 | } |
1879 | } |
||
1880 | if (groupStackM.count() > 0) |
||
1881 | { |
||
1882 | while (groupStackM.count() > 0) |
||
1883 | { |
||
17417 | fschmid | 1884 | bool isTableIt = false; |
16105 | fschmid | 1885 | QList<PageItem*> gpL = groupStackM.pop(); |
1886 | PageItem* gItem = gpL.takeFirst(); |
||
1887 | for (int id = 0; id < gpL.count(); id++) |
||
1888 | { |
||
1889 | PageItem* cItem = gpL.at(id); |
||
17417 | fschmid | 1890 | isTableIt = cItem->isTableItem; |
16105 | fschmid | 1891 | cItem->gXpos = cItem->xPos() - gItem->xPos(); |
1892 | cItem->gYpos = cItem->yPos() - gItem->yPos(); |
||
16943 | fschmid | 1893 | cItem->Parent = gItem; |
16105 | fschmid | 1894 | if (gItem->rotation() != 0) |
1895 | { |
||
1896 | QTransform ma; |
||
1897 | ma.rotate(-gItem->rotation()); |
||
1898 | FPoint n = FPoint(cItem->gXpos, cItem->gYpos); |
||
1899 | cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(); |
||
1900 | cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy(); |
||
1901 | cItem->setRotation(cItem->rotation() - gItem->rotation()); |
||
1902 | } |
||
1903 | m_Doc->MasterItems.removeOne(cItem); |
||
1904 | } |
||
18282 | jghali | 1905 | bool converted = false; |
17417 | fschmid | 1906 | if (isTableIt) |
18282 | jghali | 1907 | converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems); |
1908 | if (!converted) |
||
17417 | fschmid | 1909 | gItem->groupItemList = gpL; |
16105 | fschmid | 1910 | } |
1911 | } |
||
17826 | craig | 1912 | //update names to pointers |
1913 | updateNames2Ptr(); |
||
19104 | jghali | 1914 | |
13971 | jghali | 1915 | // reestablish first/lastAuto |
1916 | m_Doc->FirstAuto = m_Doc->LastAuto; |
||
1917 | if (m_Doc->LastAuto) |
||
1918 | { |
||
1919 | while (m_Doc->LastAuto->nextInChain()) |
||
1920 | m_Doc->LastAuto = m_Doc->LastAuto->nextInChain(); |
||
1921 | while (m_Doc->FirstAuto->prevInChain()) |
||
1922 | m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain(); |
||
1923 | } |
||
1924 | |||
1925 | // start auto save timer if needed |
||
18047 | craig | 1926 | if (m_Doc->autoSave() && ScCore->usingGUI()) |
17797 | fschmid | 1927 | m_Doc->restartAutoSaveTimer(); |
18047 | craig | 1928 | // m_Doc->autoSaveTimer->start(m_Doc->autoSaveTime()); |
19104 | jghali | 1929 | |
13971 | jghali | 1930 | if (m_mwProgressBar!=0) |
1931 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
1932 | return true; |
||
1933 | } |
||
1934 | |||
1935 | // Low level plugin API |
||
1936 | int scribus150format_getPluginAPIVersion() |
||
1937 | { |
||
1938 | return PLUGIN_API_VERSION; |
||
1939 | } |
||
1940 | |||
1941 | ScPlugin* scribus150format_getPlugin() |
||
1942 | { |
||
1943 | Scribus150Format* plug = new Scribus150Format(); |
||
1944 | Q_CHECK_PTR(plug); |
||
1945 | return plug; |
||
1946 | } |
||
1947 | |||
1948 | void scribus150format_freePlugin(ScPlugin* plugin) |
||
1949 | { |
||
1950 | Scribus150Format* plug = dynamic_cast<Scribus150Format*>(plugin); |
||
1951 | Q_ASSERT(plug); |
||
1952 | delete plug; |
||
1953 | } |
||
1954 | |||
1955 | |||
1956 | namespace { |
||
1957 | const int NOVALUE = -16000; |
||
19104 | jghali | 1958 | |
13971 | jghali | 1959 | void fixLegacyCharStyle(CharStyle& cstyle) |
1960 | { |
||
1961 | if (! cstyle.font().usable()) |
||
1962 | cstyle.resetFont(); |
||
1963 | if (cstyle.fontSize() <= -16000 / 10) |
||
1964 | cstyle.resetFontSize(); |
||
1965 | // if (cstyle.effects() == 65535) |
||
1966 | // cstyle.resetEffects(); |
||
1967 | if (cstyle.fillColor().isEmpty()) |
||
1968 | cstyle.resetFillColor(); |
||
1969 | if (cstyle.fillShade() <= -16000) |
||
1970 | cstyle.resetFillShade(); |
||
1971 | if (cstyle.strokeColor().isEmpty()) |
||
1972 | cstyle.resetStrokeColor(); |
||
1973 | if (cstyle.strokeShade() <= -16000) |
||
1974 | cstyle.resetStrokeShade(); |
||
1975 | if (cstyle.shadowXOffset() <= -16000 / 10) |
||
1976 | cstyle.resetShadowXOffset(); |
||
1977 | if (cstyle.shadowYOffset() <= -16000 / 10) |
||
1978 | cstyle.resetShadowYOffset(); |
||
1979 | if (cstyle.outlineWidth() <= -16000 / 10) |
||
1980 | cstyle.resetOutlineWidth(); |
||
1981 | if (cstyle.underlineOffset() <= -16000 / 10) |
||
1982 | cstyle.resetUnderlineOffset(); |
||
1983 | if (cstyle.underlineWidth() <= -16000 / 10) |
||
1984 | cstyle.resetUnderlineWidth(); |
||
1985 | if (cstyle.strikethruOffset() <= -16000 / 10) |
||
1986 | cstyle.resetStrikethruOffset(); |
||
1987 | if (cstyle.strikethruWidth() <= -16000 / 10) |
||
1988 | cstyle.resetStrikethruWidth(); |
||
1989 | if (cstyle.scaleH() <= -16000 / 10) |
||
1990 | cstyle.resetScaleH(); |
||
1991 | if (cstyle.scaleV() <= -16000 / 10) |
||
1992 | cstyle.resetScaleV(); |
||
1993 | if (cstyle.baselineOffset() <= -16000 / 10) |
||
1994 | cstyle.resetBaselineOffset(); |
||
1995 | if (cstyle.tracking() <= -16000 / 10) |
||
1996 | cstyle.resetTracking(); |
||
1997 | } |
||
19104 | jghali | 1998 | |
13971 | jghali | 1999 | void fixLegacyParStyle(ParagraphStyle& pstyle) |
2000 | { |
||
2001 | if (pstyle.lineSpacing() <= -16000) |
||
2002 | pstyle.resetLineSpacing(); |
||
2003 | if (pstyle.leftMargin() <= -16000) |
||
2004 | pstyle.resetLeftMargin(); |
||
2005 | if (pstyle.rightMargin() <= -16000) |
||
2006 | pstyle.resetRightMargin(); |
||
2007 | if (pstyle.firstIndent() <= -16000) |
||
2008 | pstyle.resetFirstIndent(); |
||
2009 | if (pstyle.alignment() < 0) |
||
2010 | pstyle.resetAlignment(); |
||
2011 | if (pstyle.gapBefore() <= -16000) |
||
2012 | pstyle.resetGapBefore(); |
||
2013 | if (pstyle.gapAfter() <= -16000) |
||
2014 | pstyle.resetGapAfter(); |
||
2015 | if (pstyle.dropCapLines() < 0) |
||
2016 | pstyle.resetDropCapLines(); |
||
18047 | craig | 2017 | if (pstyle.parEffectOffset() <= -16000) |
2018 | pstyle.resetParEffectOffset(); |
||
13971 | jghali | 2019 | fixLegacyCharStyle(pstyle.charStyle()); |
2020 | } |
||
19104 | jghali | 2021 | |
13971 | jghali | 2022 | }// namespace |
2023 | |||
2024 | void Scribus150Format::readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
2025 | { |
||
14991 | cbradney | 2026 | m_Doc->setPageSize(attrs.valueAsString("PAGESIZE")); |
2027 | m_Doc->setPageOrientation(attrs.valueAsInt("ORIENTATION", 0)); |
||
13971 | jghali | 2028 | m_Doc->FirstPnum = attrs.valueAsInt("FIRSTNUM", 1); |
15407 | craig | 2029 | m_Doc->setPagePositioning(attrs.valueAsInt("BOOK", 0)); |
13971 | jghali | 2030 | |
2031 | m_Doc->setUsesAutomaticTextFrames( attrs.valueAsInt("AUTOTEXT") ); |
||
2032 | m_Doc->PageSp = attrs.valueAsInt("AUTOSPALTEN"); |
||
2033 | m_Doc->PageSpa = attrs.valueAsDouble("ABSTSPALTEN"); |
||
2034 | m_Doc->setUnitIndex( attrs.valueAsInt("UNITS", 0) ); |
||
2035 | |||
17798 | craig | 2036 | //m_Doc->setHyphLanguage(attrs.valueAsString("LANGUAGE", "en_US")); |
2037 | static const QString LANGUAGE("LANGUAGE"); |
||
2038 | if (attrs.hasAttribute(LANGUAGE)) |
||
2039 | { |
||
2040 | QString l(attrs.valueAsString(LANGUAGE)); |
||
2041 | if (LanguageManager::instance()->langTableIndex(l)!=-1) |
||
2042 | m_Doc->setHyphLanguage(l); //new style storage |
||
2043 | else |
||
2044 | { //old style storage |
||
2045 | QString lnew=LanguageManager::instance()->getAbbrevFromLang(l, true, false); |
||
2046 | if (lnew.isEmpty()) |
||
2047 | lnew=LanguageManager::instance()->getAbbrevFromLang(l, false, false); |
||
2048 | m_Doc->setHyphLanguage(lnew); |
||
2049 | } |
||
2050 | } |
||
2051 | |||
2052 | |||
2053 | |||
14924 | cbradney | 2054 | m_Doc->setHyphMinimumWordLength(attrs.valueAsInt("MINWORDLEN", 3)); |
2055 | m_Doc->setHyphConsecutiveLines(attrs.valueAsInt("HYCOUNT", 2)); |
||
13971 | jghali | 2056 | |
2057 | if (attrs.hasAttribute("PAGEWIDTH")) |
||
14991 | cbradney | 2058 | m_Doc->setPageWidth(attrs.valueAsDouble("PAGEWIDTH")); |
13971 | jghali | 2059 | else |
14991 | cbradney | 2060 | m_Doc->setPageWidth(attrs.valueAsDouble("PAGEWITH")); |
2061 | m_Doc->setPageHeight(attrs.valueAsDouble("PAGEHEIGHT")); |
||
14994 | cbradney | 2062 | m_Doc->margins()->Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT")); |
2063 | m_Doc->margins()->Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT")); |
||
2064 | m_Doc->margins()->Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP")) |