Rev 7225 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
3165 | fschmid | 7 | /*************************************************************************** |
8 | preview.cpp - description |
||
9 | ------------------- |
||
10 | begin : Sun Jun 1 08:00:00 CEST 2003 |
||
11 | copyright : (C) 2003 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
23 | #include "preview.h" |
||
24 | #include "preview.moc" |
||
25 | #include <qimage.h> |
||
26 | #include <cstdlib> |
||
27 | #include <qcursor.h> |
||
28 | #include <qpainter.h> |
||
29 | #include <qcolor.h> |
||
30 | #include <qtooltip.h> |
||
31 | #include <qfile.h> |
||
3172 | subik | 32 | #include <qspinbox.h> |
3261 | fschmid | 33 | #include <qtable.h> |
3165 | fschmid | 34 | #include "pslib.h" |
35 | #include "checkDocument.h" |
||
5781 | cbradney | 36 | #include "cmsettings.h" |
3165 | fschmid | 37 | #include "prefsfile.h" |
38 | #include "prefscontext.h" |
||
3252 | craig | 39 | #include "prefsmanager.h" |
3165 | fschmid | 40 | #include "prefstable.h" |
41 | #include "util.h" |
||
3262 | cbradney | 42 | #include "sccolor.h" |
3167 | fschmid | 43 | #include "scribusview.h" |
44 | #include "scribusdoc.h" |
||
4194 | fschmid | 45 | #include "scpaths.h" |
3252 | craig | 46 | #include "pageselector.h" |
4506 | cbradney | 47 | #include "printerutil.h" |
9621 | jghali | 48 | #include "sccolorengine.h" |
5542 | fschmid | 49 | #include "gsutil.h" |
3165 | fschmid | 50 | |
4361 | cbradney | 51 | #if defined(_WIN32) |
52 | #include "scwinprint.h" |
||
53 | #endif |
||
54 | |||
3234 | fschmid | 55 | extern bool printDinUse; |
56 | |||
4361 | cbradney | 57 | PPreview::PPreview( QWidget* parent, ScribusView *vin, ScribusDoc *docu, int pngAlpha, int tiffSep, QString printer ) : QDialog( parent, "Preview", true, 0 ) |
3165 | fschmid | 58 | { |
4069 | craig | 59 | Q_ASSERT(!docu->masterPageMode()); |
3165 | fschmid | 60 | prefsManager=PrefsManager::instance(); |
61 | QString tmp; |
||
4361 | cbradney | 62 | postscriptPreview = usePostscriptPreview(printer); |
63 | QString caption = tr("Print Preview"); |
||
64 | #ifdef _WIN32 |
||
65 | if (postscriptPreview) |
||
66 | caption += " (Postscript)"; |
||
67 | else |
||
68 | caption += " (GDI)"; |
||
69 | #endif |
||
70 | setCaption( caption ); |
||
3167 | fschmid | 71 | doc = docu; |
72 | view = vin; |
||
73 | HavePngAlpha = pngAlpha; |
||
4361 | cbradney | 74 | HaveTiffSep = postscriptPreview ? tiffSep : 1; |
3165 | fschmid | 75 | APage = -1; |
76 | CMode = false; |
||
6008 | jghali | 77 | GsAl = false; |
3165 | fschmid | 78 | Trans = false; |
79 | GMode = true; |
||
5308 | fschmid | 80 | OMode = false; |
6690 | fschmid | 81 | mHor = false; |
82 | mVer = false; |
||
83 | fClip = false; |
||
84 | fSpot = true; |
||
85 | fGray = false; |
||
86 | fICC = false; |
||
3172 | subik | 87 | scaleFactor = 1.0; |
3173 | fschmid | 88 | SMode = 1; |
5542 | fschmid | 89 | getNumericGSVersion(GsMajor, GsMinor); |
3165 | fschmid | 90 | setIcon(loadIcon("AppIcon.png")); |
91 | PLayout = new QVBoxLayout(this, 0, 0, "PLayout"); |
||
6690 | fschmid | 92 | int tbWidth = 0; |
93 | Layout5 = new QHBoxLayout(); |
||
94 | Layout5->setSpacing(3); |
||
95 | Layout5->setMargin(0); |
||
96 | Anzeige = new QScrollView(this); |
||
97 | Anzeige->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 0, 0, Anzeige->sizePolicy().hasHeightForWidth() ) ); |
||
98 | Layout5->addWidget(Anzeige); |
||
99 | settingsBarLayout = new QVBoxLayout(); |
||
100 | settingsBarLayout->setSpacing(3); |
||
101 | settingsBarLayout->setMargin(0); |
||
102 | devTitle = new QGroupBox( this, "devTitle" ); |
||
6756 | fschmid | 103 | devTitle->setTitle( tr( "Display Settings" ) ); |
6690 | fschmid | 104 | devTitle->setColumnLayout(0, Qt::Vertical ); |
105 | devTitle->layout()->setSpacing( 5 ); |
||
106 | devTitle->layout()->setMargin( 5 ); |
||
107 | Layout2 = new QVBoxLayout( devTitle->layout() ); |
||
108 | Layout2->setAlignment( Qt::AlignTop ); |
||
109 | AntiAlias = new QCheckBox(devTitle, "AntiAlias"); |
||
6008 | jghali | 110 | AntiAlias->setText( tr("Enable &Antialiasing")); |
111 | AntiAlias->setChecked( postscriptPreview ? prefsManager->appPrefs.PrPr_AntiAliasing : false); |
||
112 | AntiAlias->setEnabled( postscriptPreview ); |
||
113 | Layout2->addWidget(AntiAlias); |
||
6690 | fschmid | 114 | AliasTr = new QCheckBox(devTitle, "DisplayTransparency"); |
6008 | jghali | 115 | AliasTr->setText( tr("Display Trans&parency")); |
116 | AliasTr->setChecked(prefsManager->appPrefs.PrPr_Transparency); |
||
117 | AliasTr->setEnabled( postscriptPreview ); |
||
118 | Layout2->addWidget(AliasTr); |
||
6690 | fschmid | 119 | EnableCMYK = new QCheckBox(devTitle, "DisplayCMYK"); |
5343 | cbradney | 120 | EnableCMYK->setText( tr("&Display CMYK")); |
121 | EnableCMYK->setChecked( postscriptPreview ? prefsManager->appPrefs.PrPr_Mode : false); |
||
122 | EnableCMYK->setEnabled( postscriptPreview ); |
||
6690 | fschmid | 123 | Layout2->addWidget(EnableCMYK); |
3261 | fschmid | 124 | if (HaveTiffSep != 0) |
125 | { |
||
6690 | fschmid | 126 | EnableCMYK_C = new QCheckBox(devTitle, "DisplayCMYK_C"); |
3261 | fschmid | 127 | EnableCMYK_C->setText( tr("&C")); |
4361 | cbradney | 128 | EnableCMYK_C->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_C : true); |
129 | EnableCMYK_C->setEnabled(postscriptPreview); |
||
6690 | fschmid | 130 | Layout2->addWidget(EnableCMYK_C); |
131 | EnableCMYK_M = new QCheckBox(devTitle, "DisplayCMYK_M"); |
||
3261 | fschmid | 132 | EnableCMYK_M->setText( tr("&M")); |
4361 | cbradney | 133 | EnableCMYK_M->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_M : true); |
134 | EnableCMYK_M->setEnabled(postscriptPreview); |
||
6690 | fschmid | 135 | Layout2->addWidget(EnableCMYK_M); |
136 | EnableCMYK_Y = new QCheckBox(devTitle, "DisplayCMYK_Y"); |
||
3261 | fschmid | 137 | EnableCMYK_Y->setText( tr("&Y")); |
4361 | cbradney | 138 | EnableCMYK_Y->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_Y : true); |
139 | EnableCMYK_Y->setEnabled(postscriptPreview); |
||
6690 | fschmid | 140 | Layout2->addWidget(EnableCMYK_Y); |
141 | EnableCMYK_K = new QCheckBox(devTitle, "DisplayCMYK_K"); |
||
3261 | fschmid | 142 | EnableCMYK_K->setText( tr("&K")); |
4361 | cbradney | 143 | EnableCMYK_K->setChecked(postscriptPreview ? prefsManager->appPrefs.PrPr_K : true); |
144 | EnableCMYK_K->setEnabled(postscriptPreview); |
||
6690 | fschmid | 145 | Layout2->addWidget(EnableCMYK_K); |
3261 | fschmid | 146 | } |
147 | else |
||
148 | { |
||
149 | ColorList usedSpots; |
||
150 | doc->getUsedColors(usedSpots, true); |
||
151 | QStringList spots = usedSpots.keys(); |
||
6690 | fschmid | 152 | Table = new QTable( devTitle ); |
3261 | fschmid | 153 | Table->setNumRows( spots.count()+4 ); |
154 | Table->setNumCols( 2 ); |
||
5337 | cbradney | 155 | Table->horizontalHeader()->setLabel(0, loadIcon("16/show-object.png"), ""); |
3261 | fschmid | 156 | Table->horizontalHeader()->setLabel(1, tr("Separation Name")); |
157 | Table->setColumnReadOnly(0, true); |
||
158 | Table->setColumnReadOnly(1, true); |
||
159 | Table->setColumnWidth(0, 24); |
||
160 | Table->setRowMovingEnabled(false); |
||
161 | Table->setSorting(false); |
||
162 | Table->setSelectionMode( QTable::NoSelection ); |
||
163 | Table->setFocusStyle( QTable::FollowStyle ); |
||
164 | Table->setLeftMargin(0); |
||
165 | Table->verticalHeader()->hide(); |
||
166 | flagsVisible.clear(); |
||
167 | QCheckBox *cp; |
||
168 | Table->setText(0, 1, tr("Cyan")); |
||
169 | cp = new QCheckBox(this, ""); |
||
170 | cp->setChecked(prefsManager->appPrefs.PrPr_C); |
||
171 | connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
172 | Table->setCellWidget(0, 0, cp); |
||
173 | flagsVisible.insert("Cyan", cp); |
||
174 | Table->setText(1, 1, tr("Magenta")); |
||
175 | cp = new QCheckBox(this, ""); |
||
176 | cp->setChecked(prefsManager->appPrefs.PrPr_M); |
||
177 | connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
178 | Table->setCellWidget(1, 0, cp); |
||
179 | flagsVisible.insert("Magenta", cp); |
||
180 | Table->setText(2, 1, tr("Yellow")); |
||
181 | cp = new QCheckBox(this, ""); |
||
182 | cp->setChecked(prefsManager->appPrefs.PrPr_Y); |
||
183 | connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
184 | Table->setCellWidget(2, 0, cp); |
||
185 | flagsVisible.insert("Yellow", cp); |
||
186 | Table->setText(3, 1, tr("Black")); |
||
187 | cp = new QCheckBox(this, ""); |
||
188 | cp->setChecked(prefsManager->appPrefs.PrPr_K); |
||
189 | connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
190 | Table->setCellWidget(3, 0, cp); |
||
191 | flagsVisible.insert("Black", cp); |
||
192 | for (uint sp = 0; sp < spots.count(); ++sp) |
||
193 | { |
||
194 | Table->setText(sp+4, 1, spots[sp]); |
||
195 | cp = new QCheckBox(this, ""); |
||
196 | cp->setChecked(true); |
||
197 | connect(cp, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
198 | Table->setCellWidget(sp+4, 0, cp); |
||
199 | flagsVisible.insert(spots[sp], cp); |
||
200 | } |
||
201 | Table->adjustColumn(1); |
||
202 | Table->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, Table->sizePolicy().hasHeightForWidth() ) ); |
||
6690 | fschmid | 203 | Layout2->addWidget(Table); |
4046 | fschmid | 204 | tbWidth = Table->columnWidth(1); |
3261 | fschmid | 205 | } |
6690 | fschmid | 206 | settingsBarLayout->addWidget(devTitle); |
207 | jobTitle = new QGroupBox( this, "jobTitle" ); |
||
6756 | fschmid | 208 | jobTitle->setTitle( tr( "Print Settings" ) ); |
6690 | fschmid | 209 | jobTitle->setColumnLayout(0, Qt::Vertical ); |
210 | jobTitle->layout()->setSpacing( 5 ); |
||
211 | jobTitle->layout()->setMargin( 5 ); |
||
212 | Layout1 = new QVBoxLayout( jobTitle->layout() ); |
||
213 | Layout1->setAlignment( Qt::AlignTop ); |
||
214 | |||
215 | MirrorHor = new QCheckBox( tr( "Mirror Page(s) Horizontal" ), jobTitle, "MirrorH" ); |
||
216 | Layout1->addWidget( MirrorHor ); |
||
217 | |||
218 | MirrorVert = new QCheckBox( tr( "Mirror Page(s) Vertical" ), jobTitle, "MirrorV" ); |
||
219 | Layout1->addWidget( MirrorVert ); |
||
220 | |||
221 | ClipMarg = new QCheckBox( tr( "Clip to Page Margins" ), jobTitle, "ClipMarg" ); |
||
222 | Layout1->addWidget( ClipMarg ); |
||
223 | |||
224 | useGray = new QCheckBox( tr("Print in Grayscale"), jobTitle, "useGray"); |
||
225 | Layout1->addWidget(useGray); |
||
226 | |||
227 | EnableGCR = new QCheckBox( tr("&Under Color Removal"), jobTitle, "DisplayGCR"); |
||
228 | Layout1->addWidget(EnableGCR); |
||
229 | |||
230 | EnableOverprint = new QCheckBox( tr("Force Overprint Mode"), jobTitle, "EnableOverprint"); |
||
231 | Layout1->addWidget(EnableOverprint); |
||
232 | |||
233 | spotColors = new QCheckBox( tr( "Convert Spot Colors" ), jobTitle, "spotColors" ); |
||
234 | Layout1->addWidget( spotColors ); |
||
235 | |||
236 | UseICC = new QCheckBox( tr( "Apply ICC Profiles" ), jobTitle, "UseICC" ); |
||
237 | Layout1->addWidget( UseICC ); |
||
238 | if (!doc->HasCMS) |
||
239 | UseICC->setEnabled(false); |
||
240 | |||
241 | settingsBarLayout->addWidget(jobTitle); |
||
242 | QSpacerItem* spacerC = new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
||
243 | settingsBarLayout->addItem( spacerC ); |
||
244 | Layout5->addLayout(settingsBarLayout); |
||
245 | PLayout->addLayout(Layout5); |
||
246 | |||
3168 | fschmid | 247 | Layout6 = new QHBoxLayout(); |
248 | Layout6->setSpacing(0); |
||
249 | Layout6->setMargin(0); |
||
3172 | subik | 250 | /* scaling */ |
6260 | fschmid | 251 | scaleLabel = new QLabel( tr("Scaling:"), this, "scaleLabel"); |
3173 | fschmid | 252 | scaleBox = new QComboBox( true, this, "unitSwitcher" ); |
253 | scaleBox->setEditable(false); |
||
254 | scaleBox->setFocusPolicy(QWidget::NoFocus); |
||
255 | scaleBox->insertItem("50%"); |
||
256 | scaleBox->insertItem("100%"); |
||
257 | scaleBox->insertItem("150%"); |
||
258 | scaleBox->insertItem("200%"); |
||
6024 | fschmid | 259 | scaleBox->insertItem( tr("Fit to Width")); |
260 | scaleBox->insertItem( tr("Fit to Height")); |
||
261 | scaleBox->insertItem( tr("Fit to Page")); |
||
3173 | fschmid | 262 | scaleBox->setCurrentItem(1); |
3172 | subik | 263 | Layout6->addWidget(scaleLabel); |
264 | Layout6->addWidget(scaleBox); |
||
3168 | fschmid | 265 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
266 | Layout6->addItem( spacer ); |
||
5343 | cbradney | 267 | PGSel = new PageSelector(this, doc->DocPages.count()); |
268 | PGSel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, PGSel->sizePolicy().hasHeightForWidth() ) ); |
||
269 | Layout6->addWidget(PGSel); |
||
270 | QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
271 | Layout6->addItem( spacer2 ); |
||
3498 | avox | 272 | closeButton = new QPushButton( tr("Close"), this, "closeButton" ); |
3570 | cbradney | 273 | closeButton->setAutoDefault(false); |
3488 | avox | 274 | Layout6->addWidget( closeButton ); |
3230 | fschmid | 275 | printButton = new QPushButton( tr("Print..."), this, "printButton" ); |
3570 | cbradney | 276 | printButton->setAutoDefault(false); |
3234 | fschmid | 277 | printButton->setEnabled(!printDinUse); |
3230 | fschmid | 278 | Layout6->addWidget( printButton ); |
3168 | fschmid | 279 | PLayout->addLayout(Layout6); |
6690 | fschmid | 280 | setValues(); |
3173 | fschmid | 281 | Anz = new QLabel(Anzeige->viewport()); |
282 | Anz->setPixmap(CreatePreview(0, 72)); |
||
283 | Anzeige->addChild(Anz, 0, 0); |
||
4046 | fschmid | 284 | int w = Anz->width() + tbWidth + 50; |
285 | resize(QMIN(QApplication::desktop()->width()-30,w), 500); |
||
3165 | fschmid | 286 | if (!PrefsManager::instance()->appPrefs.PrPr_Mode) |
287 | { |
||
3261 | fschmid | 288 | if (HaveTiffSep != 0) |
289 | { |
||
290 | EnableCMYK_C->setEnabled(false); |
||
291 | EnableCMYK_M->setEnabled(false); |
||
292 | EnableCMYK_Y->setEnabled(false); |
||
293 | EnableCMYK_K->setEnabled(false); |
||
294 | } |
||
295 | else |
||
296 | Table->setEnabled(false); |
||
3165 | fschmid | 297 | } |
3172 | subik | 298 | // tooltips |
6008 | jghali | 299 | 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>" ); |
3172 | subik | 300 | QToolTip::add( AliasTr, "<qt>" + tr( "Shows transparency and transparent items in your document. Requires Ghostscript 7.07 or later" ) + "</qt>"); |
301 | QToolTip::add( EnableCMYK, "<qt>" + tr( "Gives a print preview using simulations of generic CMYK inks, instead of RGB colors" ) + "</qt>"); |
||
302 | 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>" ); |
||
3173 | fschmid | 303 | QToolTip::add(scaleBox, "<qt>" + tr("Resize the scale of the page.") + "</qt>"); |
6690 | fschmid | 304 | 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>"); |
305 | QToolTip::add(EnableOverprint, "<qt>"+ tr("Enables global Overprint Mode for this document, overrides object settings") + "<qt>"); |
||
306 | QToolTip::add(UseICC,"<qt>" + tr( "Allows you to embed ICC profiles in the print stream when color management is enabled" ) + "</qt>"); |
||
307 | |||
3165 | fschmid | 308 | //signals and slots |
6690 | fschmid | 309 | connect(AntiAlias, SIGNAL(clicked()), this, SLOT(redisplay())); |
310 | connect(AliasTr, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
3165 | fschmid | 311 | connect(EnableCMYK, SIGNAL(clicked()), this, SLOT(ToggleCMYK())); |
6690 | fschmid | 312 | connect(EnableGCR, SIGNAL(clicked()), this, SLOT(redisplay())); |
313 | connect(EnableOverprint, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
314 | connect(MirrorHor, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
315 | connect(MirrorVert, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
316 | connect(ClipMarg, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
317 | connect(spotColors, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
318 | connect(useGray, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
319 | connect(UseICC, SIGNAL(clicked()), this, SLOT(redisplay())); |
||
3261 | fschmid | 320 | if (HaveTiffSep != 0) |
321 | { |
||
322 | connect(EnableCMYK_C, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
323 | connect(EnableCMYK_M, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
324 | connect(EnableCMYK_Y, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
325 | connect(EnableCMYK_K, SIGNAL(clicked()), this, SLOT(ToggleCMYK_Colour())); |
||
326 | QToolTip::add( EnableCMYK_C, tr( "Enable/disable the C (Cyan) ink plate" ) ); |
||
327 | QToolTip::add( EnableCMYK_M, tr( "Enable/disable the M (Magenta) ink plate" ) ); |
||
328 | QToolTip::add( EnableCMYK_Y, tr( "Enable/disable the Y (Yellow) ink plate" ) ); |
||
329 | QToolTip::add( EnableCMYK_K, tr( "Enable/disable the K (Black) ink plate" ) ); |
||
330 | } |
||
3165 | fschmid | 331 | connect(PGSel, SIGNAL(GotoPage(int)), this, SLOT(ToSeite(int))); |
3488 | avox | 332 | connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); |
3168 | fschmid | 333 | connect(printButton, SIGNAL(clicked()), this, SIGNAL(doPrint())); |
3173 | fschmid | 334 | connect(scaleBox, SIGNAL(activated(int)), this, SLOT(scaleBox_valueChanged(int))); |
3165 | fschmid | 335 | } |
336 | |||
6690 | fschmid | 337 | void PPreview::setValues() |
338 | { |
||
7104 | fschmid | 339 | if ((printDinUse) || (!doc->Print_Options.firstUse)) |
340 | { |
||
341 | EnableGCR->setChecked( postscriptPreview ? doc->Print_Options.doGCR : false); |
||
342 | EnableGCR->setEnabled( postscriptPreview ); |
||
343 | EnableOverprint->setChecked( postscriptPreview ? doc->Print_Options.doOverprint : false); |
||
344 | EnableOverprint->setEnabled( postscriptPreview ); |
||
345 | MirrorHor->setChecked(doc->Print_Options.mirrorH); |
||
346 | MirrorVert->setChecked(doc->Print_Options.mirrorV); |
||
347 | ClipMarg->setChecked(doc->Print_Options.doClip); |
||
348 | spotColors->setChecked(!doc->Print_Options.useSpotColors); |
||
349 | useGray->setChecked(!doc->Print_Options.useColor); |
||
350 | if (doc->HasCMS) |
||
351 | { |
||
352 | UseICC->setChecked( postscriptPreview ? doc->Print_Options.useICC : false); |
||
353 | UseICC->setEnabled( postscriptPreview ); |
||
354 | } |
||
355 | } |
||
6690 | fschmid | 356 | else |
357 | { |
||
7104 | fschmid | 358 | PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("print_options"); |
359 | EnableGCR->setChecked( postscriptPreview ? prefs->getBool("DoGCR", false) : false); |
||
360 | EnableGCR->setEnabled( postscriptPreview ); |
||
361 | EnableOverprint->setChecked( postscriptPreview ? prefs->getBool("doOverprint", false) : false); |
||
362 | EnableOverprint->setEnabled( postscriptPreview ); |
||
363 | MirrorHor->setChecked(prefs->getBool("MirrorH", false)); |
||
364 | MirrorVert->setChecked(prefs->getBool("MirrorV", false)); |
||
365 | ClipMarg->setChecked(prefs->getBool("Clip", false)); |
||
366 | spotColors->setChecked(!prefs->getBool("doSpot", true)); |
||
367 | if (prefs->getInt("PrintColor", 0) == 1) |
||
368 | useGray->setChecked(true); |
||
369 | else |
||
370 | useGray->setChecked(false); |
||
371 | if (doc->HasCMS) |
||
372 | { |
||
373 | UseICC->setChecked( postscriptPreview ? prefs->getBool("ICCinUse", false) : false); |
||
374 | UseICC->setEnabled( postscriptPreview ); |
||
375 | } |
||
6690 | fschmid | 376 | } |
377 | } |
||
378 | |||
3165 | fschmid | 379 | void PPreview::ToSeite(int num) |
380 | { |
||
381 | int n = num-1; |
||
382 | if (n == APage) |
||
383 | return; |
||
3173 | fschmid | 384 | Anz->setPixmap(CreatePreview(n, qRound(72 * scaleFactor))); |
3165 | fschmid | 385 | } |
386 | |||
6690 | fschmid | 387 | void PPreview::redisplay() |
3165 | fschmid | 388 | { |
3173 | fschmid | 389 | Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor))); |
3165 | fschmid | 390 | } |
391 | |||
392 | void PPreview::ToggleCMYK() |
||
393 | { |
||
394 | bool c = EnableCMYK->isChecked() ? true : false; |
||
3261 | fschmid | 395 | if (HaveTiffSep != 0) |
396 | { |
||
397 | EnableCMYK_C->setEnabled(c); |
||
398 | EnableCMYK_M->setEnabled(c); |
||
399 | EnableCMYK_Y->setEnabled(c); |
||
400 | EnableCMYK_K->setEnabled(c); |
||
401 | } |
||
402 | else |
||
403 | Table->setEnabled(c); |
||
3173 | fschmid | 404 | Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor))); |
3165 | fschmid | 405 | } |
406 | |||
407 | void PPreview::ToggleCMYK_Colour() |
||
408 | { |
||
409 | if (EnableCMYK->isChecked()) |
||
3173 | fschmid | 410 | Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor))); |
3165 | fschmid | 411 | } |
412 | |||
3172 | subik | 413 | void PPreview::scaleBox_valueChanged(int value) |
414 | { |
||
3173 | fschmid | 415 | switch (value) |
416 | { |
||
417 | case 0: |
||
418 | scaleFactor = 0.5; |
||
419 | break; |
||
420 | case 1: |
||
421 | scaleFactor = 1.0; |
||
422 | break; |
||
423 | case 2: |
||
424 | scaleFactor = 1.5; |
||
425 | break; |
||
426 | case 3: |
||
427 | scaleFactor = 2.0; |
||
428 | break; |
||
6024 | fschmid | 429 | case 4: |
430 | scaleFactor = Anzeige->viewport()->width() / doc->Pages->at(APage)->width(); |
||
431 | break; |
||
432 | case 5: |
||
433 | scaleFactor = Anzeige->viewport()->height() / doc->Pages->at(APage)->height(); |
||
434 | break; |
||
435 | case 6: |
||
436 | scaleFactor = QMIN(Anzeige->viewport()->height() / doc->Pages->at(APage)->height(), Anzeige->viewport()->width() / doc->Pages->at(APage)->width()); |
||
437 | break; |
||
3173 | fschmid | 438 | default: |
439 | scaleFactor = 1.0; |
||
440 | break; |
||
441 | } |
||
442 | Anz->setPixmap(CreatePreview(APage, qRound(72 * scaleFactor))); |
||
3172 | subik | 443 | } |
444 | |||
3165 | fschmid | 445 | int PPreview::RenderPreview(int Seite, int Res) |
446 | { |
||
4194 | fschmid | 447 | int ret = -1; |
3165 | fschmid | 448 | QString cmd1, cmd2, cmd3; |
5387 | avox | 449 | QMap<QString,QMap<uint, FPointArray> > ReallyUsed; |
4361 | cbradney | 450 | #if defined _WIN32 |
451 | if ( !postscriptPreview ) |
||
452 | { |
||
453 | QImage image; |
||
454 | Page* page; |
||
455 | ScWinPrint winPrint; |
||
456 | PrintOptions options; |
||
457 | page = doc->Pages->at( Seite ); |
||
458 | options.copies = 1; |
||
459 | options.doGCR = false; |
||
460 | options.mirrorH = options.mirrorV = false; |
||
461 | options.outputSeparations = false; |
||
462 | options.pageNumbers.push_back( Seite ); |
||
463 | options.PSLevel = 0; |
||
464 | options.separationName = "All"; |
||
465 | options.toFile = false; |
||
466 | options.useColor = true; |
||
467 | options.useICC = false; |
||
468 | options.useSpotColors = false; |
||
5308 | fschmid | 469 | options.doOverprint = false; |
4361 | cbradney | 470 | bool done = winPrint.gdiPrintPreview(doc, page, &image, options, Res / 72.0); |
471 | if ( done ) |
||
6043 | jghali | 472 | image.save( ScPaths::getTempFileDir() + "/sc.png", "PNG" ); |
4361 | cbradney | 473 | return (done ? 0 : 1); |
474 | } |
||
475 | #endif |
||
3165 | fschmid | 476 | // Recreate Postscript-File only when the actual Page has changed |
6690 | fschmid | 477 | if ((Seite != APage) || (EnableGCR->isChecked() != GMode) || (EnableOverprint->isChecked() != OMode) |
478 | || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer) |
||
479 | || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot)) |
||
3165 | fschmid | 480 | { |
481 | ReallyUsed.clear(); |
||
5387 | avox | 482 | doc->getUsedFonts(ReallyUsed); |
6954 | fschmid | 483 | bool useIC = UseICC->isChecked(); |
484 | if (!doc->HasCMS) |
||
485 | useIC = false; |
||
486 | PrintOptions options; |
||
487 | options.pageNumbers.push_back(Seite+1); |
||
488 | options.outputSeparations = false; |
||
489 | options.separationName = tr("All"); |
||
490 | options.allSeparations = QStringList(); |
||
491 | options.useColor = !useGray->isChecked(); |
||
492 | options.mirrorH = MirrorHor->isChecked(); |
||
493 | options.mirrorV = MirrorVert->isChecked(); |
||
494 | options.useICC = useIC; |
||
495 | options.doGCR = EnableGCR->isChecked(); |
||
496 | options.setDevParam = false; |
||
497 | options.doClip = ClipMarg->isChecked(); |
||
498 | options.doOverprint = EnableOverprint->isChecked(); |
||
499 | options.cropMarks = false; |
||
500 | options.bleedMarks = false; |
||
501 | options.registrationMarks = false; |
||
502 | options.colorMarks = false; |
||
503 | options.markOffset = 0.0; |
||
7225 | cbradney | 504 | options.bleeds.Top = 0.0; |
505 | options.bleeds.Left = 0.0; |
||
506 | options.bleeds.Right = 0.0; |
||
507 | options.bleeds.Bottom = 0.0; |
||
6954 | fschmid | 508 | PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, ReallyUsed, doc->PageColors, false, !spotColors->isChecked()); |
3165 | fschmid | 509 | if (dd != NULL) |
510 | { |
||
6043 | jghali | 511 | dd->PS_set_file( ScPaths::getTempFileDir() + "/tmp.ps"); |
6954 | fschmid | 512 | dd->CreatePS(doc, options); |
3165 | fschmid | 513 | delete dd; |
514 | } |
||
515 | else |
||
516 | return ret; |
||
517 | } |
||
4194 | fschmid | 518 | QStringList args; |
3165 | fschmid | 519 | QString tmp, tmp2, tmp3; |
3724 | cbradney | 520 | double b = doc->Pages->at(Seite)->width() * Res / 72.0; |
521 | double h = doc->Pages->at(Seite)->height() * Res / 72.0; |
||
4194 | fschmid | 522 | args.append( getShortPathName(prefsManager->ghostscriptExecutable()) ); |
523 | args.append( "-q" ); |
||
524 | args.append( "-dNOPAUSE" ); |
||
525 | args.append( "-dPARANOIDSAFER" ); |
||
526 | args.append( QString("-r%1").arg(tmp.setNum(qRound(Res))) ); |
||
527 | args.append( QString("-g%1x%2").arg(tmp2.setNum(qRound(b))).arg(tmp3.setNum(qRound(h))) ); |
||
3165 | fschmid | 528 | if (EnableCMYK->isChecked()) |
3169 | fschmid | 529 | { |
530 | if (HaveTiffSep == 0) |
||
4194 | fschmid | 531 | args.append( "-sDEVICE=tiffsep" ); |
3169 | fschmid | 532 | else |
4194 | fschmid | 533 | { |
534 | args.append( "-sDEVICE=bitcmyk" ); |
||
535 | args.append( "-dGrayValues=256" ); |
||
536 | } |
||
3169 | fschmid | 537 | } |
3165 | fschmid | 538 | else |
539 | { |
||
3167 | fschmid | 540 | if ((!AliasTr->isChecked()) || (HavePngAlpha != 0)) |
4194 | fschmid | 541 | args.append( "-sDEVICE=png16m" ); |
3165 | fschmid | 542 | else |
4194 | fschmid | 543 | args.append( "-sDEVICE=pngalpha" ); |
3165 | fschmid | 544 | } |
6008 | jghali | 545 | if (AntiAlias->isChecked()) |
546 | { |
||
4194 | fschmid | 547 | args.append( "-dTextAlphaBits=4" ); |
548 | args.append( "-dGraphicsAlphaBits=4" ); |
||
6008 | jghali | 549 | } |
3165 | fschmid | 550 | // Add any extra font paths being used by Scribus to gs's font search path |
551 | PrefsContext *pc = prefsManager->prefsFile->getContext("Fonts"); |
||
552 | PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); |
||
4194 | fschmid | 553 | const char sep = ScPaths::envPathSeparator; |
3165 | fschmid | 554 | if (extraFonts->getRowCount() >= 1) |
5345 | mrdocs | 555 | cmd1 = QString("-sFONTPATH=%1").arg(QDir::convertSeparators(extraFonts->get(0,0))); |
3165 | fschmid | 556 | for (int i = 1; i < extraFonts->getRowCount(); ++i) |
5345 | mrdocs | 557 | cmd1 += QString("%1%2").arg(sep).arg(QDir::convertSeparators(extraFonts->get(i,0))); |
4194 | fschmid | 558 | if( !cmd1.isEmpty() ) |
559 | args.append( cmd1 ); |
||
3165 | fschmid | 560 | // then add any final args and call gs |
3169 | fschmid | 561 | if ((EnableCMYK->isChecked()) && (HaveTiffSep == 0)) |
6043 | jghali | 562 | args.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif")) ); |
3169 | fschmid | 563 | else |
6043 | jghali | 564 | args.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.png")) ); |
565 | args.append( QDir::convertSeparators(ScPaths::getTempFileDir()+"/tmp.ps") ); |
||
4194 | fschmid | 566 | args.append( "-c" ); |
567 | args.append( "showpage" ); |
||
568 | args.append( "-c" ); |
||
569 | args.append( "quit" ); |
||
570 | ret = System( args ); |
||
3165 | fschmid | 571 | return ret; |
572 | } |
||
573 | |||
3261 | fschmid | 574 | int PPreview::RenderPreviewSep(int Seite, int Res) |
575 | { |
||
4194 | fschmid | 576 | int ret = -1; |
577 | QString cmd; |
||
578 | QStringList args, args1, args2, args3; |
||
5387 | avox | 579 | QMap<QString, QMap<uint, FPointArray> > ReallyUsed; |
3261 | fschmid | 580 | // Recreate Postscript-File only when the actual Page has changed |
6690 | fschmid | 581 | if ((Seite != APage) || (EnableGCR->isChecked() != GMode) || (EnableOverprint->isChecked() != OMode) |
582 | || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer) |
||
583 | || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot)) |
||
3261 | fschmid | 584 | { |
585 | ReallyUsed.clear(); |
||
5387 | avox | 586 | doc->getUsedFonts(ReallyUsed); |
6954 | fschmid | 587 | bool useIC = UseICC->isChecked(); |
588 | if (!doc->HasCMS) |
||
589 | useIC = false; |
||
590 | PrintOptions options; |
||
591 | options.pageNumbers.push_back(Seite+1); |
||
592 | options.outputSeparations = false; |
||
593 | options.separationName = tr("All"); |
||
594 | options.allSeparations = QStringList(); |
||
595 | options.useColor = !useGray->isChecked(); |
||
596 | options.mirrorH = MirrorHor->isChecked(); |
||
597 | options.mirrorV = MirrorVert->isChecked(); |
||
598 | options.useICC = useIC; |
||
599 | options.doGCR = EnableGCR->isChecked(); |
||
600 | options.setDevParam = false; |
||
601 | options.doClip = ClipMarg->isChecked(); |
||
602 | options.doOverprint = EnableOverprint->isChecked(); |
||
603 | options.cropMarks = false; |
||
604 | options.bleedMarks = false; |
||
605 | options.registrationMarks = false; |
||
606 | options.colorMarks = false; |
||
607 | options.markOffset = 0.0; |
||
7225 | cbradney | 608 | options.bleeds.Top = 0.0; |
609 | options.bleeds.Left = 0.0; |
||
610 | options.bleeds.Right = 0.0; |
||
611 | options.bleeds.Bottom = 0.0; |
||
6954 | fschmid | 612 | PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, ReallyUsed, doc->PageColors, false, !spotColors->isChecked()); |
3261 | fschmid | 613 | if (dd != NULL) |
614 | { |
||
6043 | jghali | 615 | dd->PS_set_file(ScPaths::getTempFileDir()+"/tmp.ps"); |
6954 | fschmid | 616 | dd->CreatePS(doc, options); |
3261 | fschmid | 617 | delete dd; |
618 | } |
||
619 | else |
||
620 | return ret; |
||
621 | } |
||
622 | QString tmp, tmp2, tmp3; |
||
3724 | cbradney | 623 | double b = doc->Pages->at(Seite)->width() * Res / 72.0; |
624 | double h = doc->Pages->at(Seite)->height() * Res / 72.0; |
||
4194 | fschmid | 625 | |
626 | args1.append( getShortPathName(prefsManager->ghostscriptExecutable()) ); |
||
627 | args1.append( "-q" ); |
||
628 | args1.append( "-dNOPAUSE" ); |
||
629 | args1.append( "-dPARANOIDSAFER" ); |
||
630 | args1.append( QString("-r%1").arg(tmp.setNum(qRound(Res))) ); |
||
631 | args1.append( QString("-g%1x%2").arg(tmp2.setNum(qRound(b))).arg(tmp3.setNum(qRound(h))) ); |
||
6008 | jghali | 632 | if (AntiAlias->isChecked()) |
633 | { |
||
4194 | fschmid | 634 | args1.append("-dTextAlphaBits=4"); |
635 | args1.append("-dGraphicsAlphaBits=4"); |
||
6008 | jghali | 636 | } |
3261 | fschmid | 637 | // Add any extra font paths being used by Scribus to gs's font search path |
638 | PrefsContext *pc = prefsManager->prefsFile->getContext("Fonts"); |
||
639 | PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); |
||
4194 | fschmid | 640 | const char sep = ScPaths::envPathSeparator; |
3261 | fschmid | 641 | if (extraFonts->getRowCount() >= 1) |
5345 | mrdocs | 642 | cmd = QString("-sFONTPATH=%1").arg(QDir::convertSeparators(extraFonts->get(0,0))); |
3261 | fschmid | 643 | for (int i = 1; i < extraFonts->getRowCount(); ++i) |
5345 | mrdocs | 644 | cmd += QString("%1%2").arg(sep).arg(QDir::convertSeparators(extraFonts->get(i,0))); |
4194 | fschmid | 645 | if( !cmd.isEmpty() ) |
646 | args1.append( cmd ); |
||
6043 | jghali | 647 | args1.append( QString("-sOutputFile=%1").arg(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif")) ); |
4194 | fschmid | 648 | |
6043 | jghali | 649 | args2.append( QDir::convertSeparators(ScPaths::getTempFileDir()+"/tmp.ps") ); |
4194 | fschmid | 650 | args2.append("-c"); |
651 | args2.append("quit"); |
||
652 | |||
3261 | fschmid | 653 | ColorList usedSpots; |
654 | doc->getUsedColors(usedSpots, true); |
||
655 | QStringList spots = usedSpots.keys(); |
||
4194 | fschmid | 656 | args3.append( "-sDEVICE=tiffsep" ); |
657 | |||
658 | args3.append( "-c" ); |
||
659 | cmd = "<< /SeparationColorNames "; |
||
3261 | fschmid | 660 | QString allSeps ="[ /Cyan /Magenta /Yellow /Black "; |
661 | for (uint sp = 0; sp < spots.count(); ++sp) |
||
662 | { |
||
663 | allSeps += "("+spots[sp]+") "; |
||
664 | } |
||
665 | allSeps += "]"; |
||
4194 | fschmid | 666 | cmd += allSeps + " /SeparationOrder [ /Cyan /Magenta /Yellow /Black] >> setpagedevice"; |
667 | args3.append(cmd); |
||
668 | |||
669 | args3.append("-f"); |
||
6043 | jghali | 670 | ret = System(args1 + args3 + args2, ScPaths::getTempFileDir()+"/sc.tif.txt" ); |
4194 | fschmid | 671 | |
6043 | jghali | 672 | QFile sepInfo(QDir::convertSeparators(ScPaths::getTempFileDir()+"/sc.tif.txt")); |
3261 | fschmid | 673 | sepsToFileNum.clear(); |
674 | if (sepInfo.open(IO_ReadOnly)) |
||
675 | { |
||
676 | QString Sname; |
||
677 | QTextStream tsC(&sepInfo); |
||
678 | int counter = 0; |
||
679 | while (!tsC.atEnd()) |
||
680 | { |
||
681 | Sname = tsC.readLine(); |
||
682 | QString tt = Sname.remove("%%SeparationName:").stripWhiteSpace(); |
||
683 | sepsToFileNum.insert(tt, counter); |
||
684 | counter++; |
||
685 | } |
||
686 | } |
||
687 | sepInfo.close(); |
||
688 | QString currSeps = ""; |
||
689 | uint spc = 0; |
||
690 | for (uint sp = 0; sp < spots.count(); ++sp) |
||
691 | { |
||
692 | currSeps += "("+spots[sp]+") "; |
||
693 | spc++; |
||
694 | if (sp > 6) |
||
695 | { |
||
4194 | fschmid | 696 | args3.clear(); |
697 | args3.append("-sDEVICE=tiffsep"); |
||
698 | args3.append("-c"); |
||
699 | args3.append("<< /SeparationColorNames "+allSeps+" /SeparationOrder [ "+currSeps+" ] >> setpagedevice"); |
||
700 | args3.append("-f"); |
||
701 | ret = System(args1 + args3 + args2); |
||
3261 | fschmid | 702 | currSeps = ""; |
703 | spc = 0; |
||
704 | } |
||
705 | } |
||
706 | if (spc != 0) |
||
707 | { |
||
4194 | fschmid | 708 | args3.clear(); |
709 | args3.append("-sDEVICE=tiffsep"); |
||
710 | args3.append("-c"); |
||
711 | args3.append("<< /SeparationColorNames "+allSeps+" /SeparationOrder [ "+currSeps+" ] >> setpagedevice"); |
||
712 | args3.append("-f"); |
||
713 | ret = System(args1 + args3 + args2); |
||
3261 | fschmid | 714 | } |
715 | return ret; |
||
716 | } |
||
717 | |||
5593 | avox | 718 | // this should move to scimage.cpp! |
719 | void PPreview::blendImages(QImage &target, ScImage &scsource, ScColor col) |
||
3261 | fschmid | 720 | { |
5593 | avox | 721 | QImage source = scsource.qImage(); // FIXME: this will not work once qImage always returns ARGB! |
722 | |||
3300 | avox | 723 | //FIXME: if source and target have different sizesomething went wrong. |
724 | // eg. loadPicture() failed and returned a 1x1 image |
||
9621 | jghali | 725 | CMYKColor cmykValues; |
3300 | avox | 726 | int h = QMIN(target.height(),source.height()); |
727 | int w = QMIN(target.width(),source.width()); |
||
3261 | fschmid | 728 | int cyan, c, m, yc, k, cc, mm, yy, kk; |
9621 | jghali | 729 | ScColorEngine::getCMYKValues(col, doc, cmykValues); |
730 | cmykValues.getValues(c, m, yc, k); |
||
3261 | fschmid | 731 | for (int y=0; y < h; ++y ) |
732 | { |
||
733 | QRgb *p = (QRgb *)target.scanLine( y ); |
||
734 | QRgb *pq = (QRgb *)source.scanLine( y ); |
||
735 | for (int x=0; x < w; ++x ) |
||
736 | { |
||
737 | cyan = 255 - qRed(*pq); |
||
738 | if (cyan != 0) |
||
739 | { |
||
3268 | fschmid | 740 | (c == 0) ? cc = qRed(*p) : cc = QMIN(c * cyan / 255 + qRed(*p), 255); |
741 | (m == 0) ? mm = qGreen(*p) : mm = QMIN(m * cyan / 255 + qGreen(*p), 255); |
||
742 | (yc == 0) ? yy = qBlue(*p) : yy = QMIN(yc * cyan / 255 + qBlue(*p), 255); |
||
743 | (k == 0) ? kk = qAlpha(*p) : kk = QMIN(k * cyan / 255 + qAlpha(*p), 255); |
||
3261 | fschmid | 744 | *p = qRgba(cc, mm, yy, kk); |
745 | } |
||
746 | p++; |
||
747 | pq++; |
||
748 | } |
||
749 | } |
||
750 | } |
||
751 | |||
3165 | fschmid | 752 | QPixmap PPreview::CreatePreview(int Seite, int Res) |
753 | { |
||
754 | int ret = -1; |
||
755 | QPixmap Bild; |
||
3724 | cbradney | 756 | double b = doc->Pages->at(Seite)->width() * Res / 72.0; |
757 | double h = doc->Pages->at(Seite)->height() * Res / 72.0; |
||
3165 | fschmid | 758 | qApp->setOverrideCursor(QCursor(waitCursor), true); |
3173 | fschmid | 759 | if ((Seite != APage) || (EnableCMYK->isChecked() != CMode) || (SMode != scaleBox->currentItem()) |
6008 | jghali | 760 | || (AntiAlias->isChecked() != GsAl) || ((AliasTr->isChecked() != Trans) || (EnableGCR->isChecked() != GMode) |
6690 | fschmid | 761 | || (EnableOverprint->isChecked() != OMode) && (!EnableCMYK->isChecked())) |
762 | || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) || (MirrorVert->isChecked() != mVer) |
||
763 | || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot)) |
||
3165 | fschmid | 764 | { |
3261 | fschmid | 765 | if (!EnableCMYK->isChecked() || (HaveTiffSep != 0)) |
3165 | fschmid | 766 | { |
3261 | fschmid | 767 | ret = RenderPreview(Seite, Res); |
768 | if (ret != 0) |
||
769 | { |
||
6394 | cbradney | 770 | imageLoadError(Bild, Seite); |
3261 | fschmid | 771 | return Bild; |
772 | } |
||
3165 | fschmid | 773 | } |
774 | } |
||
775 | QImage image; |
||
776 | if (EnableCMYK->isChecked()) |
||
777 | { |
||
778 | int cyan, magenta, yellow, black, alpha; |
||
779 | uint *p; |
||
6392 | fschmid | 780 | bool loaderror; |
3169 | fschmid | 781 | if (HaveTiffSep == 0) |
3165 | fschmid | 782 | { |
3261 | fschmid | 783 | if ((Seite != APage) || (EnableCMYK->isChecked() != CMode) || (SMode != scaleBox->currentItem()) |
6745 | fschmid | 784 | || (AntiAlias->isChecked() != GsAl) || (AliasTr->isChecked() != Trans) || (EnableGCR->isChecked() != GMode) |
785 | || (EnableOverprint->isChecked() != OMode) || (useGray->isChecked() != fGray) || (MirrorHor->isChecked() != mHor) |
||
786 | || (MirrorVert->isChecked() != mVer) || (ClipMarg->isChecked() != fClip) || (UseICC->isChecked() != fICC) || (spotColors->isChecked() != fSpot)) |
||
3261 | fschmid | 787 | { |
788 | ret = RenderPreviewSep(Seite, Res); |
||
6392 | fschmid | 789 | if (ret != 0) |
790 | { |
||
6394 | cbradney | 791 | imageLoadError(Bild, Seite); |
6392 | fschmid | 792 | return Bild; |
793 | } |
||
3261 | fschmid | 794 | } |
3169 | fschmid | 795 | ScImage im; |
796 | bool mode; |
||
3261 | fschmid | 797 | int w = qRound(b); |
798 | int h2 = qRound(h); |
||
799 | image = QImage(w, h2, 32); |
||
4618 | fschmid | 800 | QRgb clean = qRgba(0, 0, 0, 0); |
801 | for( int yi=0; yi < h2; ++yi ) |
||
802 | { |
||
803 | QRgb *q = (QRgb*)(image.scanLine( yi )); |
||
804 | for(int xi=0; xi < w; ++xi ) |
||
805 | { |
||
806 | *q = clean; |
||
807 | q++; |
||
808 | } |
||
809 | } |
||
5959 | jghali | 810 | CMSettings cms(doc, "", 0); |
3268 | fschmid | 811 | if (flagsVisible["Cyan"]->isChecked()) |
3165 | fschmid | 812 | { |
5542 | fschmid | 813 | if (GsMinor < 54) |
6392 | fschmid | 814 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Cyan.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
5542 | fschmid | 815 | else |
6392 | fschmid | 816 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Cyan.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
817 | if (!loaderror) |
||
818 | { |
||
6394 | cbradney | 819 | imageLoadError(Bild, Seite); |
6392 | fschmid | 820 | return Bild; |
821 | } |
||
3268 | fschmid | 822 | blendImages(image, im, ScColor(255, 0, 0, 0)); |
3165 | fschmid | 823 | } |
3268 | fschmid | 824 | if (flagsVisible["Magenta"]->isChecked()) |
825 | { |
||
5542 | fschmid | 826 | if (GsMinor < 54) |
6392 | fschmid | 827 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Magenta.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
5542 | fschmid | 828 | else |
6392 | fschmid | 829 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Magenta.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
830 | if (!loaderror) |
||
831 | { |
||
6394 | cbradney | 832 | imageLoadError(Bild, Seite); |
6392 | fschmid | 833 | return Bild; |
834 | } |
||
3268 | fschmid | 835 | blendImages(image, im, ScColor(0, 255, 0, 0)); |
836 | } |
||
837 | if (flagsVisible["Yellow"]->isChecked()) |
||
838 | { |
||
5542 | fschmid | 839 | if (GsMinor < 54) |
6392 | fschmid | 840 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Yellow.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
5542 | fschmid | 841 | else |
6392 | fschmid | 842 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Yellow.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
843 | if (!loaderror) |
||
844 | { |
||
6394 | cbradney | 845 | imageLoadError(Bild, Seite); |
6392 | fschmid | 846 | return Bild; |
847 | } |
||
3268 | fschmid | 848 | blendImages(image, im, ScColor(0, 0, 255, 0)); |
849 | } |
||
3261 | fschmid | 850 | QMap<QString, int>::Iterator sepit; |
851 | for (sepit = sepsToFileNum.begin(); sepit != sepsToFileNum.end(); ++sepit) |
||
852 | { |
||
853 | if (flagsVisible[sepit.key()]->isChecked()) |
||
854 | { |
||
5542 | fschmid | 855 | QString fnam; |
856 | if (GsMinor < 54) |
||
6043 | jghali | 857 | fnam = QString(ScPaths::getTempFileDir()+"/sc.tif.s%1.tif").arg(sepit.data()); |
5542 | fschmid | 858 | else |
6043 | jghali | 859 | fnam = QString(ScPaths::getTempFileDir()+"/sc.s%1.tif").arg(sepit.data()); |
6392 | fschmid | 860 | if (!im.LoadPicture(fnam, cms, false, false, ScImage::RGBData, 72, &mode)) |
861 | { |
||
6394 | cbradney | 862 | imageLoadError(Bild, Seite); |
6392 | fschmid | 863 | return Bild; |
864 | } |
||
3261 | fschmid | 865 | blendImages(image, im, doc->PageColors[sepit.key()]); |
866 | } |
||
867 | } |
||
868 | if (flagsVisible["Black"]->isChecked()) |
||
869 | { |
||
5959 | jghali | 870 | CMSettings cms(doc, "", 0); |
5542 | fschmid | 871 | if (GsMinor < 54) |
6392 | fschmid | 872 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Black.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
5542 | fschmid | 873 | else |
6392 | fschmid | 874 | loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Black.tif", cms, false, false, ScImage::RGBData, 72, &mode); |
875 | if (!loaderror) |
||
876 | { |
||
6394 | cbradney | 877 | imageLoadError(Bild, Seite); |
6392 | fschmid | 878 | return Bild; |
879 | } |
||
3268 | fschmid | 880 | blendImages(image, im, ScColor(0, 0, 0, 255)); |
3261 | fschmid | 881 | } |
6702 | fschmid | 882 | if (doc->HasCMS) |
3261 | fschmid | 883 | { |
6702 | fschmid | 884 | QRgb alphaFF = qRgba(0,0,0,255); |
885 | QRgb alphaOO = qRgba(255,255,255,0); |
||
886 | 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); |
||
887 | for( int yi=0; yi < h2; ++yi ) |
||
3261 | fschmid | 888 | { |
6702 | fschmid | 889 | LPBYTE ptr = image.scanLine( yi ); |
890 | cmsDoTransform(transCMYK, ptr, ptr, image.width()); |
||
891 | QRgb *q = (QRgb *) ptr; |
||
892 | for (int xi = 0; xi < image.width(); xi++, q++) |
||
3268 | fschmid | 893 | { |
6702 | fschmid | 894 | if (AliasTr->isChecked()) |
895 | { |
||
896 | cyan = qRed(*q); |
||
897 | magenta = qGreen(*q); |
||
898 | yellow = qBlue(*q); |
||
899 | if ((cyan == 255) && (magenta == 255) && (yellow == 255)) |
||
900 | *q = alphaOO; |
||
901 | else |
||
902 | *q |= alphaFF; |
||
903 | } |
||
904 | else |
||
905 | *q |= alphaFF; |
||
3268 | fschmid | 906 | } |
3261 | fschmid | 907 | } |
6702 | fschmid | 908 | cmsDeleteTransform (transCMYK); |
3261 | fschmid | 909 | } |
6702 | fschmid | 910 | else |
911 | { |
||
912 | for( int yi=0; yi < h2; ++yi ) |
||
913 | { |
||
914 | QRgb *q = (QRgb*)(image.scanLine( yi )); |
||
915 | for(int xi=0; xi < w; ++xi ) |
||
916 | { |
||
917 | cyan = qRed(*q); |
||
918 | magenta = qGreen(*q); |
||
919 | yellow = qBlue(*q); |
||
920 | black = qAlpha(*q); |
||
921 | if ((cyan != 0) || (magenta != 0) || (yellow != 0 ) || (black != 0)) |
||
922 | *q = qRgba(255-QMIN(255, cyan+black), 255-QMIN(255,magenta+black), 255-QMIN(255,yellow+black), 255); |
||
923 | else |
||
924 | { |
||
925 | if (!AliasTr->isChecked()) |
||
926 | *q = qRgba(255, 255, 255, 255); |
||
927 | } |
||
928 | q++; |
||
929 | } |
||
930 | } |
||
931 | } |
||
3165 | fschmid | 932 | } |
3169 | fschmid | 933 | else |
934 | { |
||
3173 | fschmid | 935 | int w = qRound(b); |
936 | int w2 = 4*w; |
||
937 | int h2 = qRound(h); |
||
938 | image = QImage(w, h2, 32); |
||
3169 | fschmid | 939 | QByteArray imgc(w2); |
6043 | jghali | 940 | QFile f(ScPaths::getTempFileDir()+"/sc.png"); |
3169 | fschmid | 941 | if (f.open(IO_ReadOnly)) |
942 | { |
||
6702 | fschmid | 943 | if (doc->HasCMS) |
3169 | fschmid | 944 | { |
6702 | fschmid | 945 | QRgb alphaFF = qRgba(0,0,0,255); |
946 | QRgb alphaOO = qRgba(255,255,255,0); |
||
947 | 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); |
||
948 | for (int y=0; y < h2; ++y ) |
||
3169 | fschmid | 949 | { |
6702 | fschmid | 950 | LPBYTE ptr = image.scanLine( y ); |
951 | f.readBlock(imgc.data(), w2); |
||
952 | p = (uint *)image.scanLine( y ); |
||
953 | for (int x=0; x < w2; x += 4 ) |
||
954 | { |
||
955 | cyan = uchar(imgc[x]); |
||
956 | magenta = uchar(imgc[x + 1]); |
||
957 | yellow = uchar(imgc[x + 2]); |
||
958 | black = uchar(imgc[x + 3]); |
||
959 | if (!EnableCMYK_C->isChecked()) |
||
960 | cyan = 0; |
||
961 | if (!EnableCMYK_M->isChecked()) |
||
962 | magenta = 0; |
||
963 | if (!EnableCMYK_Y->isChecked()) |
||
964 | yellow = 0; |
||
965 | if (!EnableCMYK_K->isChecked()) |
||
966 | black = 0; |
||
967 | *p = qRgba(cyan, magenta, yellow, black); |
||
968 | p++; |
||
969 | } |
||
970 | cmsDoTransform(transCMYK, ptr, ptr, image.width()); |
||
971 | QRgb *q = (QRgb *) ptr; |
||
972 | for (int xi = 0; xi < image.width(); xi++, q++) |
||
973 | { |
||
974 | if (AliasTr->isChecked()) |
||
975 | { |
||
976 | cyan = qRed(*q); |
||
977 | magenta = qGreen(*q); |
||
978 | yellow = qBlue(*q); |
||
979 | if ((cyan == 255) && (magenta == 255) && (yellow == 255)) |
||
980 | *q = alphaOO; |
||
981 | else |
||
982 | *q |= alphaFF; |
||
983 | } |
||
984 | else |
||
985 | *q |= alphaFF; |
||
986 | } |
||
3169 | fschmid | 987 | } |
6702 | fschmid | 988 | cmsDeleteTransform (transCMYK); |
3169 | fschmid | 989 | } |
6702 | fschmid | 990 | else |
991 | { |
||
992 | for (int y=0; y < h2; ++y ) |
||
993 | { |
||
994 | p = (uint *)image.scanLine( y ); |
||
995 | f.readBlock(imgc.data(), w2); |
||
996 | for (int x=0; x < w2; x += 4 ) |
||
997 | { |
||
998 | cyan = uchar(imgc[x]); |
||
999 | magenta = uchar(imgc[x + 1]); |
||
1000 | yellow = uchar(imgc[x + 2]); |
||
1001 | black = uchar(imgc[x + 3]); |
||
1002 | if (!EnableCMYK_C->isChecked()) |
||
1003 | cyan = 0; |
||
1004 | if (!EnableCMYK_M->isChecked()) |
||
1005 | magenta = 0; |
||
1006 | if (!EnableCMYK_Y->isChecked()) |
||
1007 | yellow = 0; |
||
1008 | if (!EnableCMYK_K->isChecked()) |
||
1009 | black = 0; |
||
1010 | if (AliasTr->isChecked() && ((cyan == 0) && (magenta == 0) && (yellow == 0 ) && (black == 0))) |
||
1011 | alpha = 0; |
||
1012 | else |
||
1013 | alpha = 255; |
||
1014 | *p = qRgba(255-QMIN(255, cyan+black), 255-QMIN(255,magenta+black), 255-QMIN(255,yellow+black), alpha); |
||
1015 | p++; |
||
1016 | } |
||
1017 | } |
||
1018 | } |
||
3169 | fschmid | 1019 | f.close(); |
1020 | } |
||
6392 | fschmid | 1021 | else |
1022 | { |
||
6394 | cbradney | 1023 | imageLoadError(Bild, Seite); |
6392 | fschmid | 1024 | return Bild; |
1025 | } |
||
3169 | fschmid | 1026 | } |
3165 | fschmid | 1027 | } |
1028 | else |
||
1029 | { |
||
6392 | fschmid | 1030 | if (!image.load(ScPaths::getTempFileDir()+"/sc.png")) |
1031 | { |
||
6394 | cbradney | 1032 | imageLoadError(Bild, Seite); |
6392 | fschmid | 1033 | return Bild; |
1034 | } |
||
3165 | fschmid | 1035 | image = image.convertDepth(32); |
3167 | fschmid | 1036 | if ((AliasTr->isChecked()) && (HavePngAlpha == 0)) |
3165 | fschmid | 1037 | { |
1038 | int wi = image.width(); |
||
1039 | int hi = image.height(); |
||
1040 | for( int yi=0; yi < hi; ++yi ) |
||
1041 | { |
||
1042 | QRgb *s = (QRgb*)(image.scanLine( yi )); |
||
1043 | for(int xi=0; xi < wi; ++xi ) |
||
1044 | { |
||
1045 | if((*s) == 0xffffffff) |
||
1046 | (*s) &= 0x00ffffff; |
||
1047 | s++; |
||
1048 | } |
||
1049 | } |
||
1050 | } |
||
1051 | } |
||
1052 | image.setAlphaBuffer(true); |
||
1053 | if (AliasTr->isChecked()) |
||
1054 | { |
||
1055 | Bild = QPixmap(image.width(), image.height()); |
||
1056 | QPainter p; |
||
1057 | QBrush b(QColor(205,205,205), loadIcon("testfill.png")); |
||
1058 | p.begin(&Bild); |
||
1059 | p.fillRect(0, 0, image.width(), image.height(), b); |
||
1060 | p.drawImage(0, 0, image); |
||
1061 | p.end(); |
||
1062 | } |
||
1063 | else |
||
1064 | Bild.convertFromImage(image); |
||
1065 | qApp->setOverrideCursor(QCursor(arrowCursor), true); |
||
6394 | cbradney | 1066 | getUserSelection(Seite); |
3165 | fschmid | 1067 | return Bild; |
1068 | } |
||
1069 | |||
4361 | cbradney | 1070 | //------------------------------------------------------------------------------------------------- |
1071 | |||
1072 | bool PPreview::usePostscriptPreview(QString printerName) |
||
1073 | { |
||
1074 | #ifdef _WIN32 |
||
1075 | if ( printerName == tr("File") ) |
||
1076 | return true; |
||
1077 | else if( printerName.isEmpty() ) |
||
4506 | cbradney | 1078 | return PrinterUtil::isPostscriptPrinter( ScWinPrint::getDefaultPrinter() ); |
4361 | cbradney | 1079 | else |
4506 | cbradney | 1080 | return PrinterUtil::isPostscriptPrinter( printerName ); |
4361 | cbradney | 1081 | #else |
1082 | return true; |
||
1083 | #endif |
||
1084 | } |
||
1085 | |||
1086 | //------------------------------------------------------------------------------------------------- |
||
1087 | |||
6394 | cbradney | 1088 | void PPreview::getUserSelection(int page) |
6393 | cbradney | 1089 | { |
6394 | cbradney | 1090 | APage = page; |
6393 | cbradney | 1091 | CMode = EnableCMYK->isChecked(); |
1092 | GsAl = AntiAlias->isChecked(); |
||
1093 | Trans = AliasTr->isChecked(); |
||
1094 | GMode = EnableGCR->isChecked(); |
||
1095 | SMode = scaleBox->currentItem(); |
||
1096 | OMode = EnableOverprint->isChecked(); |
||
6690 | fschmid | 1097 | mHor = MirrorHor->isChecked(); |
1098 | mVer = MirrorVert->isChecked(); |
||
1099 | fClip = ClipMarg->isChecked(); |
||
1100 | fSpot = spotColors->isChecked(); |
||
1101 | fGray = useGray->isChecked(); |
||
1102 | fICC = UseICC->isChecked(); |
||
6393 | cbradney | 1103 | } |
1104 | |||
6394 | cbradney | 1105 | void PPreview::imageLoadError(QPixmap &Bild, int page) |
6393 | cbradney | 1106 | { |
1107 | Bild.resize(1,1); |
||
1108 | qApp->setOverrideCursor(QCursor(arrowCursor), true); |
||
6394 | cbradney | 1109 | getUserSelection(page); |
1110 | } |