Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scribus134format.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "scribus134format.h"
00008 #include "scribus134format.moc"
00009 #include "scribus134formatimpl.h"
00010 
00011 #include "../../formatidlist.h"
00012 #include "commonstrings.h"
00013 #include "missing.h"
00014 #include "prefsmanager.h"
00015 #include "scconfig.h"
00016 #include "scribusdoc.h"
00017 #include "scribusview.h"
00018 #include "sccolorengine.h"
00019 
00020 #include "units.h"
00021 #include "util.h"
00022 #include "colorutil.h"
00023 #include "scgzfile.h"
00024 #include <qcursor.h>
00025 #include <qfileinfo.h>
00026 #include <qvaluelist.h>
00027 
00028 
00029 // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
00030 // do. That documentatation is not duplicated here.
00031 // Please don't implement the functionality of your plugin here; do that
00032 // in scribus134formatimpl.h and scribus134formatimpl.cpp .
00033 
00034 Scribus134Format::Scribus134Format() :
00035        LoadSavePlugin()
00036 {
00037        // Set action info in languageChange, so we only have to do
00038        // it in one place. This includes registering file formats.
00039        languageChange();
00040 }
00041 
00042 Scribus134Format::~Scribus134Format()
00043 {
00044        unregisterAll();
00045 };
00046 
00047 void Scribus134Format::languageChange()
00048 {
00049        //(Re)register file formats.
00050        unregisterAll();
00051        registerFormats();
00052 }
00053 
00054 const QString Scribus134Format::fullTrName() const
00055 {
00056        return QObject::tr("Scribus 1.3.4 Support");
00057 }
00058 
00059 const ScActionPlugin::AboutData* Scribus134Format::getAboutData() const
00060 {
00061        AboutData* about = new AboutData;
00062        Q_CHECK_PTR(about);
00063        return about;
00064 }
00065 
00066 void Scribus134Format::deleteAboutData(const AboutData* about) const
00067 {
00068        Q_ASSERT(about);
00069        delete about;
00070 }
00071 
00072 void Scribus134Format::registerFormats()
00073 {
00074        FileFormat fmt(this);
00075        fmt.trName = tr("Scribus 1.3.4 Document");
00076        fmt.formatId = FORMATID_SLA134IMPORT;
00077        fmt.load = true;
00078        fmt.save = true;
00079        fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
00080        fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", false);
00081        fmt.mimeTypes = QStringList();
00082        fmt.mimeTypes.append("application/x-scribus");
00083        fmt.priority = 64;
00084        registerFormat(fmt);
00085 }
00086 
00087 bool Scribus134Format::fileSupported(QIODevice* /* file */, const QString & fileName) const
00088 {
00089        QCString docBytes("");
00090        if(fileName.right(2) == "gz")
00091        {
00092               ScGzFile gzf(fileName);
00093               if (!gzf.read(4096))
00094               {
00095                      // FIXME: Needs better error return
00096                      return false;
00097               }
00098               docBytes = gzf.data();
00099        }
00100        else
00101        {
00102               // Not gzip encoded, just load it
00103               loadRawText(fileName, docBytes);
00104        }
00105 //     if (docBytes.left(16) == "<SCRIBUSUTF8NEW " && docBytes.left(35).contains("Version=\"1.3.4"))
00106 //            return true;
00107        int startElemPos = docBytes.left(512).find("<SCRIBUSUTF8NEW ");
00108        return startElemPos >= 0 && docBytes.mid(startElemPos, 64).find("Version=\"1.3.4") >= 0;
00109 }
00110 
00111 QString Scribus134Format::readSLA(const QString & fileName)
00112 {
00113        QCString docBytes("");
00114        if(fileName.right(2) == "gz")
00115        {
00116               ScGzFile gzf(fileName);
00117               if (!gzf.read())
00118               {
00119                      // FIXME: Needs better error return
00120                      return false;
00121               }
00122               docBytes = gzf.data();
00123        }
00124        else
00125        {
00126               // Not gzip encoded, just load it
00127               loadRawText(fileName, docBytes);
00128        }
00129        QString docText("");
00130        int startElemPos = docBytes.left(512).find("<SCRIBUSUTF8NEW ");
00131        if (startElemPos >= 0 && docBytes.mid(startElemPos, 64).find("Version=\"1.3.4") >= 0)
00132               docText = QString::fromUtf8(docBytes);
00133        else
00134               return QString::null;
00135        if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13)))
00136               docText.truncate(docText.length()-1);
00137        return docText;
00138 }
00139 
00140 void Scribus134Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QValueList<ScFace> &getDummyScFaces)
00141 {
00142        getNewReplacement=false;
00143        getReplacedFonts.clear();
00144 }
00145 
00146 bool Scribus134Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */)
00147 {
00148        if (m_Doc==0 || m_AvailableFonts==0)
00149        {
00150               Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
00151               return false;
00152        }
00153        ParagraphStyle vg;
00154        struct Layer la;
00155        struct ScribusDoc::BookMa bok;
00156        int counter;//, Pgc;
00157        //bool AtFl;
00158        bool newVersion = false;
00159        QString tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
00160        QFont fo;
00161        QMap<int,int> TableID;
00162        QPtrList<PageItem> TableItems;
00163        QMap<int,int> TableIDM;
00164        QPtrList<PageItem> TableItemsM;
00165        QMap<int,int> TableIDF;
00166        QPtrList<PageItem> TableItemsF;
00167        QMap<PageItem*, int> groupID;
00168        QMap<PageItem*, int> groupIDM;
00169        QMap<PageItem*, int> groupIDF;
00170        int a;
00171        PageItem *Neu;
00172        Page* Apage;
00173        itemRemap.clear();
00174        itemNext.clear();
00175        itemCount = 0;
00176        itemRemapM.clear();
00177        itemNextM.clear();
00178        itemCountM = 0;
00179        itemRemapF.clear();
00180        itemNextF.clear();
00181        itemCountF = 0;
00182        QDomDocument docu("scridoc");
00183        QString f(readSLA(fileName));
00184        if (f.isEmpty())
00185               return false;
00186        /* 2004/10/02 - petr vanek - bug #1092 - missing <PAGE> crash Scribus. The check constraint moved into IsScribus()
00187        FIXME: I've add test on containig tag PAGE but returning false freezes S. in scribus.cpp need some hack too...  */
00188        if (!docu.setContent(f))
00189               return false;
00190        m_Doc->PageColors.clear();
00191        m_Doc->Layers.clear();
00192        int layerToSetActive=0;
00193        ScColor lf = ScColor();
00194        QDomElement elem=docu.documentElement();
00195        if (elem.tagName() != "SCRIBUSUTF8NEW")
00196               return false;
00197        if (elem.hasAttribute("Version"))
00198               newVersion = true;
00199        QDomNode DOC=elem.firstChild();
00200        if (m_mwProgressBar!=0)
00201        {
00202               m_mwProgressBar->setTotalSteps(DOC.childNodes().count());
00203               m_mwProgressBar->setProgress(0);
00204        }
00205        int ObCount = 0;
00206        TableItems.clear();
00207        TableID.clear();
00208        TableItemsM.clear();
00209        TableIDM.clear();
00210        TableItemsF.clear();
00211        TableIDF.clear();
00212        PrefsManager* prefsManager=PrefsManager::instance();
00213        while(!DOC.isNull())
00214        {
00215               QDomElement dc=DOC.toElement();
00216        /*
00217        * Attribute von DOCUMENT auslesen
00218        */
00219               //CB Add this in to set this in the file in memory. Its saved, why not load it.
00220               //Will of course be replaced by per page settings although we still probably need a document default
00221               m_Doc->m_pageSize = dc.attribute("PAGESIZE");
00222               m_Doc->PageOri = dc.attribute("ORIENTATION", "0").toInt();
00223               m_Doc->FirstPnum = dc.attribute("FIRSTNUM", "1").toInt();
00224               m_Doc->currentPageLayout=dc.attribute("BOOK", "0").toInt();
00225               int fp;
00226               if (m_Doc->currentPageLayout == 0)
00227                      fp = 0;
00228               else
00229               {
00230                      if (dc.attribute("FIRSTLEFT", "0").toInt() == 1)
00231                             fp = 0;
00232                      else
00233                             fp = 1;
00234               }
00235               if (DOC.namedItem("PageSets").isNull())
00236               {
00237                      m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = fp;
00238                      m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble();
00239                      m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0;
00240                      m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble();
00241               }
00242               m_Doc->setUsesAutomaticTextFrames(dc.attribute("AUTOTEXT").toInt());
00243               m_Doc->PageSp=dc.attribute("AUTOSPALTEN").toInt();
00244               m_Doc->PageSpa=dc.attribute("ABSTSPALTEN").toDouble();
00245               m_Doc->setUnitIndex(dc.attribute("UNITS", "0").toInt());
00246               m_Doc->toolSettings.defSize=qRound(dc.attribute("DSIZE").toDouble() * 10);
00247               Defont=dc.attribute("DFONT");
00248               m_AvailableFonts->findFont(Defont, m_Doc);
00249               m_Doc->toolSettings.defFont = Defont;
00250               m_Doc->toolSettings.dCols=dc.attribute("DCOL", "1").toInt();
00251               m_Doc->toolSettings.dGap=dc.attribute("DGAP", "0.0").toDouble();
00252               m_Doc->documentInfo.setAuthor(dc.attribute("AUTHOR"));
00253               m_Doc->documentInfo.setComments(dc.attribute("COMMENTS"));
00254               m_Doc->documentInfo.setKeywords(dc.attribute("KEYWORDS",""));
00255               m_Doc->documentInfo.setTitle(dc.attribute("TITLE"));
00256               m_Doc->documentInfo.setPublisher(dc.attribute("PUBLISHER", ""));
00257               m_Doc->documentInfo.setDate(dc.attribute("DOCDATE", ""));
00258               m_Doc->documentInfo.setType(dc.attribute("DOCTYPE", ""));
00259               m_Doc->documentInfo.setFormat(dc.attribute("DOCFORMAT", ""));
00260               m_Doc->documentInfo.setIdent(dc.attribute("DOCIDENT", ""));
00261               m_Doc->documentInfo.setSource(dc.attribute("DOCSOURCE", ""));
00262               m_Doc->documentInfo.setLangInfo(dc.attribute("DOCLANGINFO", ""));
00263               m_Doc->documentInfo.setRelation(dc.attribute("DOCRELATION", ""));
00264               m_Doc->documentInfo.setCover(dc.attribute("DOCCOVER", ""));
00265               m_Doc->documentInfo.setRights(dc.attribute("DOCRIGHTS", ""));
00266               m_Doc->documentInfo.setContrib(dc.attribute("DOCCONTRIB", ""));
00267               m_Doc->typographicSettings.valueSuperScript = dc.attribute("VHOCH").toInt();
00268               m_Doc->typographicSettings.scalingSuperScript = dc.attribute("VHOCHSC").toInt();
00269               m_Doc->typographicSettings.valueSubScript = dc.attribute("VTIEF").toInt();
00270               m_Doc->typographicSettings.scalingSubScript = dc.attribute("VTIEFSC").toInt();
00271               m_Doc->typographicSettings.valueSmallCaps = dc.attribute("VKAPIT").toInt();
00272               m_Doc->typographicSettings.valueBaseGrid = dc.attribute("BASEGRID", "12").toDouble();
00273               m_Doc->typographicSettings.offsetBaseGrid = dc.attribute("BASEO", "0").toDouble();
00274               m_Doc->typographicSettings.autoLineSpacing = dc.attribute("AUTOL", "20").toInt();
00275               m_Doc->typographicSettings.valueUnderlinePos = dc.attribute("UnderlinePos", "-1").toInt();
00276               m_Doc->typographicSettings.valueUnderlineWidth = dc.attribute("UnderlineWidth", "-1").toInt();
00277               m_Doc->typographicSettings.valueStrikeThruPos = dc.attribute("StrikeThruPos", "-1").toInt();
00278               m_Doc->typographicSettings.valueStrikeThruWidth = dc.attribute("StrikeThruWidth", "-1").toInt();
00279               m_Doc->GroupCounter=dc.attribute("GROUPC", "1").toInt();
00280               //m_Doc->HasCMS = static_cast<bool>(dc.attribute("HCMS", "0").toInt());
00281               m_Doc->CMSSettings.SoftProofOn = static_cast<bool>(dc.attribute("DPSo", "0").toInt());
00282               m_Doc->CMSSettings.SoftProofFullOn = static_cast<bool>(dc.attribute("DPSFo", "0").toInt());
00283               m_Doc->CMSSettings.CMSinUse = static_cast<bool>(dc.attribute("DPuse", "0").toInt());
00284               m_Doc->CMSSettings.GamutCheck = static_cast<bool>(dc.attribute("DPgam", "0").toInt());
00285               m_Doc->CMSSettings.BlackPoint = static_cast<bool>(dc.attribute("DPbla", "1").toInt());
00286               m_Doc->CMSSettings.DefaultMonitorProfile = dc.attribute("DPMo","");
00287               m_Doc->CMSSettings.DefaultPrinterProfile = dc.attribute("DPPr","");
00288               m_Doc->CMSSettings.DefaultImageRGBProfile = dc.attribute("DPIn","");
00289               m_Doc->CMSSettings.DefaultImageCMYKProfile = dc.attribute("DPInCMYK","");
00290               m_Doc->CMSSettings.DefaultSolidColorRGBProfile = dc.attribute("DPIn2","");
00291               if (dc.hasAttribute("DPIn3"))
00292                      m_Doc->CMSSettings.DefaultSolidColorCMYKProfile = dc.attribute("DPIn3","");
00293               else
00294                      m_Doc->CMSSettings.DefaultSolidColorCMYKProfile = dc.attribute("DPPr","");
00295               //m_Doc->CMSSettings.DefaultIntentPrinter = dc.attribute("DIPr", "0").toInt();
00296               //m_Doc->CMSSettings.DefaultIntentMonitor = dc.attribute("DIMo", "1").toInt();
00297               m_Doc->CMSSettings.DefaultIntentColors = dc.attribute("DISc", "1").toInt();
00298               m_Doc->CMSSettings.DefaultIntentImages = dc.attribute("DIIm", "0").toInt();
00299               layerToSetActive=dc.attribute("ALAYER", "0").toInt();
00300               m_Doc->Language = dc.attribute("LANGUAGE", "");
00301               m_Doc->MinWordLen = dc.attribute("MINWORDLEN", "3").toInt();
00302               m_Doc->HyCount = dc.attribute("HYCOUNT", "2").toInt();
00303               if (dc.hasAttribute("PAGEWIDTH"))
00304                      m_Doc->pageWidth=dc.attribute("PAGEWIDTH").toDouble();
00305               else
00306                      m_Doc->pageWidth=dc.attribute("PAGEWITH").toDouble();
00307               m_Doc->pageHeight=dc.attribute("PAGEHEIGHT").toDouble();
00308               m_Doc->pageMargins.Left=QMAX(0.0, dc.attribute("BORDERLEFT").toDouble());
00309               m_Doc->pageMargins.Right=QMAX(0.0, dc.attribute("BORDERRIGHT").toDouble());
00310               m_Doc->pageMargins.Top=QMAX(0.0, dc.attribute("BORDERTOP").toDouble());
00311               m_Doc->pageMargins.Bottom=QMAX(0.0, dc.attribute("BORDERBOTTOM").toDouble());
00312               m_Doc->bleeds.Top = dc.attribute("BleedTop", "0").toDouble();
00313               m_Doc->bleeds.Left = dc.attribute("BleedLeft", "0").toDouble();
00314               m_Doc->bleeds.Right = dc.attribute("BleedRight", "0").toDouble();
00315               m_Doc->bleeds.Bottom = dc.attribute("BleedBottom", "0").toDouble();
00316               m_Doc->Automatic = static_cast<bool>(dc.attribute("AUTOMATIC", "1").toInt());
00317               m_Doc->AutoCheck = static_cast<bool>(dc.attribute("AUTOCHECK", "0").toInt());
00318               m_Doc->GuideLock = static_cast<bool>(dc.attribute("GUIDELOCK", "0").toInt());
00319               m_Doc->guidesSettings.minorGrid = dc.attribute("MINGRID", tmp.setNum(prefsManager->appPrefs.guidesSettings.minorGrid)).toDouble();
00320               m_Doc->guidesSettings.majorGrid = dc.attribute("MAJGRID", tmp.setNum(prefsManager->appPrefs.guidesSettings.majorGrid)).toDouble();
00321               m_Doc->guidesSettings.gridShown = static_cast<bool>(dc.attribute("SHOWGRID", "0").toInt());
00322               m_Doc->guidesSettings.guidesShown = static_cast<bool>(dc.attribute("SHOWGUIDES", "1").toInt());
00323               m_Doc->guidesSettings.colBordersShown = static_cast<bool>(dc.attribute("showcolborders", "0").toInt());
00324               m_Doc->guidesSettings.framesShown = static_cast<bool>(dc.attribute("SHOWFRAME", "1").toInt());
00325               m_Doc->guidesSettings.layerMarkersShown = static_cast<bool>(dc.attribute("SHOWLAYERM", "0").toInt());
00326               m_Doc->guidesSettings.marginsShown = static_cast<bool>(dc.attribute("SHOWMARGIN", "1").toInt());
00327               m_Doc->guidesSettings.baseShown = static_cast<bool>(dc.attribute("SHOWBASE", "0").toInt());
00328               m_Doc->guidesSettings.showPic = static_cast<bool>(dc.attribute("SHOWPICT", "1").toInt());
00329               m_Doc->guidesSettings.linkShown = static_cast<bool>(dc.attribute("SHOWLINK", "0").toInt());
00330               m_Doc->guidesSettings.showControls = static_cast<bool>(dc.attribute("SHOWControl", "0").toInt());
00331               m_Doc->guidesSettings.rulerMode = static_cast<bool>(dc.attribute("rulerMode", "1").toInt());
00332               m_Doc->guidesSettings.rulersShown = static_cast<bool>(dc.attribute("showrulers", "1").toInt());
00333               m_Doc->guidesSettings.showBleed = static_cast<bool>(dc.attribute("showBleed", "1").toInt());
00334               m_Doc->rulerXoffset = dc.attribute("rulerXoffset", "0").toDouble();
00335               m_Doc->rulerYoffset =dc.attribute("rulerYoffset", "0").toDouble();
00336               m_Doc->SnapGuides = static_cast<bool>(dc.attribute("SnapToGuides", "0").toInt());
00337               m_Doc->useRaster = static_cast<bool>(dc.attribute("SnapToGrid", "0").toInt());
00338               m_Doc->toolSettings.polyC = dc.attribute("POLYC", "4").toInt();
00339               m_Doc->toolSettings.polyF = dc.attribute("POLYF", "0.5").toDouble();
00340               m_Doc->toolSettings.polyR = dc.attribute("POLYR", "0").toDouble();
00341               m_Doc->toolSettings.polyFd = dc.attribute("POLYFD", "0").toInt();
00342               m_Doc->toolSettings.polyS = static_cast<bool>(dc.attribute("POLYS", "0").toInt());
00343               m_Doc->AutoSave = static_cast<bool>(dc.attribute("AutoSave", "0").toInt());
00344               m_Doc->AutoSaveTime = dc.attribute("AutoSaveTime", "600000").toInt();
00345               m_Doc->scratch.Bottom = dc.attribute("ScratchBottom", "20").toDouble();
00346               // FIXME A typo in early 1.3cvs (MAR 05) means we must support loading of
00347               // FIXME 'ScatchLeft' for a while too. This can be removed in a few months.
00348               if (dc.hasAttribute("ScatchLeft"))
00349                      m_Doc->scratch.Left = dc.attribute("ScatchLeft", "100").toDouble();
00350               else
00351                      m_Doc->scratch.Left = dc.attribute("ScratchLeft", "100").toDouble();
00352               m_Doc->scratch.Right = dc.attribute("ScratchRight", "100").toDouble();
00353               m_Doc->scratch.Top = dc.attribute("ScratchTop", "20").toDouble();
00354               m_Doc->toolSettings.dStartArrow = dc.attribute("StartArrow", "0").toInt();
00355               m_Doc->toolSettings.dEndArrow = dc.attribute("EndArrow", "0").toInt();
00356               m_Doc->toolSettings.scaleX = dc.attribute("PICTSCX", "1").toDouble();
00357               m_Doc->toolSettings.scaleY = dc.attribute("PICTSCY", "1").toDouble();
00358               m_Doc->toolSettings.scaleType = static_cast<bool>(dc.attribute("PSCALE", "1").toInt());
00359               m_Doc->toolSettings.aspectRatio = static_cast<bool>(dc.attribute("PASPECT", "0").toInt());
00360               m_Doc->toolSettings.lowResType = dc.attribute("HalfRes", "1").toInt();
00361               m_Doc->toolSettings.useEmbeddedPath = static_cast<bool>(dc.attribute("EmbeddedPath", "0").toInt());
00362               if (dc.hasAttribute("PEN"))
00363                      m_Doc->toolSettings.dPen = dc.attribute("PEN");
00364               if (dc.hasAttribute("BRUSH"))
00365                      m_Doc->toolSettings.dBrush = dc.attribute("BRUSH");
00366               if (dc.hasAttribute("PENLINE"))
00367                      m_Doc->toolSettings.dPenLine = dc.attribute("PENLINE");
00368               if (dc.hasAttribute("PENTEXT"))
00369                      m_Doc->toolSettings.dPenText = dc.attribute("PENTEXT");
00370               if (dc.hasAttribute("StrokeText"))
00371                      m_Doc->toolSettings.dStrokeText = dc.attribute("StrokeText");
00372               m_Doc->toolSettings.dTextBackGround = dc.attribute("TextBackGround", CommonStrings::None);
00373               m_Doc->toolSettings.dTextLineColor = dc.attribute("TextLineColor", CommonStrings::None);
00374               m_Doc->toolSettings.dTextBackGroundShade = dc.attribute("TextBackGroundShade", "100").toInt();
00375               m_Doc->toolSettings.dTextLineShade = dc.attribute("TextLineShade", "100").toInt();
00376               m_Doc->toolSettings.dTextPenShade = dc.attribute("TextPenShade", "100").toInt();
00377               m_Doc->toolSettings.dTextStrokeShade = dc.attribute("TextStrokeShade", "100").toInt();
00378               m_Doc->toolSettings.dLineArt = static_cast<Qt::PenStyle>(dc.attribute("STIL").toInt());
00379               m_Doc->toolSettings.dLstyleLine = static_cast<Qt::PenStyle>(dc.attribute("STILLINE").toInt());
00380               m_Doc->toolSettings.dWidth = dc.attribute("WIDTH", "1").toDouble();
00381               m_Doc->toolSettings.dWidthLine = dc.attribute("WIDTHLINE", "1").toDouble();
00382               m_Doc->toolSettings.dShade2 = dc.attribute("PENSHADE", "100").toInt();
00383               m_Doc->toolSettings.dShadeLine = dc.attribute("LINESHADE", "100").toInt();
00384               m_Doc->toolSettings.dShade = dc.attribute("BRUSHSHADE", "100").toInt();
00385               m_Doc->toolSettings.magMin = dc.attribute("MAGMIN", "10").toInt();
00386               m_Doc->toolSettings.magMax = dc.attribute("MAGMAX", "3200").toInt();
00387               m_Doc->toolSettings.magStep = dc.attribute("MAGSTEP", "200").toInt();
00388               m_Doc->toolSettings.dispX = dc.attribute("dispX", "10").toDouble();
00389               m_Doc->toolSettings.dispY = dc.attribute("dispY", "10").toDouble();
00390               m_Doc->toolSettings.constrain = dc.attribute("constrain", "15").toDouble();
00391               //CB Reset doc zoom step value to 200% instead of old values.
00392               if (m_Doc->toolSettings.magStep<100)
00393                      m_Doc->toolSettings.magStep=200;
00394               m_Doc->toolSettings.tabFillChar = dc.attribute("TabFill","");
00395               m_Doc->toolSettings.dTabWidth=dc.attribute("TabWidth", "36.0").toDouble();
00396               if (dc.hasAttribute("CPICT"))
00397                      m_Doc->toolSettings.dBrushPict = dc.attribute("CPICT");
00398               m_Doc->toolSettings.shadePict = dc.attribute("PICTSHADE", "100").toInt();
00399               if (dc.hasAttribute("PAGEC"))
00400                      m_Doc->papColor = QColor(dc.attribute("PAGEC"));
00401               if (dc.hasAttribute("MARGC"))
00402                      m_Doc->guidesSettings.margColor = QColor(dc.attribute("MARGC"));
00403               if (dc.hasAttribute("MINORC"))
00404                      m_Doc->guidesSettings.minorColor = QColor(dc.attribute("MINORC"));
00405               if (dc.hasAttribute("MAJORC"))
00406                      m_Doc->guidesSettings.majorColor = QColor(dc.attribute("MAJORC"));
00407               if (dc.hasAttribute("GuideC"))
00408                      m_Doc->guidesSettings.guideColor = QColor(dc.attribute("GuideC"));
00409               if (dc.hasAttribute("BaseC"))
00410                      m_Doc->guidesSettings.baseColor = QColor(dc.attribute("BaseC"));
00411               m_Doc->marginColored = static_cast<bool>(dc.attribute("RANDF", "0").toInt());
00412               m_Doc->guidesSettings.before = static_cast<bool>(dc.attribute("BACKG", "1").toInt());
00413               m_Doc->guidesSettings.guideRad = dc.attribute("GuideRad", "10").toDouble();
00414               m_Doc->guidesSettings.grabRad = dc.attribute("GRAB", "4").toInt();
00415               if (dc.hasAttribute("currentProfile"))
00416               {
00417                      m_Doc->checkerProfiles.clear();
00418                      m_Doc->curCheckProfile = dc.attribute("currentProfile");
00419               }
00420               m_Doc->LastAuto = 0;
00421               QDomNode PAGE=DOC.firstChild();
00422               counter = 0;
00423               while(!PAGE.isNull())
00424               {
00425                      ObCount++;
00426                      if (m_mwProgressBar!=0)
00427                             m_mwProgressBar->setProgress(ObCount);
00428                      QDomElement pg=PAGE.toElement();
00429                      if (pg.tagName()=="PageSets")
00430                      {
00431                             QDomNode PGS = PAGE.firstChild();
00432                             m_Doc->pageSets.clear();
00433                             while(!PGS.isNull())
00434                             {
00435                                    QDomElement PgsAttr = PGS.toElement();
00436                                    if(PgsAttr.tagName() == "Set")
00437                                    {
00438                                           struct PageSet pageS;
00439                                           pageS.Name = CommonStrings::untranslatePageSetString(PgsAttr.attribute("Name"));
00440                                           pageS.FirstPage = PgsAttr.attribute("FirstPage", "0").toInt();
00441                                           pageS.Rows = PgsAttr.attribute("Rows", "1").toInt();
00442                                           pageS.Columns = PgsAttr.attribute("Columns", "1").toInt();
00443                                           pageS.GapHorizontal = PgsAttr.attribute("GapHorizontal", "0").toDouble();
00444                                           pageS.GapVertical = PgsAttr.attribute("GapVertical", "0").toDouble();
00445                                           pageS.GapBelow = PgsAttr.attribute("GapBelow", "0").toDouble();
00446                                           pageS.pageNames.clear();
00447                                           QDomNode PGSN = PGS.firstChild();
00448                                           while(!PGSN.isNull())
00449                                           {
00450                                                  QDomElement PgsAttrN = PGSN.toElement();
00451                                                  if(PgsAttrN.tagName() == "PageNames")
00452                                                         pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(PgsAttrN.attribute("Name")));
00453                                                  PGSN = PGSN.nextSibling();
00454                                           }
00455                                           m_Doc->pageSets.append(pageS);
00456                                    }
00457                                    PGS = PGS.nextSibling();
00458                             }
00459                      }
00460                      if (pg.tagName()=="CheckProfile")
00461                      {
00462                             struct checkerPrefs checkerSettings;
00463                             checkerSettings.ignoreErrors = static_cast<bool>(pg.attribute("ignoreErrors", "0").toInt());
00464                             checkerSettings.autoCheck = static_cast<bool>(pg.attribute("autoCheck", "1").toInt());
00465                             checkerSettings.checkGlyphs = static_cast<bool>(pg.attribute("checkGlyphs", "1").toInt());
00466                             checkerSettings.checkOrphans = static_cast<bool>(pg.attribute("checkOrphans", "1").toInt());
00467                             checkerSettings.checkOverflow = static_cast<bool>(pg.attribute("checkOverflow", "1").toInt());
00468                             checkerSettings.checkPictures = static_cast<bool>(pg.attribute("checkPictures", "1").toInt());
00469                             checkerSettings.checkResolution = static_cast<bool>(pg.attribute("checkResolution", "1").toInt());
00470                             checkerSettings.checkTransparency = static_cast<bool>(pg.attribute("checkTransparency", "1").toInt());
00471                             checkerSettings.minResolution = pg.attribute("minResolution", "72").toDouble();
00472                             checkerSettings.maxResolution = pg.attribute("maxResolution", "4800").toDouble();
00473                             checkerSettings.checkAnnotations = static_cast<bool>(pg.attribute("checkAnnotations", "0").toInt());
00474                             checkerSettings.checkRasterPDF = static_cast<bool>(pg.attribute("checkRasterPDF", "1").toInt());
00475                             checkerSettings.checkForGIF = static_cast<bool>(pg.attribute("checkForGIF", "1").toInt());
00476                             checkerSettings.ignoreOffLayers = static_cast<bool>(pg.attribute("ignoreOffLayers", "0").toInt());
00477                             m_Doc->checkerProfiles[pg.attribute("Name")] = checkerSettings;
00478                      }
00479                      // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
00480                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
00481                      {
00482                             if (pg.hasAttribute("CMYK"))
00483                                    lf.setNamedColor(pg.attribute("CMYK"));
00484                             else
00485                                    lf.fromQColor(QColor(pg.attribute("RGB")));
00486                             if (pg.hasAttribute("Spot"))
00487                                    lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
00488                             else
00489                                    lf.setSpotColor(false);
00490                             if (pg.hasAttribute("Register"))
00491                                    lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
00492                             else
00493                                    lf.setRegistrationColor(false);
00494                             m_Doc->PageColors.insert(pg.attribute("NAME"), lf);
00495                      }
00496                      if(pg.tagName()=="STYLE")
00497                      {
00498                             readParagraphStyle(vg, pg, *m_AvailableFonts, m_Doc);
00499                             StyleSet<ParagraphStyle>tmp;
00500                             tmp.create(vg);
00501                             m_Doc->redefineStyles(tmp, false);
00502                      }
00503                      if(pg.tagName()=="CHARSTYLE")
00504                      {
00505                             readParagraphStyle(vg, pg, *m_AvailableFonts, m_Doc);
00506                             StyleSet<CharStyle> temp;
00507                             temp.create(vg.charStyle());
00508                             m_Doc->redefineCharStyles(temp, false);
00509                      }
00510                      if(pg.tagName()=="JAVA")
00511                             m_Doc->JavaScripts[pg.attribute("NAME")] = pg.attribute("SCRIPT");
00512                      if(pg.tagName()=="LAYERS")
00513                      {
00514                             la.LNr = pg.attribute("NUMMER").toInt();
00515                             la.Level = pg.attribute("LEVEL").toInt();
00516                             la.Name = pg.attribute("NAME");
00517                             la.isViewable = pg.attribute("SICHTBAR").toInt();
00518                             la.isPrintable = pg.attribute("DRUCKEN").toInt();
00519                             la.isEditable = pg.attribute("EDIT", "1").toInt();
00520                             la.flowControl = pg.attribute("FLOW", "1").toInt();
00521                             la.transparency = pg.attribute("TRANS", "1").toDouble();
00522                             la.blendMode = pg.attribute("BLEND", "0").toInt();
00523                             la.outlineMode = pg.attribute("OUTL", "0").toInt();
00524                             if (pg.hasAttribute("LAYERC"))
00525                                    la.markerColor =  QColor(pg.attribute("LAYERC","#000000"));
00526                             else
00527                             {
00528                                    QColor marker;
00529                                    switch (la.LNr % 7)
00530                                    {
00531                                           case 0:
00532                                                  marker = Qt::black;
00533                                                  break;
00534                                           case 1:
00535                                                  marker = Qt::red;
00536                                                  break;
00537                                           case 2:
00538                                                  marker = Qt::green;
00539                                                  break;
00540                                           case 3:
00541                                                  marker = Qt::blue;
00542                                                  break;
00543                                           case 4:
00544                                                  marker = Qt::cyan;
00545                                                  break;
00546                                           case 5:
00547                                                  marker = Qt::magenta;
00548                                                  break;
00549                                           case 6:
00550                                                  marker = Qt::yellow;;
00551                                                  break;
00552                                    }
00553                                    la.markerColor = marker;
00554                             }
00555                             m_Doc->Layers.append(la);
00556                      }
00557 /*                   if(pg.tagName()=="Bookmark")
00558                      {
00559                             bok.Title = pg.attribute("Title");
00560                             bok.Text = pg.attribute("Text");
00561                             bok.Aktion = pg.attribute("Aktion");
00562                             bok.ItemNr = pg.attribute("ItemNr").toInt();
00563                             bok.Seite = pg.attribute("Seite").toInt();
00564                             bok.Element = pg.attribute("Element").toInt();
00565                             bok.First = pg.attribute("First").toInt();
00566                             bok.Last = pg.attribute("Last").toInt();
00567                             bok.Prev = pg.attribute("Prev").toInt();
00568                             bok.Next = pg.attribute("Next").toInt();
00569                             bok.Parent = pg.attribute("Parent").toInt();
00570                             m_Doc->BookMarks.append(bok);
00571                      } */
00572                      if(pg.tagName()=="MultiLine")
00573                      {
00574                             multiLine ml;
00575                             QDomNode MuLn = PAGE.firstChild();
00576                             while(!MuLn.isNull())
00577                             {
00578                                    QDomElement MuL = MuLn.toElement();
00579                                    struct SingleLine sl;
00580                                    sl.Color = MuL.attribute("Color");
00581                                    sl.Dash = MuL.attribute("Dash").toInt();
00582                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
00583                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
00584                                    sl.Shade = MuL.attribute("Shade").toInt();
00585                                    sl.Width = MuL.attribute("Width").toDouble();
00586                                    ml.shortcut = MuL.attribute("Shortcut");
00587                                    ml.push_back(sl);
00588                                    MuLn = MuLn.nextSibling();
00589                             }
00590                             m_Doc->MLineStyles.insert(pg.attribute("Name"), ml);
00591                      }
00592                      if(pg.tagName()=="Arrows")
00593                      {
00594                             struct ArrowDesc arrow;
00595                             arrow.name = pg.attribute("Name");
00596                             arrow.userArrow = true;
00597                             double xa, ya;
00598                             QString tmp = pg.attribute("Points");
00599                             QTextStream fp(&tmp, IO_ReadOnly);
00600                             for (uint cx = 0; cx < pg.attribute("NumPoints").toUInt(); ++cx)
00601                             {
00602                                    fp >> xa;
00603                                    fp >> ya;
00604                                    arrow.points.addPoint(xa, ya);
00605                             }
00606                             m_Doc->arrowStyles.append(arrow);
00607                      }
00608                      if(pg.tagName()=="Printer")
00609                      {
00610                             m_Doc->Print_Options.firstUse = static_cast<bool>(pg.attribute("firstUse").toInt());
00611                             m_Doc->Print_Options.toFile = static_cast<bool>(pg.attribute("toFile").toInt());
00612                             m_Doc->Print_Options.useAltPrintCommand = static_cast<bool>(pg.attribute("useAltPrintCommand").toInt());
00613                             m_Doc->Print_Options.outputSeparations = static_cast<bool>(pg.attribute("outputSeparations").toInt());
00614                             m_Doc->Print_Options.useSpotColors = static_cast<bool>(pg.attribute("useSpotColors").toInt());
00615                             m_Doc->Print_Options.useColor = static_cast<bool>(pg.attribute("useColor").toInt());
00616                             m_Doc->Print_Options.mirrorH = static_cast<bool>(pg.attribute("mirrorH").toInt());
00617                             m_Doc->Print_Options.mirrorV = static_cast<bool>(pg.attribute("mirrorV").toInt());
00618                             m_Doc->Print_Options.useICC = static_cast<bool>(pg.attribute("useICC").toInt());
00619                             m_Doc->Print_Options.doGCR = static_cast<bool>(pg.attribute("doGCR").toInt());
00620                             m_Doc->Print_Options.doClip = static_cast<bool>(pg.attribute("doClip").toInt());
00621                             m_Doc->Print_Options.setDevParam = static_cast<bool>(pg.attribute("setDevParam").toInt());
00622                             m_Doc->Print_Options.doOverprint = static_cast<bool>(pg.attribute("doOverprint").toInt());
00623                             m_Doc->Print_Options.cropMarks = static_cast<bool>(pg.attribute("cropMarks").toInt());
00624                             m_Doc->Print_Options.bleedMarks = static_cast<bool>(pg.attribute("bleedMarks").toInt());
00625                             m_Doc->Print_Options.registrationMarks = static_cast<bool>(pg.attribute("registrationMarks").toInt());
00626                             m_Doc->Print_Options.colorMarks = static_cast<bool>(pg.attribute("colorMarks").toInt());
00627                             m_Doc->Print_Options.PSLevel = pg.attribute("PSLevel").toInt();
00628                             m_Doc->Print_Options.markOffset = pg.attribute("markOffset").toDouble();
00629                             m_Doc->Print_Options.bleeds.Top = pg.attribute("BleedTop").toDouble();
00630                             m_Doc->Print_Options.bleeds.Left = pg.attribute("BleedLeft").toDouble();
00631                             m_Doc->Print_Options.bleeds.Right = pg.attribute("BleedRight").toDouble();
00632                             m_Doc->Print_Options.bleeds.Bottom = pg.attribute("BleedBottom").toDouble();
00633                             m_Doc->Print_Options.printer = pg.attribute("printer");
00634                             m_Doc->Print_Options.filename = pg.attribute("filename");
00635                             m_Doc->Print_Options.separationName = pg.attribute("separationName");
00636                             m_Doc->Print_Options.printerCommand = pg.attribute("printerCommand");
00637                             m_Doc->Print_Options.copies = 1;
00638                             QDomNode PFO = PAGE.firstChild();
00639                             while(!PFO.isNull())
00640                             {
00641                                    QDomElement pdfF = PFO.toElement();
00642                                    if(pdfF.tagName() == "Separation")
00643                                           m_Doc->Print_Options.allSeparations.append(pdfF.attribute("Name"));
00644                                    PFO = PFO.nextSibling();
00645                             }
00646                      }
00647                      if(pg.tagName()=="PDF")
00648                      {
00649                             m_Doc->PDF_Options.Articles = static_cast<bool>(pg.attribute("Articles").toInt());
00650                             m_Doc->PDF_Options.Thumbnails = static_cast<bool>(pg.attribute("Thumbnails").toInt());
00651                             m_Doc->PDF_Options.Compress = static_cast<bool>(pg.attribute("Compress").toInt());
00652                             m_Doc->PDF_Options.CompressMethod = pg.attribute("CMethod", "0").toInt();
00653                             m_Doc->PDF_Options.Quality = pg.attribute("Quality", "0").toInt();
00654                             m_Doc->PDF_Options.RecalcPic = static_cast<bool>(pg.attribute("RecalcPic").toInt());
00655                             m_Doc->PDF_Options.Bookmarks = static_cast<bool>(pg.attribute("Bookmarks").toInt());
00656                             if (pg.hasAttribute("firstUse"))
00657                                    m_Doc->PDF_Options.firstUse = static_cast<bool>(pg.attribute("firstUse").toInt());
00658                             else
00659                                    m_Doc->PDF_Options.firstUse = true;
00660                             if (pg.hasAttribute("MirrorH"))
00661                                    m_Doc->PDF_Options.MirrorH = static_cast<bool>(pg.attribute("MirrorH").toInt());
00662                             else
00663                                    m_Doc->PDF_Options.MirrorH = false;
00664                             if (pg.hasAttribute("MirrorV"))
00665                                    m_Doc->PDF_Options.MirrorV = static_cast<bool>(pg.attribute("MirrorV").toInt());
00666                             else
00667                                    m_Doc->PDF_Options.MirrorV = false;
00668                             if (pg.hasAttribute("RotateDeg"))
00669                                    m_Doc->PDF_Options.RotateDeg = pg.attribute("RotateDeg", "0").toInt();
00670                             else
00671                                    m_Doc->PDF_Options.RotateDeg = 0;
00672                             if (pg.hasAttribute("Clip"))
00673                                    m_Doc->PDF_Options.doClip = static_cast<bool>(pg.attribute("Clip").toInt());
00674                             else
00675                                    m_Doc->PDF_Options.doClip = false;
00676                             m_Doc->PDF_Options.PresentMode = static_cast<bool>(pg.attribute("PresentMode").toInt());
00677                             m_Doc->PDF_Options.PicRes = pg.attribute("PicRes").toInt();
00678                             // Fixme: check input pdf version
00679                             m_Doc->PDF_Options.Version = (PDFOptions::PDFVersion)pg.attribute("Version").toInt();
00680                             m_Doc->PDF_Options.Resolution = pg.attribute("Resolution").toInt();
00681                             m_Doc->PDF_Options.Binding = pg.attribute("Binding").toInt();
00682                             m_Doc->PDF_Options.Datei = "";
00683                             m_Doc->PDF_Options.isGrayscale = static_cast<bool>(pg.attribute("Grayscale", "0").toInt());
00684                             m_Doc->PDF_Options.UseRGB = static_cast<bool>(pg.attribute("RGBMode", "0").toInt());
00685                             m_Doc->PDF_Options.UseProfiles = static_cast<bool>(pg.attribute("UseProfiles", "0").toInt());
00686                             m_Doc->PDF_Options.UseProfiles2 = static_cast<bool>(pg.attribute("UseProfiles2", "0").toInt());
00687                             m_Doc->PDF_Options.Intent = pg.attribute("Intent", "1").toInt();
00688                             m_Doc->PDF_Options.Intent2 = pg.attribute("Intent2", "1").toInt();
00689                             m_Doc->PDF_Options.SolidProf = pg.attribute("SolidP", "");
00690                             m_Doc->PDF_Options.ImageProf = pg.attribute("ImageP", "");
00691                             m_Doc->PDF_Options.PrintProf = pg.attribute("PrintP", "");
00692                             m_Doc->PDF_Options.Info = pg.attribute("InfoString", "");
00693                             m_Doc->PDF_Options.bleeds.Top = pg.attribute("BTop", "0").toDouble();
00694                             m_Doc->PDF_Options.bleeds.Left = pg.attribute("BLeft", "0").toDouble();
00695                             m_Doc->PDF_Options.bleeds.Right = pg.attribute("BRight", "0").toDouble();
00696                             m_Doc->PDF_Options.bleeds.Bottom = pg.attribute("BBottom", "0").toDouble();
00697                             m_Doc->PDF_Options.useDocBleeds = static_cast<bool>(pg.attribute("useDocBleeds", "0").toInt());
00698                             m_Doc->PDF_Options.cropMarks = static_cast<bool>(pg.attribute("cropMarks", "0").toInt());
00699                             m_Doc->PDF_Options.bleedMarks = static_cast<bool>(pg.attribute("bleedMarks", "0").toInt());
00700                             m_Doc->PDF_Options.registrationMarks = static_cast<bool>(pg.attribute("registrationMarks", "0").toInt());
00701                             m_Doc->PDF_Options.colorMarks = static_cast<bool>(pg.attribute("colorMarks", "0").toInt());
00702                             m_Doc->PDF_Options.docInfoMarks = static_cast<bool>(pg.attribute("docInfoMarks", "0").toInt());
00703                             m_Doc->PDF_Options.markOffset = pg.attribute("markOffset", "0").toDouble();
00704                             m_Doc->PDF_Options.EmbeddedI = static_cast<bool>(pg.attribute("ImagePr", "0").toInt());
00705                             m_Doc->PDF_Options.PassOwner = pg.attribute("PassOwner", "");
00706                             m_Doc->PDF_Options.PassUser = pg.attribute("PassUser", "");
00707                             m_Doc->PDF_Options.Permissions = pg.attribute("Permissions", "-4").toInt();
00708                             m_Doc->PDF_Options.Encrypt = static_cast<bool>(pg.attribute("Encrypt", "0").toInt());
00709                             m_Doc->PDF_Options.useLayers = static_cast<bool>(pg.attribute("UseLayers", "0").toInt());
00710                             m_Doc->PDF_Options.UseLPI = static_cast<bool>(pg.attribute("UseLpi", "0").toInt());
00711                             m_Doc->PDF_Options.UseSpotColors = static_cast<bool>(pg.attribute("UseSpotColors", "1").toInt());
00712                             m_Doc->PDF_Options.doOverprint = static_cast<bool>(pg.attribute("doOverprint", "0").toInt());
00713                             m_Doc->PDF_Options.doMultiFile = static_cast<bool>(pg.attribute("doMultiFile", "0").toInt());
00714                             m_Doc->PDF_Options.displayBookmarks = static_cast<bool>(pg.attribute("displayBookmarks", "0").toInt());
00715                             m_Doc->PDF_Options.displayFullscreen = static_cast<bool>(pg.attribute("displayFullscreen", "0").toInt());
00716                             m_Doc->PDF_Options.displayLayers = static_cast<bool>(pg.attribute("displayLayers", "0").toInt());
00717                             m_Doc->PDF_Options.displayThumbs = static_cast<bool>(pg.attribute("displayThumbs", "0").toInt());
00718                             m_Doc->PDF_Options.hideMenuBar = static_cast<bool>(pg.attribute("hideMenuBar", "0").toInt());
00719                             m_Doc->PDF_Options.hideToolBar = static_cast<bool>(pg.attribute("hideToolBar", "0").toInt());
00720                             m_Doc->PDF_Options.fitWindow = static_cast<bool>(pg.attribute("fitWindow", "0").toInt());
00721                             m_Doc->PDF_Options.PageLayout = pg.attribute("PageLayout", "0").toInt();
00722                             m_Doc->PDF_Options.openAction = pg.attribute("openAction", "");
00723                             QDomNode PFO = PAGE.firstChild();
00724                             while(!PFO.isNull())
00725                             {
00726                                    QDomElement pdfF = PFO.toElement();
00727                                    if(pdfF.tagName() == "LPI")
00728                                    {
00729                                           struct LPIData lpo;
00730                                           lpo.Angle = pdfF.attribute("Angle").toInt();
00731                                           lpo.Frequency = pdfF.attribute("Frequency").toInt();
00732                                           lpo.SpotFunc = pdfF.attribute("SpotFunction").toInt();
00733                                           m_Doc->PDF_Options.LPISettings[pdfF.attribute("Color")] = lpo;
00734                                    }
00735                                    if(pdfF.tagName() == "Fonts")
00736                                    {
00737                                           if (!m_Doc->PDF_Options.EmbedList.contains(pdfF.attribute("Name")))
00738                                                  m_Doc->PDF_Options.EmbedList.append(pdfF.attribute("Name"));
00739                                    }
00740                                    if(pdfF.tagName() == "Subset")
00741                                    {
00742                                           if (!m_Doc->PDF_Options.SubsetList.contains(pdfF.attribute("Name")))
00743                                                  m_Doc->PDF_Options.SubsetList.append(pdfF.attribute("Name"));
00744                                    }
00745                                    if(pdfF.tagName() == "Effekte")
00746                                    {
00747                                           struct PDFPresentationData ef;
00748                                           ef.pageEffectDuration = pdfF.attribute("pageEffectDuration").toInt();
00749                                           ef.pageViewDuration = pdfF.attribute("pageViewDuration").toInt();
00750                                           ef.effectType = pdfF.attribute("effectType").toInt();
00751                                           ef.Dm = pdfF.attribute("Dm").toInt();
00752                                           ef.M = pdfF.attribute("M").toInt();
00753                                           ef.Di = pdfF.attribute("Di").toInt();
00754                                           m_Doc->PDF_Options.PresentVals.append(ef);
00755                                    }
00756                                    PFO = PFO.nextSibling();
00757                             }
00758                      }
00759                      if(pg.tagName()=="DocItemAttributes")
00760                      {
00761                             QDomNode DIA = PAGE.firstChild();
00762                             m_Doc->docItemAttributes.clear();
00763                             while(!DIA.isNull())
00764                             {
00765                                    QDomElement itemAttr = DIA.toElement();
00766                                    if(itemAttr.tagName() == "ItemAttribute")
00767                                    {
00768                                           ObjectAttribute objattr;
00769                                           objattr.name=itemAttr.attribute("Name");
00770                                           objattr.type=itemAttr.attribute("Type");
00771                                           objattr.value=itemAttr.attribute("Value");
00772                                           objattr.parameter=itemAttr.attribute("Parameter");
00773                                           objattr.relationship=itemAttr.attribute("Relationship");
00774                                           objattr.relationshipto=itemAttr.attribute("RelationshipTo");
00775                                           objattr.autoaddto=itemAttr.attribute("AutoAddTo");
00776                                           m_Doc->docItemAttributes.append(objattr);
00777                                    }
00778                                    DIA = DIA.nextSibling();
00779                             }
00780                      }
00781                      if(pg.tagName()=="TablesOfContents")
00782                      {
00783                             QDomNode TOC = PAGE.firstChild();
00784                             m_Doc->docToCSetups.clear();
00785                             while(!TOC.isNull())
00786                             {
00787                                    QDomElement tocElem = TOC.toElement();
00788                                    if(tocElem.tagName() == "TableOfContents")
00789                                    {
00790                                           ToCSetup tocsetup;
00791                                           tocsetup.name=tocElem.attribute("Name");
00792                                           tocsetup.itemAttrName=tocElem.attribute("ItemAttributeName");
00793                                           tocsetup.frameName=tocElem.attribute("FrameName");
00794                                           tocsetup.listNonPrintingFrames=tocElem.attribute("ListNonPrinting");
00795                                           tocsetup.textStyle=tocElem.attribute("Style");
00796                                           QString numberPlacement=tocElem.attribute("NumberPlacement");
00797                                           if (numberPlacement=="Beginning")
00798                                                  tocsetup.pageLocation=Beginning;
00799                                           if (numberPlacement=="End")
00800                                                  tocsetup.pageLocation=End;
00801                                           if (numberPlacement=="NotShown")
00802                                                  tocsetup.pageLocation=NotShown;
00803                                           m_Doc->docToCSetups.append(tocsetup);
00804                                    }
00805                                    TOC = TOC.nextSibling();
00806                             }
00807                      }
00808                      if(pg.tagName()=="Sections")
00809                      {
00810                             QDomNode Section = PAGE.firstChild();
00811                             while(!Section.isNull())
00812                             {
00813                                    QDomElement sectionElem = Section.toElement();
00814                                    if(sectionElem.tagName() == "Section")
00815                                    {
00816                                           struct DocumentSection newSection;
00817                                           newSection.number=sectionElem.attribute("Number").toInt();
00818                                           newSection.name=sectionElem.attribute("Name");
00819                                           newSection.fromindex=sectionElem.attribute("From").toInt();
00820                                           newSection.toindex=sectionElem.attribute("To").toInt();
00821                                           if (sectionElem.attribute("Type")=="Type_1_2_3")
00822                                                  newSection.type=Type_1_2_3;
00823                                           if (sectionElem.attribute("Type")=="Type_i_ii_iii")
00824                                                  newSection.type=Type_i_ii_iii;
00825                                           if (sectionElem.attribute("Type")=="Type_I_II_III")
00826                                                  newSection.type=Type_I_II_III;
00827                                           if (sectionElem.attribute("Type")=="Type_a_b_c")
00828                                                  newSection.type=Type_a_b_c;
00829                                           if (sectionElem.attribute("Type")=="Type_A_B_C")
00830                                                  newSection.type=Type_A_B_C;
00831                                           if (sectionElem.attribute("Type")=="Type_None")
00832                                                  newSection.type=Type_None;
00833                                           newSection.sectionstartindex=sectionElem.attribute("Start").toInt();
00834                                           newSection.reversed=static_cast<bool>(sectionElem.attribute("Reversed").toInt());
00835                                           newSection.active=static_cast<bool>(sectionElem.attribute("Active").toInt());
00836                                           m_Doc->sections.insert(newSection.number, newSection);
00837                                    }
00838                                    Section = Section.nextSibling();
00839                             }
00840                      }
00841                      if ((pg.tagName()=="PAGE") || (pg.tagName()=="MASTERPAGE"))
00842                      {
00843                             a = pg.attribute("NUM").toInt();
00844                             PgNam = "";
00845                             PgNam = pg.attribute("NAM", "");
00846                             //Pgc = m_Doc->pageCount;
00847                             //AtFl = m_Doc->usesAutomaticTextFrames();
00848                             if (PgNam.isEmpty())
00849                             {
00850                                    //m_Doc->pageCount = Pgc;
00851                                    //m_Doc->Pages = &m_Doc->DocPages;
00852                                    //m_Doc->setUsesAutomaticTextFrames(AtFl);
00853                                    m_Doc->setMasterPageMode(false);
00854                             }
00855                             else
00856                             {
00857                                    //m_Doc->pageCount = 0;
00858                                    //m_Doc->setUsesAutomaticTextFrames(false);
00859                                    //m_Doc->Pages = &m_Doc->MasterPages;
00860                                    m_Doc->setMasterPageMode(true);
00861                             }
00862                             //CB: Stop calling damn GUI code in loading docs! IT doesnt *look* like
00863                             //this makes a difference apart from being faster, of course.
00864                             //ScMW->slotNewPage(a);
00865                             //Apage = m_Doc->Pages.at(a);
00866                             if (PgNam.isEmpty())
00867                             {
00868                                    Apage = m_Doc->addPage(a);
00869                                    //m_Doc->DocPages = m_Doc->Pages;
00870                                    //++m_Doc->pageCount;
00871                             }
00872                             else
00873                             {
00874                                    Apage = m_Doc->addMasterPage(a, PgNam);
00875                                    //Apage->setPageName(PgNam);
00876                                    //m_Doc->MasterNames[PgNam] = a;
00877                                    //m_Doc->MasterPages = m_Doc->Pages;
00878                                    //m_Doc->pageCount = Pgc;
00879                             }
00880                             //m_Doc->setUsesAutomaticTextFrames(AtFl);
00881                             Apage->LeftPg=pg.attribute("LEFT", "0").toInt();
00882                             QString Mus = "";
00883                             Mus = pg.attribute("MNAM","Normal");
00884                             if (!m_Doc->masterPageMode())
00885                                    Apage->MPageNam = Mus;
00886                             else
00887                                    Apage->MPageNam = "";
00888                             if (pg.hasAttribute("Size"))
00889                                    Apage->m_pageSize = pg.attribute("Size");
00890                             if (pg.hasAttribute("Orientation"))
00891                                    Apage->PageOri = pg.attribute("Orientation").toInt();
00892                             Apage->setXOffset(pg.attribute("PAGEXPOS").toDouble());
00893                             Apage->setYOffset(pg.attribute("PAGEYPOS").toDouble());
00894                             if (pg.hasAttribute("PAGEWIDTH"))
00895                                    Apage->setWidth(pg.attribute("PAGEWIDTH").toDouble());
00896                             else
00897                                    Apage->setWidth(pg.attribute("PAGEWITH").toDouble());
00898                             Apage->setHeight(pg.attribute("PAGEHEIGHT").toDouble());
00899                             Apage->setInitialHeight(Apage->height());
00900                             Apage->setInitialWidth(Apage->width());
00901                             Apage->initialMargins.Top = QMAX(0.0, pg.attribute("BORDERTOP").toDouble());
00902                             Apage->initialMargins.Bottom = QMAX(0.0, pg.attribute("BORDERBOTTOM").toDouble());
00903                             Apage->initialMargins.Left = QMAX(0.0, pg.attribute("BORDERLEFT").toDouble());
00904                             Apage->initialMargins.Right = QMAX(0.0, pg.attribute("BORDERRIGHT").toDouble());
00905                             Apage->Margins.Top = Apage->initialMargins.Top;
00906                             Apage->Margins.Bottom = Apage->initialMargins.Bottom;
00907                             m_Doc->setMasterPageMode(false);
00908                             //m_Doc->Pages=&m_Doc->DocPages;
00909                             // guides reading
00910                             tmp = "";
00911                             Apage->guides.setHorizontalAutoGap(pg.attribute("AGhorizontalAutoGap", "0.0").toDouble());
00912                             Apage->guides.setVerticalAutoGap(pg.attribute("AGverticalAutoGap", "0.0").toDouble());
00913                             Apage->guides.setHorizontalAutoCount(pg.attribute("AGhorizontalAutoCount", "0").toInt());
00914                             Apage->guides.setVerticalAutoCount(pg.attribute("AGverticalAutoCount", "0").toInt());
00915                             Apage->guides.setHorizontalAutoRefer(pg.attribute("AGhorizontalAutoRefer", "0").toInt());
00916                             Apage->guides.setVerticalAutoRefer(pg.attribute("AGverticalAutoRefer", "0").toInt());
00917                             GuideManagerIO::readVerticalGuides(pg.attribute("VerticalGuides"),
00918                                           Apage,
00919                                           GuideManagerCore::Standard,
00920                                           pg.hasAttribute("NumVGuides"));
00921                             GuideManagerIO::readHorizontalGuides(pg.attribute("HorizontalGuides"),
00922                                           Apage,
00923                                           GuideManagerCore::Standard,
00924                                           pg.hasAttribute("NumHGuides"));
00925                             GuideManagerIO::readSelection(pg.attribute("AGSelection"), Apage);
00926                             
00927                      }
00928                      if ((pg.tagName()=="PAGEOBJECT") || (pg.tagName()=="MASTEROBJECT") || (pg.tagName()=="FRAMEOBJECT"))
00929                      {
00930                                    if ((pg.tagName()=="PAGEOBJECT") || (pg.tagName()=="FRAMEOBJECT"))
00931                                    {
00932                                           //m_Doc->Items = m_Doc->DocItems;
00933                                           //m_Doc->Pages = &m_Doc->DocPages;
00934                                           m_Doc->setMasterPageMode(false);
00935                                    }
00936                                    else
00937                                    {
00938                                           //m_Doc->Items = m_Doc->MasterItems;
00939                                           //m_Doc->Pages = &m_Doc->MasterPages;
00940                                           m_Doc->setMasterPageMode(true);
00941                                    }
00942                                    if ((!pg.attribute("OnMasterPage").isEmpty()) && (pg.tagName()=="MASTEROBJECT"))
00943                                           m_Doc->setCurrentPage(m_Doc->MasterPages.at(m_Doc->MasterNames[pg.attribute("OnMasterPage")]));
00944                                    int docGc = m_Doc->GroupCounter;
00945                                    m_Doc->GroupCounter = 0;
00946                                    Neu = PasteItem(&pg, m_Doc);
00947                                    Neu->setRedrawBounding();
00948                                    if (pg.tagName()=="MASTEROBJECT")
00949                                           Neu->OwnPage = m_Doc->OnPage(Neu);
00950                                    else
00951                                           Neu->OwnPage = pg.attribute("OwnPage").toInt();
00952                                    if (pg.tagName()=="PAGEOBJECT")
00953                                           Neu->OnMasterPage = "";
00954                                    m_Doc->GroupCounter = docGc;
00955                                    tmpf = pg.attribute("IFONT", m_Doc->toolSettings.defFont);
00956                                    m_AvailableFonts->findFont(tmpf, m_Doc);
00957                                    QDomNode IT=pg.firstChild();
00958                                    LastStyles * last = new LastStyles();
00959                                    while(!IT.isNull())
00960                                    {
00961                                           QDomElement it=IT.toElement();
00962                                           if (it.tagName()=="CSTOP")
00963                                           {
00964                                                  QString name = it.attribute("NAME");
00965                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
00966                                                  int shade = it.attribute("SHADE", "100").toInt();
00967                                                  double opa = it.attribute("TRANS", "1").toDouble();
00968                                                  Neu->fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
00969                                           }
00970                                           if (it.tagName()=="ITEXT") {
00971                                                  GetItemText(&it, m_Doc, Neu, last);
00972                                           }
00973                                           else if (it.tagName()=="para") {
00974                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PARSEP);
00975                                                  ParagraphStyle newStyle;
00976                                                  PrefsManager* prefsManager=PrefsManager::instance();
00977                                                  readParagraphStyle(newStyle, it, prefsManager->appPrefs.AvailFonts, m_Doc);
00978                                                  Neu->itemText.setStyle(Neu->itemText.length()-1, newStyle);
00979                                                  Neu->itemText.setCharStyle(Neu->itemText.length()-1, 1, last->Style);
00980                                           }
00981                                           else if (it.tagName()=="tab") {
00982                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::TAB);
00983                                           }
00984                                           else if (it.tagName()=="breakline") {
00985                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::LINEBREAK);
00986                                           }
00987                                           else if (it.tagName()=="breakcol") {
00988                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::COLBREAK);
00989                                           }
00990                                           else if (it.tagName()=="breakframe") {
00991                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::FRAMEBREAK);
00992                                           }
00993                                           else if (it.tagName()=="var" && it.attribute("name")=="pgno") 
00994                                           {
00995                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PAGENUMBER);
00996                                           }
00997 
00998                                           //CB PageItemAttributes
00999                                           if(it.tagName()=="PageItemAttributes")
01000                                           {
01001                                                  QDomNode PIA = it.firstChild();
01002                                                  ObjAttrVector pageItemAttributes;
01003                                                  while(!PIA.isNull())
01004                                                  {
01005                                                         QDomElement itemAttr = PIA.toElement();
01006                                                         if(itemAttr.tagName() == "ItemAttribute")
01007                                                         {
01008                                                                ObjectAttribute objattr;
01009                                                                objattr.name=itemAttr.attribute("Name");
01010                                                                objattr.type=itemAttr.attribute("Type");
01011                                                                objattr.value=itemAttr.attribute("Value");
01012                                                                objattr.parameter=itemAttr.attribute("Parameter");
01013                                                                objattr.relationship=itemAttr.attribute("Relationship");
01014                                                                objattr.relationshipto=itemAttr.attribute("RelationshipTo");
01015                                                                objattr.autoaddto=itemAttr.attribute("AutoAddTo");
01016                                                                pageItemAttributes.append(objattr);
01017                                                         }
01018                                                         PIA = PIA.nextSibling();
01019                                                  }
01020                                                  Neu->setObjectAttributes(&pageItemAttributes);
01021                                           }
01022                                           IT=IT.nextSibling();
01023                                    }
01024                                    if (Neu->asTextFrame())
01025                                    {
01026 /*
01027  QString dbg("");
01028                                           for (int i=0; i < Neu->itemText.length(); ++i)
01029                                           {
01030                                                  dbg += Neu->itemText.text(i,1);
01031                                                  if (Neu->itemText.item(i)->effects() & ScStyle_HyphenationPossible)
01032                                                         dbg += "~";
01033                                           }
01034                                           qDebug("scribus134format: read itemtext '%s'", dbg.latin1());
01035 */                                 }
01036                                    if (Neu->asPathText())
01037                                    {
01038                                           Neu->updatePolyClip();
01039                                           Neu->Frame = true;
01040                                    }
01041                                    delete last;
01042                                    if (Neu->fill_gradient.Stops() == 0)
01043                                    {
01044                                           const ScColor& col1 = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
01045                                           const ScColor& col2 = m_Doc->PageColors[m_Doc->toolSettings.dPen];
01046                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
01047                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
01048                                    }
01049 //                                 Neu->Language = ScMW->GetLang(pg.attribute("LANGUAGE", m_Doc->Language));
01050                                    Neu->isAutoText = static_cast<bool>(pg.attribute("AUTOTEXT").toInt());
01051                                    Neu->isEmbedded = static_cast<bool>(pg.attribute("isInline", "0").toInt());
01052                                    Neu->gXpos = pg.attribute("gXpos", "0.0").toDouble();
01053                                    Neu->gYpos = pg.attribute("gYpos", "0.0").toDouble();
01054                                    QString defaultVal;
01055                                    defaultVal.setNum(Neu->width());
01056                                    Neu->gWidth = pg.attribute("gWidth",defaultVal).toDouble();
01057                                    defaultVal.setNum(Neu->height());
01058                                    Neu->gHeight = pg.attribute("gHeight",defaultVal).toDouble();
01059                                    if (Neu->isAutoText)
01060                                           m_Doc->LastAuto = Neu;
01061                                    // first of linked chain?
01062                                    if (pg.tagName()=="PAGEOBJECT")
01063                                    {
01064                                           if (pg.attribute("NEXTITEM").toInt() != -1)
01065                                                  itemNext[Neu->ItemNr] = pg.attribute("NEXTITEM").toInt();
01066                                    }
01067                                    else if (pg.tagName()=="MASTEROBJECT")
01068                                    {
01069                                           if (pg.attribute("NEXTITEM").toInt() != -1)
01070                                                  itemNextM[Neu->ItemNr] = pg.attribute("NEXTITEM").toInt();
01071                                    }
01072                                    /* not sure if we want that...
01073                                    else if (pg.tagName()=="FRAMEOBJECT")
01074                                    {
01075                                           if (pg.attribute("NEXTITEM").toInt() != -1)
01076                                                  itemNextF[Neu->ItemNr] = pg.attribute("NEXTITEM").toInt();
01077                                    }*/
01078 
01079                                    if (pg.tagName()=="FRAMEOBJECT")
01080                                    {
01081                                           m_Doc->FrameItems.append(m_Doc->Items->take(Neu->ItemNr));
01082                                           Neu->ItemNr = m_Doc->FrameItems.count()-1;
01083                                    }
01084                                    if (Neu->isTableItem)
01085                                    {
01086                                           if (pg.tagName()=="PAGEOBJECT")
01087                                           {
01088                                                  TableItems.append(Neu);
01089                                                  TableID.insert(pg.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
01090                                           }
01091                                           else if (pg.tagName()=="FRAMEOBJECT")
01092                                           {
01093                                                  TableItemsF.append(Neu);
01094                                                  TableIDF.insert(pg.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
01095                                           }
01096                                           else
01097                                           {
01098                                                  TableItemsM.append(Neu);
01099                                                  TableIDM.insert(pg.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
01100                                           }
01101                                    }
01102                                    Neu->isGroupControl = static_cast<bool>(pg.attribute("isGroupControl", "0").toInt());
01103                                    if (Neu->isGroupControl)
01104                                    {
01105                                           if (Neu->Groups.count() == 0) // Sanity check for some broken files created using buggy development versions.
01106                                           {
01107                                                  Neu->isGroupControl = false;
01108                                                  Neu->setFillColor("None");
01109                                           }
01110                                           else
01111                                           {
01112                                                  if (pg.tagName()=="PAGEOBJECT")
01113                                                         groupID.insert(Neu, pg.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
01114                                                  else if (pg.tagName()=="FRAMEOBJECT")
01115                                                         groupIDF.insert(Neu, pg.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
01116                                                  else
01117                                                         groupIDM.insert(Neu, pg.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
01118                                           }
01119                                    }
01120                                    m_Doc->setMasterPageMode(false);
01121                                    counter++;
01122                             }
01123                      PAGE=PAGE.nextSibling();
01124               }
01125               PAGE=DOC.firstChild();
01126               while(!PAGE.isNull())
01127               {
01128                      QDomElement pg=PAGE.toElement();
01129                      if(pg.tagName()=="Bookmark")
01130                      {
01131                             uint elem = pg.attribute("Element").toInt();
01132                             if (elem < m_Doc->Items->count())
01133                             {
01134                                    bok.Title = pg.attribute("Title");
01135                                    bok.Text = pg.attribute("Text");
01136                                    bok.Aktion = pg.attribute("Aktion");
01137                                    bok.ItemNr = pg.attribute("ItemNr").toInt();
01138                                    bok.PageObject = m_Doc->Items->at(elem);
01139                                    bok.First = pg.attribute("First").toInt();
01140                                    bok.Last = pg.attribute("Last").toInt();
01141                                    bok.Prev = pg.attribute("Prev").toInt();
01142                                    bok.Next = pg.attribute("Next").toInt();
01143                                    bok.Parent = pg.attribute("Parent").toInt();
01144                                    m_Doc->BookMarks.append(bok);
01145                             }
01146                      }
01147                      if(pg.tagName()=="Pattern")
01148                      {
01149                             QMap<PageItem*, int> groupID2;
01150                             QMap<int,int> TableID2;
01151                             QPtrList<PageItem> TableItems2;
01152                             ScPattern pat;
01153                             QDomNode pa = PAGE.firstChild();
01154                             uint ac = m_Doc->Items->count();
01155                             bool savedAlignGrid = m_Doc->useRaster;
01156                             bool savedAlignGuides = m_Doc->SnapGuides;
01157                             m_Doc->useRaster = false;
01158                             m_Doc->SnapGuides = false;
01159                             while(!pa.isNull())
01160                             {
01161                                    QDomElement pite = pa.toElement();
01162                                    m_Doc->setMasterPageMode(false);
01163                                    int docGc = m_Doc->GroupCounter;
01164                                    m_Doc->GroupCounter = 0;
01165                                    Neu = PasteItem(&pite, m_Doc);
01166                                    Neu->setRedrawBounding();
01167                                    Neu->OwnPage = pite.attribute("OwnPage").toInt();
01168                                    Neu->OnMasterPage = "";
01169                                    m_Doc->GroupCounter = docGc;
01170                                    tmpf = pite.attribute("IFONT", m_Doc->toolSettings.defFont);
01171                                    m_AvailableFonts->findFont(tmpf, m_Doc);
01172                                    QDomNode IT=pite.firstChild();
01173                                    LastStyles * last = new LastStyles();
01174                                    while(!IT.isNull())
01175                                    {
01176                                           QDomElement it=IT.toElement();
01177                                           if (it.tagName()=="CSTOP")
01178                                           {
01179                                                  QString name = it.attribute("NAME");
01180                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
01181                                                  int shade = it.attribute("SHADE", "100").toInt();
01182                                                  double opa = it.attribute("TRANS", "1").toDouble();
01183                                                  Neu->fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
01184                                           }
01185                                           if (it.tagName()=="ITEXT")
01186                                                  GetItemText(&it, m_Doc, Neu, last);
01187                                           else if (it.tagName()=="para") {
01188                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PARSEP);
01189                                                  ParagraphStyle newStyle;
01190                                                  PrefsManager* prefsManager=PrefsManager::instance();
01191                                                  readParagraphStyle(newStyle, it, prefsManager->appPrefs.AvailFonts, m_Doc);
01192                                                  Neu->itemText.setStyle(Neu->itemText.length()-1, newStyle);
01193                                                  Neu->itemText.setCharStyle(Neu->itemText.length()-1, 1, last->Style);
01194                                           }
01195                                           else if (it.tagName()=="tab") {
01196                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::TAB);
01197                                           }
01198                                           else if (it.tagName()=="breakline") {
01199                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::LINEBREAK);
01200                                           }
01201                                           else if (it.tagName()=="breakcol") {
01202                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::COLBREAK);
01203                                           }
01204                                           else if (it.tagName()=="breakframe") {
01205                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::FRAMEBREAK);
01206                                           }
01207                                           else if (it.tagName()=="var" && it.attribute("name")=="pgno") 
01208                                           {
01209                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PAGENUMBER);
01210                                           }
01211                                           
01212                                           if(it.tagName()=="PageItemAttributes")
01213                                           {
01214                                                  QDomNode PIA = it.firstChild();
01215                                                  ObjAttrVector pageItemAttributes;
01216                                                  while(!PIA.isNull())
01217                                                  {
01218                                                         QDomElement itemAttr = PIA.toElement();
01219                                                         if(itemAttr.tagName() == "ItemAttribute")
01220                                                         {
01221                                                                ObjectAttribute objattr;
01222                                                                objattr.name=itemAttr.attribute("Name");
01223                                                                objattr.type=itemAttr.attribute("Type");
01224                                                                objattr.value=itemAttr.attribute("Value");
01225                                                                objattr.parameter=itemAttr.attribute("Parameter");
01226                                                                objattr.relationship=itemAttr.attribute("Relationship");
01227                                                                objattr.relationshipto=itemAttr.attribute("RelationshipTo");
01228                                                                objattr.autoaddto=itemAttr.attribute("AutoAddTo");
01229                                                                pageItemAttributes.append(objattr);
01230                                                         }
01231                                                         PIA = PIA.nextSibling();
01232                                                  }
01233                                                  Neu->setObjectAttributes(&pageItemAttributes);
01234                                           }
01235                                           IT=IT.nextSibling();
01236                                    }
01237                                    delete last;
01238                                    if (Neu->asPathText())
01239                                    {
01240                                           Neu->updatePolyClip();
01241                                           Neu->Frame = true;
01242                                    }
01243                                    if (Neu->fill_gradient.Stops() == 0)
01244                                    {
01245                                           const ScColor& col1 = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
01246                                           const ScColor& col2 = m_Doc->PageColors[m_Doc->toolSettings.dPen];
01247                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
01248                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
01249                                    }
01250                                    Neu->isAutoText = static_cast<bool>(pite.attribute("AUTOTEXT").toInt());
01251                                    Neu->isEmbedded = static_cast<bool>(pite.attribute("isInline", "0").toInt());
01252                                    Neu->gXpos = pite.attribute("gXpos", "0.0").toDouble();
01253                                    Neu->gYpos = pite.attribute("gYpos", "0.0").toDouble();
01254                                    QString defaultVal;
01255                                    defaultVal.setNum(Neu->width());
01256                                    Neu->gWidth = pite.attribute("gWidth",defaultVal).toDouble();
01257                                    defaultVal.setNum(Neu->height());
01258                                    Neu->gHeight = pite.attribute("gHeight",defaultVal).toDouble();
01259                                    if (Neu->isTableItem)
01260                                    {
01261                                           TableItems2.append(Neu);
01262                                           TableID2.insert(pite.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
01263                                    }
01264                                    Neu->isGroupControl = static_cast<bool>(pite.attribute("isGroupControl", "0").toInt());
01265                                    if (Neu->isGroupControl)
01266                                    {
01267                                           if (Neu->Groups.count() == 0) // Sanity check for some broken files created using buggy development versions.
01268                                           {
01269                                                  Neu->isGroupControl = false;
01270                                                  Neu->setFillColor("None");
01271                                           }
01272                                           else
01273                                                  groupID2.insert(Neu, pite.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
01274                                    }
01275                                    pa = pa.nextSibling();
01276                             }
01277                             if (groupID2.count() != 0)
01278                             {
01279                                    QMap<PageItem*, int>::Iterator it;
01280                                    for (it = groupID2.begin(); it != groupID2.end(); ++it)
01281                                    {
01282                                           it.key()->groupsLastItem = m_Doc->Items->at(it.data());
01283                                    }
01284                             }
01285                             if (TableItems2.count() != 0)
01286                             {
01287                                    for (uint ttc = 0; ttc < TableItems2.count(); ++ttc)
01288                                    {
01289                                           PageItem* ta = TableItems2.at(ttc);
01290                                           if (ta->TopLinkID != -1)
01291                                                  ta->TopLink = m_Doc->Items->at(TableID2[ta->TopLinkID]);
01292                                           else
01293                                                  ta->TopLink = 0;
01294                                           if (ta->LeftLinkID != -1)
01295                                                  ta->LeftLink = m_Doc->Items->at(TableID2[ta->LeftLinkID]);
01296                                           else
01297                                                  ta->LeftLink = 0;
01298                                           if (ta->RightLinkID != -1)
01299                                                  ta->RightLink = m_Doc->Items->at(TableID2[ta->RightLinkID]);
01300                                           else
01301                                                  ta->RightLink = 0;
01302                                           if (ta->BottomLinkID != -1)
01303                                                  ta->BottomLink = m_Doc->Items->at(TableID2[ta->BottomLinkID]);
01304                                           else
01305                                                  ta->BottomLink = 0;
01306                                    }
01307                             }
01308                             m_Doc->useRaster = savedAlignGrid;
01309                             m_Doc->SnapGuides = savedAlignGuides;
01310                             uint ae = m_Doc->Items->count();
01311                             pat.setDoc(m_Doc);
01312                             PageItem* currItem = m_Doc->Items->at(ac);
01313                             pat.pattern = currItem->DrawObj_toImage();
01314                             for (uint as = ac; as < ae; ++as)
01315                             {
01316                                    Neu = m_Doc->Items->take(ac);
01317                                    Neu->ItemNr = pat.items.count();
01318                                    pat.items.append(Neu);
01319                             }
01320                             pat.width = pg.attribute("width", "0").toDouble();
01321                             pat.height = pg.attribute("height", "0").toDouble();
01322                             pat.scaleX = pg.attribute("scaleX", "0").toDouble();
01323                             pat.scaleY = pg.attribute("scaleY", "0").toDouble();
01324                             m_Doc->docPatterns.insert(pg.attribute("Name"), pat);
01325                      }
01326                      PAGE=PAGE.nextSibling();
01327               }
01328               DOC=DOC.nextSibling();
01329        }
01330        if (TableItemsF.count() != 0)
01331        {
01332               for (uint ttc = 0; ttc < TableItemsF.count(); ++ttc)
01333               {
01334                      PageItem* ta = TableItemsF.at(ttc);
01335                      if (ta->TopLinkID != -1)
01336                             ta->TopLink = m_Doc->FrameItems.at(TableIDF[ta->TopLinkID]);
01337                      else
01338                             ta->TopLink = 0;
01339                      if (ta->LeftLinkID != -1)
01340                             ta->LeftLink = m_Doc->FrameItems.at(TableIDF[ta->LeftLinkID]);
01341                      else
01342                             ta->LeftLink = 0;
01343                      if (ta->RightLinkID != -1)
01344                             ta->RightLink = m_Doc->FrameItems.at(TableIDF[ta->RightLinkID]);
01345                      else
01346                             ta->RightLink = 0;
01347                      if (ta->BottomLinkID != -1)
01348                             ta->BottomLink = m_Doc->FrameItems.at(TableIDF[ta->BottomLinkID]);
01349                      else
01350                             ta->BottomLink = 0;
01351               }
01352        }
01353        if (TableItemsM.count() != 0)
01354        {
01355               for (uint ttc = 0; ttc < TableItemsM.count(); ++ttc)
01356               {
01357                      PageItem* ta = TableItemsM.at(ttc);
01358                      if (ta->TopLinkID != -1)
01359                             ta->TopLink = m_Doc->MasterItems.at(TableIDM[ta->TopLinkID]);
01360                      else
01361                             ta->TopLink = 0;
01362                      if (ta->LeftLinkID != -1)
01363                             ta->LeftLink = m_Doc->MasterItems.at(TableIDM[ta->LeftLinkID]);
01364                      else
01365                             ta->LeftLink = 0;
01366                      if (ta->RightLinkID != -1)
01367                             ta->RightLink = m_Doc->MasterItems.at(TableIDM[ta->RightLinkID]);
01368                      else
01369                             ta->RightLink = 0;
01370                      if (ta->BottomLinkID != -1)
01371                             ta->BottomLink = m_Doc->MasterItems.at(TableIDM[ta->BottomLinkID]);
01372                      else
01373                             ta->BottomLink = 0;
01374               }
01375        }
01376        if (TableItems.count() != 0)
01377        {
01378               for (uint ttc = 0; ttc < TableItems.count(); ++ttc)
01379               {
01380                      PageItem* ta = TableItems.at(ttc);
01381                      if (ta->TopLinkID != -1)
01382                             ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
01383                      else
01384                             ta->TopLink = 0;
01385                      if (ta->LeftLinkID != -1)
01386                             ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
01387                      else
01388                             ta->LeftLink = 0;
01389                      if (ta->RightLinkID != -1)
01390                             ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
01391                      else
01392                             ta->RightLink = 0;
01393                      if (ta->BottomLinkID != -1)
01394                             ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
01395                      else
01396                             ta->BottomLink = 0;
01397               }
01398        }
01399        if (groupIDF.count() != 0)
01400        {
01401               QMap<PageItem*, int>::Iterator it;
01402               for (it = groupIDF.begin(); it != groupIDF.end(); ++it)
01403               {
01404                      it.key()->groupsLastItem = m_Doc->FrameItems.at(it.data());
01405               }
01406        }
01407        if (groupID.count() != 0)
01408        {
01409               QMap<PageItem*, int>::Iterator it;
01410               for (it = groupID.begin(); it != groupID.end(); ++it)
01411               {
01412                      it.key()->groupsLastItem = m_Doc->DocItems.at(it.data());
01413               }
01414        }
01415        if (groupIDM.count() != 0)
01416        {
01417               QMap<PageItem*, int>::Iterator it;
01418               for (it = groupIDM.begin(); it != groupIDM.end(); ++it)
01419               {
01420                      it.key()->groupsLastItem = m_Doc->MasterItems.at(it.data());
01421               }
01422        }
01423        m_Doc->setActiveLayer(layerToSetActive);
01424        m_Doc->setMasterPageMode(false);
01425        m_Doc->reformPages();
01426 
01427        if (m_Doc->Layers.count() == 0)
01428        {
01429               la.LNr = 0;
01430               la.Level = 0;
01431               la.Name = QObject::tr("Background");
01432               la.isViewable = true;
01433               la.isPrintable = true;
01434               la.isEditable = true;
01435               la.flowControl = true;
01436               la.transparency = 1.0;
01437               la.blendMode = 0;
01438               la.markerColor = QColor(0, 0, 0);
01439               la.outlineMode = false;
01440               m_Doc->Layers.append(la);
01441        }
01442 
01443        // reestablish textframe links
01444        if (itemNext.count() != 0)
01445        {
01446               QMap<int,int>::Iterator lc;
01447               for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
01448               {
01449                      if (lc.data() >= 0)
01450                      {
01451                             PageItem * Its = m_Doc->DocItems.at(lc.key());
01452                             PageItem * Itn = m_Doc->DocItems.at(lc.data());
01453                             if (Itn->prevInChain() || Its->nextInChain()) 
01454                             {
01455                                    qDebug("scribus134format: corruption in linked textframes detected");
01456                                    continue;
01457                             }
01458                             Its->link(Itn);
01459                      }
01460               }
01461        }
01462        
01463        if (itemNextM.count() != 0)
01464        {
01465               QMap<int,int>::Iterator lc;
01466               for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
01467               {
01468                      if (lc.data() >= 0)
01469                      {
01470                             PageItem * Its = m_Doc->MasterItems.at(lc.key());
01471                             PageItem * Itn = m_Doc->MasterItems.at(lc.data());
01472                             if (Itn->prevInChain() || Its->nextInChain()) 
01473                             {
01474                                    qDebug("scribus134format: corruption in linked textframes detected");
01475                                    continue;
01476                             }
01477                             Its->link(Itn);
01478                      }
01479               }
01480        }
01481        
01482        // reestablish first/lastAuto
01483        m_Doc->FirstAuto = m_Doc->LastAuto;
01484        if (m_Doc->LastAuto)
01485        {
01486               while (m_Doc->LastAuto->nextInChain())
01487                      m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
01488               while (m_Doc->FirstAuto->prevInChain())
01489                      m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
01490        }
01491        
01492        if (m_mwProgressBar!=0)
01493               m_mwProgressBar->setProgress(DOC.childNodes().count());
01494        return true;
01495 //     return false;
01496 }
01497 
01498 
01499 // Low level plugin API
01500 int scribus134format_getPluginAPIVersion()
01501 {
01502        return PLUGIN_API_VERSION;
01503 }
01504 
01505 ScPlugin* scribus134format_getPlugin()
01506 {
01507        Scribus134Format* plug = new Scribus134Format();
01508        Q_CHECK_PTR(plug);
01509        return plug;
01510 }
01511 
01512 void scribus134format_freePlugin(ScPlugin* plugin)
01513 {
01514        Scribus134Format* plug = dynamic_cast<Scribus134Format*>(plugin);
01515        Q_ASSERT(plug);
01516        delete plug;
01517 }
01518 
01519 
01520 namespace {
01521        const int NOVALUE = -16000;
01522        
01523        void fixLegacyCharStyle(CharStyle& cstyle) 
01524        {
01525               if (! cstyle.font().usable())
01526                      cstyle.resetFont();
01527               if (cstyle.fontSize() <= -16000 / 10)
01528                      cstyle.resetFontSize();
01529 //            if (cstyle.effects() == 65535)
01530 //                   cstyle.resetEffects();
01531               if (cstyle.fillColor().isEmpty())
01532                      cstyle.resetFillColor();
01533               if (cstyle.fillShade() <= -16000)
01534                      cstyle.resetFillShade();
01535               if (cstyle.strokeColor().isEmpty())
01536                      cstyle.resetStrokeColor();
01537               if (cstyle.strokeShade() <= -16000)
01538                      cstyle.resetStrokeShade();
01539               if (cstyle.shadowXOffset() <= -16000 / 10)
01540                      cstyle.resetShadowXOffset();
01541               if (cstyle.shadowYOffset() <= -16000 / 10)
01542                      cstyle.resetShadowYOffset();
01543               if (cstyle.outlineWidth() <= -16000 / 10)
01544                      cstyle.resetOutlineWidth();
01545               if (cstyle.underlineOffset() <= -16000 / 10)
01546                      cstyle.resetUnderlineOffset();
01547               if (cstyle.underlineWidth() <= -16000 / 10)
01548                      cstyle.resetUnderlineWidth();
01549               if (cstyle.strikethruOffset() <= -16000 / 10)
01550                      cstyle.resetStrikethruOffset();
01551               if (cstyle.strikethruWidth() <= -16000 / 10)
01552                      cstyle.resetStrikethruWidth();
01553               if (cstyle.scaleH() <= -16000 / 10)
01554                      cstyle.resetScaleH();
01555               if (cstyle.scaleV() <= -16000 / 10)
01556                      cstyle.resetScaleV();
01557               if (cstyle.baselineOffset() <= -16000 / 10)
01558                      cstyle.resetBaselineOffset();
01559               if (cstyle.tracking() <= -16000 / 10)
01560                      cstyle.resetTracking();
01561        }
01562        
01563        void fixLegacyParStyle(ParagraphStyle& pstyle) 
01564        {
01565               if (pstyle.lineSpacing() <= -16000)
01566                      pstyle.resetLineSpacing();
01567               if (pstyle.leftMargin() <= -16000)
01568                      pstyle.resetLeftMargin();
01569               if (pstyle.rightMargin() <= -16000)
01570                      pstyle.resetRightMargin();
01571               if (pstyle.firstIndent() <= -16000)
01572                      pstyle.resetFirstIndent();
01573               if (pstyle.alignment() < 0)
01574                      pstyle.resetAlignment();
01575               if (pstyle.gapBefore() <= -16000)
01576                      pstyle.resetGapBefore();
01577               if (pstyle.gapAfter() <= -16000)
01578                      pstyle.resetGapAfter();
01579               if (pstyle.dropCapLines() < 0)
01580                      pstyle.resetDropCapLines();
01581               if (pstyle.dropCapOffset() <= -16000)
01582                      pstyle.resetDropCapOffset();
01583               fixLegacyCharStyle(pstyle.charStyle());
01584        }
01585        
01586 }// namespace
01587 
01588 
01589 void Scribus134Format::GetCStyle(const QDomElement *it, ScribusDoc *doc, CharStyle & newStyle)
01590 {
01591        if (it->hasAttribute("CNAME"))
01592               newStyle.setName(it->attribute("CNAME"));
01593        if (it->hasAttribute("CPARENT"))
01594               newStyle.setParent(it->attribute("CPARENT"));
01595        
01596        if (it->hasAttribute("FONT"))
01597               newStyle.setFont(m_AvailableFonts->findFont(it->attribute("FONT"),doc));
01598        
01599        if (it->hasAttribute("FONTSIZE"))
01600               newStyle.setFontSize(qRound(it->attribute("FONTSIZE").toDouble() * 10));
01601        
01602        if (it->hasAttribute("FCOLOR"))
01603               newStyle.setFillColor(it->attribute("FCOLOR"));
01604        
01605        if (it->hasAttribute("KERN"))
01606               newStyle.setTracking(qRound(it->attribute("KERN").toDouble() * 10));
01607        
01608        if (it->hasAttribute("FSHADE"))
01609               newStyle.setFillShade(it->attribute("FSHADE").toInt());
01610        
01611        if (it->hasAttribute("EFFECTS"))
01612               newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("EFFECTS").toInt()).featureList());
01613        
01614        if (it->hasAttribute("EFFECT"))
01615               newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("EFFECT").toInt()).featureList());
01616        
01617        if (it->hasAttribute("FEATURES"))
01618               newStyle.setFeatures(QStringList::split( " ", it->attribute("FEATURES")));
01619        
01620        if (it->hasAttribute("SCOLOR"))
01621               newStyle.setStrokeColor(it->attribute("SCOLOR", CommonStrings::None));
01622        
01623        if (it->hasAttribute("SSHADE"))
01624               newStyle.setStrokeShade(it->attribute("SSHADE").toInt());
01625        
01626        if (it->hasAttribute("SCALEH"))
01627               newStyle.setScaleH(qRound(it->attribute("SCALEH").toDouble() * 10));
01628        
01629        if (it->hasAttribute("SCALEV"))
01630               newStyle.setScaleV(qRound(it->attribute("SCALEV").toDouble() * 10));
01631        
01632        if (it->hasAttribute("BASEO"))
01633               newStyle.setBaselineOffset(qRound(it->attribute("BASEO").toDouble() * 10));
01634        
01635        if (it->hasAttribute("TXTSHX"))
01636               newStyle.setShadowXOffset(qRound(it->attribute("TXTSHX").toDouble() * 10));
01637        
01638        if (it->hasAttribute("TXTSHY"))
01639               newStyle.setShadowYOffset(qRound(it->attribute("TXTSHY").toDouble() * 10));
01640        
01641        if (it->hasAttribute("TXTOUT"))
01642               newStyle.setOutlineWidth(qRound(it->attribute("TXTOUT").toDouble() * 10));
01643        
01644        if (it->hasAttribute("TXTULP"))
01645               newStyle.setUnderlineOffset(qRound(it->attribute("TXTULP").toDouble() * 10));
01646        
01647        if (it->hasAttribute("TXTULW"))
01648               newStyle.setUnderlineWidth(qRound(it->attribute("TXTULW").toDouble() * 10));
01649        
01650        if (it->hasAttribute("TXTSTP"))
01651               newStyle.setStrikethruOffset(qRound(it->attribute("TXTSTP").toDouble() * 10));
01652        
01653        if (it->hasAttribute("TXTSTW"))
01654               newStyle.setStrikethruWidth(qRound(it->attribute("TXTSTW").toDouble() * 10));
01655 
01656        if (it->hasAttribute("SHORTCUT"))
01657               newStyle.setShortcut(it->attribute("SHORTCUT"));
01658        
01659        if (it->hasAttribute("wordTrack"))
01660               newStyle.setWordTracking(it->attribute("wordTrack").toDouble());
01661 
01662 }      
01663 
01664 void Scribus134Format::GetItemText(QDomElement *it, ScribusDoc *doc, PageItem* obj, LastStyles* last, bool impo, bool VorLFound)
01665 {
01666        QString tmp2, tmpf;
01667        CharStyle newStyle;
01668        GetCStyle(it, doc, newStyle);
01669        
01670        if (it->hasAttribute("Unicode"))
01671        {
01672               tmp2 = QChar(it->attribute("Unicode").toUInt());
01673        }
01674        else
01675        {
01676               tmp2 = it->attribute("CH");
01677               
01678               // legacy stuff:
01679               tmp2.replace(QRegExp("\r"), QChar(13));
01680               tmp2.replace(QRegExp("\n"), QChar(13));
01681               tmp2.replace(QRegExp("\t"), QChar(9));
01682        }
01683        
01684        // more legacy stuff:
01685        
01686        if (it->hasAttribute("CFONT"))
01687               newStyle.setFont(m_AvailableFonts->findFont(it->attribute("CFONT"), doc));
01688        
01689        if (it->hasAttribute("CSIZE"))
01690               newStyle.setFontSize(qRound(it->attribute("CSIZE").toDouble() * 10));
01691        
01692        if (it->hasAttribute("CCOLOR"))
01693               newStyle.setFillColor(it->attribute("CCOLOR"));
01694        
01695        if (it->hasAttribute("CEXTRA"))
01696               newStyle.setTracking(qRound(it->attribute("CEXTRA").toDouble() / it->attribute("CSIZE").toDouble() * 1000.0));
01697        else if (it->hasAttribute("CKERN"))
01698               newStyle.setTracking(it->attribute("CKERN").toInt());
01699        
01700        if (it->hasAttribute("CSHADE"))
01701               newStyle.setFillShade(it->attribute("CSHADE").toInt());
01702        
01703        if (it->hasAttribute("CSTYLE"))
01704               newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("CSTYLE").toInt()).featureList());
01705 
01706        QString pstylename = it->attribute("PSTYLE", "");
01707        int calign = it->attribute("CALIGN", "-1").toInt();            
01708        
01709        int ab = it->attribute("CAB", "-1").toInt();
01710        if (ab >= 5) {
01711               pstylename = doc->paragraphStyles()[ab-5].name();
01712               calign = -1;
01713        }
01714        else if (ab >= 0) {
01715               pstylename = "";
01716               calign = ab;
01717        }
01718        
01719        if (it->hasAttribute("CSTROKE"))
01720               newStyle.setStrokeColor(it->attribute("CSTROKE", CommonStrings::None));
01721        
01722        if (it->hasAttribute("CSHADE2"))
01723               newStyle.setStrokeShade(it->attribute("CSHADE2", "100").toInt());
01724        
01725        if (it->hasAttribute("CSCALE"))
01726               newStyle.setScaleH(QMIN(QMAX(qRound(it->attribute("CSCALE", "100").toDouble() * 10), 100), 4000));
01727        
01728        if (it->hasAttribute("CSCALEV"))
01729               newStyle.setScaleV(QMIN(QMAX(qRound(it->attribute("CSCALEV", "100").toDouble() * 10), 100), 4000));
01730        
01731        if (it->hasAttribute("CBASE"))
01732               newStyle.setBaselineOffset(qRound(it->attribute("CBASE", "0").toDouble() * 10));
01733        
01734        if (it->hasAttribute("CSHX"))
01735               newStyle.setShadowXOffset(qRound(it->attribute("CSHX", "5").toDouble() * 10));
01736        
01737        if (it->hasAttribute("CSHY"))
01738               newStyle.setShadowYOffset(qRound(it->attribute("CSHY", "-5").toDouble() * 10));
01739        
01740        if (it->hasAttribute("COUT"))
01741               newStyle.setOutlineWidth(qRound(it->attribute("COUT", "1").toDouble() * 10));
01742        
01743        if (it->hasAttribute("CULP"))
01744               newStyle.setUnderlineOffset(qRound(it->attribute("CULP", "-0.1").toDouble() * 10));
01745        
01746        if (it->hasAttribute("CULW"))
01747               newStyle.setUnderlineWidth(qRound(it->attribute("CULW", "-0.1").toDouble() * 10));
01748        
01749        
01750        if (it->hasAttribute("CSTP"))
01751               newStyle.setStrikethruOffset(qRound(it->attribute("CSTP", "-0.1").toDouble() * 10));
01752        
01753        if (it->hasAttribute("CSTW"))
01754               newStyle.setStrikethruWidth(qRound(it->attribute("CSTW", "-0.1").toDouble() * 10));
01755        
01756        fixLegacyCharStyle(newStyle);
01757        
01758        if (impo && ab >= 0 && VorLFound)
01759               last->ParaStyle = DoVorl[ab].toInt();
01760        else
01761        {
01762               last->ParaStyle = doc->paragraphStyles().find(pstylename);
01763        }
01764        // end of legacy stuff
01765        
01766        int iobj = it->attribute("COBJ", "-1").toInt();
01767        for (uint cxx=0; cxx<tmp2.length(); ++cxx)
01768        {
01769               QChar ch = tmp2.at(cxx);           
01770               { // Legacy mode
01771                      if (ch == QChar(5))
01772                             ch = SpecialChars::PARSEP;
01773                      if (ch == QChar(4))
01774                             ch = SpecialChars::TAB;
01775               }
01776               
01777               int pos = obj->itemText.length();
01778               if (ch == SpecialChars::OBJECT) {
01779                      if (iobj != -1) {
01780                             obj->itemText.insertObject(pos, doc->FrameItems.at(iobj));
01781                      }
01782               }
01783               else if (ch == SpecialChars::SHYPHEN && pos > 0)
01784               {
01785 //                   qDebug(QString("scribus134format: SHYPHEN at %1").arg(pos));
01786                      ScText* lastItem = obj->itemText.item(pos-1);
01787                      // double SHY means user provided SHY, single SHY is automatic one
01788                      if (lastItem->effects() & ScStyle_HyphenationPossible)
01789                      {
01790                             lastItem->setEffects(lastItem->effects() & ~ScStyle_HyphenationPossible);
01791                             obj->itemText.insertChars(pos, QString(ch));
01792                      }
01793                      else
01794                      {
01795                             lastItem->setEffects(lastItem->effects() | ScStyle_HyphenationPossible);
01796                      }
01797               }
01798               else {
01799                      obj->itemText.insertChars(pos, QString(ch));
01800               }
01801 //            qDebug(QString("style at %1: %2 ^ %3 = %4 (%5)").arg(pos).arg((uint)newStyle.effects()).arg((uint)last->Style.effects()).arg((uint)(newStyle.effects() ^ last->Style.effects())).arg(newStyle != last->Style));
01802               if (newStyle != last->Style) // || (newStyle.effects() ^ last->Style.effects()) == ScStyle_HyphenationPossible) 
01803               {  // FIXME StyleFlag operator== ignores hyphen flag
01804 //                   qDebug(QString("new style at %1: %2 -> %3").arg(pos).arg(last->Style.asString()).arg(newStyle.asString()));
01805                      obj->itemText.setCharStyle(last->StyleStart, pos-last->StyleStart, last->Style);
01806                      last->Style = newStyle;
01807                      last->StyleStart = pos;
01808               }
01809               if (ch == SpecialChars::PARSEP) {
01810                      ParagraphStyle pstyle;
01811                      if (last->ParaStyle >= 0) {
01812                             pstyle.setParent( doc->paragraphStyles()[last->ParaStyle].name());
01813                      }
01814                      if (calign >= 0)
01815                             pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(calign));
01816 //                   qDebug(QString("par style at %1: %2/%3 (%4) calign %5").arg(pos).arg(pstyle.name()).arg(pstyle.parent()).arg(last->ParaStyle).arg(calign));
01817                      obj->itemText.applyStyle(pos, pstyle);
01818               }
01819        }
01820        obj->itemText.setCharStyle(last->StyleStart, obj->itemText.length()-last->StyleStart, last->Style);
01821 /*
01822        QString dbg("");
01823        for (int i=0; i < obj->itemText.length(); ++i)
01824        {
01825               dbg += obj->itemText.text(i,1);
01826               if (obj->itemText.item(i)->effects() & ScStyle_HyphenationPossible)
01827                      dbg += "~";
01828        }
01829        qDebug("scribus134format: read itemtext %d '%s'", obj->itemText.length(), dbg.latin1());
01830        */
01831        ParagraphStyle pstyle;
01832        if (last->ParaStyle >= 0) {
01833               pstyle.setParent( doc->paragraphStyles()[last->ParaStyle].name());
01834               obj->itemText.applyStyle(obj->itemText.length()-1, pstyle);
01835        }
01836        if (calign >= 0) {
01837               pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(calign));
01838               obj->itemText.applyStyle(obj->itemText.length()-1, pstyle);
01839        }
01840 }
01841 
01842 
01843 
01844 void Scribus134Format::readParagraphStyle(ParagraphStyle& vg, const QDomElement& pg, SCFonts &avail, ScribusDoc *doc)
01845 {
01846        vg.erase();
01847        vg.setName(pg.attribute("NAME"));
01848        vg.setParent(pg.attribute("PARENT", ""));
01849        if (pg.hasAttribute("LINESPMode"))
01850               vg.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg.attribute("LINESPMode").toInt()));
01851        if (pg.hasAttribute("LINESP"))
01852               vg.setLineSpacing(pg.attribute("LINESP").toDouble());
01853        if (pg.hasAttribute("INDENT"))
01854               vg.setLeftMargin(pg.attribute("INDENT").toDouble());
01855        if (pg.hasAttribute("RMARGIN"))
01856               vg.setRightMargin(pg.attribute("RMARGIN").toDouble());
01857        if (pg.hasAttribute("FIRST"))
01858               vg.setFirstIndent(pg.attribute("FIRST").toDouble());
01859        if (pg.hasAttribute("ALIGN"))
01860               vg.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pg.attribute("ALIGN").toInt()));
01861        if (pg.hasAttribute("VOR"))
01862               vg.setGapBefore(pg.attribute("VOR").toDouble());
01863        if (pg.hasAttribute("NACH"))
01864               vg.setGapAfter(pg.attribute("NACH").toDouble());
01865        if (pg.hasAttribute("DROP"))
01866               vg.setHasDropCap(static_cast<bool>(pg.attribute("DROP").toInt()));
01867        if (pg.hasAttribute("DROPLIN"))
01868               vg.setDropCapLines(pg.attribute("DROPLIN").toInt());
01869        if (pg.hasAttribute("DROPDIST"))
01870               vg.setDropCapOffset(pg.attribute("DROPDIST").toDouble());
01871        if (pg.hasAttribute("PSHORTCUT"))
01872               vg.setShortcut(pg.attribute("PSHORTCUT"));
01873 
01874        //            vg.tabValues().clear();
01875        if ((pg.hasAttribute("NUMTAB")) && (pg.attribute("NUMTAB", "0").toInt() != 0))
01876        {
01877               QValueList<ParagraphStyle::TabRecord> tbs;
01878               ParagraphStyle::TabRecord tb;
01879               QString tmp = pg.attribute("TABS");
01880               QTextStream tgv(&tmp, IO_ReadOnly);
01881               double xf, xf2;
01882               for (int cxv = 0; cxv < pg.attribute("NUMTAB", "0").toInt(); cxv += 2)
01883               {
01884                      tgv >> xf;
01885                      tgv >> xf2;
01886                      tb.tabPosition = xf2;
01887                      tb.tabType = static_cast<int>(xf);
01888                      tb.tabFillChar =  QChar();
01889                      tbs.append(tb);
01890               }
01891               vg.setTabValues(tbs);
01892               tmp = "";
01893        }
01894        else
01895        {
01896               QValueList<ParagraphStyle::TabRecord> tbs;
01897               vg.resetTabValues();
01898               QDomNode IT = pg.firstChild();
01899               while(!IT.isNull())
01900               {
01901                      QDomElement it = IT.toElement();
01902                      if (it.tagName()=="Tabs")
01903                      {
01904                             ParagraphStyle::TabRecord tb;
01905                             tb.tabPosition = it.attribute("Pos").toDouble();
01906                             tb.tabType = it.attribute("Type").toInt();
01907                             QString tbCh = "";
01908                             tbCh = it.attribute("Fill","");
01909                             if (tbCh.isEmpty())
01910                                    tb.tabFillChar = QChar();
01911                             else
01912                                    tb.tabFillChar = tbCh[0];
01913                             tbs.append(tb);
01914                      }
01915                      IT=IT.nextSibling();
01916               }
01917               if (tbs.count() > 0)
01918                      vg.setTabValues(tbs);
01919        }
01920        
01921        if (pg.hasAttribute("OpticalMargins"))
01922               vg.setOpticalMargins(pg.attribute("OpticalMargins").toInt());
01923        if (pg.hasAttribute("HyphenationMode"))
01924               vg.setHyphenationMode(pg.attribute("HyphenationMode").toInt());
01925        if (pg.hasAttribute("MinWordTrack"))
01926               vg.setMinWordTracking(pg.attribute("MinWordTrack").toDouble());
01927        if (pg.hasAttribute("NormWordTrack"))
01928               vg.charStyle().setWordTracking(pg.attribute("NormWordTrack").toDouble());
01929        if (pg.hasAttribute("MinGlyphShrink"))
01930               vg.setMinGlyphExtension(pg.attribute("MinGlyphShrink").toDouble());
01931        if (pg.hasAttribute("MaxGlyphExtend"))
01932               vg.setMaxGlyphExtension(pg.attribute("MaxGlyphExtend").toDouble());
01933        
01934        GetCStyle( &pg, doc, vg.charStyle());
01935        
01936        fixLegacyParStyle(vg);
01937 }
01938 
01939 
01940 PageItem* Scribus134Format::PasteItem(QDomElement *obj, ScribusDoc *doc)
01941 {
01942        struct ImageLoadRequest loadingInfo;
01943        int z = 0;
01944        PageItem::ItemType pt = static_cast<PageItem::ItemType>(obj->attribute("PTYPE").toInt());
01945        double x = obj->attribute("XPOS").toDouble();
01946        double y = obj->attribute("YPOS").toDouble();
01947        double w = obj->attribute("WIDTH").toDouble();
01948        double h = obj->attribute("HEIGHT").toDouble();
01949        double pw = obj->attribute("PWIDTH").toDouble();
01950        double scx = obj->attribute("LOCALSCX").toDouble();
01951        double scy = obj->attribute("LOCALSCY").toDouble();
01952        QString Pcolor = obj->attribute("PCOLOR");
01953        QString Pcolor2 = obj->attribute("PCOLOR2");
01954        QColor tmpc;
01955        PageItem *currItem=NULL;
01956        QString tmp;
01957        int xi;
01958        double xf, yf, xf2;
01959        QString clPath;
01960        QDomNode IT;
01961        switch (pt)
01962        {
01963        // OBSOLETE CR 2005-02-06
01964        case PageItem::ItemType1:
01965               z = doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, x, y, w, h, pw, Pcolor, Pcolor2, true);
01966               currItem = doc->Items->at(z);
01967               break;
01968        //
01969        case PageItem::ImageFrame:
01970               z = doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, x, y, w, h, 1, doc->toolSettings.dBrushPict, CommonStrings::None, true);
01971               currItem = doc->Items->at(z);
01972               currItem->setImageXYScale(scx, scy);
01973               currItem->setImageXYOffset(obj->attribute("LOCALX").toDouble(), obj->attribute("LOCALY").toDouble());
01974               currItem->Pfile = obj->attribute("PFILE");
01975               currItem->IProfile = obj->attribute("PRFILE","");
01976               currItem->EmProfile = obj->attribute("EPROF","");
01977               currItem->IRender = obj->attribute("IRENDER", "1").toInt();
01978               currItem->UseEmbedded = obj->attribute("EMBEDDED", "1").toInt();
01979               currItem->pixm.imgInfo.lowResType = obj->attribute("ImageRes", "1").toInt();
01980               IT = obj->firstChild();
01981               while(!IT.isNull())
01982               {
01983                      QDomElement it = IT.toElement();
01984                      if (it.tagName()=="ImageEffect")
01985                      {
01986                             struct ScImage::imageEffect ef;
01987                             ef.effectParameters = it.attribute("Param");
01988                             ef.effectCode = it.attribute("Code").toInt();
01989                             currItem->effectsInUse.append(ef);
01990                      }
01991                      IT=IT.nextSibling();
01992               }
01993               if (!currItem->Pfile.isEmpty())
01994                      doc->loadPict(currItem->Pfile, currItem, false);
01995               currItem->IProfile = obj->attribute("PRFILE","");
01996               currItem->EmProfile = obj->attribute("EPROF","");
01997               currItem->IRender = obj->attribute("IRENDER", "1").toInt();
01998               currItem->UseEmbedded = obj->attribute("EMBEDDED", "1").toInt();
01999               currItem->setImageXYScale(scx, scy);
02000               clPath = obj->attribute("ImageClip", "");
02001               if (currItem->pixm.imgInfo.PDSpathData.contains(clPath))
02002               {
02003                      currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[clPath].copy();
02004                      currItem->pixm.imgInfo.usedPath = clPath;
02005                      QWMatrix cl;
02006                      cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
02007                      cl.scale(currItem->imageXScale(), currItem->imageYScale());
02008                      currItem->imageClip.map(cl);
02009               }
02010               currItem->setImageShown(obj->attribute("PICART").toInt());
02011 /*            currItem->BBoxX = obj->attribute("BBOXX").toDouble();
02012               currItem->BBoxH = obj->attribute("BBOXH").toDouble(); */
02013               currItem->ScaleType = obj->attribute("SCALETYPE", "1").toInt();
02014               currItem->AspectRatio = obj->attribute("RATIO", "0").toInt();
02015               currItem->setLineWidth(pw);
02016               if (currItem->pixm.imgInfo.layerInfo.count() != 0)
02017               {
02018                      bool found = false;
02019                      IT = obj->firstChild();
02020                      while(!IT.isNull())
02021                      {
02022                             QDomElement it = IT.toElement();
02023                             if (it.tagName() == "PSDLayer")
02024                             {
02025                                    found = true;
02026                                    loadingInfo.blend = it.attribute("Blend");
02027                                    loadingInfo.opacity = it.attribute("Opacity").toInt();
02028                                    loadingInfo.visible = static_cast<bool>(it.attribute("Visible").toInt());
02029                                    loadingInfo.useMask = static_cast<bool>(it.attribute("useMask", "1").toInt());
02030                                    currItem->pixm.imgInfo.RequestProps.insert(it.attribute("Layer").toInt(), loadingInfo);
02031                             }
02032                             IT=IT.nextSibling();
02033                      }
02034                      if (found)
02035                      {
02036                             currItem->pixm.imgInfo.isRequest = true;
02037                             doc->loadPict(currItem->Pfile, currItem, true);
02038                      }
02039               }
02040               break;
02041        // OBSOLETE CR 2005-02-06
02042        case PageItem::ItemType3:
02043               z = doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, x, y, w, h, pw, Pcolor, Pcolor2, true);
02044               currItem = doc->Items->at(z);
02045               break;
02046        //
02047        case PageItem::PathText:
02048               z = doc->itemAdd(PageItem::PathText, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
02049               currItem = doc->Items->at(z);
02050               if ((obj->attribute("ANNOTATION", "0").toInt()) && (static_cast<bool>(obj->attribute("ANICON", "0").toInt())))
02051               {
02052                      currItem->setImageXYScale(scx, scy);
02053                      currItem->setImageXYOffset(obj->attribute("LOCALX").toDouble(), obj->attribute("LOCALY").toDouble());
02054                      currItem->Pfile = obj->attribute("PFILE");
02055                      currItem->Pfile2 = obj->attribute("PFILE2","");
02056                      currItem->Pfile3 = obj->attribute("PFILE3","");
02057                      currItem->IProfile = obj->attribute("PRFILE","");
02058                      currItem->EmProfile = obj->attribute("EPROF","");
02059                      currItem->IRender = obj->attribute("IRENDER", "1").toInt();
02060                      currItem->UseEmbedded = obj->attribute("EMBEDDED", "1").toInt();
02061                      doc->LoadPict(currItem->Pfile, z);
02062                      currItem->setImageXYScale(scx, scy);
02063                      currItem->setImageShown(obj->attribute("PICART").toInt());
02064 /*                   currItem->BBoxX = obj->attribute("BBOXX").toDouble();
02065                      currItem->BBoxH = obj->attribute("BBOXH").toDouble(); */
02066                      currItem->ScaleType = obj->attribute("SCALETYPE", "1").toInt();
02067                      currItem->AspectRatio = obj->attribute("RATIO", "0").toInt();
02068               }
02069               //currItem->convertTo(pt);
02070               break;
02071        case PageItem::TextFrame:
02072               z = doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
02073               currItem = doc->Items->at(z);
02074               if ((obj->attribute("ANNOTATION", "0").toInt()) && (static_cast<bool>(obj->attribute("ANICON", "0").toInt())))
02075               {
02076                      currItem->setImageXYScale(scx, scy);
02077                      currItem->setImageXYOffset(obj->attribute("LOCALX").toDouble(), obj->attribute("LOCALY").toDouble());
02078                      currItem->Pfile = obj->attribute("PFILE");
02079                      currItem->Pfile2 = obj->attribute("PFILE2","");
02080                      currItem->Pfile3 = obj->attribute("PFILE3","");
02081                      currItem->IProfile = obj->attribute("PRFILE","");
02082                      currItem->EmProfile = obj->attribute("EPROF","");
02083                      currItem->IRender = obj->attribute("IRENDER", "1").toInt();
02084                      currItem->UseEmbedded = obj->attribute("EMBEDDED", "1").toInt();
02085                      doc->LoadPict(currItem->Pfile, z);
02086                      currItem->setImageXYScale(scx, scy);
02087                      currItem->setImageShown(obj->attribute("PICART").toInt());
02088 /*                   currItem->BBoxX = obj->attribute("BBOXX").toDouble();
02089                      currItem->BBoxH = obj->attribute("BBOXH").toDouble(); */
02090                      currItem->ScaleType = obj->attribute("SCALETYPE", "1").toInt();
02091                      currItem->AspectRatio = obj->attribute("RATIO", "0").toInt();
02092               }
02093                      //currItem->convertTo(pt);
02094               break;
02095        case PageItem::Line:
02096               z = doc->itemAdd(PageItem::Line, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor2, true);
02097               currItem = doc->Items->at(z);
02098               break;
02099        case PageItem::Polygon:
02100               z = doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
02101               currItem = doc->Items->at(z);
02102               break;
02103        case PageItem::PolyLine:
02104               z = doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
02105               currItem = doc->Items->at(z);
02106               break;
02107        case PageItem::Multiple:
02108               Q_ASSERT(false);
02109               break;
02110        }
02111        currItem->FrameType = obj->attribute("FRTYPE", "0").toInt();
02112        int startArrowIndex = obj->attribute("startArrowIndex", "0").toInt();
02113        if ((startArrowIndex < 0) || (startArrowIndex > static_cast<int>(doc->arrowStyles.size())))
02114        {
02115               qDebug(QString("scribus134format: invalid arrow index: %").arg(startArrowIndex));
02116               startArrowIndex = 0;
02117        }
02118        currItem->setStartArrowIndex(startArrowIndex);
02119        int endArrowIndex = obj->attribute("endArrowIndex", "0").toInt();
02120        if ((endArrowIndex < 0) || (endArrowIndex > static_cast<int>(doc->arrowStyles.size())))
02121        {
02122               qDebug(QString("scribus134format: invalid arrow index: %").arg(endArrowIndex));
02123               endArrowIndex = 0;
02124        }
02125        currItem->setEndArrowIndex(endArrowIndex);
02126        currItem->NamedLStyle = obj->attribute("NAMEDLST", "");
02127        currItem->isBookmark = obj->attribute("BOOKMARK").toInt();
02128        if ((currItem->isBookmark) && (doc->BookMarks.count() == 0))
02129               doc->OldBM = true;
02130        currItem->setImageFlippedH(obj->attribute("FLIPPEDH").toInt());
02131        currItem->setImageFlippedV(obj->attribute("FLIPPEDV").toInt());
02132        currItem->setCornerRadius(obj->attribute("RADRECT", "0").toDouble());
02133        currItem->ClipEdited = obj->attribute("CLIPEDIT", "0").toInt();
02134        currItem->setFillColor(Pcolor);
02135        currItem->setLineColor(Pcolor2);
02136        currItem->setFillShade(obj->attribute("SHADE").toInt());
02137        currItem->setLineShade(obj->attribute("SHADE2").toInt());
02138        ParagraphStyle pstyle;
02139        if (obj->hasAttribute("LINESP"))
02140               pstyle.setLineSpacing(obj->attribute("LINESP").toDouble());
02141        if (obj->hasAttribute("LINESPMode"))
02142               pstyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(obj->attribute("LINESPMode", "0").toInt()));
02143        if (obj->hasAttribute("ALIGN"))
02144               pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(obj->attribute("ALIGN", "0").toInt()));
02145        if (obj->hasAttribute("IFONT"))
02146               pstyle.charStyle().setFont(m_AvailableFonts->findFont(obj->attribute("IFONT"), doc));
02147        if (obj->hasAttribute("ISIZE"))
02148               pstyle.charStyle().setFontSize(qRound(obj->attribute("ISIZE").toDouble() * 10));
02149        if (obj->hasAttribute("TXTSTROKE"))
02150               pstyle.charStyle().setStrokeColor(obj->attribute("TXTSTROKE"));
02151        if (obj->hasAttribute("TXTFILL"))
02152               pstyle.charStyle().setFillColor(obj->attribute("TXTFILL"));
02153        if (obj->hasAttribute("TXTSTRSH"))
02154               pstyle.charStyle().setStrokeShade(obj->attribute("TXTSTRSH").toInt());
02155        if (obj->hasAttribute("TXTFILLSH"))
02156               pstyle.charStyle().setFillShade(obj->attribute("TXTFILLSH").toInt());
02157        if (obj->hasAttribute("TXTSCALE"))
02158               pstyle.charStyle().setScaleH(qRound(obj->attribute("TXTSCALE").toDouble() * 10));
02159        if (obj->hasAttribute("TXTSCALEV"))
02160               pstyle.charStyle().setScaleV(qRound(obj->attribute("TXTSCALEV").toDouble() * 10));
02161        if (obj->hasAttribute("TXTBASE"))
02162               pstyle.charStyle().setBaselineOffset(qRound(obj->attribute("TXTBASE").toDouble() * 10));
02163        if (obj->hasAttribute("TXTSHX"))
02164               pstyle.charStyle().setShadowXOffset(qRound(obj->attribute("TXTSHX").toDouble() * 10));
02165        if (obj->hasAttribute("TXTSHY"))
02166               pstyle.charStyle().setShadowYOffset(qRound(obj->attribute("TXTSHY").toDouble() * 10));
02167        if (obj->hasAttribute("TXTOUT"))
02168               pstyle.charStyle().setOutlineWidth(qRound(obj->attribute("TXTOUT").toDouble() * 10));
02169        if (obj->hasAttribute("TXTULP"))
02170               pstyle.charStyle().setUnderlineOffset(qRound(obj->attribute("TXTULP").toDouble() * 10));
02171        if (obj->hasAttribute("TXTULW"))
02172               pstyle.charStyle().setUnderlineWidth(qRound(obj->attribute("TXTULW").toDouble() * 10));
02173        if (obj->hasAttribute("TXTSTP"))
02174               pstyle.charStyle().setStrikethruOffset(qRound(obj->attribute("TXTSTP").toDouble() * 10));
02175        if (obj->hasAttribute("TXTSTW"))
02176               pstyle.charStyle().setStrikethruWidth(qRound(obj->attribute("TXTSTW").toDouble() * 10));
02177        if (obj->hasAttribute("TXTSTYLE"))
02178               pstyle.charStyle().setFeatures(static_cast<StyleFlag>(obj->attribute("TXTSTYLE").toInt()).featureList());
02179        if (obj->hasAttribute("TXTKERN"))
02180               pstyle.charStyle().setTracking(qRound(obj->attribute("TXTKERN", "0").toDouble() * 10));
02181        if (obj->hasAttribute("wordTrack"))
02182               pstyle.charStyle().setWordTracking(obj->attribute("wordTrack").toDouble());
02183        if (obj->hasAttribute("MinWordTrack"))
02184               pstyle.setMinWordTracking(obj->attribute("MinWordTrack").toDouble());
02185        if (obj->hasAttribute("MinGlyphShrink"))
02186               pstyle.setMinGlyphExtension(obj->attribute("MinGlyphShrink").toDouble());
02187        if (obj->hasAttribute("MaxGlyphExtend"))
02188               pstyle.setMaxGlyphExtension(obj->attribute("MaxGlyphExtend").toDouble());
02189        if (obj->hasAttribute("OpticalMargins"))
02190               pstyle.setOpticalMargins(obj->attribute("OpticalMargins").toInt());
02191        if (obj->hasAttribute("HyphenationMode"))
02192               pstyle.setHyphenationMode(obj->attribute("HyphenationMode").toInt());
02193        currItem->itemText.setDefaultStyle(pstyle);
02194        currItem->setRotation(obj->attribute("ROT").toDouble());
02195        currItem->setTextToFrameDist(obj->attribute("EXTRA").toDouble(),
02196                                                         obj->attribute("REXTRA", "1").toDouble(),
02197                                                         obj->attribute("TEXTRA", "1").toDouble(),
02198                                                         obj->attribute("BEXTRA", "1").toDouble());
02199 
02200        currItem->PLineArt = Qt::PenStyle(obj->attribute("PLINEART").toInt());
02201        currItem->PLineEnd = Qt::PenCapStyle(obj->attribute("PLINEEND", "0").toInt());
02202        currItem->PLineJoin = Qt::PenJoinStyle(obj->attribute("PLINEJOIN", "0").toInt());
02203        currItem->setPrintEnabled(obj->attribute("PRINTABLE").toInt());
02204        currItem->setIsAnnotation(obj->attribute("ANNOTATION", "0").toInt());
02205        currItem->annotation().setType(obj->attribute("ANTYPE", "0").toInt());
02206        QString AnName = obj->attribute("ANNAME","");
02207        if (!AnName.isEmpty())
02208        {
02209               if (currItem->itemName() == AnName)
02210                      currItem->AutoName = true;
02211               else
02212               {
02213                      currItem->setItemName(AnName);
02214                      currItem->AutoName = false;
02215               }
02216        }
02217        currItem->annotation().setAction(obj->attribute("ANACTION",""));
02218        currItem->annotation().setE_act(obj->attribute("ANEACT",""));
02219        currItem->annotation().setX_act(obj->attribute("ANXACT",""));
02220        currItem->annotation().setD_act(obj->attribute("ANDACT",""));
02221        currItem->annotation().setFo_act(obj->attribute("ANFOACT",""));
02222        currItem->annotation().setBl_act(obj->attribute("ANBLACT",""));
02223        currItem->annotation().setK_act(obj->attribute("ANKACT",""));
02224        currItem->annotation().setF_act(obj->attribute("ANFACT",""));
02225        currItem->annotation().setV_act(obj->attribute("ANVACT",""));
02226        currItem->annotation().setC_act(obj->attribute("ANCACT",""));
02227        currItem->annotation().setActionType(obj->attribute("ANACTYP", "0").toInt());
02228        currItem->annotation().setExtern(obj->attribute("ANEXTERN",""));
02229        if ((!currItem->annotation().Extern().isEmpty()) && (currItem->annotation().ActionType() != 8))
02230        {
02231               QFileInfo efp(currItem->annotation().Extern());
02232               currItem->annotation().setExtern(efp.absFilePath());
02233        }
02234        currItem->annotation().setZiel(obj->attribute("ANZIEL", "0").toInt());
02235        currItem->annotation().setToolTip(obj->attribute("ANTOOLTIP",""));
02236        currItem->annotation().setRollOver(obj->attribute("ANROLL",""));
02237        currItem->annotation().setDown(obj->attribute("ANDOWN",""));
02238        currItem->annotation().setBwid(obj->attribute("ANBWID", "1").toInt());
02239        currItem->annotation().setBsty(obj->attribute("ANBSTY", "0").toInt());
02240        currItem->annotation().setFeed(obj->attribute("ANFEED", "1").toInt());
02241        currItem->annotation().setFlag(obj->attribute("ANFLAG", "0").toInt());
02242        currItem->annotation().setFont(obj->attribute("ANFONT", "4").toInt());
02243        currItem->annotation().setFormat(obj->attribute("ANFORMAT", "0").toInt());
02244        currItem->annotation().setVis(obj->attribute("ANVIS", "0").toInt());
02245        currItem->annotation().setIsChk(static_cast<bool>(obj->attribute("ANCHK", "0").toInt()));
02246        currItem->annotation().setAAact(static_cast<bool>(obj->attribute("ANAA", "0").toInt()));
02247        currItem->annotation().setHTML(static_cast<bool>(obj->attribute("ANHTML", "0").toInt()));
02248        currItem->annotation().setUseIcons(static_cast<bool>(obj->attribute("ANICON", "0").toInt()));
02249        currItem->annotation().setChkStil(obj->attribute("ANCHKS", "0").toInt());
02250        currItem->annotation().setMaxChar(obj->attribute("ANMC", "-1").toInt());
02251        currItem->annotation().setBorderColor(obj->attribute("ANBCOL", CommonStrings::None));
02252        currItem->annotation().setIPlace(obj->attribute("ANPLACE", "1").toInt());
02253        currItem->annotation().setScaleW(obj->attribute("ANSCALE", "0").toInt());
02254        currItem->TopLine = static_cast<bool>(obj->attribute("TopLine", "0").toInt());
02255        currItem->LeftLine = static_cast<bool>(obj->attribute("LeftLine", "0").toInt());
02256        currItem->RightLine = static_cast<bool>(obj->attribute("RightLine", "0").toInt());
02257        currItem->BottomLine = static_cast<bool>(obj->attribute("BottomLine", "0").toInt());
02258        currItem->isTableItem = static_cast<bool>(obj->attribute("isTableItem", "0").toInt());
02259        currItem->TopLinkID =  obj->attribute("TopLINK", "-1").toInt();
02260        currItem->LeftLinkID =  obj->attribute("LeftLINK", "-1").toInt();
02261        currItem->RightLinkID =  obj->attribute("RightLINK", "-1").toInt();
02262        currItem->BottomLinkID =  obj->attribute("BottomLINK", "-1").toInt();
02263        currItem->PoShow = obj->attribute("PLTSHOW", "0").toInt();
02264        currItem->BaseOffs = obj->attribute("BASEOF", "0").toDouble();
02265        currItem->textPathType =  obj->attribute("textPathType", "0").toInt();
02266        currItem->textPathFlipped = static_cast<bool>(obj->attribute("textPathFlipped", "0").toInt());
02267        if ( obj->hasAttribute("TEXTFLOWMODE") )
02268               currItem->setTextFlowMode((PageItem::TextFlowMode) obj->attribute("TEXTFLOWMODE", "0").toInt());
02269        else if ( obj->attribute("TEXTFLOW").toInt() )
02270        {
02271               if (obj->attribute("TEXTFLOW2", "0").toInt())
02272                      currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
02273               else if (obj->attribute("TEXTFLOW3", "0").toInt())
02274                      currItem->setTextFlowMode(PageItem::TextFlowUsesContourLine);
02275               else
02276                      currItem->setTextFlowMode(PageItem::TextFlowUsesFrameShape);   
02277        }
02278        else
02279               currItem->setTextFlowMode(PageItem::TextFlowDisabled);
02280        currItem->DashOffset = obj->attribute("DASHOFF", "0.0").toDouble();
02281        currItem->setReversed(static_cast<bool>(obj->attribute("REVERS", "0").toInt()));
02282        currItem->setLocked(static_cast<bool>(obj->attribute("LOCK", "0").toInt()));
02283        currItem->setSizeLocked(static_cast<bool>(obj->attribute("LOCKR", "0").toInt()));
02284        currItem->setFillTransparency(obj->attribute("TransValue", "0.0").toDouble());
02285        currItem->fillRule = static_cast<bool>(obj->attribute("fillRule", "1").toInt());
02286        currItem->doOverprint = static_cast<bool>(obj->attribute("doOverprint", "0").toInt());
02287        if (obj->hasAttribute("TransValueS"))
02288               currItem->setLineTransparency(obj->attribute("TransValueS", "0.0").toDouble());
02289        else
02290               currItem->setLineTransparency(obj->attribute("TransValue", "0.0").toDouble());
02291        currItem->setFillBlendmode(obj->attribute("TransBlend", "0").toInt());
02292        currItem->setLineBlendmode(obj->attribute("TransBlendS", "0").toInt());
02293        if (obj->attribute("TRANSPARENT", "0").toInt() == 1)
02294               currItem->setFillColor(CommonStrings::None);
02295        currItem->Cols = obj->attribute("COLUMNS", "1").toInt();
02296        currItem->ColGap = obj->attribute("COLGAP", "0.0").toDouble();
02297        if (obj->attribute("LAYER", "0").toInt() != -1)
02298               currItem->LayerNr = obj->attribute("LAYER", "0").toInt();
02299        tmp = "";
02300        if ((obj->hasAttribute("GROUPS")) && (obj->attribute("NUMGROUP", "0").toInt() != 0))
02301        {
02302               tmp = obj->attribute("GROUPS");
02303               QTextStream fg(&tmp, IO_ReadOnly);
02304               currItem->Groups.clear();
02305               for (int cx = 0; cx < obj->attribute("NUMGROUP", "0").toInt(); ++cx)
02306               {
02307                      fg >> xi;
02308                      currItem->Groups.push(xi);
02309               }
02310               tmp = "";
02311        }
02312        else
02313               currItem->Groups.clear();
02314 
02315        QValueList<ParagraphStyle::TabRecord> tbs;
02316        tmp = "";
02317        if ((obj->hasAttribute("NUMTAB")) && (obj->attribute("NUMTAB", "0").toInt() != 0))
02318        {
02319               QValueList<ParagraphStyle::TabRecord> tbs;
02320               ParagraphStyle::TabRecord tb;
02321               tmp = obj->attribute("TABS");
02322               QTextStream tgv(&tmp, IO_ReadOnly);
02323               for (int cxv = 0; cxv < obj->attribute("NUMTAB", "0").toInt(); cxv += 2)
02324               {
02325                      tgv >> xf;
02326                      tgv >> xf2;
02327                      tb.tabPosition = xf2;
02328                      tb.tabType = static_cast<int>(xf);
02329                      tb.tabFillChar = QChar();
02330                      tbs.append(tb);
02331               }
02332               tmp = "";
02333        }
02334        else
02335        {
02336               IT = obj->firstChild();
02337               while(!IT.isNull())
02338               {
02339                      QDomElement it = IT.toElement();
02340                      if (it.tagName()=="Tabs")
02341                      {
02342                             ParagraphStyle::TabRecord tb;
02343                             tb.tabPosition = it.attribute("Pos").toDouble();
02344                             tb.tabType = it.attribute("Type").toInt();
02345                             QString tbCh = "";
02346                             tbCh = it.attribute("Fill","");
02347                             if (tbCh.isEmpty())
02348                                    tb.tabFillChar = QChar();
02349                             else
02350                                    tb.tabFillChar = tbCh[0];
02351                             tbs.append(tb);
02352                      }
02353                      IT=IT.nextSibling();
02354               }
02355        }
02356        if (tbs.count() > 0) {
02357               ParagraphStyle newDefault(currItem->itemText.defaultStyle());
02358               newDefault.setTabValues(tbs);
02359               currItem->itemText.setDefaultStyle(newDefault);
02360        }
02361        
02362        if ((obj->hasAttribute("NUMDASH")) && (obj->attribute("NUMDASH", "0").toInt() != 0))
02363        {
02364               tmp = obj->attribute("DASHS");
02365               QTextStream dgv(&tmp, IO_ReadOnly);
02366               currItem->DashValues.clear();
02367               for (int cxv = 0; cxv < obj->attribute("NUMDASH", "0").toInt(); ++cxv)
02368               {
02369                      dgv >> xf;
02370                      currItem->DashValues.append(xf);
02371               }
02372               tmp = "";
02373        }
02374        else
02375               currItem->DashValues.clear();
02376        tmp = "";
02377        if (obj->hasAttribute("NUMPO"))
02378        {
02379               currItem->PoLine.resize(obj->attribute("NUMPO").toUInt());
02380               tmp = obj->attribute("POCOOR");
02381               QTextStream fp(&tmp, IO_ReadOnly);
02382               for (uint cx=0; cx<obj->attribute("NUMPO").toUInt(); ++cx)
02383               {
02384                      fp >> xf;
02385                      fp >> yf;
02386                      currItem->PoLine.setPoint(cx, xf, yf);
02387               }
02388        }
02389        else
02390               currItem->PoLine.resize(0);
02391        tmp = "";
02392        if (obj->hasAttribute("NUMCO"))
02393        {
02394               currItem->ContourLine.resize(obj->attribute("NUMCO").toUInt());
02395               tmp = obj->attribute("COCOOR");
02396               QTextStream fp(&tmp, IO_ReadOnly);
02397               for (uint cx=0; cx<obj->attribute("NUMCO").toUInt(); ++cx)
02398               {
02399                      fp >> xf;
02400                      fp >> yf;
02401                      currItem->ContourLine.setPoint(cx, xf, yf);
02402               }
02403        }
02404        else
02405               currItem->ContourLine = currItem->PoLine.copy();
02406        if (!currItem->asLine())
02407               currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
02408        else
02409        {
02410               int ph = static_cast<int>(QMAX(1.0, currItem->lineWidth() / 2.0));
02411               currItem->Segments.clear();
02412               currItem->PoLine.resize(0);
02413               currItem->Clip.setPoints(4, -ph,-ph, static_cast<int>(currItem->width()+ph),-ph,
02414                                 static_cast<int>(currItem->width()+ph),static_cast<int>(currItem->height()+ph),
02415                                 -ph,static_cast<int>(currItem->height()+ph));
02416               currItem->setHeight(1.0);
02417        }
02418        if (currItem->asImageFrame())
02419               currItem->AdjustPictScale();
02420        if (currItem->asPathText())
02421        {
02422               currItem->updatePolyClip();
02423               currItem->Frame = true;
02424        }
02425        currItem->GrType = obj->attribute("GRTYP", "0").toInt();
02426        QString GrColor;
02427        QString GrColor2;
02428        int GrShade = 0;
02429        int GrShade2 = 0;
02430        if (currItem->GrType != 0)
02431        {
02432               if (currItem->GrType == 8)
02433               {
02434                      currItem->setPattern(obj->attribute("pattern", ""));
02435                      double patternScaleX = obj->attribute("pScaleX", "100.0").toDouble();
02436                      double patternScaleY = obj->attribute("pScaleY", "100.0").toDouble();
02437                      double patternOffsetX = obj->attribute("pOffsetX", "0.0").toDouble();
02438                      double patternOffsetY = obj->attribute("pOffsetY", "0.0").toDouble();
02439                      double patternRotation = obj->attribute("pRotation", "0.0").toDouble();
02440                      currItem->setPatternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
02441               }
02442               else
02443               {
02444                      currItem->GrStartX = obj->attribute("GRSTARTX", "0.0").toDouble();
02445                      currItem->GrStartY = obj->attribute("GRSTARTY", "0.0").toDouble();
02446                      currItem->GrEndX = obj->attribute("GRENDX", "0.0").toDouble();
02447                      currItem->GrEndY = obj->attribute("GRENDY", "0.0").toDouble();
02448                      GrColor = obj->attribute("GRCOLOR","");
02449                      if (!GrColor.isEmpty())
02450                      {
02451                             GrColor2 = obj->attribute("GRCOLOR2","");
02452                             GrShade = obj->attribute("GRSHADE", "100").toInt();
02453                             GrShade2 = obj->attribute("GRSHADE2", "100").toInt();
02454                      }
02455               }
02456        }
02457        if ((currItem->GrType != 0) && (currItem->GrType != 8))
02458        {
02459               currItem->fill_gradient.clearStops();
02460               if ((!GrColor.isEmpty()) && (!GrColor2.isEmpty()))
02461               {
02462                      if (currItem->GrType == 5)
02463                      {
02464                             if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
02465                                    currItem->SetFarbe(&tmpc, GrColor, GrShade);
02466                             currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor, GrShade);
02467                             if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
02468                                    currItem->SetFarbe(&tmpc, GrColor2, GrShade2);
02469                             currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor2, GrShade2);
02470                      }
02471                      else
02472                      {
02473                             if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
02474                                    currItem->SetFarbe(&tmpc, GrColor2, GrShade2);
02475                             currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor2, GrShade2);
02476                             if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
02477                                    currItem->SetFarbe(&tmpc, GrColor, GrShade);
02478                             currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor, GrShade);
02479                      }
02480               }
02481 //            currItem->updateGradientVectors();
02482        }
02483        //currItem->setRedrawBounding();
02484        //currItem->OwnPage = view->OnPage(currItem);
02485        return currItem;
02486 }
02487 
02488 bool Scribus134Format::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName)
02489 {
02490 //     qDebug(QString("loading page %2 from file '%1' from 1.3.x plugin").arg(fileName).arg(pageNumber));
02491        if (m_Doc==0 || m_AvailableFonts==0)
02492        {
02493               Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
02494               return false;
02495        }
02496        ParagraphStyle vg;
02497        struct Layer la;
02498        struct ScribusDoc::BookMa bok;
02499        PageItem *Neu;
02500        Page* Apage = NULL;
02501        itemRemap.clear();
02502        itemNext.clear();
02503        itemCount = 0;
02504        itemRemapM.clear();
02505        itemNextM.clear();
02506        itemCountM = 0;
02507        itemRemapF.clear();
02508        itemNextF.clear();
02509        itemCountF = 0;
02510        QString tmV, tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
02511        QFont fo;
02512        QMap<int,int> TableID;
02513        QPtrList<PageItem> TableItems;
02514        QMap<PageItem*, int> groupID;
02515        int a, counter, baseobj;
02516        double pageX = 0, pageY = 0;
02517        bool newVersion = false;
02518        bool VorLFound = false;
02519        QMap<int,int> layerTrans;
02520        int maxLayer = 0;
02521        int maxLevel = 0;
02522        layerTrans.clear();
02523        uint layerCount=m_Doc->layerCount();
02524        for (uint la2 = 0; la2 < layerCount; ++la2)
02525        {
02526               maxLayer = QMAX(m_Doc->Layers[la2].LNr, maxLayer);
02527               maxLevel = QMAX(m_Doc->Layers[la2].Level, maxLevel);
02528        }
02529        DoVorl.clear();
02530        DoVorl[0] = "0";
02531        DoVorl[1] = "1";
02532        DoVorl[2] = "2";
02533        DoVorl[3] = "3";
02534        DoVorl[4] = "4";
02535        VorlC = 5;
02536        QDomDocument docu("scridoc");
02537        QString f(readSLA(fileName));
02538        if (f.isEmpty())
02539               return false;
02540        if(!docu.setContent(f))
02541               return false;
02542        QDomElement elem=docu.documentElement();
02543        if (elem.tagName() != "SCRIBUSUTF8NEW")
02544               return false;
02545        if (elem.hasAttribute("Version"))
02546               newVersion = true;
02547        QDomNode DOC=elem.firstChild();
02548        counter = m_Doc->Items->count();
02549        baseobj = counter;
02550 //     PrefsManager* prefsManager=PrefsManager::instance();
02551        while(!DOC.isNull())
02552        {
02553               QDomElement dc=DOC.toElement();
02554               QDomNode PAGE=DOC.firstChild();
02555               while(!PAGE.isNull())
02556               {
02557                      QDomElement pg=PAGE.toElement();
02558                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
02559                      {
02560                             ScColor lf;
02561                             if (pg.hasAttribute("CMYK"))
02562                                    lf.setNamedColor(pg.attribute("CMYK"));
02563                             else
02564                                    lf.fromQColor(QColor(pg.attribute("RGB")));
02565                             if (pg.hasAttribute("Spot"))
02566                                    lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
02567                             else
02568                                    lf.setSpotColor(false);
02569                             if (pg.hasAttribute("Register"))
02570                                    lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
02571                             else
02572                                    lf.setRegistrationColor(false);
02573                             m_Doc->PageColors.insert(pg.attribute("NAME"), lf);
02574                      }
02575                      if(pg.tagName()=="STYLE")
02576                      {
02577                             GetStyle(&pg, &vg, NULL, m_Doc, true);
02578                             VorLFound = true;
02579                      }
02580                      if(pg.tagName()=="JAVA")
02581                             m_Doc->JavaScripts[pg.attribute("NAME")] = pg.attribute("SCRIPT");
02582                      if(pg.tagName()=="LAYERS")
02583                      {
02584                             la.LNr = pg.attribute("NUMMER").toInt();
02585                             la.Level = pg.attribute("LEVEL").toInt();
02586                             la.Name = pg.attribute("NAME");
02587                             la.isViewable = pg.attribute("SICHTBAR").toInt();
02588                             la.isPrintable = pg.attribute("DRUCKEN").toInt();
02589                             la.isEditable = pg.attribute("EDIT", "1").toInt();
02590                             la.flowControl = pg.attribute("FLOW", "1").toInt();
02591                             la.transparency = pg.attribute("TRANS", "1").toDouble();
02592                             la.blendMode = pg.attribute("BLEND", "0").toInt();
02593                             la.outlineMode = pg.attribute("OUTL", "0").toInt();
02594                             if (pg.hasAttribute("LAYERC"))
02595                                    la.markerColor =  QColor(pg.attribute("LAYERC","#000000"));
02596                             else
02597                             {
02598                                    QColor marker;
02599                                    switch (la.LNr % 7)
02600                                    {
02601                                           case 0:
02602                                                  marker = Qt::black;
02603                                                  break;
02604                                           case 1:
02605                                                  marker = Qt::red;
02606                                                  break;
02607                                           case 2:
02608                                                  marker = Qt::green;
02609                                                  break;
02610                                           case 3:
02611                                                  marker = Qt::blue;
02612                                                  break;
02613                                           case 4:
02614                                                  marker = Qt::cyan;
02615                                                  break;
02616                                           case 5:
02617                                                  marker = Qt::magenta;
02618                                                  break;
02619                                           case 6:
02620                                                  marker = Qt::yellow;;
02621                                                  break;
02622                                    }
02623                                    la.markerColor = marker;
02624                             }
02625                             bool laex = false;
02626                             uint layerCount=m_Doc->layerCount();
02627                             for (uint la2 = 0; la2 < layerCount; ++la2)
02628                             {
02629                                    if (m_Doc->Layers[la2].Name == la.Name)
02630                                    {
02631                                           laex = true;
02632                                           layerTrans.insert(la.LNr, m_Doc->Layers[la2].LNr);
02633                                    }
02634                             }
02635                             if (!laex)
02636                             {
02637                                    maxLayer++;
02638                                    maxLevel++;
02639                                    layerTrans.insert(la.LNr, maxLayer);
02640                                    la.LNr = maxLayer;
02641                                    la.Level = maxLevel;
02642                                    m_Doc->Layers.append(la);
02643                             }
02644                      }
02645                      if(pg.tagName()=="MultiLine")
02646                      {
02647                             multiLine ml;
02648                             QDomNode MuLn = PAGE.firstChild();
02649                             while(!MuLn.isNull())
02650                             {
02651                                    QDomElement MuL = MuLn.toElement();
02652                                    struct SingleLine sl;
02653                                    sl.Color = MuL.attribute("Color");
02654                                    sl.Dash = MuL.attribute("Dash").toInt();
02655                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
02656                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
02657                                    sl.Shade = MuL.attribute("Shade").toInt();
02658                                    sl.Width = MuL.attribute("Width").toDouble();
02659                                    ml.shortcut = MuL.attribute("Shortcut");
02660                                    ml.push_back(sl);
02661                                    MuLn = MuLn.nextSibling();
02662                             }
02663                             QString Nam = pg.attribute("Name");
02664                             QString Nam2 = Nam;
02665                             int copyC = 1;
02666                             QMap<QString,multiLine>::ConstIterator mlit = m_Doc->MLineStyles.find(Nam2);
02667                             if (mlit != m_Doc->MLineStyles.end() && ml != mlit.data())
02668                             {
02669                                    while (m_Doc->MLineStyles.contains(Nam2))
02670                                    {
02671                                           Nam2 = QObject::tr("Copy #%1 of ").arg(copyC)+Nam;
02672                                           copyC++;
02673                                    }
02674                             }
02675                             m_Doc->MLineStyles.insert(Nam2, ml);
02676                      }
02677                      if(pg.tagName()=="Arrows")
02678                      {
02679                             struct ArrowDesc arrow;
02680                             arrow.name = pg.attribute("Name");
02681                             arrow.userArrow = true;
02682                             double xa, ya;
02683                             QString tmp = pg.attribute("Points");
02684                             QTextStream fp(&tmp, IO_ReadOnly);
02685                             for (uint cx = 0; cx < pg.attribute("NumPoints").toUInt(); ++cx)
02686                             {
02687                                    fp >> xa;
02688                                    fp >> ya;
02689                                    arrow.points.addPoint(xa, ya);
02690                             }
02691                             m_Doc->arrowStyles.append(arrow);
02692                      }
02693                      if (((pg.tagName()=="PAGE") || (pg.tagName()=="MASTERPAGE")) && (pg.attribute("NUM").toInt() == pageNumber))
02694                      {
02695                             a = m_Doc->currentPage()->pageNr();
02696                             Apage = m_Doc->Pages->at(a);
02697                             if ((pg.tagName()!="MASTERPAGE") && (Mpage))
02698                             {
02699                                    PAGE=PAGE.nextSibling();
02700                                    continue;
02701                             }
02702                             if (Mpage)
02703                             {
02704                                    Apage->LeftPg=pg.attribute("LEFT", "0").toInt();
02705                                    
02706                                    if (!renamedPageName.isEmpty())
02707                                           Apage->setPageName(renamedPageName);
02708                                    else
02709                                           Apage->setPageName(pg.attribute("NAM",""));
02710                             }
02711                             if (pg.hasAttribute("Size"))
02712                                    Apage->m_pageSize = pg.attribute("Size");
02713                             if (pg.hasAttribute("Orientation"))
02714                                    Apage->PageOri = pg.attribute("Orientation").toInt();
02715                             if (pg.hasAttribute("PAGEWIDTH"))
02716                                    Apage->setWidth(pg.attribute("PAGEWIDTH").toDouble());
02717                             else
02718                                    Apage->setWidth(pg.attribute("PAGEWITH").toDouble());
02719                             Apage->setHeight(pg.attribute("PAGEHEIGHT").toDouble());
02720                             Apage->setInitialHeight(Apage->height());
02721                             Apage->setInitialWidth(Apage->width());
02722                             Apage->initialMargins.Top = QMAX(0.0, pg.attribute("BORDERTOP").toDouble());
02723                             Apage->initialMargins.Bottom = QMAX(0.0, pg.attribute("BORDERBOTTOM").toDouble());
02724                             Apage->initialMargins.Left = QMAX(0.0, pg.attribute("BORDERLEFT").toDouble());
02725                             Apage->initialMargins.Right = QMAX(0.0, pg.attribute("BORDERRIGHT").toDouble());
02726                             Apage->Margins.Top = Apage->initialMargins.Top;
02727                             Apage->Margins.Bottom = Apage->initialMargins.Bottom;
02728                             pageX = pg.attribute("PAGEXPOS").toDouble();
02729                             pageY = pg.attribute("PAGEYPOS").toDouble();
02730                             // guides reading
02731                             tmp = "";
02732                             Apage->guides.setHorizontalAutoGap(pg.attribute("AGhorizontalAutoGap", "0.0").toDouble());
02733                             Apage->guides.setVerticalAutoGap(pg.attribute("AGverticalAutoGap", "0.0").toDouble());
02734                             Apage->guides.setHorizontalAutoCount(pg.attribute("AGhorizontalAutoCount", "0").toInt());
02735                             Apage->guides.setVerticalAutoCount(pg.attribute("AGverticalAutoCount", "0").toInt());
02736                             Apage->guides.setHorizontalAutoRefer(pg.attribute("AGhorizontalAutoRefer", "0").toInt());
02737                             Apage->guides.setVerticalAutoRefer(pg.attribute("AGverticalAutoRefer", "0").toInt());
02738                             GuideManagerIO::readVerticalGuides(pg.attribute("VerticalGuides"),
02739                                                                                     Apage,
02740                                                                                     GuideManagerCore::Standard,
02741                                                                                     pg.hasAttribute("NumVGuides"));
02742                             GuideManagerIO::readHorizontalGuides(pg.attribute("HorizontalGuides"),
02743                                                                                     Apage,
02744                                                                                     GuideManagerCore::Standard,
02745                                                                                     pg.hasAttribute("NumHGuides"));
02746                             GuideManagerIO::readSelection(pg.attribute("AGSelection"), Apage);
02747                             
02748                      }
02749                      if ((pg.tagName()=="PAGEOBJECT") || (pg.tagName()=="MASTEROBJECT") || (pg.tagName()=="FRAMEOBJECT"))
02750                      {
02751                             if (Mpage)
02752                             {
02753                                    if (pg.tagName() != "MASTEROBJECT")
02754                                    {
02755                                           PAGE=PAGE.nextSibling();
02756                                           continue;
02757                                    }
02758                             }
02759                             else
02760                             {
02761                                    if (pg.tagName() == "MASTEROBJECT")
02762                                    {
02763                                           PAGE=PAGE.nextSibling();
02764                                           continue;
02765                                    }
02766                             }
02767                             if (pg.attribute("OwnPage").toInt() != pageNumber)
02768                             {                    
02769                                    if (pg.tagName()=="PAGEOBJECT")
02770                                           itemRemap[itemCount++] = -1;
02771                                    else if (pg.tagName()=="MASTEROBJECT")
02772                                           itemRemapM[itemCountM++] = -1;
02773                             }
02774                             else
02775 //                          if (pg.attribute("OwnPage").toInt() == pageNumber)
02776                             {
02777                                    // first of linked chain?
02778                                    if (pg.tagName()=="PAGEOBJECT")
02779                                    {
02780                                           itemRemap[itemCount++] = m_Doc->DocItems.count();
02781                                           if (pg.attribute("NEXTITEM").toInt() != -1)
02782                                                  itemNext[m_Doc->DocItems.count()] = pg.attribute("NEXTITEM").toInt();
02783                                    }
02784                                    else if (pg.tagName()=="MASTEROBJECT")
02785                                    {
02786                                           itemRemapM[itemCountM++] = m_Doc->MasterItems.count();
02787                                           if (pg.attribute("NEXTITEM").toInt() != -1)
02788                                                  itemNextM[m_Doc->MasterItems.count()] = pg.attribute("NEXTITEM").toInt();
02789                                    }
02790                                    /* not sure if we want that...
02791                                    else if (pg.tagName()=="FRAMEOBJECT")
02792                                    {
02793                                           itemRemapF[itemCountF++] = m_Doc->FrameItems->count();
02794                                           if (pg.attribute("NEXTITEM").toInt() != -1)
02795                                                  itemNextF[m_Doc->FrameItems->count()] = pg.attribute("NEXTITEM").toInt();
02796                                    }*/
02797                                    int docGc = m_Doc->GroupCounter;
02798                                    m_Doc->GroupCounter = 0;
02799                                    Neu = PasteItem(&pg, m_Doc);
02800                                    Neu->moveBy(-pageX + Apage->xOffset(), - pageY + Apage->yOffset());
02801                                    Neu->setRedrawBounding();
02802                                    //CB Must run onpage as we cant use pagetoload if the page has been renamed. 
02803                                    //CB TODO Make this accept a page to place onto.
02804                                    //Neu->OwnPage = m_Doc->OnPage(Neu);
02805                                    //Neu->OwnPage = PageToLoad;
02806                                    Neu->OwnPage = m_Doc->currentPageNumber();
02807                                    if (pg.tagName()=="PAGEOBJECT")
02808                                           Neu->OnMasterPage = "";
02809                                    m_Doc->GroupCounter = docGc;
02810                                    tmpf = pg.attribute("IFONT", m_Doc->toolSettings.defFont);
02811                                    m_AvailableFonts->findFont(tmpf, m_Doc);
02812                                    QDomNode IT=pg.firstChild();
02813                                    LastStyles * last = new LastStyles();
02814                                    while(!IT.isNull())
02815                                    {
02816                                           QDomElement it=IT.toElement();
02817                                           if (it.tagName()=="CSTOP")
02818                                           {
02819                                                  QString name = it.attribute("NAME");
02820                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
02821                                                  int shade = it.attribute("SHADE", "100").toInt();
02822                                                  double opa = it.attribute("TRANS", "1").toDouble();
02823                                                  Neu->fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
02824                                           }
02825                                           if (it.tagName()=="ITEXT")
02826                                                  GetItemText(&it, m_Doc, Neu, last, true, VorLFound);
02827                                           else if (it.tagName()=="para") {
02828                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PARSEP);
02829                                                  ParagraphStyle newStyle;
02830                                                  PrefsManager* prefsManager=PrefsManager::instance();
02831                                                  readParagraphStyle(newStyle, it, prefsManager->appPrefs.AvailFonts, m_Doc);
02832                                                  Neu->itemText.setStyle(Neu->itemText.length()-1, newStyle);
02833                                                  Neu->itemText.setCharStyle(Neu->itemText.length()-1, 1, last->Style);
02834                                           }
02835                                           else if (it.tagName()=="tab") {
02836                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::TAB);
02837                                           }
02838                                           else if (it.tagName()=="breakline") {
02839                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::LINEBREAK);
02840                                           }
02841                                           else if (it.tagName()=="breakcol") {
02842                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::COLBREAK);
02843                                           }
02844                                           else if (it.tagName()=="breakframe") {
02845                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::FRAMEBREAK);
02846                                           }
02847                                           else if (it.tagName()=="var" && it.attribute("name")=="pgno") 
02848                                           {
02849                                                  Neu->itemText.insertChars(Neu->itemText.length(), SpecialChars::PAGENUMBER);
02850                                           }
02851                                           
02852                                           if(it.tagName()=="PageItemAttributes")
02853                                           {
02854                                                  QDomNode PIA = it.firstChild();
02855                                                  ObjAttrVector pageItemAttributes;
02856                                                  while(!PIA.isNull())
02857                                                  {
02858                                                         QDomElement itemAttr = PIA.toElement();
02859                                                         if(itemAttr.tagName() == "ItemAttribute")
02860                                                         {
02861                                                                ObjectAttribute objattr;
02862                                                                objattr.name=itemAttr.attribute("Name");
02863                                                                objattr.type=itemAttr.attribute("Type");
02864                                                                objattr.value=itemAttr.attribute("Value");
02865                                                                objattr.parameter=itemAttr.attribute("Parameter");
02866                                                                objattr.relationship=itemAttr.attribute("Relationship");
02867                                                                objattr.relationshipto=itemAttr.attribute("RelationshipTo");
02868                                                                objattr.autoaddto=itemAttr.attribute("AutoAddTo");
02869                                                                pageItemAttributes.append(objattr);
02870                                                         }
02871                                                         PIA = PIA.nextSibling();
02872                                                  }
02873                                                  Neu->setObjectAttributes(&pageItemAttributes);
02874                                           }
02875                                           IT=IT.nextSibling();
02876                                    }
02877                                    delete last;
02878                                    if (Neu->asPathText())
02879                                    {
02880                                           Neu->updatePolyClip();
02881                                           Neu->Frame = true;
02882                                    }
02883                                    if (Neu->fill_gradient.Stops() == 0)
02884                                    {
02885                                           const ScColor& col1 = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
02886                                           const ScColor& col2 = m_Doc->PageColors[m_Doc->toolSettings.dPen];
02887                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
02888                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
02889                                    }
02890 //                                 Neu->Language = ScMW->GetLang(pg.attribute("LANGUAGE", m_Doc->Language));
02891 //                                 Neu->Language = m_Doc->Language;
02892                                    Neu->isAutoText = static_cast<bool>(pg.attribute("AUTOTEXT").toInt());
02893                                    Neu->isEmbedded = static_cast<bool>(pg.attribute("isInline", "0").toInt());
02894                                    Neu->gXpos = pg.attribute("gXpos", "0.0").toDouble();
02895                                    Neu->gYpos = pg.attribute("gYpos", "0.0").toDouble();
02896                                    QString defaultVal;
02897                                    defaultVal.setNum(Neu->width());
02898                                    Neu->gWidth = pg.attribute("gWidth",defaultVal).toDouble();
02899                                    defaultVal.setNum(Neu->height());
02900                                    Neu->gHeight = pg.attribute("gHeight",defaultVal).toDouble();
02901                                    if (Neu->isAutoText)
02902                                           m_Doc->LastAuto = Neu;
02903                                    if (Neu->isTableItem)
02904                                    {
02905                                           TableItems.append(Neu);
02906                                           TableID.insert(pg.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
02907                                    }
02908                                    Neu->isGroupControl = static_cast<bool>(pg.attribute("isGroupControl", "0").toInt());
02909                                    if (Neu->isGroupControl)
02910                                    {
02911                                           if (Neu->Groups.count() == 0) // Sanity check for some broken files created using buggy development versions.
02912                                           {
02913                                                  Neu->isGroupControl = false;
02914                                                  Neu->setFillColor("None");
02915                                           }
02916                                           else
02917                                                  groupID.insert(Neu, pg.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
02918                                    }
02919                                    if (pg.tagName()=="FRAMEOBJECT")
02920                                    {
02921                                           m_Doc->FrameItems.append(m_Doc->Items->take(Neu->ItemNr));
02922                                           Neu->ItemNr = m_Doc->FrameItems.count()-1;
02923                                    }
02924                             }
02925                             counter++;
02926                      }
02927                      PAGE=PAGE.nextSibling();
02928               }
02929               PAGE=DOC.firstChild();
02930               while(!PAGE.isNull())
02931               {
02932                      QDomElement pg=PAGE.toElement();
02933                      if(pg.tagName()=="Bookmark")
02934                      {
02935                             uint elem = pg.attribute("Element").toInt();
02936                             if (elem < m_Doc->Items->count())
02937                             {
02938                                    bok.Title = pg.attribute("Title");
02939                                    bok.Text = pg.attribute("Text");
02940                                    bok.Aktion = pg.attribute("Aktion");
02941                                    bok.ItemNr = pg.attribute("ItemNr").toInt();
02942                                    bok.PageObject = m_Doc->Items->at(elem);
02943                                    bok.First = pg.attribute("First").toInt();
02944                                    bok.Last = pg.attribute("Last").toInt();
02945                                    bok.Prev = pg.attribute("Prev").toInt();
02946                                    bok.Next = pg.attribute("Next").toInt();
02947                                    bok.Parent = pg.attribute("Parent").toInt();
02948                                    m_Doc->BookMarks.append(bok);
02949                             }
02950                      }
02951                      if(pg.tagName()=="Pattern")
02952                      {
02953                             ScPattern pat;
02954                             QDomNode pa = PAGE.firstChild();
02955                             uint ac = m_Doc->Items->count();
02956                             bool savedAlignGrid = m_Doc->useRaster;
02957                             bool savedAlignGuides = m_Doc->SnapGuides;
02958                             m_Doc->useRaster = false;
02959                             m_Doc->SnapGuides = false;
02960                             while(!pa.isNull())
02961                             {
02962                                    QDomElement pite = pa.toElement();
02963                                    m_Doc->setMasterPageMode(false);
02964                                    // first of linked chain?
02965                                    if (pg.tagName()=="PAGEOBJECT")
02966                                    {
02967                                           itemRemap[itemCount++] = m_Doc->DocItems.count();
02968                                           if (pg.attribute("NEXTITEM").toInt() != -1)
02969                                                  itemNext[m_Doc->DocItems.count()] = pg.attribute("NEXTITEM").toInt();
02970                                    }
02971                                    /* not sure if we want that...
02972                                    else if (pg.tagName()=="MASTEROBJECT")
02973                                    {
02974                                           itemRemapM[itemCountM++] = m_Doc->MasterItems->count();
02975                                           if (pg.attribute("NEXTITEM").toInt() != -1)
02976                                                  itemNextM[m_Doc->MasterItems->count()] = pg.attribute("NEXTITEM").toInt();
02977                                    }
02978                                    else if (pg.tagName()=="FRAMEOBJECT")
02979                                    {
02980                                                  itemRemapF[itemCountF++] = m_Doc->FrameItems->count();
02981                                                  if (pg.attribute("NEXTITEM").toInt() != -1)
02982                                                         itemNextF[m_Doc->FrameItems->count()] = pg.attribute("NEXTITEM").toInt();
02983                                    }*/
02984                                    int docGc = m_Doc->GroupCounter;
02985                                    m_Doc->GroupCounter = 0;
02986                                    Neu = PasteItem(&pite, m_Doc);
02987                                    Neu->setRedrawBounding();
02988                                    Neu->OwnPage = pite.attribute("OwnPage").toInt();
02989                                    Neu->OnMasterPage = "";
02990                                    m_Doc->GroupCounter = docGc;
02991                                    tmpf = pite.attribute("IFONT", m_Doc->toolSettings.defFont);
02992                                    m_AvailableFonts->findFont(tmpf, m_Doc);
02993                                    QDomNode IT=pite.firstChild();
02994                                    LastStyles * last = new LastStyles();
02995                                    while(!IT.isNull())
02996                                    {
02997                                           QDomElement it=IT.toElement();
02998                                           if (it.tagName()=="CSTOP")
02999                                           {
03000                                                  QString name = it.attribute("NAME");
03001                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
03002                                                  int shade = it.attribute("SHADE", "100").toInt();
03003                                                  double opa = it.attribute("TRANS", "1").toDouble();
03004                                                  Neu->fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
03005                                           }
03006                                           if (it.tagName()=="ITEXT")
03007                                                  GetItemText(&it, m_Doc, Neu, last);
03008                                           if(it.tagName()=="PageItemAttributes")
03009                                           {
03010                                                  QDomNode PIA = it.firstChild();
03011                                                  ObjAttrVector pageItemAttributes;
03012                                                  while(!PIA.isNull())
03013                                                  {
03014                                                         QDomElement itemAttr = PIA.toElement();
03015                                                         if(itemAttr.tagName() == "ItemAttribute")
03016                                                         {
03017                                                                ObjectAttribute objattr;
03018                                                                objattr.name=itemAttr.attribute("Name");
03019                                                                objattr.type=itemAttr.attribute("Type");
03020                                                                objattr.value=itemAttr.attribute("Value");
03021                                                                objattr.parameter=itemAttr.attribute("Parameter");
03022                                                                objattr.relationship=itemAttr.attribute("Relationship");
03023                                                                objattr.relationshipto=itemAttr.attribute("RelationshipTo");
03024                                                                objattr.autoaddto=itemAttr.attribute("AutoAddTo");
03025                                                                pageItemAttributes.append(objattr);
03026                                                         }
03027                                                         PIA = PIA.nextSibling();
03028                                                  }
03029                                                  Neu->setObjectAttributes(&pageItemAttributes);
03030                                           }
03031                                           IT=IT.nextSibling();
03032                                    }
03033                                    delete last;
03034                                    if (Neu->asPathText())
03035                                    {
03036                                           Neu->updatePolyClip();
03037                                           Neu->Frame = true;
03038                                    }
03039                                    if (Neu->fill_gradient.Stops() == 0)
03040                                    {
03041                                           const ScColor& col1 = m_Doc->PageColors[m_Doc->toolSettings.dBrush];
03042                                           const ScColor& col2 = m_Doc->PageColors[m_Doc->toolSettings.dPen];
03043                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, m_Doc), 0.0, 0.5, 1.0, m_Doc->toolSettings.dBrush, 100);
03044                                           Neu->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, m_Doc), 1.0, 0.5, 1.0, m_Doc->toolSettings.dPen, 100);
03045                                    }
03046                                    Neu->isAutoText = static_cast<bool>(pite.attribute("AUTOTEXT").toInt());
03047                                    Neu->isEmbedded = static_cast<bool>(pite.attribute("isInline", "0").toInt());
03048                                    Neu->gXpos = pite.attribute("gXpos", "0.0").toDouble();
03049                                    Neu->gYpos = pite.attribute("gYpos", "0.0").toDouble();
03050                                    QString defaultVal;
03051                                    defaultVal.setNum(Neu->width());
03052                                    Neu->gWidth = pite.attribute("gWidth",defaultVal).toDouble();
03053                                    defaultVal.setNum(Neu->height());
03054                                    Neu->gHeight = pite.attribute("gHeight",defaultVal).toDouble();
03055                                    if (Neu->isTableItem)
03056                                    {
03057                                           TableItems.append(Neu);
03058                                           TableID.insert(pite.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
03059                                    }
03060                                    Neu->isGroupControl = static_cast<bool>(pite.attribute("isGroupControl", "0").toInt());
03061                                    if (Neu->isGroupControl)
03062                                    {
03063                                           if (Neu->Groups.count() == 0) // Sanity check for some broken files created using buggy development versions.
03064                                           {
03065                                                  Neu->isGroupControl = false;
03066                                                  Neu->setFillColor("None");
03067                                           }
03068                                           else
03069                                                  groupID.insert(Neu, pite.attribute("groupsLastItem", "0").toInt()+Neu->ItemNr);
03070                                    }
03071                                    pa = pa.nextSibling();
03072                             }
03073                             m_Doc->useRaster = savedAlignGrid;
03074                             m_Doc->SnapGuides = savedAlignGuides;
03075                             uint ae = m_Doc->Items->count();
03076                             pat.setDoc(m_Doc);
03077                             PageItem* currItem = m_Doc->Items->at(ac);
03078                             pat.pattern = currItem->DrawObj_toImage();
03079                             for (uint as = ac; as < ae; ++as)
03080                             {
03081                                    Neu = m_Doc->Items->take(ac);
03082                                    Neu->ItemNr = pat.items.count();
03083                                    pat.items.append(Neu);
03084                             }
03085                             pat.width = pg.attribute("width", "0").toDouble();
03086                             pat.height = pg.attribute("height", "0").toDouble();
03087                             pat.scaleX = pg.attribute("scaleX", "0").toDouble();
03088                             pat.scaleY = pg.attribute("scaleY", "0").toDouble();
03089                             m_Doc->docPatterns.insert(pg.attribute("Name"), pat);
03090                      }
03091                      PAGE=PAGE.nextSibling();
03092               }
03093               DOC=DOC.nextSibling();
03094        }
03095        if (TableItems.count() != 0)
03096        {
03097               for (uint ttc = 0; ttc < TableItems.count(); ++ttc)
03098               {
03099                      PageItem* ta = TableItems.at(ttc);
03100                      if (ta->TopLinkID != -1)
03101                             ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
03102                      else
03103                             ta->TopLink = 0;
03104                      if (ta->LeftLinkID != -1)
03105                             ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
03106                      else
03107                             ta->LeftLink = 0;
03108                      if (ta->RightLinkID != -1)
03109                             ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
03110                      else
03111                             ta->RightLink = 0;
03112                      if (ta->BottomLinkID != -1)
03113                             ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
03114                      else
03115                             ta->BottomLink = 0;
03116               }
03117        }
03118        if (groupID.count() != 0)
03119        {
03120               QMap<PageItem*, int>::Iterator it;
03121               for (it = groupID.begin(); it != groupID.end(); ++it)
03122               {
03123                      it.key()->groupsLastItem = m_Doc->Items->at(it.data());
03124               }
03125        }
03126        
03127        // reestablish textframe links
03128        if (itemNext.count() != 0 && !Mpage)
03129        {
03130               QMap<int,int>::Iterator lc;
03131               for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
03132               {
03133                      if (itemRemap[lc.data()] >= 0)
03134                      {
03135                             if ((static_cast<uint>(lc.key()) < m_Doc->Items->count()) && (static_cast<uint>(itemRemap[lc.data()]) < m_Doc->Items->count()))
03136                             {
03137                                    PageItem * Its = m_Doc->DocItems.at(lc.key());
03138                                    PageItem * Itn = m_Doc->DocItems.at(itemRemap[lc.data()]);
03139                                    if (Itn->prevInChain() || Its->nextInChain()) 
03140                                    {
03141                                           qDebug("scribus134format: corruption in linked textframes detected");
03142                                           continue;
03143                                    }
03144                                    Its->link(Itn);
03145                             }
03146                      }
03147               }
03148        }
03149        else if (itemNextM.count() != 0 && Mpage)
03150        {
03151               QMap<int,int>::Iterator lc;
03152               for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
03153               {
03154                      if (itemRemapM[lc.data()] >= 0)
03155                      {
03156                             if ((static_cast<uint>(lc.key()) < m_Doc->MasterItems.count()) && (static_cast<uint>(itemRemapM[lc.data()]) < m_Doc->MasterItems.count()))
03157                             {
03158                                    PageItem * Its = m_Doc->MasterItems.at(lc.key());
03159                                    PageItem * Itn = m_Doc->MasterItems.at(itemRemapM[lc.data()]);
03160                                    if (Itn->prevInChain() || Its->nextInChain()) 
03161                                    {
03162                                           qDebug("scribus134format: corruption in linked textframes detected");
03163                                           continue;
03164                                    }
03165                                    Its->link(Itn);
03166                             }
03167                      }
03168               }
03169        }
03170        
03171        // reestablish first/lastAuto
03172        m_Doc->FirstAuto = m_Doc->LastAuto;
03173        if (m_Doc->LastAuto)
03174        {
03175               while (m_Doc->LastAuto->nextInChain())
03176                      m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
03177               while (m_Doc->FirstAuto->prevInChain())
03178                      m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
03179        }
03180 
03181        return true;
03182 }
03183 
03184 void Scribus134Format::GetStyle(QDomElement *pg, ParagraphStyle *vg, StyleSet<ParagraphStyle> * tempStyles, ScribusDoc* doc, bool fl)
03185 {
03186        bool fou;
03187        QString tmpf, tmf, tmV;
03188        fou = false;
03189        const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? tempStyles : & doc->paragraphStyles();
03190        PrefsManager* prefsManager=PrefsManager::instance();
03191        readParagraphStyle(*vg, *pg, prefsManager->appPrefs.AvailFonts, doc);
03192        for (uint xx=0; xx<docParagraphStyles->count(); ++xx)
03193        {
03194               if (vg->name() == (*docParagraphStyles)[xx].name())
03195               {
03196                      if (vg->equiv((*docParagraphStyles)[xx]))
03197                      {
03198                             if (fl)
03199                             {
03200                                    DoVorl[VorlC] = tmV.setNum(xx);
03201                                    VorlC++;
03202                             }
03203                             fou = true;
03204                      }
03205                      else
03206                      {
03207                             vg->setName("Copy of "+(*docParagraphStyles)[xx].name());
03208                             fou = false;
03209                      }
03210                      break;
03211               }
03212        }
03213        if (!fou)
03214        {
03215               for (uint xx=0; xx< docParagraphStyles->count(); ++xx)
03216               {
03217                      if (vg->equiv((*docParagraphStyles)[xx]))
03218                      {
03219                             vg->setName((*docParagraphStyles)[xx].name());
03220                             fou = true;
03221                             if (fl)
03222                             {
03223                                    DoVorl[VorlC] = tmV.setNum(xx);
03224                                    VorlC++;
03225                             }
03226                             break;
03227                      }
03228               }
03229        }
03230        if (!fou)
03231        {
03232               if (tempStyles)
03233                      tempStyles->create(*vg);
03234               else
03235               {
03236                      StyleSet<ParagraphStyle> tmp;
03237                      tmp.create(*vg);
03238                      doc->redefineStyles(tmp, false);
03239               }
03240               if (fl)
03241               {
03242                      DoVorl[VorlC] = tmV.setNum(docParagraphStyles->count()-1);
03243                      VorlC++;
03244               }
03245        }
03246 }
03247 
03248 
03249 bool Scribus134Format::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles)
03250 {
03251        ParagraphStyle vg;
03252        QDomDocument docu("scridoc");
03253        QString tmpf, tmf;
03254        QString f (readSLA(fileName));
03255        if (f.isEmpty())
03256               return false;
03257        if(!docu.setContent(f))
03258               return false;
03259        QDomElement elem=docu.documentElement();
03260        if (elem.tagName() != "SCRIBUSUTF8NEW")
03261               return false;
03262        QDomNode DOC=elem.firstChild();
03263        while(!DOC.isNull())
03264        {
03265               QDomElement dc=DOC.toElement();
03266               QDomNode PAGE=DOC.firstChild();
03267               while(!PAGE.isNull())
03268               {
03269                      QDomElement pg=PAGE.toElement();
03270                      if(pg.tagName()=="STYLE")
03271                             GetStyle(&pg, &vg, &docParagraphStyles, doc, false);
03272                      PAGE=PAGE.nextSibling();
03273               }
03274               DOC=DOC.nextSibling();
03275        }
03276        return true;
03277 }
03278 
03279 bool Scribus134Format::readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles)
03280 {
03281        CharStyle cstyle;
03282        QDomDocument docu("scridoc");
03283        QString tmpf, tmf;
03284        QString f (readSLA(fileName));
03285        if (f.isEmpty())
03286               return false;
03287        if(!docu.setContent(f))
03288               return false;
03289        QDomElement elem=docu.documentElement();
03290        if (elem.tagName() != "SCRIBUSUTF8NEW")
03291               return false;
03292        QDomNode DOC=elem.firstChild();
03293        while(!DOC.isNull())
03294        {
03295               QDomElement dc=DOC.toElement();
03296               QDomNode PAGE=DOC.firstChild();
03297               while(!PAGE.isNull())
03298               {
03299                      QDomElement pg=PAGE.toElement();
03300                      if(pg.tagName()=="CHARSTYLE")
03301                      {
03302                             GetCStyle(&pg, doc, cstyle);
03303                             docCharStyles.create(cstyle);
03304                      }
03305                      PAGE=PAGE.nextSibling();
03306               }
03307               DOC=DOC.nextSibling();
03308        }
03309        return true;
03310 }
03311 
03312 bool Scribus134Format::readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty)
03313 {
03314        QDomDocument docu("scridoc");
03315        QString f(readSLA(fileName));
03316        if (f.isEmpty())
03317               return false;
03318        if(!docu.setContent(f))
03319               return false;
03320        QDomElement elem=docu.documentElement();
03321        if (elem.tagName() != "SCRIBUSUTF8NEW")
03322               return false;
03323        QDomNode DOC=elem.firstChild();
03324        while(!DOC.isNull())
03325        {
03326               QDomElement dc=DOC.toElement();
03327               QDomNode PAGE=DOC.firstChild();
03328               while(!PAGE.isNull())
03329               {
03330                      QDomElement pg=PAGE.toElement();
03331                      if(pg.tagName()=="MultiLine")
03332                      {
03333                             multiLine ml;
03334                             QDomNode MuLn = PAGE.firstChild();
03335                             while(!MuLn.isNull())
03336                             {
03337                                    QDomElement MuL = MuLn.toElement();
03338                                    struct SingleLine sl;
03339                                    sl.Color = MuL.attribute("Color");
03340                                    sl.Dash = MuL.attribute("Dash").toInt();
03341                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
03342                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
03343                                    sl.Shade = MuL.attribute("Shade").toInt();
03344                                    sl.Width = MuL.attribute("Width").toDouble();
03345                                    ml.shortcut = MuL.attribute("Shortcut");
03346                                    ml.push_back(sl);
03347                                    MuLn = MuLn.nextSibling();
03348                             }
03349                             QString Nam = pg.attribute("Name");
03350                             QString Nam2 = Nam;
03351                             int copyC = 1;
03352                             QMap<QString,multiLine>::ConstIterator mlit = Sty->find(Nam2);
03353                             if (mlit != Sty->end() && ml != mlit.data())
03354                             {
03355                                    while (Sty->contains(Nam2))
03356                                    {
03357                                           Nam2 = tr("Copy #%1 of ").arg(copyC)+Nam;
03358                                           copyC++;
03359                                    }
03360                             }
03361                             Sty->insert(Nam2, ml);
03362                      }
03363                      PAGE=PAGE.nextSibling();
03364               }
03365               DOC=DOC.nextSibling();
03366        }
03367        return true;
03368 }
03369 
03370 bool Scribus134Format::readColors(const QString& fileName, ColorList & colors)
03371 {
03372        QString f(readSLA(fileName));
03373        if (f.isEmpty())
03374               return false;
03375        QDomDocument docu("scridoc");
03376        if(!docu.setContent(f))
03377               return false;
03378        colors.clear();
03379        ScColor lf = ScColor();
03380        QDomElement elem=docu.documentElement();
03381        if (elem.tagName() != "SCRIBUSUTF8NEW")
03382               return false;
03383        QDomNode DOC=elem.firstChild();
03384        while(!DOC.isNull())
03385        {
03386               QDomElement dc=DOC.toElement();
03387               QDomNode PAGE=DOC.firstChild();
03388               while(!PAGE.isNull())
03389               {
03390                      QDomElement pg=PAGE.toElement();
03391                      // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
03392                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
03393                      {
03394                             if (pg.hasAttribute("CMYK"))
03395                                    lf.setNamedColor(pg.attribute("CMYK"));
03396                             else
03397                                    lf.fromQColor(QColor(pg.attribute("RGB")));
03398                             if (pg.hasAttribute("Spot"))
03399                                    lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
03400                             else
03401                                    lf.setSpotColor(false);
03402                             if (pg.hasAttribute("Register"))
03403                                    lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
03404                             else
03405                                    lf.setRegistrationColor(false);
03406                             colors.insert(pg.attribute("NAME"), lf);
03407                      }
03408                      PAGE=PAGE.nextSibling();
03409               }
03410               DOC=DOC.nextSibling();
03411        }
03412        return true;
03413 }
03414 
03415 bool Scribus134Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
03416 {
03417        QString PgNam;
03418        int counter = 0;
03419        int counter2 = 0;
03420        QDomDocument docu("scridoc");
03421        QString f(readSLA(fileName));
03422        if (f.isEmpty())
03423               return false;
03424        if(!docu.setContent(f))
03425               return false;
03426        QDomElement elem=docu.documentElement();
03427        if (elem.tagName() != "SCRIBUSUTF8NEW")
03428               return false;
03429        QDomNode DOC=elem.firstChild();
03430        while(!DOC.isNull())
03431        {
03432               QDomNode PAGE=DOC.firstChild();
03433               while(!PAGE.isNull())
03434               {
03435                      QDomElement pg=PAGE.toElement();
03436                      PgNam = pg.attribute("NAM", "");
03437                      if(pg.tagName()=="PAGE")
03438                             counter++;
03439                      if(pg.tagName()=="MASTERPAGE")
03440                      {
03441                             counter2++;
03442                             masterPageNames.append(PgNam);
03443                      }
03444                      PAGE=PAGE.nextSibling();
03445               }
03446               DOC=DOC.nextSibling();
03447        }
03448        *num1 = counter;
03449        *num2 = counter2;
03450        return true;
03451 }
03452