Rev 14150 | Rev 14170 | 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" |
||
14 | #include "pageitem_latexframe.h" |
||
15 | #include "prefsmanager.h" |
||
16 | #include "scclocale.h" |
||
17 | #include "scconfig.h" |
||
18 | #include "sccolorengine.h" |
||
19 | #include "scpattern.h" |
||
20 | #include "scribuscore.h" |
||
21 | #include "scribusdoc.h" |
||
22 | #include "scribusview.h" |
||
23 | #include "sctextstream.h" |
||
24 | #include "scxmlstreamreader.h" |
||
25 | #include "undomanager.h" |
||
26 | #include "units.h" |
||
27 | #include "util.h" |
||
28 | #include "util_math.h" |
||
29 | #include "util_color.h" |
||
30 | #include "scgzfile.h" |
||
31 | #ifdef HAVE_OSG |
||
32 | #include "pageitem_osgframe.h" |
||
33 | #endif |
||
34 | #include <QCursor> |
||
35 | // #include <QDebug> |
||
36 | #include <QFileInfo> |
||
37 | #include <QList> |
||
38 | #include <QByteArray> |
||
39 | #include <QApplication> |
||
40 | |||
41 | |||
42 | // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods |
||
43 | // do. That documentatation is not duplicated here. |
||
44 | // Please don't implement the functionality of your plugin here; do that |
||
45 | // in scribus150formatimpl.h and scribus150formatimpl.cpp . |
||
46 | |||
47 | Scribus150Format::Scribus150Format() : |
||
48 | LoadSavePlugin() |
||
49 | { |
||
50 | // Set action info in languageChange, so we only have to do |
||
51 | // it in one place. This includes registering file formats. |
||
52 | languageChange(); |
||
53 | } |
||
54 | |||
55 | Scribus150Format::~Scribus150Format() |
||
56 | { |
||
57 | unregisterAll(); |
||
58 | }; |
||
59 | |||
60 | void Scribus150Format::languageChange() |
||
61 | { |
||
62 | //(Re)register file formats. |
||
63 | unregisterAll(); |
||
64 | registerFormats(); |
||
65 | } |
||
66 | |||
67 | const QString Scribus150Format::fullTrName() const |
||
68 | { |
||
69 | return QObject::tr("Scribus 1.3.4+ Support"); |
||
70 | } |
||
71 | |||
72 | const ScActionPlugin::AboutData* Scribus150Format::getAboutData() const |
||
73 | { |
||
74 | AboutData* about = new AboutData; |
||
75 | Q_CHECK_PTR(about); |
||
76 | about->authors = QString::fromUtf8( |
||
77 | "Franz Schmid <franz@scribus.info>, " |
||
78 | "The Scribus Team"); |
||
79 | about->shortDescription = tr("Scribus 1.3.4+ File Format Support"); |
||
80 | about->description = tr("Allows Scribus to read Scribus 1.3.4 and higher formatted files."); |
||
81 | // about->version |
||
82 | // about->releaseDate |
||
83 | // about->copyright |
||
84 | about->license = "GPL"; |
||
85 | return about; |
||
86 | } |
||
87 | |||
88 | void Scribus150Format::deleteAboutData(const AboutData* about) const |
||
89 | { |
||
90 | Q_ASSERT(about); |
||
91 | delete about; |
||
92 | } |
||
93 | |||
94 | void Scribus150Format::registerFormats() |
||
95 | { |
||
96 | FileFormat fmt(this); |
||
97 | fmt.trName = tr("Scribus 1.5.0+ Document"); |
||
98 | fmt.formatId = FORMATID_SLA150IMPORT; |
||
99 | fmt.load = true; |
||
100 | fmt.save = true; |
||
101 | fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)"; |
||
102 | fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive); |
||
103 | fmt.mimeTypes = QStringList(); |
||
104 | fmt.mimeTypes.append("application/x-scribus"); |
||
105 | fmt.priority = 64; |
||
106 | registerFormat(fmt); |
||
107 | } |
||
108 | |||
109 | bool Scribus150Format::fileSupported(QIODevice* /* file */, const QString & fileName) const |
||
110 | { |
||
111 | QByteArray docBytes(""); |
||
112 | if(fileName.right(2) == "gz") |
||
113 | { |
||
114 | if (!ScGzFile::readFromFile(fileName, docBytes, 4096)) |
||
115 | { |
||
116 | // FIXME: Needs better error return |
||
117 | return false; |
||
118 | } |
||
119 | } |
||
120 | else |
||
121 | { |
||
122 | // Not gzip encoded, just load it |
||
123 | loadRawText(fileName, docBytes); |
||
124 | } |
||
125 | // if (docBytes.left(16) == "<SCRIBUSUTF8NEW " && docBytes.left(35).contains("Version=\"1.3.4")) |
||
126 | // return true; |
||
127 | int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW "); |
||
128 | return startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0)); |
||
129 | } |
||
130 | |||
131 | QString Scribus150Format::readSLA(const QString & fileName) |
||
132 | { |
||
133 | QByteArray docBytes(""); |
||
134 | if(fileName.right(2) == "gz") |
||
135 | { |
||
136 | if (!ScGzFile::readFromFile(fileName, docBytes)) |
||
137 | { |
||
138 | // FIXME: Needs better error return |
||
139 | return false; |
||
140 | } |
||
141 | } |
||
142 | else |
||
143 | { |
||
144 | // Not gzip encoded, just load it |
||
145 | loadRawText(fileName, docBytes); |
||
146 | } |
||
147 | QString docText(""); |
||
148 | int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW "); |
||
149 | if (startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0))) |
||
150 | docText = QString::fromUtf8(docBytes); |
||
151 | else |
||
152 | return QString::null; |
||
153 | if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13))) |
||
154 | docText.truncate(docText.length()-1); |
||
155 | return docText; |
||
156 | } |
||
157 | |||
158 | void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces) |
||
159 | { |
||
160 | getNewReplacement=false; |
||
161 | getReplacedFonts.clear(); |
||
162 | } |
||
163 | |||
164 | bool Scribus150Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */) |
||
165 | { |
||
166 | if (m_Doc==0 || m_AvailableFonts==0) |
||
167 | { |
||
168 | Q_ASSERT(m_Doc==0 || m_AvailableFonts==0); |
||
169 | return false; |
||
170 | } |
||
171 | ParagraphStyle vg; |
||
172 | struct ScribusDoc::BookMa bok; |
||
173 | QMap<int, ScribusDoc::BookMa> bookmarks; |
||
174 | |||
175 | bool newVersion = false; |
||
176 | |||
177 | QMap<int,int> TableID; |
||
178 | QMap<int,int> TableIDM; |
||
179 | QMap<int,int> TableIDF; |
||
180 | QList<PageItem*> TableItems; |
||
181 | QList<PageItem*> TableItemsM; |
||
182 | QList<PageItem*> TableItemsF; |
||
183 | QMap<PageItem*, int> groupID; |
||
184 | QMap<PageItem*, int> groupIDM; |
||
185 | QMap<PageItem*, int> groupIDF; |
||
186 | |||
187 | QString f(readSLA(fileName)); |
||
188 | if (f.isEmpty()) |
||
189 | return false; |
||
190 | QString fileDir = QFileInfo(fileName).absolutePath(); |
||
191 | int firstPage = 0; |
||
192 | int layerToSetActive = 0; |
||
193 | ScColor lf = ScColor(); |
||
194 | |||
195 | if (m_mwProgressBar!=0) |
||
196 | { |
||
197 | m_mwProgressBar->setMaximum(f.length()); |
||
198 | m_mwProgressBar->setValue(0); |
||
199 | } |
||
200 | // Stop autosave timer,it will be restarted only if doc has autosave feature is enabled |
||
201 | if (m_Doc->autoSaveTimer->isActive()) |
||
202 | m_Doc->autoSaveTimer->stop(); |
||
203 | |||
204 | groupRemap.clear(); |
||
205 | itemRemap.clear(); |
||
206 | itemNext.clear(); |
||
207 | itemCount = 0; |
||
208 | itemRemapM.clear(); |
||
209 | itemNextM.clear(); |
||
210 | itemCountM = 0; |
||
211 | itemRemapF.clear(); |
||
212 | itemNextF.clear(); |
||
213 | |||
214 | TableItems.clear(); |
||
215 | TableID.clear(); |
||
216 | TableItemsM.clear(); |
||
217 | TableIDM.clear(); |
||
218 | TableItemsF.clear(); |
||
219 | TableIDF.clear(); |
||
220 | |||
221 | m_Doc->GroupCounter = 1; |
||
222 | m_Doc->LastAuto = 0; |
||
223 | m_Doc->PageColors.clear(); |
||
224 | m_Doc->Layers.clear(); |
||
225 | |||
226 | bool firstElement = true; |
||
227 | bool success = true; |
||
228 | bool hasPageSets = false; |
||
229 | int progress = 0; |
||
230 | |||
231 | ScXmlStreamReader reader(f); |
||
232 | ScXmlStreamAttributes attrs; |
||
233 | while(!reader.atEnd() && !reader.hasError()) |
||
234 | { |
||
235 | QXmlStreamReader::TokenType tType = reader.readNext(); |
||
236 | if (tType != QXmlStreamReader::StartElement) |
||
237 | continue; |
||
238 | QStringRef tagName = reader.name(); |
||
239 | attrs = reader.scAttributes(); |
||
240 | |||
241 | if (m_mwProgressBar != 0) |
||
242 | { |
||
243 | int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100); |
||
244 | if (newProgress != progress) |
||
245 | { |
||
246 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
247 | progress = newProgress; |
||
248 | } |
||
249 | } |
||
250 | |||
251 | if (firstElement) |
||
252 | { |
||
253 | if (tagName != "SCRIBUSUTF8NEW") |
||
254 | { |
||
255 | success = false; |
||
256 | break; |
||
257 | } |
||
258 | if (attrs.hasAttribute("Version")) |
||
259 | newVersion = true; |
||
260 | firstElement = false; |
||
261 | } |
||
262 | if (tagName == "DOCUMENT") |
||
263 | { |
||
264 | readDocAttributes(m_Doc, attrs); |
||
265 | layerToSetActive = attrs.valueAsInt("ALAYER", 0); |
||
266 | if (m_Doc->currentPageLayout == 0) |
||
267 | firstPage = 0; |
||
268 | else |
||
269 | { |
||
270 | if (attrs.valueAsInt("FIRSTLEFT", 0) == 1) |
||
271 | firstPage = 0; |
||
272 | else |
||
273 | firstPage = 1; |
||
274 | } |
||
275 | if (attrs.hasAttribute("currentProfile")) |
||
276 | { |
||
277 | m_Doc->checkerProfiles.clear(); |
||
278 | m_Doc->curCheckProfile = attrs.valueAsString("currentProfile"); |
||
279 | } |
||
280 | } |
||
281 | if (tagName == "CheckProfile") |
||
282 | { |
||
283 | success = readCheckProfile(m_Doc, attrs); |
||
284 | if (!success) break; |
||
285 | } |
||
286 | if (tagName == "PageSets") |
||
287 | { |
||
288 | success = readPageSets(m_Doc, reader); |
||
289 | if (!success) break; |
||
290 | hasPageSets = true; |
||
291 | } |
||
292 | // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file... |
||
293 | if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None) |
||
294 | { |
||
295 | success = readColor(m_Doc->PageColors, attrs); |
||
296 | if (!success) break; |
||
297 | } |
||
14150 | fschmid | 298 | if (tagName == "Gradient") |
299 | { |
||
300 | VGradient gra; |
||
301 | QString grName = attrs.valueAsString("Name"); |
||
302 | success = readGradient(m_Doc, gra, reader); |
||
303 | if (!success) break; |
||
304 | if (!grName.isEmpty()) |
||
305 | { |
||
306 | m_Doc->docGradients.insert(grName, gra); |
||
307 | } |
||
308 | } |
||
13971 | jghali | 309 | if (tagName == "STYLE") |
310 | { |
||
311 | readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts); |
||
312 | StyleSet<ParagraphStyle>tmp; |
||
313 | tmp.create(vg); |
||
314 | m_Doc->redefineStyles(tmp, false); |
||
315 | } |
||
316 | if (tagName == "CHARSTYLE") |
||
317 | { |
||
318 | readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts); |
||
319 | StyleSet<CharStyle> temp; |
||
320 | temp.create(vg.charStyle()); |
||
321 | m_Doc->redefineCharStyles(temp, false); |
||
322 | } |
||
323 | if (tagName == "JAVA") |
||
324 | { |
||
325 | QString name = attrs.valueAsString("NAME"); |
||
326 | if (!name.isEmpty()) |
||
327 | m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT"); |
||
328 | } |
||
329 | if (tagName == "LAYERS") |
||
330 | { |
||
331 | ScLayer newLayer; |
||
332 | readLayers(newLayer, attrs); |
||
333 | m_Doc->Layers.append(newLayer); |
||
334 | } |
||
335 | if (tagName == "Arrows") |
||
336 | { |
||
337 | success = readArrows(m_Doc, attrs); |
||
338 | if (!success) break; |
||
339 | } |
||
340 | if (tagName == "MultiLine") |
||
341 | { |
||
342 | multiLine ml; |
||
343 | QString mlName = attrs.valueAsString("Name"); |
||
344 | success = readMultiline(ml, reader); |
||
345 | if (!success) break; |
||
346 | if (!mlName.isEmpty()) |
||
347 | { |
||
348 | m_Doc->MLineStyles.insert(mlName, ml); |
||
349 | } |
||
350 | } |
||
351 | if (tagName == "Bookmark") |
||
352 | { |
||
353 | int bmElem = 0; |
||
354 | struct ScribusDoc::BookMa bookmark; |
||
355 | success = readBookMark(bookmark, bmElem, attrs); |
||
356 | if (!success) break; |
||
357 | bookmarks.insert(bmElem, bookmark); |
||
358 | } |
||
359 | if (tagName == "PDF") |
||
360 | { |
||
361 | success = readPDFOptions(m_Doc, reader); |
||
362 | if (!success) break; |
||
363 | } |
||
364 | if (tagName == "Printer") |
||
365 | { |
||
366 | success = readPrinterOptions(m_Doc, reader); |
||
367 | if (!success) break; |
||
368 | } |
||
369 | if (tagName == "DocItemAttributes") |
||
370 | { |
||
371 | success = readDocItemAttributes(m_Doc, reader); |
||
372 | if (!success) break; |
||
373 | } |
||
374 | if (tagName == "TablesOfContents") |
||
375 | { |
||
376 | success = readTableOfContents(m_Doc, reader); |
||
377 | if (!success) break; |
||
378 | } |
||
379 | if (tagName == "Sections") |
||
380 | { |
||
381 | success = readSections(m_Doc, reader); |
||
382 | if (!success) break; |
||
383 | } |
||
384 | if (tagName == "HYPHEN") |
||
385 | { |
||
386 | success = readHyphen(m_Doc, reader); |
||
387 | if (!success) break; |
||
388 | } |
||
389 | if (tagName == "PAGE" || tagName == "MASTERPAGE") |
||
390 | { |
||
391 | success = readPage(m_Doc, reader); |
||
392 | if (!success) break; |
||
393 | } |
||
394 | if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT") |
||
395 | { |
||
396 | ItemInfo itemInfo; |
||
397 | success = readObject(m_Doc, reader, itemInfo, fileDir, false); |
||
398 | if (!success) break; |
||
399 | |||
400 | // first of linked chain? |
||
401 | if (tagName == "PAGEOBJECT") |
||
402 | { |
||
403 | if (itemInfo.nextItem != -1) |
||
404 | itemNext[itemInfo.item->ItemNr] = itemInfo.nextItem; |
||
405 | } |
||
406 | else if (tagName == "MASTEROBJECT") |
||
407 | { |
||
408 | if (itemInfo.nextItem != -1) |
||
409 | itemNextM[itemInfo.item->ItemNr] = itemInfo.nextItem; |
||
410 | } |
||
411 | /* not sure if we want that... |
||
412 | else if (tagName == "FRAMEOBJECT") |
||
413 | { |
||
414 | if (itemInfo.nextItem != -1) |
||
415 | itemNextF[itemInfo.item->ItemNr] = itemInfo.nextItem; |
||
416 | }*/ |
||
417 | |||
418 | if (itemInfo.item->isTableItem) |
||
419 | { |
||
420 | if (tagName == "PAGEOBJECT") |
||
421 | { |
||
422 | TableItems.append(itemInfo.item); |
||
423 | TableID.insert(itemInfo.ownLink, itemInfo.item->ItemNr); |
||
424 | } |
||
425 | else if (tagName == "FRAMEOBJECT") |
||
426 | { |
||
427 | TableItemsF.append(itemInfo.item); |
||
428 | TableIDF.insert(itemInfo.ownLink, itemInfo.item->ItemNr); |
||
429 | } |
||
430 | else |
||
431 | { |
||
432 | TableItemsM.append(itemInfo.item); |
||
433 | TableIDM.insert(itemInfo.ownLink, itemInfo.item->ItemNr); |
||
434 | } |
||
435 | } |
||
436 | if (itemInfo.item->isGroupControl) |
||
437 | { |
||
438 | if (tagName == "PAGEOBJECT") |
||
439 | groupID.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr); |
||
440 | else if (tagName == "FRAMEOBJECT") |
||
441 | groupIDF.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr); |
||
442 | else |
||
443 | groupIDM.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr); |
||
444 | } |
||
445 | } |
||
446 | if (tagName == "Pattern") |
||
447 | { |
||
448 | success = readPattern(m_Doc, reader, fileDir); |
||
449 | if (!success) break; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | if (reader.hasError()) |
||
454 | return false; |
||
455 | |||
456 | QMap<int, ScribusDoc::BookMa>::Iterator it; |
||
457 | for (it = bookmarks.begin(); it != bookmarks.end(); ++it) |
||
458 | { |
||
459 | int elem = it.key(); |
||
460 | if (elem < m_Doc->Items->count()) |
||
461 | { |
||
462 | ScribusDoc::BookMa bookmark = it.value(); |
||
463 | bookmark.PageObject = m_Doc->Items->at(elem); |
||
464 | m_Doc->BookMarks.append( bookmark ); |
||
465 | } |
||
466 | } |
||
467 | |||
468 | if (TableItemsF.count() != 0) |
||
469 | { |
||
470 | for (int ttc = 0; ttc < TableItemsF.count(); ++ttc) |
||
471 | { |
||
472 | PageItem* ta = TableItemsF.at(ttc); |
||
473 | if (ta->TopLinkID != -1) |
||
474 | ta->TopLink = m_Doc->FrameItems.at(TableIDF[ta->TopLinkID]); |
||
475 | else |
||
476 | ta->TopLink = 0; |
||
477 | if (ta->LeftLinkID != -1) |
||
478 | ta->LeftLink = m_Doc->FrameItems.at(TableIDF[ta->LeftLinkID]); |
||
479 | else |
||
480 | ta->LeftLink = 0; |
||
481 | if (ta->RightLinkID != -1) |
||
482 | ta->RightLink = m_Doc->FrameItems.at(TableIDF[ta->RightLinkID]); |
||
483 | else |
||
484 | ta->RightLink = 0; |
||
485 | if (ta->BottomLinkID != -1) |
||
486 | ta->BottomLink = m_Doc->FrameItems.at(TableIDF[ta->BottomLinkID]); |
||
487 | else |
||
488 | ta->BottomLink = 0; |
||
489 | } |
||
490 | } |
||
491 | if (TableItemsM.count() != 0) |
||
492 | { |
||
493 | for (int ttc = 0; ttc < TableItemsM.count(); ++ttc) |
||
494 | { |
||
495 | PageItem* ta = TableItemsM.at(ttc); |
||
496 | if (ta->TopLinkID != -1) |
||
497 | ta->TopLink = m_Doc->MasterItems.at(TableIDM[ta->TopLinkID]); |
||
498 | else |
||
499 | ta->TopLink = 0; |
||
500 | if (ta->LeftLinkID != -1) |
||
501 | ta->LeftLink = m_Doc->MasterItems.at(TableIDM[ta->LeftLinkID]); |
||
502 | else |
||
503 | ta->LeftLink = 0; |
||
504 | if (ta->RightLinkID != -1) |
||
505 | ta->RightLink = m_Doc->MasterItems.at(TableIDM[ta->RightLinkID]); |
||
506 | else |
||
507 | ta->RightLink = 0; |
||
508 | if (ta->BottomLinkID != -1) |
||
509 | ta->BottomLink = m_Doc->MasterItems.at(TableIDM[ta->BottomLinkID]); |
||
510 | else |
||
511 | ta->BottomLink = 0; |
||
512 | } |
||
513 | } |
||
514 | if (TableItems.count() != 0) |
||
515 | { |
||
516 | for (int ttc = 0; ttc < TableItems.count(); ++ttc) |
||
517 | { |
||
518 | PageItem* ta = TableItems.at(ttc); |
||
519 | if (ta->TopLinkID != -1) |
||
520 | ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]); |
||
521 | else |
||
522 | ta->TopLink = 0; |
||
523 | if (ta->LeftLinkID != -1) |
||
524 | ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]); |
||
525 | else |
||
526 | ta->LeftLink = 0; |
||
527 | if (ta->RightLinkID != -1) |
||
528 | ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]); |
||
529 | else |
||
530 | ta->RightLink = 0; |
||
531 | if (ta->BottomLinkID != -1) |
||
532 | ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]); |
||
533 | else |
||
534 | ta->BottomLink = 0; |
||
535 | } |
||
536 | } |
||
537 | if (groupIDF.count() != 0) |
||
538 | { |
||
539 | QMap<PageItem*, int>::Iterator it; |
||
540 | for (it = groupIDF.begin(); it != groupIDF.end(); ++it) |
||
541 | { |
||
542 | it.key()->groupsLastItem = m_Doc->FrameItems.at(it.value()); |
||
543 | } |
||
544 | } |
||
545 | if (groupID.count() != 0) |
||
546 | { |
||
547 | QMap<PageItem*, int>::Iterator it; |
||
548 | for (it = groupID.begin(); it != groupID.end(); ++it) |
||
549 | { |
||
550 | it.key()->groupsLastItem = m_Doc->DocItems.at(it.value()); |
||
551 | } |
||
552 | } |
||
553 | if (groupIDM.count() != 0) |
||
554 | { |
||
555 | QMap<PageItem*, int>::Iterator it; |
||
556 | for (it = groupIDM.begin(); it != groupIDM.end(); ++it) |
||
557 | { |
||
558 | it.key()->groupsLastItem = m_Doc->MasterItems.at(it.value()); |
||
559 | } |
||
560 | } |
||
561 | //CB Add this in to set this in the file in memory. Its saved, why not load it. |
||
562 | //Will of course be replaced by per page settings although we still probably need a document default |
||
563 | if (!hasPageSets) |
||
564 | { |
||
565 | m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = firstPage; |
||
566 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble(); |
||
567 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0; |
||
568 | // m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble(); |
||
569 | } |
||
570 | m_Doc->setActiveLayer(layerToSetActive); |
||
571 | m_Doc->setMasterPageMode(false); |
||
572 | m_Doc->reformPages(); |
||
573 | |||
574 | if (m_Doc->Layers.count() == 0) |
||
575 | m_Doc->Layers.newLayer( QObject::tr("Background") ); |
||
576 | |||
577 | // reestablish textframe links |
||
578 | if (itemNext.count() != 0) |
||
579 | { |
||
580 | QMap<int,int>::Iterator lc; |
||
581 | for (lc = itemNext.begin(); lc != itemNext.end(); ++lc) |
||
582 | { |
||
583 | if (lc.value() >= 0) |
||
584 | { |
||
585 | PageItem * Its = m_Doc->DocItems.at(lc.key()); |
||
586 | PageItem * Itn = m_Doc->DocItems.at(lc.value()); |
||
587 | if (Itn->prevInChain() || Its->nextInChain()) |
||
588 | { |
||
589 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
590 | continue; |
||
591 | } |
||
592 | Its->link(Itn); |
||
593 | } |
||
594 | } |
||
595 | } |
||
596 | |||
597 | if (itemNextM.count() != 0) |
||
598 | { |
||
599 | QMap<int,int>::Iterator lc; |
||
600 | for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc) |
||
601 | { |
||
602 | if (lc.value() >= 0) |
||
603 | { |
||
604 | PageItem * Its = m_Doc->MasterItems.at(lc.key()); |
||
605 | PageItem * Itn = m_Doc->MasterItems.at(lc.value()); |
||
606 | if (Itn->prevInChain() || Its->nextInChain()) |
||
607 | { |
||
608 | qDebug() << "scribus150format: corruption in linked textframes detected"; |
||
609 | continue; |
||
610 | } |
||
611 | Its->link(Itn); |
||
612 | } |
||
613 | } |
||
614 | } |
||
615 | |||
616 | // reestablish first/lastAuto |
||
617 | m_Doc->FirstAuto = m_Doc->LastAuto; |
||
618 | if (m_Doc->LastAuto) |
||
619 | { |
||
620 | while (m_Doc->LastAuto->nextInChain()) |
||
621 | m_Doc->LastAuto = m_Doc->LastAuto->nextInChain(); |
||
622 | while (m_Doc->FirstAuto->prevInChain()) |
||
623 | m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain(); |
||
624 | } |
||
625 | |||
626 | // start auto save timer if needed |
||
627 | if (m_Doc->AutoSave && ScCore->usingGUI()) |
||
628 | m_Doc->autoSaveTimer->start(m_Doc->AutoSaveTime); |
||
629 | |||
630 | if (m_mwProgressBar!=0) |
||
631 | m_mwProgressBar->setValue(reader.characterOffset()); |
||
632 | return true; |
||
633 | // return false; |
||
634 | } |
||
635 | |||
636 | // Low level plugin API |
||
637 | int scribus150format_getPluginAPIVersion() |
||
638 | { |
||
639 | return PLUGIN_API_VERSION; |
||
640 | } |
||
641 | |||
642 | ScPlugin* scribus150format_getPlugin() |
||
643 | { |
||
644 | Scribus150Format* plug = new Scribus150Format(); |
||
645 | Q_CHECK_PTR(plug); |
||
646 | return plug; |
||
647 | } |
||
648 | |||
649 | void scribus150format_freePlugin(ScPlugin* plugin) |
||
650 | { |
||
651 | Scribus150Format* plug = dynamic_cast<Scribus150Format*>(plugin); |
||
652 | Q_ASSERT(plug); |
||
653 | delete plug; |
||
654 | } |
||
655 | |||
656 | |||
657 | namespace { |
||
658 | const int NOVALUE = -16000; |
||
659 | |||
660 | void fixLegacyCharStyle(CharStyle& cstyle) |
||
661 | { |
||
662 | if (! cstyle.font().usable()) |
||
663 | cstyle.resetFont(); |
||
664 | if (cstyle.fontSize() <= -16000 / 10) |
||
665 | cstyle.resetFontSize(); |
||
666 | // if (cstyle.effects() == 65535) |
||
667 | // cstyle.resetEffects(); |
||
668 | if (cstyle.fillColor().isEmpty()) |
||
669 | cstyle.resetFillColor(); |
||
670 | if (cstyle.fillShade() <= -16000) |
||
671 | cstyle.resetFillShade(); |
||
672 | if (cstyle.strokeColor().isEmpty()) |
||
673 | cstyle.resetStrokeColor(); |
||
674 | if (cstyle.strokeShade() <= -16000) |
||
675 | cstyle.resetStrokeShade(); |
||
676 | if (cstyle.shadowXOffset() <= -16000 / 10) |
||
677 | cstyle.resetShadowXOffset(); |
||
678 | if (cstyle.shadowYOffset() <= -16000 / 10) |
||
679 | cstyle.resetShadowYOffset(); |
||
680 | if (cstyle.outlineWidth() <= -16000 / 10) |
||
681 | cstyle.resetOutlineWidth(); |
||
682 | if (cstyle.underlineOffset() <= -16000 / 10) |
||
683 | cstyle.resetUnderlineOffset(); |
||
684 | if (cstyle.underlineWidth() <= -16000 / 10) |
||
685 | cstyle.resetUnderlineWidth(); |
||
686 | if (cstyle.strikethruOffset() <= -16000 / 10) |
||
687 | cstyle.resetStrikethruOffset(); |
||
688 | if (cstyle.strikethruWidth() <= -16000 / 10) |
||
689 | cstyle.resetStrikethruWidth(); |
||
690 | if (cstyle.scaleH() <= -16000 / 10) |
||
691 | cstyle.resetScaleH(); |
||
692 | if (cstyle.scaleV() <= -16000 / 10) |
||
693 | cstyle.resetScaleV(); |
||
694 | if (cstyle.baselineOffset() <= -16000 / 10) |
||
695 | cstyle.resetBaselineOffset(); |
||
696 | if (cstyle.tracking() <= -16000 / 10) |
||
697 | cstyle.resetTracking(); |
||
698 | } |
||
699 | |||
700 | void fixLegacyParStyle(ParagraphStyle& pstyle) |
||
701 | { |
||
702 | if (pstyle.lineSpacing() <= -16000) |
||
703 | pstyle.resetLineSpacing(); |
||
704 | if (pstyle.leftMargin() <= -16000) |
||
705 | pstyle.resetLeftMargin(); |
||
706 | if (pstyle.rightMargin() <= -16000) |
||
707 | pstyle.resetRightMargin(); |
||
708 | if (pstyle.firstIndent() <= -16000) |
||
709 | pstyle.resetFirstIndent(); |
||
710 | if (pstyle.alignment() < 0) |
||
711 | pstyle.resetAlignment(); |
||
712 | if (pstyle.gapBefore() <= -16000) |
||
713 | pstyle.resetGapBefore(); |
||
714 | if (pstyle.gapAfter() <= -16000) |
||
715 | pstyle.resetGapAfter(); |
||
716 | if (pstyle.dropCapLines() < 0) |
||
717 | pstyle.resetDropCapLines(); |
||
718 | if (pstyle.dropCapOffset() <= -16000) |
||
719 | pstyle.resetDropCapOffset(); |
||
720 | fixLegacyCharStyle(pstyle.charStyle()); |
||
721 | } |
||
722 | |||
723 | }// namespace |
||
724 | |||
725 | void Scribus150Format::readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
726 | { |
||
727 | m_Doc->m_pageSize = attrs.valueAsString("PAGESIZE"); |
||
728 | m_Doc->PageOri = attrs.valueAsInt("ORIENTATION", 0); |
||
729 | m_Doc->FirstPnum = attrs.valueAsInt("FIRSTNUM", 1); |
||
730 | m_Doc->currentPageLayout = attrs.valueAsInt("BOOK", 0); |
||
731 | |||
732 | m_Doc->setUsesAutomaticTextFrames( attrs.valueAsInt("AUTOTEXT") ); |
||
733 | m_Doc->PageSp = attrs.valueAsInt("AUTOSPALTEN"); |
||
734 | m_Doc->PageSpa = attrs.valueAsDouble("ABSTSPALTEN"); |
||
735 | m_Doc->setUnitIndex( attrs.valueAsInt("UNITS", 0) ); |
||
736 | |||
737 | m_Doc->Language = attrs.valueAsString("LANGUAGE", ""); |
||
738 | m_Doc->MinWordLen = attrs.valueAsInt("MINWORDLEN", 3); |
||
739 | m_Doc->HyCount = attrs.valueAsInt("HYCOUNT", 2); |
||
740 | |||
741 | if (attrs.hasAttribute("PAGEWIDTH")) |
||
742 | m_Doc->pageWidth = attrs.valueAsDouble("PAGEWIDTH"); |
||
743 | else |
||
744 | m_Doc->pageWidth = attrs.valueAsDouble("PAGEWITH"); |
||
745 | m_Doc->pageHeight = attrs.valueAsDouble("PAGEHEIGHT"); |
||
746 | m_Doc->pageMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT")); |
||
747 | m_Doc->pageMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT")); |
||
748 | m_Doc->pageMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP")); |
||
749 | m_Doc->pageMargins.Bottom= qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM")); |
||
750 | m_Doc->marginPreset = attrs.valueAsInt("PRESET", 0); |
||
751 | m_Doc->bleeds.Top = attrs.valueAsDouble("BleedTop", 0.0); |
||
752 | m_Doc->bleeds.Left = attrs.valueAsDouble("BleedLeft", 0.0); |
||
753 | m_Doc->bleeds.Right = attrs.valueAsDouble("BleedRight", 0.0); |
||
754 | m_Doc->bleeds.Bottom = attrs.valueAsDouble("BleedBottom", 0.0); |
||
755 | m_Doc->Automatic = attrs.valueAsBool("AUTOMATIC", true); |
||
756 | m_Doc->AutoCheck = attrs.valueAsBool("AUTOCHECK", false); |
||
757 | m_Doc->GuideLock = attrs.valueAsBool("GUIDELOCK", false); |
||
758 | |||
759 | m_Doc->rulerXoffset = attrs.valueAsDouble("rulerXoffset", 0.0); |
||
760 | m_Doc->rulerYoffset = attrs.valueAsDouble("rulerYoffset", 0.0); |
||
761 | m_Doc->SnapGuides = attrs.valueAsBool("SnapToGuides", false); |
||
762 | m_Doc->useRaster = attrs.valueAsBool("SnapToGrid", false); |
||
763 | |||
764 | m_Doc->AutoSave = attrs.valueAsBool("AutoSave", false); |
||
765 | m_Doc->AutoSaveTime = attrs.valueAsInt("AutoSaveTime", 600000); |
||
766 | m_Doc->scratch.Bottom = attrs.valueAsDouble("ScratchBottom", 20.0); |
||
767 | // FIXME A typo in early 1.3cvs (MAR 05) means we must support loading of |
||
768 | // FIXME 'ScatchLeft' for a while too. This can be removed in a few months. |
||
769 | if (attrs.hasAttribute("ScatchLeft")) |
||
770 | m_Doc->scratch.Left = attrs.valueAsDouble("ScatchLeft", 100.0); |
||
771 | else |
||
772 | m_Doc->scratch.Left = attrs.valueAsDouble("ScratchLeft", 100.0); |
||
773 | m_Doc->scratch.Right = attrs.valueAsDouble("ScratchRight", 100.0); |
||
774 | m_Doc->scratch.Top = attrs.valueAsDouble("ScratchTop", 20.0); |
||
775 | m_Doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", -1.0); |
||
776 | m_Doc->GapVertical = attrs.valueAsDouble("GapVertical", -1.0); |
||
777 | |||
778 | if (attrs.hasAttribute("PAGEC")) |
||
779 | m_Doc->papColor = QColor(attrs.valueAsString("PAGEC")); |
||
780 | |||
781 | m_Doc->marginColored = attrs.valueAsBool("RANDF", false); |
||
782 | |||
783 | readCMSSettings(doc, attrs); |
||
784 | readDocumentInfo(doc, attrs); |
||
785 | readGuideSettings(doc, attrs); |
||
786 | readToolSettings(doc, attrs); |
||
787 | readTypographicSettings(doc, attrs); |
||
788 | } |
||
789 | |||
790 | void Scribus150Format::readCMSSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
791 | { |
||
792 | doc->CMSSettings.SoftProofOn = attrs.valueAsBool("DPSo", false); |
||
793 | doc->CMSSettings.SoftProofFullOn = attrs.valueAsBool("DPSFo", false); |
||
794 | doc->CMSSettings.CMSinUse = attrs.valueAsBool("DPuse", false); |
||
795 | doc->CMSSettings.GamutCheck = attrs.valueAsBool("DPgam", false); |
||
796 | doc->CMSSettings.BlackPoint = attrs.valueAsBool("DPbla", true); |
||
797 | doc->CMSSettings.DefaultMonitorProfile = attrs.valueAsString("DPMo",""); |
||
798 | doc->CMSSettings.DefaultPrinterProfile = attrs.valueAsString("DPPr",""); |
||
799 | doc->CMSSettings.DefaultImageRGBProfile = attrs.valueAsString("DPIn",""); |
||
800 | doc->CMSSettings.DefaultImageCMYKProfile = attrs.valueAsString("DPInCMYK",""); |
||
801 | doc->CMSSettings.DefaultSolidColorRGBProfile = attrs.valueAsString("DPIn2",""); |
||
802 | if (attrs.hasAttribute("DPIn3")) |
||
803 | doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPIn3",""); |
||
804 | else |
||
805 | doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPPr",""); |
||
806 | doc->CMSSettings.DefaultIntentColors = attrs.valueAsInt("DISc", 1); |
||
807 | doc->CMSSettings.DefaultIntentImages = attrs.valueAsInt("DIIm", 0); |
||
808 | } |
||
809 | |||
810 | void Scribus150Format::readDocumentInfo(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
811 | { |
||
812 | doc->documentInfo.setAuthor(attrs.valueAsString("AUTHOR")); |
||
813 | doc->documentInfo.setComments(attrs.valueAsString("COMMENTS")); |
||
814 | doc->documentInfo.setKeywords(attrs.valueAsString("KEYWORDS","")); |
||
815 | doc->documentInfo.setTitle(attrs.valueAsString("TITLE")); |
||
816 | doc->documentInfo.setSubject(attrs.valueAsString("SUBJECT")); |
||
817 | doc->documentInfo.setPublisher(attrs.valueAsString("PUBLISHER", "")); |
||
818 | doc->documentInfo.setDate(attrs.valueAsString("DOCDATE", "")); |
||
819 | doc->documentInfo.setType(attrs.valueAsString("DOCTYPE", "")); |
||
820 | doc->documentInfo.setFormat(attrs.valueAsString("DOCFORMAT", "")); |
||
821 | doc->documentInfo.setIdent(attrs.valueAsString("DOCIDENT", "")); |
||
822 | doc->documentInfo.setSource(attrs.valueAsString("DOCSOURCE", "")); |
||
823 | doc->documentInfo.setLangInfo(attrs.valueAsString("DOCLANGINFO", "")); |
||
824 | doc->documentInfo.setRelation(attrs.valueAsString("DOCRELATION", "")); |
||
825 | doc->documentInfo.setCover(attrs.valueAsString("DOCCOVER", "")); |
||
826 | doc->documentInfo.setRights(attrs.valueAsString("DOCRIGHTS", "")); |
||
827 | doc->documentInfo.setContrib(attrs.valueAsString("DOCCONTRIB", "")); |
||
828 | } |
||
829 | |||
830 | void Scribus150Format::readGuideSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
831 | { |
||
832 | PrefsManager* prefsManager = PrefsManager::instance(); |
||
833 | doc->guidesSettings.minorGridSpacing = attrs.valueAsDouble("MINGRID", prefsManager->appPrefs.guidesPrefs.minorGridSpacing); |
||
834 | doc->guidesSettings.majorGridSpacing = attrs.valueAsDouble("MAJGRID", prefsManager->appPrefs.guidesPrefs.majorGridSpacing); |
||
835 | doc->guidesSettings.gridShown = attrs.valueAsBool("SHOWGRID", false); |
||
836 | doc->guidesSettings.guidesShown =attrs.valueAsBool("SHOWGUIDES", true); |
||
837 | doc->guidesSettings.colBordersShown = attrs.valueAsBool("showcolborders", false); |
||
838 | doc->guidesSettings.framesShown = attrs.valueAsBool("SHOWFRAME", true); |
||
839 | doc->guidesSettings.layerMarkersShown = attrs.valueAsBool("SHOWLAYERM", false); |
||
840 | doc->guidesSettings.marginsShown = attrs.valueAsBool("SHOWMARGIN", true); |
||
841 | doc->guidesSettings.baselineGridShown = attrs.valueAsBool("SHOWBASE", false); |
||
842 | doc->guidesSettings.showPic = attrs.valueAsBool("SHOWPICT", true); |
||
843 | doc->guidesSettings.linkShown = attrs.valueAsBool("SHOWLINK", false); |
||
844 | doc->guidesSettings.showControls = attrs.valueAsBool("SHOWControl", false); |
||
845 | doc->guidesSettings.rulerMode = attrs.valueAsBool("rulerMode", true); |
||
846 | doc->guidesSettings.rulersShown = attrs.valueAsBool("showrulers", true); |
||
847 | doc->guidesSettings.showBleed = attrs.valueAsBool("showBleed", true); |
||
848 | if (attrs.hasAttribute("MARGC")) |
||
849 | doc->guidesSettings.marginColor = QColor(attrs.valueAsString("MARGC")); |
||
850 | if (attrs.hasAttribute("MINORC")) |
||
851 | doc->guidesSettings.minorGridColor = QColor(attrs.valueAsString("MINORC")); |
||
852 | if (attrs.hasAttribute("MAJORC")) |
||
853 | doc->guidesSettings.majorGridColor = QColor(attrs.valueAsString("MAJORC")); |
||
854 | if (attrs.hasAttribute("GuideC")) |
||
855 | doc->guidesSettings.guideColor = QColor(attrs.valueAsString("GuideC")); |
||
856 | if (attrs.hasAttribute("BaseC")) |
||
857 | doc->guidesSettings.baselineGridColor = QColor(attrs.valueAsString("BaseC")); |
||
858 | doc->guidesSettings.guidePlacement = attrs.valueAsBool("BACKG", true); |
||
859 | doc->guidesSettings.guideRad = attrs.valueAsDouble("GuideRad", 10.0); |
||
860 | doc->guidesSettings.grabRadius = attrs.valueAsInt("GRAB", 4); |
||
861 | } |
||
862 | |||
863 | void Scribus150Format::readToolSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
864 | { |
||
13996 | cbradney | 865 | QString textFont = attrs.valueAsString("DFONT"); |
866 | m_AvailableFonts->findFont(textFont, doc); |
||
13971 | jghali | 867 | |
13996 | cbradney | 868 | doc->itemToolPrefs.textFont = textFont; |
869 | doc->itemToolPrefs.textSize = qRound(attrs.valueAsDouble("DSIZE", 12.0) * 10); |
||
870 | doc->itemToolPrefs.textColumns = attrs.valueAsInt("DCOL", 1); |
||
871 | doc->itemToolPrefs.textColumnGap = attrs.valueAsDouble("DGAP", 0.0); |
||
13971 | jghali | 872 | |
13996 | cbradney | 873 | doc->itemToolPrefs.polyCorners = attrs.valueAsInt("POLYC", 4); |
14022 | cbradney | 874 | doc->itemToolPrefs.polyFactor = attrs.valueAsDouble("POLYF", 0.5); |
13996 | cbradney | 875 | doc->itemToolPrefs.polyRotation = attrs.valueAsDouble("POLYR", 0.0); |
876 | doc->itemToolPrefs.polyCurvature = attrs.valueAsDouble("POLYCUR", 0.0); |
||
14027 | fschmid | 877 | doc->itemToolPrefs.polyFactorGuiVal = attrs.valueAsInt("POLYFD", 0); |
13996 | cbradney | 878 | doc->itemToolPrefs.polyUseFactor = attrs.valueAsBool("POLYS", false); |
13971 | jghali | 879 | |
13996 | cbradney | 880 | doc->itemToolPrefs.lineStartArrow = attrs.valueAsInt("StartArrow", 0); |
881 | doc->itemToolPrefs.lineEndArrow = attrs.valueAsInt("EndArrow", 0); |
||
882 | doc->itemToolPrefs.imageScaleX = attrs.valueAsDouble("PICTSCX", 1.0); |
||
883 | doc->itemToolPrefs.imageScaleY = attrs.valueAsDouble("PICTSCY", 1.0); |
||
884 | doc->itemToolPrefs.imageScaleType = attrs.valueAsBool("PSCALE", true); |
||
885 | doc->itemToolPrefs.imageAspectRatio = attrs.valueAsBool("PASPECT", false); |
||
886 | doc->itemToolPrefs.imageLowResType = attrs.valueAsInt("HalfRes", 1); |
||
887 | doc->itemToolPrefs.imageUseEmbeddedPath = attrs.valueAsBool("EmbeddedPath", false); |
||
13971 | jghali | 888 | if (attrs.hasAttribute("PEN")) |
14014 | cbradney | 889 | doc->itemToolPrefs.shapeLineColor = attrs.valueAsString("PEN"); |
13971 | jghali | 890 | if (attrs.hasAttribute("BRUSH")) |
14014 | cbradney | 891 | doc->itemToolPrefs.shapeFillColor = attrs.valueAsString("BRUSH"); |
13971 | jghali | 892 | if (attrs.hasAttribute("PENLINE")) |
13996 | cbradney | 893 | doc->itemToolPrefs.lineColor = attrs.valueAsString("PENLINE"); |
13971 | jghali | 894 | if (attrs.hasAttribute("PENTEXT")) |
13996 | cbradney | 895 | doc->itemToolPrefs.textColor = attrs.valueAsString("PENTEXT"); |
13971 | jghali | 896 | if (attrs.hasAttribute("StrokeText")) |
13996 | cbradney | 897 | doc->itemToolPrefs.textStrokeColor = attrs.valueAsString("StrokeText"); |
14014 | cbradney | 898 | doc->itemToolPrefs.textFillColor = attrs.valueAsString("TextBackGround", CommonStrings::None); |
13996 | cbradney | 899 | doc->itemToolPrefs.textLineColor = attrs.valueAsString("TextLineColor", CommonStrings::None); |
14014 | cbradney | 900 | doc->itemToolPrefs.textFillColorShade =attrs.valueAsInt("TextBackGroundShade", 100); |
901 | doc->itemToolPrefs.textLineColorShade = attrs.valueAsInt("TextLineShade", 100); |
||
13996 | cbradney | 902 | doc->itemToolPrefs.textShade = attrs.valueAsInt("TextPenShade", 100); |
903 | doc->itemToolPrefs.textStrokeShade = attrs.valueAsInt("TextStrokeShade", 100); |
||
14014 | cbradney | 904 | doc->itemToolPrefs.shapeLineStyle = static_cast<Qt::PenStyle>(attrs.valueAsInt("STIL")); |
13996 | cbradney | 905 | doc->itemToolPrefs.lineStyle = static_cast<Qt::PenStyle>(attrs.valueAsInt("STILLINE")); |
14014 | cbradney | 906 | doc->itemToolPrefs.shapeLineWidth = attrs.valueAsDouble("WIDTH", 0.0); |
13996 | cbradney | 907 | doc->itemToolPrefs.lineWidth = attrs.valueAsDouble("WIDTHLINE", 1.0); |
14014 | cbradney | 908 | doc->itemToolPrefs.shapeLineColorShade = attrs.valueAsInt("PENSHADE", 100); |
909 | doc->itemToolPrefs.lineColorShade = attrs.valueAsInt("LINESHADE", 100); |
||
910 | doc->itemToolPrefs.shapeFillColorShade = attrs.valueAsInt("BRUSHSHADE", 100); |
||
13971 | jghali | 911 | doc->opToolPrefs.magMin = attrs.valueAsInt("MAGMIN", 10); |
912 | doc->opToolPrefs.magMax = attrs.valueAsInt("MAGMAX", 3200); |
||
913 | doc->opToolPrefs.magStep = attrs.valueAsInt("MAGSTEP", 200); |
||
914 | doc->opToolPrefs.dispX = attrs.valueAsDouble("dispX", 10.0); |
||
915 | doc->opToolPrefs.dispY = attrs.valueAsDouble("dispY", 10.0); |
||
916 | doc->opToolPrefs.constrain = attrs.valueAsDouble("constrain", 15.0); |
||
917 | //CB Reset doc zoom step value to 200% instead of old values. |
||
918 | if (doc->opToolPrefs.magStep < 100) |
||
919 | doc->opToolPrefs.magStep = 200; |
||
13996 | cbradney | 920 | doc->itemToolPrefs.textTabFillChar = attrs.valueAsString("TabFill",""); |
921 | doc->itemToolPrefs.textTabWidth = attrs.valueAsDouble("TabWidth", 36.0); |
||
13971 | jghali | 922 | if (attrs.hasAttribute("CPICT")) |
13996 | cbradney | 923 | doc->itemToolPrefs.imageFillColor = attrs.valueAsString("CPICT"); |
14014 | cbradney | 924 | doc->itemToolPrefs.imageFillColorShade = attrs.valueAsInt("PICTSHADE", 100); |
13971 | jghali | 925 | } |
926 | |||
927 | void Scribus150Format::readTypographicSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
928 | { |
||
929 | doc->typographicSettings.valueSuperScript = attrs.valueAsInt("VHOCH"); |
||
930 | doc->typographicSettings.scalingSuperScript = attrs.valueAsInt("VHOCHSC"); |
||
931 | doc->typographicSettings.valueSubScript = attrs.valueAsInt("VTIEF"); |
||
932 | doc->typographicSettings.scalingSubScript = attrs.valueAsInt("VTIEFSC"); |
||
933 | doc->typographicSettings.valueSmallCaps = attrs.valueAsInt("VKAPIT"); |
||
934 | doc->guidesSettings.valueBaselineGrid = attrs.valueAsDouble("BASEGRID", 12.0); |
||
935 | doc->guidesSettings.offsetBaselineGrid = attrs.valueAsDouble("BASEO", 0.0); |
||
936 | doc->typographicSettings.autoLineSpacing = attrs.valueAsInt("AUTOL", 20); |
||
937 | doc->typographicSettings.valueUnderlinePos = attrs.valueAsInt("UnderlinePos", -1); |
||
938 | doc->typographicSettings.valueUnderlineWidth = attrs.valueAsInt("UnderlineWidth", -1); |
||
939 | doc->typographicSettings.valueStrikeThruPos = attrs.valueAsInt("StrikeThruPos", -1); |
||
940 | doc->typographicSettings.valueStrikeThruWidth = attrs.valueAsInt("StrikeThruWidth", -1); |
||
941 | } |
||
942 | |||
943 | bool Scribus150Format::readPageSets(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
944 | { |
||
945 | struct PageSet pageS; |
||
946 | ScXmlStreamAttributes attrs; |
||
947 | |||
948 | doc->pageSets.clear(); |
||
949 | while(!reader.atEnd() && !reader.hasError()) |
||
950 | { |
||
951 | reader.readNext(); |
||
952 | QStringRef tagName = reader.name(); |
||
953 | if(reader.isStartElement()) |
||
954 | attrs = reader.attributes(); |
||
955 | if (reader.isEndElement() && tagName == "PageSets") |
||
956 | break; |
||
957 | if(reader.isStartElement() && tagName == "Set") |
||
958 | { |
||
959 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
960 | pageS.Name = CommonStrings::untranslatePageSetString(attrs.valueAsString("Name")); |
||
961 | pageS.FirstPage = attrs.valueAsInt("FirstPage", 0); |
||
962 | pageS.Rows = attrs.valueAsInt("Rows", 1); |
||
963 | pageS.Columns = attrs.valueAsInt("Columns", 1); |
||
964 | // pageS.GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0); |
||
965 | // pageS.GapVertical = attrs.valueAsDouble("GapVertical", 0); |
||
966 | // pageS.GapBelow = attrs.valueAsDouble("GapBelow", 0); |
||
967 | pageS.pageNames.clear(); |
||
968 | } |
||
969 | if(reader.isEndElement() && tagName == "Set") |
||
970 | { |
||
971 | doc->pageSets.append(pageS); |
||
972 | if ((doc->pageSets.count()-1 == doc->currentPageLayout) && ((doc->GapHorizontal < 0) && (doc->GapVertical < 0))) |
||
973 | { |
||
974 | doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0.0); |
||
975 | doc->GapVertical = attrs.valueAsDouble("GapBelow", 0.0); |
||
976 | } |
||
977 | } |
||
978 | if (reader.isStartElement() && tagName == "PageNames") |
||
979 | pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(attrs.valueAsString("Name"))); |
||
980 | } |
||
981 | return !reader.hasError(); |
||
982 | } |
||
983 | |||
984 | bool Scribus150Format::readCheckProfile(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
985 | { |
||
986 | struct CheckerPrefs checkerSettings; |
||
987 | QString profileName = attrs.valueAsString("Name"); |
||
988 | if (profileName.isEmpty()) |
||
989 | return true; |
||
990 | checkerSettings.ignoreErrors = attrs.valueAsBool("ignoreErrors", false); |
||
991 | checkerSettings.autoCheck = attrs.valueAsBool("autoCheck", true); |
||
992 | checkerSettings.checkGlyphs = attrs.valueAsBool("checkGlyphs", true); |
||
993 | checkerSettings.checkOrphans = attrs.valueAsBool("checkOrphans", true); |
||
994 | checkerSettings.checkOverflow = attrs.valueAsBool("checkOverflow", true); |
||
995 | checkerSettings.checkPictures = attrs.valueAsBool("checkPictures", true); |
||
996 | checkerSettings.checkResolution = attrs.valueAsBool("checkResolution", true); |
||
997 | checkerSettings.checkTransparency = attrs.valueAsBool("checkTransparency", true); |
||
998 | checkerSettings.minResolution = attrs.valueAsDouble("minResolution", 72.0); |
||
999 | checkerSettings.maxResolution = attrs.valueAsDouble("maxResolution", 4800.0); |
||
1000 | checkerSettings.checkAnnotations = attrs.valueAsBool("checkAnnotations", false); |
||
1001 | checkerSettings.checkRasterPDF = attrs.valueAsBool("checkRasterPDF", true); |
||
1002 | checkerSettings.checkForGIF = attrs.valueAsBool("checkForGIF", true); |
||
1003 | checkerSettings.ignoreOffLayers = attrs.valueAsBool("ignoreOffLayers", false); |
||
1004 | doc->checkerProfiles[profileName] = checkerSettings; |
||
1005 | return true; |
||
1006 | } |
||
1007 | |||
1008 | bool Scribus150Format::readColor(ColorList& colors, ScXmlStreamAttributes& attrs) |
||
1009 | { |
||
1010 | ScColor color; |
||
1011 | if (attrs.hasAttribute("CMYK")) |
||
1012 | color.setNamedColor(attrs.valueAsString("CMYK")); |
||
1013 | else |
||
1014 | color.fromQColor(QColor(attrs.valueAsString("RGB"))); |
||
1015 | color.setSpotColor( attrs.valueAsBool("Spot", false) ); |
||
1016 | color.setRegistrationColor( attrs.valueAsBool("Register", false) ); |
||
1017 | QString name = attrs.valueAsString("NAME"); |
||
1018 | colors.insert((name.isEmpty()) ? color.name() : name, color); |
||
1019 | return true; |
||
1020 | } |
||
1021 | |||
14150 | fschmid | 1022 | bool Scribus150Format::readGradient(ScribusDoc *doc, VGradient &gra, ScXmlStreamReader& reader) |
1023 | { |
||
1024 | gra = VGradient(VGradient::linear); |
||
1025 | gra.clearStops(); |
||
1026 | ScXmlStreamAttributes rattrs = reader.scAttributes(); |
||
1027 | QStringRef tagName = reader.name(); |
||
1028 | while(!reader.atEnd() && !reader.hasError()) |
||
1029 | { |
||
1030 | ScXmlStreamReader::TokenType tType = reader.readNext(); |
||
1031 | if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName) |
||
1032 | break; |
||
1033 | if (tType == ScXmlStreamReader::StartElement && reader.name() == "CSTOP") |
||
1034 | { |
||
1035 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1036 | QString name = attrs.valueAsString("NAME"); |
||
1037 | double ramp = attrs.valueAsDouble("RAMP", 0.0); |
||
1038 | int shade = attrs.valueAsInt("SHADE", 100); |
||
1039 | double opa = attrs.valueAsDouble("TRANS", 1.0); |
||
1040 | gra.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade); |
||
1041 | } |
||
1042 | } |
||
1043 | return !reader.hasError(); |
||
1044 | } |
||
1045 | |||
13971 | jghali | 1046 | void Scribus150Format::readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle) |
1047 | { |
||
1048 | static const QString CNAME("CNAME"); |
||
1049 | if (attrs.hasAttribute(CNAME)) |
||
1050 | newStyle.setName(attrs.valueAsString(CNAME)); |
||
1051 | |||
1052 | // The default style attribute must be correctly set before trying to assign a parent |
||
1053 | static const QString DEFAULTSTYLE("DefaultStyle"); |
||
1054 | if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE)) |
||
1055 | newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE)); |
||
1056 | else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle) |
||
1057 | newStyle.setDefaultStyle(true); |
||
1058 | else |
||
1059 | newStyle.setDefaultStyle(false); |
||
1060 | |||
1061 | static const QString CPARENT("CPARENT"); |
||
1062 | if (attrs.hasAttribute(CPARENT)) |
||
1063 | newStyle.setParent(attrs.valueAsString(CPARENT)); |
||
1064 | |||
1065 | static const QString FONT("FONT"); |
||
1066 | if (attrs.hasAttribute(FONT)) |
||
1067 | newStyle.setFont(m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc)); |
||
1068 | |||
1069 | static const QString FONTSIZE("FONTSIZE"); |
||
1070 | if (attrs.hasAttribute(FONTSIZE)) |
||
1071 | newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10)); |
||
1072 | |||
1073 | static const QString FCOLOR("FCOLOR"); |
||
1074 | if (attrs.hasAttribute(FCOLOR)) |
||
1075 | newStyle.setFillColor(attrs.valueAsString(FCOLOR)); |
||
1076 | |||
1077 | static const QString KERN("KERN"); |
||
1078 | if (attrs.hasAttribute(KERN)) |
||
1079 | newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10)); |
||
1080 | |||
1081 | static const QString FSHADE("FSHADE"); |
||
1082 | if (attrs.hasAttribute(FSHADE)) |
||
1083 | newStyle.setFillShade(attrs.valueAsInt(FSHADE)); |
||
1084 | |||
1085 | static const QString EFFECTS("EFFECTS"); |
||
1086 | if (attrs.hasAttribute(EFFECTS)) |
||
1087 | newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList()); |
||
1088 | |||
1089 | static const QString EFFECT("EFFECT"); |
||
1090 | if (attrs.hasAttribute(EFFECT)) |
||
1091 | newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList()); |
||
1092 | |||
1093 | static const QString FEATURES("FEATURES"); |
||
1094 | if (attrs.hasAttribute(FEATURES)) |
||
1095 | newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", QString::SkipEmptyParts)); |
||
1096 | |||
1097 | static const QString SCOLOR("SCOLOR"); |
||
1098 | if (attrs.hasAttribute(SCOLOR)) |
||
1099 | newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None)); |
||
1100 | |||
1101 | static const QString SSHADE("SSHADE"); |
||
1102 | if (attrs.hasAttribute(SSHADE)) |
||
1103 | newStyle.setStrokeShade(attrs.valueAsInt(SSHADE)); |
||
1104 | |||
1105 | static const QString SCALEH("SCALEH"); |
||
1106 | if (attrs.hasAttribute(SCALEH)) |
||
1107 | newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10)); |
||
1108 | |||
1109 | static const QString SCALEV("SCALEV"); |
||
1110 | if (attrs.hasAttribute(SCALEV)) |
||
1111 | newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10)); |
||
1112 | |||
1113 | static const QString BASEO("BASEO"); |
||
1114 | if (attrs.hasAttribute(BASEO)) |
||
1115 | newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10)); |
||
1116 | |||
1117 | static const QString TXTSHX("TXTSHX"); |
||
1118 | if (attrs.hasAttribute(TXTSHX)) |
||
1119 | newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10)); |
||
1120 | |||
1121 | static const QString TXTSHY("TXTSHY"); |
||
1122 | if (attrs.hasAttribute(TXTSHY)) |
||
1123 | newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10)); |
||
1124 | |||
1125 | static const QString TXTOUT("TXTOUT"); |
||
1126 | if (attrs.hasAttribute(TXTOUT)) |
||
1127 | newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10)); |
||
1128 | |||
1129 | static const QString TXTULP("TXTULP"); |
||
1130 | if (attrs.hasAttribute(TXTULP)) |
||
1131 | newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10)); |
||
1132 | |||
1133 | static const QString TXTULW("TXTULW"); |
||
1134 | if (attrs.hasAttribute(TXTULW)) |
||
1135 | newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10)); |
||
1136 | |||
1137 | static const QString TXTSTP("TXTSTP"); |
||
1138 | if (attrs.hasAttribute(TXTSTP)) |
||
1139 | newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10)); |
||
1140 | |||
1141 | static const QString TXTSTW("TXTSTW"); |
||
1142 | if (attrs.hasAttribute(TXTSTW)) |
||
1143 | newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10)); |
||
1144 | |||
1145 | static const QString SHORTCUT("SHORTCUT"); |
||
1146 | if (attrs.hasAttribute(SHORTCUT)) |
||
1147 | newStyle.setShortcut(attrs.valueAsString(SHORTCUT)); |
||
1148 | |||
1149 | static const QString WORDTRACK("wordTrack"); |
||
1150 | if (attrs.hasAttribute(WORDTRACK)) |
||
1151 | newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK)); |
||
1152 | } |
||
1153 | |||
1154 | void Scribus150Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle, SCFonts &fonts) |
||
1155 | { |
||
1156 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1157 | |||
1158 | newStyle.erase(); |
||
1159 | newStyle.setName(attrs.valueAsString("NAME", "")); |
||
1160 | // The default style attribute must be correctly set before trying to assign a parent |
||
1161 | static const QString DEFAULTSTYLE("DefaultStyle"); |
||
1162 | if (attrs.hasAttribute(DEFAULTSTYLE)) |
||
1163 | newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE)); |
||
1164 | else if (newStyle.name() == CommonStrings::DefaultParagraphStyle || newStyle.name() == CommonStrings::trDefaultParagraphStyle) |
||
1165 | newStyle.setDefaultStyle(true); |
||
1166 | else |
||
1167 | newStyle.setDefaultStyle(false); |
||
1168 | newStyle.setParent(attrs.valueAsString("PARENT", "")); |
||
1169 | |||
1170 | static const QString LINESPMode("LINESPMode"); |
||
1171 | if (attrs.hasAttribute(LINESPMode)) |
||
1172 | newStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt(LINESPMode))); |
||
1173 | |||
1174 | static const QString LINESP("LINESP"); |
||
1175 | if (attrs.hasAttribute(LINESP)) |
||
1176 | newStyle.setLineSpacing(attrs.valueAsDouble(LINESP)); |
||
1177 | |||
1178 | static const QString INDENT("INDENT"); |
||
1179 | if (attrs.hasAttribute(INDENT)) |
||
1180 | newStyle.setLeftMargin(attrs.valueAsDouble(INDENT)); |
||
1181 | |||
1182 | static const QString RMARGIN("RMARGIN"); |
||
1183 | if (attrs.hasAttribute(RMARGIN)) |
||
1184 | newStyle.setRightMargin(attrs.valueAsDouble(RMARGIN)); |
||
1185 | |||
1186 | static const QString FIRST("FIRST"); |
||
1187 | if (attrs.hasAttribute(FIRST)) |
||
1188 | newStyle.setFirstIndent(attrs.valueAsDouble(FIRST)); |
||
1189 | |||
1190 | static const QString ALIGN("ALIGN"); |
||
1191 | if (attrs.hasAttribute(ALIGN)) |
||
1192 | newStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt(ALIGN))); |
||
1193 | |||
1194 | static const QString VOR("VOR"); |
||
1195 | if (attrs.hasAttribute(VOR)) |
||
1196 | newStyle.setGapBefore(attrs.valueAsDouble(VOR)); |
||
1197 | |||
1198 | static const QString NACH("NACH"); |
||
1199 | if (attrs.hasAttribute(NACH)) |
||
1200 | newStyle.setGapAfter(attrs.valueAsDouble(NACH)); |
||
1201 | |||
1202 | static const QString DROP("DROP"); |
||
1203 | if (attrs.hasAttribute(DROP)) |
||
1204 | newStyle.setHasDropCap(static_cast<bool>(attrs.valueAsInt(DROP))); |
||
1205 | |||
1206 | static const QString DROPLIN("DROPLIN"); |
||
1207 | if (attrs.hasAttribute(DROPLIN)) |
||
1208 | newStyle.setDropCapLines(attrs.valueAsInt(DROPLIN)); |
||
1209 | |||
1210 | static const QString DROPDIST("DROPDIST"); |
||
1211 | if (attrs.hasAttribute(DROPDIST)) |
||
1212 | newStyle.setDropCapOffset(attrs.valueAsDouble(DROPDIST)); |
||
1213 | |||
1214 | static const QString PSHORTCUT("PSHORTCUT"); |
||
1215 | if (attrs.hasAttribute(PSHORTCUT)) |
||
1216 | newStyle.setShortcut(attrs.valueAsString(PSHORTCUT)); |
||
1217 | |||
1218 | static const QString OpticalMargins("OpticalMargins"); |
||
1219 | if (attrs.hasAttribute(OpticalMargins)) |
||
1220 | newStyle.setOpticalMargins(attrs.valueAsInt(OpticalMargins)); |
||
1221 | |||
1222 | static const QString HyphenationMode("HyphenationMode"); |
||
1223 | if (attrs.hasAttribute(HyphenationMode)) |
||
1224 | newStyle.setHyphenationMode(attrs.valueAsInt(HyphenationMode)); |
||
1225 | |||
1226 | static const QString MinWordTrack("MinWordTrack"); |
||
1227 | if (attrs.hasAttribute(MinWordTrack)) |
||
1228 | newStyle.setMinWordTracking(attrs.valueAsDouble(MinWordTrack)); |
||
1229 | |||
1230 | static const QString NormWordTrack("NormWordTrack"); |
||
1231 | if (attrs.hasAttribute(NormWordTrack)) |
||
1232 | newStyle.charStyle().setWordTracking(attrs.valueAsDouble(NormWordTrack)); |
||
1233 | |||
1234 | static const QString MinGlyphShrink("MinGlyphShrink"); |
||
1235 | if (attrs.hasAttribute(MinGlyphShrink)) |
||
1236 | newStyle.setMinGlyphExtension(attrs.valueAsDouble(MinGlyphShrink)); |
||
1237 | |||
1238 | static const QString MaxGlyphExtend("MaxGlyphExtend"); |
||
1239 | if (attrs.hasAttribute(MaxGlyphExtend)) |
||
1240 | newStyle.setMaxGlyphExtension(attrs.valueAsDouble(MaxGlyphExtend)); |
||
1241 | |||
1242 | readCharacterStyleAttrs( doc, attrs, newStyle.charStyle()); |
||
1243 | |||
1244 | // newStyle.tabValues().clear(); |
||
1245 | QList<ParagraphStyle::TabRecord> tbs; |
||
1246 | newStyle.resetTabValues(); |
||
1247 | QStringRef thisTagName = reader.name(); |
||
1248 | while (!reader.atEnd() && !reader.hasError()) |
||
1249 | { |
||
1250 | reader.readNext(); |
||
1251 | if (reader.isEndElement() && reader.name() == thisTagName) |
||
1252 | break; |
||
1253 | if (reader.isStartElement() && reader.name() == "Tabs") |
||
1254 | { |
||
1255 | ParagraphStyle::TabRecord tb; |
||
1256 | ScXmlStreamAttributes attrs2 = reader.scAttributes(); |
||
1257 | tb.tabPosition = attrs2.valueAsDouble("Pos"); |
||
1258 | tb.tabType = attrs2.valueAsInt("Type"); |
||
1259 | QString tbCh = attrs2.valueAsString("Fill",""); |
||
1260 | tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0]; |
||
1261 | tbs.append(tb); |
||
1262 | } |
||
1263 | } |
||
1264 | if (tbs.count() > 0) |
||
1265 | newStyle.setTabValues(tbs); |
||
1266 | |||
1267 | fixLegacyParStyle(newStyle); |
||
1268 | } |
||
1269 | |||
1270 | void Scribus150Format::readLayers(ScLayer& layer, ScXmlStreamAttributes& attrs) |
||
1271 | { |
||
1272 | int lId = attrs.valueAsInt("NUMMER"); |
||
1273 | int level = attrs.valueAsInt("LEVEL"); |
||
1274 | layer = ScLayer( attrs.valueAsString("NAME"), level, lId); |
||
1275 | layer.isViewable = attrs.valueAsInt("SICHTBAR"); |
||
1276 | layer.isPrintable = attrs.valueAsInt("DRUCKEN"); |
||
1277 | layer.isEditable = attrs.valueAsInt("EDIT", 1); |
||
1278 | layer.flowControl = attrs.valueAsInt("FLOW", 1); |
||
1279 | layer.transparency = attrs.valueAsDouble("TRANS", 1.0); |
||
1280 | layer.blendMode = attrs.valueAsInt("BLEND", 0); |
||
1281 | layer.outlineMode = attrs.valueAsInt("OUTL", 0); |
||
1282 | if (attrs.hasAttribute("LAYERC")) |
||
1283 | layer.markerColor = QColor(attrs.valueAsString("LAYERC","#000000")); |
||
1284 | } |
||
1285 | |||
1286 | bool Scribus150Format::readArrows(ScribusDoc* doc, ScXmlStreamAttributes& attrs) |
||
1287 | { |
||
1288 | double xa, ya; |
||
1289 | struct ArrowDesc arrow; |
||
1290 | arrow.name = attrs.valueAsString("Name"); |
||
1291 | arrow.userArrow = true; |
||
1292 | QString tmp = attrs.valueAsString("Points"); |
||
1293 | ScTextStream fp(&tmp, QIODevice::ReadOnly); |
||
1294 | unsigned int numPoints = attrs.valueAsUInt("NumPoints"); |
||
1295 | for (uint cx = 0; cx < numPoints; ++cx) |
||
1296 | { |
||
1297 | fp >> xa; |
||
1298 | fp >> ya; |
||
1299 | arrow.points.addPoint(xa, ya); |
||
1300 | } |
||
1301 | doc->arrowStyles.append(arrow); |
||
1302 | return true; |
||
1303 | } |
||
1304 | |||
1305 | bool Scribus150Format::readMultiline(multiLine& ml, ScXmlStreamReader& reader) |
||
1306 | { |
||
1307 | ml = multiLine(); |
||
1308 | ScXmlStreamAttributes rattrs = reader.scAttributes(); |
||
1309 | QStringRef tagName = reader.name(); |
||
1310 | while(!reader.atEnd() && !reader.hasError()) |
||
1311 | { |
||
1312 | ScXmlStreamReader::TokenType tType = reader.readNext(); |
||
1313 | if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName) |
||
1314 | break; |
||
1315 | if (tType == ScXmlStreamReader::StartElement && reader.name() == "SubLine") |
||
1316 | { |
||
1317 | struct SingleLine sl; |
||
1318 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1319 | sl.Color = attrs.valueAsString("Color"); |
||
1320 | sl.Dash = attrs.valueAsInt("Dash"); |
||
1321 | sl.LineEnd = attrs.valueAsInt("LineEnd"); |
||
1322 | sl.LineJoin = attrs.valueAsInt("LineJoin"); |
||
1323 | sl.Shade = attrs.valueAsInt("Shade"); |
||
1324 | sl.Width = attrs.valueAsDouble("Width"); |
||
1325 | ml.shortcut = attrs.valueAsString("Shortcut"); |
||
1326 | ml.push_back(sl); |
||
1327 | } |
||
1328 | } |
||
1329 | return !reader.hasError(); |
||
1330 | } |
||
1331 | |||
1332 | bool Scribus150Format::readBookMark(ScribusDoc::BookMa& bookmark, int& elem, ScXmlStreamAttributes& attrs) |
||
1333 | { |
||
1334 | elem = attrs.valueAsInt("Element"); |
||
1335 | bookmark.PageObject = NULL; |
||
1336 | bookmark.Title = attrs.valueAsString("Title"); |
||
1337 | bookmark.Text = attrs.valueAsString("Text"); |
||
1338 | bookmark.Aktion = attrs.valueAsString("Aktion"); |
||
1339 | bookmark.ItemNr = attrs.valueAsInt("ItemNr"); |
||
1340 | bookmark.First = attrs.valueAsInt("First"); |
||
1341 | bookmark.Last = attrs.valueAsInt("Last"); |
||
1342 | bookmark.Prev = attrs.valueAsInt("Prev"); |
||
1343 | bookmark.Next = attrs.valueAsInt("Next"); |
||
1344 | bookmark.Parent = attrs.valueAsInt("Parent"); |
||
1345 | return true; |
||
1346 | } |
||
1347 | |||
1348 | bool Scribus150Format::readPDFOptions(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
1349 | { |
||
1350 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1351 | |||
1352 | doc->PDF_Options.firstUse = attrs.valueAsBool("firstUse", true); |
||
1353 | doc->PDF_Options.Articles = attrs.valueAsBool("Articles"); |
||
1354 | doc->PDF_Options.Thumbnails = attrs.valueAsBool("Thumbnails"); |
||
1355 | doc->PDF_Options.Compress = attrs.valueAsBool("Compress"); |
||
1356 | doc->PDF_Options.CompressMethod = (PDFOptions::PDFCompression)attrs.valueAsInt("CMethod", 0); |
||
1357 | doc->PDF_Options.Quality = attrs.valueAsInt("Quality", 0); |
||
1358 | doc->PDF_Options.RecalcPic = attrs.valueAsBool("RecalcPic"); |
||
1359 | doc->PDF_Options.Bookmarks = attrs.valueAsBool("Bookmarks"); |
||
1360 | doc->PDF_Options.MirrorH = attrs.valueAsBool("MirrorH", false); |
||
1361 | doc->PDF_Options.MirrorV = attrs.valueAsBool("MirrorV", false); |
||
1362 | doc->PDF_Options.RotateDeg = attrs.valueAsInt("RotateDeg", 0); |
||
1363 | doc->PDF_Options.doClip = attrs.valueAsBool("Clip", false); |
||
1364 | doc->PDF_Options.PresentMode = attrs.valueAsBool("PresentMode"); |
||
1365 | doc->PDF_Options.PicRes = attrs.valueAsInt("PicRes"); |
||
1366 | // Fixme: check input pdf version |
||
1367 | doc->PDF_Options.Version = (PDFOptions::PDFVersion) attrs.valueAsInt("Version"); |
||
1368 | doc->PDF_Options.Resolution = attrs.valueAsInt("Resolution"); |
||
1369 | doc->PDF_Options.Binding = attrs.valueAsInt("Binding"); |
||
1370 | doc->PDF_Options.fileName = ""; |
||
1371 | doc->PDF_Options.isGrayscale = attrs.valueAsBool("Grayscale", false); |
||
1372 | doc->PDF_Options.UseRGB = attrs.valueAsBool("RGBMode", false); |
||
1373 | doc->PDF_Options.UseProfiles = attrs.valueAsBool("UseProfiles", false); |
||
1374 | doc->PDF_Options.UseProfiles2 = attrs.valueAsBool("UseProfiles2", false); |
||
1375 | doc->PDF_Options.Intent = attrs.valueAsInt("Intent", 1); |
||
1376 | doc->PDF_Options.Intent2 = attrs.valueAsInt("Intent2", 1); |
||
1377 | doc->PDF_Options.SolidProf = attrs.valueAsString("SolidP", ""); |
||
1378 | doc->PDF_Options.ImageProf = attrs.valueAsString("ImageP", ""); |
||
1379 | doc->PDF_Options.PrintProf = attrs.valueAsString("PrintP", ""); |
||
1380 | doc->PDF_Options.Info = attrs.valueAsString("InfoString", ""); |
||
1381 | doc->PDF_Options.bleeds.Top = attrs.valueAsDouble("BTop", 0.0); |
||
1382 | doc->PDF_Options.bleeds.Left = attrs.valueAsDouble("BLeft", 0.0); |
||
1383 | doc->PDF_Options.bleeds.Right = attrs.valueAsDouble("BRight", 0.0); |
||
1384 | doc->PDF_Options.bleeds.Bottom = attrs.valueAsDouble("BBottom", 0.0); |
||
1385 | doc->PDF_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds", true); |
||
1386 | doc->PDF_Options.cropMarks = attrs.valueAsBool("cropMarks", false); |
||
1387 | doc->PDF_Options.bleedMarks = attrs.valueAsBool("bleedMarks", false); |
||
1388 | doc->PDF_Options.registrationMarks = attrs.valueAsBool("registrationMarks", false); |
||
1389 | doc->PDF_Options.colorMarks = attrs.valueAsBool("colorMarks", false); |
||
1390 | doc->PDF_Options.docInfoMarks = attrs.valueAsBool("docInfoMarks", false); |
||
1391 | doc->PDF_Options.markOffset = attrs.valueAsDouble("markOffset", 0.0); |
||
1392 | doc->PDF_Options.EmbeddedI = attrs.valueAsBool("ImagePr", false); |
||
1393 | doc->PDF_Options.PassOwner = attrs.valueAsString("PassOwner", ""); |
||
1394 | doc->PDF_Options.PassUser = attrs.valueAsString("PassUser", ""); |
||
1395 | doc->PDF_Options.Permissions = attrs.valueAsInt("Permissions", -4); |
||
1396 | doc->PDF_Options.Encrypt = attrs.valueAsBool("Encrypt", false); |
||
1397 | doc->PDF_Options.useLayers = attrs.valueAsBool("UseLayers", false); |
||
1398 | doc->PDF_Options.UseLPI = attrs.valueAsBool("UseLpi", false); |
||
1399 | doc->PDF_Options.UseSpotColors = attrs.valueAsBool("UseSpotColors", true); |
||
1400 | doc->PDF_Options.doMultiFile = attrs.valueAsBool("doMultiFile", false); |
||
1401 | doc->PDF_Options.displayBookmarks = attrs.valueAsBool("displayBookmarks", false); |
||
1402 | doc->PDF_Options.displayFullscreen = attrs.valueAsBool("displayFullscreen", false); |
||
1403 | doc->PDF_Options.displayLayers = attrs.valueAsBool("displayLayers", false); |
||
1404 | doc->PDF_Options.displayThumbs = attrs.valueAsBool("displayThumbs", false); |
||
1405 | doc->PDF_Options.hideMenuBar = attrs.valueAsBool("hideMenuBar", false); |
||
1406 | doc->PDF_Options.hideToolBar = attrs.valueAsBool("hideToolBar", false); |
||
1407 | doc->PDF_Options.fitWindow = attrs.valueAsBool("fitWindow", false); |
||
1408 | doc->PDF_Options.PageLayout = attrs.valueAsInt("PageLayout", 0); |
||
1409 | doc->PDF_Options.openAction = attrs.valueAsString("openAction", ""); |
||
1410 | |||
1411 | QStringRef tagName = reader.name(); |
||
1412 | while(!reader.atEnd() && !reader.hasError()) |
||
1413 | { |
||
1414 | reader.readNext(); |
||
1415 | if (reader.isEndElement() && (reader.name() == tagName)) |
||
1416 | break; |
||
1417 | if (!reader.isStartElement()) |
||
1418 | continue; |
||
1419 | QStringRef tName = reader.name(); |
||
1420 | attrs = reader.scAttributes(); |
||
1421 | if(tName == "LPI") |
||
1422 | { |
||
1423 | struct LPIData lpo; |
||
1424 | lpo.Angle = attrs.valueAsInt("Angle"); |
||
1425 | lpo.Frequency = attrs.valueAsInt("Frequency"); |
||
1426 | lpo.SpotFunc = attrs.valueAsInt("SpotFunction"); |
||
1427 | doc->PDF_Options.LPISettings[attrs.valueAsString("Color")] = lpo; |
||
1428 | } |
||
1429 | if(tName == "Fonts") |
||
1430 | { |
||
1431 | QString fname = attrs.valueAsString("Name"); |
||
1432 | if (!doc->PDF_Options.EmbedList.contains(fname)) |
||
1433 | doc->PDF_Options.EmbedList.append(fname); |
||
1434 | } |
||
1435 | if(tName == "Subset") |
||
1436 | { |
||
1437 | QString sname = attrs.valueAsString("Name"); |
||
1438 | if (!doc->PDF_Options.SubsetList.contains(sname)) |
||
1439 | doc->PDF_Options.SubsetList.append(sname); |
||
1440 | } |
||
1441 | if(tName == "Effekte") |
||
1442 | { |
||
1443 | struct PDFPresentationData ef; |
||
1444 | ef.pageEffectDuration = attrs.valueAsInt("pageEffectDuration"); |
||
1445 | ef.pageViewDuration = attrs.valueAsInt("pageViewDuration"); |
||
1446 | ef.effectType = attrs.valueAsInt("effectType"); |
||
1447 | ef.Dm = attrs.valueAsInt("Dm"); |
||
1448 | ef.M = attrs.valueAsInt("M"); |
||
1449 | ef.Di = attrs.valueAsInt("Di"); |
||
1450 | doc->PDF_Options.PresentVals.append(ef); |
||
1451 | } |
||
1452 | } |
||
1453 | return !reader.hasError(); |
||
1454 | } |
||
1455 | |||
1456 | bool Scribus150Format::readPrinterOptions(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
1457 | { |
||
1458 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1459 | doc->Print_Options.firstUse = attrs.valueAsBool("firstUse"); |
||
1460 | doc->Print_Options.toFile = attrs.valueAsBool("toFile"); |
||
1461 | doc->Print_Options.useAltPrintCommand = attrs.valueAsBool("useAltPrintCommand"); |
||
1462 | doc->Print_Options.outputSeparations = attrs.valueAsBool("outputSeparations"); |
||
1463 | doc->Print_Options.useSpotColors = attrs.valueAsBool("useSpotColors"); |
||
1464 | doc->Print_Options.useColor = attrs.valueAsBool("useColor"); |
||
1465 | doc->Print_Options.mirrorH = attrs.valueAsBool("mirrorH"); |
||
1466 | doc->Print_Options.mirrorV = attrs.valueAsBool("mirrorV"); |
||
1467 | doc->Print_Options.useICC = attrs.valueAsBool("useICC"); |
||
1468 | doc->Print_Options.doGCR = attrs.valueAsBool("doGCR"); |
||
1469 | doc->Print_Options.doClip = attrs.valueAsBool("doClip"); |
||
1470 | doc->Print_Options.setDevParam = attrs.valueAsBool("setDevParam"); |
||
1471 | doc->Print_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds"); |
||
1472 | doc->Print_Options.cropMarks = attrs.valueAsBool("cropMarks"); |
||
1473 | doc->Print_Options.bleedMarks = attrs.valueAsBool("bleedMarks"); |
||
1474 | doc->Print_Options.registrationMarks = attrs.valueAsBool("registrationMarks"); |
||
1475 | doc->Print_Options.colorMarks = attrs.valueAsBool("colorMarks"); |
||
1476 | doc->Print_Options.includePDFMarks = attrs.valueAsBool("includePDFMarks", "1"); |
||
1477 | if (attrs.hasAttribute("PrintEngine")) |
||
1478 | doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PrintEngine", 3); |
||
1479 | else |
||
1480 | doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PSLevel", 3); |
||
1481 | doc->Print_Options.markOffset = attrs.valueAsDouble("markOffset"); |
||
1482 | doc->Print_Options.bleeds.Top = attrs.valueAsDouble("BleedTop"); |
||
1483 | doc->Print_Options.bleeds.Left = attrs.valueAsDouble("BleedLeft"); |
||
1484 | doc->Print_Options.bleeds.Right = attrs.valueAsDouble("BleedRight"); |
||
1485 | doc->Print_Options.bleeds.Bottom = attrs.valueAsDouble("BleedBottom"); |
||
1486 | doc->Print_Options.printer = attrs.valueAsString("printer"); |
||
1487 | doc->Print_Options.filename = attrs.valueAsString("filename"); |
||
1488 | doc->Print_Options.separationName = attrs.valueAsString("separationName"); |
||
1489 | doc->Print_Options.printerCommand = attrs.valueAsString("printerCommand"); |
||
1490 | doc->Print_Options.copies = 1; |
||
1491 | |||
1492 | QStringRef tagName = reader.name(); |
||
1493 | while(!reader.atEnd() && !reader.hasError()) |
||
1494 | { |
||
1495 | ScXmlStreamReader::TokenType tType = reader.readNext(); |
||
1496 | QStringRef tName = reader.name(); |
||
1497 | if (tType == ScXmlStreamReader::StartElement && tName == "Separation") |
||
1498 | doc->Print_Options.allSeparations.append(reader.attributes().value("Name").toString()); |
||
1499 | if (tType == ScXmlStreamReader::EndElement && tName == tagName) |
||
1500 | break; |
||
1501 | } |
||
1502 | return !reader.hasError(); |
||
1503 | } |
||
1504 | |||
1505 | bool Scribus150Format::readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader) |
||
1506 | { |
||
1507 | QStringRef tagName = reader.name(); |
||
1508 | doc->docItemAttributes.clear(); |
||
1509 | while(!reader.atEnd() && !reader.hasError()) |
||
1510 | { |
||
1511 | reader.readNext(); |
||
1512 | if (reader.isEndElement() && reader.name() == tagName) |
||
1513 | break; |
||
1514 | if(reader.isStartElement() && reader.name() == "ItemAttribute") |
||
1515 | { |
||
1516 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1517 | ObjectAttribute objattr; |
||
1518 | objattr.name = attrs.valueAsString("Name"); |
||
1519 | objattr.type = attrs.valueAsString("Type"); |
||
1520 | objattr.value = attrs.valueAsString("Value"); |
||
1521 | objattr.parameter = attrs.valueAsString("Parameter"); |
||
1522 | objattr.relationship = attrs.valueAsString("Relationship"); |
||
1523 | objattr.relationshipto = attrs.valueAsString("RelationshipTo"); |
||
1524 | objattr.autoaddto = attrs.valueAsString("AutoAddTo"); |
||
1525 | doc->docItemAttributes.append(objattr); |
||
1526 | } |
||
1527 | } |
||
1528 | return !reader.hasError(); |
||
1529 | } |
||
1530 | |||
1531 | bool Scribus150Format::readTableOfContents(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
1532 | { |
||
1533 | QStringRef tagName = reader.name(); |
||
1534 | m_Doc->docToCSetups.clear(); |
||
1535 | while(!reader.atEnd() && !reader.hasError()) |
||
1536 | { |
||
1537 | reader.readNext(); |
||
1538 | if (reader.isEndElement() && reader.name() == tagName) |
||
1539 | break; |
||
1540 | if(reader.isStartElement() && reader.name() == "TableOfContents") |
||
1541 | { |
||
1542 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1543 | ToCSetup tocsetup; |
||
1544 | tocsetup.name = attrs.valueAsString("Name"); |
||
1545 | tocsetup.itemAttrName = attrs.valueAsString("ItemAttributeName"); |
||
1546 | tocsetup.frameName = attrs.valueAsString("FrameName"); |
||
1547 | tocsetup.textStyle = attrs.valueAsString("Style"); |
||
1548 | tocsetup.listNonPrintingFrames = QVariant(attrs.valueAsString("ListNonPrinting")).toBool(); |
||
1549 | QString numberPlacement = attrs.valueAsString("NumberPlacement"); |
||
1550 | if (numberPlacement == "Beginning") |
||
1551 | tocsetup.pageLocation = Beginning; |
||
1552 | if (numberPlacement == "End") |
||
1553 | tocsetup.pageLocation = End; |
||
1554 | if (numberPlacement == "NotShown") |
||
1555 | tocsetup.pageLocation = NotShown; |
||
1556 | doc->docToCSetups.append(tocsetup); |
||
1557 | } |
||
1558 | } |
||
1559 | return !reader.hasError(); |
||
1560 | } |
||
1561 | |||
1562 | bool Scribus150Format::readSections(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
1563 | { |
||
1564 | QStringRef tagName = reader.name(); |
||
1565 | while(!reader.atEnd() && !reader.hasError()) |
||
1566 | { |
||
1567 | reader.readNext(); |
||
1568 | if (reader.isEndElement() && reader.name() == tagName) |
||
1569 | break; |
||
1570 | if (reader.isStartElement() && reader.name() == "Section") |
||
1571 | { |
||
1572 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1573 | struct DocumentSection newSection; |
||
1574 | newSection.number = attrs.valueAsInt("Number"); |
||
1575 | newSection.name = attrs.valueAsString("Name"); |
||
1576 | newSection.fromindex = attrs.valueAsInt("From"); |
||
1577 | newSection.toindex = attrs.valueAsInt("To"); |
||
1578 | QString type = attrs.valueAsString("Type"); |
||
1579 | if (type == "Type_1_2_3") |
||
1580 | newSection.type=Type_1_2_3; |
||
1581 | if (type == "Type_i_ii_iii") |
||
1582 | newSection.type=Type_i_ii_iii; |
||
1583 | if (type == "Type_I_II_III") |
||
1584 | newSection.type=Type_I_II_III; |
||
1585 | if (type == "Type_a_b_c") |
||
1586 | newSection.type=Type_a_b_c; |
||
1587 | if (type == "Type_A_B_C") |
||
1588 | newSection.type=Type_A_B_C; |
||
1589 | if (type == "Type_None") |
||
1590 | newSection.type=Type_None; |
||
1591 | newSection.sectionstartindex = attrs.valueAsInt("Start"); |
||
1592 | newSection.reversed = attrs.valueAsBool("Reversed"); |
||
1593 | newSection.active = attrs.valueAsBool("Active"); |
||
1594 | doc->sections.insert(newSection.number, newSection); |
||
1595 | } |
||
1596 | } |
||
1597 | return !reader.hasError(); |
||
1598 | } |
||
1599 | |||
1600 | bool Scribus150Format::readHyphen(ScribusDoc *doc, ScXmlStreamReader& reader) |
||
1601 | { |
||
1602 | QStringRef tagName = reader.name(); |
||
1603 | while(!reader.atEnd() && !reader.hasError()) |
||
1604 | { |
||
1605 | reader.readNext(); |
||
1606 | if (reader.isEndElement() && reader.name() == tagName) |
||
1607 | break; |
||
1608 | if (reader.isStartElement() && reader.name() == "EXCEPTION") |
||
1609 | { |
||
1610 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1611 | QString word = attrs.valueAsString("WORD"); |
||
1612 | QString hyph = attrs.valueAsString("HYPHENATED"); |
||
1613 | doc->docHyphenator->specialWords.insert(word, hyph); |
||
1614 | } |
||
1615 | else if (reader.isStartElement() && reader.name() == "IGNORE") |
||
1616 | { |
||
1617 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1618 | QString word = attrs.valueAsString("WORD"); |
||
1619 | doc->docHyphenator->ignoredWords.insert(word); |
||
1620 | } |
||
1621 | } |
||
1622 | return !reader.hasError(); |
||
1623 | } |
||
1624 | |||
1625 | bool Scribus150Format::readPage(ScribusDoc* doc, ScXmlStreamReader& reader) |
||
1626 | { |
||
1627 | QStringRef tagName = reader.name(); |
||
1628 | |||
1629 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1630 | int pageNum = attrs.valueAsInt("NUM"); |
||
1631 | QString pageName = attrs.valueAsString("NAM", ""); |
||
1632 | if (tagName == "MASTERPAGE" && pageName.isEmpty()) |
||
1633 | { |
||
1634 | qDebug() << "scribus150format: corrupted masterpage with empty name detected"; |
||
1635 | return true; |
||
1636 | } |
||
1637 | m_Doc->setMasterPageMode(!pageName.isEmpty()); |
||
1638 | Page* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName); |
||
1639 | |||
1640 | newPage->LeftPg = attrs.valueAsInt("LEFT", 0); |
||
1641 | QString mpName = attrs.valueAsString("MNAM", "Normal"); |
||
1642 | newPage->MPageNam = m_Doc->masterPageMode() ? QString("") : mpName; |
||
1643 | if (attrs.hasAttribute("Size")) |
||
1644 | newPage->m_pageSize = attrs.valueAsString("Size"); |
||
1645 | if (attrs.hasAttribute("Orientation")) |
||
1646 | newPage->setOrientation(attrs.valueAsInt("Orientation")); |
||
1647 | newPage->setXOffset(attrs.valueAsDouble("PAGEXPOS")); |
||
1648 | newPage->setYOffset(attrs.valueAsDouble("PAGEYPOS")); |
||
1649 | if (attrs.hasAttribute("PAGEWIDTH")) |
||
1650 | newPage->setWidth(attrs.valueAsDouble("PAGEWIDTH")); |
||
1651 | else |
||
1652 | newPage->setWidth(attrs.valueAsDouble("PAGEWITH")); |
||
1653 | newPage->setHeight(attrs.valueAsDouble("PAGEHEIGHT")); |
||
1654 | newPage->setInitialHeight(newPage->height()); |
||
1655 | newPage->setInitialWidth(newPage->width()); |
||
1656 | newPage->initialMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP")); |
||
1657 | newPage->initialMargins.Bottom = qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM")); |
||
1658 | newPage->initialMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT")); |
||
1659 | newPage->initialMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT")); |
||
1660 | newPage->marginPreset = attrs.valueAsInt("PRESET", 0); |
||
1661 | newPage->Margins.Top = newPage->initialMargins.Top; |
||
1662 | newPage->Margins.Bottom = newPage->initialMargins.Bottom; |
||
1663 | m_Doc->setMasterPageMode(false); |
||
1664 | //m_Doc->Pages=&m_Doc->DocPages; |
||
1665 | // guides reading |
||
1666 | newPage->guides.setHorizontalAutoGap( attrs.valueAsDouble("AGhorizontalAutoGap", 0.0)); |
||
1667 | newPage->guides.setVerticalAutoGap ( attrs.valueAsDouble("AGverticalAutoGap", 0.0)); |
||
1668 | newPage->guides.setHorizontalAutoCount( attrs.valueAsInt("AGhorizontalAutoCount", 0) ); |
||
1669 | newPage->guides.setVerticalAutoCount ( attrs.valueAsInt("AGverticalAutoCount", 0) ); |
||
1670 | newPage->guides.setHorizontalAutoRefer( attrs.valueAsInt("AGhorizontalAutoRefer", 0) ); |
||
1671 | newPage->guides.setVerticalAutoRefer ( attrs.valueAsInt("AGverticalAutoRefer", 0) ); |
||
1672 | GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"), |
||
1673 | newPage, |
||
1674 | GuideManagerCore::Standard, |
||
1675 | attrs.hasAttribute("NumVGuides")); |
||
1676 | GuideManagerIO::readHorizontalGuides(attrs.valueAsString("HorizontalGuides"), |
||
1677 | newPage, |
||
1678 | GuideManagerCore::Standard, |
||
1679 | attrs.hasAttribute("NumHGuides")); |
||
1680 | GuideManagerIO::readSelection(attrs.valueAsString("AGSelection"), newPage); |
||
1681 | return true; |
||
1682 | } |
||
1683 | |||
1684 | bool Scribus150Format::readObject(ScribusDoc* doc, ScXmlStreamReader& reader, ItemInfo& info, const QString& baseDir, bool loadPage) |
||
1685 | { |
||
1686 | QStringRef tagName = reader.name(); |
||
1687 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1688 | |||
1689 | if (!loadPage) |
||
1690 | { |
||
1691 | if (tagName == "PAGEOBJECT" || tagName == "FRAMEOBJECT" || tagName == "PatternItem") |
||
1692 | doc->setMasterPageMode(false); |
||
1693 | else |
||
1694 | doc->setMasterPageMode(true); |
||
1695 | } |
||
1696 | int pagenr = -1; |
||
1697 | if ((!attrs.value("OnMasterPage").isEmpty()) && (tagName == "MASTEROBJECT")) |
||
1698 | { |
||
1699 | doc->setCurrentPage(doc->MasterPages.at(doc->MasterNames[attrs.valueAsString("OnMasterPage")])); |
||
1700 | pagenr = -2; |
||
1701 | } |
||
1702 | |||
1703 | PageItem* newItem = pasteItem(doc, attrs, baseDir, pagenr); |
||
1704 | newItem->setRedrawBounding(); |
||
1705 | if (tagName == "MASTEROBJECT") |
||
1706 | newItem->OwnPage = doc->OnPage(newItem); |
||
1707 | else |
||
1708 | newItem->OwnPage = attrs.valueAsInt("OwnPage"); |
||
1709 | if (tagName == "PAGEOBJECT") |
||
1710 | newItem->OnMasterPage = ""; |
||
13996 | cbradney | 1711 | QString tmpf = attrs.valueAsString("IFONT", doc->itemToolPrefs.textFont); |
13971 | jghali | 1712 | m_AvailableFonts->findFont(tmpf, doc); |
1713 | |||
1714 | // newItem->Language = ScMW->GetLang(pg.attribute("LANGUAGE", doc->Language)); |
||
1715 | newItem->isAutoText = attrs.valueAsBool("AUTOTEXT", false); |
||
1716 | newItem->isEmbedded = attrs.valueAsBool("isInline", false); |
||
1717 | newItem->gXpos = attrs.valueAsDouble("gXpos", 0.0); |
||
1718 | newItem->gYpos = attrs.valueAsDouble("gYpos", 0.0); |
||
1719 | newItem->gWidth = attrs.valueAsDouble("gWidth", newItem->width()); |
||
1720 | newItem->gHeight = attrs.valueAsDouble("gHeight", newItem->height()); |
||
1721 | if (newItem->isAutoText) |
||
1722 | doc->LastAuto = newItem; |
||
1723 | |||
1724 | if (tagName == "FRAMEOBJECT") |
||
1725 | { |
||
1726 | doc->FrameItems.append(doc->Items->takeAt(newItem->ItemNr)); |
||
1727 | newItem->ItemNr = doc->FrameItems.count()-1; |
||
1728 | } |
||
1729 | |||
1730 | info.item = newItem; |
||
1731 | info.nextItem = attrs.valueAsInt("NEXTITEM", -1); |
||
1732 | info.ownLink = newItem->isTableItem ? attrs.valueAsInt("OwnLINK", 0) : 0; |
||
1733 | info.groupLastItem = 0; |
||
1734 | |||
1735 | newItem->isGroupControl = attrs.valueAsBool("isGroupControl", 0); |
||
1736 | if (newItem->isGroupControl) |
||
1737 | { |
||
1738 | int groupLastItem = attrs.valueAsInt("groupsLastItem", 0); |
||
1739 | // Sanity check for some broken files created using buggy development versions. |
||
1740 | if ((newItem->Groups.count() == 0) || (groupLastItem <= 0)) |
||
1741 | { |
||
1742 | newItem->isGroupControl = false; |
||
1743 | newItem->setFillColor("None"); |
||
1744 | } |
||
1745 | info.groupLastItem = groupLastItem; |
||
1746 | } |
||
1747 | |||
1748 | bool layerFound = true; |
||
1749 | struct ImageLoadRequest loadingInfo; |
||
1750 | #ifdef HAVE_OSG |
||
1751 | struct PageItem_OSGFrame::viewDefinition currentView; |
||
1752 | #endif |
||
1753 | QList<ParagraphStyle::TabRecord> tabValues; |
||
1754 | |||
1755 | LastStyles * lastStyle = new LastStyles(); |
||
1756 | while(!reader.atEnd() && !reader.hasError()) |
||
1757 | { |
||
1758 | ScXmlStreamReader::TokenType tType = reader.readNext(); |
||
1759 | if (reader.isEndElement() && tagName == reader.name()) |
||
1760 | break; |
||
1761 | if (tType != ScXmlStreamReader::StartElement) |
||
1762 | continue; |
||
1763 | QStringRef tName = reader.name(); |
||
1764 | ScXmlStreamAttributes tAtt = reader.scAttributes(); |
||
1765 | if (tName == "CSTOP") |
||
1766 | { |
||
1767 | QString name = tAtt.valueAsString("NAME"); |
||
1768 | double ramp = tAtt.valueAsDouble("RAMP", 0.0); |
||
1769 | int shade = tAtt.valueAsInt("SHADE", 100); |
||
1770 | double opa = tAtt.valueAsDouble("TRANS", 1.0); |
||
1771 | newItem->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade); |
||
1772 | } |
||
1773 | |||
1774 | if (tName == "ITEXT") |
||
1775 | readItemText(newItem, tAtt, lastStyle); |
||
1776 | else if (tName == "para") |
||
1777 | { |
||
1778 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PARSEP); |
||
1779 | ParagraphStyle newStyle; |
||
1780 | PrefsManager* prefsManager = PrefsManager::instance(); |
||
1781 | readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.fontPrefs.AvailFonts); |
||
1782 | newItem->itemText.setStyle(newItem->itemText.length()-1, newStyle); |
||
1783 | newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, lastStyle->Style); |
||
1784 | } |
||
1785 | else if (tName == "trail") |
||
1786 | { |
||
1787 | ParagraphStyle newStyle; |
||
1788 | PrefsManager* prefsManager = PrefsManager::instance(); |
||
1789 | readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.fontPrefs.AvailFonts); |
||
1790 | newItem->itemText.setStyle(newItem->itemText.length(), newStyle); |
||
1791 | } |
||
1792 | else if (tName == "tab") |
||
1793 | { |
||
1794 | CharStyle newStyle; |
||
1795 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::TAB); |
||
1796 | readCharacterStyleAttrs(doc, tAtt, newStyle); |
||
1797 | newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, newStyle); |
||
1798 | lastStyle->StyleStart = newItem->itemText.length()-1; |
||
1799 | lastStyle->Style = newStyle; |
||
1800 | } |
||
1801 | else if (tName == "breakline") |
||
1802 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::LINEBREAK); |
||
1803 | else if (tName == "breakcol") |
||
1804 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::COLBREAK); |
||
1805 | else if (tName == "breakframe") |
||
1806 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::FRAMEBREAK); |
||
1807 | else if (tName == "nbhyphen") |
||
1808 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBHYPHEN); |
||
1809 | else if (tName == "nbspace") |
||
1810 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBSPACE); |
||
1811 | else if (tName == "zwnbspace") |
||
1812 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWNBSPACE); |
||
1813 | else if (tName == "zwspace") |
||
1814 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWSPACE); |
||
1815 | else if (tName == "var") |
||
1816 | { |
||
1817 | CharStyle newStyle; |
||
1818 | if (tAtt.value("name") == "pgno") |
||
1819 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGENUMBER); |
||
1820 | else |
||
1821 | newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGECOUNT); |
||
1822 | readCharacterStyleAttrs(doc, tAtt, newStyle); |
||
1823 | newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, newStyle); |
||
1824 | lastStyle->StyleStart = newItem->itemText.length()-1; |
||
1825 | lastStyle->Style = newStyle; |
||
1826 | } |
||
1827 | if (tName == "PageItemAttributes") |
||
1828 | { |
||
1829 | readPageItemAttributes(newItem, reader); |
||
1830 | } |
||
1831 | if (tName == "PSDLayer") |
||
1832 | { |
||
1833 | layerFound = true; |
||
1834 | loadingInfo.blend = tAtt.valueAsString("Blend"); |
||
1835 | loadingInfo.opacity = tAtt.valueAsInt("Opacity"); |
||
1836 | loadingInfo.visible = tAtt.valueAsBool("Visible"); |
||
1837 | loadingInfo.useMask = tAtt.valueAsBool("useMask", true); |
||
1838 | newItem->pixm.imgInfo.RequestProps.insert(tAtt.valueAsInt("Layer"), loadingInfo); |
||
1839 | } |
||
1840 | #ifdef HAVE_OSG |
||
1841 | if (tName == "OSGViews") |
||
1842 | { |
||
1843 | currentView.angleFOV = tAtt.valueAsDouble("angleFOV"); |
||
1844 | QString tmp = ""; |
||
1845 | tmp = tAtt.valueAsString("trackM"); |
||
1846 | ScTextStream fp(&tmp, QIODevice::ReadOnly); |
||
1847 | double m1, m2, m3, m4; |
||
1848 | double m5, m6, m7, m8; |
||
1849 | double m9, m10, m11, m12; |
||
1850 | double m13, m14, m15, m16; |
||
1851 | fp >> m1 >> m2 >> m3 >> m4; |
||
1852 | fp >> m5 >> m6 >> m7 >> m8; |
||
1853 | fp >> m9 >> m10 >> m11 >> m12; |
||
1854 | fp >> m13 >> m14 >> m15 >> m16; |
||
1855 | currentView.trackerMatrix.set(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16); |
||
1856 | tmp = ""; |
||
1857 | tmp = tAtt.valueAsString("trackC"); |
||
1858 | ScTextStream fp2(&tmp, QIODevice::ReadOnly); |
||
1859 | double v1, v2, v3; |
||
1860 | fp2 >> v1 >> v2 >> v3; |
||
1861 | currentView.trackerCenter.set(v1, v2, v3); |
||
1862 | tmp = ""; |
||
1863 | tmp = tAtt.valueAsString("cameraP"); |
||
1864 | ScTextStream fp3(&tmp, QIODevice::ReadOnly); |
||
1865 | fp3 >> v1 >> v2 >> v3; |
||
1866 | currentView.cameraPosition.set(v1, v2, v3); |
||
1867 | tmp = ""; |
||
1868 | tmp = tAtt.valueAsString("cameraU"); |
||
1869 | ScTextStream fp4(&tmp, QIODevice::ReadOnly); |
||
1870 | fp4 >> v1 >> v2 >> v3; |
||
1871 | currentView.cameraUp.set(v1, v2, v3); |
||
1872 | currentView.trackerDist = tAtt.valueAsDouble("trackerDist"); |
||
1873 | currentView.trackerSize = tAtt.valueAsDouble("trackerSize"); |
||
1874 | currentView.illumination = static_cast<PageItem_OSGFrame::LightType>(tAtt.valueAsInt("illumination")); |
||
1875 | currentView.rendermode = static_cast<PageItem_OSGFrame::RenderType>(tAtt.valueAsInt("rendermode")); |
||
1876 | currentView.addedTransparency = tAtt.valueAsDouble("trans"); |
||
1877 | currentView.colorAC = QColor(tAtt.valueAsString("colorAC")); |
||
1878 | currentView.colorFC = QColor(tAtt.valueAsString("colorFC")); |
||
1879 | if (newItem->asOSGFrame()) |
||
1880 | newItem->asOSGFrame()->viewMap.insert(tAtt.valueAsString("viewName"), currentView); |
||
1881 | } |
||
1882 | #endif |
||
1883 | if (tName == "ImageEffect") |
||
1884 | { |
||
1885 | struct ImageEffect ef; |
||
1886 | ef.effectParameters = tAtt.valueAsString("Param"); |
||
1887 | ef.effectCode = tAtt.valueAsInt("Code"); |
||
1888 | newItem->effectsInUse.append(ef); |
||
1889 | } |
||
1890 | if (tName == "Tabs") |
||
1891 | { |
||
1892 | ParagraphStyle::TabRecord tb; |
||
1893 | tb.tabPosition = tAtt.valueAsDouble("Pos"); |
||
1894 | tb.tabType = tAtt.valueAsInt("Type"); |
||
1895 | QString tbCh = tAtt.valueAsString("Fill", ""); |
||
1896 | tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0]; |
||
1897 | tabValues.append(tb); |
||
1898 | } |
||
1899 | if (tName == "LATEX") |
||
1900 | { |
||
1901 | if (newItem->asLatexFrame()) |
||
1902 | { |
||
1903 | readLatexInfo(newItem->asLatexFrame(), reader); |
||
1904 | } |
||
1905 | else |
||
1906 | { |
||
1907 | while (!reader.atEnd() && !reader.hasError()) |
||
1908 | { |
||
1909 | reader.readNext(); |
||
1910 | if (reader.isEndElement() && reader.name() == tName) |
||
1911 | break; |
||
1912 | } |
||
1913 | } |
||
1914 | } |
||
1915 | } |
||
1916 | delete lastStyle; |
||
1917 | |||
1918 | if (tabValues.count() > 0) |
||
1919 | { |
||
1920 | ParagraphStyle newDefault(newItem->itemText.defaultStyle()); |
||
1921 | newDefault.setTabValues(tabValues); |
||
1922 | newItem->itemText.setDefaultStyle(newDefault); |
||
1923 | } |
||
1924 | |||
1925 | if (newItem->fill_gradient.Stops() == 0) |
||
1926 | { |
||
14014 | cbradney | 1927 | const ScColor& col1 = doc->PageColors[doc->itemToolPrefs.shapeFillColor]; |
1928 | const ScColor& col2 = doc->PageColors[doc->itemToolPrefs.shapeLineColor]; |
||
1929 | newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, doc), 0.0, 0.5, 1.0, doc->itemToolPrefs.shapeFillColor, 100); |
||
1930 | newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, doc), 1.0, 0.5, 1.0, doc->itemToolPrefs.shapeLineColor, 100); |
||
13971 | jghali | 1931 | } |
1932 | |||
1933 | if (newItem->asPathText()) |
||
1934 | { |
||
1935 | newItem->updatePolyClip(); |
||
1936 | newItem->Frame = true; |
||
1937 | } |
||
1938 | #ifdef HAVE_OSG |
||
1939 | if (newItem->asImageFrame() || newItem->asLatexFrame() || newItem->asOSGFrame()) |
||
1940 | #else |
||
1941 | if (newItem->asImageFrame() || newItem->asLatexFrame()) |
||
1942 | #endif |
||
1943 | { |
||
1944 | if (!newItem->Pfile.isEmpty()) |
||
1945 | { |
||
1946 | doc->loadPict(newItem->Pfile, newItem, false); |
||
1947 | if (layerFound) |
||
1948 | { |
||
1949 | newItem->pixm.imgInfo.isRequest = true; |
||
1950 | doc->loadPict(newItem->Pfile, newItem, true); |
||
1951 | } |
||
1952 | newItem->AdjustPictScale(); |
||
1953 | } |
||
1954 | } |
||
1955 | |||
1956 | if (!loadPage) |
||
1957 | doc->setMasterPageMode(false); |
||
1958 | return !reader.hasError(); |
||
1959 | } |
||
1960 | |||
1961 | bool Scribus150Format::readPattern(ScribusDoc* doc, ScXmlStreamReader& reader, const QString& baseDir) |
||
1962 | { |
||
1963 | ScPattern pat; |
||
1964 | ScXmlStreamAttributes attrs = reader.scAttributes(); |
||
1965 | QString patternName = attrs.valueAsString("Name"); |
||
1966 | bool success = true; |
||
1967 | |||
1968 | if (patternName.isEmpty()) |
||
1969 | { |
||
1970 | reader.readToElementEnd(); |
||
1971 | return true; |
||
1972 | } |
||
1973 | |||
1974 | QMap<PageItem*, int> groupID2; |
||
1975 | QMap<int,int> TableID2; |
||
1976 | QList<PageItem*> TableItems2; |
||
1977 | |||
1978 | pat.setDoc(doc); |
||
1979 | pat.width = attrs.valueAsDouble("width", 0.0); |
||
1980 | pat.height = attrs.valueAsDouble("height", 0.0); |
||
1981 | pat.scaleX = attrs.valueAsDouble("scaleX", 0.0); |
||
1982 | pat.scaleY = attrs.valueAsDouble("scaleY", 0.0); |
||
1983 | pat.xoffset = attrs.valueAsDouble("xoffset", 0.0); |
||
1984 | pat.yoffset = attrs.valueAsDouble("yoffset", 0.0); |
||
1985 | |||
1986 | uint itemCount1 = m_Doc->Items->count(); |
||
1987 | bool savedAlignGrid = m_Doc->useRaster; |
||
1988 | bool savedAlignGuides = m_Doc->SnapGuides; |
||
1989 | m_Doc->useRaster = false; |
||
1990 | m_Doc->SnapGuides = false; |
||
1991 | |||
1992 | QStringRef tagName = reader.name(); |
||
1993 | while(!reader.atEnd() && !reader.hasError()) |
||
1994 | { |
||
1995 | reader.readNext(); |
||
1996 | if (reader.isEndElement() && reader.name() == tagName) |
||
1997 | break; |
||
1998 | if (!reader.isStartElement() || reader.name() != "PatternItem") |
||
1999 | continue; |
||
2000 | |||
2001 | QStringRef tName = reader.name(); |
||
2002 | ScXmlStreamAttributes tAtt = reader.attributes(); |
||
2003 | |||
2004 | ItemInfo itemInfo; |
||
2005 | m_Doc->setMasterPageMode(false); |
||
2006 | |||
2007 | int ownPage = tAtt.valueAsInt("OwnPage"); |
||
2008 | success = readObject(doc, reader, itemInfo, baseDir, false); |
||
2009 | if (!success) break; |
||
2010 | |||
2011 | itemInfo.item->OwnPage = ownPage; |
||
2012 | itemInfo.item->OnMasterPage = ""; |
||
2013 | |||
2014 | if (itemInfo.item->isTableItem) |
||
2015 | { |
||
2016 | TableItems2.append(itemInfo.item); |
||
2017 | TableID2.insert(itemInfo.ownLink, itemInfo.item->ItemNr); |
||
2018 | } |
||
2019 | if (itemInfo.item->isGroupControl) |
||
2020 | { |
||
2021 | groupID2.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr); |
||
2022 | } |
||
2023 | } |
||
2024 | |||
2025 | doc->useRaster = savedAlignGrid; |
||
2026 | doc->SnapGuides = savedAlignGuides; |
||
2027 | if (!success) |
||
2028 | { |
||
2029 | return false; |
||
2030 | } |
||
2031 | |||
2032 | if (groupID2.count() != 0) |
||
2033 | { |
||
2034 | QMap<PageItem*, int>::Iterator it; |
||
2035 | for (it = groupID2.begin(); it != groupID2.end(); ++it) |
||
2036 | { |
||
2037 | it.key()->groupsLastItem = m_Doc->Items->at(it.value()); |
||
2038 | } |
||
2039 | } |
||
2040 | if (TableItems2.count() != 0) |
||
2041 | { |
||
2042 | for (int ttc = 0; ttc < TableItems2.count(); ++ttc) |
||
2043 | { |
||
2044 | PageItem* ta = TableItems2.at(ttc); |
||
2045 | if (ta->TopLinkID != -1) |
||
2046 | ta->TopLink = m_Doc->Items->at(TableID2[ta->TopLinkID]); |
||
2047 | else |
||
2048 | ta->TopLink = 0; |
||
2049 | if (ta->LeftLinkID != -1) |
||
2050 | ta->LeftLink = m_Doc->Items->at(TableID2[ta->LeftLinkID]); |
||
2051 | else |
||
2052 | ta->LeftLink = 0; |
||
2053 | if (ta->RightLinkID != -1) |
||
2054 | ta->RightLink = m_Doc->Items->at(TableID2[ta->RightLinkID]); |
||
2055 | else |
||
2056 | ta->RightLink = 0; |
||
2057 | if (ta->BottomLinkID != -1) |
||
2058 | ta->BottomLink = m_Doc->Items->at(TableID2[ta->BottomLinkID]); |
||
2059 | else |
||
2060 | ta->BottomLink = 0; |
||
2061 | } |
||
2062 | } |
||
2063 | |||
2064 | uint itemCount2 = m_Doc->Items->count(); |
||
2065 | if (itemCount2 > itemCount1) |
||
2066 | { |
||
2067 | PageItem* currItem = doc->Items->at(itemCount1), *newItem; |
||
2068 | pat.pattern = currItem->DrawObj_toImage(); |
||
2069 | pat.pattern = pat.pattern.copy(-pat.xoffset, -pat.yoffset, pat.width, pat.height); |
||
2070 | for (uint as = itemCount1; as < itemCount2; ++as) |
||
2071 | { |
||
2072 | newItem = doc->Items->takeAt(itemCount1); |
||
2073 | newItem->moveBy(pat.xoffset, pat.yoffset, true); |
||
2074 | newItem->gXpos += pat.xoffset; |
||
2075 | newItem->gYpos += pat.yoffset; |
||
2076 | newItem->ItemNr = pat.items.count(); |
||
2077 | pat.items.append(newItem); |
||
2078 | } |
||
2079 | } |
||
2080 | doc->docPatterns.insert(patternName, pat); |
||
2081 | |||
2082 | return success; |
||
2083 | } |
||
2084 | |||
2085 | bool Scribus150Format::readItemText(PageItem *obj, ScXmlStreamAttributes& attrs, LastStyles* last) |
||
2086 | { |
||
2087 | QString tmp2; |
||
2088 | CharStyle newStyle; |
||
2089 | ScribusDoc* doc = obj->doc(); |
||
2090 | |||
2091 | readCharacterStyleAttrs(doc, attrs, newStyle); |
||
2092 | |||
2093 | if (attrs.hasAttribute(QLatin1String("Unicode"))) |
||
2094 | { |
||
2095 | tmp2 = QChar(attrs.valueAsInt("Unicode")); |
||
2096 | } |
||
2097 | else |
||
2098 | { |
||
2099 | tmp2 = attrs.valueAsString("CH"); |
||
2100 | |||
2101 | // legacy stuff: |
||
2102 | tmp2.replace(QRegExp("\r"), QChar(13)); |
||
2103 | tmp2.replace(QRegExp("\n"), QChar(13)); |
||
2104 | tmp2.replace(QRegExp("\t"), QChar(9)); |
||
2105 | } |
||
2106 | |||
2107 | // more legacy stuff: |
||
2108 | QString pstylename = attrs.valueAsString("PSTYLE", ""); |
||
2109 | |||
2110 | fixLegacyCharStyle(newStyle); |
||
2111 | last->ParaStyle = pstylename; |
||
2112 | // end of legacy stuff |
||
2113 | |||
2114 | int iobj = attrs.valueAsInt("COBJ", -1); |
||
2115 | |||
2116 | for (int cxx=0; cxx<tmp2.length(); ++cxx) |
||
2117 | { |
||
2118 | QChar ch = tmp2.at(cxx); |
||
2119 | { // Legacy mode |
||
2120 | if (ch == QChar(5)) |
||
2121 | ch = SpecialChars::PARSEP; |
||
2122 | if (ch == QChar(4)) |
||
2123 | ch = SpecialChars::TAB; |
||
2124 | } |
||
2125 | |||
2126 | int pos = obj->itemText.length(); |
||
2127 | if (ch == SpecialChars::OBJECT) { |
||
14083 | jghali | 2128 | if (iobj >= 0) { |
2129 | if (iobj < doc->FrameItems.count()) |
||
2130 | obj->itemText.insertObject(pos, doc->FrameItems.at(iobj)); |
||
2131 | else |
||
2132 | qDebug() << QString("scribus150format: invalid inline frame used in text object : %1").arg(iobj); |
||
13971 | jghali | 2133 | } |
2134 | } |
||
2135 | else if (ch == SpecialChars::SHYPHEN && pos > 0) |
||
2136 | { |
||
2137 | // qDebug() << QString("scribus150format: SHYPHEN at %1").arg(pos); |
||
2138 | ScText* lastItem = obj->itemText.item(pos-1); |
||
2139 | // double SHY means user provided SHY, single SHY is automatic one |
||
2140 | if (lastItem->effects() & ScStyle_HyphenationPossible) |
||
2141 | { |
||
2142 | lastItem->setEffects(lastItem->effects() & ~ScStyle_HyphenationPossible); |
||
2143 | obj->itemText.insertChars(pos, QString(ch)); |
||
2144 | } |
||
2145 | else |
||
2146 | { |
||
2147 | lastItem->setEffects(lastItem->effects() | ScStyle_HyphenationPossible); |
||
2148 | } |
||
2149 | } |
||
2150 | else { |
||
2151 | obj->itemText.insertChars(pos, QString(ch)); |
||
2152 | } |
||
2153 | // qDebug() << QString("style at %1: %2 ^ %3 = %4 (%5)").arg(pos).arg((uint)newStyle.effects()).arg((uint)last->Style.effects()).arg((uint)(newStyle.effects() ^ last->Style.effects())).arg(newStyle != last->Style); |
||
2154 | if (newStyle != last->Style) // || (newStyle.effects() ^ last->Style.effects()) == ScStyle_HyphenationPossible) |
||
2155 | { // FIXME StyleFlag operator== ignores hyphen flag |
||
2156 | // qDebug() << QString("new style at %1: %2 -> %3").arg(pos).arg(last->Style.asString()).arg(newStyle.asString()); |
||
2157 | obj->itemText.setCharStyle(last->StyleStart, pos-last->StyleStart, last->Style); |
||
2158 | last->Style = newStyle; |
||
2159 | last->StyleStart = pos; |
||
2160 | } |
||
2161 | if (ch == SpecialChars::PARSEP) { |
||
2162 | ParagraphStyle pstyle; |
||
2163 | // Qt4 if (last->ParaStyle >= 0) { |
||
2164 | if (!last->ParaStyle.isEmpty()) { |
||
2165 | pstyle.setParent( last->ParaStyle ); |
||
2166 | } |
||
2167 | obj->itemText.applyStyle(pos, pstyle); |
||
2168 | } |
||
2169 | } |
||
2170 | |||
2171 | obj->itemText.setCharStyle(last->StyleStart, obj->itemText.length()-last->StyleStart, last->Style); |
||
2172 | last->StyleStart = obj->itemText.length(); |
||
2173 | /* |
||
2174 | QString dbg(""); |
||
2175 | for (int i=0; i < obj->itemText.length(); ++i) |
||
2176 | { |
||
2177 | dbg += obj->itemText.text(i,1); |
||
2178 | if (obj->itemText.item(i)->effects() & ScStyle_HyphenationPossible) |
||
2179 | dbg += "~"; |
||
2180 | } |
||
2181 | qDebug("scribus150format: read itemtext %d '%s'", obj->itemText.length(), dbg.latin1()); |
||
2182 | */ |
||
2183 | ParagraphStyle pstyle; |
||
2184 | |||
2185 | if (!last->ParaStyle.isEmpty()) { // Qt4 >= 0) { |
||
2186 | pstyle.setParent( last->ParaStyle ); |
||
2187 | obj->itemText.applyStyle(obj->itemText.length()-1, pstyle); |
||
2188 | } |
||
2189 | |||
2190 | return true; |
||
2191 | } |
||
2192 | |||
2193 | bool Scribus150Format::readPageItemAttributes(PageItem* item, ScXmlStreamReader& reader) |
||
2194 | { |
||
2195 | QStringRef tagName = reader.name(); |
||
2196 | ObjAttrVector pageItemAttributes; |
||
2197 | while(!reader.atEnd() && !reader.hasError()) |
||
2198 | { |
||
2199 | reader.readNext(); |
||
2200 | if (reader.isEndElement() && reader.name() == tagName) |
||
2201 | break; |
||
2202 | if (reader.isStartElement() && reader.name() == "ItemAttribute") |
||
2203 | { |
||
2204 | ScXmlStreamAttributes tAtt = reader.scAttributes(); |
||
2205 | ObjectAttribute objattr; |
||
2206 | objattr.name = tAtt.valueAsString("Name"); |
||
2207 | objattr.type = tAtt.valueAsString("Type"); |
||
2208 | objattr.value = tAtt.valueAsString("Value"); |
||
2209 | objattr.parameter = tAtt.valueAsString("Parameter"); |
||
2210 | objattr.relationship = tAtt.valueAsString("Relationship"); |
||
2211 | objattr.relationshipto = tAtt.valueAsString("RelationshipTo"); |
||
2212 | objattr.autoaddto = tAtt.valueAsString("AutoAddTo"); |
||
2213 | pageItemAttributes.append(objattr); |
||
2214 | } |
||
2215 | } |
||
2216 | item->setObjectAttributes(&pageItemAttributes); |
||
2217 | return !reader.hasError(); |
||
2218 | } |
||
2219 | |||
2220 | PageItem* Scribus150Format::pasteItem(ScribusDoc *doc, ScXmlStreamAttributes& attrs, const QString& baseDir, int pagenr) |
||
2221 | { |
||
2222 | int z = 0; |
||
2223 | struct ImageLoadRequest loadingInfo; |
||
2224 | PageItem::ItemType pt = static_cast<PageItem::ItemType>(attrs.valueAsInt("PTYPE")); |
||
2225 | double xf, yf; |
||
2226 | double x = attrs.valueAsDouble("XPOS"); |
||
2227 | double y = attrs.valueAsDouble("YPOS"); |
||
2228 | double w = attrs.valueAsDouble("WIDTH"); |
||
2229 | double h = attrs.valueAsDouble("HEIGHT"); |
||
2230 | double pw = attrs.valueAsDouble("PWIDTH"); |
||
2231 | double scx = attrs.valueAsDouble("LOCALSCX"); |
||
2232 | double scy = attrs.valueAsDouble("LOCALSCY"); |
||
2233 | QString Pcolor = attrs.valueAsString("PCOLOR"); |
||
2234 | if (Pcolor.isEmpty()) |
||
2235 | Pcolor = CommonStrings::None; |
||