Back to index

scribus-ng  1.3.4.dfsg+svn20071115
fileloader.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 <qdom.h>
00008 #include <qfile.h>
00009 #include <qfileinfo.h>
00010 #include <qtl.h>
00011 #include <qcursor.h>
00012 #include <qregexp.h>
00013 #include <qdir.h>
00014 #include <qtextcodec.h>
00015 #include <qcheckbox.h>
00016 #include <qmessagebox.h>
00017 #include <qprogressbar.h>
00018 #include <cstdlib>
00019 #include <cmath>
00020 #include <qtextstream.h>
00021 
00022 #include "commonstrings.h"
00023 #include "fileloader.h"
00024 #include "fileloader.moc"
00025 #include "fontreplacedialog.h"
00026 #include "hyphenator.h"
00027 #include "missing.h"
00028 #include "page.h"
00029 #include "pluginmanager.h"
00030 #include "plugins/formatidlist.h"
00031 #include "pagestructs.h"
00032 #include "resourcecollection.h"
00033 #include "scconfig.h"
00034 #include "scribuscore.h"
00035 #include "scribusXml.h"
00036 #include "units.h"
00037 #include "loadsaveplugin.h"
00038 #include "guidemanager.h"
00039 #include "text/nlsconfig.h"
00040 
00041 // We need to include the headers for the plugins we support until we start
00042 // using LoadSavePlugin to pick them for us. We only use these headers to
00043 // get the format IDs, NOTHING ELSE.
00044 // #include "plugins/svgimplugin/svgplugin.h"
00045 // #include "plugins/psimport/importpsplugin.h"
00046 // #include "plugins/fileloader/oodraw/oodrawimp.h"
00047 
00048 #include <zlib.h>
00049 #include "util.h"
00050 #include "prefsmanager.h"
00051 
00059 FileLoader::FileLoader(const QString & fileName) :
00060        QObject(0, "FileLoader"),
00061        FileName(fileName),
00062        FileType(-1),
00063        formatSLA12x(LoadSavePlugin::getFormatById(FORMATID_SLA12XIMPORT)),
00064        formatSLA13x(LoadSavePlugin::getFormatById(FORMATID_SLA13XIMPORT)),
00065        formatSLA134(LoadSavePlugin::getFormatById(FORMATID_SLA134IMPORT)),
00066        formatPS(LoadSavePlugin::getFormatById(FORMATID_PSIMPORT)),
00067        formatSVG(LoadSavePlugin::getFormatById(FORMATID_SVGIMPORT)),
00068        formatSXD(LoadSavePlugin::getFormatById(FORMATID_SXDIMPORT)),
00069        formatODG(LoadSavePlugin::getFormatById(FORMATID_ODGIMPORT)),
00070        prefsManager(PrefsManager::instance())
00071 {
00072 }
00073 
00074 // FIXME: This static method is here as a temporary transitional
00075 // measure during the process of converting to file loader plugins.
00076 const QString FileLoader::getLoadFilterString()
00077 {
00078        return LoadSavePlugin::fileDialogLoadFilter().join(";;");
00079 }
00080 
00088 int FileLoader::TestFile()
00089 {
00090        QFileInfo fi = QFileInfo(FileName);
00091        int ret = -1;
00092        if (!fi.exists())
00093               ret = -1;
00094        QString ext = fi.extension(true).lower();
00095 
00096        QValueList<FileFormat> fileFormats(LoadSavePlugin::supportedFormats());
00097        QValueList<FileFormat>::const_iterator it(fileFormats.constBegin());
00098        QValueList<FileFormat>::const_iterator itEnd(fileFormats.constEnd());
00099        for ( ; it != itEnd ; ++it )
00100        {
00101               if ((*it).nameMatch.search("."+ext)!=-1)
00102               {
00103 //                   qDebug(QString("Match :%1: :.%2: on %3").arg((*it).nameMatch.pattern()).arg(ext).arg((*it).trName));
00104                      if ((*it).plug!=0)
00105                      {
00106                             if ((*it).plug->fileSupported(0, FileName))
00107                             {
00108 //                                 qDebug(QString("File Supported With: %1").arg((*it).trName));
00109                                    ret=(*it).formatId;
00110                                    break;
00111                             }
00112                      }
00113               }
00114 //            else
00115 //                   qDebug(QString("No Match :%1: :.%2: on %3").arg((*it).nameMatch.pattern()).arg(ext).arg((*it).trName));
00116        }
00117        
00118 //     if (ret==-1)
00119 //     {
00120 //            if ((ext.endsWith("sla.gz")) || (ext.endsWith("sla")) || (ext.endsWith("scd.gz")) || (ext.endsWith("scd")))
00121 //                   ret = CheckScribus();
00122 //            else 
00123 //            if (((ext.endsWith("ps")) || (ext.endsWith("eps"))) && (formatPS))
00124 //                   ret = FORMATID_PSIMPORT;
00125 //            else if (((ext.endsWith("svg")) || (ext.endsWith("svgz"))) && (formatSVG))
00126 //                   ret = FORMATID_SVGIMPORT;
00127 //            else if ((ext.endsWith("sxd")) && (formatSXD))
00128 //                   ret = FORMATID_SXDIMPORT;
00129 //            else if ((ext.endsWith("odg")) && (formatODG))
00130 //                   ret = FORMATID_ODGIMPORT;
00131 //     }
00132 /*     if (ext == "pdf")
00133               ret = 4; */
00134        FileType = ret;
00135        return ret;
00136 }
00137 /*
00138 static void replaceFonts(ScribusDoc* currDoc, PageItem *it, QMap<QString, int> UsedFonts, QMap<QString, QString> ReplacedFonts)
00139 {      
00140        if ((it->asTextFrame()) || (it->asPathText()))
00141        {
00142               CharStyle newFontStyle;
00143               for (uint e = 0; e < it->itemText.nrOfRuns(); ++e)
00144               {
00145                      int start = it->itemText.startOfRun(e);
00146                      ScFace oldFont = it->itemText.charStyle(start).font();
00147                      if (!UsedFonts.contains(oldFont.scName())) {
00148                             newFontStyle.setFont((*currDoc->AllFonts)[ReplacedFonts[oldFont.scName()]]);
00149                             it->itemText.applyCharStyle(start, it->itemText.endOfRun(e) - start, newFontStyle );
00150                      }
00151               }
00152        }
00153 }
00154 
00155 */
00156 bool FileLoader::LoadPage(ScribusDoc* currDoc, int PageToLoad, bool Mpage, QString renamedPageName)
00157 {
00158        bool ret = false;
00159 //     newReplacement = false;
00160        ReplacedFonts = currDoc->AllFonts->getSubstitutions();
00161 //     dummyScFaces.clear();
00162        QValueList<FileFormat>::const_iterator it;
00163        if (findFormat(FileType, it))
00164        {
00165               if (FileType==FORMATID_SLA12XIMPORT)
00166               {
00167                      (*it).plug->setupTargets(currDoc, currDoc->view(), currDoc->scMW(), currDoc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00168                      ret=(*it).plug->loadPage(FileName, PageToLoad, Mpage, renamedPageName);
00169                      //if (ret)
00170                      //     (*it).plug->getReplacedFontData(newReplacement, ReplacedFonts, dummyScFaces);
00171               }
00172               if (FileType==FORMATID_SLA13XIMPORT || FileType==FORMATID_SLA134IMPORT)
00173               {
00174                      (*it).plug->setupTargets(currDoc, 0, currDoc->scMW(), currDoc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00175                      ret=(*it).plug->loadPage(FileName, PageToLoad, Mpage, renamedPageName);
00176                      //if (ret)
00177                      //     (*it).plug->getReplacedFontData(newReplacement, ReplacedFonts, dummyScFaces);
00178               }
00179        }
00180        if (ret)
00181               ret = postLoad(currDoc);  // FIXME: return false if user doesnt want to replace fonts??
00182        
00183        /*
00184        //FIXME: this goes into scribusdoc and should work with substitutes
00185        if (ReplacedFonts.count() != 0)
00186        {
00187               if ((prefsManager->appPrefs.askBeforeSubstituite) || (newReplacement))
00188               {
00189                      qApp->setOverrideCursor(QCursor(Qt::arrowCursor), true);
00190                      FontReplaceDialog dia(0, &ReplacedFonts);
00191                      if (dia.exec())
00192                      {
00193                             QMap<QString,QString>::Iterator itfsu;
00194                             for (itfsu = ReplacedFonts.begin(); itfsu != ReplacedFonts.end(); ++itfsu)
00195                             {
00196                                    if (dia.stickyReplacements->isChecked())
00197                                           prefsManager->appPrefs.GFontSub[itfsu.key()] = itfsu.data();
00198                             }
00199                      }
00200                      else
00201                      {
00202                             return false;
00203                      }
00204               }
00205               for (uint d = 0; d < currDoc->MasterItems.count(); ++d)
00206               {
00207                      replaceFonts(currDoc, currDoc->MasterItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00208               }
00209               for (uint d = 0; d < currDoc->DocItems.count(); ++d)
00210               {
00211                      replaceFonts(currDoc, currDoc->DocItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00212               }
00213               for (uint d = 0; d < currDoc->FrameItems.count(); ++d)
00214               {
00215                      replaceFonts(currDoc, currDoc->FrameItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00216               }
00217               for (uint a = 0; a < currDoc->paragraphStyles().count(); ++a)
00218               {
00219 //                   if ( !currDoc->paragraphStyles()[a].charStyle().font().isNone() && !currDoc->UsedFonts.contains(currDoc->paragraphStyles()[a].charStyle().font().scName()))
00220 //                          currDoc->paragraphStyles()[a].charStyle().setFont
00221 //                                 ((*currDoc->AllFonts)[ReplacedFonts[currDoc->paragraphStyles()[a].charStyle().font().scName()]]);
00222               }
00223               QMap<QString,QString>::Iterator itfsu;
00224               for (itfsu = ReplacedFonts.begin(); itfsu != ReplacedFonts.end(); ++itfsu)
00225               {
00226                      if (!currDoc->UsedFonts.contains(itfsu.data()))
00227                      {
00228 //                          QFont fo = prefsManager->appPrefs.AvailFonts[itfsu.data()]->Font;
00229 //                          fo.setPointSize(qRound(ScMW->doc->toolSettings.defSize / 10.0));
00230                             currDoc->AddFont(itfsu.data(), qRound(currDoc->toolSettings.defSize / 10.0));
00231                      }
00232               }
00233               if (prefsManager->appPrefs.askBeforeSubstituite)
00234                      ReplacedFonts.clear();
00235               //dummyScFaces.clear();
00236        }
00237         */
00238        return ret;
00239 }
00240 
00248 bool FileLoader::LoadFile(ScribusDoc* currDoc)
00249 {
00250        newReplacement = false;
00251        currDoc->guidesSettings.marginsShown = prefsManager->appPrefs.guidesSettings.marginsShown;
00252        currDoc->guidesSettings.framesShown = prefsManager->appPrefs.guidesSettings.framesShown;
00253        currDoc->guidesSettings.layerMarkersShown = prefsManager->appPrefs.guidesSettings.layerMarkersShown;
00254        currDoc->guidesSettings.gridShown = prefsManager->appPrefs.guidesSettings.gridShown;
00255        currDoc->guidesSettings.guidesShown = prefsManager->appPrefs.guidesSettings.guidesShown;
00256        currDoc->guidesSettings.colBordersShown = prefsManager->appPrefs.guidesSettings.colBordersShown;
00257        currDoc->guidesSettings.baseShown = prefsManager->appPrefs.guidesSettings.baseShown;
00258        currDoc->guidesSettings.linkShown = prefsManager->appPrefs.guidesSettings.linkShown;
00259        currDoc->toolSettings.polyC = prefsManager->appPrefs.toolSettings.polyC;
00260        currDoc->toolSettings.polyF = prefsManager->appPrefs.toolSettings.polyF;
00261        currDoc->toolSettings.polyR = prefsManager->appPrefs.toolSettings.polyR;
00262        currDoc->toolSettings.polyFd = prefsManager->appPrefs.toolSettings.polyFd;
00263        currDoc->toolSettings.polyS = prefsManager->appPrefs.toolSettings.polyS;
00264        currDoc->AutoSave = prefsManager->appPrefs.AutoSave;
00265        currDoc->AutoSaveTime = prefsManager->appPrefs.AutoSaveTime;
00266        ReplacedFonts = currDoc->AllFonts->getSubstitutions();
00267        //dummyScFaces.clear();
00268        bool ret = false;
00269        QValueList<FileFormat>::const_iterator it;
00270        if (findFormat(FileType, it))
00271               switch (FileType)
00272               {
00273                      case FORMATID_SLA12XIMPORT:
00274                             {
00275                                    (*it).setupTargets(currDoc, currDoc->view(), currDoc->scMW(), currDoc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00276                                    ret=(*it).loadFile(FileName, LoadSavePlugin::lfCreateDoc);
00277                                    //if (ret)
00278                                    //     (*it).getReplacedFontData(newReplacement, ReplacedFonts, dummyScFaces);
00279                             }
00280                             break;
00281                      case FORMATID_SLA13XIMPORT:
00282                      case FORMATID_SLA134IMPORT:
00283                             {
00284                                    (*it).setupTargets(currDoc, 0, currDoc->scMW(), currDoc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00285                                    ret=(*it).loadFile(FileName, LoadSavePlugin::lfCreateDoc);
00286                                    //if (ret)
00287                                    //     (*it).getReplacedFontData(newReplacement, ReplacedFonts, dummyScFaces);
00288                             }
00289                             break;
00290                      default:
00291                             (*it).setupTargets(currDoc, currDoc->view(), currDoc->scMW(), currDoc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00292                             ret = (*it).loadFile(FileName, LoadSavePlugin::lfCreateDoc);
00293                             break;
00294               }
00295        return ret;
00296 }
00297 
00298 bool FileLoader::SaveFile(const QString& fileName, ScribusDoc *doc, QProgressBar* /*dia2*/)
00299 {
00300        bool ret = false;
00301        QValueList<FileFormat>::const_iterator it;
00302        if (findFormat(FORMATID_SLA134EXPORT, it))
00303 //            switch (FileType)
00304 //            {
00305 //                   case FORMATID_SLA12XIMPORT:
00306 //                                 ret=(*it).loadFile(FileName, LoadSavePlugin::lfCreateDoc);
00307 //                          break;
00308 //                   case FORMATID_SLA13XIMPORT:
00309                                    (*it).setupTargets(doc, 0, doc->scMW(), doc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00310                                    ret=(*it).saveFile(fileName);
00311 //                          break;
00312 //                   default:
00313 //                          ret = (*it).loadFile(FileName, LoadSavePlugin::lfCreateDoc);
00314 //                          break;
00315 //            }
00316        return ret;
00317 }
00318 
00319 bool FileLoader::ReadStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles)
00320 {
00321        QValueList<FileFormat>::const_iterator it;
00322        if (findFormat(FileType, it)) {
00323               (*it).plug->setupTargets(doc, 0, doc->scMW(), doc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00324               return (*it).readStyles(fileName, doc, docParagraphStyles);
00325        }
00326        return false;
00327 }
00328 
00329 bool FileLoader::ReadCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles)
00330 {
00331        QValueList<FileFormat>::const_iterator it;
00332        if (findFormat(FileType, it)) {
00333               (*it).plug->setupTargets(doc, 0, doc->scMW(), doc->scMW()->mainWindowProgressBar, &(prefsManager->appPrefs.AvailFonts));
00334               return (*it).readCharStyles(fileName, doc, docCharStyles);
00335        }
00336        return false;
00337 }
00338 
00339 bool FileLoader::ReadColors(const QString& fileName, ColorList & colors)
00340 {
00341        QValueList<FileFormat>::const_iterator it;
00342        if (findFormat(FileType, it))
00343               return (*it).readColors(fileName, colors);
00344        return false;
00345 }
00346 
00347 
00348 bool FileLoader::ReadPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
00349 {
00350        QValueList<FileFormat>::const_iterator it;
00351        if (findFormat(FileType, it))
00352               return (*it).readPageCount(fileName, num1, num2, masterPageNames);
00353        return false;
00354 }
00355 
00356 bool FileLoader::ReadLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty)
00357 {
00358        QValueList<FileFormat>::const_iterator it;
00359        if (findFormat(FileType, it))
00360               return (*it).readLineStyles(fileName, Sty);
00361        return false;
00362 }
00363 
00364 void FileLoader::readParagraphStyle(ParagraphStyle& vg, const QDomElement& pg, SCFonts &avail, ScribusDoc *currDoc)
00365 {
00366        vg.setName(pg.attribute("NAME"));
00367        vg.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg.attribute("LINESPMode", "0").toInt()));
00368        vg.setLineSpacing(pg.attribute("LINESP").toDouble());
00369        vg.setLeftMargin(pg.attribute("INDENT", "0").toDouble());
00370        if (pg.hasAttribute("RMARGIN"))
00371               vg.setRightMargin(pg.attribute("RMARGIN", "0").toDouble());
00372        else
00373               vg.setRightMargin(0);
00374        vg.setFirstIndent(pg.attribute("FIRST", "0").toDouble());
00375        vg.setAlignment(static_cast<ParagraphStyle::AlignmentType>(pg.attribute("ALIGN").toInt()));
00376        vg.setGapBefore(pg.attribute("VOR", "0").toDouble());
00377        vg.setGapAfter(pg.attribute("NACH", "0").toDouble());
00378        QString tmpf = pg.attribute("FONT", currDoc->toolSettings.defFont);
00379        currDoc->AllFonts->findFont(tmpf, currDoc);
00380               vg.charStyle().setFont((*currDoc->AllFonts)[tmpf]);
00381               vg.charStyle().setFontSize(qRound(pg.attribute("FONTSIZE", "12").toDouble() * 10.0));
00382               vg.setHasDropCap(static_cast<bool>(pg.attribute("DROP", "0").toInt()));
00383               vg.setDropCapLines(pg.attribute("DROPLIN", "2").toInt());
00384               vg.setDropCapOffset(pg.attribute("DROPDIST", "0").toDouble());
00385               vg.charStyle().setFeatures(static_cast<StyleFlag>(pg.attribute("EFFECT", "0").toInt()).featureList());
00386               vg.charStyle().setFillColor(pg.attribute("FCOLOR", currDoc->toolSettings.dBrush));
00387               vg.charStyle().setFillShade(pg.attribute("FSHADE", "100").toInt());
00388               vg.charStyle().setStrokeColor(pg.attribute("SCOLOR", currDoc->toolSettings.dPen));
00389               vg.charStyle().setStrokeShade(pg.attribute("SSHADE", "100").toInt());
00390               if (static_cast<bool>(pg.attribute("BASE", "0").toInt()))
00391                      vg.setLineSpacingMode(ParagraphStyle::BaselineGridLineSpacing);
00392               vg.charStyle().setShadowXOffset(qRound(pg.attribute("TXTSHX", "5").toDouble() * 10));
00393               vg.charStyle().setShadowYOffset(qRound(pg.attribute("TXTSHY", "-5").toDouble() * 10));
00394               vg.charStyle().setOutlineWidth(qRound(pg.attribute("TXTOUT", "1").toDouble() * 10));
00395               vg.charStyle().setUnderlineOffset(qRound(pg.attribute("TXTULP", "-0.1").toDouble() * 10));
00396               vg.charStyle().setUnderlineWidth(qRound(pg.attribute("TXTULW", "-0.1").toDouble() * 10));
00397               vg.charStyle().setStrikethruOffset(qRound(pg.attribute("TXTSTP", "-0.1").toDouble() * 10));
00398               vg.charStyle().setStrikethruWidth(qRound(pg.attribute("TXTSTW", "-0.1").toDouble() * 10));
00399               vg.charStyle().setScaleH(qRound(pg.attribute("SCALEH", "100").toDouble() * 10));
00400               vg.charStyle().setScaleV(qRound(pg.attribute("SCALEV", "100").toDouble() * 10));
00401               vg.charStyle().setBaselineOffset(qRound(pg.attribute("BASEO", "0").toDouble() * 10));
00402               vg.charStyle().setTracking(qRound(pg.attribute("KERN", "0").toDouble() * 10));
00403               if ((pg.hasAttribute("NUMTAB")) && (pg.attribute("NUMTAB", "0").toInt() != 0))
00404               {
00405                      QValueList<ParagraphStyle::TabRecord> tbs;
00406                      ParagraphStyle::TabRecord tb;
00407                      QString tmp = pg.attribute("TABS");
00408                      QTextStream tgv(&tmp, IO_ReadOnly);
00409                      double xf, xf2;
00410                      for (int cxv = 0; cxv < pg.attribute("NUMTAB", "0").toInt(); cxv += 2)
00411                      {
00412                             tgv >> xf;
00413                             tgv >> xf2;
00414                             tb.tabPosition = xf2;
00415                             tb.tabType = static_cast<int>(xf);
00416                             tb.tabFillChar =  QChar();
00417                             tbs.append(tb);
00418                      }
00419                      vg.setTabValues(tbs);
00420                      tmp = "";
00421               }
00422               else
00423               {
00424                      QValueList<ParagraphStyle::TabRecord> tbs;
00425                      QDomNode IT = pg.firstChild();
00426                      while(!IT.isNull())
00427                      {
00428                             QDomElement it = IT.toElement();
00429                             if (it.tagName()=="Tabs")
00430                             {
00431                                    ParagraphStyle::TabRecord tb;
00432                                    tb.tabPosition = it.attribute("Pos").toDouble();
00433                                    tb.tabType = it.attribute("Type").toInt();
00434                                    QString tbCh = "";
00435                                    tbCh = it.attribute("Fill","");
00436                                    if (tbCh.isEmpty())
00437                                           tb.tabFillChar = QChar();
00438                                    else
00439                                           tb.tabFillChar = tbCh[0];
00440                                    tbs.append(tb);
00441                             }
00442                             IT=IT.nextSibling();
00443                      }
00444                      vg.setTabValues(tbs);
00445               }
00446 }
00447 
00448 bool FileLoader::postLoad(ScribusDoc* currDoc)
00449 {
00450        //CB #3749 We have to set these up in post load as each format will load into the doc itself
00451        //settings. As the hyphenator was created in the doc constructor, it needs to be updated.
00452        //FIXME: Remove these duplicate settings altogether
00453        if (currDoc->docHyphenator!=0)
00454        {
00455                      currDoc->docHyphenator->Automatic=currDoc->Automatic;
00456                      currDoc->docHyphenator->AutoCheck=currDoc->AutoCheck;
00457                      currDoc->docHyphenator->Language=currDoc->Language;
00458                      currDoc->docHyphenator->MinWordLen=currDoc->MinWordLen;
00459                      currDoc->docHyphenator->HyCount=currDoc->HyCount;
00460        }
00461 /*     for (uint d = 0; d < ScMW->doc->MasterItems.count(); ++d)
00462        {
00463               PageItem *it = ScMW->doc->MasterItems.at(d);
00464               if ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText))
00465               {
00466                      for (uint e = 0; e < it->itemText.count(); ++e)
00467                      {
00468                             ScText *hl = it->itemText.at(e);
00469                             if ((hl->ch == QChar(25)) && ((int)hl->cembedded != -1))
00470                                    hl->cembedded = ScMW->doc->FrameItems.at((int)hl->cembedded);
00471                             else
00472                                    hl->cembedded = 0;
00473                      }
00474               }
00475        }
00476        for (uint d = 0; d < ScMW->doc->DocItems.count(); ++d)
00477        {
00478               PageItem *it = ScMW->doc->DocItems.at(d);
00479               if ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText))
00480               {
00481                      for (uint e = 0; e < it->itemText.count(); ++e)
00482                      {
00483                             ScText *hl = it->itemText.at(e);
00484                             if ((hl->ch == QChar(25)) && ((int)hl->cembedded != -1))
00485                                    hl->cembedded = ScMW->doc->FrameItems.at((int)hl->cembedded);
00486                             else
00487                                    hl->cembedded = 0;
00488                      }
00489               }
00490        } */
00491        //FIXME: this goes into scribusdoc
00492        //ResourceCollection rsc;
00493        //currDoc->getNamedResources(rsc);
00494        //ReplacedFonts.clear();
00495        //QMap<QString,QString>::ConstIterator it;
00496        //for (it = rsc.fonts().begin(); it != rsc.fonts().end(); ++it)
00497        //{
00498        //     const ScFace& font (rsc.availableFonts->findFont(it.key(), currDoc));
00499        //     if (font.isReplacement() )
00500        //            ReplacedFonts[it.key()] = font.replacementName();
00501        //}
00502               ReplacedFonts = currDoc->AllFonts->getSubstitutions(ReplacedFonts.keys());
00503        if (ReplacedFonts.count() != 0)
00504        {
00505               if ((prefsManager->appPrefs.askBeforeSubstituite)) 
00506               {
00507                      qApp->setOverrideCursor(QCursor(Qt::arrowCursor), true);
00508                      FontReplaceDialog dia(0, &ReplacedFonts);
00509                      if (dia.exec())
00510                      {
00511                             QMap<QString,QString>::Iterator itfsu;
00512                             for (itfsu = ReplacedFonts.begin(); itfsu != ReplacedFonts.end(); ++itfsu)
00513                             {
00514                                    if (dia.stickyReplacements->isChecked())
00515                                           prefsManager->appPrefs.GFontSub[itfsu.key()] = itfsu.data();
00516                             }
00517                             currDoc->AllFonts->setSubstitutions(ReplacedFonts, currDoc);
00518                             //ResourceCollection repl;
00519                             //repl.mapFonts(ReplacedFonts);
00520                             //currDoc->replaceNamedResources(repl);
00521                             return true;
00522                      }
00523                      else
00524                      {
00525                             return false;
00526                      }
00527               }
00528               /*
00529               for (uint d = 0; d < currDoc->MasterItems.count(); ++d)
00530               {
00531                      replaceFonts(currDoc, currDoc->MasterItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00532               }
00533               for (uint d = 0; d < currDoc->DocItems.count(); ++d)
00534               {
00535                      replaceFonts(currDoc, currDoc->DocItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00536               }
00537               for (uint d = 0; d < currDoc->FrameItems.count(); ++d)
00538               {
00539                      replaceFonts(currDoc, currDoc->FrameItems.at(d), currDoc->UsedFonts, ReplacedFonts);
00540               }
00541               for (uint a = 0; a < currDoc->paragraphStyles().count(); ++a)
00542               {
00543                      if ( !currDoc->paragraphStyles()[a].charStyle().font().isNone() 
00544                              && !currDoc->UsedFonts.contains(currDoc->paragraphStyles()[a].charStyle().font().scName()))
00545                      {
00546 //                          currDoc->paragraphStyles()[a].charStyle().setFont
00547 //                                 ((*currDoc->AllFonts)[ReplacedFonts[currDoc->paragraphStyles()[a].charStyle().font().scName()]]);
00548                      }
00549               }
00550               QValueList<QString> tmpList;
00551               tmpList.clear();
00552               for (uint fe = 0; fe < currDoc->PDF_Options.EmbedList.count(); ++fe)
00553               {
00554                      if (ReplacedFonts.contains(currDoc->PDF_Options.EmbedList[fe]))
00555                             tmpList.append(ReplacedFonts[currDoc->PDF_Options.EmbedList[fe]]);
00556                      else
00557                             tmpList.append(currDoc->PDF_Options.EmbedList[fe]);
00558               }
00559               currDoc->PDF_Options.EmbedList = tmpList;
00560               tmpList.clear();
00561               for (uint fe = 0; fe < currDoc->PDF_Options.SubsetList.count(); ++fe)
00562               {
00563                      if (ReplacedFonts.contains(currDoc->PDF_Options.SubsetList[fe]))
00564                             tmpList.append(ReplacedFonts[currDoc->PDF_Options.SubsetList[fe]]);
00565                      else
00566                             tmpList.append(currDoc->PDF_Options.SubsetList[fe]);
00567               }
00568               currDoc->PDF_Options.SubsetList = tmpList;
00569               QMap<QString,QString>::Iterator itfsu;
00570               for (itfsu = ReplacedFonts.begin(); itfsu != ReplacedFonts.end(); ++itfsu)
00571               {
00572                      if (!currDoc->UsedFonts.contains(itfsu.data()))
00573                      {
00574 //                          QFont fo = prefsManager->appPrefs.AvailFonts[itfsu.data()]->Font;
00575 //                          fo.setPointSize(qRound(ScMW->doc->toolSettings.defSize / 10.0));
00576                             currDoc->AddFont(itfsu.data(), qRound(currDoc->toolSettings.defSize / 10.0));
00577                      }
00578               }
00579               if (prefsManager->appPrefs.askBeforeSubstituite)
00580                      ReplacedFonts.clear();
00581               dummyScFaces.clear();
00582                */
00583        }
00584 
00585        return true;
00586 }
00587 
00588 void FileLoader::informReplacementFonts()
00589 {
00590        if (ReplacedFonts.count() != 0)
00591        {
00592               qApp->setOverrideCursor(QCursor(arrowCursor), true);
00593               QString mess = tr("Some fonts used by this document have been substituted:")+"\n\n";
00594               QMap<QString,QString>::Iterator it;
00595               for (it = ReplacedFonts.begin(); it != ReplacedFonts.end(); ++it)
00596               {
00597                      mess += it.key() + tr(" was replaced by: ")+ it.data() +"\n";
00598               }
00599               QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, mess, 1, 0, 0);
00600        }
00601 }
00602 
00603 bool FileLoader::findFormat(uint formatId, QValueList<FileFormat>::const_iterator &it)
00604 {
00605        QValueList<FileFormat> fileFormats(LoadSavePlugin::supportedFormats());
00606        it=fileFormats.constBegin();
00607        QValueList<FileFormat>::const_iterator itEnd(fileFormats.constEnd());
00608        for ( ; it != itEnd ; ++it )
00609        {
00610               if (formatId==(*it).formatId)
00611                      return true;
00612        }
00613        return false;
00614 }