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