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