Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

scribusdoc.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 /***************************************************************************
00008                           scribusdoc.cpp  -  description
00009                              -------------------
00010     begin                : Fre Apr  6 21:47:55 CEST 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 
00025 #include <utility>
00026 
00027 #include <QByteArray>
00028 #include <QDebug>
00029 #include <QEventLoop>
00030 #include <QFile>
00031 #include <QList>
00032 #include <QPainter>
00033 #include <QPixmap>
00034 #include <QProgressBar>
00035 
00036 #include "canvas.h"
00037 #include "cmserrorhandling.h"
00038 #include "commonstrings.h"
00039 #include "fileloader.h"
00040 #include "filewatcher.h"
00041 #include "guidemanager.h"
00042 #include "hruler.h"
00043 #include "hyphenator.h"
00044 #include "layers.h"
00045 #include "page.h"
00046 #include "pageitem.h"
00047 #include "pageitem_imageframe.h"
00048 #include "pageitem_latexframe.h"
00049 #include "pageitem_line.h"
00050 #include "pageitem_pathtext.h"
00051 #include "pageitem_polygon.h"
00052 #include "pageitem_polyline.h"
00053 #include "pageitem_textframe.h"
00054 #include "pagepalette.h"
00055 #include "pagesize.h"
00056 #include "pagestructs.h"
00057 #include "prefsfile.h"
00058 #include "prefsmanager.h"
00059 #include "resourcecollection.h"
00060 #include "sccolorengine.h"
00061 #include "scmessagebox.h"
00062 #include "scpainter.h"
00063 #include "scraction.h"
00064 #include "scribus.h"
00065 #include "scribusXml.h"
00066 #include "scribuscore.h"
00067 #include "scribusdoc.h"
00068 #include "scribusview.h"
00069 #include "scribuswin.h"
00070 #include "selection.h"
00071 #include "story.h"
00072 #include "text/nlsconfig.h"
00073 #include "undomanager.h"
00074 #include "undostate.h"
00075 #include "units.h"
00076 #include "util.h"
00077 #include "util_cms.h"
00078 #include "util_icon.h"
00079 #include "util_math.h"
00080 
00081 
00082 
00083 // static const bool FRAMESELECTION_EDITS_DEFAULTSTYLE = false;
00084 
00085 
00086 
00091 class DocUpdater : public Observer<Page*>, public Observer<PageItem*> 
00092 {
00093     ScribusDoc* doc;
00094 public:
00095     DocUpdater(ScribusDoc* d) : doc(d) {}
00096     
00097     void changed(Page* pg)
00098     {
00099         QRectF pagebox(pg->xOffset(), pg->yOffset(), pg->width(), pg->height());
00100         doc->invalidateRegion(pagebox);
00101         doc->regionsChanged()->update(pagebox);
00102     }
00103     
00104     void changed(PageItem* it)
00105     {
00106         it->invalidateLayout();
00107         doc->regionsChanged()->update(it->getBoundingRect());
00108     }
00109 };
00110 
00111 
00112 
00113 
00114 ScribusDoc::ScribusDoc() : UndoObject( tr("Document")), Observable<ScribusDoc>(NULL),
00115     m_hasGUI(false),
00116     prefsData(PrefsManager::instance()->appPrefs),
00117     undoManager(UndoManager::instance()),
00118     loading(false),
00119     modified(false),
00120     ActiveLayer(0),
00121     docUnitIndex(prefsData.docUnitIndex),
00122     docUnitRatio(unitGetRatioFromIndex(docUnitIndex)),
00123     automaticTextFrames(0),
00124     m_masterPageMode(false),
00125     m_ScMW(0),
00126     m_View(0),
00127     m_guardedObject(this),
00128     is12doc(false),
00129     NrItems(0),
00130     First(1), Last(0),
00131     viewCount(0), viewID(0),
00132     SnapGuides(false), GuideLock(false),
00133     scratch(prefsData.scratch),
00134     GapHorizontal(prefsData.GapHorizontal),
00135     GapVertical(prefsData.GapVertical),
00136 //  ScratchLeft(prefsData.ScratchLeft),
00137 //  ScratchRight(prefsData.ScratchRight),
00138 //  ScratchTop(prefsData.ScratchTop),
00139 //  ScratchBottom(prefsData.ScratchBottom),
00140     minCanvasCoordinate(FPoint(0, 0)),
00141     maxCanvasCoordinate(FPoint(scratch.Left + scratch.Right, scratch.Top + scratch.Bottom)),
00142     rulerXoffset(0.0), rulerYoffset(0.0),
00143     Pages(0), MasterPages(), DocPages(),
00144     MasterNames(),
00145     Items(0), MasterItems(), DocItems(), FrameItems(),
00146     m_Selection(new Selection(this, true)),
00147     pageWidth(0), pageHeight(0),
00148     pageSets(prefsData.pageSets),
00149     PageSp(1), PageSpa(0),
00150     currentPageLayout(0),
00151     PageOri(0), m_pageSize(0),
00152     FirstPnum(1),
00153     useRaster(false),
00154     PageColors(this, true),
00155     appMode(modeNormal),
00156     SubMode(-1),
00157     ShapeValues(0),
00158     ValCount(0),
00159     DocName( tr("Document")+"-"),
00160     UsedFonts(),
00161     AllFonts(&prefsData.AvailFonts),
00162     AObjects(),
00163     papColor(prefsData.DpapColor),
00164     CurrentSel(-1),
00165     nodeEdit(),
00166     typographicSettings(prefsData.typographicSettings),
00167     guidesSettings(prefsData.guidesSettings),
00168     toolSettings(prefsData.toolSettings),
00169     checkerProfiles(prefsData.checkerProfiles),
00170     curCheckProfile(prefsData.curCheckProfile),
00171     LastAuto(0), FirstAuto(0),
00172     DraggedElem(0),
00173     ElemToLink(0),
00174     DragElements(),
00175     docParagraphStyles(),
00176     docCharStyles(),
00177     Layers(),
00178     marginColored(prefsData.marginColored),
00179     GroupCounter(1),
00180     JavaScripts(),
00181     TotalItems(0),
00182     MinWordLen(prefsData.MinWordLen),
00183     HyCount(prefsData.HyCount),
00184     Language(prefsData.Language),
00185     Automatic(prefsData.Automatic),
00186     AutoCheck(prefsData.AutoCheck),
00187     PDF_Options(prefsData.PDF_Options),
00188     RePos(false),
00189     BookMarks(),
00190     OldBM(false),
00191     hasName(false),
00192     RotMode(0),
00193     AutoSave(prefsData.AutoSave),
00194     AutoSaveTime(prefsData.AutoSaveTime),
00195     autoSaveTimer(new QTimer(this)),
00196     MLineStyles(),
00197     arrowStyles(prefsData.arrowStyles),
00198     WinHan(0),
00199     DoDrawing(true),
00200     OpenNodes(),
00201     CurTimer(0),
00202     docLayerErrors(),
00203     docItemErrors(),
00204     masterItemErrors(),
00205     docItemAttributes(prefsData.defaultItemAttributes),
00206     docToCSetups(prefsData.defaultToCSetups),
00207     // sections
00208     symReturn(), symNewLine(), symTab(), symNonBreak(), symNewCol(), symNewFrame(),
00209     docHyphenator(0),
00210     m_itemCreationTransaction(NULL),
00211     m_updateManager()
00212 {
00213     init();
00214     bleeds = prefsData.bleeds;
00215     PDF_Options.bleeds = bleeds;
00216     Print_Options.firstUse = true;
00217 }
00218 
00219 
00220 ScribusDoc::ScribusDoc(const QString& docName, int unitindex, const PageSize& pagesize, const MarginStruct& margins, const DocPagesSetup& pagesSetup) : UndoObject( tr("Document")),
00221     m_hasGUI(false),
00222     prefsData(PrefsManager::instance()->appPrefs),
00223     undoManager(UndoManager::instance()),
00224     loading(false),
00225     modified(false),
00226     ActiveLayer(0),
00227     docUnitIndex(unitindex),
00228     docUnitRatio(unitGetRatioFromIndex(docUnitIndex)),
00229     automaticTextFrames(pagesSetup.autoTextFrames),
00230     m_masterPageMode(false),
00231     m_ScMW(0),
00232     m_View(0),
00233     m_guardedObject(this),
00234     is12doc(false),
00235     NrItems(0),
00236     First(1), Last(0),
00237     viewCount(0), viewID(0),
00238     SnapGuides(false), GuideLock(false),
00239     scratch(prefsData.scratch),
00240     GapHorizontal(prefsData.GapHorizontal),
00241     GapVertical(prefsData.GapVertical),
00242 //  ScratchLeft(prefsData.ScratchLeft),
00243 //  ScratchRight(prefsData.ScratchRight),
00244 //  ScratchTop(prefsData.ScratchTop),
00245 //  ScratchBottom(prefsData.ScratchBottom),
00246     minCanvasCoordinate(FPoint(0, 0)),
00247     maxCanvasCoordinate(FPoint(scratch.Left + scratch.Right, scratch.Top + scratch.Bottom)),
00248     rulerXoffset(0.0), rulerYoffset(0.0),
00249     Pages(0), MasterPages(), DocPages(),
00250     MasterNames(),
00251     Items(0), MasterItems(), DocItems(), FrameItems(),
00252     m_Selection(new Selection(this, true)),
00253     pageWidth(pagesize.width()), pageHeight(pagesize.height()),
00254     pageMargins(margins),
00255     pageSets(prefsData.pageSets),
00256     PageSp(pagesSetup.columnCount), PageSpa(pagesSetup.columnDistance),
00257     currentPageLayout(pagesSetup.pageArrangement),
00258     PageOri(pagesSetup.orientation), m_pageSize(pagesize.name()),
00259     FirstPnum(pagesSetup.firstPageNumber),
00260     useRaster(false),
00261     PageColors(this, true),
00262     appMode(modeNormal),
00263     SubMode(-1),
00264     ShapeValues(0),
00265     ValCount(0),
00266     DocName(docName),
00267     UsedFonts(),
00268     AllFonts(&prefsData.AvailFonts),
00269     AObjects(),
00270     papColor(prefsData.DpapColor),
00271     CurrentSel(-1),
00272     nodeEdit(),
00273     typographicSettings(prefsData.typographicSettings),
00274     guidesSettings(prefsData.guidesSettings),
00275     toolSettings(prefsData.toolSettings),
00276     checkerProfiles(prefsData.checkerProfiles),
00277     curCheckProfile(prefsData.curCheckProfile),
00278     LastAuto(0), FirstAuto(0),
00279     DraggedElem(0),
00280     ElemToLink(0),
00281     DragElements(),
00282     docParagraphStyles(),
00283     docCharStyles(),
00284     Layers(),
00285     marginColored(prefsData.marginColored),
00286     GroupCounter(1),
00287     JavaScripts(),
00288     TotalItems(0),
00289     MinWordLen(prefsData.MinWordLen),
00290     HyCount(prefsData.HyCount),
00291     Language(prefsData.Language),
00292     Automatic(prefsData.Automatic),
00293     AutoCheck(prefsData.AutoCheck),
00294     PDF_Options(prefsData.PDF_Options),
00295     RePos(false),
00296     BookMarks(),
00297     OldBM(false),
00298     hasName(false),
00299     RotMode(0),
00300     AutoSave(prefsData.AutoSave),
00301     AutoSaveTime(prefsData.AutoSaveTime),
00302     autoSaveTimer(new QTimer(this)),
00303     MLineStyles(),
00304     arrowStyles(prefsData.arrowStyles),
00305     WinHan(0),
00306     DoDrawing(true),
00307     OpenNodes(),
00308     CurTimer(0),
00309     docLayerErrors(),
00310     docItemErrors(),
00311     masterItemErrors(),
00312     docItemAttributes(prefsData.defaultItemAttributes),
00313     docToCSetups(prefsData.defaultToCSetups),
00314     // sections
00315     symReturn(), symNewLine(), symTab(), symNonBreak(), symNewCol(), symNewFrame(),
00316     docHyphenator(0),
00317     m_itemCreationTransaction(NULL),
00318     m_updateManager()
00319 {
00320     pageSets[pagesSetup.pageArrangement].FirstPage = pagesSetup.firstPageLocation;
00321     init();
00322     bleeds = prefsData.bleeds;
00323     PDF_Options.bleeds = bleeds;
00324     Print_Options.firstUse = true;
00325 }
00326 
00327 
00328 void ScribusDoc::init()
00329 {
00330     Q_CHECK_PTR(m_Selection);
00331     Q_CHECK_PTR(autoSaveTimer);
00332 
00333     HasCMS = false;
00334     CMSSettings.CMSinUse = false;
00335 
00336     DocInputRGBProf = NULL;
00337     DocInputCMYKProf = NULL;
00338     DocInputImageRGBProf = NULL;
00339     DocInputImageCMYKProf = NULL;
00340     DocOutputProf = NULL;
00341     DocPrinterProf = NULL;
00342     stdTransRGBMon = NULL;
00343     stdTransCMYKMon = NULL;
00344     stdProof = NULL;
00345     stdTransImg = NULL;
00346     stdProofImg = NULL;
00347     stdTransCMYK = NULL;
00348     stdProofCMYK = NULL;
00349     stdTransRGB = NULL;
00350     stdProofGC = NULL;
00351     stdProofCMYKGC = NULL;
00352     SetDefaultCMSParams();
00353 
00354     // init update change management
00355     setUpdateManager(&m_updateManager);
00356     m_itemsChanged.setUpdateManager(&m_updateManager);
00357     m_pagesChanged.setUpdateManager(&m_updateManager);
00358     m_regionsChanged.setUpdateManager(&m_updateManager);
00359     nodeEdit.setUpdateManager(&m_updateManager);
00360     
00361     // setup update() event chains
00362     m_docUpdater = new DocUpdater(this);
00363     m_itemsChanged.connectObserver(m_docUpdater);
00364     m_pagesChanged.connectObserver(m_docUpdater);
00365 
00366     PrefsManager *prefsManager = PrefsManager::instance();
00367     CMSSettings = prefsManager->appPrefs.DCMSset;
00368     PDF_Options.SolidProf = CMSSettings.DefaultSolidColorRGBProfile;
00369     PDF_Options.ImageProf = CMSSettings.DefaultImageRGBProfile;
00370     PDF_Options.PrintProf = CMSSettings.DefaultPrinterProfile;
00371     PDF_Options.Intent = CMSSettings.DefaultIntentColors;
00372     PDF_Options.Intent2 = CMSSettings.DefaultIntentImages;
00373 
00374     AddFont(prefsData.toolSettings.defFont);//, prefsData.AvailFonts[prefsData.toolSettings.defFont]->Font);
00375     toolSettings.defFont = prefsData.toolSettings.defFont;
00376     toolSettings.defSize = prefsData.toolSettings.defSize;
00377     toolSettings.tabFillChar = prefsData.toolSettings.tabFillChar;
00378     toolSettings.dispX = prefsData.toolSettings.dispX;
00379     toolSettings.dispY = prefsData.toolSettings.dispY;
00380     toolSettings.constrain = prefsData.toolSettings.constrain;
00381 
00382     PageColors.ensureBlackAndWhite();
00383     if (prefsData.toolSettings.dPen != CommonStrings::None)
00384         PageColors.insert(prefsData.toolSettings.dPen, prefsData.DColors[prefsData.toolSettings.dPen]);
00385     toolSettings.dPen = prefsData.toolSettings.dPen;
00386     if (prefsData.toolSettings.dPenLine != CommonStrings::None)
00387         PageColors.insert(prefsData.toolSettings.dPenLine, prefsData.DColors[prefsData.toolSettings.dPenLine]);
00388     toolSettings.dPenLine = prefsData.toolSettings.dPenLine;
00389     if (prefsData.toolSettings.dPenText != CommonStrings::None)
00390         PageColors.insert(prefsData.toolSettings.dPenText, prefsData.DColors[prefsData.toolSettings.dPenText]);
00391     toolSettings.dPenText = prefsData.toolSettings.dPenText;
00392     if (prefsData.toolSettings.dStrokeText != CommonStrings::None)
00393         PageColors.insert(prefsData.toolSettings.dStrokeText, prefsData.DColors[prefsData.toolSettings.dStrokeText]);
00394     toolSettings.dStrokeText = prefsData.toolSettings.dStrokeText;
00395     if (prefsData.toolSettings.dBrush != CommonStrings::None)
00396         PageColors.insert(prefsData.toolSettings.dBrush, prefsData.DColors[prefsData.toolSettings.dBrush]);
00397     toolSettings.dBrush = prefsData.toolSettings.dBrush;
00398     if (prefsData.toolSettings.dBrushPict != CommonStrings::None)
00399         PageColors.insert(prefsData.toolSettings.dBrushPict, prefsData.DColors[prefsData.toolSettings.dBrushPict]);
00400     toolSettings.dBrushPict = prefsData.toolSettings.dBrushPict;
00401     if (prefsData.toolSettings.dTextBackGround != CommonStrings::None)
00402         PageColors.insert(prefsData.toolSettings.dTextBackGround, prefsData.DColors[prefsData.toolSettings.dTextBackGround]);
00403     toolSettings.dTextBackGround = prefsData.toolSettings.dTextBackGround;
00404     if (prefsData.toolSettings.dTextLineColor != CommonStrings::None)
00405         PageColors.insert(prefsData.toolSettings.dTextLineColor, prefsData.DColors[prefsData.toolSettings.dTextLineColor]);
00406 
00407     
00408     ParagraphStyle pstyle;
00409     pstyle.setName( tr("Default Paragraph Style"));
00410     pstyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
00411     pstyle.setLineSpacing(15);
00412     pstyle.setAlignment(ParagraphStyle::Leftaligned);
00413     pstyle.setLeftMargin(0);
00414     pstyle.setFirstIndent(0);
00415     pstyle.setRightMargin(0);
00416     pstyle.setGapBefore(0);
00417     pstyle.setGapAfter(0);
00418     pstyle.setHasDropCap(false);
00419     pstyle.setDropCapLines(2);
00420     pstyle.setDropCapOffset(0);
00421     pstyle.charStyle().setParent("");
00422     
00423     CharStyle cstyle;
00424     cstyle.setName( tr("Default Character Style"));
00425     cstyle.setFont(prefsData.AvailFonts[toolSettings.defFont]);
00426     cstyle.setFontSize(toolSettings.defSize);
00427     cstyle.setFeatures(QStringList(CharStyle::INHERIT));
00428     cstyle.setFillColor(toolSettings.dPenText);
00429     cstyle.setFillShade(toolSettings.dTextPenShade);
00430     cstyle.setStrokeColor(toolSettings.dStrokeText);
00431     cstyle.setStrokeShade(toolSettings.dTextStrokeShade);
00432     cstyle.setBaselineOffset(0);
00433     cstyle.setShadowXOffset(50);
00434     cstyle.setShadowYOffset(-50);
00435     cstyle.setOutlineWidth(10);
00436     cstyle.setUnderlineOffset(typographicSettings.valueUnderlinePos);
00437     cstyle.setUnderlineWidth(typographicSettings.valueUnderlineWidth);
00438     cstyle.setStrikethruOffset(typographicSettings.valueStrikeThruPos);
00439     cstyle.setStrikethruWidth(typographicSettings.valueStrikeThruPos);
00440     cstyle.setScaleH(1000);
00441     cstyle.setScaleV(1000);
00442     cstyle.setTracking(0);
00443     cstyle.setLanguage(PrefsManager::instance()->appPrefs.Language);
00444     
00445     docParagraphStyles.create(pstyle);
00446     docParagraphStyles.makeDefault( &(docParagraphStyles[0]) );
00447     
00448     docCharStyles.create(cstyle);
00449     docCharStyles.makeDefault( &(docCharStyles[0]) );
00450     
00451     docParagraphStyles[0].breakImplicitCharStyleInheritance();
00452     docParagraphStyles[0].charStyle().setContext( & docCharStyles );
00453 //  docParagraphStyles[0].charStyle().setName( "cdocdefault" ); // DONT TRANSLATE
00454 
00455     currentStyle = pstyle;
00456     
00457     Layers.addLayer( tr("Background") );
00458     // Fixme: Check PDF version input
00459     PDF_Options.Version = (PDFOptions::PDFVersion)prefsData.PDF_Options.Version;
00460 
00461     PDF_Options.firstUse = true;
00462     docPatterns.clear();
00463 
00464     if (AutoSave && ScCore->usingGUI())
00465         autoSaveTimer->start(AutoSaveTime);
00466     //Do this after all the collections have been created and cleared!
00467     m_masterPageMode=true; // quick hack to force the change of pointers in setMasterPageMode();
00468     setMasterPageMode(false);
00469     addSymbols();
00470 }
00471 
00472 
00473 ScribusDoc::~ScribusDoc()
00474 {
00475     m_guardedObject.nullify();
00476     CloseCMSProfiles();
00477 //  DocItems.setAutoDelete(true);
00478 //  FrameItems.setAutoDelete(true);
00479 //  DocItems.clear();
00480     while (!DocItems.isEmpty())
00481     {
00482         delete DocItems.takeFirst();
00483     }
00484     FrameItems.clear();
00485 
00486     while (!MasterPages.isEmpty())
00487     {
00488         delete MasterPages.takeFirst();
00489     }
00490     while (!DocPages.isEmpty())
00491     {
00492         delete DocPages.takeFirst();
00493     }
00494 //  MasterPages.setAutoDelete(true);
00495 //  DocPages.setAutoDelete(true);
00496 //  MasterPages.clear();
00497 //  DocPages.clear();
00498 //  MasterItems.setAutoDelete(true);
00499 //  MasterItems.clear();
00500     while (!MasterItems.isEmpty())
00501     {
00502         delete MasterItems.takeFirst();
00503     }
00504     QMap<QString,int>::Iterator it3;
00505     for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3)
00506     {
00507         if (!(*AllFonts)[it3.key()].localForDocument().isEmpty())
00508             (*AllFonts).removeFont(it3.key());
00509         else
00510             (*AllFonts)[it3.key()].decreaseUsage();
00511     }
00512 }
00513 
00514 
00515 void ScribusDoc::setup(const int unitIndex, const int fp, const int firstLeft, const int orientation, const int firstPageNumber, const QString& defaultPageSize, const QString& documentName)
00516 {
00517     docUnitIndex=unitIndex;
00518     pageSets[fp].FirstPage = firstLeft;
00519     PageOri = orientation;
00520     m_pageSize = defaultPageSize;
00521     FirstPnum = firstPageNumber;
00522     currentPageLayout = fp;
00523     setName(documentName);
00524     HasCMS = false;
00525     if (!PDF_Options.UseLPI)
00526     {
00527         PDF_Options.LPISettings.clear();
00528         struct LPIData lpo;
00529         lpo.Frequency = 75;
00530         lpo.SpotFunc = 2;
00531         lpo.Angle = 105;
00532         PDF_Options.LPISettings.insert("Cyan", lpo);
00533         lpo.Angle = 75;
00534         PDF_Options.LPISettings.insert("Magenta", lpo);
00535         lpo.Angle = 90;
00536         PDF_Options.LPISettings.insert("Yellow", lpo);
00537         lpo.Angle = 45;
00538         PDF_Options.LPISettings.insert("Black", lpo);
00539         ActiveLayer = 0;
00540     }
00541 
00542     appMode = modeNormal;
00543     PrefsManager *prefsManager=PrefsManager::instance();
00544     PageColors = prefsManager->colorSet();
00545     PageColors.ensureBlackAndWhite();
00546     PageColors.setDocument(this);
00547 
00548     CMSSettings = prefsManager->appPrefs.DCMSset;
00549     PDF_Options.SolidProf = CMSSettings.DefaultSolidColorRGBProfile;
00550     PDF_Options.ImageProf = CMSSettings.DefaultImageRGBProfile;
00551     PDF_Options.PrintProf = CMSSettings.DefaultPrinterProfile;
00552     PDF_Options.Intent = CMSSettings.DefaultIntentColors;
00553     PDF_Options.Intent2 = CMSSettings.DefaultIntentImages;
00554     BlackPoint   = CMSSettings.BlackPoint;
00555     SoftProofing = CMSSettings.SoftProofOn;
00556     Gamut        = CMSSettings.GamutCheck;
00557     IntentColors = CMSSettings.DefaultIntentColors;
00558     IntentImages = CMSSettings.DefaultIntentImages;
00559     if (ScCore->haveCMS() && CMSSettings.CMSinUse)
00560     {
00561         if (OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles))
00562         {
00563             HasCMS = true;
00564             PDF_Options.SComp = CMSSettings.ComponentsInput2;
00565         }
00566         else
00567         {
00568             SetDefaultCMSParams();
00569             HasCMS = false;
00570         }
00571     }
00572 }
00573 
00574 
00575 void ScribusDoc::setGUI(bool hasgui, ScribusMainWindow* mw, ScribusView* view)
00576 {
00577     m_hasGUI = hasgui;
00578     m_ScMW=mw;
00579     //FIXME: stop using m_View
00580     m_View=view;
00581     docHyphenator=new Hyphenator(m_ScMW, this);
00582     Q_CHECK_PTR(docHyphenator);
00583 }
00584 
00585 
00586 void ScribusDoc::setLoading(const bool docLoading)
00587 {
00588     loading = docLoading;
00589 }
00590 
00591 
00592 bool ScribusDoc::isLoading() const
00593 {
00594     return loading;
00595 }
00596 
00597 
00598 //AV: eeks. That should not be used
00599 ScribusView* ScribusDoc::view() const
00600 {
00601 //  return (WinHan ? (((ScribusWin*) WinHan)->view()) : 0);
00602     return m_View;
00603 }
00604 
00605 
00606 const ScGuardedPtr<ScribusDoc>& ScribusDoc::guardedPtr() const
00607 {
00608     return m_guardedObject;
00609 }
00610 
00611 
00612 void ScribusDoc::CloseCMSProfiles()
00613 {
00614     HasCMS = false;
00615     if (ScCore->haveCMS() /*&& CMSSettings.CMSinUse*/)
00616     {
00617         if (DocInputImageRGBProf && !ScCore->IsDefaultProfile(DocInputImageRGBProf))
00618             cmsCloseProfile(DocInputImageRGBProf);
00619         if (DocInputImageCMYKProf && !ScCore->IsDefaultProfile(DocInputImageCMYKProf))
00620             cmsCloseProfile(DocInputImageCMYKProf);
00621         if (DocInputRGBProf && !ScCore->IsDefaultProfile(DocInputRGBProf))
00622             cmsCloseProfile(DocInputRGBProf);
00623         if (DocInputCMYKProf && !ScCore->IsDefaultProfile(DocInputCMYKProf))
00624             cmsCloseProfile(DocInputCMYKProf);
00625         if (DocOutputProf && !ScCore->IsDefaultProfile(DocOutputProf))
00626             cmsCloseProfile(DocOutputProf);
00627         if (DocPrinterProf && !ScCore->IsDefaultProfile(DocPrinterProf))
00628             cmsCloseProfile(DocPrinterProf);
00629         if (stdTransRGBMon && !ScCore->IsDefaultTransform(stdTransRGBMon))
00630             cmsDeleteTransform(stdTransRGBMon);
00631         if (stdTransCMYKMon && !ScCore->IsDefaultTransform(stdTransCMYKMon))
00632             cmsDeleteTransform(stdTransCMYKMon);
00633         if (stdProof && !ScCore->IsDefaultTransform(stdProof))
00634             cmsDeleteTransform(stdProof);
00635         if (stdTransImg && !ScCore->IsDefaultTransform(stdTransImg))
00636             cmsDeleteTransform(stdTransImg);
00637         if (stdProofImg && !ScCore->IsDefaultTransform(stdProofImg))
00638             cmsDeleteTransform(stdProofImg);
00639         if (stdTransCMYK && !ScCore->IsDefaultTransform(stdTransCMYK))
00640             cmsDeleteTransform(stdTransCMYK);
00641         if (stdProofCMYK && !ScCore->IsDefaultTransform(stdProofCMYK))
00642             cmsDeleteTransform(stdProofCMYK);
00643         if (stdTransRGB && !ScCore->IsDefaultTransform(stdTransRGB))
00644             cmsDeleteTransform(stdTransRGB);
00645         if (stdProofCMYKGC && !ScCore->IsDefaultTransform(stdProofCMYKGC))
00646             cmsDeleteTransform(stdProofCMYKGC);
00647         if (stdProofGC && !ScCore->IsDefaultTransform(stdProofGC))
00648             cmsDeleteTransform(stdProofGC);
00649         DocInputRGBProf = NULL;
00650         DocInputCMYKProf = NULL;
00651         DocInputImageRGBProf = NULL;
00652         DocInputImageCMYKProf = NULL;
00653         DocOutputProf = NULL;
00654         DocPrinterProf = NULL;
00655         stdTransRGBMon = NULL;
00656         stdTransCMYKMon = NULL;
00657         stdProof = NULL;
00658         stdTransImg = NULL;
00659         stdProofImg = NULL;
00660         stdTransCMYK = NULL;
00661         stdProofCMYK = NULL;
00662         stdTransRGB = NULL;
00663         stdProofCMYKGC = NULL;
00664         stdProofGC = NULL;
00665     }
00666     SetDefaultCMSParams();
00667 }
00668 
00669 void ScribusDoc::SetDefaultCMSParams()
00670 {
00671     BlackPoint     = true;
00672     SoftProofing   = false;
00673     Gamut          = false;
00674     IntentColors   = 1; // INTENT_RELATIVE_COLORIMETRIC
00675     IntentImages   = 1; // INTENT_RELATIVE_COLORIMETRIC
00676     DocInputRGBProf       = ScCore->defaultRGBProfile;
00677     DocInputCMYKProf      = ScCore->defaultCMYKProfile;
00678     DocInputImageRGBProf  = ScCore->defaultRGBProfile;
00679     DocInputImageCMYKProf = ScCore->defaultCMYKProfile;
00680     DocOutputProf         = ScCore->defaultRGBProfile;
00681     DocPrinterProf        = ScCore->defaultCMYKProfile;
00682     stdTransRGBMon        = ScCore->defaultRGBToScreenSolidTrans;
00683     stdTransCMYKMon       = ScCore->defaultCMYKToRGBTrans;
00684     stdTransRGB           = ScCore->defaultCMYKToRGBTrans;
00685     stdTransCMYK          = ScCore->defaultRGBToCMYKTrans;
00686     stdProof              = ScCore->defaultRGBToScreenSolidTrans;
00687     stdProofGC            = ScCore->defaultRGBToScreenSolidTrans;
00688     stdProofCMYK          = ScCore->defaultCMYKToRGBTrans;
00689     stdProofCMYKGC        = ScCore->defaultCMYKToRGBTrans;
00690     stdTransImg           = ScCore->defaultRGBToScreenImageTrans;
00691     stdProofImg           = ScCore->defaultRGBToScreenImageTrans;
00692     stdProofImgCMYK       = ScCore->defaultCMYKToScreenImageTrans;
00693 }
00694 
00695 bool ScribusDoc::OpenCMSProfiles(ProfilesL InPo, ProfilesL InPoCMYK, ProfilesL MoPo, ProfilesL PrPo)
00696 {
00697     HasCMS = false;
00698     cmsHPROFILE inputProf = NULL;
00699     cmsErrorAction(LCMS_ERROR_ABORT);
00700     if (setjmp(cmsJumpBuffer))
00701     {
00702         // Reset to the default handler otherwise may enter a loop
00703         // if an error occur afterwards
00704         cmsSetErrorHandler(NULL);
00705         cmsErrorAction(LCMS_ERROR_IGNORE);
00706         CloseCMSProfiles();
00707         cmsErrorAction(LCMS_ERROR_ABORT);
00708         CMSSettings.CMSinUse = false;
00709         QString message = tr("An error occurred while opening ICC profiles, color management is not enabled." );
00710         if (ScCore->usingGUI())
00711             QMessageBox::warning(m_ScMW, CommonStrings::trWarning, message, QMessageBox::Ok, 0, 0);
00712         else
00713             qWarning( "%s", message.toLocal8Bit().data() );
00714         return false;
00715     }
00716     cmsSetErrorHandler(&cmsErrorHandler);
00717     const QByteArray rgbInputProfilePath(InPo[CMSSettings.DefaultSolidColorRGBProfile].toLocal8Bit());
00718     DocInputRGBProf = cmsOpenProfileFromFile(rgbInputProfilePath.data(), "r");
00719     const QByteArray cmykInputProfilePath(InPoCMYK[CMSSettings.DefaultSolidCo