Rev 20636 |
Rev 20682 |
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 "../../formatidlist.h"
#include "commonstrings.h"
#include "ui/missing.h"
#include "hyphenator.h"
#include "langmgr.h"
#include "notesstyles.h"
#include "pageitem_latexframe.h"
#include "pageitem_noteframe.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 "undomanager.h"
#include "units.h"
#include "util.h"
#include "util_math.h"
#include "util_color.h"
#include "util_text.h"
#ifdef HAVE_OSG
#include "pageitem_osgframe.h"
#endif
#include "pageitem_table.h"
#include "pageitem_regularpolygon.h"
#include "pageitem_arc.h"
#include "pageitem_spiral.h"
#include "pagestructs.h"
#include <QApplication>
#include <QByteArray>
#include <QCursor>
// #include <QDebug>
#include <QFileInfo>
#include <QList>
#include <QScopedPointer>
// 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() :
LoadSavePlugin()
{
// 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)";
}
const 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;
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
loadRawText(fileName, docBytes);
}
QRegExp regExp150("Version=\"1.5.[0-9]");
int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
if (startElemPos >= 0)
{
bool is150 = ( regExp150.indexIn(docBytes.mid(startElemPos, 64)) >= 0 );
return is150;
}
return false;
}
QIODevice* Scribus150Format::slaReader(const QString & fileName)
{
if (!fileSupported(0, fileName))
return NULL;
QIODevice* ioDevice = 0;
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 NULL;
}
ioDevice = compressor;
}
else
{
ioDevice = new QFile(fileName);
if (!ioDevice->open(QIODevice::ReadOnly))
{
delete ioDevice;
return NULL;
}
}
return ioDevice;
}
void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces)
{
getNewReplacement=false;
getReplacedFonts.clear();
}
bool Scribus150Format::loadElements(const QString & data, QString fileDir, int toLayer, double Xp_in, double Yp_in, bool loc)
{
ParagraphStyle vg;
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*> > groupStack;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStack2;
itemRemap.clear();
itemNext.clear();
itemCount = 0;
itemRemapM.clear();
itemNextM.clear();
itemCountM = 0;
itemRemapF.clear();
itemNextF.clear();
FrameItems.clear();
bool firstElement = true;
bool success = true;
ScXmlStreamReader reader(data);
ScXmlStreamAttributes attrs;
while(!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QStringRef tagName = reader.name();
attrs = reader.scAttributes();
if (firstElement)
{
if (tagName == "SCRIBUSELEM" || tagName == "SCRIBUSELEMUTF8")
{
if (!loc)
{
GrX = attrs.valueAsDouble("XP");
GrY = attrs.valueAsDouble("YP");
}
}
else
{
success = false;
break;
}
firstElement = false;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
{
success = readColor(m_Doc->PageColors, attrs);
if (!success) break;
}
if (tagName == "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 == "STYLE")
{
readParagraphStyle(m_Doc, reader, vg);
StyleSet<ParagraphStyle>tmp;
tmp.create(vg);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == "CHARSTYLE")
{
CharStyle cstyle;
StyleSet<CharStyle> temp;
ScXmlStreamAttributes attrs = reader.scAttributes();
readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle);
temp.create(cstyle);
m_Doc->redefineCharStyles(temp, false);
}
if (tagName == "TableStyle")
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
}
if (tagName == "CellStyle")
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
}
if (tagName == "Arrows")
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
if (tagName == "MultiLine")
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success) break;
if (!mlName.isEmpty())
{
m_Doc->MLineStyles.insert(mlName, ml);
}
}
if ((tagName == "ITEM") || (tagName == "PAGEOBJECT") || (tagName == "FRAMEOBJECT"))
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, itemInfo, fileDir, true);
if (!success)
break;
itemInfo.item->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 == "ITEM")
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == "ITEM")
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
}
if (itemInfo.isWeldFlag)
{
if (tagName == "ITEM")
{
WeldItems.append(itemInfo.item);
WeldID.insert(itemInfo.ownWeld, itemInfo.item);
}
}
}
if (groupStack.count() > 0)
{
groupStack.top().append(itemInfo.item);
while (static_cast<int>(itemInfo.ownNr) == groupStack2.top())
{
if ((tagName == "PAGEOBJECT") || (tagName == "ITEM"))
groupStackP.push(groupStack.pop());
else if (tagName == "FRAMEOBJECT")
groupStackF.push(groupStack.pop());
else
groupStackM.push(groupStack.pop());
groupStack2.pop();
if (groupStack2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> GroupItems;
GroupItems.append(itemInfo.item);
groupStack.push(GroupItems);
groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
if (tagName == "Pattern")
{
success = readPattern(m_Doc, reader, fileDir);
if (!success) break;
}
if (tagName == "NotesStyles")
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
if (tagName == "NotesFrames")
{
success = readNotesFrames(reader);
if (!success) break;
}
if (tagName == "Notes")
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
if (tagName == "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->TopLink = LinkID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = LinkID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = LinkID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = LinkID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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->testLinkCandidate(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->TopLink = TableIDF[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDF[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDF[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDF[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableIDM[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDM[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDM[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDM[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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(0), *Itn(0);
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->testLinkCandidate(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 = FPoint(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());
}
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 = FPoint(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());
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
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 = FPoint(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());
}
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::loadPalette(const QString & fileName)
{
if (m_Doc==0 || m_AvailableFonts==0)
{
Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
return false;
}
ParagraphStyle vg;
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*> > groupStack;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStack2;
QByteArray docBytes("");
loadRawText(fileName, docBytes);
QString f = QString::fromUtf8(docBytes);
if (f.isEmpty())
{
setFileReadError();
return false;
}
QString fileDir = QFileInfo(fileName).absolutePath();
if (m_mwProgressBar!=0)
{
m_mwProgressBar->setMaximum(f.length());
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 = 0;
// m_Doc->PageColors.clear();
// m_Doc->Layers.clear();
bool firstElement = true;
bool success = true;
int progress = 0;
ScXmlStreamReader reader(f);
ScXmlStreamAttributes attrs;
while(!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType tType = reader.readNext();
if (tType != QXmlStreamReader::StartElement)
continue;
QStringRef tagName = reader.name();
attrs = reader.scAttributes();
if (m_mwProgressBar != 0)
{
int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100);
if (newProgress != progress)
{
m_mwProgressBar->setValue(reader.characterOffset());
progress = newProgress;
}
}
if (firstElement)
{
if (tagName != "SCRIBUSCOLORS")
{
success = false;
break;
}
firstElement = false;
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
{
success = readColor(m_Doc->PageColors, attrs);
if (!success) break;
}
if (tagName == "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 == "Arrows")
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
if (tagName == "MultiLine")
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success) break;
if (!mlName.isEmpty())
{
m_Doc->MLineStyles.insert(mlName, ml);
}
}
if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT")
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, itemInfo, fileDir, false);
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 == "PAGEOBJECT")
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
else if (tagName == "MASTEROBJECT")
{
if (itemInfo.nextItem != -1)
itemNextM[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == "PAGEOBJECT")
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
else if (tagName == "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 (groupStack.count() > 0)
{
groupStack.top().append(itemInfo.item);
while (static_cast<int>(itemInfo.ownNr) == groupStack2.top())
{
if (tagName == "PAGEOBJECT")
groupStackP.push(groupStack.pop());
else if (tagName == "FRAMEOBJECT")
groupStackF.push(groupStack.pop());
else
groupStackM.push(groupStack.pop());
groupStack2.pop();
if (groupStack2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> GroupItems;
GroupItems.append(itemInfo.item);
groupStack.push(GroupItems);
groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
if (tagName == "Pattern")
{
success = readPattern(m_Doc, reader, fileDir);
if (!success) break;
}
if (tagName == "NotesStyles")
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
if (tagName == "NotesFrames")
{
success = readNotesFrames(reader);
if (!success) break;
}
if (tagName == "Notes")
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
if (tagName == "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->TopLink = LinkID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = LinkID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = LinkID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = LinkID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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->testLinkCandidate(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->TopLink = TableIDF[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDF[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDF[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDF[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableIDM[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDM[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDM[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDM[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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(0), *Itn(0);
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->testLinkCandidate(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(0), *Itn(0);
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->testLinkCandidate(Itn))
{
qDebug() << "scribus150format: corruption in linked textframes detected";
continue;
}
Its->link(Itn);
}
}
}
}
if (groupStackP.count() > 0)
{
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 = FPoint(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());
}
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;
}
}
if (groupStackF.count() > 0)
{
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 = FPoint(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());
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
if (!converted)
gItem->groupItemList = gpL;
}
}
if (groupStackM.count() > 0)
{
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 = FPoint(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());
}
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!=0)
{
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==0 || m_AvailableFonts==0)
{
Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
return false;
}
ParagraphStyle vg;
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*> > groupStack;
QStack< QList<PageItem*> > groupStackF;
QStack< QList<PageItem*> > groupStackM;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStack2;
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!=0)
{
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();
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 = 0;
m_Doc->PageColors.clear();
m_Doc->Layers.clear();
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;
QStringRef tagName = reader.name();
attrs = reader.scAttributes();
if (m_mwProgressBar != 0)
{
int newProgress = qRound(ioDevice->pos() / (double) ioDevice->size() * 100);
if (newProgress != progress)
{
m_mwProgressBar->setValue(reader.characterOffset());
progress = newProgress;
}
}
if (firstElement)
{
if (tagName != "SCRIBUSUTF8NEW")
{
success = false;
break;
}
firstElement = false;
}
if (tagName == "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"));
}
}
if (tagName == "CheckProfile")
{
success = readCheckProfile(m_Doc, attrs);
if (!success) break;
}
if (tagName == "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...
if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
{
success = readColor(m_Doc->PageColors, attrs);
if (!success) break;
}
if (tagName == "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 == "STYLE")
{
readParagraphStyle(m_Doc, reader, vg);
StyleSet<ParagraphStyle>tmp;
tmp.create(vg);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == "CHARSTYLE")
{
CharStyle cstyle;
ScXmlStreamAttributes attrs = reader.scAttributes();
readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle);
StyleSet<CharStyle> temp;
temp.create(cstyle);
m_Doc->redefineCharStyles(temp, false);
}
if (tagName == "TableStyle")
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
}
if (tagName == "CellStyle")
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
}
if (tagName == "JAVA")
{
QString name = attrs.valueAsString("NAME");
if (!name.isEmpty())
m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
}
if (tagName == "LAYERS")
{
ScLayer newLayer;
readLayers(newLayer, attrs);
m_Doc->Layers.append(newLayer);
}
if (tagName == "Arrows")
{
success = readArrows(m_Doc, attrs);
if (!success) break;
}
if (tagName == "MultiLine")
{
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
if (!success) break;
if (!mlName.isEmpty())
{
m_Doc->MLineStyles.insert(mlName, ml);
}
}
if (tagName == "Bookmark")
{
int bmElem = 0;
struct ScribusDoc::BookMa bookmark;
success = readBookMark(bookmark, bmElem, attrs);
if (!success) break;
bookmarks.insert(bmElem, bookmark);
}
if (tagName == "PDF")
{
success = readPDFOptions(m_Doc, reader);
if (!success) break;
}
if (tagName == "Printer")
{
success = readPrinterOptions(m_Doc, reader);
if (!success) break;
}
if (tagName == "DocItemAttributes")
{
success = readDocItemAttributes(m_Doc, reader);
if (!success) break;
}
if (tagName == "TablesOfContents")
{
success = readTableOfContents(m_Doc, reader);
if (!success) break;
}
if (tagName == "Sections")
{
success = readSections(m_Doc, reader);
if (!success) break;
}
if (tagName == "HYPHEN")
{
success = readHyphen(m_Doc, reader);
if (!success) break;
}
if (tagName == "PAGE" || tagName == "MASTERPAGE")
{
success = readPage(m_Doc, reader);
if (!success)
break;
}
if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT")
{
ItemInfo itemInfo;
success = readObject(m_Doc, reader, itemInfo, fileDir, false);
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 == "PAGEOBJECT")
{
if (itemInfo.nextItem != -1)
itemNext[itemInfo.ownNr] = itemInfo.nextItem;
}
else if (tagName == "MASTEROBJECT")
{
if (itemInfo.nextItem != -1)
itemNextM[itemInfo.ownNr] = itemInfo.nextItem;
}
if (itemInfo.item->isTableItem)
{
if (tagName == "PAGEOBJECT")
{
TableItems.append(itemInfo.item);
TableID.insert(itemInfo.ownLink, itemInfo.item);
}
else if (tagName == "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 (groupStack.count() > 0)
{
groupStack.top().append(itemInfo.item);
while (static_cast<int>(itemInfo.ownNr) == groupStack2.top())
{
if (tagName == "PAGEOBJECT")
groupStackP.push(groupStack.pop());
else if (tagName == "FRAMEOBJECT")
groupStackF.push(groupStack.pop());
else
groupStackM.push(groupStack.pop());
groupStack2.pop();
if (groupStack2.count() == 0)
break;
}
}
if (itemInfo.isGroupFlag)
{
QList<PageItem*> GroupItems;
GroupItems.append(itemInfo.item);
groupStack.push(GroupItems);
groupStack2.push(itemInfo.groupLastItem + itemInfo.ownNr);
}
}
if (tagName == "Pattern")
{
success = readPattern(m_Doc, reader, fileDir);
if (!success)
break;
}
if (tagName == "NotesStyles")
{
success = readNotesStyles(m_Doc, reader);
if (!success) break;
}
if (tagName == "NotesFrames")
{
success = readNotesFrames(reader);
if (!success) break;
}
if (tagName == "Notes")
{
success = readNotes(m_Doc, reader);
if (!success) break;
}
if (tagName == "Marks")
{
success = readMarks(m_Doc, reader);
if (!success) break;
}
}
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();
if (elem < m_Doc->Items->count())
{
ScribusDoc::BookMa bookmark = it.value();
bookmark.PageObject = m_Doc->Items->at(elem);
m_Doc->BookMarks.append( bookmark );
}
}
if (isNewFormat)
{
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = LinkID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = LinkID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = LinkID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = LinkID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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->testLinkCandidate(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->TopLink = TableIDF[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDF[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDF[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDF[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItemsM.count() != 0)
{
for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
{
PageItem* ta = TableItemsM.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableIDM[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableIDM[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableIDM[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableIDM[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
if (TableItems.count() != 0)
{
for (int ttc = 0; ttc < TableItems.count(); ++ttc)
{
PageItem* ta = TableItems.at(ttc);
if (ta->TopLinkID != -1)
ta->TopLink = TableID[ta->TopLinkID];
else
ta->TopLink = 0;
if (ta->LeftLinkID != -1)
ta->LeftLink = TableID[ta->LeftLinkID];
else
ta->LeftLink = 0;
if (ta->RightLinkID != -1)
ta->RightLink = TableID[ta->RightLinkID];
else
ta->RightLink = 0;
if (ta->BottomLinkID != -1)
ta->BottomLink = TableID[ta->BottomLinkID];
else
ta->BottomLink = 0;
}
}
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 == NULL)
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(0), *Itn(0);
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->testLinkCandidate(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(0), *Itn(0);
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->testLinkCandidate(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
m_Doc->fixParagraphStyles();
m_Doc->fixNotesStyles();
if (m_Doc->Layers.count() == 0)
m_Doc->Layers.newLayer( QObject::tr("Background") );
if (!EffVal.isEmpty())
{
for (int pdoE = 0; pdoE < EffVal.count(); ++pdoE)
{
if (pdoE < m_Doc->Pages->count())
m_Doc->Pages->at(pdoE)->PresentVals = EffVal[pdoE];
}
}
if (groupStackP.count() > 0)
{
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 = FPoint(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());
}
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;
}
}
if (groupStackF.count() > 0)
{
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 = FPoint(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());
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
bool converted = false;
if (isTableIt)
converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
if (!converted)
gItem->groupItemList = gpL;
}
}
if (groupStackM.count() > 0)
{
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 = FPoint(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());
}
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!=0)
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 = dynamic_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, ScXmlStreamAttributes& attrs)
{
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) );
//m_Doc->setHyphLanguage(attrs.valueAsString("LANGUAGE", "en_US"));
static const QString LANGUAGE("LANGUAGE");
if (attrs.hasAttribute(LANGUAGE))
{
QString l(attrs.valueAsString(LANGUAGE));
if (LanguageManager::instance()->langTableIndex(l)!=-1)
m_Doc->setHyphLanguage(l); //new style storage
else
{ //old style storage
QString lnew=LanguageManager::instance()->getAbbrevFromLang(l, true, false);
if (lnew.isEmpty())
lnew=LanguageManager::instance()->getAbbrevFromLang(l, false, false);
m_Doc->setHyphLanguage(lnew);
}
}
m_Doc->setHyphMinimumWordLength(attrs.valueAsInt("MINWORDLEN", 3));
m_Doc->setHyphConsecutiveLines(attrs.valueAsInt("HYCOUNT", 2));
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));
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, ScXmlStreamAttributes& attrs)
{
PrefsManager* prefsManager = PrefsManager::instance();
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->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, ScXmlStreamAttributes& attrs)
{
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, ScXmlStreamAttributes& attrs)
{
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 = 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, ScXmlStreamAttributes& attrs)
{
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);
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);
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, ScXmlStreamAttributes& attrs)
{
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", 100, 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)
{
struct PageSet pageS;
ScXmlStreamAttributes attrs;
doc->clearPageSets();
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
QStringRef tagName = reader.name();
if (reader.isStartElement())
attrs = reader.attributes();
if (reader.isEndElement() && tagName == "PageSets")
break;
if(reader.isStartElement() && tagName == "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 == "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 == "PageNames")
pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(attrs.valueAsString("Name")));
}
return !reader.hasError();
}
bool Scribus150Format::readCheckProfile(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
{
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;
}
bool Scribus150Format::readColor(ColorList& colors, ScXmlStreamAttributes& attrs)
{
ScColor color;
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.setColor(L, a, b);
}
color.setSpotColor( attrs.valueAsBool("Spot", false) );
color.setRegistrationColor( attrs.valueAsBool("Register", false) );
QString name = attrs.valueAsString("NAME", color.name());
// #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);
return true;
}
bool Scribus150Format::readGradient(ScribusDoc *doc, VGradient &gra, ScXmlStreamReader& reader)
{
gra = VGradient(VGradient::linear);
gra.clearStops();
ScXmlStreamAttributes rattrs = reader.scAttributes();
QStringRef tagName = reader.name();
while(!reader.atEnd() && !reader.hasError())
{
ScXmlStreamReader::TokenType tType = reader.readNext();
if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
break;
if (tType == ScXmlStreamReader::StartElement && reader.name() == "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, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
{
static const QString CPARENT("CPARENT");
if (attrs.hasAttribute(CPARENT))
newStyle.setParent(attrs.valueAsString(CPARENT));
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 FCOLOR("FCOLOR");
if (attrs.hasAttribute(FCOLOR))
newStyle.setFillColor(attrs.valueAsString(FCOLOR));
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( " ", QString::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, true, false);
if (lnew.isEmpty())
lnew=LanguageManager::instance()->getAbbrevFromLang(l, false, 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, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
{
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)
{
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", "");
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
{
if (m_Doc->styleExists(parentStyle))
newStyle.setParent(parentStyle);
else if (parStyleMap.contains(parentStyle))
newStyle.setParent(parStyleMap.value(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 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("NumeartionOther");
if (attrs.hasAttribute(NumerationOther))
newStyle.setNumOther(static_cast<bool>(attrs.valueAsInt(NumerationOther)));
static const QString NumearationHigher("NumerationHigher");
if (attrs.hasAttribute(NumearationHigher))
newStyle.setNumHigher(static_cast<bool>(attrs.valueAsInt(NumearationHigher)));
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 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();
QStringRef thisTagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == thisTagName)
break;
if (reader.isStartElement() && reader.name() == "Tabs")
{
ParagraphStyle::TabRecord tb;
ScXmlStreamAttributes attrs2 = reader.scAttributes();
tb.tabPosition = attrs2.valueAsDouble("Pos");
tb.tabType = attrs2.valueAsInt("Type");
QString tbCh = attrs2.valueAsString("Fill","");
tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0];
tbs.append(tb);
}
}
if (tbs.count() > 0)
newStyle.setTabValues(tbs);
fixLegacyParStyle(newStyle);
}
void Scribus150Format::readTableStyle(ScribusDoc *doc, ScXmlStreamReader& reader, TableStyle& newStyle)
{
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"));
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.name() == "TableBorderLeft")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setLeftBorder(border);
}
else if (reader.name() == "TableBorderRight")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setRightBorder(border);
}
else if (reader.name() == "TableBorderTop")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setTopBorder(border);
}
else if (reader.name() == "TableBorderBottom")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setBottomBorder(border);
}
}
}
void Scribus150Format::readCellStyle(ScribusDoc *doc, ScXmlStreamReader& reader, CellStyle& newStyle)
{
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"));
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));
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.name() == "TableBorderLeft")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setLeftBorder(border);
}
else if (reader.name() == "TableBorderRight")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setRightBorder(border);
}
else if (reader.name() == "TableBorderTop")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setTopBorder(border);
}
else if (reader.name() == "TableBorderBottom")
{
TableBorder border;
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement() && reader.name() == "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));
}
}
newStyle.setBottomBorder(border);
}
}
}
void Scribus150Format::readLayers(ScLayer& layer, ScXmlStreamAttributes& attrs)
{
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)
{
double xa, 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);
}
doc->appendToArrowStyles(arrow);
return true;
}
bool Scribus150Format::readMultiline(multiLine& ml, ScXmlStreamReader& reader)
{
ml = multiLine();
ScXmlStreamAttributes rattrs = reader.scAttributes();
QStringRef tagName = reader.name();
while(!reader.atEnd() && !reader.hasError())
{
ScXmlStreamReader::TokenType tType = reader.readNext();
if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
break;
if (tType == ScXmlStreamReader::StartElement && reader.name() == "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, ScXmlStreamAttributes& attrs)
{
elem = attrs.valueAsInt("Element");
bookmark.PageObject = NULL;
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 = (PDFOptions::PDFVersion) 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->pdfOptions().PassOwner = attrs.valueAsString("PassOwner", "");
doc->pdfOptions().PassUser = attrs.valueAsString("PassUser", "");
doc->pdfOptions().Permissions = attrs.valueAsInt("Permissions", -4);
doc->pdfOptions().Encrypt = attrs.valueAsBool("Encrypt", false);
doc->pdfOptions().useLayers = attrs.valueAsBool("UseLayers", false);
doc->pdfOptions().UseLPI = attrs.valueAsBool("UseLpi", false);
doc->pdfOptions().UseSpotColors = attrs.valueAsBool("UseSpotColors", true);
doc->pdfOptions().doMultiFile = attrs.valueAsBool("doMultiFile", false);
doc->pdfOptions().displayBookmarks = attrs.valueAsBool("displayBookmarks", false);
doc->pdfOptions().displayFullscreen = attrs.valueAsBool("displayFullscreen", false);
doc->pdfOptions().displayLayers = attrs.valueAsBool("displayLayers", false);
doc->pdfOptions().displayThumbs = attrs.valueAsBool("displayThumbs", false);
doc->pdfOptions().hideMenuBar = attrs.valueAsBool("hideMenuBar", false);
doc->pdfOptions().hideToolBar = attrs.valueAsBool("hideToolBar", false);
doc->pdfOptions().fitWindow = attrs.valueAsBool("fitWindow", false);
doc->pdfOptions().openAfterExport = attrs.valueAsBool("openAfterExport", false);
doc->pdfOptions().PageLayout = attrs.valueAsInt("PageLayout", 0);
doc->pdfOptions().openAction = attrs.valueAsString("openAction", "");
QStringRef tagName = reader.name();
while (!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && (reader.name() == tagName))
break;
if (!reader.isStartElement())
continue;
QStringRef tName = reader.name();
attrs = reader.scAttributes();
if (tName == "LPI")
{
struct LPIData lpo;
lpo.Angle = attrs.valueAsInt("Angle");
lpo.Frequency = attrs.valueAsInt("Frequency");
lpo.SpotFunc = attrs.valueAsInt("SpotFunction");
doc->pdfOptions().LPISettings[attrs.valueAsString("Color")] = lpo;
}
if (tName == "Fonts")
{
QString fname = attrs.valueAsString("Name");
if (!doc->pdfOptions().EmbedList.contains(fname))
doc->pdfOptions().EmbedList.append(fname);
}
if (tName == "Subset")
{
QString sname = attrs.valueAsString("Name");
if (!doc->pdfOptions().SubsetList.contains(sname))
doc->pdfOptions().SubsetList.append(sname);
}
if (tName == "Effekte")
{
struct PDFPresentationData ef;
ef.pageEffectDuration = attrs.valueAsInt("pageEffectDuration");
ef.pageViewDuration = attrs.valueAsInt("pageViewDuration");
ef.effectType = attrs.valueAsInt("effectType");
ef.Dm = attrs.valueAsInt("Dm");
ef.M = attrs.valueAsInt("M");
ef.Di = attrs.valueAsInt("Di");
EffVal.append(ef);
}
}
return !reader.hasError();
}
bool Scribus150Format::readPrinterOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
{
ScXmlStreamAttributes attrs = reader.scAttributes();
doc->Print_Options.firstUse = attrs.valueAsBool("firstUse");
doc->Print_Options.toFile = attrs.valueAsBool("toFile");
doc->Print_Options.useAltPrintCommand = attrs.valueAsBool("useAltPrintCommand");
doc->Print_Options.outputSeparations = attrs.valueAsBool("outputSeparations");
doc->Print_Options.useSpotColors = attrs.valueAsBool("useSpotColors");
doc->Print_Options.useColor = attrs.valueAsBool("useColor");
doc->Print_Options.mirrorH = attrs.valueAsBool("mirrorH");
doc->Print_Options.mirrorV = attrs.valueAsBool("mirrorV");
doc->Print_Options.doGCR = attrs.valueAsBool("doGCR");
doc->Print_Options.doClip = attrs.valueAsBool("doClip");
doc->Print_Options.setDevParam = attrs.valueAsBool("setDevParam");
doc->Print_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds");
doc->Print_Options.cropMarks = attrs.valueAsBool("cropMarks");
doc->Print_Options.bleedMarks = attrs.valueAsBool("bleedMarks");
doc->Print_Options.registrationMarks = attrs.valueAsBool("registrationMarks");
doc->Print_Options.colorMarks = attrs.valueAsBool("colorMarks");
doc->Print_Options.includePDFMarks = attrs.valueAsBool("includePDFMarks", "1");
if (attrs.hasAttribute("PrintEngine"))
doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PrintEngine", 3);
else
doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PSLevel", 3);
doc->Print_Options.markLength = attrs.valueAsDouble("markLength");
doc->Print_Options.markOffset = attrs.valueAsDouble("markOffset");
doc->Print_Options.bleeds.setTop(attrs.valueAsDouble("BleedTop"));
doc->Print_Options.bleeds.setLeft(attrs.valueAsDouble("BleedLeft"));
doc->Print_Options.bleeds.setRight(attrs.valueAsDouble("BleedRight"));
doc->Print_Options.bleeds.setBottom(attrs.valueAsDouble("BleedBottom"));
doc->Print_Options.printer = attrs.valueAsString("printer");
doc->Print_Options.filename = attrs.valueAsString("filename");
doc->Print_Options.separationName = attrs.valueAsString("separationName");
doc->Print_Options.printerCommand = attrs.valueAsString("printerCommand");
doc->Print_Options.copies = 1;
QStringRef tagName = reader.name();
while(!reader.atEnd() && !reader.hasError())
{
ScXmlStreamReader::TokenType tType = reader.readNext();
QStringRef tName = reader.name();
if (tType == ScXmlStreamReader::StartElement && tName == "Separation")
doc->Print_Options.allSeparations.append(reader.attributes().value("Name").toString());
if (tType == ScXmlStreamReader::EndElement && tName == tagName)
break;
}
return !reader.hasError();
}
bool Scribus150Format::readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader)
{
QStringRef tagName = reader.name();
doc->clearItemAttributes();
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if(reader.isStartElement() && reader.name() == "ItemAttribute")
{
ScXmlStreamAttributes attrs = reader.scAttributes();
ObjectAttribute objattr;
objattr.name = attrs.valueAsString("Name");
objattr.type = attrs.valueAsString("Type");
objattr.value = attrs.valueAsString("Value");
objattr.parameter = attrs.valueAsString("Parameter");
objattr.relationship = attrs.valueAsString("Relationship");
objattr.relationshipto = attrs.valueAsString("RelationshipTo");
objattr.autoaddto = attrs.valueAsString("AutoAddTo");
doc->appendToItemAttributes(objattr);
}
}
return !reader.hasError();
}
bool Scribus150Format::readTableOfContents(ScribusDoc* doc, ScXmlStreamReader& reader)
{
QStringRef tagName = reader.name();
m_Doc->clearTocSetups();
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if(reader.isStartElement() && reader.name() == "TableOfContents")
{
ScXmlStreamAttributes attrs = reader.scAttributes();
ToCSetup tocsetup;
tocsetup.name = attrs.valueAsString("Name");
tocsetup.itemAttrName = attrs.valueAsString("ItemAttributeName");
tocsetup.frameName = attrs.valueAsString("FrameName");
tocsetup.textStyle = attrs.valueAsString("Style");
tocsetup.listNonPrintingFrames = QVariant(attrs.valueAsString("ListNonPrinting")).toBool();
QString numberPlacement(attrs.valueAsString("NumberPlacement"));
if (numberPlacement == "Beginning")
tocsetup.pageLocation = Beginning;
if (numberPlacement == "End")
tocsetup.pageLocation = End;
if (numberPlacement == "NotShown")
tocsetup.pageLocation = NotShown;
doc->appendToTocSetups(tocsetup);
}
}
return !reader.hasError();
}
bool Scribus150Format::readNotesStyles(ScribusDoc* doc, ScXmlStreamReader& reader)
{
QStringRef tagName = reader.name();
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
//read notes styles
if (reader.isStartElement() && reader.name() == "notesStyle")
{
ScXmlStreamAttributes attrs = reader.scAttributes();
NotesStyle NS;
NS.setName(attrs.valueAsString("Name"));
NS.setStart(attrs.valueAsInt("Start"));
NS.setEndNotes(attrs.valueAsBool("Endnotes"));
QString type = attrs.valueAsString("Type");
if (type == "Type_1_2_3")
NS.setType(Type_1_2_3);
else if (type == "Type_i_ii_iii")
NS.setType(Type_i_ii_iii);
else if (type == "Type_I_II_III")
NS.setType(Type_I_II_III);
else if (type == "Type_a_b_c")
NS.setType(Type_a_b_c);
else if (type == "Type_A_B_C")
NS.setType(Type_A_B_C);
else if (type == "Type_asterix")
NS.setType(Type_asterix);
else if (type == "Type_CJK")
NS.setType(Type_CJK);
else //if (type == "Type_None")
NS.setType(Type_None);
NS.setRange((NumerationRange) attrs.valueAsInt("Range"));
NS.setPrefix(attrs.valueAsString("Prefix"));
NS.setSuffix(attrs.valueAsString("Suffix"));
NS.setAutoNotesHeight(attrs.valueAsBool("AutoHeight"));
NS.setAutoNotesWidth(attrs.valueAsBool("AutoWidth"));
NS.setAutoRemoveEmptyNotesFrames(attrs.valueAsBool("AutoRemove"));
NS.setAutoWeldNotesFrames(attrs.valueAsBool("AutoWeld"));
NS.setSuperscriptInNote(attrs.valueAsBool("SuperNote"));
NS.setSuperscriptInMaster(attrs.valueAsBool("SuperMaster"));
NS.setMarksCharStyle("");
NS.setNotesParStyle("");
QString name;
name = attrs.valueAsString("MarksStyle");
if (!name.isEmpty())
NS.setMarksCharStyle(name);
name = attrs.valueAsString("NotesStyle");
if (!name.isEmpty())
NS.setNotesParStyle(name);
m_Doc->newNotesStyle(NS);
}
}
return !reader.hasError();
}
bool Scribus150Format::readNotesFrames(ScXmlStreamReader& reader)
{
notesFramesData.clear();
QStringRef tagName = reader.name();
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if (reader.isEndElement() && reader.name() == tagName)
break;
if (reader.isStartElement())
{
ScXmlStreamAttributes attrs = reader.scAttributes();
NoteFrameData eF;
eF.NSname = attrs.valueAsString("NSname");
eF.myID = attrs.valueAsInt("myID");
if (reader.name() == "ENDNOTEFRAME")
{
eF.index = attrs.valueAsInt("index");
eF.NSrange = (NumerationRange) attrs.valueAsInt("range");
eF.itemID = attrs.