kernel/qprintengine_pdf.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qprintengine_pdf_p.h" -
43 -
44#ifndef QT_NO_PRINTER -
45 -
46#include <qiodevice.h> -
47#include <qfile.h> -
48#include <qdebug.h> -
49#include <qbuffer.h> -
50#include "qprinterinfo.h" -
51 -
52#include <limits.h> -
53#include <math.h> -
54 -
55 -
56#ifdef Q_OS_UNIX -
57#include "private/qcore_unix_p.h" // overrides QT_OPEN -
58#endif -
59 -
60#ifdef Q_OS_WIN -
61#include <io.h> // _close. -
62#endif -
63 -
64QT_BEGIN_NAMESPACE -
65 -
66//#define FONT_DUMP -
67 -
68extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size); -
69 -
70#define Q_MM(n) int((n * 720 + 127) / 254) -
71#define Q_IN(n) int(n * 72) -
72 -
73static const char * const psToStr[QPrinter::NPageSize+1] = -
74{ -
75 "A4", "B5", "Letter", "Legal", "Executive", -
76 "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1", -
77 "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E", -
78 "DLE", "Folio", "Ledger", "Tabloid", 0 -
79}; -
80 -
81QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize) -
82{ -
83 QSizeF s = qt_paperSizeToQSizeF(paperSize);
executed (the execution status of this line is deduced): QSizeF s = qt_paperSizeToQSizeF(paperSize);
-
84 PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) };
executed (the execution status of this line is deduced): PaperSize p = { int((s.width() * 720 + 127) / 254), int((s.height() * 720 + 127) / 254) };
-
85 return p;
executed: return p;
Execution Count:31
31
86} -
87 -
88const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize) -
89{ -
90 return psToStr[paperSize];
never executed: return psToStr[paperSize];
0
91} -
92 -
93 -
94QPdfPrintEngine::QPdfPrintEngine(QPrinter::PrinterMode m) -
95 : QPdfEngine(*new QPdfPrintEnginePrivate(m)) -
96{ -
97 state = QPrinter::Idle;
executed (the execution status of this line is deduced): state = QPrinter::Idle;
-
98}
executed: }
Execution Count:117
117
99 -
100QPdfPrintEngine::QPdfPrintEngine(QPdfPrintEnginePrivate &p) -
101 : QPdfEngine(p) -
102{ -
103 state = QPrinter::Idle;
executed (the execution status of this line is deduced): state = QPrinter::Idle;
-
104}
executed: }
Execution Count:117
117
105 -
106QPdfPrintEngine::~QPdfPrintEngine() -
107{ -
108} -
109 -
110bool QPdfPrintEngine::begin(QPaintDevice *pdev) -
111{ -
112 Q_D(QPdfPrintEngine);
executed (the execution status of this line is deduced): QPdfPrintEnginePrivate * const d = d_func();
-
113 -
114 if (!d->openPrintDevice()) {
evaluated: !d->openPrintDevice()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:20
1-20
115 state = QPrinter::Error;
executed (the execution status of this line is deduced): state = QPrinter::Error;
-
116 return false;
executed: return false;
Execution Count:1
1
117 } -
118 state = QPrinter::Active;
executed (the execution status of this line is deduced): state = QPrinter::Active;
-
119 -
120 return QPdfEngine::begin(pdev);
executed: return QPdfEngine::begin(pdev);
Execution Count:20
20
121} -
122 -
123bool QPdfPrintEngine::end() -
124{ -
125 Q_D(QPdfPrintEngine);
executed (the execution status of this line is deduced): QPdfPrintEnginePrivate * const d = d_func();
-
126 -
127 QPdfEngine::end();
executed (the execution status of this line is deduced): QPdfEngine::end();
-
128 -
129 d->closePrintDevice();
executed (the execution status of this line is deduced): d->closePrintDevice();
-
130 state = QPrinter::Idle;
executed (the execution status of this line is deduced): state = QPrinter::Idle;
-
131 -
132 return true;
executed: return true;
Execution Count:20
20
133} -
134 -
135bool QPdfPrintEngine::newPage() -
136{ -
137 return QPdfEngine::newPage();
never executed: return QPdfEngine::newPage();
0
138} -
139 -
140int QPdfPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const -
141{ -
142 return QPdfEngine::metric(m);
executed: return QPdfEngine::metric(m);
Execution Count:150
150
143} -
144 -
145void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) -
146{ -
147 Q_D(QPdfPrintEngine);
executed (the execution status of this line is deduced): QPdfPrintEnginePrivate * const d = d_func();
-
148 -
149 switch (int(key)) { -
150 case PPK_CollateCopies: -
151 d->collate = value.toBool();
executed (the execution status of this line is deduced): d->collate = value.toBool();
-
152 break;
executed: break;
Execution Count:5
5
153 case PPK_ColorMode: -
154 d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
executed (the execution status of this line is deduced): d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
-
155 break;
executed: break;
Execution Count:5
5
156 case PPK_Creator: -
157 d->creator = value.toString();
executed (the execution status of this line is deduced): d->creator = value.toString();
-
158 break;
executed: break;
Execution Count:4
4
159 case PPK_DocumentName: -
160 d->title = value.toString();
executed (the execution status of this line is deduced): d->title = value.toString();
-
161 break;
executed: break;
Execution Count:5
5
162 case PPK_FullPage: -
163 d->fullPage = value.toBool();
executed (the execution status of this line is deduced): d->fullPage = value.toBool();
-
164 break;
executed: break;
Execution Count:22
22
165 case PPK_CopyCount: // fallthrough -
166 case PPK_NumberOfCopies: -
167 d->copies = value.toInt();
executed (the execution status of this line is deduced): d->copies = value.toInt();
-
168 break;
executed: break;
Execution Count:1
1
169 case PPK_Orientation: -
170 d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape);
executed (the execution status of this line is deduced): d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape);
-
171 break;
executed: break;
Execution Count:46
46
172 case PPK_OutputFileName: -
173 d->outputFileName = value.toString();
executed (the execution status of this line is deduced): d->outputFileName = value.toString();
-
174 break;
executed: break;
Execution Count:42
42
175 case PPK_PageOrder: -
176 d->pageOrder = QPrinter::PageOrder(value.toInt());
executed (the execution status of this line is deduced): d->pageOrder = QPrinter::PageOrder(value.toInt());
-
177 break;
executed: break;
Execution Count:5
5
178 case PPK_PaperSize: -
179 d->printerPaperSize = QPrinter::PaperSize(value.toInt());
executed (the execution status of this line is deduced): d->printerPaperSize = QPrinter::PaperSize(value.toInt());
-
180 d->updatePaperSize();
executed (the execution status of this line is deduced): d->updatePaperSize();
-
181 break;
executed: break;
Execution Count:31
31
182 case PPK_PaperSource: -
183 d->paperSource = QPrinter::PaperSource(value.toInt());
executed (the execution status of this line is deduced): d->paperSource = QPrinter::PaperSource(value.toInt());
-
184 break;
executed: break;
Execution Count:5
5
185 case PPK_PrinterName: -
186 d->printerName = value.toString();
executed (the execution status of this line is deduced): d->printerName = value.toString();
-
187 break;
executed: break;
Execution Count:7
7
188 case PPK_PrinterProgram: -
189 d->printProgram = value.toString();
executed (the execution status of this line is deduced): d->printProgram = value.toString();
-
190 break;
executed: break;
Execution Count:4
4
191 case PPK_Resolution: -
192 d->resolution = value.toInt();
executed (the execution status of this line is deduced): d->resolution = value.toInt();
-
193 break;
executed: break;
Execution Count:27
27
194 case PPK_SelectionOption: -
195 d->selectionOption = value.toString();
executed (the execution status of this line is deduced): d->selectionOption = value.toString();
-
196 break;
executed: break;
Execution Count:4
4
197 case PPK_FontEmbedding: -
198 d->embedFonts = value.toBool();
executed (the execution status of this line is deduced): d->embedFonts = value.toBool();
-
199 break;
executed: break;
Execution Count:5
5
200 case PPK_Duplex: -
201 d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt());
executed (the execution status of this line is deduced): d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt());
-
202 break;
executed: break;
Execution Count:5
5
203 case PPK_CustomPaperSize: -
204 d->printerPaperSize = QPrinter::Custom;
executed (the execution status of this line is deduced): d->printerPaperSize = QPrinter::Custom;
-
205 d->customPaperSize = value.toSizeF();
executed (the execution status of this line is deduced): d->customPaperSize = value.toSizeF();
-
206 d->updatePaperSize();
executed (the execution status of this line is deduced): d->updatePaperSize();
-
207 break;
executed: break;
Execution Count:7
7
208 case PPK_PageMargins: -
209 { -
210 QList<QVariant> margins(value.toList());
executed (the execution status of this line is deduced): QList<QVariant> margins(value.toList());
-
211 Q_ASSERT(margins.size() == 4);
executed (the execution status of this line is deduced): qt_noop();
-
212 d->leftMargin = margins.at(0).toReal();
executed (the execution status of this line is deduced): d->leftMargin = margins.at(0).toReal();
-
213 d->topMargin = margins.at(1).toReal();
executed (the execution status of this line is deduced): d->topMargin = margins.at(1).toReal();
-
214 d->rightMargin = margins.at(2).toReal();
executed (the execution status of this line is deduced): d->rightMargin = margins.at(2).toReal();
-
215 d->bottomMargin = margins.at(3).toReal();
executed (the execution status of this line is deduced): d->bottomMargin = margins.at(3).toReal();
-
216 d->pageMarginsSet = true;
executed (the execution status of this line is deduced): d->pageMarginsSet = true;
-
217 break;
executed: break;
Execution Count:10
10
218 } -
219 default: -
220 break;
never executed: break;
0
221 } -
222}
executed: }
Execution Count:240
240
223 -
224QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const -
225{ -
226 Q_D(const QPdfPrintEngine);
executed (the execution status of this line is deduced): const QPdfPrintEnginePrivate * const d = d_func();
-
227 -
228 QVariant ret;
executed (the execution status of this line is deduced): QVariant ret;
-
229 switch (int(key)) { -
230 case PPK_CollateCopies: -
231 ret = d->collate;
executed (the execution status of this line is deduced): ret = d->collate;
-
232 break;
executed: break;
Execution Count:12
12
233 case PPK_ColorMode: -
234 ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color;
evaluated: d->grayscale
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:7
5-7
235 break;
executed: break;
Execution Count:12
12
236 case PPK_Creator: -
237 ret = d->creator;
executed (the execution status of this line is deduced): ret = d->creator;
-
238 break;
executed: break;
Execution Count:7
7
239 case PPK_DocumentName: -
240 ret = d->title;
executed (the execution status of this line is deduced): ret = d->title;
-
241 break;
executed: break;
Execution Count:10
10
242 case PPK_FullPage: -
243 ret = d->fullPage;
executed (the execution status of this line is deduced): ret = d->fullPage;
-
244 break;
executed: break;
Execution Count:8
8
245 case PPK_CopyCount: -
246 ret = d->copies;
executed (the execution status of this line is deduced): ret = d->copies;
-
247 break;
executed: break;
Execution Count:5
5
248 case PPK_SupportsMultipleCopies: -
249 ret = false;
never executed (the execution status of this line is deduced): ret = false;
-
250 break;
never executed: break;
0
251 case PPK_NumberOfCopies: -
252 ret = d->copies;
never executed (the execution status of this line is deduced): ret = d->copies;
-
253 break;
never executed: break;
0
254 case PPK_Orientation: -
255 ret = d->landscape ? QPrinter::Landscape : QPrinter::Portrait;
evaluated: d->landscape
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:27
27-29
256 break;
executed: break;
Execution Count:56
56
257 case PPK_OutputFileName: -
258 ret = d->outputFileName;
executed (the execution status of this line is deduced): ret = d->outputFileName;
-
259 break;
executed: break;
Execution Count:10
10
260 case PPK_PageOrder: -
261 ret = d->pageOrder;
executed (the execution status of this line is deduced): ret = d->pageOrder;
-
262 break;
executed: break;
Execution Count:12
12
263 case PPK_PaperSize: -
264 ret = d->printerPaperSize;
executed (the execution status of this line is deduced): ret = d->printerPaperSize;
-
265 break;
executed: break;
Execution Count:22
22
266 case PPK_PaperSource: -
267 ret = d->paperSource;
executed (the execution status of this line is deduced): ret = d->paperSource;
-
268 break;
executed: break;
Execution Count:8
8
269 case PPK_PrinterName: -
270 ret = d->printerName;
executed (the execution status of this line is deduced): ret = d->printerName;
-
271 break;
executed: break;
Execution Count:14
14
272 case PPK_PrinterProgram: -
273 ret = d->printProgram;
executed (the execution status of this line is deduced): ret = d->printProgram;
-
274 break;
executed: break;
Execution Count:7
7
275 case PPK_Resolution: -
276 ret = d->resolution;
executed (the execution status of this line is deduced): ret = d->resolution;
-
277 break;
executed: break;
Execution Count:165
165
278 case PPK_SupportedResolutions: -
279 ret = QList<QVariant>() << 72;
never executed (the execution status of this line is deduced): ret = QList<QVariant>() << 72;
-
280 break;
never executed: break;
0
281 case PPK_PaperRect: -
282 ret = d->paperRect();
executed (the execution status of this line is deduced): ret = d->paperRect();
-
283 break;
executed: break;
Execution Count:78
78
284 case PPK_PageRect: -
285 ret = d->pageRect();
executed (the execution status of this line is deduced): ret = d->pageRect();
-
286 break;
executed: break;
Execution Count:24
24
287 case PPK_SelectionOption: -
288 ret = d->selectionOption;
executed (the execution status of this line is deduced): ret = d->selectionOption;
-
289 break;
executed: break;
Execution Count:7
7
290 case PPK_FontEmbedding: -
291 ret = d->embedFonts;
executed (the execution status of this line is deduced): ret = d->embedFonts;
-
292 break;
executed: break;
Execution Count:8
8
293 case PPK_Duplex: -
294 ret = d->duplex;
executed (the execution status of this line is deduced): ret = d->duplex;
-
295 break;
executed: break;
Execution Count:12
12
296 case PPK_CustomPaperSize: -
297 ret = d->customPaperSize;
executed (the execution status of this line is deduced): ret = d->customPaperSize;
-
298 break;
executed: break;
Execution Count:4
4
299 case PPK_PageMargins: -
300 { -
301 QList<QVariant> margins;
executed (the execution status of this line is deduced): QList<QVariant> margins;
-
302 if (d->printerPaperSize == QPrinter::Custom && !d->pageMarginsSet)
evaluated: d->printerPaperSize == QPrinter::Custom
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:36
evaluated: !d->pageMarginsSet
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
2-36
303 margins << 0 << 0 << 0 << 0;
executed: margins << 0 << 0 << 0 << 0;
Execution Count:2
2
304 else -
305 margins << d->leftMargin << d->topMargin
executed: margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin;
Execution Count:40
40
306 << d->rightMargin << d->bottomMargin;
executed: margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin;
Execution Count:40
40
307 ret = margins;
executed (the execution status of this line is deduced): ret = margins;
-
308 break;
executed: break;
Execution Count:42
42
309 } -
310 default: -
311 break;
never executed: break;
0
312 } -
313 return ret;
executed: return ret;
Execution Count:523
523
314} -
315 -
316 -
317bool QPdfPrintEnginePrivate::openPrintDevice() -
318{ -
319 if (outDevice)
partially evaluated: outDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
320 return false;
never executed: return false;
0
321 -
322 if (!outputFileName.isEmpty()) {
partially evaluated: !outputFileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:21
no
Evaluation Count:0
0-21
323 QFile *file = new QFile(outputFileName);
executed (the execution status of this line is deduced): QFile *file = new QFile(outputFileName);
-
324 if (! file->open(QFile::WriteOnly|QFile::Truncate)) {
evaluated: ! file->open(QFile::WriteOnly|QFile::Truncate)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:20
1-20
325 delete file;
executed (the execution status of this line is deduced): delete file;
-
326 return false;
executed: return false;
Execution Count:1
1
327 } -
328 outDevice = file;
executed (the execution status of this line is deduced): outDevice = file;
-
329 }
executed: }
Execution Count:20
20
330 -
331 return true;
executed: return true;
Execution Count:20
20
332} -
333 -
334void QPdfPrintEnginePrivate::closePrintDevice() -
335{ -
336 if (outDevice) {
partially evaluated: outDevice
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
0-20
337 outDevice->close();
executed (the execution status of this line is deduced): outDevice->close();
-
338 if (fd >= 0)
partially evaluated: fd >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:20
0-20
339 #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400 -
340 ::_close(fd); -
341 #else -
342 ::close(fd);
never executed: ::close(fd);
0
343 #endif -
344 fd = -1;
executed (the execution status of this line is deduced): fd = -1;
-
345 delete outDevice;
executed (the execution status of this line is deduced): delete outDevice;
-
346 outDevice = 0;
executed (the execution status of this line is deduced): outDevice = 0;
-
347 }
executed: }
Execution Count:20
20
348}
executed: }
Execution Count:20
20
349 -
350 -
351 -
352QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m) -
353 : QPdfEnginePrivate(), -
354 duplex(QPrinter::DuplexNone), -
355 collate(false), -
356 copies(1), -
357 pageOrder(QPrinter::FirstPageFirst), -
358 paperSource(QPrinter::Auto), -
359 printerPaperSize(QPrinter::A4), -
360 pageMarginsSet(false), -
361 fd(-1) -
362{ -
363 resolution = 72;
executed (the execution status of this line is deduced): resolution = 72;
-
364 if (m == QPrinter::HighResolution)
evaluated: m == QPrinter::HighResolution
TRUEFALSE
yes
Evaluation Count:56
yes
Evaluation Count:178
56-178
365 resolution = 1200;
executed: resolution = 1200;
Execution Count:56
56
366 else if (m == QPrinter::ScreenResolution)
evaluated: m == QPrinter::ScreenResolution
TRUEFALSE
yes
Evaluation Count:172
yes
Evaluation Count:6
6-172
367 resolution = qt_defaultDpi();
executed: resolution = qt_defaultDpi();
Execution Count:172
172
368} -
369 -
370QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate() -
371{ -
372} -
373 -
374 -
375void QPdfPrintEnginePrivate::updatePaperSize() -
376{ -
377 if (printerPaperSize == QPrinter::Custom) {
evaluated: printerPaperSize == QPrinter::Custom
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:31
7-31
378 paperSize = customPaperSize;
executed (the execution status of this line is deduced): paperSize = customPaperSize;
-
379 } else {
executed: }
Execution Count:7
7
380 QPdf::PaperSize s = QPdf::paperSize(printerPaperSize);
executed (the execution status of this line is deduced): QPdf::PaperSize s = QPdf::paperSize(printerPaperSize);
-
381 paperSize = QSize(s.width, s.height);
executed (the execution status of this line is deduced): paperSize = QSize(s.width, s.height);
-
382 }
executed: }
Execution Count:31
31
383} -
384 -
385 -
386QT_END_NAMESPACE -
387 -
388#endif // QT_NO_PRINTER -
389 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial