Back to index

scribus-ng  1.3.4.dfsg+svn20071115
preview.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                           preview.cpp  -  description
00009                              -------------------
00010     begin                : Sun Jun 1 08:00:00 CEST 2003
00011     copyright            : (C) 2003 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 #include "preview.h"
00024 #include "preview.moc"
00025 #include <qimage.h>
00026 #include <cstdlib>
00027 #include <qcursor.h>
00028 #include <qpainter.h>
00029 #include <qcolor.h>
00030 #include <qtooltip.h>
00031 #include <qfile.h>
00032 #include <qspinbox.h>
00033 #include <qtable.h>
00034 #include "pslib.h"
00035 #include "checkDocument.h"
00036 #include "cmsettings.h"
00037 #include "prefsfile.h"
00038 #include "prefscontext.h"
00039 #include "prefsmanager.h"
00040 #include "prefstable.h"
00041 #include "util.h"
00042 #include "sccolor.h"
00043 #include "scribusview.h"
00044 #include "scribusdoc.h"
00045 #include "scpaths.h"
00046 #include "pageselector.h"
00047 #include "printerutil.h"
00048 #include "sccolorengine.h"
00049 #include "gsutil.h"
00050 
00051 #if defined(_WIN32)
00052 #include "scwinprint.h"
00053 #endif
00054 
00055 extern bool printDinUse;
00056 
00057 PPreview::PPreview( QWidget* parent, ScribusView *vin, ScribusDoc *docu, int pngAlpha, int tiffSep, QString printer ) : QDialog( parent, "Preview", true, 0 )
00058 {
00059        Q_ASSERT(!docu->masterPageMode());
00060        prefsManager=PrefsManager::instance();
00061        QString tmp;
00062        postscriptPreview = usePostscriptPreview(printer);
00063        QString caption = tr("Print Preview");
00064 #ifdef _WIN32
00065        if (postscriptPreview)
00066               caption += " (Postscript)";
00067        else
00068               caption += " (GDI)";
00069 #endif
00070        setCaption( caption );
00071        doc = docu;
00072        view = vin;
00073        HavePngAlpha = pngAlpha;
00074        HaveTiffSep = postscriptPreview ? tiffSep : 1;
00075        APage = -1;
00076        CMode = false;
00077        GsAl = false;
00078        Trans = false;
00079        GMode = true;
00080        OMode = false;
00081        mHor = false;
00082        mVer = false;
00083        fClip = false;
00084        fSpot = true;
00085        fGray = false;
00086        fICC = false;
00087        scaleFactor = 1.0;
00088        SMode = 1;
00089        getNumericGSVersion(GsMajor, GsMinor);
00090        setIcon(loadIcon("AppIcon.png"));
00091        PLayout = new QVBoxLayout(this, 0, 0, "PLayout");
00092        int tbWidth = 0;
00093        Layout5 = new QHBoxLayout();
00094        Layout5->setSpacing(3);
00095        Layout5->setMargin(0);
00096        Anzeige = new QScrollView(this);
00097        Anzeige->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 0, 0, Anzeige->sizePolicy().hasHeightForWidth() ) );
00098        Layout5->addWidget(Anzeige);
00099        settingsBarLayout = new QVBoxLayout();
00100        settingsBarLayout->setSpacing(3);
00101        settingsBarLayout->setMargin(0);
00102        devTitle = new QGroupBox( this, "devTitle" );
00103        devTitle->setTitle( tr( "Display Settings" ) );
00104        devTitle->setColumnLayout(0, Qt::Vertical );
00105        devTitle->layout()->setSpacing( 5 );
00106        devTitle->layout()->setMargin( 5 );
00107        Layout2 = new QVBoxLayout( devTitle->layout() );
00108        Layout2->setAlignment( Qt::AlignTop );
00109        AntiAlias = new QCheckBox(devTitle, "AntiAlias");
00110        AntiAlias->setText( tr("Enable &Antialiasing"));
00111        AntiAlias->setChecked( postscriptPreview ? prefsManager->appPrefs.PrPr_AntiAliasing : false);
00112        AntiAlias->setEnabled( postscriptPreview );
00113        Layout2->addWidget(AntiAlias);
00114        AliasTr = new QCheckBox(devTitle, "DisplayTransparency");
00115        AliasTr->setText( tr("Display Trans&parency"));
00116        AliasTr->setChecked(prefsManager->appPrefs.PrPr_Transparency);
00117        AliasTr->setEnabled( postscriptPreview );
00118        Layout2->addWidget(AliasTr);
00119        EnableCMYK = new QCheckBox(devTitle, "DisplayCMYK");
00120        EnableCMYK->setText( tr("&Display CMYK"));
00121        EnableCMYK->setChecked( postscriptPreview ? prefsManager->appPrefs.PrPr_Mode : false);
00122        EnableCMYK->setEnabled( postscriptPreview );
00123        Layout2->addWidget(EnableCMYK);
00124        if (HaveTiffSep != 0)
00125        {
00126               EnableCMYK_C = new QCheckBox(devTitle, "DisplayCMYK_C");
00127               EnableCMYK_C->setText( tr("&C"));
00128               EnableCMYK_C->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_C : true);
00129               EnableCMYK_C->setEnabled(postscriptPreview);
00130               Layout2->addWidget(EnableCMYK_C);
00131               EnableCMYK_M = new QCheckBox(devTitle, "DisplayCMYK_M");
00132               EnableCMYK_M->setText( tr("&M"));
00133               EnableCMYK_M->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_M : true);
00134               EnableCMYK_M->setEnabled(postscriptPreview);
00135               Layout2->addWidget(EnableCMYK_M);
00136               EnableCMYK_Y = new QCheckBox(devTitle, "DisplayCMYK_Y");
00137               EnableCMYK_Y->setText( tr("&Y"));
00138               EnableCMYK_Y->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_Y : true);
00139               EnableCMYK_Y->setEnabled(postscriptPreview);
00140               Layout2->addWidget(EnableCMYK_Y);
00141               EnableCMYK_K = new QCheckBox(devTitle, "DisplayCMYK_K");
00142               EnableCMYK_K->setText( tr("&K"));
00143               EnableCMYK_K->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_K : true);
00144               EnableCMYK_K->setEnabled(postscriptPreview);
00145               Layout2->addWidget(EnableCMYK_K);
00146        }
00147        else
00148        {
00149               ColorList usedSpots;
00150               doc->getUsedColors(usedSpots, true);
00151               QStringList spots = usedSpots.keys();
00152               Table = new QTable( devTitle );
00153               Table->setNumRows( spots.count()+4 );
00154               Table->setNumCols( 2 );
00155               Table->horizontalHeader()->setLabel(0, loadIcon("16/show-object.png"), "");
00156               Table->horizontalHeader()->setLabel(1, tr("Separation Name"));
00157               Table->setColumnReadOnly(0, true);
00158               Table->setColumnReadOnly(1, true);
00159               Table->setColumnWidth(0, 24);
00160               Table->setRowMovingEnabled(false);
00161               Table->setSorting(false);
00162               Table->setSelectionMode( QTable::NoSelection );
00163               Table->setFocusStyle( QTable::FollowStyle );
00164               Table->setLeftMargin(0);
00165               Table->verticalHeader()->hide();
00166               flagsVisible.clear();
00167               QCheckBox *cp;
00168               Table->setText(0, 1, tr("Cyan"));
00169               cp = new QCheckBox(this, "");
00170               cp->setChecked(prefsManager->appPrefs.PrPr_C);
00171               connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00172               Table->setCellWidget(0, 0, cp);
00173               flagsVisible.insert("Cyan", cp);
00174               Table->setText(1, 1, tr("Magenta"));
00175               cp = new QCheckBox(this, "");
00176               cp->setChecked(prefsManager->appPrefs.PrPr_M);
00177               connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00178               Table->setCellWidget(1, 0, cp);
00179               flagsVisible.insert("Magenta", cp);
00180               Table->setText(2, 1, tr("Yellow"));
00181               cp = new QCheckBox(this, "");
00182               cp->setChecked(prefsManager->appPrefs.PrPr_Y);
00183               connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00184               Table->setCellWidget(2, 0, cp);
00185               flagsVisible.insert("Yellow", cp);
00186               Table->setText(3, 1, tr("Black"));
00187               cp = new QCheckBox(this, "");
00188               cp->setChecked(prefsManager->appPrefs.PrPr_K);
00189               connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00190               Table->setCellWidget(3, 0, cp);
00191               flagsVisible.insert("Black", cp);
00192               for (uint sp = 0; sp < spots.count(); ++sp)
00193               {
00194                      Table->setText(sp+4, 1, spots[sp]);
00195                      cp = new QCheckBox(this, "");
00196                      cp->setChecked(true);
00197                      connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00198                      Table->setCellWidget(sp+4, 0, cp);
00199                      flagsVisible.insert(spots[sp], cp);
00200               }
00201               Table->adjustColumn(1);
00202               Table->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, Table->sizePolicy().hasHeightForWidth() ) );
00203               Layout2->addWidget(Table);
00204               tbWidth = Table->columnWidth(1);
00205        }
00206        settingsBarLayout->addWidget(devTitle);
00207        jobTitle = new QGroupBox( this, "jobTitle" );
00208        jobTitle->setTitle( tr( "Print Settings" ) );
00209        jobTitle->setColumnLayout(0, Qt::Vertical );
00210        jobTitle->layout()->setSpacing( 5 );
00211        jobTitle->layout()->setMargin( 5 );
00212        Layout1 = new QVBoxLayout( jobTitle->layout() );
00213        Layout1->setAlignment( Qt::AlignTop );
00214 
00215        MirrorHor = new QCheckBox( tr( "Mirror Page(s) Horizontal" ), jobTitle, "MirrorH" );
00216        Layout1->addWidget( MirrorHor );
00217 
00218        MirrorVert = new QCheckBox( tr( "Mirror Page(s) Vertical" ), jobTitle, "MirrorV" );
00219        Layout1->addWidget( MirrorVert );
00220 
00221        ClipMarg = new QCheckBox( tr( "Clip to Page Margins" ), jobTitle, "ClipMarg" );
00222        Layout1->addWidget( ClipMarg );
00223 
00224        useGray = new QCheckBox( tr("Print in Grayscale"), jobTitle, "useGray");
00225        Layout1->addWidget(useGray);
00226 
00227        EnableGCR = new QCheckBox( tr("&Under Color Removal"), jobTitle, "DisplayGCR");
00228        Layout1->addWidget(EnableGCR);
00229 
00230        EnableOverprint = new QCheckBox( tr("Force Overprint Mode"), jobTitle, "EnableOverprint");
00231        Layout1->addWidget(EnableOverprint);
00232 
00233        spotColors = new QCheckBox( tr( "Convert Spot Colors" ), jobTitle, "spotColors" );
00234        Layout1->addWidget( spotColors );
00235 
00236        UseICC = new QCheckBox( tr( "Apply ICC Profiles" ), jobTitle, "UseICC" );
00237        Layout1->addWidget( UseICC );
00238        if (!doc->HasCMS)
00239               UseICC->setEnabled(false);
00240 
00241        settingsBarLayout->addWidget(jobTitle);
00242        QSpacerItem* spacerC = new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding );
00243        settingsBarLayout->addItem( spacerC );
00244        Layout5->addLayout(settingsBarLayout);
00245        PLayout->addLayout(Layout5);
00246 
00247        Layout6 = new QHBoxLayout();
00248        Layout6->setSpacing(0);
00249        Layout6->setMargin(0);
00250        /* scaling */
00251        scaleLabel = new QLabel( tr("Scaling:"), this, "scaleLabel");
00252        scaleBox = new QComboBox( true, this, "unitSwitcher" );
00253        scaleBox->setEditable(false);
00254        scaleBox->setFocusPolicy(QWidget::NoFocus);
00255        scaleBox->insertItem("50%");
00256        scaleBox->insertItem("100%");
00257        scaleBox->insertItem("150%");
00258        scaleBox->insertItem("200%");
00259        scaleBox->insertItem( tr("Fit to Width"));
00260        scaleBox->insertItem( tr("Fit to Height"));
00261        scaleBox->insertItem( tr("Fit to Page"));
00262        scaleBox->setCurrentItem(1);
00263        Layout6->addWidget(scaleLabel);
00264        Layout6->addWidget(scaleBox);
00265        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00266        Layout6->addItem( spacer );
00267        PGSel = new PageSelector(this, doc->DocPages.count());
00268        PGSel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, PGSel->sizePolicy().hasHeightForWidth() ) );
00269        Layout6->addWidget(PGSel);
00270        QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00271        Layout6->addItem( spacer2 );
00272        closeButton = new QPushButton( tr("Close"), this, "closeButton" );
00273        closeButton->setAutoDefault(false);
00274        Layout6->addWidget( closeButton );
00275        printButton = new QPushButton( tr("Print..."), this, "printButton" );
00276        printButton->setAutoDefault(false);       
00277        printButton->setEnabled(!printDinUse);
00278        Layout6->addWidget( printButton );
00279        PLayout->addLayout(Layout6);
00280        setValues();
00281        Anz = new QLabel(Anzeige->viewport());
00282        Anz->setPixmap(CreatePreview(0, 72));
00283        Anzeige->addChild(Anz, 0, 0);
00284        int w = Anz->width() + tbWidth + 50;
00285        resize(QMIN(QApplication::desktop()->width()-30,w), 500);
00286        if (!PrefsManager::instance()->appPrefs.PrPr_Mode)
00287        {
00288               if (HaveTiffSep != 0)
00289               {
00290                      EnableCMYK_C->setEnabled(false);
00291                      EnableCMYK_M->setEnabled(false);
00292                      EnableCMYK_Y->setEnabled(false);
00293                      EnableCMYK_K->setEnabled(false);
00294               }
00295               else
00296                      Table->setEnabled(false);
00297        }
00298        // tooltips
00299        QToolTip::add( AntiAlias, "<qt>" + tr( "Provides a more pleasant view of Type 1 fonts, TrueType Fonts, OpenType Fonts, EPS, PDF and vector graphics in the preview, at the expense of a slight slowdown in previewing" ) + "</qt>" );
00300        QToolTip::add( AliasTr, "<qt>" + tr( "Shows transparency and transparent items in your document. Requires Ghostscript 7.07 or later" ) + "</qt>");
00301        QToolTip::add( EnableCMYK, "<qt>" + tr( "Gives a print preview using simulations of generic CMYK inks, instead of RGB colors" ) + "</qt>");
00302        QToolTip::add( EnableGCR, "<qt>" + tr( "A way of switching off some of the gray shades which are composed of cyan, yellow and magenta and using black instead. UCR most affects parts of images which are neutral and/or dark tones which are close to the gray. Use of this may improve printing some images and some experimentation and testing is need on a case by case basis. UCR reduces the possibility of over saturation with CMY inks." ) + "</qt>" );
00303        QToolTip::add(scaleBox, "<qt>" + tr("Resize the scale of the page.") + "</qt>");
00304        QToolTip::add(spotColors,"<qt>" + tr( "Enables Spot Colors to be converted to composite colors. Unless you are planning to print spot colors at a commercial printer, this is probably best left enabled." ) + "</qt>");
00305        QToolTip::add(EnableOverprint, "<qt>"+ tr("Enables global Overprint Mode for this document, overrides object settings") + "<qt>");
00306        QToolTip::add(UseICC,"<qt>" + tr( "Allows you to embed ICC profiles in the print stream when color management is enabled" ) + "</qt>");
00307 
00308        //signals and slots
00309        connect(AntiAlias, SIGNAL(clicked()), this, SLOT(redisplay()));
00310        connect(AliasTr, SIGNAL(clicked()), this, SLOT(redisplay()));
00311        connect(EnableCMYK, SIGNAL(clicked()), this, SLOT(ToggleCMYK()));
00312        connect(EnableGCR, SIGNAL(clicked()), this, SLOT(redisplay()));
00313        connect(EnableOverprint, SIGNAL(clicked()), this, SLOT(redisplay()));
00314        connect(MirrorHor, SIGNAL(clicked()), this, SLOT(redisplay()));
00315        connect(MirrorVert, SIGNAL(clicked()), this, SLOT(redisplay()));
00316        connect(ClipMarg, SIGNAL(clicked()), this, SLOT(redisplay()));
00317        connect(spotColors, SIGNAL(clicked()), this, SLOT(redisplay()));
00318        connect(useGray, SIGNAL(clicked()), this, SLOT(redisplay()));
00319        connect(UseICC, SIGNAL(clicked()), this, SLOT(redisplay()));
00320        if (HaveTiffSep != 0)
00321        {
00322               connect(EnableCMYK_C, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00323               connect(EnableCMYK_M, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00324               connect(EnableCMYK_Y, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00325               connect(EnableCMYK_K, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour()));
00326               QToolTip::add( EnableCMYK_C, tr( "Enable/disable the C (Cyan) ink plate" ) );
00327               QToolTip::add( EnableCMYK_M, tr( "Enable/disable the M (Magenta) ink plate" ) );
00328               QToolTip::add( EnableCMYK_Y, tr( "Enable/disable the Y (Yellow) ink plate" ) );
00329               QToolTip::add( EnableCMYK_K, tr( "Enable/disable the K (Black) ink plate" ) );
00330        }
00331        connect(PGSel, SIGNAL(GotoPage(int)), this, SLOT(ToSeite(int)));
00332        connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00333        connect(printButton, SIGNAL(clicked()), this, SIGNAL(doPrint()));
00334        connect(scaleBox, SIGNAL(activated(int)), this, SLOT(scaleBox_valueChanged(int)));
00335 }
00336 
00337 void PPreview::setValues()
00338 {
00339        if ((printDinUse) || (!doc->Print_Options.firstUse))
00340        {
00341               EnableGCR->setChecked( postscriptPreview ? doc->Print_Options.doGCR : false);
00342               EnableGCR->setEnabled( postscriptPreview );
00343               EnableOverprint->setChecked( postscriptPreview ? doc->Print_Options.doOverprint : false);
00344               EnableOverprint->setEnabled( postscriptPreview );
00345               MirrorHor->setChecked(doc->Print_Options.mirrorH);
00346               MirrorVert->setChecked(doc->Print_Options.mirrorV);
00347               ClipMarg->setChecked(doc->Print_Options.doClip);
00348               spotColors->setChecked(!doc->Print_Options.useSpotColors);
00349               useGray->setChecked(!doc->Print_Options.useColor);
00350               if (doc->HasCMS)
00351               {
00352                      UseICC->setChecked( postscriptPreview ? doc->Print_Options.useICC : false);
00353                      UseICC->setEnabled( postscriptPreview );
00354               }
00355        }
00356        else
00357        {
00358               PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("print_options");
00359               EnableGCR->setChecked( postscriptPreview ? prefs->getBool("DoGCR", false) : false);
00360               EnableGCR->setEnabled( postscriptPreview );
00361               EnableOverprint->setChecked( postscriptPreview ? prefs->getBool("doOverprint", false) : false);
00362               EnableOverprint->setEnabled( postscriptPreview );
00363               MirrorHor->setChecked(prefs->getBool("MirrorH", false));
00364               MirrorVert->setChecked(prefs->getBool("MirrorV", false));
00365               ClipMarg->setChecked(prefs->getBool("Clip", false));
00366               spotColors->setChecked(!prefs->getBool("doSpot", true));
00367               if (prefs->getInt("PrintColor", 0) == 1)
00368                      useGray->setChecked(true);
00369               else
00370                      useGray->setChecked(false);
00371               if (doc->HasCMS)
00372               {
00373                      UseICC->setChecked( postscriptPreview ? prefs->getBool("ICCinUse", false) : false);
00374                      UseICC->setEnabled( postscriptPreview );
00375               }
00376        }
00377 }
00378 
00379 void PPreview::ToSeite(int num)
00380 {
00381        int n = num-1;
00382        if (n == APage)
00383               return;
00384        Anz->setPixmap(CreatePreview(n, qRound(72 * scaleFactor)));
00385 }
00386 
00387 void PPreview::redisplay()
00388 {
00389        Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor)));
00390 }
00391 
00392 void PPreview::ToggleCMYK()
00393 {
00394        bool c = EnableCMYK->isChecked() ? true : false;
00395        if (HaveTiffSep != 0)
00396        {
00397               EnableCMYK_C->setEnabled(c);
00398               EnableCMYK_M->setEnabled(c);
00399               EnableCMYK_Y->setEnabled(c);
00400               EnableCMYK_K->setEnabled(c);
00401        }
00402        else
00403               Table->setEnabled(c);
00404        Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor)));
00405 }
00406 
00407 void PPreview::ToggleCMYK_Colour()
00408 {
00409        if (EnableCMYK->isChecked())
00410               Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor)));
00411 }
00412 
00413 void PPreview::scaleBox_valueChanged(int value)
00414 {
00415        switch (value)
00416        {
00417               case 0:
00418                      scaleFactor = 0.5;
00419                      break;
00420               case 1:
00421                      scaleFactor = 1.0;
00422                      break;
00423               case 2:
00424                      scaleFactor = 1.5;
00425                      break;
00426               case 3:
00427                      scaleFactor = 2.0;
00428                      break;
00429               case 4:
00430                      scaleFactor = Anzeige->viewport()->width() / doc->Pages->at(APage)->width();
00431                      break;
00432               case 5:
00433                      scaleFactor = Anzeige->viewport()->height() / doc->Pages->at(APage)->height();
00434                      break;
00435               case 6:
00436                      scaleFactor = QMIN(Anzeige->viewport()->height() / doc->Pages->at(APage)->height(), Anzeige->viewport()->width() / doc->Pages->at(APage)->width());
00437                      break;
00438               default:
00439                      scaleFactor = 1.0;
00440                      break;
00441        }
00442        Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor)));
00443 }
00444 
00445 int PPreview::RenderPreview(int Seite, int Res)
00446 {
00447        int ret = -1;
00448        QString cmd1, cmd2, cmd3;
00449        QMap<QString,QMap<uint, FPointArray> > ReallyUsed;
00450 #if defined _WIN32
00451        if ( !postscriptPreview )
00452        {
00453               QImage image;
00454               Page* page;
00455               ScWinPrint winPrint;
00456               PrintOptions options;
00457               page = doc->Pages->at( Seite );
00458               options.copies = 1;
00459               options.doGCR = false;
00460               options.mirrorH = options.mirrorV = false;
00461               options.outputSeparations = false;
00462               options.pageNumbers.push_back( Seite );
00463               options.PSLevel = 0;
00464               options.separationName = "All";
00465               options.toFile = false;
00466               options.useColor = true;
00467               options.useICC = false;
00468               options.useSpotColors = false;
00469               options.doOverprint = false;
00470               bool done = winPrint.gdiPrintPreview(doc, page, &image, options, Res / 72.0);
00471               if ( done )
00472                      image.save( ScPaths::getTempFileDir() + "/sc.png", "PNG" );
00473               return (done ? 0 : 1);
00474        }
00475 #endif
00476        // Recreate Postscript-File only when the actual Page has changed
00477        if ((Seite != APage)  || (EnableGCR->isChecked() != GMode)  || (EnableOverprint->isChecked() != OMode)
00478               || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer)
00479               || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot))
00480        {
00481               ReallyUsed.clear();
00482               doc->getUsedFonts(ReallyUsed);
00483               bool useIC = UseICC->isChecked();
00484               if (!doc->HasCMS)
00485                      useIC = false;
00486               PrintOptions options;
00487               options.pageNumbers.push_back(Seite+1);
00488               options.outputSeparations = false;
00489               options.separationName = tr("All");
00490               options.allSeparations = QStringList();
00491               options.useColor = !useGray->isChecked();
00492               options.mirrorH = MirrorHor->isChecked();
00493               options.mirrorV = MirrorVert->isChecked();
00494               options.useICC = useIC;
00495               options.doGCR = EnableGCR->isChecked();
00496               options.setDevParam = false;
00497               options.doClip = ClipMarg->isChecked();
00498               options.doOverprint = EnableOverprint->isChecked();
00499               options.cropMarks = false;
00500               options.bleedMarks = false;
00501               options.registrationMarks = false;
00502               options.colorMarks = false;
00503               options.markOffset = 0.0;
00504               options.bleeds.Top = 0.0;
00505               options.bleeds.Left = 0.0;
00506               options.bleeds.Right = 0.0;
00507               options.bleeds.Bottom = 0.0;
00508               PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, ReallyUsed, doc->PageColors, false, !spotColors->isChecked());
00509               if (dd != NULL)
00510               {
00511                      dd->PS_set_file( ScPaths::getTempFileDir() + "/tmp.ps");
00512                      dd->CreatePS(doc, options);
00513                      delete dd;
00514               }
00515               else
00516                      return ret;
00517        }
00518        QStringList args;
00519        QString tmp, tmp2, tmp3;
00520        double b = doc->Pages->at(Seite)->width() * Res / 72.0;
00521        double h = doc->Pages->at(Seite)->height() * Res / 72.0;
00522        args.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
00523        args.append( "-q" );
00524        args.append( "-dNOPAUSE" );
00525        args.append( "-dPARANOIDSAFER" );
00526        args.append( QString("-r%1").arg(tmp.setNum(qRound(Res))) );
00527        args.append( QString("-g%1x%2").arg(tmp2.setNum(qRound(b))).arg(tmp3.setNum(qRound(h))) );
00528        if (EnableCMYK->isChecked())
00529        {
00530               if (HaveTiffSep == 0)
00531                      args.append( "-sDEVICE=tiffsep" );
00532               else
00533               {
00534                      args.append( "-sDEVICE=bitcmyk" );
00535                      args.append( "-dGrayValues=256" ); 
00536               }
00537        }
00538        else
00539        {
00540               if ((!AliasTr->isChecked()) || (HavePngAlpha != 0))
00541                      args.append( "-sDEVICE=png16m" );
00542               else
00543                      args.append( "-sDEVICE=pngalpha" );
00544        }
00545        if (AntiAlias->isChecked())
00546        {
00547               args.append( "-dTextAlphaBits=4" );
00548               args.append( "-dGraphicsAlphaBits=4" );
00549        }
00550        // Add any extra font paths being used by Scribus to gs's font search path
00551        PrefsContext *pc = prefsManager->prefsFile->getContext("Fonts");
00552        PrefsTable *extraFonts = pc->getTable("ExtraFontDirs");
00553        const char sep = ScPaths::envPathSeparator;
00554        if (extraFonts->getRowCount() >= 1)
00555               cmd1 = QString("-sFONTPATH=%1").arg(QDir::convertSeparators(extraFonts->get(0,0)));
00556        for (int i = 1; i < extraFonts->getRowCount(); ++i)
00557               cmd1 += QString("%1%2").arg(sep).arg(QDir::convertSeparators(extraFonts->get(i,0)));
00558        if( !cmd1.isEmpty() )
00559               args.append( cmd1 );
00560        // then add any final args and call gs
00561        if ((EnableCMYK->isChecked()) && (HaveTiffSep == 0))
00562               args.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif")) );
00563        else
00564               args.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.png")) );
00565        args.append( QDir::convertSeparators(ScPaths::getTempFileDir()+"/tmp.ps") );
00566        args.append( "-c" );
00567        args.append( "showpage" );
00568        args.append( "-c" );
00569        args.append( "quit" );
00570        ret = System( args );
00571        return ret;
00572 }
00573 
00574 int PPreview::RenderPreviewSep(int Seite, int Res)
00575 {
00576        int ret = -1;
00577        QString cmd;
00578        QStringList args, args1, args2, args3;
00579        QMap<QString, QMap<uint, FPointArray> > ReallyUsed;
00580        // Recreate Postscript-File only when the actual Page has changed
00581        if ((Seite != APage)  || (EnableGCR->isChecked() != GMode)  || (EnableOverprint->isChecked() != OMode)
00582               || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer)
00583               || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot))
00584        {
00585               ReallyUsed.clear();
00586               doc->getUsedFonts(ReallyUsed);
00587               bool useIC = UseICC->isChecked();
00588               if (!doc->HasCMS)
00589                      useIC = false;
00590               PrintOptions options;
00591               options.pageNumbers.push_back(Seite+1);
00592               options.outputSeparations = false;
00593               options.separationName = tr("All");
00594               options.allSeparations = QStringList();
00595               options.useColor = !useGray->isChecked();
00596               options.mirrorH = MirrorHor->isChecked();
00597               options.mirrorV = MirrorVert->isChecked();
00598               options.useICC = useIC;
00599               options.doGCR = EnableGCR->isChecked();
00600               options.setDevParam = false;
00601               options.doClip = ClipMarg->isChecked();
00602               options.doOverprint = EnableOverprint->isChecked();
00603               options.cropMarks = false;
00604               options.bleedMarks = false;
00605               options.registrationMarks = false;
00606               options.colorMarks = false;
00607               options.markOffset = 0.0;
00608               options.bleeds.Top = 0.0;
00609               options.bleeds.Left = 0.0;
00610               options.bleeds.Right = 0.0;
00611               options.bleeds.Bottom = 0.0;
00612               PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, ReallyUsed, doc->PageColors, false, !spotColors->isChecked());
00613               if (dd != NULL)
00614               {
00615                      dd->PS_set_file(ScPaths::getTempFileDir()+"/tmp.ps");
00616                      dd->CreatePS(doc, options);
00617                      delete dd;
00618               }
00619               else
00620                      return ret;
00621        }
00622        QString tmp, tmp2, tmp3;
00623        double b = doc->Pages->at(Seite)->width() * Res / 72.0;
00624        double h = doc->Pages->at(Seite)->height() * Res / 72.0;
00625 
00626        args1.append( getShortPathName(prefsManager->ghostscriptExecutable()) );
00627        args1.append( "-q" );
00628        args1.append( "-dNOPAUSE" );
00629        args1.append( "-dPARANOIDSAFER" );
00630        args1.append( QString("-r%1").arg(tmp.setNum(qRound(Res))) );
00631        args1.append( QString("-g%1x%2").arg(tmp2.setNum(qRound(b))).arg(tmp3.setNum(qRound(h))) ); 
00632        if (AntiAlias->isChecked())
00633        {
00634               args1.append("-dTextAlphaBits=4");
00635               args1.append("-dGraphicsAlphaBits=4");
00636        }
00637        // Add any extra font paths being used by Scribus to gs's font search path
00638        PrefsContext *pc = prefsManager->prefsFile->getContext("Fonts");
00639        PrefsTable *extraFonts = pc->getTable("ExtraFontDirs");
00640        const char sep = ScPaths::envPathSeparator;
00641        if (extraFonts->getRowCount() >= 1)
00642               cmd = QString("-sFONTPATH=%1").arg(QDir::convertSeparators(extraFonts->get(0,0)));
00643        for (int i = 1; i < extraFonts->getRowCount(); ++i)
00644               cmd += QString("%1%2").arg(sep).arg(QDir::convertSeparators(extraFonts->get(i,0)));
00645        if( !cmd.isEmpty() )
00646               args1.append( cmd );
00647        args1.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif")) );
00648 
00649        args2.append( QDir::convertSeparators(ScPaths::getTempFileDir()+"/tmp.ps") );
00650        args2.append("-c");
00651        args2.append("quit");
00652 
00653        ColorList usedSpots;
00654        doc->getUsedColors(usedSpots, true);
00655        QStringList spots = usedSpots.keys();
00656        args3.append( "-sDEVICE=tiffsep" );
00657 
00658        args3.append( "-c" );
00659        cmd = "<< /SeparationColorNames ";
00660        QString allSeps ="[ /Cyan /Magenta /Yellow /Black ";
00661        for (uint sp = 0; sp < spots.count(); ++sp)
00662        {
00663               allSeps += "("+spots[sp]+") ";
00664        }
00665        allSeps += "]";
00666        cmd += allSeps + " /SeparationOrder [ /Cyan /Magenta /Yellow /Black] >> setpagedevice";
00667        args3.append(cmd);
00668 
00669        args3.append("-f");
00670        ret = System(args1 + args3 + args2, ScPaths::getTempFileDir()+"/sc.tif.txt" );
00671 
00672        QFile sepInfo(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif.txt"));
00673        sepsToFileNum.clear();
00674        if (sepInfo.open(IO_ReadOnly))
00675        {
00676               QString Sname;
00677               QTextStream tsC(&sepInfo);
00678               int counter = 0;
00679               while (!tsC.atEnd())
00680               {
00681                      Sname = tsC.readLine();
00682                      QString tt = Sname.remove("%%SeparationName:").stripWhiteSpace();
00683                      sepsToFileNum.insert(tt, counter);
00684                      counter++;
00685               }
00686        }
00687        sepInfo.close();
00688        QString currSeps = "";
00689        uint spc = 0;
00690        for (uint sp = 0; sp < spots.count(); ++sp)
00691        {
00692               currSeps += "("+spots[sp]+") ";
00693               spc++;
00694               if (sp > 6)
00695               {
00696                      args3.clear();
00697                      args3.append("-sDEVICE=tiffsep");
00698                      args3.append("-c");
00699                      args3.append("<< /SeparationColorNames "+allSeps+" /SeparationOrder [ "+currSeps+" ] >> setpagedevice");
00700                      args3.append("-f");
00701                      ret = System(args1 + args3 + args2);
00702                      currSeps = "";
00703                      spc = 0;
00704               }
00705        }
00706        if (spc != 0)
00707        {
00708               args3.clear();
00709               args3.append("-sDEVICE=tiffsep");
00710               args3.append("-c");
00711               args3.append("<< /SeparationColorNames "+allSeps+" /SeparationOrder [ "+currSeps+" ] >> setpagedevice");
00712               args3.append("-f");
00713               ret = System(args1 + args3 + args2);
00714        }
00715        return ret;
00716 }
00717 
00718 // this should move to scimage.cpp!
00719 void PPreview::blendImages(QImage &target, ScImage &scsource, ScColor col)
00720 {
00721        QImage source = scsource.qImage(); // FIXME: this will not work once qImage always returns ARGB!
00722        
00723        //FIXME: if source and target have different sizesomething went wrong.
00724        // eg. loadPicture() failed and returned a 1x1 image
00725        CMYKColor cmykValues;
00726        int h = QMIN(target.height(),source.height());
00727        int w = QMIN(target.width(),source.width());
00728        int cyan, c, m, yc, k, cc, mm, yy, kk;
00729        ScColorEngine::getCMYKValues(col, doc, cmykValues);
00730        cmykValues.getValues(c, m, yc, k);
00731        for (int y=0; y < h; ++y )
00732        {
00733               QRgb *p = (QRgb *)target.scanLine( y );
00734               QRgb *pq = (QRgb *)source.scanLine( y );
00735               for (int x=0; x < w; ++x )
00736               {
00737                      cyan = 255 - qRed(*pq);
00738                      if (cyan != 0)
00739                      {
00740                             (c == 0) ? cc = qRed(*p) : cc = QMIN(c * cyan / 255 + qRed(*p), 255);
00741                             (m == 0) ? mm = qGreen(*p) : mm = QMIN(m * cyan / 255 + qGreen(*p), 255);
00742                             (yc == 0) ? yy = qBlue(*p) : yy = QMIN(yc * cyan / 255 + qBlue(*p), 255);
00743                             (k == 0) ? kk = qAlpha(*p) : kk = QMIN(k * cyan / 255 + qAlpha(*p), 255);
00744                             *p = qRgba(cc, mm, yy, kk);
00745                      }
00746                      p++;
00747                      pq++;
00748               }
00749        }
00750 }
00751 
00752 QPixmap PPreview::CreatePreview(int Seite, int Res)
00753 {
00754        int ret = -1;
00755        QPixmap Bild;
00756        double b = doc->Pages->at(Seite)->width() * Res / 72.0;
00757        double h = doc->Pages->at(Seite)->height() * Res / 72.0;
00758        qApp->setOverrideCursor(QCursor(waitCursor), true);
00759        if ((Seite != APage) || (EnableCMYK->isChecked() != CMode) || (SMode != scaleBox->currentItem())
00760                || (AntiAlias->isChecked() != GsAl) || ((AliasTr->isChecked() != Trans) || (EnableGCR->isChecked() != GMode)
00761                      || (EnableOverprint->isChecked() != OMode) && (!EnableCMYK->isChecked()))
00762                       || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer)
00763                       || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot))
00764        {
00765               if (!EnableCMYK->isChecked() || (HaveTiffSep != 0))
00766               {
00767                      ret = RenderPreview(Seite, Res);
00768                      if (ret != 0)
00769                      {
00770                             imageLoadError(Bild, Seite);
00771                             return Bild;
00772                      }
00773               }
00774        }
00775        QImage image;
00776        if (EnableCMYK->isChecked())
00777        {
00778               int cyan, magenta, yellow, black, alpha;
00779               uint *p;
00780               bool loaderror;
00781               if (HaveTiffSep == 0)
00782               {
00783                      if ((Seite != APage) || (EnableCMYK->isChecked() != CMode) || (SMode != scaleBox->currentItem())
00784                       || (AntiAlias->isChecked() != GsAl) || (AliasTr->isChecked() != Trans) || (EnableGCR->isChecked() != GMode)
00785                       || (EnableOverprint->isChecked() != OMode) || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor)
00786                       || (MirrorVert->isChecked() != mVer) || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot))
00787                      {
00788                             ret = RenderPreviewSep(Seite, Res);
00789                             if (ret != 0)
00790                             {
00791                                    imageLoadError(Bild, Seite);
00792                                    return Bild;
00793                             }
00794                      }
00795                      ScImage im;
00796                      bool mode;
00797                      int w = qRound(b);
00798                      int h2 = qRound(h);
00799                      image = QImage(w, h2, 32);
00800                      QRgb clean = qRgba(0, 0, 0, 0);
00801                      for( int yi=0; yi < h2; ++yi )
00802                      {
00803                             QRgb *q = (QRgb*)(image.scanLine( yi ));
00804                             for(int xi=0; xi < w; ++xi )
00805                             {
00806                                    *q = clean;
00807                                    q++;
00808                             }
00809                      }
00810                      CMSettings cms(doc, "", 0);
00811                      if (flagsVisible["Cyan"]->isChecked())
00812                      {
00813                             if (GsMinor < 54)
00814                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Cyan.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00815                             else
00816                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Cyan.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00817                             if (!loaderror)
00818                             {
00819                                    imageLoadError(Bild, Seite);
00820                                    return Bild;
00821                             }
00822                             blendImages(image, im, ScColor(255, 0, 0, 0));
00823                      }
00824                      if (flagsVisible["Magenta"]->isChecked())
00825                      {
00826                             if (GsMinor < 54)
00827                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Magenta.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00828                             else
00829                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Magenta.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00830                             if (!loaderror)
00831                             {
00832                                    imageLoadError(Bild, Seite);
00833                                    return Bild;
00834                             }
00835                             blendImages(image, im, ScColor(0, 255, 0, 0));
00836                      }
00837                      if (flagsVisible["Yellow"]->isChecked())
00838                      {
00839                             if (GsMinor < 54)
00840                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Yellow.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00841                             else
00842                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Yellow.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00843                             if (!loaderror)
00844                             {
00845                                    imageLoadError(Bild, Seite);
00846                                    return Bild;
00847                             }
00848                             blendImages(image, im, ScColor(0, 0, 255, 0));
00849                      }
00850                      QMap<QString, int>::Iterator sepit;
00851                      for (sepit = sepsToFileNum.begin(); sepit != sepsToFileNum.end(); ++sepit)
00852                      {
00853                             if (flagsVisible[sepit.key()]->isChecked())
00854                             {
00855                                    QString fnam;
00856                                    if (GsMinor < 54)
00857                                           fnam = QString(ScPaths::getTempFileDir()+"/sc.tif.s%1.tif").arg(sepit.data());
00858                                    else
00859                                           fnam = QString(ScPaths::getTempFileDir()+"/sc.s%1.tif").arg(sepit.data());
00860                                    if (!im.LoadPicture(fnam, cms, false, false, ScImage::RGBData, 72, &mode))
00861                                    {
00862                                           imageLoadError(Bild, Seite);
00863                                           return Bild;
00864                                    }
00865                                    blendImages(image, im, doc->PageColors[sepit.key()]);
00866                             }
00867                      }
00868                      if (flagsVisible["Black"]->isChecked())
00869                      {
00870                             CMSettings cms(doc, "", 0);
00871                             if (GsMinor < 54)
00872                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Black.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00873                             else
00874                                    loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Black.tif", cms, false, false, ScImage::RGBData, 72, &mode);
00875                             if (!loaderror)
00876                             {
00877                                    imageLoadError(Bild, Seite);
00878                                    return Bild;
00879                             }
00880                             blendImages(image, im, ScColor(0, 0, 0, 255));
00881                      }
00882                      if (doc->HasCMS)
00883                      {
00884                             QRgb alphaFF = qRgba(0,0,0,255);
00885                             QRgb alphaOO = qRgba(255,255,255,0);
00886                             cmsHTRANSFORM transCMYK = cmsCreateTransform(doc->DocPrinterProf, (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)), doc->DocOutputProf, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_LOWRESPRECALC);
00887                             for( int yi=0; yi < h2; ++yi )
00888                             {
00889                                    LPBYTE ptr = image.scanLine( yi );
00890                                    cmsDoTransform(transCMYK, ptr, ptr, image.width());
00891                                    QRgb *q = (QRgb *) ptr;
00892                                    for (int xi = 0; xi < image.width(); xi++, q++)
00893                                    {
00894                                           if (AliasTr->isChecked())
00895                                           {
00896                                                  cyan = qRed(*q);
00897                                                  magenta = qGreen(*q);
00898                                                  yellow = qBlue(*q);
00899                                                  if     ((cyan == 255) && (magenta == 255) && (yellow == 255))
00900                                                         *q = alphaOO;
00901                                                  else
00902                                                         *q |= alphaFF;
00903                                           }
00904                                           else
00905                                                  *q |= alphaFF;
00906                                    }
00907                             }
00908                             cmsDeleteTransform (transCMYK);
00909                      }
00910                      else
00911                      {
00912                             for( int yi=0; yi < h2; ++yi )
00913                             {
00914                                    QRgb *q = (QRgb*)(image.scanLine( yi ));
00915                                    for(int xi=0; xi < w; ++xi )
00916                                    {
00917                                           cyan = qRed(*q);
00918                                           magenta = qGreen(*q);
00919                                           yellow = qBlue(*q);
00920                                           black = qAlpha(*q);
00921                                           if ((cyan != 0) || (magenta != 0) || (yellow != 0 ) || (black != 0))
00922                                                  *q = qRgba(255-QMIN(255, cyan+black), 255-QMIN(255,magenta+black), 255-QMIN(255,yellow+black), 255);
00923                                           else
00924                                           {
00925                                                  if (!AliasTr->isChecked())
00926                                                         *q = qRgba(255, 255, 255, 255);
00927                                           }
00928                                           q++;
00929                                    }
00930                             }
00931                      }
00932               }
00933               else
00934               {
00935                      int w = qRound(b);
00936                      int w2 = 4*w;
00937                      int h2 = qRound(h);
00938                      image = QImage(w, h2, 32);
00939                      QByteArray imgc(w2);
00940                      QFile f(ScPaths::getTempFileDir()+"/sc.png");
00941                      if (f.open(IO_ReadOnly))
00942                      {
00943                             if (doc->HasCMS)
00944                             {
00945                                    QRgb alphaFF = qRgba(0,0,0,255);
00946                                    QRgb alphaOO = qRgba(255,255,255,0);
00947                                    cmsHTRANSFORM transCMYK = cmsCreateTransform(doc->DocPrinterProf, (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)), doc->DocOutputProf, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_LOWRESPRECALC);
00948                                    for (int y=0; y < h2; ++y )
00949                                    {
00950                                           LPBYTE ptr = image.scanLine( y );
00951                                           f.readBlock(imgc.data(), w2);
00952                                           p = (uint *)image.scanLine( y );
00953                                           for (int x=0; x < w2; x += 4 )
00954                                           {
00955                                                  cyan = uchar(imgc[x]);
00956                                                  magenta = uchar(imgc[x + 1]);
00957                                                  yellow = uchar(imgc[x + 2]);
00958                                                  black = uchar(imgc[x + 3]);
00959                                                  if (!EnableCMYK_C->isChecked())
00960                                                         cyan = 0;
00961                                                  if (!EnableCMYK_M->isChecked())
00962                                                         magenta = 0;
00963                                                  if (!EnableCMYK_Y->isChecked())
00964                                                         yellow = 0;
00965                                                  if (!EnableCMYK_K->isChecked())
00966                                                         black = 0;
00967                                                  *p = qRgba(cyan, magenta, yellow, black);
00968                                                  p++;
00969                                           }
00970                                           cmsDoTransform(transCMYK, ptr, ptr, image.width());
00971                                           QRgb *q = (QRgb *) ptr;
00972                                           for (int xi = 0; xi < image.width(); xi++, q++)
00973                                           {
00974                                                  if (AliasTr->isChecked())
00975                                                  {
00976                                                         cyan = qRed(*q);
00977                                                         magenta = qGreen(*q);
00978                                                         yellow = qBlue(*q);
00979                                                         if     ((cyan == 255) && (magenta == 255) && (yellow == 255))
00980                                                                *q = alphaOO;
00981                                                         else
00982                                                                *q |= alphaFF;
00983                                                  }
00984                                                  else
00985                                                         *q |= alphaFF;
00986                                           }
00987                                    }
00988                                    cmsDeleteTransform (transCMYK);
00989                             }
00990                             else
00991                             {
00992                                    for (int y=0; y < h2; ++y )
00993                                    {
00994                                           p = (uint *)image.scanLine( y );
00995                                           f.readBlock(imgc.data(), w2);
00996                                           for (int x=0; x < w2; x += 4 )
00997                                           {
00998                                                  cyan = uchar(imgc[x]);
00999                                                  magenta = uchar(imgc[x + 1]);
01000                                                  yellow = uchar(imgc[x + 2]);
01001                                                  black = uchar(imgc[x + 3]);
01002                                                  if (!EnableCMYK_C->isChecked())
01003                                                         cyan = 0;
01004                                                  if (!EnableCMYK_M->isChecked())
01005                                                         magenta = 0;
01006                                                  if (!EnableCMYK_Y->isChecked())
01007                                                         yellow = 0;
01008                                                  if (!EnableCMYK_K->isChecked())
01009                                                         black = 0;
01010                                                  if (AliasTr->isChecked() && ((cyan == 0) && (magenta == 0) && (yellow == 0 ) && (black == 0)))
01011                                                         alpha = 0;
01012                                                  else
01013                                                         alpha = 255;
01014                                                  *p = qRgba(255-QMIN(255, cyan+black), 255-QMIN(255,magenta+black), 255-QMIN(255,yellow+black), alpha);
01015                                                  p++;
01016                                           }
01017                                    }
01018                             }
01019                             f.close();
01020                      }
01021                      else
01022                      {
01023                             imageLoadError(Bild, Seite);
01024                             return Bild;
01025                      }
01026               }
01027        }
01028        else
01029        {
01030               if (!image.load(ScPaths::getTempFileDir()+"/sc.png"))
01031               {
01032                      imageLoadError(Bild, Seite);
01033                      return Bild;
01034               }
01035               image = image.convertDepth(32);
01036               if ((AliasTr->isChecked()) && (HavePngAlpha == 0))
01037               {
01038                      int wi = image.width();
01039                      int hi = image.height();
01040                      for( int yi=0; yi < hi; ++yi )
01041                      {
01042                             QRgb *s = (QRgb*)(image.scanLine( yi ));
01043                             for(int xi=0; xi < wi; ++xi )
01044                             {
01045                                    if((*s) == 0xffffffff)
01046                                           (*s) &= 0x00ffffff;
01047                                    s++;
01048                             }
01049                      }
01050               }
01051        }
01052        image.setAlphaBuffer(true);
01053        if (AliasTr->isChecked())
01054        {
01055               Bild = QPixmap(image.width(), image.height());
01056               QPainter p;
01057               QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
01058               p.begin(&Bild);
01059               p.fillRect(0, 0, image.width(), image.height(), b);
01060               p.drawImage(0, 0, image);
01061               p.end();
01062        }
01063        else
01064               Bild.convertFromImage(image);
01065        qApp->setOverrideCursor(QCursor(arrowCursor), true);
01066        getUserSelection(Seite);
01067        return Bild;
01068 }
01069 
01070 //-------------------------------------------------------------------------------------------------
01071 
01072 bool PPreview::usePostscriptPreview(QString printerName)
01073 {
01074 #ifdef _WIN32
01075        if ( printerName == tr("File") )
01076               return true;
01077        else if( printerName.isEmpty() )
01078               return PrinterUtil::isPostscriptPrinter( ScWinPrint::getDefaultPrinter() );
01079        else
01080               return PrinterUtil::isPostscriptPrinter( printerName );
01081 #else
01082        return true;
01083 #endif
01084 }
01085 
01086 //-------------------------------------------------------------------------------------------------
01087 
01088 void PPreview::getUserSelection(int page)
01089 {
01090        APage = page;
01091        CMode = EnableCMYK->isChecked();
01092        GsAl = AntiAlias->isChecked();
01093        Trans = AliasTr->isChecked();
01094        GMode = EnableGCR->isChecked();
01095        SMode = scaleBox->currentItem();
01096        OMode = EnableOverprint->isChecked();
01097        mHor = MirrorHor->isChecked();
01098        mVer = MirrorVert->isChecked();
01099        fClip = ClipMarg->isChecked();
01100        fSpot = spotColors->isChecked();
01101        fGray = useGray->isChecked();
01102        fICC = UseICC->isChecked();
01103 }
01104 
01105 void PPreview::imageLoadError(QPixmap &Bild, int page)
01106 {
01107        Bild.resize(1,1);
01108        qApp->setOverrideCursor(QCursor(arrowCursor), true);
01109        getUserSelection(page);
01110 }