kernel/qprintengine_pdf.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17 -
18extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size); -
19 -
20 -
21 -
22 -
23static const char * const psToStr[QPrinter::NPageSize+1] = -
24{ -
25 "A4", "B5", "Letter", "Legal", "Executive", -
26 "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1", -
27 "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E", -
28 "DLE", "Folio", "Ledger", "Tabloid", 0 -
29}; -
30 -
31QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize) -
32{ -
33 QSizeF s = qt_paperSizeToQSizeF(paperSize); -
34 PaperSize p = { int((s.width() * 720 + 127) / 254), int((s.height() * 720 + 127) / 254) }; -
35 return p;
executed: return p;
Execution Count:31
31
36} -
37 -
38const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize) -
39{ -
40 return psToStr[paperSize];
never executed: return psToStr[paperSize];
0
41} -
42 -
43 -
44QPdfPrintEngine::QPdfPrintEngine(QPrinter::PrinterMode m) -
45 : QPdfEngine(*new QPdfPrintEnginePrivate(m)) -
46{ -
47 state = QPrinter::Idle; -
48}
executed: }
Execution Count:117
117
49 -
50QPdfPrintEngine::QPdfPrintEngine(QPdfPrintEnginePrivate &p) -
51 : QPdfEngine(p) -
52{ -
53 state = QPrinter::Idle; -
54}
executed: }
Execution Count:117
117
55 -
56QPdfPrintEngine::~QPdfPrintEngine() -
57{ -
58} -
59 -
60bool QPdfPrintEngine::begin(QPaintDevice *pdev) -
61{ -
62 QPdfPrintEnginePrivate * const d = d_func(); -
63 -
64 if (!d->openPrintDevice()) {
evaluated: !d->openPrintDevice()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:20
1-20
65 state = QPrinter::Error; -
66 return false;
executed: return false;
Execution Count:1
1
67 } -
68 state = QPrinter::Active; -
69 -
70 return QPdfEngine::begin(pdev);
executed: return QPdfEngine::begin(pdev);
Execution Count:20
20
71} -
72 -
73bool QPdfPrintEngine::end() -
74{ -
75 QPdfPrintEnginePrivate * const d = d_func(); -
76 -
77 QPdfEngine::end(); -
78 -
79 d->closePrintDevice(); -
80 state = QPrinter::Idle; -
81 -
82 return true;
executed: return true;
Execution Count:20
20
83} -
84 -
85bool QPdfPrintEngine::newPage() -
86{ -
87 return QPdfEngine::newPage();
never executed: return QPdfEngine::newPage();
0
88} -
89 -
90int QPdfPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const -
91{ -
92 return QPdfEngine::metric(m);
executed: return QPdfEngine::metric(m);
Execution Count:150
150
93} -
94 -
95void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) -
96{ -
97 QPdfPrintEnginePrivate * const d = d_func(); -
98 -
99 switch (int(key)) { -
100 case PPK_CollateCopies: -
101 d->collate = value.toBool(); -
102 break;
executed: break;
Execution Count:5
5
103 case PPK_ColorMode: -
104 d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); -
105 break;
executed: break;
Execution Count:5
5
106 case PPK_Creator: -
107 d->creator = value.toString(); -
108 break;
executed: break;
Execution Count:4
4
109 case PPK_DocumentName: -
110 d->title = value.toString(); -
111 break;
executed: break;
Execution Count:5
5
112 case PPK_FullPage: -
113 d->fullPage = value.toBool(); -
114 break;
executed: break;
Execution Count:22
22
115 case PPK_CopyCount: -
116 case PPK_NumberOfCopies: -
117 d->copies = value.toInt(); -
118 break;
executed: break;
Execution Count:1
1
119 case PPK_Orientation: -
120 d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape); -
121 break;
executed: break;
Execution Count:46
46
122 case PPK_OutputFileName: -
123 d->outputFileName = value.toString(); -
124 break;
executed: break;
Execution Count:42
42
125 case PPK_PageOrder: -
126 d->pageOrder = QPrinter::PageOrder(value.toInt()); -
127 break;
executed: break;
Execution Count:5
5
128 case PPK_PaperSize: -
129 d->printerPaperSize = QPrinter::PaperSize(value.toInt()); -
130 d->updatePaperSize(); -
131 break;
executed: break;
Execution Count:31
31
132 case PPK_PaperSource: -
133 d->paperSource = QPrinter::PaperSource(value.toInt()); -
134 break;
executed: break;
Execution Count:5
5
135 case PPK_PrinterName: -
136 d->printerName = value.toString(); -
137 break;
executed: break;
Execution Count:7
7
138 case PPK_PrinterProgram: -
139 d->printProgram = value.toString(); -
140 break;
executed: break;
Execution Count:4
4
141 case PPK_Resolution: -
142 d->resolution = value.toInt(); -
143 break;
executed: break;
Execution Count:27
27
144 case PPK_SelectionOption: -
145 d->selectionOption = value.toString(); -
146 break;
executed: break;
Execution Count:4
4
147 case PPK_FontEmbedding: -
148 d->embedFonts = value.toBool(); -
149 break;
executed: break;
Execution Count:5
5
150 case PPK_Duplex: -
151 d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt()); -
152 break;
executed: break;
Execution Count:5
5
153 case PPK_CustomPaperSize: -
154 d->printerPaperSize = QPrinter::Custom; -
155 d->customPaperSize = value.toSizeF(); -
156 d->updatePaperSize(); -
157 break;
executed: break;
Execution Count:7
7
158 case PPK_PageMargins: -
159 { -
160 QList<QVariant> margins(value.toList()); -
161 qt_noop(); -
162 d->leftMargin = margins.at(0).toReal(); -
163 d->topMargin = margins.at(1).toReal(); -
164 d->rightMargin = margins.at(2).toReal(); -
165 d->bottomMargin = margins.at(3).toReal(); -
166 d->pageMarginsSet = true; -
167 break;
executed: break;
Execution Count:10
10
168 } -
169 default: -
170 break;
never executed: break;
0
171 } -
172}
executed: }
Execution Count:240
240
173 -
174QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const -
175{ -
176 const QPdfPrintEnginePrivate * const d = d_func(); -
177 -
178 QVariant ret; -
179 switch (int(key)) { -
180 case PPK_CollateCopies: -
181 ret = d->collate; -
182 break;
executed: break;
Execution Count:12
12
183 case PPK_ColorMode: -
184 ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color;
evaluated: d->grayscale
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:7
5-7
185 break;
executed: break;
Execution Count:12
12
186 case PPK_Creator: -
187 ret = d->creator; -
188 break;
executed: break;
Execution Count:7
7
189 case PPK_DocumentName: -
190 ret = d->title; -
191 break;
executed: break;
Execution Count:10
10
192 case PPK_FullPage: -
193 ret = d->fullPage; -
194 break;
executed: break;
Execution Count:8
8
195 case PPK_CopyCount: -
196 ret = d->copies; -
197 break;
executed: break;
Execution Count:5
5
198 case PPK_SupportsMultipleCopies: -
199 ret = false; -
200 break;
never executed: break;
0
201 case PPK_NumberOfCopies: -
202 ret = d->copies; -
203 break;
never executed: break;
0
204 case PPK_Orientation: -
205 ret = d->landscape ? QPrinter::Landscape : QPrinter::Portrait;
evaluated: d->landscape
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:27
27-29
206 break;
executed: break;
Execution Count:56
56
207 case PPK_OutputFileName: -
208 ret = d->outputFileName; -
209 break;
executed: break;
Execution Count:10
10
210 case PPK_PageOrder: -
211 ret = d->pageOrder; -
212 break;
executed: break;
Execution Count:12
12
213 case PPK_PaperSize: -
214 ret = d->printerPaperSize; -
215 break;
executed: break;
Execution Count:22
22
216 case PPK_PaperSource: -
217 ret = d->paperSource; -
218 break;
executed: break;
Execution Count:8
8
219 case PPK_PrinterName: -
220 ret = d->printerName; -
221 break;
executed: break;
Execution Count:14
14
222 case PPK_PrinterProgram: -
223 ret = d->printProgram; -
224 break;
executed: break;
Execution Count:7
7
225 case PPK_Resolution: -
226 ret = d->resolution; -
227 break;
executed: break;
Execution Count:165
165
228 case PPK_SupportedResolutions: -
229 ret = QList<QVariant>() << 72; -
230 break;
never executed: break;
0
231 case PPK_PaperRect: -
232 ret = d->paperRect(); -
233 break;
executed: break;
Execution Count:78
78
234 case PPK_PageRect: -
235 ret = d->pageRect(); -
236 break;
executed: break;
Execution Count:24
24
237 case PPK_SelectionOption: -
238 ret = d->selectionOption; -
239 break;
executed: break;
Execution Count:7
7
240 case PPK_FontEmbedding: -
241 ret = d->embedFonts; -
242 break;
executed: break;
Execution Count:8
8
243 case PPK_Duplex: -
244 ret = d->duplex; -
245 break;
executed: break;
Execution Count:12
12
246 case PPK_CustomPaperSize: -
247 ret = d->customPaperSize; -
248 break;
executed: break;
Execution Count:4
4
249 case PPK_PageMargins: -
250 { -
251 QList<QVariant> margins; -
252 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
253 margins << 0 << 0 << 0 << 0;
executed: margins << 0 << 0 << 0 << 0;
Execution Count:2
2
254 else -
255 margins << d->leftMargin << d->topMargin 40
256 << d->rightMargin << d->bottomMargin;
executed: margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin;
Execution Count:40
40
257 ret = margins; -
258 break;
executed: break;
Execution Count:42
42
259 } -
260 default: -
261 break;
never executed: break;
0
262 } -
263 return ret;
executed: return ret;
Execution Count:523
523
264} -
265 -
266 -
267bool QPdfPrintEnginePrivate::openPrintDevice() -
268{ -
269 if (outDevice)
partially evaluated: outDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
270 return false;
never executed: return false;
0
271 -
272 if (!outputFileName.isEmpty()) {
partially evaluated: !outputFileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:21
no
Evaluation Count:0
0-21
273 QFile *file = new QFile(outputFileName); -
274 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
275 delete file; -
276 return false;
executed: return false;
Execution Count:1
1
277 } -
278 outDevice = file; -
279 }
executed: }
Execution Count:20
20
280 -
281 return true;
executed: return true;
Execution Count:20
20
282} -
283 -
284void QPdfPrintEnginePrivate::closePrintDevice() -
285{ -
286 if (outDevice) {
partially evaluated: outDevice
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
0-20
287 outDevice->close(); -
288 if (fd >= 0)
partially evaluated: fd >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:20
0-20
289 -
290 -
291 -
292 ::close(fd);
never executed: ::close(fd);
0
293 -
294 fd = -1; -
295 delete outDevice; -
296 outDevice = 0; -
297 }
executed: }
Execution Count:20
20
298}
executed: }
Execution Count:20
20
299 -
300 -
301 -
302QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m) -
303 : QPdfEnginePrivate(), -
304 duplex(QPrinter::DuplexNone), -
305 collate(false), -
306 copies(1), -
307 pageOrder(QPrinter::FirstPageFirst), -
308 paperSource(QPrinter::Auto), -
309 printerPaperSize(QPrinter::A4), -
310 pageMarginsSet(false), -
311 fd(-1) -
312{ -
313 resolution = 72; -
314 if (m == QPrinter::HighResolution)
evaluated: m == QPrinter::HighResolution
TRUEFALSE
yes
Evaluation Count:56
yes
Evaluation Count:178
56-178
315 resolution = 1200;
executed: resolution = 1200;
Execution Count:56
56
316 else if (m == QPrinter::ScreenResolution)
evaluated: m == QPrinter::ScreenResolution
TRUEFALSE
yes
Evaluation Count:172
yes
Evaluation Count:6
6-172
317 resolution = qt_defaultDpi();
executed: resolution = qt_defaultDpi();
Execution Count:172
172
318} -
319 -
320QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate() -
321{ -
322} -
323 -
324 -
325void QPdfPrintEnginePrivate::updatePaperSize() -
326{ -
327 if (printerPaperSize == QPrinter::Custom) {
evaluated: printerPaperSize == QPrinter::Custom
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:31
7-31
328 paperSize = customPaperSize; -
329 } else {
executed: }
Execution Count:7
7
330 QPdf::PaperSize s = QPdf::paperSize(printerPaperSize); -
331 paperSize = QSize(s.width, s.height); -
332 }
executed: }
Execution Count:31
31
333} -
334 -
335 -
336 -
337 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial