Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scribus12format.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 "scribus12format.h"
00008 #include "scribus12format.moc"
00009 #include "scribus12formatimpl.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 
00019 #include "units.h"
00020 #include "util.h"
00021 #include "colorutil.h"
00022 #include "scgzfile.h"
00023 #include <qcursor.h>
00024 #include <qfileinfo.h>
00025 #include <qvaluelist.h>
00026 
00027 
00028 // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
00029 // do. That documentatation is not duplicated here.
00030 // Please don't implement the functionality of your plugin here; do that
00031 // in scribus12formatimpl.h and scribus12formatimpl.cpp .
00032 
00033 Scribus12Format::Scribus12Format() :
00034        LoadSavePlugin()
00035 {
00036        // Set action info in languageChange, so we only have to do
00037        // it in one place. This includes registering file formats.
00038        languageChange();
00039 }
00040 
00041 Scribus12Format::~Scribus12Format()
00042 {
00043        unregisterAll();
00044 };
00045 
00046 void Scribus12Format::languageChange()
00047 {
00048        //(Re)register file formats.
00049        unregisterAll();
00050        registerFormats();
00051 }
00052 
00053 const QString Scribus12Format::fullTrName() const
00054 {
00055        return QObject::tr("Scribus 1.2.x Support");
00056 }
00057 
00058 const ScActionPlugin::AboutData* Scribus12Format::getAboutData() const
00059 {
00060        AboutData* about = new AboutData;
00061        Q_CHECK_PTR(about);
00062        return about;
00063 }
00064 
00065 void Scribus12Format::deleteAboutData(const AboutData* about) const
00066 {
00067        Q_ASSERT(about);
00068        delete about;
00069 }
00070 
00071 // Low level plugin API
00072 int scribus12format_getPluginAPIVersion()
00073 {
00074        return PLUGIN_API_VERSION;
00075 }
00076 
00077 ScPlugin* scribus12format_getPlugin()
00078 {
00079        Scribus12Format* plug = new Scribus12Format();
00080        Q_CHECK_PTR(plug);
00081        return plug;
00082 }
00083 
00084 void scribus12format_freePlugin(ScPlugin* plugin)
00085 {
00086        Scribus12Format* plug = dynamic_cast<Scribus12Format*>(plugin);
00087        Q_ASSERT(plug);
00088        delete plug;
00089 }
00090 
00091 
00092 
00093 void Scribus12Format::registerFormats()
00094 {
00095        FileFormat fmt(this);
00096        fmt.trName = tr("Scribus 1.2.x Document");
00097        fmt.formatId = FORMATID_SLA12XIMPORT;
00098        fmt.load = true;
00099        fmt.save = false;
00100        fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
00101        fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", false);
00102        fmt.mimeTypes = QStringList();
00103        fmt.mimeTypes.append("application/x-scribus");
00104        fmt.priority = 64;
00105        registerFormat(fmt);
00106 }
00107 
00108 bool Scribus12Format::fileSupported(QIODevice* /* file */, const QString & fileName) const
00109 {
00110        QCString docBytes("");
00111        if(fileName.right(2) == "gz")
00112        {
00113               ScGzFile gzf(fileName);
00114               if (!gzf.read(4096))
00115               {
00116                      // FIXME: Needs better error return
00117                      return false;
00118               }
00119               docBytes = gzf.data();
00120        }
00121        else
00122        {
00123               // Not gzip encoded, just load it
00124               loadRawText(fileName, docBytes);
00125        }
00126        if (docBytes.left(16) != "<SCRIBUSUTF8NEW " && (docBytes.left(12) == "<SCRIBUSUTF8" || docBytes.left(9) == "<SCRIBUS>"))
00127               return true;
00128        return false;
00129 }
00130 
00131 QString Scribus12Format::readSLA(const QString & fileName)
00132 {
00133        QCString docBytes("");
00134        if(fileName.right(2) == "gz")
00135        {
00136               ScGzFile gzf(fileName);
00137               if (!gzf.read())
00138               {
00139                      // FIXME: Needs better error return
00140                      return false;
00141               }
00142               docBytes = gzf.data();
00143        }
00144        else
00145        {
00146               // Not gzip encoded, just load it
00147               loadRawText(fileName, docBytes);
00148        }
00149        QString docText("");
00150        if (docBytes.left(16) != "<SCRIBUSUTF8NEW ") // Not a 1.3.x doc
00151        {
00152               if (docBytes.left(12) == "<SCRIBUSUTF8") // 1.2.x UTF8 doc
00153                      docText = QString::fromUtf8(docBytes);
00154               else if (docBytes.left(9) == "<SCRIBUS>") // Older non utf8 doc
00155                      docText = QString::fromLocal8Bit(docBytes);
00156               else 
00157                      return QString::null;
00158        }
00159        else
00160        {
00161               qDebug("scribus12format: SCRIBUSUTF8NEW");
00162               return QString::null;
00163        }
00164        if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13)))
00165               docText.truncate(docText.length()-1);
00166        return docText;
00167 }
00168 
00169 
00170 void Scribus12Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QValueList<ScFace> &getDummyScFaces)
00171 {
00172        getNewReplacement=false;
00173        getReplacedFonts.clear();
00174        getDummyScFaces.clear();
00175 }
00176 
00177 
00178 static long scribus12itemID(int itemNr, int pageNr)
00179 {
00180        return itemNr * 100000 + pageNr; 
00181 }
00182 
00183 
00184 bool Scribus12Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */)
00185 {
00186        if (m_Doc==0 || m_View==0 || m_AvailableFonts==0)
00187        {
00188               Q_ASSERT(m_Doc==0 || m_View==0 || m_AvailableFonts==0);
00189               return false;
00190        }
00191 //     ReplacedFonts.clear();
00192 //     newReplacement = false;
00193 //     dummyScFaces.clear();
00194        DoVorl.clear();
00195        DoVorl[0] = "";
00196        DoVorl[1] = "";
00197        DoVorl[2] = "";
00198        DoVorl[3] = "";
00199        DoVorl[4] = "";
00200        VorlC = 5;
00201        
00202 //start old ReadDoc
00203        //Scribus 1.2 docs, see fileloader.cpp for 1.3 docs
00204        struct CopyPasteBuffer OB;
00205        ParagraphStyle vg;
00206        struct Layer la;
00207        struct ScribusDoc::BookMa bok;
00208        int counter;
00209        bool newVersion = false;
00210        QString tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
00211        QMap<int,int> TableID;
00212        QPtrList<PageItem> TableItems;
00213        int x, a;
00214 //     double xf, xf2;
00215        PageItem *Neu;
00216        itemRemap.clear();
00217        itemNext.clear();
00218        QDomDocument docu("scridoc");
00219        QFile fi(fileName);
00220        // Load the document text
00221        QString f(readSLA(fileName));
00222        if (f.isEmpty())
00223               return false;
00224        // Build the DOM from it
00225        if (!docu.setContent(f))
00226               return false;
00227        // and begin loading the doc
00228        m_Doc->PageColors.clear();
00229        m_Doc->Layers.clear();
00230        ScColor lf = ScColor();
00231        QDomElement elem=docu.documentElement();
00232        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
00233               return false;
00234        if (elem.hasAttribute("Version"))
00235               newVersion = true;
00236        QDomNode DOC=elem.firstChild();
00237        if (m_mwProgressBar!=0)
00238        {
00239               m_mwProgressBar->setTotalSteps(DOC.childNodes().count());
00240               m_mwProgressBar->setProgress(0);
00241        }
00242        int ObCount = 0;
00243        int activeLayer = 0;
00244        PrefsManager* prefsManager=PrefsManager::instance();
00245        while(!DOC.isNull())
00246        {
00247               QDomElement dc=DOC.toElement();
00248        /*
00249        * Attribute von DOCUMENT auslesen
00250        */
00251               if (dc.hasAttribute("PAGEWIDTH"))
00252                      m_Doc->pageWidth=dc.attribute("PAGEWIDTH").toDouble();
00253               else
00254                      m_Doc->pageWidth=dc.attribute("PAGEWITH").toDouble();
00255               m_Doc->pageHeight=dc.attribute("PAGEHEIGHT").toDouble();
00256               m_Doc->pageMargins.Left=QMAX(0.0, dc.attribute("BORDERLEFT").toDouble());
00257               m_Doc->pageMargins.Right=QMAX(0.0, dc.attribute("BORDERRIGHT").toDouble());
00258               m_Doc->pageMargins.Top=QMAX(0.0, dc.attribute("BORDERTOP").toDouble());
00259               m_Doc->pageMargins.Bottom=QMAX(0.0, dc.attribute("BORDERBOTTOM").toDouble());
00260               m_Doc->PageOri = dc.attribute("ORIENTATION", "0").toInt();
00261               m_Doc->m_pageSize = dc.attribute("PAGESIZE");
00262               m_Doc->FirstPnum = dc.attribute("FIRSTNUM", "1").toInt();
00263               m_Doc->currentPageLayout=dc.attribute("BOOK", "0").toInt();
00264               int fp;
00265               if (dc.attribute("FIRSTLEFT", "0").toInt() == 1)
00266                      fp = 0;
00267               else
00268                      fp = 1;
00269               if (m_Doc->currentPageLayout == 0)
00270                      fp = 0;
00271               m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = fp;
00272               m_Doc->setUsesAutomaticTextFrames(dc.attribute("AUTOTEXT").toInt());
00273               m_Doc->PageSp=dc.attribute("AUTOSPALTEN").toInt();
00274               m_Doc->PageSpa=dc.attribute("ABSTSPALTEN").toDouble();
00275               m_Doc->setUnitIndex(dc.attribute("UNITS", "0").toInt());
00276               m_Doc->guidesSettings.gridShown = prefsManager->appPrefs.guidesSettings.gridShown;
00277               m_Doc->guidesSettings.guidesShown = prefsManager->appPrefs.guidesSettings.guidesShown;
00278               m_Doc->guidesSettings.colBordersShown = prefsManager->appPrefs.guidesSettings.colBordersShown;
00279               m_Doc->guidesSettings.framesShown = prefsManager->appPrefs.guidesSettings.framesShown;
00280               m_Doc->guidesSettings.layerMarkersShown = prefsManager->appPrefs.guidesSettings.layerMarkersShown;
00281               m_Doc->guidesSettings.marginsShown = prefsManager->appPrefs.guidesSettings.marginsShown;
00282               m_Doc->guidesSettings.baseShown = prefsManager->appPrefs.guidesSettings.baseShown;
00283               m_Doc->guidesSettings.linkShown = prefsManager->appPrefs.guidesSettings.linkShown;
00284               m_Doc->guidesSettings.showPic = true;
00285               m_Doc->guidesSettings.showControls = false;
00286 //            DoFonts.clear();
00287               m_Doc->toolSettings.defSize=qRound(dc.attribute("DSIZE").toDouble() * 10);
00288               Defont=dc.attribute("DFONT");
00289               m_Doc->toolSettings.defFont = prefsManager->appPrefs.toolSettings.defFont;
00290               m_AvailableFonts->findFont(Defont, m_Doc);
00291               m_Doc->toolSettings.defFont = Defont;
00292               m_Doc->toolSettings.dCols=dc.attribute("DCOL", "1").toInt();
00293               m_Doc->toolSettings.dGap=dc.attribute("DGAP", "0.0").toDouble();
00294               m_Doc->documentInfo.setAuthor(dc.attribute("AUTHOR"));
00295               m_Doc->documentInfo.setComments(dc.attribute("COMMENTS"));
00296               m_Doc->documentInfo.setKeywords(dc.attribute("KEYWORDS",""));
00297               m_Doc->documentInfo.setTitle(dc.attribute("TITLE"));
00298               m_Doc->documentInfo.setPublisher(dc.attribute("PUBLISHER", ""));
00299               m_Doc->documentInfo.setDate(dc.attribute("DOCDATE", ""));
00300               m_Doc->documentInfo.setType(dc.attribute("DOCTYPE", ""));
00301               m_Doc->documentInfo.setFormat(dc.attribute("DOCFORMAT", ""));
00302               m_Doc->documentInfo.setIdent(dc.attribute("DOCIDENT", ""));
00303               m_Doc->documentInfo.setSource(dc.attribute("DOCSOURCE", ""));
00304               m_Doc->documentInfo.setLangInfo(dc.attribute("DOCLANGINFO", ""));
00305               m_Doc->documentInfo.setRelation(dc.attribute("DOCRELATION", ""));
00306               m_Doc->documentInfo.setCover(dc.attribute("DOCCOVER", ""));
00307               m_Doc->documentInfo.setRights(dc.attribute("DOCRIGHTS", ""));
00308               m_Doc->documentInfo.setContrib(dc.attribute("DOCCONTRIB", ""));
00309               m_Doc->typographicSettings.valueSuperScript = dc.attribute("VHOCH").toInt();
00310               m_Doc->typographicSettings.scalingSuperScript = dc.attribute("VHOCHSC").toInt();
00311               m_Doc->typographicSettings.valueSubScript = dc.attribute("VTIEF").toInt();
00312               m_Doc->typographicSettings.scalingSubScript = dc.attribute("VTIEFSC").toInt();
00313               m_Doc->typographicSettings.valueSmallCaps = dc.attribute("VKAPIT").toInt();
00314               m_Doc->typographicSettings.valueBaseGrid = dc.attribute("BASEGRID", "12").toDouble();
00315               m_Doc->typographicSettings.offsetBaseGrid = dc.attribute("BASEO", "0").toDouble();
00316               m_Doc->typographicSettings.autoLineSpacing = dc.attribute("AUTOL", "20").toInt();
00317               m_Doc->GroupCounter=dc.attribute("GROUPC", "1").toInt();
00318               //m_Doc->HasCMS = static_cast<bool>(dc.attribute("HCMS", "0").toInt());
00319               m_Doc->CMSSettings.SoftProofOn = static_cast<bool>(dc.attribute("DPSo", "0").toInt());
00320               m_Doc->CMSSettings.SoftProofFullOn = static_cast<bool>(dc.attribute("DPSFo", "0").toInt());
00321               m_Doc->CMSSettings.CMSinUse = static_cast<bool>(dc.attribute("DPuse", "0").toInt());
00322               m_Doc->CMSSettings.GamutCheck = static_cast<bool>(dc.attribute("DPgam", "0").toInt());
00323               m_Doc->CMSSettings.BlackPoint = static_cast<bool>(dc.attribute("DPbla", "1").toInt());
00324               m_Doc->CMSSettings.DefaultMonitorProfile = dc.attribute("DPMo","");
00325               m_Doc->CMSSettings.DefaultPrinterProfile = dc.attribute("DPPr","");
00326               m_Doc->CMSSettings.DefaultImageRGBProfile = dc.attribute("DPIn","");
00327               m_Doc->CMSSettings.DefaultImageCMYKProfile = dc.attribute("DPPr",""); // Use DPPr to match 1.2.x behavior
00328               m_Doc->CMSSettings.DefaultSolidColorRGBProfile = dc.attribute("DPIn2","");
00329               m_Doc->CMSSettings.DefaultSolidColorCMYKProfile = dc.attribute("DPPr",""); // Use DPPr to match 1.2.x behavior
00330               //m_Doc->CMSSettings.DefaultIntentPrinter = dc.attribute("DIPr", "0").toInt();
00331               //m_Doc->CMSSettings.DefaultIntentMonitor = dc.attribute("DIMo", "1").toInt();
00332               m_Doc->CMSSettings.DefaultIntentColors = dc.attribute("DISc", "1").toInt();
00333               m_Doc->CMSSettings.DefaultIntentImages = dc.attribute("DIIm", "0").toInt();
00334               activeLayer = dc.attribute("ALAYER", "0").toInt();
00335               m_Doc->Language = dc.attribute("LANGUAGE", "");
00336               m_Doc->MinWordLen = dc.attribute("MINWORDLEN", "3").toInt();
00337               m_Doc->HyCount = dc.attribute("HYCOUNT", "2").toInt();
00338               m_Doc->Automatic = static_cast<bool>(dc.attribute("AUTOMATIC", "1").toInt());
00339               m_Doc->AutoCheck = static_cast<bool>(dc.attribute("AUTOCHECK", "0").toInt());
00340               m_Doc->GuideLock = static_cast<bool>(dc.attribute("GUIDELOCK", "0").toInt());
00341               m_Doc->SnapGuides = static_cast<bool>(dc.attribute("SnapToGuides", "0").toInt());
00342               m_Doc->useRaster = static_cast<bool>(dc.attribute("SnapToGrid", "0").toInt());
00343               m_Doc->guidesSettings.minorGrid = dc.attribute("MINGRID", tmp.setNum(prefsManager->appPrefs.guidesSettings.minorGrid)).toDouble();
00344               m_Doc->guidesSettings.majorGrid = dc.attribute("MAJGRID", tmp.setNum(prefsManager->appPrefs.guidesSettings.majorGrid)).toDouble();
00345               m_Doc->toolSettings.dStartArrow = 0;
00346               m_Doc->toolSettings.dEndArrow = 0;
00347               m_Doc->LastAuto = 0;
00348               QDomNode PAGE=DOC.firstChild();
00349               counter = 0;
00350               while(!PAGE.isNull())
00351               {
00352                      ObCount++;
00353                      if (m_mwProgressBar!=0)
00354                             m_mwProgressBar->setProgress(ObCount);
00355                      QDomElement pg=PAGE.toElement();
00356                      // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
00357                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
00358                      {
00359                             if (pg.hasAttribute("CMYK"))
00360                                    lf.setNamedColor(pg.attribute("CMYK"));
00361                             else
00362                                    lf.fromQColor(QColor(pg.attribute("RGB")));
00363                             lf.setSpotColor(false);
00364                             lf.setRegistrationColor(false);
00365                             m_Doc->PageColors.insert(pg.attribute("NAME"), lf);
00366                      }
00367                      if(pg.tagName()=="STYLE")
00368                      {
00369                             vg.erase();
00370                             GetStyle(&pg, &vg, NULL, m_Doc, true);
00371 #if 0
00372                             vg.setName(pg.attribute("NAME"));
00373                             vg.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg.attribute("LINESPMode", "0").toInt()));
00374                             vg.setLineSpacing(pg.attribute("LINESP").toDouble());
00375                             vg.setLeftMargin(pg.attribute("INDENT", "0").toDouble());
00376                             vg.setFirstIndent(pg.attribute("FIRST", "0").toDouble());
00377                             vg.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pg.attribute("ALIGN").toInt()));
00378                             vg.setGapBefore(pg.attribute("VOR", "0").toDouble());
00379                             vg.setGapAfter(pg.attribute("NACH", "0").toDouble());
00380                             tmpf = pg.attribute("FONT", m_Doc->toolSettings.defFont);
00381                             
00382                             m_AvailableFonts->findFont(tmpf, m_Doc));
00383                             vg.charStyle().setFont((*m_AvailableFonts)[tmpf]);
00384                             vg.charStyle().setFontSize(qRound(pg.attribute("FONTSIZE", "12").toDouble() * 10.0));
00385                             vg.setHasDropCap(static_cast<bool>(pg.attribute("DROP", "0").toInt()));
00386                             vg.setDropCapLines(pg.attribute("DROPLIN", "2").toInt());
00387                             vg.setDropCapOffset(pg.attribute("DROPDIST", "0").toDouble());
00388                             vg.charStyle().setFeatures(static_cast<StyleFlag>(pg.attribute("EFFECT", "0").toInt()).featureList());
00389                             QString fColor = pg.attribute("FCOLOR", m_Doc->toolSettings.dBrush);
00390                             int fShade = pg.attribute("FSHADE", "100").toInt();
00391                             handleOldColorShade(m_Doc, fColor, fShade);
00392                             QString sColor = pg.attribute("SCOLOR", m_Doc->toolSettings.dPen);
00393                             int sShade = pg.attribute("SSHADE", "100").toInt();
00394                             handleOldColorShade(m_Doc, sColor, sShade);
00395                             vg.charStyle().setFillColor(fColor);
00396                             vg.charStyle().setFillShade(fShade);
00397                             vg.charStyle().setStrokeColor(sColor);
00398                             vg.charStyle().setStrokeShade(sShade);
00399                             if (static_cast<bool>(pg.attribute("BASE", "0").toInt()))
00400                                    vg.setLineSpacingMode(ParagraphStyle::BaselineGridLineSpacing);
00401                             vg.charStyle().setShadowXOffset(50);
00402                             vg.charStyle().setShadowYOffset(-50);
00403                             vg.charStyle().setOutlineWidth(10);
00404                             vg.charStyle().setUnderlineOffset(m_Doc->typographicSettings.valueUnderlinePos);
00405                             vg.charStyle().setUnderlineWidth(m_Doc->typographicSettings.valueUnderlineWidth);
00406                             vg.charStyle().setStrikethruOffset(m_Doc->typographicSettings.valueStrikeThruPos);
00407                             vg.charStyle().setStrikethruWidth(m_Doc->typographicSettings.valueStrikeThruPos);
00408                             vg.charStyle().setScaleH(1000);
00409                             vg.charStyle().setScaleV(1000);
00410                             vg.charStyle().setBaselineOffset(0);
00411                             vg.charStyle().setTracking(0);
00412                             if ((pg.hasAttribute("NUMTAB")) && (pg.attribute("NUMTAB", "0").toInt() != 0))
00413                             {
00414                                    tmp = pg.attribute("TABS");
00415                                    QTextStream tgv(&tmp, IO_ReadOnly);
00416 //                                 vg.tabValues().clear();
00417                                    QValueList<ParagraphStyle::TabRecord> tbs;
00418                                    ParagraphStyle::TabRecord tb;
00419                                    for (int cxv = 0; cxv < pg.attribute("NUMTAB", "0").toInt(); cxv += 2)
00420                                    {
00421                                           tgv >> xf;
00422                                           tgv >> xf2;
00423                                           tb.tabPosition = xf2;
00424                                           tb.tabType = static_cast<int>(xf);
00425                                           tb.tabFillChar = QChar();
00426                                           tbs.append(tb);
00427                                    }
00428                                    vg.setTabValues(tbs);
00429                                    tmp = "";
00430                             }
00431 //                          else
00432 //                                 vg.tabValues().clear();
00433 #endif
00434                             StyleSet<ParagraphStyle> temp;
00435                             temp.create(vg);
00436                             m_Doc->redefineStyles(temp, false);
00437                      }
00438                      if(pg.tagName()=="JAVA")
00439                             m_Doc->JavaScripts[pg.attribute("NAME")] = pg.attribute("SCRIPT");
00440                      if(pg.tagName()=="LAYERS")
00441                      {
00442                             la.LNr = pg.attribute("NUMMER").toInt();
00443                             la.Level = pg.attribute("LEVEL").toInt();
00444                             la.Name = pg.attribute("NAME");
00445                             la.isViewable = pg.attribute("SICHTBAR").toInt();
00446                             la.isPrintable = pg.attribute("DRUCKEN").toInt();
00447                             la.isEditable = true;
00448                             la.flowControl = true;
00449                             la.outlineMode = false;
00450                             la.blendMode = 0;
00451                             la.transparency = 1.0;
00452                             QColor marker;
00453                             switch (la.LNr % 7)
00454                             {
00455                                    case 0:
00456                                           marker = Qt::black;
00457                                           break;
00458                                    case 1:
00459                                           marker = Qt::red;
00460                                           break;
00461                                    case 2:
00462                                           marker = Qt::green;
00463                                           break;
00464                                    case 3:
00465                                           marker = Qt::blue;
00466                                           break;
00467                                    case 4:
00468                                           marker = Qt::cyan;
00469                                           break;
00470                                    case 5:
00471                                           marker = Qt::magenta;
00472                                           break;
00473                                    case 6:
00474                                           marker = Qt::yellow;;
00475                                           break;
00476                             }
00477                             la.markerColor = marker;
00478                             la.outlineMode = false;
00479                             m_Doc->Layers.append(la);
00480                      }
00481                      if(pg.tagName()=="MultiLine")
00482                      {
00483                             multiLine ml;
00484                             QDomNode MuLn = PAGE.firstChild();
00485                             while(!MuLn.isNull())
00486                             {
00487                                    QDomElement MuL = MuLn.toElement();
00488                                    struct SingleLine sl;
00489                                    sl.Color = MuL.attribute("Color");
00490                                    sl.Dash = MuL.attribute("Dash").toInt();
00491                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
00492                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
00493                                    sl.Shade = MuL.attribute("Shade").toInt();
00494                                    sl.Width = MuL.attribute("Width").toDouble();
00495                                    ml.push_back(sl);
00496                                    MuLn = MuLn.nextSibling();
00497                             }
00498                             m_Doc->MLineStyles.insert(pg.attribute("Name"), ml);
00499                      }
00500                      if(pg.tagName()=="PAGE")
00501                      {
00502                             TableItems.clear();
00503                             TableID.clear();
00504                      /*
00505                      * Attribute von PAGE auslesen
00506                      */
00507                             a = pg.attribute("NUM").toInt();
00508                             PgNam = "";
00509                             PgNam = pg.attribute("NAM", "");
00510                             QString Mus = "";
00511                             Mus = pg.attribute("MNAM","Normal");
00512                             if (PgNam.isEmpty())
00513                             {
00514                                    //We store the pages master page but do not apply it now
00515                                    //as it may not exist yet. They are applied in scribus.cpp for now.
00516                                    m_Doc->setMasterPageMode(false);
00517                                    m_Doc->setCurrentPage(m_Doc->addPage(a));
00518                                    m_Doc->currentPage()->MPageNam=Mus;
00519                             }
00520                             else
00521                             {
00522                                    m_Doc->setMasterPageMode(true);
00523                                    m_Doc->setCurrentPage(m_Doc->addMasterPage(a, PgNam));
00524                             }
00525                             //CB: Remove this unnecessarily "slow" slot call when we have no gui for the doc yet!
00526                             //Items dont appear in the right place if we just m_Doc->addPage(a); for <=1.2.x docs
00527                             //so we have to call the view, but we certainly dont need to emit to the mainwindow!
00528                             //This call now picks up the added page and does some view black magic. A must for
00529                             //1.2.x docs!
00530                             m_View->addPage(a);
00531                             //emit NewPage(a);
00532                             m_Doc->Pages->at(a)->LeftPg=pg.attribute("LEFT", "0").toInt();
00533 
00534                             // guides reading
00535                             tmp = "";
00536                             GuideManagerIO::readVerticalGuides(pg.attribute("VerticalGuides"),
00537                                                  m_Doc->Pages->at(a),
00538                                                  GuideManagerCore::Standard,
00539                                                  pg.hasAttribute("NumVGuides"));
00540                             GuideManagerIO::readHorizontalGuides(pg.attribute("HorizontalGuides"),
00541                                                  m_Doc->Pages->at(a),
00542                                                  GuideManagerCore::Standard,
00543                                                  pg.hasAttribute("NumHGuides"));
00544 
00545                             QDomNode OBJ=PAGE.firstChild();
00546                             int pageNo = a;
00547                             int pageItem = 0;
00548                             while(!OBJ.isNull())
00549                             {
00550                                    QDomElement obj=OBJ.toElement();
00551                                    /*
00552                                     * Attribute von OBJECT auslesen
00553                                     */
00554                                    if (!m_Doc->masterPageMode())
00555                                    {
00556                                           const long long itemID = scribus12itemID(pageItem++, pageNo);
00557 //                                        qDebug(QString("1.2 remap: %1 -> %2 [%3 on page %4]").arg(itemID).arg(m_Doc->Items->count()).arg(pageItem-1).arg(pageNo));
00558                                           itemRemap[itemID] = m_Doc->Items->count();
00559                                           if (obj.tagName()=="PAGEOBJECT")
00560                                           {
00561                                                  // member of linked chain?
00562                                                  if (obj.attribute("NEXTITEM").toInt() != -1)
00563                                                  {
00564                                                         itemNext[m_Doc->Items->count()] = scribus12itemID(obj.attribute("NEXTITEM").toInt(), 
00565                                                                                                                                               obj.attribute("NEXTPAGE").toInt());
00566                                                  }
00567                                           }
00568                                    }
00569                                    GetItemProps(newVersion, &obj, &OB);
00570                                    OB.Xpos = obj.attribute("XPOS").toDouble()+m_Doc->Pages->at(a)->xOffset();
00571                                    OB.Ypos=obj.attribute("YPOS").toDouble()+m_Doc->Pages->at(a)->yOffset();
00572                                    OB.NamedLStyle = obj.attribute("NAMEDLST", "");
00573                                    OB.isBookmark=obj.attribute("BOOKMARK").toInt();
00574                                    if ((OB.isBookmark) && (m_Doc->BookMarks.count() == 0))
00575                                           m_Doc->OldBM = true;
00576                                    OB.textAlignment = obj.attribute("ALIGN", "0").toInt();
00577                                    OB.startArrowIndex =  0;
00578                                    OB.endArrowIndex =  0;
00579                                    tmpf = obj.attribute("IFONT", m_Doc->toolSettings.defFont);
00580                                    m_AvailableFonts->findFont(tmpf, m_Doc);
00581                                    OB.IFont = tmpf;
00582                                    OB.LayerNr = obj.attribute("LAYER", "0").toInt();
00583                                    OB.Language = obj.attribute("LANGUAGE", m_Doc->Language);
00584                                    tmp = "";
00585                                    if ((obj.hasAttribute("GROUPS")) && (obj.attribute("NUMGROUP", "0").toInt() != 0))
00586                                    {
00587                                           tmp = obj.attribute("GROUPS");
00588                                           QTextStream fg(&tmp, IO_ReadOnly);
00589                                           OB.Groups.clear();
00590                                           for (int cx = 0; cx < obj.attribute("NUMGROUP", "0").toInt(); ++cx)
00591                                           {
00592                                                  fg >> x;
00593                                                  OB.Groups.push(x);
00594                                           }
00595                                           tmp = "";
00596                                    }
00597                                    else
00598                                           OB.Groups.clear();
00599                                    QDomNode IT=OBJ.firstChild();
00600                                    while(!IT.isNull())
00601                                    {
00602                                           QDomElement it=IT.toElement();
00603                                           if (it.tagName()=="CSTOP")
00604                                           {
00605                                                  QString name = it.attribute("NAME");
00606                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
00607                                                  int shade = it.attribute("SHADE", "100").toInt();
00608                                                  double opa = it.attribute("TRANS", "1").toDouble();
00609                                                  handleOldColorShade(m_Doc, name, shade);
00610                                                  OB.fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
00611                                                  OB.GrColor = "";
00612                                                  OB.GrColor2 = "";
00613                                           }
00614                                           IT=IT.nextSibling();
00615                                    }
00616                                    OB.itemText = "";
00617                                    int docGc = m_Doc->GroupCounter;
00618                                    m_Doc->GroupCounter = 0;
00619                                    uint last = m_Doc->Items->count();
00620                                    m_View->PasteItem(&OB, true);
00621                                    m_Doc->GroupCounter = docGc;
00622                                    Neu = m_Doc->Items->at(last);
00623                                    Neu->OnMasterPage = PgNam;
00624                                    Neu->OwnPage = a; //No need to scan for OnPage as we know page by page in 1.2.x
00625                                    Neu->oldOwnPage = 0;
00626                                    Neu->setRedrawBounding();
00627                                    IT=OBJ.firstChild();
00628                                    LastStyles * lastS = new LastStyles();
00629                                    while(!IT.isNull())
00630                                    {
00631                                           QDomElement it=IT.toElement();
00632                                           if (it.tagName()=="ITEXT")
00633                                                  GetItemText(&it, m_Doc, true, false, Neu, lastS);
00634                                           IT=IT.nextSibling();
00635                                    }
00636                                    delete lastS;
00637                                    Neu->isAutoText=static_cast<bool>(obj.attribute("AUTOTEXT").toInt());
00638                                    if (Neu->isAutoText)
00639                                           m_Doc->LastAuto = Neu;
00640 //                                 Neu->NextIt = obj.attribute("NEXTITEM").toInt();
00641 //                                 nextPg[Neu->ItemNr] = obj.attribute("NEXTPAGE").toInt();
00642                                    if (Neu->isTableItem)
00643                                    {
00644                                           TableItems.append(Neu);
00645                                           TableID.insert(obj.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
00646                                    }
00647                                    counter++;
00648                                    OBJ=OBJ.nextSibling();
00649                             }
00650                             if (TableItems.count() != 0)
00651                             {
00652                                    for (uint ttc = 0; ttc < TableItems.count(); ++ttc)
00653                                    {
00654                                           PageItem* ta = TableItems.at(ttc);
00655                                           if (ta->TopLinkID != -1)
00656                                                  ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
00657                                           else
00658                                                  ta->TopLink = 0;
00659                                           if (ta->LeftLinkID != -1)
00660                                                  ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
00661                                           else
00662                                                  ta->LeftLink = 0;
00663                                           if (ta->RightLinkID != -1)
00664                                                  ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
00665                                           else
00666                                                  ta->RightLink = 0;
00667                                           if (ta->BottomLinkID != -1)
00668                                                  ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
00669                                           else
00670                                                  ta->BottomLink = 0;
00671                                    }
00672                             }
00673                      }
00674                      PAGE=PAGE.nextSibling();
00675               }
00676               m_Doc->setMasterPageMode(false);
00677               PAGE=DOC.firstChild();
00678               while(!PAGE.isNull())
00679               {
00680                      QDomElement pg=PAGE.toElement();
00681                      if(pg.tagName()=="Bookmark")
00682                      {
00683                             uint elem = pg.attribute("Element").toInt();
00684                             if (elem < m_Doc->Items->count())
00685                             {
00686                                    bok.Title = pg.attribute("Title");
00687                                    bok.Text = pg.attribute("Text");
00688                                    bok.Aktion = pg.attribute("Aktion");
00689                                    bok.ItemNr = pg.attribute("ItemNr").toInt();
00690                                    bok.PageObject = m_Doc->Items->at(elem);
00691                                    bok.First = pg.attribute("First").toInt();
00692                                    bok.Last = pg.attribute("Last").toInt();
00693                                    bok.Prev = pg.attribute("Prev").toInt();
00694                                    bok.Next = pg.attribute("Next").toInt();
00695                                    bok.Parent = pg.attribute("Parent").toInt();
00696                                    m_Doc->BookMarks.append(bok);
00697                             }
00698                      }
00699                      if(pg.tagName()=="PDF")
00700                      {
00701                             m_Doc->PDF_Options.Articles = static_cast<bool>(pg.attribute("Articles").toInt());
00702                             m_Doc->PDF_Options.Thumbnails = static_cast<bool>(pg.attribute("Thumbnails").toInt());
00703                             m_Doc->PDF_Options.Compress = static_cast<bool>(pg.attribute("Compress").toInt());
00704                             m_Doc->PDF_Options.CompressMethod = pg.attribute("CMethod", "0").toInt();
00705                             m_Doc->PDF_Options.Quality = pg.attribute("Quality", "0").toInt();
00706                             m_Doc->PDF_Options.RecalcPic = static_cast<bool>(pg.attribute("RecalcPic").toInt());
00707                             m_Doc->PDF_Options.Bookmarks = static_cast<bool>(pg.attribute("Bookmarks").toInt());
00708                             if (pg.hasAttribute("MirrorH"))
00709                                    m_Doc->PDF_Options.MirrorH = static_cast<bool>(pg.attribute("MirrorH").toInt());
00710                             else
00711                                    m_Doc->PDF_Options.MirrorH = false;
00712                             if (pg.hasAttribute("MirrorV"))
00713                                    m_Doc->PDF_Options.MirrorV = static_cast<bool>(pg.attribute("MirrorV").toInt());
00714                             else
00715                                    m_Doc->PDF_Options.MirrorV = false;
00716                             if (pg.hasAttribute("RotateDeg"))
00717                                    m_Doc->PDF_Options.RotateDeg = pg.attribute("RotateDeg", "0").toInt();
00718                             else
00719                                    m_Doc->PDF_Options.RotateDeg = 0;
00720                             m_Doc->PDF_Options.PresentMode = static_cast<bool>(pg.attribute("PresentMode").toInt());
00721                             m_Doc->PDF_Options.PicRes = pg.attribute("PicRes").toInt();
00722                             m_Doc->PDF_Options.Version = (PDFOptions::PDFVersion)pg.attribute("Version").toInt();
00723                             m_Doc->PDF_Options.Resolution = pg.attribute("Resolution").toInt();
00724                             m_Doc->PDF_Options.Binding = pg.attribute("Binding").toInt();
00725                             m_Doc->PDF_Options.Datei = "";
00726                             m_Doc->PDF_Options.isGrayscale = false;
00727                             m_Doc->PDF_Options.UseRGB = static_cast<bool>(pg.attribute("RGBMode", "0").toInt());
00728                             m_Doc->PDF_Options.UseProfiles = static_cast<bool>(pg.attribute("UseProfiles", "0").toInt());
00729                             m_Doc->PDF_Options.UseProfiles2 = static_cast<bool>(pg.attribute("UseProfiles2", "0").toInt());
00730                             m_Doc->PDF_Options.Intent = pg.attribute("Intent", "1").toInt();
00731                             m_Doc->PDF_Options.Intent2 = pg.attribute("Intent2", "1").toInt();
00732                             m_Doc->PDF_Options.SolidProf = pg.attribute("SolidP", "");
00733                             m_Doc->PDF_Options.ImageProf = pg.attribute("ImageP", "");
00734                             m_Doc->PDF_Options.PrintProf = pg.attribute("PrintP", "");
00735                             m_Doc->PDF_Options.Info = pg.attribute("InfoString", "");
00736                             m_Doc->PDF_Options.bleeds.Top = pg.attribute("BTop", "0").toDouble();
00737                             m_Doc->PDF_Options.bleeds.Left = pg.attribute("BLeft", "0").toDouble();
00738                             m_Doc->PDF_Options.bleeds.Right = pg.attribute("BRight", "0").toDouble();
00739                             m_Doc->PDF_Options.bleeds.Bottom = pg.attribute("BBottom", "0").toDouble();
00740                             m_Doc->PDF_Options.EmbeddedI = static_cast<bool>(pg.attribute("ImagePr", "0").toInt());
00741                             m_Doc->PDF_Options.PassOwner = pg.attribute("PassOwner", "");
00742                             m_Doc->PDF_Options.PassUser = pg.attribute("PassUser", "");
00743                             m_Doc->PDF_Options.Permissions = pg.attribute("Permissions", "-4").toInt();
00744                             m_Doc->PDF_Options.Encrypt = static_cast<bool>(pg.attribute("Encrypt", "0").toInt());
00745                             m_Doc->PDF_Options.useLayers = static_cast<bool>(pg.attribute("UseLayers", "0").toInt());
00746                             m_Doc->PDF_Options.UseLPI = static_cast<bool>(pg.attribute("UseLpi", "0").toInt());
00747                             m_Doc->PDF_Options.UseSpotColors = true;
00748                             m_Doc->PDF_Options.doOverprint = false;
00749                             m_Doc->PDF_Options.doMultiFile = false;
00750                             QDomNode PFO = PAGE.firstChild();
00751                             while(!PFO.isNull())
00752                             {
00753                                    QDomElement pdfF = PFO.toElement();
00754                                    if(pdfF.tagName() == "LPI")
00755                                    {
00756                                           struct LPIData lpo;
00757                                           lpo.Angle = pdfF.attribute("Angle").toInt();
00758                                           lpo.Frequency = pdfF.attribute("Frequency").toInt();
00759                                           lpo.SpotFunc = pdfF.attribute("SpotFunction").toInt();
00760                                           m_Doc->PDF_Options.LPISettings[pdfF.attribute("Color")] = lpo;
00761                                    }
00762                                    if(pdfF.tagName() == "Fonts")
00763                                    {
00764                                           if (!m_Doc->PDF_Options.EmbedList.contains(pdfF.attribute("Name")))
00765                                                  m_Doc->PDF_Options.EmbedList.append(pdfF.attribute("Name"));
00766                                    }
00767                                    if(pdfF.tagName() == "Subset")
00768                                    {
00769                                           if (!m_Doc->PDF_Options.SubsetList.contains(pdfF.attribute("Name")))
00770                                                  m_Doc->PDF_Options.SubsetList.append(pdfF.attribute("Name"));
00771                                    }
00772                                    if(pdfF.tagName() == "Effekte")
00773                                    {
00774                                    struct PDFPresentationData ef;
00775                                    ef.pageEffectDuration = pdfF.attribute("pageEffectDuration").toInt();
00776                                    ef.pageViewDuration = pdfF.attribute("pageViewDuration").toInt();
00777                                    ef.effectType = pdfF.attribute("effectType").toInt();
00778                                    ef.Dm = pdfF.attribute("Dm").toInt();
00779                                    ef.M = pdfF.attribute("M").toInt();
00780                                    ef.Di = pdfF.attribute("Di").toInt();
00781                                           m_Doc->PDF_Options.PresentVals.append(ef);
00782                                    }
00783                                    PFO = PFO.nextSibling();
00784                             }
00785                      }
00786                      PAGE=PAGE.nextSibling();
00787               }
00788               DOC=DOC.nextSibling();
00789        }
00790        //m_Doc->Pages = &m_Doc->DocPages;
00791        //m_Doc->pageCount = m_Doc->Pages->count();
00792        //m_Doc->Items = m_Doc->DocItems;
00793        m_Doc->setMasterPageMode(false);
00794        m_View->reformPages();
00795        if (m_Doc->layerCount() == 0)
00796        {
00797               la.LNr = 0;
00798               la.Level = 0;
00799               la.Name = tr("Background");
00800               la.isViewable = true;
00801               la.isPrintable = true;
00802               la.isEditable = true;
00803               la.blendMode = 0;
00804               la.transparency = 1.0;
00805               la.flowControl = false;
00806               la.outlineMode = false;
00807               la.markerColor = QColor(Qt::black);
00808               m_Doc->Layers.append(la);
00809        }
00810        m_Doc->setActiveLayer(activeLayer);
00811        
00812        // reestablish textframe links
00813        if (itemNext.count() != 0)
00814        {
00815               QMap<int,long long>::Iterator lc;
00816               for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
00817               {
00818 //                   qDebug(QString("1.2 textframe links: %1->%2[%3]").arg(lc.key()).arg(itemRemap[lc.data()]).arg(lc.data()));
00819                      PageItem *Its = m_Doc->Items->at(lc.key());
00820                      PageItem *Itn = m_Doc->Items->at(itemRemap[lc.data()]);
00821                      assert(Its && Its->asTextFrame());
00822                      assert(Itn && Itn->asTextFrame());
00823                      if (Itn->prevInChain() || Its->nextInChain()) 
00824                      {
00825                             qDebug("scribus12format: corruption in linked textframes detected");
00826                             continue;
00827                      }
00828                      Its->link(Itn);
00829               }
00830        }
00831 
00832        // reestablish first/lastAuto
00833        m_Doc->FirstAuto = m_Doc->LastAuto;
00834        if (m_Doc->LastAuto)
00835        {
00836               while (m_Doc->LastAuto->nextInChain())
00837                      m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
00838               while (m_Doc->FirstAuto->prevInChain())
00839                      m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
00840        }
00841        
00842        m_View->unitSwitcher->setCurrentText(unitGetStrFromIndex(m_Doc->unitIndex()));
00843        if (m_mwProgressBar!=0)
00844               m_mwProgressBar->setProgress(DOC.childNodes().count());
00845        return true;
00846 //end old ReadDoc
00847        
00848        
00849        //return false;
00850 }
00851 
00852 bool Scribus12Format::saveFile(const QString & /* fileName */, const FileFormat & /* fmt */)
00853 {
00854        return false;
00855 }
00856 
00857 void Scribus12Format::GetItemText(QDomElement *it, ScribusDoc *doc, bool VorLFound, bool impo, PageItem* obj, LastStyles* last)
00858 {
00859        QString tmp2(it->attribute("CH"));
00860        tmp2.replace(QRegExp("\r"), QChar(5));
00861        tmp2.replace(QRegExp("\n"), QChar(5));
00862        tmp2.replace(QRegExp("\t"), QChar(4));
00863        tmp2.replace(SpecialChars::OLD_NBHYPHEN, SpecialChars::NBHYPHEN);
00864        tmp2.replace(SpecialChars::OLD_NBSPACE, SpecialChars::NBSPACE);
00865        QString tmpf(it->attribute("CFONT", doc->toolSettings.defFont));
00866        doc->AllFonts->findFont(tmpf, doc);
00867        int size = qRound(it->attribute("CSIZE").toDouble() * 10);
00868        QString fcolor(it->attribute("CCOLOR"));
00869        int shade = it->attribute("CSHADE").toInt();
00870        handleOldColorShade(doc, fcolor, shade);
00871        int extra;
00872        if (it->hasAttribute("CEXTRA"))
00873               extra = qRound(it->attribute("CEXTRA").toDouble() / it->attribute("CSIZE").toDouble() * 1000.0);
00874        else
00875               extra = it->attribute("CKERN").toInt();
00876        int cstyle = it->attribute("CSTYLE").toInt() & 255;
00877        int ab = it->attribute("CAB", "0").toInt();
00878        QString stroke(it->attribute("CSTROKE",CommonStrings::None));
00879        int shade2 = it->attribute("CSHADE2", "100").toInt();
00880        handleOldColorShade(doc, stroke, shade2);
00881        int scale = qRound(it->attribute("CSCALE", "100").toDouble() * 10);
00882        int scalev = qRound(it->attribute("CSCALEV", "100").toDouble() * 10);
00883        int base = qRound(it->attribute("CBASE", "0").toDouble() * 10);
00884        int shX = qRound(it->attribute("CSHX", "5").toDouble() * 10);
00885        int shY = qRound(it->attribute("CSHY", "-5").toDouble() * 10);
00886        int outL = qRound(it->attribute("COUT", "1").toDouble() * 10);
00887        int ulp = qRound(it->attribute("CULP", "-0.1").toDouble() * 10);
00888        int ulw = qRound(it->attribute("CULW", "-0.1").toDouble() * 10);
00889        int stp = qRound(it->attribute("CSTP", "-0.1").toDouble() * 10);
00890        int stw = qRound(it->attribute("CSTW", "-0.1").toDouble() * 10);
00891        for (uint cxx=0; cxx<tmp2.length(); ++cxx)
00892        {
00893               CharStyle style;
00894               QChar ch(tmp2.at(cxx));
00895               if (ch == QChar(5))
00896                      ch = SpecialChars::PARSEP;
00897               if (ch == QChar(4))
00898                      ch = SpecialChars::TAB;
00899               
00900               style.setFont((*doc->AllFonts)[tmpf]);
00901               style.setFontSize(size);
00902               style.setFillColor(fcolor);
00903               style.setTracking(extra);
00904               style.setFillShade(shade);
00905               style.setFeatures(static_cast<StyleFlag>(cstyle).featureList());
00906               style.setStrokeColor(stroke);
00907               style.setStrokeShade(shade2);
00908               style.setScaleH(QMIN(QMAX(scale, 100), 4000));
00909               style.setScaleV(QMIN(QMAX(scalev, 100), 4000));
00910               style.setBaselineOffset(base);
00911               style.setShadowXOffset(shX);
00912               style.setShadowYOffset(shY);
00913               style.setOutlineWidth(outL);
00914               style.setUnderlineOffset(ulp);
00915               style.setUnderlineWidth(ulw);
00916               style.setStrikethruOffset(stp);
00917               style.setStrikethruWidth(stw);
00918               int pos = obj->itemText.length();
00919               obj->itemText.insertChars(pos, QString(ch));
00920 
00921               if (style != last->Style) {
00922                      //     qDebug(QString("new style at %1: %2 -> %3").arg(pos).arg(last->Style.asString()).arg(newStyle.asString()));
00923                      obj->itemText.applyCharStyle(last->StyleStart, pos-last->StyleStart, last->Style);
00924                      last->Style = style;
00925                      last->StyleStart = pos;
00926               }
00927 
00928               if (ch == SpecialChars::PARSEP || cxx+1 == tmp2.length()) {
00929 //                   qDebug(QString("scribus12 para: %1 %2 %3 %4").arg(ab)
00930 //                             .arg(ab < signed(DoVorl.size())? DoVorl[ab] : QString("./."))
00931 //                             .arg(VorLFound).arg(DoVorl.size()));
00932                      ParagraphStyle pstyle;
00933                      if (ab < 5) {
00934                             pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(ab));
00935                      }
00936                      else if (VorLFound) {
00937                             pstyle.setParent( DoVorl[ab] );
00938                      }
00939                      obj->itemText.applyStyle(pos, pstyle); 
00940               }
00941        }
00942        obj->itemText.applyCharStyle(last->StyleStart, obj->itemText.length()-last->StyleStart, last->Style);
00943        return;
00944 }
00945 
00946 bool Scribus12Format::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString /*renamedPageName*/)
00947 {
00948 //     qDebug(QString("loading page %2 from file '%1' from 1.2.x plugin").arg(fileName).arg(pageNumber));
00949        if (m_Doc==0 || m_View==0 || m_AvailableFonts==0)
00950        {
00951               Q_ASSERT(m_Doc==0 || m_View==0 || m_AvailableFonts==0);
00952               return false;
00953        }
00954 
00955        struct CopyPasteBuffer OB;
00956        ParagraphStyle vg;
00957        struct Layer la;
00958        struct ScribusDoc::BookMa bok;
00959        PageItem *Neu;
00960        itemRemap.clear();
00961        itemNext.clear();
00962        QString tmV, tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
00963        QMap<int,int> TableID;
00964        QPtrList<PageItem> TableItems;
00965        int x, a, counter, baseobj;
00966        bool newVersion = false;
00967        bool VorLFound = false;
00968        QMap<int,int> layerTrans;
00969        int maxLayer = 0;
00970        int maxLevel = 0;
00971        layerTrans.clear();
00972        uint layerCount=m_Doc->layerCount();
00973        for (uint la2 = 0; la2 < layerCount; ++la2)
00974        {
00975               maxLayer = QMAX(m_Doc->Layers[la2].LNr, maxLayer);
00976               maxLevel = QMAX(m_Doc->Layers[la2].Level, maxLevel);
00977        }
00978        DoVorl.clear();
00979        DoVorl[0] = "";
00980        DoVorl[1] = "";
00981        DoVorl[2] = "";
00982        DoVorl[3] = "";
00983        DoVorl[4] = "";
00984        VorlC = 5;
00985        QDomDocument docu("scridoc");
00986        QString f(readSLA(fileName));
00987        if (f.isEmpty())
00988               return false;
00989        if(!docu.setContent(f))
00990               return false;
00991        ScColor lf = ScColor();
00992        QDomElement elem=docu.documentElement();
00993        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
00994               return false;
00995        if (elem.hasAttribute("Version"))
00996               newVersion = true;
00997        QDomNode DOC=elem.firstChild();
00998        while(!DOC.isNull())
00999        {
01000               QDomElement dc=DOC.toElement();
01001        /*
01002        * Attribute von DOCUMENT auslesen
01003        */
01004               QDomNode PAGE=DOC.firstChild();
01005               while(!PAGE.isNull())
01006               {
01007                      QDomElement pg=PAGE.toElement();
01008                      // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
01009                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
01010                      {
01011                             if (pg.hasAttribute("CMYK"))
01012                                    lf.setNamedColor(pg.attribute("CMYK"));
01013                             else
01014                                    lf.fromQColor(QColor(pg.attribute("RGB")));
01015                             lf.setSpotColor(false);
01016                             lf.setRegistrationColor(false);
01017                             m_Doc->PageColors.insert(pg.attribute("NAME"), lf);
01018                      }
01019                      if(pg.tagName()=="STYLE")
01020                      {
01021                             GetStyle(&pg, &vg, NULL, m_Doc, true);
01022                             VorLFound = true;
01023                      }
01024                      if(pg.tagName()=="JAVA")
01025                             m_Doc->JavaScripts[pg.attribute("NAME")] = pg.attribute("SCRIPT");
01026                      if(pg.tagName()=="LAYERS")
01027                      {
01028                             la.LNr = pg.attribute("NUMMER").toInt();
01029                             la.Level = pg.attribute("LEVEL").toInt();
01030                             la.Name = pg.attribute("NAME");
01031                             la.isViewable = pg.attribute("SICHTBAR").toInt();
01032                             la.isPrintable = pg.attribute("DRUCKEN").toInt();
01033                             la.isEditable = true;
01034                             la.flowControl = true;
01035                             la.transparency = 1.0;
01036                             la.blendMode = 0;
01037                             QColor marker;
01038                             switch (la.LNr % 7)
01039                             {
01040                                    case 0:
01041                                           marker = Qt::black;
01042                                           break;
01043                                    case 1:
01044                                           marker = Qt::red;
01045                                           break;
01046                                    case 2:
01047                                           marker = Qt::green;
01048                                           break;
01049                                    case 3:
01050                                           marker = Qt::blue;
01051                                           break;
01052                                    case 4:
01053                                           marker = Qt::cyan;
01054                                           break;
01055                                    case 5:
01056                                           marker = Qt::magenta;
01057                                           break;
01058                                    case 6:
01059                                           marker = Qt::yellow;;
01060                                           break;
01061                             }
01062                             la.markerColor = marker;
01063                             la.outlineMode = false;
01064                             bool laex = false;
01065                             uint layerCount=m_Doc->layerCount();
01066                             for (uint la2 = 0; la2 < layerCount; ++la2)
01067                             {
01068                                    if (m_Doc->Layers[la2].Name == la.Name)
01069                                    {
01070                                           laex = true;
01071                                           layerTrans.insert(la.LNr, m_Doc->Layers[la2].LNr);
01072                                    }
01073                             }
01074                             if (!laex)
01075                             {
01076                                    maxLayer++;
01077                                    maxLevel++;
01078                                    layerTrans.insert(la.LNr, maxLayer);
01079                                    la.LNr = maxLayer;
01080                                    la.Level = maxLevel;
01081                                    m_Doc->Layers.append(la);
01082                             }
01083                      }
01084                      if(pg.tagName()=="MultiLine")
01085                      {
01086                             multiLine ml;
01087                             QDomNode MuLn = PAGE.firstChild();
01088                             while(!MuLn.isNull())
01089                             {
01090                                    QDomElement MuL = MuLn.toElement();
01091                                    struct SingleLine sl;
01092                                    sl.Color = MuL.attribute("Color");
01093                                    sl.Dash = MuL.attribute("Dash").toInt();
01094                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
01095                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
01096                                    sl.Shade = MuL.attribute("Shade").toInt();
01097                                    sl.Width = MuL.attribute("Width").toDouble();
01098                                    ml.push_back(sl);
01099                                    MuLn = MuLn.nextSibling();
01100                             }
01101                             QString Nam = pg.attribute("Name");
01102                             QString Nam2 = Nam;
01103                             int copyC = 1;
01104                             QMap<QString,multiLine>::ConstIterator mlit = m_Doc->MLineStyles.find(Nam2);
01105                             if (mlit != m_Doc->MLineStyles.end() && ml != mlit.data())
01106                             {
01107                                    while (m_Doc->MLineStyles.contains(Nam2))
01108                                    {
01109                                           Nam2 = tr("Copy #%1 of ").arg(copyC)+Nam;
01110                                           copyC++;
01111                                    }
01112                             }
01113                             m_Doc->MLineStyles.insert(Nam2, ml);
01114                      }
01115                      if ((pg.tagName()=="PAGE") && (pg.attribute("NUM").toInt() == pageNumber))
01116                      {
01117                             a = m_Doc->currentPage()->pageNr();
01118                             if (Mpage)
01119                             {
01120                                    if (pg.attribute("NAM", "").isEmpty())
01121                                    {
01122                                           PAGE=PAGE.nextSibling();
01123                                           continue;
01124                                    }
01125                             }
01126                             else
01127                             {
01128                                    if (!pg.attribute("NAM", "").isEmpty())
01129                                    {
01130                                           PAGE=PAGE.nextSibling();
01131                                           continue;
01132                                    }
01133                             }
01134 /*                          if ((pg.attribute("NAM", "").isEmpty()) && (Mpage))
01135                             {
01136                                    PAGE=PAGE.nextSibling();
01137                                    continue;
01138                             } */
01139                             if (Mpage)
01140                             {
01141                                    m_Doc->Pages->at(a)->LeftPg=pg.attribute("LEFT", "0").toInt();
01142                                    m_Doc->Pages->at(a)->setPageName(pg.attribute("NAM",""));
01143                             }
01144                             TableItems.clear();
01145                             TableID.clear();
01146                             /*
01147                             * Attribute von PAGE auslesen
01148                             */
01149                             tmp = "";
01150                             GuideManagerIO::readVerticalGuides(pg.attribute("VerticalGuides"),
01151                                           m_Doc->Pages->at(a),
01152                                           GuideManagerCore::Standard,
01153                                           pg.hasAttribute("NumVGuides"));
01154                             GuideManagerIO::readHorizontalGuides(pg.attribute("HorizontalGuides"),
01155                                           m_Doc->Pages->at(a),
01156                                           GuideManagerCore::Standard,
01157                                           pg.hasAttribute("NumHGuides"));
01158 
01159                             QDomNode OBJ=PAGE.firstChild();
01160                             counter = m_Doc->Items->count();
01161                             baseobj = counter;
01162                             int pageItem = 0;
01163                             while(!OBJ.isNull())
01164                             {
01165                                    QDomElement obj=OBJ.toElement();
01166                             /*
01167                             * Attribute von OBJECT auslesen
01168                             */
01169                                    itemRemap[scribus12itemID(pageItem++, pageNumber)] = m_Doc->Items->count();
01170                                    if (obj.tagName()=="PAGEOBJECT")
01171                                    {
01172                                           // member of linked chain?
01173                                           if ((obj.attribute("NEXTITEM").toInt() != -1) && (obj.attribute("NEXTPAGE").toInt() == pageNumber))
01174                                           {
01175                                                  itemNext[m_Doc->Items->count()] = scribus12itemID(obj.attribute("NEXTITEM").toInt(), pageNumber);
01176                                           }
01177                                    }
01178                                    GetItemProps(newVersion, &obj, &OB);
01179                                    OB.Xpos = obj.attribute("XPOS").toDouble()+m_Doc->Pages->at(a)->xOffset();
01180                                    OB.Ypos=obj.attribute("YPOS").toDouble()+m_Doc->Pages->at(a)->yOffset();
01181                                    OB.NamedLStyle = obj.attribute("NAMEDLST", "");
01182                                    if (!m_Doc->MLineStyles.contains(OB.NamedLStyle))
01183                                           OB.NamedLStyle = "";
01184                                    OB.startArrowIndex =  0;
01185                                    OB.endArrowIndex =  0;
01186                                    OB.isBookmark=obj.attribute("BOOKMARK").toInt();
01187                                    if ((OB.isBookmark) && (m_Doc->BookMarks.count() == 0))
01188                                           m_Doc->OldBM = true;
01189                                    OB.textAlignment = obj.attribute("ALIGN", "0").toInt();
01190                                    tmpf = obj.attribute("IFONT", m_Doc->toolSettings.defFont);
01191                                    if (tmpf.isEmpty())
01192                                           tmpf = m_Doc->toolSettings.defFont;
01193                                    m_AvailableFonts->findFont(tmpf, m_Doc);
01194                                    OB.IFont = tmpf;
01195                                    OB.LayerNr = layerTrans[obj.attribute("LAYER", "0").toInt()];
01196                                    OB.Language = obj.attribute("LANGUAGE", m_Doc->Language);
01197                                    tmp = "";
01198                                    if ((obj.hasAttribute("GROUPS")) && (obj.attribute("NUMGROUP", "0").toInt() != 0))
01199                                    {
01200                                           tmp = obj.attribute("GROUPS");
01201                                           QTextStream fg(&tmp, IO_ReadOnly);
01202                                           OB.Groups.clear();
01203                                           for (int cx = 0; cx < obj.attribute("NUMGROUP", "0").toInt(); ++cx)
01204                                           {
01205                                                  fg >> x;
01206                                                  OB.Groups.push(x);
01207                                           }
01208                                    tmp = "";
01209                                    }
01210                                    else
01211                                           OB.Groups.clear();
01212                                    QDomNode IT=OBJ.firstChild();
01213                                    while(!IT.isNull())
01214                                    {
01215                                           QDomElement it=IT.toElement();
01216                                           if (it.tagName()=="CSTOP")
01217                                           {
01218                                                  QString name = it.attribute("NAME");
01219                                                  double ramp = it.attribute("RAMP", "0.0").toDouble();
01220                                                  int shade = it.attribute("SHADE", "100").toInt();
01221                                                  double opa = it.attribute("TRANS", "1").toDouble();
01222                                                  handleOldColorShade(m_Doc, name, shade);
01223                                                  OB.fill_gradient.addStop(SetColor(m_Doc, name, shade), ramp, 0.5, opa, name, shade);
01224                                                  OB.GrColor = "";
01225                                                  OB.GrColor2 = "";
01226                                           }
01227                                           IT=IT.nextSibling();
01228                                    }
01229                                    OB.itemText = "";
01230                                    m_View->PasteItem(&OB, true);
01231                                    Neu = m_Doc->Items->at(counter);
01232                                    IT=OBJ.firstChild();
01233                                    LastStyles * last = new LastStyles();
01234                                    while(!IT.isNull())
01235                                    {
01236                                           QDomElement it=IT.toElement();
01237                                           if (it.tagName()=="ITEXT")
01238                                                  GetItemText(&it, m_Doc, VorLFound, true, Neu, last);
01239                                           IT=IT.nextSibling();
01240                                    }
01241                                    delete last;
01242                                    
01243 //                                 if (obj.attribute("NEXTPAGE").toInt() == pageNumber)
01244 //                                 {
01245 //                                        Neu->NextIt = baseobj + obj.attribute("NEXTITEM").toInt();
01246 //                                        nextPg[Neu->ItemNr] = a; // obj.attribute("NEXTPAGE").toInt();
01247 //                                 }
01248 //                                 else
01249 //                                        Neu->NextIt = -1;
01250                                    if (Neu->isTableItem)
01251                                    {
01252                                           TableItems.append(Neu);
01253                                           TableID.insert(obj.attribute("OwnLINK", "0").toInt(), Neu->ItemNr);
01254                                    }
01255                                    counter++;
01256                                    OBJ=OBJ.nextSibling();
01257                             }
01258                             if (TableItems.count() != 0)
01259                             {
01260                                    for (uint ttc = 0; ttc < TableItems.count(); ++ttc)
01261                                    {
01262                                           PageItem* ta = TableItems.at(ttc);
01263                                           if (ta->TopLinkID != -1)
01264                                                  ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
01265                                           else
01266                                                  ta->TopLink = 0;
01267                                           if (ta->LeftLinkID != -1)
01268                                                  ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
01269                                           else
01270                                                  ta->LeftLink = 0;
01271                                           if (ta->RightLinkID != -1)
01272                                                  ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
01273                                           else
01274                                                  ta->RightLink = 0;
01275                                           if (ta->BottomLinkID != -1)
01276                                                  ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
01277                                           else
01278                                                  ta->BottomLink = 0;
01279                                    }
01280                             }
01281                             // reestablish textframe links
01282                             if (itemNext.count() != 0)
01283                             {
01284                                    QMap<int,long long>::Iterator lc;
01285                                    for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
01286                                    {
01287                                           PageItem *Its = m_Doc->Items->at(lc.key());
01288                                           PageItem *Itn = m_Doc->Items->at(itemRemap[lc.data()]);
01289                                           assert(Its && Its->asTextFrame());
01290                                           assert(Itn && Itn->asTextFrame());
01291                                           if (Itn->prevInChain() || Its->nextInChain()) 
01292                                           {
01293                                                  qDebug("scribus12format: corruption in linked textframes detected");
01294                                                  continue;
01295                                           }
01296                                           Its->link(Itn);
01297                                    }
01298                             }
01299                             
01300                             if (!Mpage)
01301                                    m_View->reformPages();
01302                             PAGE=DOC.firstChild();
01303                             while(!PAGE.isNull())
01304                             {
01305                                    QDomElement pg=PAGE.toElement();
01306                                    if(pg.tagName()=="Bookmark")
01307                                    {
01308                                           uint elem = pg.attribute("Element").toInt();
01309                                           if (elem < m_Doc->Items->count())
01310                                           {
01311                                                  bok.Title = pg.attribute("Title");
01312                                                  bok.Text = pg.attribute("Text");
01313                                                  bok.Aktion = pg.attribute("Aktion");
01314                                                  bok.ItemNr = pg.attribute("ItemNr").toInt();
01315                                                  bok.PageObject = m_Doc->Items->at(elem);
01316                                                  bok.First = pg.attribute("First").toInt();
01317                                                  bok.Last = pg.attribute("Last").toInt();
01318                                                  bok.Prev = pg.attribute("Prev").toInt();
01319                                                  bok.Next = pg.attribute("Next").toInt();
01320                                                  bok.Parent = pg.attribute("Parent").toInt();
01321                                                  m_Doc->BookMarks.append(bok);
01322                                           }
01323                                    }
01324                             PAGE=PAGE.nextSibling();
01325                             }
01326                             return true;
01327                      }
01328                      PAGE=PAGE.nextSibling();
01329               }
01330               DOC=DOC.nextSibling();
01331        }
01332        return false;
01333 }
01334 
01335 void Scribus12Format::GetStyle(QDomElement *pg, ParagraphStyle *vg, StyleSet<ParagraphStyle> * tempParagraphStyles, ScribusDoc* doc, bool fl)
01336 {
01337        bool fou;
01338        int fShade, sShade;
01339        QString fColor, sColor;
01340        QString tmpf, tmf, tmV;
01341        double xf, xf2;
01342        fou = false;
01343        const StyleSet<ParagraphStyle> & docParagraphStyles(tempParagraphStyles? *tempParagraphStyles : doc->paragraphStyles());
01344        vg->setName(pg->attribute("NAME"));
01345        vg->setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg->attribute("LINESPMode", "0").toInt()));
01346        vg->setLineSpacing(pg->attribute("LINESP").toDouble());
01347        vg->setLeftMargin(pg->attribute("INDENT", "0").toDouble());
01348        vg->setFirstIndent(pg->attribute("FIRST", "0").toDouble());
01349        vg->setAlignment(static_cast<ParagraphStyle::AlignmentType>(pg->attribute("ALIGN").toInt()));
01350        vg->setGapBefore(pg->attribute("VOR", "0").toDouble());
01351        vg->setGapAfter(pg->attribute("NACH", "0").toDouble());
01352        tmpf = pg->attribute("FONT", doc->toolSettings.defFont);
01353        if (tmpf.isEmpty())
01354               tmpf = doc->toolSettings.defFont;
01355        PrefsManager *prefsManager=PrefsManager::instance();
01356        prefsManager->appPrefs.AvailFonts.findFont(tmpf, doc);
01357        vg->charStyle().setFont(prefsManager->appPrefs.AvailFonts[tmpf]);
01358        vg->charStyle().setFontSize(qRound(pg->attribute("FONTSIZE", "12").toDouble() * 10.0));
01359        vg->setHasDropCap(static_cast<bool>(pg->attribute("DROP", "0").toInt()));
01360        vg->setDropCapLines(pg->attribute("DROPLIN", "2").toInt());
01361        vg->setDropCapOffset(pg->attribute("DROPDIST", "0").toDouble());
01362        vg->charStyle().setFeatures(static_cast<StyleFlag>((pg->attribute("EFFECT", "0").toInt())).featureList());
01363        fColor = pg->attribute("FCOLOR", doc->toolSettings.dBrush);
01364        fShade = pg->attribute("FSHADE", "100").toInt();
01365        handleOldColorShade(doc, fColor, fShade);
01366        sColor = pg->attribute("SCOLOR", doc->toolSettings.dPen);
01367        sShade = pg->attribute("SSHADE", "100").toInt();
01368        handleOldColorShade(doc, sColor, sShade);
01369        vg->charStyle().setFillColor(fColor);
01370        vg->charStyle().setFillShade(fShade);
01371        vg->charStyle().setStrokeColor(sColor);
01372        vg->charStyle().setStrokeShade(sShade);
01373        if (static_cast<bool>(pg->attribute("BASE", "0").toInt()))
01374               vg->setLineSpacingMode(ParagraphStyle::BaselineGridLineSpacing);
01375        vg->charStyle().setShadowXOffset(qRound(pg->attribute("TXTSHX", "5").toDouble() * 10));
01376        vg->charStyle().setShadowYOffset(qRound(pg->attribute("TXTSHY", "-5").toDouble() * 10));
01377        vg->charStyle().setOutlineWidth(qRound(pg->attribute("TXTOUT", "1").toDouble() * 10));
01378        vg->charStyle().setUnderlineOffset(qRound(pg->attribute("TXTULP", "-0.1").toDouble() * 10));
01379        vg->charStyle().setUnderlineWidth(qRound(pg->attribute("TXTULW", "-0.1").toDouble() * 10));
01380        vg->charStyle().setStrikethruOffset(qRound(pg->attribute("TXTSTP", "-0.1").toDouble() * 10));
01381        vg->charStyle().setStrikethruWidth(qRound(pg->attribute("TXTSTW", "-0.1").toDouble() * 10));
01382        vg->charStyle().setScaleH(qRound(pg->attribute("SCALEH", "100").toDouble() * 10));
01383        vg->charStyle().setScaleV(qRound(pg->attribute("SCALEV", "100").toDouble() * 10));
01384        vg->charStyle().setBaselineOffset(qRound(pg->attribute("BASEO", "0").toDouble() * 10));
01385        vg->charStyle().setTracking(qRound(pg->attribute("KERN", "0").toDouble() * 10));
01386 //     vg->tabValues().clear();
01387        if ((pg->hasAttribute("NUMTAB")) && (pg->attribute("NUMTAB", "0").toInt() != 0))
01388        {
01389               QValueList<ParagraphStyle::TabRecord> tbs;
01390               ParagraphStyle::TabRecord tb;
01391               QString tmp = pg->attribute("TABS");
01392               QTextStream tgv(&tmp, IO_ReadOnly);
01393               for (int cxv = 0; cxv < pg->attribute("NUMTAB", "0").toInt(); cxv += 2)
01394               {
01395                      tgv >> xf;
01396                      tgv >> xf2;
01397                      tb.tabPosition = xf2;
01398                      tb.tabType = static_cast<int>(xf);
01399                      tb.tabFillChar = QChar();
01400                      tbs.append(tb);
01401               }
01402               vg->setTabValues(tbs);
01403               tmp = "";
01404        }
01405        else
01406        {
01407               QValueList<ParagraphStyle::TabRecord> tbs;
01408               QDomNode IT = pg->firstChild();
01409               while(!IT.isNull())
01410               {
01411                      QDomElement it = IT.toElement();
01412                      if (it.tagName()=="Tabs")
01413                      {
01414                             ParagraphStyle::TabRecord tb;
01415                             tb.tabPosition = it.attribute("Pos").toDouble();
01416                             tb.tabType = it.attribute("Type").toInt();
01417                             QString tbCh = "";
01418                             tbCh = it.attribute("Fill","");
01419                             if (tbCh.isEmpty())
01420                                    tb.tabFillChar = QChar();
01421                             else
01422                                    tb.tabFillChar = tbCh[0];
01423                             tbs.append(tb);
01424                      }
01425                      vg->setTabValues(tbs);
01426                      IT=IT.nextSibling();
01427               }
01428        }
01429        for (uint xx=0; xx<docParagraphStyles.count(); ++xx)
01430        {
01431               if (vg->name() == docParagraphStyles[xx].name())
01432               {
01433                      //Compare the attributes of the pasted styles vs existing ones
01434                      if (vg->equiv(docParagraphStyles[xx]))
01435                      {
01436                             if (fl)
01437                             {
01438                                    DoVorl[VorlC] = docParagraphStyles[xx].name();
01439                                    VorlC++;
01440                             }
01441                             fou = true;
01442                      }
01443                      else
01444                      {
01445                             vg->setName("Copy of "+docParagraphStyles[xx].name());
01446                             fou = false;
01447                      }
01448                      break;
01449               }
01450        }
01451        if (!fou)
01452        {
01453               for (uint xx=0; xx< docParagraphStyles.count(); ++xx)
01454               {
01455                      if (vg->equiv(docParagraphStyles[xx]))
01456                      {
01457                             vg->setName(docParagraphStyles[xx].name());
01458                             fou = true;
01459                             if (fl)
01460                             {
01461                                    DoVorl[VorlC] = docParagraphStyles[xx].name();
01462                                    VorlC++;
01463                             }
01464                             break;
01465                      }
01466               }
01467        }
01468        if (!fou)
01469        {
01470               if (tempParagraphStyles)
01471                      tempParagraphStyles->create(*vg);
01472               else {
01473                      StyleSet<ParagraphStyle> temp;
01474                      temp.create(*vg);
01475                      doc->redefineStyles(temp, false);
01476               }
01477               if (fl)
01478               {
01479                      DoVorl[VorlC] = vg->name();
01480                      VorlC++;
01481               }
01482        }
01483 }
01484 /*
01485 QString Scribus12Format::AskForFont(SCFonts &avail, QString fStr, ScribusDoc *doc)
01486 {
01487        PrefsManager *prefsManager=PrefsManager::instance();
01488 //     QFont fo;
01489        QString tmpf = fStr;
01490        if ((!avail.contains(tmpf)) || (!avail[tmpf].usable()))
01491        {
01492               if ((!prefsManager->appPrefs.GFontSub.contains(tmpf)) || (!avail[prefsManager->appPrefs.GFontSub[tmpf]].usable()))
01493               {
01494                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
01495                      MissingFont *dia = new MissingFont(0, tmpf, doc);
01496                      dia->exec();
01497                      tmpf = dia->getReplacementFont();
01498                      delete dia;
01499                      qApp->setOverrideCursor(QCursor(waitCursor), true);
01500                      prefsManager->appPrefs.GFontSub[fStr] = tmpf;
01501               }
01502               else
01503                      tmpf = prefsManager->appPrefs.GFontSub[tmpf];
01504               ReplacedFonts[fStr] = tmpf;
01505        }
01506        if (!doc->UsedFonts.contains(tmpf))
01507        {
01508 //            fo = avail[tmpf]->Font;
01509 //            fo.setPointSize(qRound(doc->toolSettings.defSize / 10.0));
01510               doc->AddFont(tmpf);
01511        }
01512        DoFonts[fStr] = tmpf;
01513        return tmpf;
01514 }
01515 */
01516 bool Scribus12Format::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles)
01517 {
01518        ParagraphStyle vg;
01519        QDomDocument docu("scridoc");
01520        QString tmpf, tmf;
01521 //     DoFonts.clear();
01522        QString f (readSLA(fileName));
01523        if (f.isEmpty())
01524               return false;
01525        if(!docu.setContent(f))
01526               return false;
01527        QDomElement elem=docu.documentElement();
01528        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
01529               return false;
01530        QDomNode DOC=elem.firstChild();
01531        while(!DOC.isNull())
01532        {
01533               QDomElement dc=DOC.toElement();
01534               QDomNode PAGE=DOC.firstChild();
01535               while(!PAGE.isNull())
01536               {
01537                      QDomElement pg=PAGE.toElement();
01538                      if(pg.tagName()=="STYLE")
01539                             GetStyle(&pg, &vg, &docParagraphStyles, doc, false);
01540                      PAGE=PAGE.nextSibling();
01541               }
01542               DOC=DOC.nextSibling();
01543        }
01544        return true;
01545 }
01546 
01547 bool Scribus12Format::readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty)
01548 {
01549        QDomDocument docu("scridoc");
01550        QString f(readSLA(fileName));
01551        if (f.isEmpty())
01552               return false;
01553        if(!docu.setContent(f))
01554               return false;
01555        QDomElement elem=docu.documentElement();
01556        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
01557               return false;
01558        QDomNode DOC=elem.firstChild();
01559        while(!DOC.isNull())
01560        {
01561               QDomElement dc=DOC.toElement();
01562               QDomNode PAGE=DOC.firstChild();
01563               while(!PAGE.isNull())
01564               {
01565                      QDomElement pg=PAGE.toElement();
01566                      if(pg.tagName()=="MultiLine")
01567                      {
01568                             multiLine ml;
01569                             QDomNode MuLn = PAGE.firstChild();
01570                             while(!MuLn.isNull())
01571                             {
01572                                    QDomElement MuL = MuLn.toElement();
01573                                    struct SingleLine sl;
01574                                    sl.Color = MuL.attribute("Color");
01575                                    sl.Dash = MuL.attribute("Dash").toInt();
01576                                    sl.LineEnd = MuL.attribute("LineEnd").toInt();
01577                                    sl.LineJoin = MuL.attribute("LineJoin").toInt();
01578                                    sl.Shade = MuL.attribute("Shade").toInt();
01579                                    sl.Width = MuL.attribute("Width").toDouble();
01580                                    ml.push_back(sl);
01581                                    MuLn = MuLn.nextSibling();
01582                             }
01583                             QString Nam = pg.attribute("Name");
01584                             QString Nam2 = Nam;
01585                             int copyC = 1;
01586                             QMap<QString,multiLine>::ConstIterator mlit = Sty->find(Nam2);
01587                             if (mlit != Sty->end() && ml != mlit.data())
01588                             {
01589                                    while (Sty->contains(Nam2))
01590                                    {
01591                                           Nam2 = tr("Copy #%1 of ").arg(copyC)+Nam;
01592                                           copyC++;
01593                                    }
01594                             }
01595                             Sty->insert(Nam2, ml);
01596                      }
01597                      PAGE=PAGE.nextSibling();
01598               }
01599               DOC=DOC.nextSibling();
01600        }
01601        return true;
01602 }
01603 
01604 
01605 bool Scribus12Format::readColors(const QString& fileName, ColorList & colors)
01606 {
01607        QString f(readSLA(fileName));
01608        if (f.isEmpty())
01609               return false;
01610        QDomDocument docu("scridoc");
01611        if(!docu.setContent(f))
01612               return false;
01613        colors.clear();
01614        ScColor lf = ScColor();
01615        QDomElement elem=docu.documentElement();
01616        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
01617               return false;
01618        QDomNode DOC=elem.firstChild();
01619        while(!DOC.isNull())
01620        {
01621               QDomElement dc=DOC.toElement();
01622               QDomNode PAGE=DOC.firstChild();
01623               while(!PAGE.isNull())
01624               {
01625                      QDomElement pg=PAGE.toElement();
01626                      // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
01627                      if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
01628                      {
01629                             if (pg.hasAttribute("CMYK"))
01630                                    lf.setNamedColor(pg.attribute("CMYK"));
01631                             else
01632                                    lf.fromQColor(QColor(pg.attribute("RGB")));
01633                             if (pg.hasAttribute("Spot"))
01634                                    lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
01635                             else
01636                                    lf.setSpotColor(false);
01637                             if (pg.hasAttribute("Register"))
01638                                    lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
01639                             else
01640                                    lf.setRegistrationColor(false);
01641                             colors.insert(pg.attribute("NAME"), lf);
01642                      }
01643                      PAGE=PAGE.nextSibling();
01644               }
01645               DOC=DOC.nextSibling();
01646        }
01647        return true;
01648 }
01649 
01650 bool Scribus12Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
01651 {
01652        QString PgNam;
01653        int counter = 0;
01654        int counter2 = 0;
01655        QDomDocument docu("scridoc");
01656        QString f(readSLA(fileName));
01657        if (f.isEmpty())
01658               return false;
01659        if(!docu.setContent(f))
01660               return false;
01661        QDomElement elem=docu.documentElement();
01662        if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8"))
01663               return false;
01664        QDomNode DOC=elem.firstChild();
01665        while(!DOC.isNull())
01666        {
01667               QDomNode PAGE=DOC.firstChild();
01668               while(!PAGE.isNull())
01669               {
01670                      QDomElement pg=PAGE.toElement();
01671                      if(pg.tagName()=="PAGE")
01672                      {
01673                             PgNam = pg.attribute("NAM", "");
01674                             if (PgNam.isEmpty())
01675                                    counter++;
01676                             else
01677                             {
01678                                    counter2++;
01679                                    masterPageNames.append(PgNam);
01680                             }
01681                      }
01682                      PAGE=PAGE.nextSibling();
01683               }
01684               DOC=DOC.nextSibling();
01685        }
01686        *num1 = counter;
01687        *num2 = counter2;
01688        return true;
01689 }