Rev 25195 |
Rev 25248 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "scribus150format.h"
#include "scribus150formatimpl.h"
#include <algorithm>
#include <QApplication>
#include <QByteArray>
#include <QCursor>
// #include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QList>
#include <QRegularExpression>
#include <QScopedPointer>
#include <QStringView>
#include "../../formatidlist.h"
#include "commonstrings.h"
#include "hyphenator.h"
#include "langmgr.h"
#include "notesstyles.h"
#include "pageitem_arc.h"
#include "pageitem_latexframe.h"
#include "pageitem_noteframe.h"
#ifdef HAVE_OSG
#include "pageitem_osgframe.h"
#endif
#include "pageitem_regularpolygon.h"
#include "pageitem_spiral.h"
#include "pageitem_table.h"
#include "pagestructs.h"
#include "pageitem_line.h"
#include "pagesize.h"
#include "prefsmanager.h"
#include "qtiocompressor.h"
#include "scclocale.h"
#include "scconfig.h"
#include "sccolorengine.h"
#include "scpattern.h"
#include "scribuscore.h"
#include "scribusdoc.h"
#include "sctextstream.h"
#include "scxmlstreamreader.h"
#include "textnote.h"
#include "undomanager.h"
#include "ui/missing.h"
#include "units.h"
#include "util.h"
#include "util_color.h"
#include "util_math.h"
#include "util_printer.h"
#include "util_text.h"
// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
// do. That documentatation is not duplicated here.
// Please don't implement the functionality of your plugin here; do that
// in scribus150formatimpl.h and scribus150formatimpl.cpp .
Scribus150Format::Scribus150Format()
{
// Set action info in languageChange, so we only have to do
// it in one place. This includes registering file formats.
registerFormats();
languageChange();
}
Scribus150Format::~Scribus150Format()
{
unregisterAll();
}
void Scribus150Format::languageChange()
{
FileFormat* fmt = getFormatByID(FORMATID_SLA150IMPORT);
fmt->trName = tr("Scribus 1.5.0+ Document");
fmt->filter = fmt->trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
}
QString Scribus150Format::fullTrName() const
{
return QObject::tr("Scribus 1.5.0+ Support");
}
const ScActionPlugin::AboutData* Scribus150Format::getAboutData() const
{
AboutData* about = new AboutData;
Q_CHECK_PTR(about);
about->authors = QString::fromUtf8(
"Franz Schmid <franz@scribus.info>, "
"The Scribus Team");
about->shortDescription = tr("Scribus 1.5.0+ File Format Support");
about->description = tr("Allows Scribus to read Scribus 1.5.0 and higher formatted files.");
// about->version
// about->releaseDate
// about->copyright
about->license = "GPL";
return about;
}
void Scribus150Format::deleteAboutData(const AboutData* about) const
{
Q_ASSERT(about);
delete about;
}
void Scribus150Format::registerFormats()
{
FileFormat fmt(this);
fmt.trName = tr("Scribus 1.5.0+ Document");
fmt.formatId = FORMATID_SLA150IMPORT;
fmt.load = true;
fmt.save = true;
fmt.colorReading = true;
fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
fmt.mimeTypes = QStringList();
fmt.mimeTypes.append("application/x-scribus");
fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz";
fmt.priority = 64;
fmt.nativeScribus = true;
registerFormat(fmt);
}
bool Scribus150Format::fileSupported(QIODevice* /* file */, const QString & fileName) const
{
QByteArray docBytes;
if (fileName.right(2) == "gz")
{
QFile file(fileName);
QtIOCompressor compressor(&file);
compressor.setStreamFormat(QtIOCompressor::GzipFormat);
compressor.open(QIODevice::ReadOnly);
docBytes = compressor.read(1024);
compressor.close();
if (docBytes.isEmpty())
return false;
}
else
{
// Not gzip encoded, just load it
loadRawBytes(fileName, docBytes, 1024);
}
int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
if (startElemPos < 0)
return false;
QRegularExpression regExp150("Version=\"1.5.[0-9]");
QRegularExpression regExp170("Version=\"1.7.[0-9]");
QRegularExpressionMatch match150 = regExp150.match(docBytes.mid(startElemPos, 64));
QRegularExpressionMatch match170 = regExp170.match(docBytes.mid(startElemPos, 64));
return match150.hasMatch() || match170.hasMatch();
}
bool Scribus150Format::paletteSupported(QIODevice* /* file */, const QString & fileName) const
{
QByteArray docBytes;
if (fileName.right(2) == "gz")
{
QFile file(fileName);
QtIOCompressor compressor(&file);
compressor.setStreamFormat(QtIOCompressor::GzipFormat);
compressor.open(QIODevice::ReadOnly);
docBytes = compressor.read(1024);
compressor.close();
if (docBytes.isEmpty())
return false;
}
else
{
// Not gzip encoded, just load it
loadRawBytes(fileName, docBytes, 1024);
}
int startElemPos = docBytes.indexOf("<SCRIBUSCOLORS");
return (startElemPos >= 0);
}
bool Scribus150Format::storySupported(const QByteArray& storyData) const
{
int startElemPos = storyData.left(512).indexOf("<ScribusStory ");
if (startElemPos < 0)
return false;
QRegularExpression regExp150("Version=\"1.5.[0-9]");
QRegularExpression regExp170("Version=\"1.7.[0-9]");
QRegularExpressionMatch match150 = regExp150.match(storyData.mid(startElemPos, 64));
QRegularExpressionMatch match170 = regExp170.match(storyData.mid(startElemPos, 64));
return match150.hasMatch() || match170.hasMatch();
}
QIODevice* Scribus150Format::slaReader(const QString & fileName)
{
if (!fileSupported(nullptr, fileName))
return nullptr;
QIODevice* ioDevice = nullptr;
if (fileName.right(2) == "gz")
{
aFile.setFileName(fileName);
QtIOCompressor *compressor = new QtIOCompressor(&aFile);
compressor->setStreamFormat(QtIOCompressor::GzipFormat);
if (!compressor->open(QIODevice::ReadOnly))
{
delete compressor;
return nullptr;
}
ioDevice = compressor;
}
else
{
ioDevice = new QFile(fileName);
if (!ioDevice->open(QIODevice::ReadOnly))
{
delete ioDevice;
return nullptr;
}
}
return ioDevice;
}
QIODevice* Scribus150Format::paletteReader(const QString & fileName)
{
if (!paletteSupported(nullptr, fileName))
return nullptr;
QIODevice* ioDevice = nullptr;
if (fileName.right(2) == "gz")
{
aFile.setFileName(fileName);
QtIOCompressor *compressor = new QtIOCompressor(&aFile);
compressor->setStreamFormat(QtIOCompressor::GzipFormat);
if (!compressor->open(QIODevice::ReadOnly))
{
delete compressor;
return nullptr;
}
ioDevice = compressor;
}
else
{
ioDevice = new QFile(fileName);
if (!ioDevice->open(QIODevice::ReadOnly))
{
delete ioDevice;
return nullptr;
}
}
return ioDevice;
}
void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces)
{
getNewReplacement = false;
getReplacedFonts.clear();
}
bool Scribus150Format::loadElements(const QString& data, const QString& fileDir, int toLayer, double Xp_in, double Yp_in, bool loc)
{
isNewFormat = false;
LayerToPaste = toLayer;
Xp = Xp_in;
Yp = Yp_in;
GrX = 0.0;
GrY = 0.0;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsF;
QList<PageItem*> TableItemsM;
QList<PageItem*> WeldItems;
QMap<int, PageItem*> TableID;
QMap<int, PageItem*> TableIDF;
QMap<int, PageItem*> TableIDM;
QMap<int, PageItem*> WeldID;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
QStack< QList<PageItem*> > groupStackPI;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStackFI2;
QStack<int> groupStackMI2;
QStack<int> groupStackPI2;
parStyleMap.clear();
charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
itemRemapM.clear();
itemNextM.clear();
itemCountM = 0;
itemRemapF.clear();
itemNextF.clear();
FrameItems.clear();
LinkID.clear();
markeredItemsMap.clear();
markeredMarksMap.clear();
nsetRangeItemNamesMap.clear();
notesFramesData.clear();
notesMasterMarks.clear();
notesNSets.clear();
bool firstElement = true;
bool success = true;
ReadObjectParams readObjectParams;
readObjectParams.baseDir = fileDir;
readObjectParams.itemKind = PageItem::StandardItem;
readObjectParams.loadingPage = true;
ScXmlStreamReader reader(data);
ScXmlStreamAttributes attrs;
while (!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QString tagName(reader.nameAsString());
attrs = reader.scAttributes();
if (firstElement)
{
if (tagName == QLatin1String("SCRIBUSELEM") || tagName == QLatin1String("SCRIBUSELEMUTF8"))
{
if (!loc)
{
GrX = attrs.valueAsDouble("XP");
GrY = attrs.valueAsDouble("YP");
}
}
else
{
success = false;
break;
}
firstElement = false;
continue;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == QLatin1String("COLOR") && attrs.valueAsString("NAME") != CommonStrings::None)
{
QString colorName = attrs.valueAsString("NAME");
if (m_Doc->PageColors.contains(colorName))
continue;
readColor(m_Doc->PageColors, attrs);
}
else if (tagName == QLatin1String("Gradient"))
{
VGradient gra;
QString grName = attrs.valueAsString("Name");
success = readGradient(m_Doc, gra, reader);
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
if (!grName.isEmpty() && !m_Doc->docGradients.contains(grName))
m_Doc->docGradients.insert(grName, gra);
}
else if (tagName == QLatin1String("STYLE"))
{
ParagraphStyle pstyle;
getStyle(pstyle, reader, nullptr, m_Doc, true);
}
else if (tagName == QLatin1String("CHARSTYLE"))
{
CharStyle cstyle;
getStyle(cstyle, reader, nullptr, m_Doc, true);
}
else if (tagName == QLatin1String("TableStyle"))
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->tableStyles().contains(tstyle.name()))
continue;
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
}
else if (tagName == QLatin1String("CellStyle"))
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->cellStyles().contains(tstyle.name()))
continue;
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
}
else if (tagName == QLatin1String("Arrows"))
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
else if (tagName == QLatin1String("MultiLine"))
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success)
break;
if (!mlName.isEmpty() && !m_Doc->docLineStyles.contains(mlName))
m_Doc->docLineStyles.insert(mlName, ml);
}
else if ((tagName == QLatin1String("ITEM")) || (tagName == QLatin1String("PAGEOBJECT")) || (tagName == QLatin1String("FRAMEOBJECT")))
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, readObjectParams, itemInfo);
if (!success)
break;
itemInfo.item->m_layerID = LayerToPaste;
if (isNewFormat)
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.itemID] = itemInfo.nextItem;
if (itemInfo.item->isTableItem)
TableItems.append(itemInfo.item);
if (itemInfo.isWeldFlag)
WeldItems.append(itemInfo.item);
}
else
{
// first of linked chain?
if (tagName == QLatin1String("ITEM"))
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == QLatin1String("ITEM"))
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
}
if (itemInfo.isWeldFlag)
{
if (tagName == QLatin1String("ITEM"))
{
WeldItems.append(itemInfo.item);
WeldID.insert(itemInfo.ownWeld, itemInfo.item);
}
}
}
if ((tagName == QLatin1String("PAGEOBJECT")) && (groupStackPI.count() > 0))
{
groupStackPI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackPI2.top())
{
groupStackP.push(groupStackPI.pop());
groupStackPI2.pop();
if (groupStackPI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("FRAMEOBJECT")) && (groupStackFI.count() > 0))
{
groupStackFI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackFI2.top())
{
groupStackF.push(groupStackFI.pop());
groupStackFI2.pop();
if (groupStackFI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("MASTEROBJECT")) && (groupStackMI.count() > 0))
{
groupStackMI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackMI2.top())
{
groupStackM.push(groupStackMI.pop());
groupStackMI2.pop();
if (groupStackMI2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> groupItems;
groupItems.append(itemInfo.item);
if (tagName == QLatin1String("PAGEOBJECT"))
{
groupStackPI.push(groupItems);
groupStackPI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else if (tagName == QLatin1String("FRAMEOBJECT"))
{
groupStackFI.push(groupItems);
groupStackFI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else
{
groupStackMI.push(groupItems);
groupStackMI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
}
else if (tagName == QLatin1String("Pattern"))
{
success = readPattern(m_Doc, reader, fileDir);
if (!success) break;
}
else if (tagName == QLatin1String("NotesStyles"))
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("NotesFrames"))
{
success = readNotesFrames(reader);
if (!success) break;
}
else if (tagName == QLatin1String("Notes"))
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("Marks"))
{
success = readMarks(m_Doc, reader);
if (!success) break;
}
else
{
reader.skipCurrentElement();
}
}
if (reader.hasError())
{
setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
return false;
}
if (isNewFormat)
{
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = LinkID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = LinkID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = LinkID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = LinkID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
//update names to pointers
updateNames2Ptr();
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem * Its = LinkID[lc.key()];
PageItem * Itn = LinkID[lc.value()];
if (!Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
else
{
if (TableItemsF.count() != 0)
{
for (int ttc = 0; ttc < TableItemsF.count(); ++ttc)
{
PageItem* ta = TableItemsF.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDF[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDF[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDF[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDF[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDM[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDM[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDM[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDM[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0 ; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
//update names to pointers
updateNames2Ptr();
// reestablish textframe links
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem *Its(nullptr), *Itn(nullptr);
if (lc.key() < m_Doc->DocItems.count())
Its = m_Doc->DocItems.at(lc.key());
if (lc.value() < m_Doc->DocItems.count())
Itn = m_Doc->DocItems.at(lc.value());
if (!Its || !Itn || !Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
while (groupStackP.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackP.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->DocItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackF.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackF.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, nullptr);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackM.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackM.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->MasterItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
if (!converted)
gItem->groupItemList = gpL;
}
return true;
}
bool Scribus150Format::loadStory(const QByteArray& data, StoryText& story, PageItem* item)
{
isNewFormat = false;
parStyleMap.clear();
charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
itemRemapM.clear();
itemNextM.clear();
itemCountM = 0;
itemRemapF.clear();
itemNextF.clear();
FrameItems.clear();
LinkID.clear();
markeredItemsMap.clear();
markeredMarksMap.clear();
nsetRangeItemNamesMap.clear();
notesFramesData.clear();
notesMasterMarks.clear();
notesNSets.clear();
bool firstElement = true;
bool success = true;
ReadObjectParams readObjectParams;
readObjectParams.baseDir = QString() /*fileDir*/; //FIXME
readObjectParams.itemKind = PageItem::InlineItem;
readObjectParams.loadingPage = true;
ScXmlStreamReader reader(data);
ScXmlStreamAttributes attrs;
while (!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QString tagName(reader.nameAsString());
attrs = reader.scAttributes();
if (firstElement)
{
if (tagName != QLatin1String("ScribusStory"))
{
success = false;
break;
}
firstElement = false;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == QLatin1String("COLOR") && attrs.valueAsString("NAME") != CommonStrings::None)
{
QString colorName = attrs.valueAsString("NAME");
if (m_Doc->PageColors.contains(colorName))
continue;
readColor(m_Doc->PageColors, attrs);
}
if (tagName == QLatin1String("Gradient"))
{
VGradient gra;
QString grName = attrs.valueAsString("Name");
success = readGradient(m_Doc, gra, reader);
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
if (!grName.isEmpty() && !m_Doc->docGradients.contains(grName))
m_Doc->docGradients.insert(grName, gra);
}
if (tagName == QLatin1String("STYLE"))
{
ParagraphStyle pstyle;
readParagraphStyle(m_Doc, reader, pstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->paragraphStyles().contains(pstyle.name()))
continue;
StyleSet<ParagraphStyle> tmp;
tmp.create(pstyle);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == QLatin1String("CHARSTYLE"))
{
CharStyle cstyle;
ScXmlStreamAttributes attrs = reader.scAttributes();
readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->charStyles().contains(cstyle.name()))
continue;
StyleSet<CharStyle> temp;
temp.create(cstyle);
m_Doc->redefineCharStyles(temp, false);
}
if (tagName == QLatin1String("TableStyle"))
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->tableStyles().contains(tstyle.name()))
continue;
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
}
if (tagName == QLatin1String("CellStyle"))
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
if (m_Doc->cellStyles().contains(tstyle.name()))
continue;
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
}
if (tagName == QLatin1String("Arrows"))
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
if (tagName == QLatin1String("MultiLine"))
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success)
break;
if (!mlName.isEmpty() && !m_Doc->docLineStyles.contains(mlName))
m_Doc->docLineStyles.insert(mlName, ml);
}
if (tagName == QLatin1String("FRAMEOBJECT"))
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, readObjectParams, itemInfo);
if (!success)
break;
itemInfo.item->m_layerID = LayerToPaste;
}
if (tagName == QLatin1String("StoryText"))
{
readStoryText(m_Doc, reader, story, item);
}
if (tagName == QLatin1String("Pattern")) // FIXME
{
/*success = readPattern(m_Doc, reader, fileDir);
if (!success) break;*/
}
if (tagName == QLatin1String("NotesStyles"))
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
if (tagName == QLatin1String("Notes"))
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
if (tagName == QLatin1String("Marks"))
{
success = readMarks(m_Doc, reader);
if (!success) break;
}
}
if (reader.hasError())
{
setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
return false;
}
//update names to pointers
updateNames2Ptr();
return true;
}
bool Scribus150Format::loadPalette(const QString & fileName)
{
if (m_Doc == nullptr || m_AvailableFonts == nullptr)
{
Q_ASSERT(m_Doc == nullptr || m_AvailableFonts == nullptr);
return false;
}
Xp = 0.0;
Yp = 0.0;
GrX = 0.0;
GrY = 0.0;
isNewFormat = false;
QMap<int, PageItem*> TableID;
QMap<int, PageItem*> TableIDM;
QMap<int, PageItem*> TableIDF;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsM;
QList<PageItem*> TableItemsF;
QMap<int, PageItem*> WeldID;
QList<PageItem*> WeldItems;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
QStack< QList<PageItem*> > groupStackPI;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStackFI2;
QStack<int> groupStackMI2;
QStack<int> groupStackPI2;
QScopedPointer<QIODevice> ioDevice(paletteReader(fileName));
if (ioDevice.isNull())
{
setFileReadError();
return false;
}
QString fileDir = QFileInfo(fileName).absolutePath();
if (m_mwProgressBar != nullptr)
{
m_mwProgressBar->setMaximum(ioDevice->size());
m_mwProgressBar->setValue(0);
}
itemRemap.clear();
itemNext.clear();
itemCount = 0;
itemRemapM.clear();
itemNextM.clear();
itemCountM = 0;
itemRemapF.clear();
itemNextF.clear();
TableItems.clear();
TableID.clear();
TableItemsM.clear();
TableIDM.clear();
TableItemsF.clear();
TableIDF.clear();
WeldItems.clear();
m_Doc->GroupCounter = 1;
m_Doc->LastAuto = nullptr;
// m_Doc->PageColors.clear();
// m_Doc->Layers.clear();
bool firstElement = true;
bool success = true;
int progress = 0;
ReadObjectParams readObjectParams;
readObjectParams.baseDir = fileDir;
readObjectParams.itemKind = PageItem::StandardItem;
readObjectParams.loadingPage = false;
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
while (!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QString tagName(reader.nameAsString());
attrs = reader.scAttributes();
if (m_mwProgressBar != nullptr)
{
int newProgress = qRound(ioDevice->pos() / (double) ioDevice->size() * 100);
if (newProgress != progress)
{
m_mwProgressBar->setValue(reader.characterOffset());
progress = newProgress;
}
}
if (firstElement)
{
if (tagName != QLatin1String("SCRIBUSCOLORS"))
{
success = false;
break;
}
firstElement = false;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == QLatin1String("COLOR") && attrs.valueAsString("NAME") != CommonStrings::None)
readColor(m_Doc->PageColors, attrs);
if (tagName == QLatin1String("Gradient"))
{
VGradient gra;
QString grName = attrs.valueAsString("Name");
success = readGradient(m_Doc, gra, reader);
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
if (!grName.isEmpty())
{
m_Doc->docGradients.insert(grName, gra);
}
}
if (tagName == QLatin1String("Arrows"))
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
if (tagName == QLatin1String("MultiLine"))
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success) break;
if (!mlName.isEmpty())
{
m_Doc->docLineStyles.insert(mlName, ml);
}
}
if (tagName == QLatin1String("PAGEOBJECT") || tagName == QLatin1String("MASTEROBJECT") || tagName == QLatin1String("FRAMEOBJECT"))
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, readObjectParams, itemInfo);
if (!success) break;
if (isNewFormat)
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.itemID] = itemInfo.nextItem;
if (itemInfo.item->isTableItem)
TableItems.append(itemInfo.item);
if (itemInfo.isWeldFlag)
WeldItems.append(itemInfo.item);
}
else
{
// first of linked chain?
if (tagName == QLatin1String("PAGEOBJECT"))
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
else if (tagName == QLatin1String("MASTEROBJECT"))
{
if (itemInfo.nextItem != -1)
itemNextM[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == QLatin1String("PAGEOBJECT"))
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
else if (tagName == QLatin1String("FRAMEOBJECT"))
{
TableItemsF.append(itemInfo.item);
TableIDF.insert(itemInfo.ownLink, itemInfo.item);
}
else
{
TableItemsM.append(itemInfo.item);
TableIDM.insert(itemInfo.ownLink, itemInfo.item);
}
}
if (itemInfo.isWeldFlag)
{
WeldItems.append(itemInfo.item);
WeldID.insert(itemInfo.ownWeld, itemInfo.item);
}
}
if ((tagName == QLatin1String("PAGEOBJECT")) && (groupStackPI.count() > 0))
{
groupStackPI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackPI2.top())
{
groupStackP.push(groupStackPI.pop());
groupStackPI2.pop();
if (groupStackPI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("FRAMEOBJECT")) && (groupStackFI.count() > 0))
{
groupStackFI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackFI2.top())
{
groupStackF.push(groupStackFI.pop());
groupStackFI2.pop();
if (groupStackFI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("MASTEROBJECT")) && (groupStackMI.count() > 0))
{
groupStackMI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackMI2.top())
{
groupStackM.push(groupStackMI.pop());
groupStackMI2.pop();
if (groupStackMI2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> groupItems;
groupItems.append(itemInfo.item);
if (tagName == QLatin1String("PAGEOBJECT"))
{
groupStackPI.push(groupItems);
groupStackPI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else if (tagName == QLatin1String("FRAMEOBJECT"))
{
groupStackFI.push(groupItems);
groupStackFI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else
{
groupStackMI.push(groupItems);
groupStackMI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
}
if (tagName == QLatin1String("Pattern"))
{
success = readPattern(m_Doc, reader, fileDir);
if (!success) break;
}
if (tagName == QLatin1String("NotesStyles"))
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
if (tagName == QLatin1String("NotesFrames"))
{
success = readNotesFrames(reader);
if (!success) break;
}
if (tagName == QLatin1String("Notes"))
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
if (tagName == QLatin1String("Marks"))
{
success = readMarks(m_Doc, reader);
if (!success) break;
}
}
if (reader.hasError())
{
setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
return false;
}
if (isNewFormat)
{
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = LinkID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = LinkID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = LinkID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = LinkID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0 ; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem * Its = LinkID[lc.key()];
PageItem * Itn = LinkID[lc.value()];
if (!Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
else
{
if (TableItemsF.count() != 0)
{
for (int ttc = 0; ttc < TableItemsF.count(); ++ttc)
{
PageItem* ta = TableItemsF.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDF[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDF[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDF[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDF[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDM[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDM[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDM[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDM[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0 ; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
// reestablish textframe links
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem *Its(nullptr), *Itn(nullptr);
if (lc.key() < m_Doc->DocItems.count())
Its = m_Doc->DocItems.at(lc.key());
if (lc.value() < m_Doc->DocItems.count())
Itn = m_Doc->DocItems.at(lc.value());
if (!Its || !Itn || !Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
if (itemNextM.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem *Its(nullptr), *Itn(nullptr);
if (lc.key() < m_Doc->MasterItems.count())
Its = m_Doc->MasterItems.at(lc.key());
if (lc.value() < m_Doc->MasterItems.count())
Itn = m_Doc->MasterItems.at(lc.value());
if (!Its || !Itn || !Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
while (groupStackP.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackP.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->DocItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackF.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackF.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, nullptr);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackM.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackM.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->MasterItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
if (!converted)
gItem->groupItemList = gpL;
}
if (m_Doc->Layers.count() == 0)
m_Doc->Layers.newLayer( QObject::tr("Background") );
if (m_mwProgressBar!=nullptr)
{
m_mwProgressBar->setValue(reader.characterOffset());
m_mwProgressBar->reset();
}
return true;
}
bool Scribus150Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */)
{
if (m_Doc==nullptr || m_AvailableFonts==nullptr)
{
Q_ASSERT(m_Doc==nullptr || m_AvailableFonts==nullptr);
return false;
}
Xp = 0.0;
Yp = 0.0;
GrX = 0.0;
GrY = 0.0;
struct ScribusDoc::BookMa bok;
QMap<int, ScribusDoc::BookMa> bookmarks;
isNewFormat = false;
QMap<int, PageItem*> TableID;
QMap<int, PageItem*> TableIDM;
QMap<int, PageItem*> TableIDF;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsM;
QList<PageItem*> TableItemsF;
QMap<int, PageItem*> WeldID;
QList<PageItem*> WeldItems;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
QStack< QList<PageItem*> > groupStackPI;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStackFI2;
QStack<int> groupStackMI2;
QStack<int> groupStackPI2;
markeredItemsMap.clear();
markeredMarksMap.clear();
nsetRangeItemNamesMap.clear();
notesFramesData.clear();
notesMasterMarks.clear();
notesNSets.clear();
QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
if (ioDevice.isNull())
{
setFileReadError();
return false;
}
QString fileDir = QFileInfo(fileName).absolutePath();
int firstPage = 0;
int layerToSetActive = 0;
if (m_mwProgressBar != nullptr)
{
m_mwProgressBar->setMaximum(ioDevice->size());
m_mwProgressBar->setValue(0);
}
// Stop autosave timer,it will be restarted only if doc has autosave feature is enabled
if (m_Doc->autoSaveTimer->isActive())
m_Doc->autoSaveTimer->stop();
parStyleMap.clear();
charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
itemRemapM.clear();
itemNextM.clear();
itemCountM = 0;
itemRemapF.clear();
itemNextF.clear();
FrameItems.clear();
TableItems.clear();
TableID.clear();
TableItemsM.clear();
TableIDM.clear();
TableItemsF.clear();
TableIDF.clear();
WeldItems.clear();
WeldID.clear();
LinkID.clear();
m_Doc->GroupCounter = 1;
m_Doc->LastAuto = nullptr;
m_Doc->PageColors.clear();
m_Doc->Layers.clear();
ReadObjectParams readObjectParams;
readObjectParams.baseDir = fileDir;
readObjectParams.itemKind = PageItem::StandardItem;
readObjectParams.loadingPage = false;
bool firstElement = true;
bool success = true;
bool hasPageSets = false;
int progress = 0;
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
while (!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QString tagName(reader.nameAsString());
attrs = reader.scAttributes();
if (m_mwProgressBar != nullptr)
{
int newProgress = qRound(ioDevice->pos() / (double) ioDevice->size() * 100);
if (newProgress != progress)
{
m_mwProgressBar->setValue(reader.characterOffset());
progress = newProgress;
}
}
if (firstElement)
{
if (tagName != QLatin1String("SCRIBUSUTF8NEW"))
{
success = false;
break;
}
firstElement = false;
continue;
}
if (tagName == QLatin1String("DOCUMENT"))
{
readDocAttributes(m_Doc, attrs);
layerToSetActive = attrs.valueAsInt("ALAYER", 0);
if (m_Doc->pagePositioning() == 0)
firstPage = 0;
else
{
if (attrs.valueAsInt("FIRSTLEFT", 0) == 1)
firstPage = 0;
else
firstPage = 1;
}
if (attrs.hasAttribute("currentProfile"))
{
m_Doc->clearCheckerProfiles();
m_Doc->setCurCheckProfile(attrs.valueAsString("currentProfile"));
}
}
else if (tagName == QLatin1String("CheckProfile"))
{
success = readCheckProfile(m_Doc, attrs);
if (!success) break;
}
else if (tagName == QLatin1String("PageSets"))
{
success = readPageSets(m_Doc, reader);
if (!success) break;
hasPageSets = true;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
else if (tagName == QLatin1String("COLOR") && attrs.valueAsString("NAME") != CommonStrings::None)
readColor(m_Doc->PageColors, attrs);
else if (tagName == QLatin1String("Gradient"))
{
VGradient gra;
QString grName = attrs.valueAsString("Name");
success = readGradient(m_Doc, gra, reader);
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
if (!grName.isEmpty())
m_Doc->docGradients.insert(grName, gra);
}
else if (tagName == QLatin1String("STYLE"))
{
ParagraphStyle pstyle;
readParagraphStyle(m_Doc, reader, pstyle);
StyleSet<ParagraphStyle>tmp;
tmp.create(pstyle);
m_Doc->redefineStyles(tmp, false);
}
else if (tagName == QLatin1String("CHARSTYLE"))
{
CharStyle cstyle;
ScXmlStreamAttributes attrs = reader.scAttributes();
readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle);
StyleSet<CharStyle> temp;
temp.create(cstyle);
m_Doc->redefineCharStyles(temp, false);
}
else if (tagName == QLatin1String("TableStyle"))
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
}
else if (tagName == QLatin1String("CellStyle"))
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
}
else if (tagName == QLatin1String("JAVA"))
{
QString name = attrs.valueAsString("NAME");
if (!name.isEmpty())
m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
}
else if (tagName == QLatin1String("LAYERS"))
{
ScLayer newLayer;
readLayers(newLayer, attrs);
m_Doc->Layers.append(newLayer);
}
else if (tagName == QLatin1String("Arrows"))
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
else if (tagName == QLatin1String("MultiLine"))
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success) break;
if (!mlName.isEmpty())
{
m_Doc->docLineStyles.insert(mlName, ml);
}
}
else if (tagName == QLatin1String("Bookmark"))
{
int bmElem = 0;
struct ScribusDoc::BookMa bookmark;
success = readBookMark(bookmark, bmElem, attrs);
if (!success) break;
bookmarks.insert(bmElem, bookmark);
}
else if (tagName == QLatin1String("PDF"))
{
success = readPDFOptions(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("Printer"))
{
success = readPrinterOptions(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("DocItemAttributes"))
{
success = readDocItemAttributes(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("TablesOfContents"))
{
success = readTableOfContents(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("Sections"))
{
success = readSections(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("HYPHEN"))
{
success = readHyphen(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("PAGE") || tagName == QLatin1String("MASTERPAGE"))
{
success = readPage(m_Doc, reader);
if (!success)
break;
}
else if (tagName == QLatin1String("PAGEOBJECT") || tagName == QLatin1String("MASTEROBJECT") || tagName == QLatin1String("FRAMEOBJECT"))
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, readObjectParams, itemInfo);
if (!success)
break;
// first of linked chain?
if (isNewFormat)
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.itemID] = itemInfo.nextItem;
if (itemInfo.item->isTableItem)
TableItems.append(itemInfo.item);
if (itemInfo.isWeldFlag)
WeldItems.append(itemInfo.item);
}
else
{
if (tagName == QLatin1String("PAGEOBJECT"))
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
else if (tagName == QLatin1String("MASTEROBJECT"))
{
if (itemInfo.nextItem != -1)
itemNextM[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == QLatin1String("PAGEOBJECT"))
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
else if (tagName == QLatin1String("FRAMEOBJECT"))
{
TableItemsF.append(itemInfo.item);
TableIDF.insert(itemInfo.ownLink, itemInfo.item);
}
else
{
TableItemsM.append(itemInfo.item);
TableIDM.insert(itemInfo.ownLink, itemInfo.item);
}
}
if (itemInfo.isWeldFlag)
{
WeldItems.append(itemInfo.item);
WeldID.insert(itemInfo.ownWeld, itemInfo.item);
}
}
if ((tagName == QLatin1String("PAGEOBJECT")) && (groupStackPI.count() > 0))
{
groupStackPI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackPI2.top())
{
groupStackP.push(groupStackPI.pop());
groupStackPI2.pop();
if (groupStackPI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("FRAMEOBJECT")) && (groupStackFI.count() > 0))
{
groupStackFI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackFI2.top())
{
groupStackF.push(groupStackFI.pop());
groupStackFI2.pop();
if (groupStackFI2.count() == 0)
break;
}
}
else if ((tagName == QLatin1String("MASTEROBJECT")) && (groupStackMI.count() > 0))
{
groupStackMI.top().append(itemInfo.item);
while (itemInfo.ownNr == groupStackMI2.top())
{
groupStackM.push(groupStackMI.pop());
groupStackMI2.pop();
if (groupStackMI2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> groupItems;
groupItems.append(itemInfo.item);
if (tagName == QLatin1String("PAGEOBJECT"))
{
groupStackPI.push(groupItems);
groupStackPI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else if (tagName == QLatin1String("FRAMEOBJECT"))
{
groupStackFI.push(groupItems);
groupStackFI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
else
{
groupStackMI.push(groupItems);
groupStackMI2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
}
else if (tagName == QLatin1String("Pattern"))
{
success = readPattern(m_Doc, reader, fileDir);
if (!success)
break;
}
else if (tagName == QLatin1String("NotesStyles"))
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("NotesFrames"))
{
success = readNotesFrames(reader);
if (!success) break;
}
else if (tagName == QLatin1String("Notes"))
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
else if (tagName == QLatin1String("Marks"))
{
success = readMarks(m_Doc, reader);
if (!success) break;
}
else
{
reader.skipCurrentElement();
}
}
if (reader.hasError())
{
setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
return false;
}
QMap<int, ScribusDoc::BookMa>::Iterator it;
for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
{
int elem = it.key();
PageItem* item = LinkID.value(elem, (PageItem*) nullptr);
if (!item)
continue;
ScribusDoc::BookMa bookmark = it.value();
bookmark.PageObject = item;
m_Doc->BookMarks.append( bookmark );
}
std::stable_sort(m_Doc->BookMarks.begin(), m_Doc->BookMarks.end());
if (isNewFormat)
{
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = LinkID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = LinkID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = LinkID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = LinkID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0 ; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = LinkID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem * Its = LinkID[lc.key()];
PageItem * Itn = LinkID[lc.value()];
if (!Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
else
{
if (TableItemsF.count() != 0)
{
for (int ttc = 0; ttc < TableItemsF.count(); ++ttc)
{
PageItem* ta = TableItemsF.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDF[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDF[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDF[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDF[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableIDM[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableIDM[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableIDM[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableIDM[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->m_topLink = TableID[ta->TopLinkID];
else
ta->m_topLink = nullptr;
if (ta->LeftLinkID != -1)
ta->m_leftLink = TableID[ta->LeftLinkID];
else
ta->m_leftLink = nullptr;
if (ta->RightLinkID != -1)
ta->m_rightLink = TableID[ta->RightLinkID];
else
ta->m_rightLink = nullptr;
if (ta->BottomLinkID != -1)
ta->m_bottomLink = TableID[ta->BottomLinkID];
else
ta->m_bottomLink = nullptr;
}
}
if (WeldItems.count() != 0)
{
for (int ttc = 0; ttc < WeldItems.count(); ++ttc)
{
PageItem* ta = WeldItems.at(ttc);
for (int i = 0 ; i < ta->weldList.count(); ++i)
{
PageItem::WeldingInfo wInf = ta->weldList.at(i);
ta->weldList[i].weldItem = WeldID.value(wInf.weldID, 0);
if (ta->weldList[i].weldItem == nullptr)
ta->weldList.removeAt(i--);
}
}
}
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem *Its(nullptr), *Itn(nullptr);
if (lc.key() < m_Doc->DocItems.count())
Its = m_Doc->DocItems.at(lc.key());
if (lc.value() < m_Doc->DocItems.count())
Itn = m_Doc->DocItems.at(lc.value());
if (!Its || !Itn || !Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
if (itemNextM.count() != 0)
{
QMap<int,int>::Iterator lc;
for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
{
if (lc.value() >= 0)
{
PageItem *Its(nullptr), *Itn(nullptr);
if (lc.key() < m_Doc->MasterItems.count())
Its = m_Doc->MasterItems.at(lc.key());
if (lc.value() < m_Doc->MasterItems.count())
Itn = m_Doc->MasterItems.at(lc.value());
if (!Its || !Itn || !Its->canBeLinkedTo(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
//CB Add this in to set this in the file in memory. Its saved, why not load it.
//Will of course be replaced by per page settings although we still probably need a document default
if (!hasPageSets)
{
m_Doc->setPageSetFirstPage(m_Doc->pagePositioning(), firstPage);
//->Prefs m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = firstPage;
// m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble();
// m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0;
// m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble();
}
m_Doc->setActiveLayer(layerToSetActive);
m_Doc->setMasterPageMode(false);
m_Doc->reformPages();
m_Doc->refreshGuides();
// #12282 : some docs have language dependent style names specified in style properties
// #14129 : some others reference deleted character styles
m_Doc->fixCharacterStyles();
m_Doc->fixParagraphStyles();
m_Doc->fixNotesStyles();
// #14603 : it seems we need this also for some 1.5.x docs
m_Doc->fixItemPageOwner();
if (m_Doc->Layers.count() == 0)
m_Doc->Layers.newLayer( QObject::tr("Background") );
if (!pdfPresEffects.isEmpty())
{
for (int pdoE = 0; pdoE < pdfPresEffects.count(); ++pdoE)
{
if (pdoE < m_Doc->Pages->count())
m_Doc->Pages->at(pdoE)->PresentVals = pdfPresEffects[pdoE];
}
}
while (groupStackP.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackP.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->DocItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackF.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackF.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, nullptr);
if (!converted)
gItem->groupItemList = gpL;
}
while (groupStackM.count() > 0)
{
bool isTableIt = false;
QList<PageItem*> gpL = groupStackM.pop();
PageItem* gItem = gpL.takeFirst();
for (int id = 0; id < gpL.count(); id++)
{
PageItem* cItem = gpL.at(id);
isTableIt = cItem->isTableItem;
cItem->gXpos = cItem->xPos() - gItem->xPos();
cItem->gYpos = cItem->yPos() - gItem->yPos();
cItem->Parent = gItem;
if (gItem->rotation() != 0)
{
QTransform ma;
ma.rotate(-gItem->rotation());
FPoint n(cItem->gXpos, cItem->gYpos);
cItem->gXpos = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
cItem->gYpos = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
cItem->setRotation(cItem->rotation() - gItem->rotation());
cItem->oldRot = cItem->rotation();
}
m_Doc->MasterItems.removeOne(cItem);
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
if (!converted)
gItem->groupItemList = gpL;
}
//update names to pointers
updateNames2Ptr();
// reestablish first/lastAuto
m_Doc->FirstAuto = m_Doc->LastAuto;
if (m_Doc->LastAuto)
{
while (m_Doc->LastAuto->nextInChain())
m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
while (m_Doc->FirstAuto->prevInChain())
m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
}
// start auto save timer if needed
if (m_Doc->autoSave() && ScCore->usingGUI())
m_Doc->restartAutoSaveTimer();
// m_Doc->autoSaveTimer->start(m_Doc->autoSaveTime());
if (m_mwProgressBar!=nullptr)
m_mwProgressBar->setValue(reader.characterOffset());
return true;
}
// Low level plugin API
int scribus150format_getPluginAPIVersion()
{
return PLUGIN_API_VERSION;
}
ScPlugin* scribus150format_getPlugin()
{
Scribus150Format* plug = new Scribus150Format();
Q_CHECK_PTR(plug);
return plug;
}
void scribus150format_freePlugin(ScPlugin* plugin)
{
Scribus150Format* plug = qobject_cast<Scribus150Format*>(plugin);
Q_ASSERT(plug);
delete plug;
}
namespace {
const int NOVALUE = -16000;
void fixLegacyCharStyle(CharStyle& cstyle)
{
if (! cstyle.font().usable())
cstyle.resetFont();
if (cstyle.fontSize() <= NOVALUE / 10)
cstyle.resetFontSize();
// if (cstyle.effects() == 65535)
// cstyle.resetEffects();
if (cstyle.fillColor().isEmpty())
cstyle.resetFillColor();
if (cstyle.fillShade() <= NOVALUE)
cstyle.resetFillShade();
if (cstyle.strokeColor().isEmpty())
cstyle.resetStrokeColor();
if (cstyle.strokeShade() <= NOVALUE)
cstyle.resetStrokeShade();
if (cstyle.shadowXOffset() <= NOVALUE / 10)
cstyle.resetShadowXOffset();
if (cstyle.shadowYOffset() <= NOVALUE / 10)
cstyle.resetShadowYOffset();
if (cstyle.outlineWidth() <= NOVALUE / 10)
cstyle.resetOutlineWidth();
if (cstyle.underlineOffset() <= NOVALUE / 10)
cstyle.resetUnderlineOffset();
if (cstyle.underlineWidth() <= NOVALUE / 10)
cstyle.resetUnderlineWidth();
if (cstyle.strikethruOffset() <= NOVALUE / 10)
cstyle.resetStrikethruOffset();
if (cstyle.strikethruWidth() <= NOVALUE / 10)
cstyle.resetStrikethruWidth();
if (cstyle.scaleH() <= NOVALUE / 10)
cstyle.resetScaleH();
if (cstyle.scaleV() <= NOVALUE / 10)
cstyle.resetScaleV();
if (cstyle.baselineOffset() <= NOVALUE / 10)
cstyle.resetBaselineOffset();
if (cstyle.tracking() <= NOVALUE / 10)
cstyle.resetTracking();
}
void fixLegacyParStyle(ParagraphStyle& pstyle)
{
if (pstyle.lineSpacing() <= NOVALUE)
pstyle.resetLineSpacing();
if (pstyle.leftMargin() <= NOVALUE)
pstyle.resetLeftMargin();
if (pstyle.rightMargin() <= NOVALUE)
pstyle.resetRightMargin();
if (pstyle.firstIndent() <= NOVALUE)
pstyle.resetFirstIndent();
if (pstyle.alignment() < 0)
pstyle.resetAlignment();
if (pstyle.gapBefore() <= NOVALUE)
pstyle.resetGapBefore();
if (pstyle.gapAfter() <= NOVALUE)
pstyle.resetGapAfter();
if (pstyle.dropCapLines() < 0)
pstyle.resetDropCapLines();
if (pstyle.parEffectOffset() <= NOVALUE)
pstyle.resetParEffectOffset();
fixLegacyCharStyle(pstyle.charStyle());
}
}// namespace
void Scribus150Format::readDocAttributes(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
m_Doc->setPageSize(attrs.valueAsString("PAGESIZE"));
m_Doc->setPageOrientation(attrs.valueAsInt("ORIENTATION", 0));
m_Doc->FirstPnum = attrs.valueAsInt("FIRSTNUM", 1);
m_Doc->setPagePositioning(attrs.valueAsInt("BOOK", 0));
m_Doc->setUsesAutomaticTextFrames( attrs.valueAsInt("AUTOTEXT") );
m_Doc->PageSp = attrs.valueAsInt("AUTOSPALTEN");
m_Doc->PageSpa = attrs.valueAsDouble("ABSTSPALTEN");
m_Doc->setUnitIndex( attrs.valueAsInt("UNITS", 0) );
static const QString LANGUAGE("LANGUAGE");
if (attrs.hasAttribute(LANGUAGE))
{
QString l(attrs.valueAsString(LANGUAGE));
if (LanguageManager::instance()->langTableIndex(l) != -1)
m_Doc->setLanguage(l); //new style storage
else
{ //old style storage
QString lnew = LanguageManager::instance()->getAbbrevFromLang(l, false);
if (lnew.isEmpty())
lnew = LanguageManager::instance()->getAbbrevFromLang(l, false);
m_Doc->setLanguage(lnew);
}
}
if (attrs.hasAttribute("PAGEWIDTH"))
m_Doc->setPageWidth(attrs.valueAsDouble("PAGEWIDTH"));
else
m_Doc->setPageWidth(attrs.valueAsDouble("PAGEWITH"));
m_Doc->setPageHeight(attrs.valueAsDouble("PAGEHEIGHT"));
m_Doc->margins()->setLeft(qMax(0.0, attrs.valueAsDouble("BORDERLEFT")));
m_Doc->margins()->setRight(qMax(0.0, attrs.valueAsDouble("BORDERRIGHT")));
m_Doc->margins()->setTop(qMax(0.0, attrs.valueAsDouble("BORDERTOP")));
m_Doc->margins()->setBottom(qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM")));
m_Doc->setMarginPreset(attrs.valueAsInt("PRESET", 0));
m_Doc->bleeds()->setTop(attrs.valueAsDouble("BleedTop", 0.0));
m_Doc->bleeds()->setLeft(attrs.valueAsDouble("BleedLeft", 0.0));
m_Doc->bleeds()->setRight(attrs.valueAsDouble("BleedRight", 0.0));
m_Doc->bleeds()->setBottom(attrs.valueAsDouble("BleedBottom", 0.0));
m_Doc->setHyphAutomatic(attrs.valueAsBool("AUTOMATIC", true));
m_Doc->setHyphAutoCheck(attrs.valueAsBool("AUTOCHECK", false));
m_Doc->GuideLock = attrs.valueAsBool("GUIDELOCK", false);
m_Doc->rulerXoffset = attrs.valueAsDouble("rulerXoffset", 0.0);
m_Doc->rulerYoffset = attrs.valueAsDouble("rulerYoffset", 0.0);
m_Doc->SnapGuides = attrs.valueAsBool("SnapToGuides", false);
m_Doc->SnapElement = attrs.valueAsBool("SnapToElement", false);
m_Doc->SnapGrid = attrs.valueAsBool("SnapToGrid", false);
m_Doc->setAutoSave(attrs.valueAsBool("AutoSave", false));
m_Doc->setAutoSaveTime(attrs.valueAsInt("AutoSaveTime", 600000));
m_Doc->setAutoSaveKeep(attrs.valueAsBool("AutoSaveKeep", false));
m_Doc->setAutoSaveCount(attrs.valueAsInt("AutoSaveCount", 1));
m_Doc->setAutoSaveInDocDir(attrs.valueAsBool("AUtoSaveInDocDir", true));
m_Doc->setAutoSaveDir(attrs.valueAsString("AutoSaveDir", ""));
double leftScratch;
// FIXME A typo in early 1.3cvs (MAR 05) means we must support loading of
// FIXME 'ScatchLeft' for a while too. This can be removed in a few months.
if (attrs.hasAttribute("ScatchLeft"))
leftScratch = attrs.valueAsDouble("ScatchLeft", 100.0);
else
leftScratch = attrs.valueAsDouble("ScratchLeft", 100.0);
m_Doc->scratch()->set(attrs.valueAsDouble("ScratchTop", 20.0), leftScratch,
attrs.valueAsDouble("ScratchBottom", 20.0),attrs.valueAsDouble("ScratchRight", 100.0));
m_Doc->setPageGapHorizontal(attrs.valueAsDouble("GapHorizontal", -1.0));
m_Doc->setPageGapVertical(attrs.valueAsDouble("GapVertical", -1.0));
if (attrs.hasAttribute("PAGEC"))
m_Doc->setPaperColor(QColor(attrs.valueAsString("PAGEC")));
//->Prefs m_Doc->papColor = QColor(attrs.valueAsString("PAGEC"));
m_Doc->setMarginColored(attrs.valueAsBool("RANDF", false));
readCMSSettings(doc, attrs);
readDocumentInfo(doc, attrs);
readGuideSettings(doc, attrs);
readToolSettings(doc, attrs);
readTypographicSettings(doc, attrs);
}
void Scribus150Format::readCMSSettings(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
doc->cmsSettings().SoftProofOn = attrs.valueAsBool("DPSo", false);
doc->cmsSettings().SoftProofFullOn = attrs.valueAsBool("DPSFo", false);
doc->cmsSettings().CMSinUse = attrs.valueAsBool("DPuse", false);
doc->cmsSettings().GamutCheck = attrs.valueAsBool("DPgam", false);
doc->cmsSettings().BlackPoint = attrs.valueAsBool("DPbla", true);
doc->cmsSettings().DefaultMonitorProfile = PrefsManager::instance().appPrefs.colorPrefs.DCMSset.DefaultMonitorProfile;
doc->cmsSettings().DefaultPrinterProfile = attrs.valueAsString("DPPr","");
doc->cmsSettings().DefaultImageRGBProfile = attrs.valueAsString("DPIn","");
doc->cmsSettings().DefaultImageCMYKProfile = attrs.valueAsString("DPInCMYK","");
doc->cmsSettings().DefaultSolidColorRGBProfile = attrs.valueAsString("DPIn2","");
if (attrs.hasAttribute("DPIn3"))
doc->cmsSettings().DefaultSolidColorCMYKProfile = attrs.valueAsString("DPIn3","");
else
doc->cmsSettings().DefaultSolidColorCMYKProfile = attrs.valueAsString("DPPr","");
doc->cmsSettings().DefaultIntentColors = (eRenderIntent) attrs.valueAsInt("DISc", 1);
doc->cmsSettings().DefaultIntentImages = (eRenderIntent) attrs.valueAsInt("DIIm", 0);
}
void Scribus150Format::readDocumentInfo(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
DocumentInformation di;
di.setAuthor(attrs.valueAsString("AUTHOR"));
di.setComments(attrs.valueAsString("COMMENTS"));
di.setKeywords(attrs.valueAsString("KEYWORDS",""));
di.setTitle(attrs.valueAsString("TITLE"));
di.setSubject(attrs.valueAsString("SUBJECT"));
di.setPublisher(attrs.valueAsString("PUBLISHER", ""));
di.setDate(attrs.valueAsString("DOCDATE", ""));
di.setType(attrs.valueAsString("DOCTYPE", ""));
di.setFormat(attrs.valueAsString("DOCFORMAT", ""));
di.setIdent(attrs.valueAsString("DOCIDENT", ""));
di.setSource(attrs.valueAsString("DOCSOURCE", ""));
di.setLangInfo(attrs.valueAsString("DOCLANGINFO", ""));
di.setRelation(attrs.valueAsString("DOCRELATION", ""));
di.setCover(attrs.valueAsString("DOCCOVER", ""));
di.setRights(attrs.valueAsString("DOCRIGHTS", ""));
di.setContrib(attrs.valueAsString("DOCCONTRIB", ""));
doc->setDocumentInfo(di);
}
void Scribus150Format::readGuideSettings(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
PrefsManager& prefsManager = PrefsManager::instance();
doc->guidesPrefs().minorGridSpacing = attrs.valueAsDouble("MINGRID", prefsManager.appPrefs.guidesPrefs.minorGridSpacing);
doc->guidesPrefs().majorGridSpacing = attrs.valueAsDouble("MAJGRID", prefsManager.appPrefs.guidesPrefs.majorGridSpacing);
doc->guidesPrefs().gridShown = attrs.valueAsBool("SHOWGRID", false);
doc->guidesPrefs().guidesShown =attrs.valueAsBool("SHOWGUIDES", true);
doc->guidesPrefs().colBordersShown = attrs.valueAsBool("showcolborders", false);
doc->guidesPrefs().framesShown = attrs.valueAsBool("SHOWFRAME", true);
doc->guidesPrefs().layerMarkersShown = attrs.valueAsBool("SHOWLAYERM", false);
doc->guidesPrefs().marginsShown = attrs.valueAsBool("SHOWMARGIN", true);
doc->guidesPrefs().baselineGridShown = attrs.valueAsBool("SHOWBASE", false);
doc->guidesPrefs().showPic = attrs.valueAsBool("SHOWPICT", true);
doc->guidesPrefs().linkShown = attrs.valueAsBool("SHOWLINK", false);
doc->guidesPrefs().showControls = attrs.valueAsBool("SHOWControl", false);
doc->guidesPrefs().rulerMode = attrs.valueAsBool("rulerMode", true);
doc->guidesPrefs().rulersShown = attrs.valueAsBool("showrulers", true);
doc->guidesPrefs().showBleed = attrs.valueAsBool("showBleed", true);
m_Doc->drawAsPreview = false /*attrs.valueAsBool("previewMode", false)*/;
if (attrs.hasAttribute("MARGC"))
doc->guidesPrefs().marginColor = QColor(attrs.valueAsString("MARGC"));
if (attrs.hasAttribute("MINORC"))
doc->guidesPrefs().minorGridColor = QColor(attrs.valueAsString("MINORC"));
if (attrs.hasAttribute("MAJORC"))
doc->guidesPrefs().majorGridColor = QColor(attrs.valueAsString("MAJORC"));
if (attrs.hasAttribute("GuideC"))
doc->guidesPrefs().guideColor = QColor(attrs.valueAsString("GuideC"));
if (attrs.hasAttribute("BaseC"))
doc->guidesPrefs().baselineGridColor = QColor(attrs.valueAsString("BaseC"));
if (attrs.hasAttribute("BACKG"))
{
doc->guidesPrefs().renderStackOrder.clear();
if (attrs.valueAsBool("BACKG", true))
doc->guidesPrefs().renderStackOrder << 0 << 1 << 2 << 3 << 4;
else
doc->guidesPrefs().renderStackOrder << 4 << 0 << 1 << 2 << 3;
}
if (attrs.hasAttribute("renderStack"))
{
doc->guidesPrefs().renderStackOrder.clear();
QString renderStack = attrs.valueAsString("renderStack", "0 1 2 3 4");
ScTextStream fp(&renderStack, QIODevice::ReadOnly);
QString val;
while (!fp.atEnd())
{
fp >> val;
doc->guidesPrefs().renderStackOrder << val.toInt();
}
}
doc->guidesPrefs().gridType = attrs.valueAsInt("GridType", 0);
doc->guidesPrefs().guideRad = attrs.valueAsDouble("GuideRad", 10.0);
doc->guidesPrefs().grabRadius = attrs.valueAsInt("GRAB", 4);
}
void Scribus150Format::readToolSettings(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
const ItemToolPrefs& defToolPrefs = PrefsManager::instance().appPrefs.itemToolPrefs;
QString textFont = attrs.valueAsString("DFONT");
m_AvailableFonts->findFont(textFont, doc);
doc->itemToolPrefs().textFont = textFont;
doc->itemToolPrefs().textSize = qRound(attrs.valueAsDouble("DSIZE", 12.0) * 10);
doc->itemToolPrefs().textColumns = attrs.valueAsInt("DCOL", 1);
doc->itemToolPrefs().textColumnGap = attrs.valueAsDouble("DGAP", 0.0);
const MarginStruct& defDistances = defToolPrefs.textDistances;
doc->itemToolPrefs().textDistances.setLeft(attrs.valueAsDouble("TextDistLeft", defDistances.left()));
doc->itemToolPrefs().textDistances.setRight(attrs.valueAsDouble("TextDistRight", defDistances.right()));
doc->itemToolPrefs().textDistances.setBottom(attrs.valueAsDouble("TextDistBottom", defDistances.bottom()));
doc->itemToolPrefs().textDistances.setTop(attrs.valueAsDouble("TextDistTop", defDistances.top()));
doc->itemToolPrefs().polyCorners = attrs.valueAsInt("POLYC", 4);
doc->itemToolPrefs().polyFactor = attrs.valueAsDouble("POLYF", 0.5);
doc->itemToolPrefs().polyRotation = attrs.valueAsDouble("POLYR", 0.0);
doc->itemToolPrefs().polyInnerRot = attrs.valueAsDouble("POLYIR", 0.0);
doc->itemToolPrefs().polyCurvature = attrs.valueAsDouble("POLYCUR", 0.0);
doc->itemToolPrefs().polyOuterCurvature = attrs.valueAsDouble("POLYOCUR", 0.0);
doc->itemToolPrefs().polyUseFactor = attrs.valueAsBool("POLYS", false);
doc->itemToolPrefs().arcStartAngle = attrs.valueAsDouble("arcStartAngle", 30.0);
doc->itemToolPrefs().arcSweepAngle = attrs.valueAsDouble("arcSweepAngle", 300.0);
doc->itemToolPrefs().spiralStartAngle = attrs.valueAsDouble("spiralStartAngle", 0.0);
doc->itemToolPrefs().spiralEndAngle = attrs.valueAsDouble("spiralEndAngle", 1080.0);
doc->itemToolPrefs().spiralFactor = attrs.valueAsDouble("spiralFactor", 1.2);
doc->itemToolPrefs().lineStartArrow = attrs.valueAsInt("StartArrow", 0);
doc->itemToolPrefs().lineEndArrow = attrs.valueAsInt("EndArrow", 0);
doc->itemToolPrefs().imageScaleX = attrs.valueAsDouble("PICTSCX", 1.0);
doc->itemToolPrefs().imageScaleY = attrs.valueAsDouble("PICTSCY", 1.0);
doc->itemToolPrefs().imageScaleType = attrs.valueAsBool("PSCALE", true);
doc->itemToolPrefs().imageAspectRatio = attrs.valueAsBool("PASPECT", false);
doc->itemToolPrefs().imageLowResType = attrs.valueAsInt("HalfRes", 1);
doc->itemToolPrefs().imageUseEmbeddedPath = attrs.valueAsBool("EmbeddedPath", false);
if (attrs.hasAttribute("PEN"))
doc->itemToolPrefs().shapeLineColor = attrs.valueAsString("PEN");
if (attrs.hasAttribute("BRUSH"))
doc->itemToolPrefs().shapeFillColor = attrs.valueAsString("BRUSH");
if (attrs.hasAttribute("PENLINE"))
doc->itemToolPrefs().lineColor = attrs.valueAsString("PENLINE");
if (attrs.hasAttribute("PENTEXT"))
doc->itemToolPrefs().textColor = attrs.valueAsString("PENTEXT");
if (attrs.hasAttribute("StrokeText"))
doc->itemToolPrefs().textStrokeColor = attrs.valueAsString("StrokeText");
doc->itemToolPrefs().textFillColor = attrs.valueAsString("TextBackGround", CommonStrings::None);
doc->itemToolPrefs().textLineColor = attrs.valueAsString("TextLineColor", CommonStrings::None);
doc->itemToolPrefs().textFillColorShade =attrs.valueAsInt("TextBackGroundShade", 100);
doc->itemToolPrefs().textLineColorShade = attrs.valueAsInt("TextLineShade", 100);
doc->itemToolPrefs().textShade = attrs.valueAsInt("TextPenShade", 100);
doc->itemToolPrefs().textStrokeShade = attrs.valueAsInt("TextStrokeShade", 100);
doc->itemToolPrefs().shapeLineStyle = static_cast<Qt::PenStyle>(attrs.valueAsInt("STIL"));
doc->itemToolPrefs().lineStyle = static_cast<Qt::PenStyle>(attrs.valueAsInt("STILLINE"));
doc->itemToolPrefs().shapeLineWidth = attrs.valueAsDouble("WIDTH", 0.0);
doc->itemToolPrefs().lineWidth = attrs.valueAsDouble("WIDTHLINE", 1.0);
doc->itemToolPrefs().shapeLineColorShade = attrs.valueAsInt("PENSHADE", 100);
doc->itemToolPrefs().lineColorShade = attrs.valueAsInt("LINESHADE", 100);
doc->itemToolPrefs().shapeFillColorShade = attrs.valueAsInt("BRUSHSHADE", 100);
doc->itemToolPrefs().calligraphicPenFillColor = attrs.valueAsString("calligraphicPenFillColor", "Black");
doc->itemToolPrefs().calligraphicPenLineColor = attrs.valueAsString("calligraphicPenLineColor", "Black");
doc->itemToolPrefs().calligraphicPenFillColorShade = attrs.valueAsInt("calligraphicPenFillColorShade", 100);
doc->itemToolPrefs().calligraphicPenLineColorShade = attrs.valueAsInt("calligraphicPenLineColorShade", 100);
doc->itemToolPrefs().calligraphicPenLineWidth = attrs.valueAsDouble("calligraphicPenLineWidth", 1.0);
doc->itemToolPrefs().calligraphicPenAngle = attrs.valueAsDouble("calligraphicPenAngle", 0.0);
doc->itemToolPrefs().calligraphicPenWidth = attrs.valueAsDouble("calligraphicPenWidth", 10.0);
doc->itemToolPrefs().calligraphicPenStyle = static_cast<Qt::PenStyle>(attrs.valueAsInt("calligraphicPenStyle"));
doc->opToolPrefs().dispX = attrs.valueAsDouble("dispX", 10.0);
doc->opToolPrefs().dispY = attrs.valueAsDouble("dispY", 10.0);
doc->opToolPrefs().constrain = attrs.valueAsDouble("constrain", 15.0);
doc->itemToolPrefs().textTabFillChar = attrs.valueAsString("TabFill","");
doc->itemToolPrefs().textTabWidth = attrs.valueAsDouble("TabWidth", 36.0);
doc->itemToolPrefs().firstLineOffset = (FirstLineOffsetPolicy) attrs.valueAsInt("FirstLineOffset", (int) FLOPRealGlyphHeight); // Default to FLOPRealGlyphHeight for legacy docs
doc->itemToolPrefs().firstLineOffset = qMax(FLOPRealGlyphHeight, qMin(doc->itemToolPrefs().firstLineOffset, FLOPBaselineGrid));
if (attrs.hasAttribute("CPICT"))
doc->itemToolPrefs().imageFillColor = attrs.valueAsString("CPICT");
doc->itemToolPrefs().imageFillColorShade = attrs.valueAsInt("PICTSHADE", 100);
if (attrs.hasAttribute("CSPICT"))
doc->itemToolPrefs().imageStrokeColor = attrs.valueAsString("CSPICT");
doc->itemToolPrefs().imageStrokeColorShade = attrs.valueAsInt("PICTSSHADE", 100);
}
void Scribus150Format::readTypographicSettings(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
doc->typographicPrefs().valueSuperScript = attrs.valueAsInt("VHOCH");
doc->typographicPrefs().scalingSuperScript = attrs.valueAsInt("VHOCHSC");
doc->typographicPrefs().valueSubScript = attrs.valueAsInt("VTIEF");
doc->typographicPrefs().scalingSubScript = attrs.valueAsInt("VTIEFSC");
doc->typographicPrefs().valueSmallCaps = attrs.valueAsInt("VKAPIT");
doc->guidesPrefs().valueBaselineGrid = attrs.valueAsDouble("BASEGRID", 12.0);
doc->guidesPrefs().offsetBaselineGrid = attrs.valueAsDouble("BASEO", 0.0);
// #9621 : autolinespacing is now expressed as a percentage of the font height
doc->typographicPrefs().autoLineSpacing = attrs.valueAsInt("AUTOL", 1, 500, 100);
doc->typographicPrefs().valueUnderlinePos = attrs.valueAsInt("UnderlinePos", -1);
doc->typographicPrefs().valueUnderlineWidth = attrs.valueAsInt("UnderlineWidth", -1);
doc->typographicPrefs().valueStrikeThruPos = attrs.valueAsInt("StrikeThruPos", -1);
doc->typographicPrefs().valueStrikeThruWidth = attrs.valueAsInt("StrikeThruWidth", -1);
}
bool Scribus150Format::readPageSets(ScribusDoc* doc, ScXmlStreamReader& reader) const
{
struct PageSet pageS;
ScXmlStreamAttributes attrs;
doc->clearPageSets();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
QString tagName(reader.nameAsString());
if (reader.isStartElement())
attrs = reader.attributes();
if (reader.isEndElement() && tagName == QLatin1String("PageSets"))
break;
if (reader.isStartElement() && tagName == QLatin1String("Set"))
{
ScXmlStreamAttributes attrs = reader.scAttributes();
pageS.Name = CommonStrings::untranslatePageSetString(attrs.valueAsString("Name"));
pageS.FirstPage = attrs.valueAsInt("FirstPage", 0);
pageS.Rows = attrs.valueAsInt("Rows", 1);
pageS.Columns = attrs.valueAsInt("Columns", 1);
// pageS.GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0);
// pageS.GapVertical = attrs.valueAsDouble("GapVertical", 0);
// pageS.GapBelow = attrs.valueAsDouble("GapBelow", 0);
pageS.pageNames.clear();
}
if (reader.isEndElement() && tagName == QLatin1String("Set"))
{
// doc->pageSets.append(pageS);
doc->appendToPageSets(pageS);
if ((doc->pageSets().count()-1 == doc->pagePositioning()) && ((doc->pageGapHorizontal() < 0) && (doc->pageGapVertical() < 0)))
{
doc->setPageGapHorizontal(attrs.valueAsDouble("GapHorizontal", 0.0));
doc->setPageGapVertical(attrs.valueAsDouble("GapBelow", 0.0));
}
}
if (reader.isStartElement() && tagName == QLatin1String("PageNames"))
pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(attrs.valueAsString("Name")));
}
return !reader.hasError();
}
bool Scribus150Format::readCheckProfile(ScribusDoc* doc, const ScXmlStreamAttributes& attrs) const
{
struct CheckerPrefs checkerSettings;
QString profileName = attrs.valueAsString("Name");
if (profileName.isEmpty())
return true;
checkerSettings.ignoreErrors = attrs.valueAsBool("ignoreErrors", false);
checkerSettings.autoCheck = attrs.valueAsBool("autoCheck", true);
checkerSettings.checkGlyphs = attrs.valueAsBool("checkGlyphs", true);
checkerSettings.checkOrphans = attrs.valueAsBool("checkOrphans", true);
checkerSettings.checkOverflow = attrs.valueAsBool("checkOverflow", true);
checkerSettings.checkPictures = attrs.valueAsBool("checkPictures", true);
checkerSettings.checkPartFilledImageFrames = attrs.valueAsBool("checkPartFilledImageFrames", false);
checkerSettings.checkResolution = attrs.valueAsBool("checkResolution", true);
checkerSettings.checkTransparency = attrs.valueAsBool("checkTransparency", true);
checkerSettings.minResolution = attrs.valueAsDouble("minResolution", 72.0);
checkerSettings.maxResolution = attrs.valueAsDouble("maxResolution", 4800.0);
checkerSettings.checkAnnotations = attrs.valueAsBool("checkAnnotations", false);
checkerSettings.checkRasterPDF = attrs.valueAsBool("checkRasterPDF", true);
checkerSettings.checkForGIF = attrs.valueAsBool("checkForGIF", true);
checkerSettings.ignoreOffLayers = attrs.valueAsBool("ignoreOffLayers", false);
checkerSettings.checkNotCMYKOrSpot = attrs.valueAsBool("checkNotCMYKOrSpot", false);
checkerSettings.checkDeviceColorsAndOutputIntent = attrs.valueAsBool("checkDeviceColorsAndOutputIntent", false);
checkerSettings.checkFontNotEmbedded = attrs.valueAsBool("checkFontNotEmbedded", false);
checkerSettings.checkFontIsOpenType = attrs.valueAsBool("checkFontIsOpenType", false);
checkerSettings.checkAppliedMasterDifferentSide = attrs.valueAsBool("checkAppliedMasterDifferentSide", true);
checkerSettings.checkEmptyTextFrames = attrs.valueAsBool("checkEmptyTextFrames", true);
doc->set1CheckerProfile(profileName, checkerSettings);
return true;
}
void Scribus150Format::readColor(ColorList& colors, const ScXmlStreamAttributes& attrs) const
{
ScColor color;
if (attrs.hasAttribute("SPACE"))
{
QString space = attrs.valueAsString("SPACE");
if (space == "CMYK")
{
double c = attrs.valueAsDouble("C", 0) / 100.0;
double m = attrs.valueAsDouble("M", 0) / 100.0;
double y = attrs.valueAsDouble("Y", 0) / 100.0;
double k = attrs.valueAsDouble("K", 0) / 100.0;
color.setCmykColorF(c, m, y, k);
}
else if (space == "RGB")
{
double r = attrs.valueAsDouble("R", 0) / 255.0;
double g = attrs.valueAsDouble("G", 0) / 255.0;
double b = attrs.valueAsDouble("B", 0) / 255.0;
color.setRgbColorF(r, g, b);
}
else if (space == "Lab")
{
double L = attrs.valueAsDouble("L", 0);
double a = attrs.valueAsDouble("A", 0);
double b = attrs.valueAsDouble("B", 0);
color.setLabColor(L, a, b);
}
}
else if (attrs.hasAttribute("CMYK"))
color.setNamedColor(attrs.valueAsString("CMYK"));
else if (attrs.hasAttribute("RGB"))
color.fromQColor(QColor(attrs.valueAsString("RGB")));
else
{
double L = attrs.valueAsDouble("L", 0);
double a = attrs.valueAsDouble("A", 0);
double b = attrs.valueAsDouble("B", 0);
color.setLabColor(L, a, b);
}
color.setSpotColor( attrs.valueAsBool("Spot", false) );
color.setRegistrationColor( attrs.valueAsBool("Register", false) );
QString name(attrs.valueAsString("NAME", color.name()));
if (name == "All")
{
color.setSpotColor(true);
color.setRegistrationColor(true);
color.setCmykColorF(1.0, 1.0, 1.0, 1.0);
}
// #10323 : break loading of doc which contain colors with different names
// and same definition
// colors.tryAddColor(name, color);
if (name.length() > 0 && !colors.contains(name))
colors.insert(name, color);
}
bool Scribus150Format::readGradient(ScribusDoc *doc, VGradient &gra, ScXmlStreamReader& reader) const
{
gra = VGradient(VGradient::linear);
gra.clearStops();
ScXmlStreamAttributes rattrs = reader.scAttributes();
QString tagName(reader.nameAsString());
while (!reader.atEnd() && !reader.hasError())
{
ScXmlStreamReader::TokenType tType = reader.readNext();
if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
break;
if (tType == ScXmlStreamReader::StartElement && reader.name() == QLatin1String("CSTOP"))
{
ScXmlStreamAttributes attrs = reader.scAttributes();
QString name = attrs.valueAsString("NAME");
double ramp = attrs.valueAsDouble("RAMP", 0.0);
int shade = attrs.valueAsInt("SHADE", 100);
double opa = attrs.valueAsDouble("TRANS", 1.0);
gra.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
}
}
return !reader.hasError();
}
void Scribus150Format::readCharacterStyleAttrs(ScribusDoc *doc, const ScXmlStreamAttributes& attrs, CharStyle & newStyle) const
{
static const QString CPARENT("CPARENT");
if (attrs.hasAttribute(CPARENT))
{
QString parentStyle = attrs.valueAsString(CPARENT);
if (!parentStyle.isEmpty())
parentStyle = charStyleMap.value(parentStyle, parentStyle);
newStyle.setParent(parentStyle);
}
static const QString FONT("FONT");
if (attrs.hasAttribute(FONT))
{
const ScFace& face = m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc);
if (!face.isNone())
newStyle.setFont(face);
}
static const QString FONTSIZE("FONTSIZE");
if (attrs.hasAttribute(FONTSIZE))
newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10));
static const QString FONTFEATURES("FONTFEATURES");
if (attrs.hasAttribute(FONTFEATURES))
newStyle.setFontFeatures(attrs.valueAsString(FONTFEATURES));
static const QString FCOLOR("FCOLOR");
if (attrs.hasAttribute(FCOLOR))
newStyle.setFillColor(attrs.valueAsString(FCOLOR));
static const QString HyphenChar("HyphenChar");
if (attrs.hasAttribute(HyphenChar))
newStyle.setHyphenChar(attrs.valueAsInt(HyphenChar));
static const QString HyphenWordMin("HyphenWordMin");
if (attrs.hasAttribute(HyphenWordMin))
newStyle.setHyphenWordMin(attrs.valueAsInt(HyphenWordMin));
static const QString KERN("KERN");
if (attrs.hasAttribute(KERN))
newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10));
static const QString FSHADE("FSHADE");
if (attrs.hasAttribute(FSHADE))
newStyle.setFillShade(attrs.valueAsInt(FSHADE));
static const QString EFFECTS("EFFECTS");
if (attrs.hasAttribute(EFFECTS))
newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList());
static const QString EFFECT("EFFECT");
if (attrs.hasAttribute(EFFECT))
newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList());
static const QString FEATURES("FEATURES");
if (attrs.hasAttribute(FEATURES))
newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", Qt::SkipEmptyParts));
static const QString SCOLOR("SCOLOR");
if (attrs.hasAttribute(SCOLOR))
newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None));
static const QString BCOLOR("BGCOLOR");
if (attrs.hasAttribute(BCOLOR))
newStyle.setBackColor(attrs.valueAsString(BCOLOR, CommonStrings::None));
static const QString BSHADE("BGSHADE");
if (attrs.hasAttribute(BSHADE))
newStyle.setBackShade(attrs.valueAsInt(BSHADE, 100));
static const QString SSHADE("SSHADE");
if (attrs.hasAttribute(SSHADE))
newStyle.setStrokeShade(attrs.valueAsInt(SSHADE));
static const QString SCALEH("SCALEH");
if (attrs.hasAttribute(SCALEH))
newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10));
static const QString SCALEV("SCALEV");
if (attrs.hasAttribute(SCALEV))
newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10));
static const QString BASEO("BASEO");
if (attrs.hasAttribute(BASEO))
newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10));
static const QString TXTSHX("TXTSHX");
if (attrs.hasAttribute(TXTSHX))
newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10));
static const QString TXTSHY("TXTSHY");
if (attrs.hasAttribute(TXTSHY))
newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10));
static const QString TXTOUT("TXTOUT");
if (attrs.hasAttribute(TXTOUT))
newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10));
static const QString TXTULP("TXTULP");
if (attrs.hasAttribute(TXTULP))
newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10));
static const QString TXTULW("TXTULW");
if (attrs.hasAttribute(TXTULW))
newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10));
static const QString TXTSTP("TXTSTP");
if (attrs.hasAttribute(TXTSTP))
newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10));
static const QString TXTSTW("TXTSTW");
if (attrs.hasAttribute(TXTSTW))
newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10));
static const QString LANGUAGE("LANGUAGE");
if (attrs.hasAttribute(LANGUAGE))
{
QString l(attrs.valueAsString(LANGUAGE));
if (LanguageManager::instance()->langTableIndex(l) != -1)
newStyle.setLanguage(l); //new style storage
else
{ //old style storage
QString lnew = LanguageManager::instance()->getAbbrevFromLang(l, false);
if (lnew.isEmpty())
lnew = LanguageManager::instance()->getAbbrevFromLang(l, false);
newStyle.setLanguage(lnew);
}
}
static const QString SHORTCUT("SHORTCUT");
if (attrs.hasAttribute(SHORTCUT))
newStyle.setShortcut(attrs.valueAsString(SHORTCUT));
static const QString WORDTRACK("wordTrack");
if (attrs.hasAttribute(WORDTRACK))
newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
}
void Scribus150Format::readNamedCharacterStyleAttrs(ScribusDoc *doc, const ScXmlStreamAttributes& attrs, CharStyle & newStyle) const
{
static const QString CNAME("CNAME");
if (attrs.hasAttribute(CNAME))
newStyle.setName(attrs.valueAsString(CNAME));
// The default style attribute must be correctly set before trying to assign a parent
static const QString DEFAULTSTYLE("DefaultStyle");
if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE))
newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle)
newStyle.setDefaultStyle(true);
else
newStyle.setDefaultStyle(false);
readCharacterStyleAttrs(doc, attrs, newStyle);
// Check that a style is not its own parent
QString parentStyle = newStyle.parent();
if (parentStyle == newStyle.name())
newStyle.setParent(QString());
}
void Scribus150Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle) const
{
ScXmlStreamAttributes attrs = reader.scAttributes();
newStyle.erase();
newStyle.setName(attrs.valueAsString("NAME", ""));
// The default style attribute must be correctly set before trying to assign a parent
static const QString DEFAULTSTYLE("DefaultStyle");
if (attrs.hasAttribute(DEFAULTSTYLE))
newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
else if (newStyle.name() == CommonStrings::DefaultParagraphStyle || newStyle.name() == CommonStrings::trDefaultParagraphStyle)
newStyle.setDefaultStyle(true);
else
newStyle.setDefaultStyle(false);
QString parentStyle = attrs.valueAsString("PARENT", QString());
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
{
parentStyle = parStyleMap.value(parentStyle, parentStyle);
if (m_Doc->styleExists(parentStyle))
newStyle.setParent(parentStyle);
else
newStyle.setParent(CommonStrings::DefaultParagraphStyle);
}
static const QString LINESPMode("LINESPMode");
if (attrs.hasAttribute(LINESPMode))
newStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt(LINESPMode)));
static const QString LINESP("LINESP");
if (attrs.hasAttribute(LINESP))
newStyle.setLineSpacing(attrs.valueAsDouble(LINESP));
static const QString INDENT("INDENT");
if (attrs.hasAttribute(INDENT))
newStyle.setLeftMargin(attrs.valueAsDouble(INDENT));
static const QString RMARGIN("RMARGIN");
if (attrs.hasAttribute(RMARGIN))
newStyle.setRightMargin(attrs.valueAsDouble(RMARGIN));
static const QString FIRST("FIRST");
if (attrs.hasAttribute(FIRST))
newStyle.setFirstIndent(attrs.valueAsDouble(FIRST));
static const QString ALIGN("ALIGN");
if (attrs.hasAttribute(ALIGN))
newStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt(ALIGN)));
static const QString DIRECTION("DIRECTION");
if (attrs.hasAttribute(DIRECTION))
newStyle.setDirection(static_cast<ParagraphStyle::DirectionType>(attrs.valueAsInt(DIRECTION)));
static const QString VOR("VOR");
if (attrs.hasAttribute(VOR))
newStyle.setGapBefore(attrs.valueAsDouble(VOR));
static const QString NACH("NACH");
if (attrs.hasAttribute(NACH))
newStyle.setGapAfter(attrs.valueAsDouble(NACH));
static const QString ParagraphEffectCharStyle("ParagraphEffectCharStyle");
if (attrs.hasAttribute(ParagraphEffectCharStyle))
newStyle.setPeCharStyleName(attrs.valueAsString(ParagraphEffectCharStyle));
static const QString ParagraphEffectOffset("ParagraphEffectOffset");
if (attrs.hasAttribute(ParagraphEffectOffset))
newStyle.setParEffectOffset(attrs.valueAsDouble(ParagraphEffectOffset));
static const QString ParagraphEffectIndent("ParagraphEffectIndent");
if (attrs.hasAttribute(ParagraphEffectIndent))
newStyle.setParEffectIndent(attrs.valueAsDouble(ParagraphEffectIndent));
static const QString DROP("DROP");
if (attrs.hasAttribute(DROP))
newStyle.setHasDropCap(static_cast<bool>(attrs.valueAsInt(DROP)));
static const QString DROPCHSTYLE("DROPCHSTYLE");
if (attrs.hasAttribute(DROPCHSTYLE))
newStyle.setPeCharStyleName(attrs.valueAsString(DROPCHSTYLE));
static const QString DROPLIN("DROPLIN");
if (attrs.hasAttribute(DROPLIN))
newStyle.setDropCapLines(attrs.valueAsInt(DROPLIN));
static const QString DROPDIST("DROPDIST");
if (attrs.hasAttribute(DROPDIST))
newStyle.setParEffectOffset(attrs.valueAsDouble(DROPDIST));
static const QString Bullet("Bullet");
if (attrs.hasAttribute(Bullet))
newStyle.setHasBullet(static_cast<bool>(attrs.valueAsInt(Bullet)));
static const QString BulletStr("BulletStr");
if (attrs.hasAttribute(BulletStr))
newStyle.setBulletStr(attrs.valueAsString(BulletStr));
static const QString Numeration("Numeration");
if (attrs.hasAttribute(Numeration))
newStyle.setHasNum(static_cast<bool>(attrs.valueAsInt(Numeration)));
static const QString NumerationName("NumerationName");
if (attrs.hasAttribute(NumerationName))
newStyle.setNumName(attrs.valueAsString(NumerationName));
static const QString NumerationFormat("NumerationFormat");
if (attrs.hasAttribute(NumerationFormat))
newStyle.setNumFormat(attrs.valueAsInt(NumerationFormat));
static const QString NumerationLevel("NumerationLevel");
if (attrs.hasAttribute(NumerationLevel))
newStyle.setNumLevel(attrs.valueAsInt(NumerationLevel));
static const QString NumerationStart("NumerationStart");
if (attrs.hasAttribute(NumerationStart))
newStyle.setNumStart(attrs.valueAsInt(NumerationStart));
static const QString NumearationPrefix("NumerationPrefix");
if (attrs.hasAttribute(NumearationPrefix))
newStyle.setNumPrefix(attrs.valueAsString(NumearationPrefix));
static const QString NumerationSuffix("NumerationSuffix");
if (attrs.hasAttribute(NumerationSuffix))
newStyle.setNumSuffix(attrs.valueAsString(NumerationSuffix));
static const QString NumerationRestart("NumerationRestart");
if (attrs.hasAttribute(NumerationRestart))
newStyle.setNumRestart(attrs.valueAsInt(NumerationRestart));
static const QString NumerationOther("NumerationOther");
if (attrs.hasAttribute(NumerationOther))
newStyle.setNumOther(static_cast<bool>(attrs.valueAsInt(NumerationOther)));
static const QString NumerationHigher("NumerationHigher");
if (attrs.hasAttribute(NumerationHigher))
newStyle.setNumHigher(static_cast<bool>(attrs.valueAsInt(NumerationHigher)));
static const QString PSHORTCUT("PSHORTCUT");
if (attrs.hasAttribute(PSHORTCUT))
newStyle.setShortcut(attrs.valueAsString(PSHORTCUT));
static const QString OpticalMargins("OpticalMargins");
if (attrs.hasAttribute(OpticalMargins))
newStyle.setOpticalMargins(attrs.valueAsInt(OpticalMargins));
static const QString HyphenConsecutiveLines("HyphenConsecutiveLines");
if (attrs.hasAttribute(HyphenConsecutiveLines))
newStyle.setHyphenConsecutiveLines(attrs.valueAsInt(HyphenConsecutiveLines));
static const QString HyphenationMode("HyphenationMode");
if (attrs.hasAttribute(HyphenationMode))
newStyle.setHyphenationMode(attrs.valueAsInt(HyphenationMode));
static const QString MinWordTrack("MinWordTrack");
if (attrs.hasAttribute(MinWordTrack))
newStyle.setMinWordTracking(attrs.valueAsDouble(MinWordTrack));
static const QString NormWordTrack("NormWordTrack");
if (attrs.hasAttribute(NormWordTrack))
newStyle.charStyle().setWordTracking(attrs.valueAsDouble(NormWordTrack));
static const QString MinGlyphShrink("MinGlyphShrink");
if (attrs.hasAttribute(MinGlyphShrink))
newStyle.setMinGlyphExtension(attrs.valueAsDouble(MinGlyphShrink));
static const QString MaxGlyphExtend("MaxGlyphExtend");
if (attrs.hasAttribute(MaxGlyphExtend))
newStyle.setMaxGlyphExtension(attrs.valueAsDouble(MaxGlyphExtend));
static const QString KeepLinesStart("KeepLinesStart");
if (attrs.hasAttribute(KeepLinesStart))
newStyle.setKeepLinesStart(attrs.valueAsInt(KeepLinesStart));
static const QString KeepLinesEnd("KeepLinesEnd");
if (attrs.hasAttribute(KeepLinesEnd))
newStyle.setKeepLinesEnd(attrs.valueAsInt(KeepLinesEnd));
static const QString KeepWithNext("KeepWithNext");
if (attrs.hasAttribute(KeepWithNext))
newStyle.setKeepWithNext(attrs.valueAsInt(KeepWithNext));
static const QString KeepTogether("KeepTogether");
if (attrs.hasAttribute(KeepTogether))
newStyle.setKeepTogether(attrs.valueAsInt(KeepTogether));
static const QString BCOLOR("BCOLOR");
if (attrs.hasAttribute(BCOLOR))
newStyle.setBackgroundColor(attrs.valueAsString(BCOLOR, CommonStrings::None));
static const QString BSHADE("BSHADE");
if (attrs.hasAttribute(BSHADE))
newStyle.setBackgroundShade(attrs.valueAsInt(BSHADE, 100));
readCharacterStyleAttrs(doc, attrs, newStyle.charStyle());
// newStyle.tabValues().clear();
QList<ParagraphStyle::TabRecord> tbs;
newStyle.resetTabValues();
QString thisTagName(reader.nameAsString());
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == thisTagName)
break;
if (reader.isStartElement() && reader.name() == QLatin1String("Tabs"))
{
ParagraphStyle::TabRecord tb;
ScXmlStreamAttributes attrs2 = reader.scAttributes();
tb.tabPosition = attrs2.valueAsDouble("Pos");
tb.tabType = attrs2.valueAsInt("Type");
QString tbCh(attrs2.valueAsString("Fill",""));
if (!tbCh.isEmpty())
tb.tabFillChar = tbCh[0];
tbs.append(tb);
}
}
if (tbs.count() > 0)
newStyle.setTabValues(tbs);
fixLegacyParStyle(newStyle);
}
void Scribus150Format::readTableStyle(ScribusDoc *doc, ScXmlStreamReader& reader, TableStyle& newStyle) const
{
ScXmlStreamAttributes attrs = reader.scAttributes();
newStyle.erase();
newStyle.setName(attrs.valueAsString("NAME", ""));
// The default style attribute must be correctly set before trying to assign a parent
if (attrs.hasAttribute("DefaultStyle"))
newStyle.setDefaultStyle(attrs.valueAsInt("DefaultStyle"));
else if (newStyle.name() == CommonStrings::DefaultTableStyle || newStyle.name() == CommonStrings::trDefaultTableStyle)
newStyle.setDefaultStyle(true);
else
newStyle.setDefaultStyle(false);
QString parentStyle = attrs.valueAsString("PARENT", "");
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
newStyle.setParent(parentStyle);
if (attrs.hasAttribute("FillColor"))
newStyle.setFillColor(attrs.valueAsString("FillColor"));
if (attrs.hasAttribute("FillShade"))
newStyle.setFillShade(attrs.valueAsDouble("FillShade"));
QString tagName(reader.nameAsString());
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (!reader.isStartElement())
continue;
if (reader.name() == QLatin1String("TableBorderLeft"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setLeftBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderRight"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setRightBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderTop"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setTopBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderBottom"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setBottomBorder(border);
}
else
reader.skipCurrentElement();
}
}
void Scribus150Format::readTableBorderLines(ScribusDoc* /*doc*/, ScXmlStreamReader& reader, TableBorder& border) const
{
QStringView tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (!reader.isStartElement())
continue;
if (reader.name() == QLatin1String("TableBorderLine"))
{
ScXmlStreamAttributes tAttB = reader.scAttributes();
double width = tAttB.valueAsDouble("Width", 0.0);
QString color = tAttB.valueAsString("Color", CommonStrings::None);
double shade = tAttB.valueAsDouble("Shade", 100.0);
int style = tAttB.valueAsInt("PenStyle", 1);
border.addBorderLine(TableBorderLine(width, static_cast<Qt::PenStyle>(style), color, shade));
}
else
reader.skipCurrentElement();
}
}
void Scribus150Format::readCellStyle(ScribusDoc *doc, ScXmlStreamReader& reader, CellStyle& newStyle) const
{
ScXmlStreamAttributes attrs = reader.scAttributes();
newStyle.erase();
newStyle.setName(attrs.valueAsString("NAME", ""));
// The default style attribute must be correctly set before trying to assign a parent
if (attrs.hasAttribute("DefaultStyle"))
newStyle.setDefaultStyle(attrs.valueAsInt("DefaultStyle"));
else if (newStyle.name() == CommonStrings::DefaultCellStyle || newStyle.name() == CommonStrings::trDefaultCellStyle)
newStyle.setDefaultStyle(true);
else
newStyle.setDefaultStyle(false);
QString parentStyle = attrs.valueAsString("PARENT", "");
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
newStyle.setParent(parentStyle);
if (attrs.hasAttribute("FillColor"))
newStyle.setFillColor(attrs.valueAsString("FillColor"));
if (attrs.hasAttribute("FillShade"))
newStyle.setFillShade(attrs.valueAsDouble("FillShade"));
if (attrs.hasAttribute("LeftPadding"))
newStyle.setLeftPadding(attrs.valueAsDouble("LeftPadding", 0.0));
if (attrs.hasAttribute("RightPadding"))
newStyle.setRightPadding(attrs.valueAsDouble("RightPadding", 0.0));
if (attrs.hasAttribute("TopPadding"))
newStyle.setTopPadding(attrs.valueAsDouble("TopPadding", 0.0));
if (attrs.hasAttribute("BottomPadding"))
newStyle.setBottomPadding(attrs.valueAsDouble("BottomPadding", 0.0));
QString tagName(reader.nameAsString());
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (!reader.isStartElement())
break;
if (reader.name() == QLatin1String("TableBorderLeft"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setLeftBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderRight"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setRightBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderTop"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setTopBorder(border);
}
else if (reader.name() == QLatin1String("TableBorderBottom"))
{
TableBorder border;
readTableBorderLines(doc, reader, border);
newStyle.setBottomBorder(border);
}
else
{
reader.skipCurrentElement();
}
}
}
void Scribus150Format::readLayers(ScLayer& layer, const ScXmlStreamAttributes& attrs) const
{
int lId = attrs.valueAsInt("NUMMER");
int level = attrs.valueAsInt("LEVEL");
layer = ScLayer( attrs.valueAsString("NAME"), level, lId);
layer.isViewable = attrs.valueAsInt("SICHTBAR");
layer.isPrintable = attrs.valueAsInt("DRUCKEN");
layer.isEditable = attrs.valueAsInt("EDIT", 1);
layer.flowControl = attrs.valueAsInt("FLOW", 1);
layer.isSelectable = attrs.valueAsInt("SELECT", 0);
layer.transparency = attrs.valueAsDouble("TRANS", 1.0);
layer.blendMode = attrs.valueAsInt("BLEND", 0);
layer.outlineMode = attrs.valueAsInt("OUTL", 0);
if (attrs.hasAttribute("LAYERC"))
layer.markerColor = QColor(attrs.valueAsString("LAYERC","#000000"));
}
bool Scribus150Format::readArrows(ScribusDoc* doc, ScXmlStreamAttributes& attrs) const
{
double xa;
double ya;
struct ArrowDesc arrow;
arrow.name = attrs.valueAsString("Name");
arrow.userArrow = true;
QString tmp = attrs.valueAsString("Points");
ScTextStream fp(&tmp, QIODevice::ReadOnly);
unsigned int numPoints = attrs.valueAsUInt("NumPoints");
for (uint cx = 0; cx < numPoints; ++cx)
{
fp >> xa;
fp >> ya;
arrow.points.addPoint(xa, ya);
}
if (!doc->hasArrowStyle(arrow.name))
doc->appendToArrowStyles(arrow);
return true;
}
bool Scribus150Format::readMultiline(multiLine& ml, ScXmlStreamReader& reader) const
{
ml = multiLine();
ScXmlStreamAttributes rattrs = reader.scAttributes();
QString tagName(reader.nameAsString());
while (!reader.atEnd() && !reader.hasError())
{
ScXmlStreamReader::TokenType tType = reader.readNext();
if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
break;
if (tType == ScXmlStreamReader::StartElement && reader.name() == QLatin1String("SubLine"))
{
struct SingleLine sl;
ScXmlStreamAttributes attrs = reader.scAttributes();
sl.Color = attrs.valueAsString("Color");
sl.Dash = attrs.valueAsInt("Dash");
sl.LineEnd = attrs.valueAsInt("LineEnd");
sl.LineJoin = attrs.valueAsInt("LineJoin");
sl.Shade = attrs.valueAsInt("Shade");
sl.Width = attrs.valueAsDouble("Width");
ml.shortcut = attrs.valueAsString("Shortcut");
ml.push_back(sl);
}
}
return !reader.hasError();
}
bool Scribus150Format::readBookMark(ScribusDoc::BookMa& bookmark, int& elem, const ScXmlStreamAttributes& attrs) const
{
elem = attrs.valueAsInt("Element");
bookmark.PageObject = nullptr;
bookmark.Title = attrs.valueAsString("Title");
bookmark.Text = attrs.valueAsString("Text");
bookmark.Aktion = attrs.valueAsString("Aktion");
bookmark.ItemNr = attrs.valueAsInt("ItemNr");
bookmark.First = attrs.valueAsInt("First");
bookmark.Last = attrs.valueAsInt("Last");
bookmark.Prev = attrs.valueAsInt("Prev");
bookmark.Next = attrs.valueAsInt("Next");
bookmark.Parent = attrs.valueAsInt("Parent");
return true;
}
bool Scribus150Format::readPDFOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
{
ScXmlStreamAttributes attrs = reader.scAttributes();
doc->pdfOptions().firstUse = attrs.valueAsBool("firstUse", true);
doc->pdfOptions().Articles = attrs.valueAsBool("Articles");
doc->pdfOptions().Thumbnails = attrs.valueAsBool("Thumbnails");
doc->pdfOptions().Compress = attrs.valueAsBool("Compress");
doc->pdfOptions().CompressMethod = (PDFOptions::PDFCompression) attrs.valueAsInt("CMethod", 0);
doc->pdfOptions().Quality = attrs.valueAsInt("Quality", 0);
doc->pdfOptions().RecalcPic = attrs.valueAsBool("RecalcPic");
doc->pdfOptions().embedPDF = attrs.valueAsBool("EmbedPDF", false);
doc->pdfOptions().Bookmarks = attrs.valueAsBool("Bookmarks");
doc->pdfOptions().MirrorH = attrs.valueAsBool("MirrorH", false);
doc->pdfOptions().MirrorV = attrs.valueAsBool("MirrorV", false);
doc->pdfOptions().RotateDeg = attrs.valueAsInt("RotateDeg", 0);
doc->pdfOptions().pageRangeSelection = attrs.valueAsInt("rangeSel", 0);
doc->pdfOptions().pageRangeString = attrs.valueAsString("rangeTxt", "");
doc->pdfOptions().doClip = attrs.valueAsBool("Clip", false);
doc->pdfOptions().PresentMode = attrs.valueAsBool("PresentMode");
doc->pdfOptions().PicRes = attrs.valueAsInt("PicRes");
// Fixme: check input pdf version
doc->pdfOptions().Version = (PDFVersion::Version) attrs.valueAsInt("Version");
doc->pdfOptions().Resolution = attrs.valueAsInt("Resolution");
doc->pdfOptions().Binding = attrs.valueAsInt("Binding");
doc->pdfOptions().fileName = "";
doc->pdfOptions().FontEmbedding = (PDFOptions::PDFFontEmbedding) attrs.valueAsInt("FontEmbedding", 0);
doc->pdfOptions().isGrayscale = attrs.valueAsBool("Grayscale", false);
doc->pdfOptions().UseRGB = attrs.valueAsBool("RGBMode", false);
doc->pdfOptions().UseProfiles = attrs.valueAsBool("UseProfiles", false);
doc->pdfOptions().UseProfiles2 = attrs.valueAsBool("UseProfiles2", false);
doc->pdfOptions().Intent = attrs.valueAsInt("Intent", 1);
doc->pdfOptions().Intent2 = attrs.valueAsInt("Intent2", 1);
doc->pdfOptions().SolidProf = attrs.valueAsString("SolidP", "");
doc->pdfOptions().ImageProf = attrs.valueAsString("ImageP", "");
doc->pdfOptions().PrintProf = attrs.valueAsString("PrintP", "");
doc->pdfOptions().Info = attrs.valueAsString("InfoString", "");
doc->pdfOptions().bleeds.setTop(attrs.valueAsDouble("BTop", 0.0));
doc->pdfOptions().bleeds.setLeft(attrs.valueAsDouble("BLeft", 0.0));
doc->pdfOptions().bleeds.setRight(attrs.valueAsDouble("BRight", 0.0));
doc->pdfOptions().bleeds.setBottom(attrs.valueAsDouble("BBottom", 0.0));
doc->pdfOptions().useDocBleeds = attrs.valueAsBool("useDocBleeds", true);
doc->pdfOptions().cropMarks = attrs.valueAsBool("cropMarks", false);
doc->pdfOptions().bleedMarks = attrs.valueAsBool("bleedMarks", false);
doc->pdfOptions().registrationMarks = attrs.valueAsBool("registrationMarks", false);
doc->pdfOptions().colorMarks = attrs.valueAsBool("colorMarks", false);
doc->pdfOptions().docInfoMarks = attrs.valueAsBool("docInfoMarks", false);
doc->pdfOptions().markLength = attrs.valueAsDouble("markLength", 20.0);
doc->pdfOptions().markOffset = attrs.valueAsDouble("markOffset", 0.0);
doc->pdfOptions().EmbeddedI = attrs.valueAsBool("ImagePr", false);
doc-