qpdf.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpdf.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11static const bool do_compress = true;-
12-
13-
14-
15-
16static const bool interpolateImages = false;-
17-
18-
19-
20inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features()-
21{-
22 QPaintEngine::PaintEngineFeatures f = QPaintEngine::AllFeatures;-
23 f &= ~(QPaintEngine::PorterDuff-
24 | QPaintEngine::PerspectiveTransform-
25 | QPaintEngine::ObjectBoundingModeGradients-
26 | QPaintEngine::ConicalGradientFill);-
27 return
never executed: return f;
f;
never executed: return f;
0
28}-
29-
30-
31-
32-
33const char *qt_real_to_string(qreal val, char *buf) {-
34 const char *ret = buf;-
35-
36 if (qIsNaN(val)
qIsNaN(val)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
37 *(buf++) = '0';-
38 *(buf++) = ' ';-
39 *buf = 0;-
40 return
never executed: return ret;
ret;
never executed: return ret;
0
41 }-
42-
43 if (val < 0
val < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
44 *(buf++) = '-';-
45 val = -val;-
46 }
never executed: end of block
0
47 unsigned int ival = (unsigned int) val;-
48 qreal frac = val - (qreal)ival;-
49-
50 int ifrac = (int)(frac * 1000000000);-
51 if (ifrac == 1000000000
ifrac == 1000000000Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
52 ++ival;-
53 ifrac = 0;-
54 }
never executed: end of block
0
55 char output[256];-
56 int i = 0;-
57 while (ival
ivalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
58 output[i] = '0' + (ival % 10);-
59 ++i;-
60 ival /= 10;-
61 }
never executed: end of block
0
62 int fact = 100000000;-
63 if (i == 0
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
64 *(buf++) = '0';-
65 }
never executed: end of block
else {
0
66 while (i
iDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
67 *(buf++) = output[--i];-
68 fact /= 10;-
69 ifrac /= 10;-
70 }
never executed: end of block
0
71 }
never executed: end of block
0
72-
73 if (ifrac
ifracDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
74 *(buf++) = '.';-
75 while (fact
factDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
76 *(buf++) = '0' + ((ifrac/fact) % 10);-
77 fact /= 10;-
78 }
never executed: end of block
0
79 }
never executed: end of block
0
80 *(buf++) = ' ';-
81 *buf = 0;-
82 return
never executed: return ret;
ret;
never executed: return ret;
0
83}-
84-
85const char *qt_int_to_string(int val, char *buf) {-
86 const char *ret = buf;-
87 if (val < 0
val < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
88 *(buf++) = '-';-
89 val = -val;-
90 }
never executed: end of block
0
91 char output[256];-
92 int i = 0;-
93 while (val
valDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 output[i] = '0' + (val % 10);-
95 ++i;-
96 val /= 10;-
97 }
never executed: end of block
0
98 if (i == 0
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
99 *(buf++) = '0';-
100 }
never executed: end of block
else {
0
101 while (i
iDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
102 *(
never executed: *(buf++) = output[--i];
buf++) = output[--i];
never executed: *(buf++) = output[--i];
0
103 }
never executed: end of block
0
104 *(buf++) = ' ';-
105 *buf = 0;-
106 return
never executed: return ret;
ret;
never executed: return ret;
0
107}-
108-
109-
110namespace QPdf {-
111 ByteStream::ByteStream(QByteArray *byteArray, bool fileBacking)-
112 : dev(new QBuffer(byteArray)),-
113 fileBackingEnabled(fileBacking),-
114 fileBackingActive(false),-
115 handleDirty(false)-
116 {-
117 dev->open(QIODevice::ReadWrite | QIODevice::Append);-
118 }
never executed: end of block
0
119-
120 ByteStream::ByteStream(bool fileBacking)-
121 : dev(new QBuffer(&ba)),-
122 fileBackingEnabled(fileBacking),-
123 fileBackingActive(false),-
124 handleDirty(false)-
125 {-
126 dev->open(QIODevice::ReadWrite);-
127 }
never executed: end of block
0
128-
129 ByteStream::~ByteStream()-
130 {-
131 delete dev;-
132 }
never executed: end of block
0
133-
134 ByteStream &ByteStream::operator <<(char chr)-
135 {-
136 if (handleDirty
handleDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
) prepareBuffer();
never executed: prepareBuffer();
0
137 dev->write(&chr, 1);-
138 return
never executed: return *this;
*this;
never executed: return *this;
0
139 }-
140-
141 ByteStream &ByteStream::operator <<(const char *str)-
142 {-
143 if (handleDirty
handleDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
) prepareBuffer();
never executed: prepareBuffer();
0
144 dev->write(str, strlen(str));-
145 return
never executed: return *this;
*this;
never executed: return *this;
0
146 }-
147-
148 ByteStream &ByteStream::operator <<(const QByteArray &str)-
149 {-
150 if (handleDirty
handleDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
) prepareBuffer();
never executed: prepareBuffer();
0
151 dev->write(str);-
152 return
never executed: return *this;
*this;
never executed: return *this;
0
153 }-
154-
155 ByteStream &ByteStream::operator <<(const ByteStream &src)-
156 {-
157 ((!(!src.dev->isSequential())) ? qt_assert("!src.dev->isSequential()",__FILE__,209) : qt_noop());-
158 if (handleDirty
handleDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
) prepareBuffer();
never executed: prepareBuffer();
0
159-
160-
161 ByteStream &s = const_cast<ByteStream&>(src);-
162 qint64 pos = s.dev->pos();-
163 s.dev->reset();-
164 while (!s.dev->atEnd()
!s.dev->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
165 QByteArray buf = s.dev->read(chunkSize());-
166 dev->write(buf);-
167 }
never executed: end of block
0
168 s.dev->seek(pos);-
169 return
never executed: return *this;
*this;
never executed: return *this;
0
170 }-
171-
172 ByteStream &ByteStream::operator <<(qreal val) {-
173 char buf[256];-
174 qt_real_to_string(val, buf);-
175 *this << buf;-
176 return
never executed: return *this;
*this;
never executed: return *this;
0
177 }-
178-
179 ByteStream &ByteStream::operator <<(int val) {-
180 char buf[256];-
181 qt_int_to_string(val, buf);-
182 *this << buf;-
183 return
never executed: return *this;
*this;
never executed: return *this;
0
184 }-
185-
186 ByteStream &ByteStream::operator <<(const QPointF &p) {-
187 char buf[256];-
188 qt_real_to_string(p.x(), buf);-
189 *this << buf;-
190 qt_real_to_string(p.y(), buf);-
191 *this << buf;-
192 return
never executed: return *this;
*this;
never executed: return *this;
0
193 }-
194-
195 QIODevice *ByteStream::stream()-
196 {-
197 dev->reset();-
198 handleDirty = true;-
199 return
never executed: return dev;
dev;
never executed: return dev;
0
200 }-
201-
202 void ByteStream::clear()-
203 {-
204 dev->open(QIODevice::ReadWrite | QIODevice::Truncate);-
205 }
never executed: end of block
0
206-
207 void ByteStream::constructor_helper(QByteArray *ba)-
208 {-
209 delete dev;-
210 dev = new QBuffer(ba);-
211 dev->open(QIODevice::ReadWrite);-
212 }
never executed: end of block
0
213-
214 void ByteStream::prepareBuffer()-
215 {-
216 ((!(!dev->isSequential())) ? qt_assert("!dev->isSequential()",__FILE__,268) : qt_noop());-
217 qint64 size = dev->size();-
218 if (fileBackingEnabled
fileBackingEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& !fileBackingActive
!fileBackingActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 && size > maxMemorySize()
size > maxMemorySize()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
220-
221 QTemporaryFile *newFile = new QTemporaryFile;-
222 newFile->open();-
223 dev->reset();-
224 while (!dev->atEnd()
!dev->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
225 QByteArray buf = dev->read(chunkSize());-
226 newFile->write(buf);-
227 }
never executed: end of block
0
228 delete dev;-
229 dev = newFile;-
230 ba.clear();-
231 fileBackingActive = true;-
232 }
never executed: end of block
0
233 if (dev->pos() != size
dev->pos() != sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
234 dev->seek(size);-
235 handleDirty = false;-
236 }
never executed: end of block
0
237 }
never executed: end of block
0
238}-
239-
240-
241-
242QByteArray QPdf::generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags)-
243{-
244 QByteArray result;-
245 if (!path.elementCount()
!path.elementCount()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
246 return
never executed: return result;
result;
never executed: return result;
0
247-
248 ByteStream s(&result);-
249-
250 int start = -1;-
251 for (int i = 0; i < path.elementCount()
i < path.elementCount()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
252 const QPainterPath::Element &elm = path.elementAt(i);-
253 switch (elm.type) {-
254 case
never executed: case QPainterPath::MoveToElement:
QPainterPath::MoveToElement:
never executed: case QPainterPath::MoveToElement:
0
255 if (start >= 0
start >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
256 && path.elementAt(start).x == path.elementAt(i-1).x
path.elementAt...ementAt(i-1).xDescription
TRUEnever evaluated
FALSEnever evaluated
0
257 && path.elementAt(start).y == path.elementAt(i-1).y
path.elementAt...ementAt(i-1).yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
258 s << "h\n";
never executed: s << "h\n";
0
259 s << matrix.map(QPointF(elm.x, elm.y)) << "m\n";-
260 start = i;-
261 break;
never executed: break;
0
262 case
never executed: case QPainterPath::LineToElement:
QPainterPath::LineToElement:
never executed: case QPainterPath::LineToElement:
0
263 s << matrix.map(QPointF(elm.x, elm.y)) << "l\n";-
264 break;
never executed: break;
0
265 case
never executed: case QPainterPath::CurveToElement:
QPainterPath::CurveToElement:
never executed: case QPainterPath::CurveToElement:
0
266 ((!(path.elementAt(i+1).type == QPainterPath::CurveToDataElement)) ? qt_assert("path.elementAt(i+1).type == QPainterPath::CurveToDataElement",__FILE__,318) : qt_noop());-
267 ((!(path.elementAt(i+2).type == QPainterPath::CurveToDataElement)) ? qt_assert("path.elementAt(i+2).type == QPainterPath::CurveToDataElement",__FILE__,319) : qt_noop());-
268 s << matrix.map(QPointF(elm.x, elm.y))-
269 << matrix.map(QPointF(path.elementAt(i+1).x, path.elementAt(i+1).y))-
270 << matrix.map(QPointF(path.elementAt(i+2).x, path.elementAt(i+2).y))-
271 << "c\n";-
272 i += 2;-
273 break;
never executed: break;
0
274 default
never executed: default:
:
never executed: default:
0
275 QMessageLogger(__FILE__, 327, __PRETTY_FUNCTION__).fatal("QPdf::generatePath(), unhandled type: %d", elm.type);-
276 }
never executed: end of block
0
277 }-
278 if (start >= 0
start >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
279 && path.elementAt(start).x == path.elementAt(path.elementCount()-1).x
path.elementAt...ntCount()-1).xDescription
TRUEnever evaluated
FALSEnever evaluated
0
280 && path.elementAt(start).y == path.elementAt(path.elementCount()-1).y
path.elementAt...ntCount()-1).yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
281 s << "h\n";
never executed: s << "h\n";
0
282-
283 Qt::FillRule fillRule = path.fillRule();-
284-
285 const char *op = "";-
286 switch (flags) {-
287 case
never executed: case ClipPath:
ClipPath:
never executed: case ClipPath:
0
288 op = (
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
fillRule == Qt::WindingFill)
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
? "W n\n" : "W* n\n";
0
289 break;
never executed: break;
0
290 case
never executed: case FillPath:
FillPath:
never executed: case FillPath:
0
291 op = (
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
fillRule == Qt::WindingFill)
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
? "f\n" : "f*\n";
0
292 break;
never executed: break;
0
293 case
never executed: case StrokePath:
StrokePath:
never executed: case StrokePath:
0
294 op = "S\n";-
295 break;
never executed: break;
0
296 case
never executed: case FillAndStrokePath:
FillAndStrokePath:
never executed: case FillAndStrokePath:
0
297 op = (
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
fillRule == Qt::WindingFill)
(fillRule == Qt::WindingFill)Description
TRUEnever evaluated
FALSEnever evaluated
? "B\n" : "B*\n";
0
298 break;
never executed: break;
0
299 }-
300 s << op;-
301 return
never executed: return result;
result;
never executed: return result;
0
302}-
303-
304QByteArray QPdf::generateMatrix(const QTransform &matrix)-
305{-
306 QByteArray result;-
307 ByteStream s(&result);-
308 s << matrix.m11()-
309 << matrix.m12()-
310 << matrix.m21()-
311 << matrix.m22()-
312 << matrix.dx()-
313 << matrix.dy()-
314 << "cm\n";-
315 return
never executed: return result;
result;
never executed: return result;
0
316}-
317-
318QByteArray QPdf::generateDashes(const QPen &pen)-
319{-
320 QByteArray result;-
321 ByteStream s(&result);-
322 s << '[';-
323-
324 QVector<qreal> dasharray = pen.dashPattern();-
325 qreal w = pen.widthF();-
326 if (w < 0.001
w < 0.001Description
TRUEnever evaluated
FALSEnever evaluated
)
0
327 w = 1;
never executed: w = 1;
0
328 for (int i = 0; i < dasharray.size()
i < dasharray.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
329 qreal dw = dasharray.at(i)*w;-
330 if (dw < 0.0001
dw < 0.0001Description
TRUEnever evaluated
FALSEnever evaluated
) dw = 0.0001;
never executed: dw = 0.0001;
0
331 s << dw;-
332 }
never executed: end of block
0
333 s << ']';-
334 s << pen.dashOffset() * w;-
335 s << " d\n";-
336 return
never executed: return result;
result;
never executed: return result;
0
337}-
338-
339-
340-
341static const char* const pattern_for_brush[] = {-
342 0,-
343 0,-
344 "0 J\n"-
345 "6 w\n"-
346 "[] 0 d\n"-
347 "4 0 m\n"-
348 "4 8 l\n"-
349 "0 4 m\n"-
350 "8 4 l\n"-
351 "S\n",-
352-
353 "0 J\n"-
354 "2 w\n"-
355 "[6 2] 1 d\n"-
356 "0 0 m\n"-
357 "0 8 l\n"-
358 "8 0 m\n"-
359 "8 8 l\n"-
360 "S\n"-
361 "[] 0 d\n"-
362 "2 0 m\n"-
363 "2 8 l\n"-
364 "6 0 m\n"-
365 "6 8 l\n"-
366 "S\n"-
367 "[6 2] -3 d\n"-
368 "4 0 m\n"-
369 "4 8 l\n"-
370 "S\n",-
371-
372 "0 J\n"-
373 "2 w\n"-
374 "[6 2] 1 d\n"-
375 "0 0 m\n"-
376 "0 8 l\n"-
377 "8 0 m\n"-
378 "8 8 l\n"-
379 "S\n"-
380 "[2 2] -1 d\n"-
381 "2 0 m\n"-
382 "2 8 l\n"-
383 "6 0 m\n"-
384 "6 8 l\n"-
385 "S\n"-
386 "[6 2] -3 d\n"-
387 "4 0 m\n"-
388 "4 8 l\n"-
389 "S\n",-
390-
391 "0 J\n"-
392 "2 w\n"-
393 "[2 2] 1 d\n"-
394 "0 0 m\n"-
395 "0 8 l\n"-
396 "8 0 m\n"-
397 "8 8 l\n"-
398 "S\n"-
399 "[2 2] -1 d\n"-
400 "2 0 m\n"-
401 "2 8 l\n"-
402 "6 0 m\n"-
403 "6 8 l\n"-
404 "S\n"-
405 "[2 2] 1 d\n"-
406 "4 0 m\n"-
407 "4 8 l\n"-
408 "S\n",-
409-
410 "0 J\n"-
411 "2 w\n"-
412 "[2 6] -1 d\n"-
413 "0 0 m\n"-
414 "0 8 l\n"-
415 "8 0 m\n"-
416 "8 8 l\n"-
417 "S\n"-
418 "[2 2] 1 d\n"-
419 "2 0 m\n"-
420 "2 8 l\n"-
421 "6 0 m\n"-
422 "6 8 l\n"-
423 "S\n"-
424 "[2 6] 3 d\n"-
425 "4 0 m\n"-
426 "4 8 l\n"-
427 "S\n",-
428-
429 "0 J\n"-
430 "2 w\n"-
431 "[2 6] -1 d\n"-
432 "0 0 m\n"-
433 "0 8 l\n"-
434 "8 0 m\n"-
435 "8 8 l\n"-
436 "S\n"-
437 "[2 6] 3 d\n"-
438 "4 0 m\n"-
439 "4 8 l\n"-
440 "S\n",-
441-
442 "0 J\n"-
443 "2 w\n"-
444 "[2 6] -1 d\n"-
445 "0 0 m\n"-
446 "0 8 l\n"-
447 "8 0 m\n"-
448 "8 8 l\n"-
449 "S\n",-
450-
451 "1 w\n"-
452 "0 4 m\n"-
453 "8 4 l\n"-
454 "S\n",-
455-
456 "1 w\n"-
457 "4 0 m\n"-
458 "4 8 l\n"-
459 "S\n",-
460-
461 "1 w\n"-
462 "4 0 m\n"-
463 "4 8 l\n"-
464 "0 4 m\n"-
465 "8 4 l\n"-
466 "S\n",-
467-
468 "1 w\n"-
469 "-1 5 m\n"-
470 "5 -1 l\n"-
471 "3 9 m\n"-
472 "9 3 l\n"-
473 "S\n",-
474-
475 "1 w\n"-
476 "-1 3 m\n"-
477 "5 9 l\n"-
478 "3 -1 m\n"-
479 "9 5 l\n"-
480 "S\n",-
481-
482 "1 w\n"-
483 "-1 3 m\n"-
484 "5 9 l\n"-
485 "3 -1 m\n"-
486 "9 5 l\n"-
487 "-1 5 m\n"-
488 "5 -1 l\n"-
489 "3 9 m\n"-
490 "9 3 l\n"-
491 "S\n",-
492};-
493-
494QByteArray QPdf::patternForBrush(const QBrush &b)-
495{-
496 int style = b.style();-
497 if (style > Qt::DiagCrossPattern
style > Qt::DiagCrossPatternDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
498 return
never executed: return QByteArray();
QByteArray();
never executed: return QByteArray();
0
499 return
never executed: return pattern_for_brush[style];
pattern_for_brush[style];
never executed: return pattern_for_brush[style];
0
500}-
501-
502-
503static void moveToHook(qfixed x, qfixed y, void *data)-
504{-
505 QPdf::Stroker *t = (QPdf::Stroker *)data;-
506 if (!t->first
!t->firstDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
507 *
never executed: *t->stream << "h\n";
t->stream << "h\n";
never executed: *t->stream << "h\n";
0
508 if (!t->cosmeticPen
!t->cosmeticPenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
509 t->matrix.map(x, y, &x, &y);
never executed: t->matrix.map(x, y, &x, &y);
0
510 *t->stream << x << y << "m\n";-
511 t->first = false;-
512}
never executed: end of block
0
513-
514static void lineToHook(qfixed x, qfixed y, void *data)-
515{-
516 QPdf::Stroker *t = (QPdf::Stroker *)data;-
517 if (!t->cosmeticPen
!t->cosmeticPenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
518 t->matrix.map(x, y, &x, &y);
never executed: t->matrix.map(x, y, &x, &y);
0
519 *t->stream << x << y << "l\n";-
520}
never executed: end of block
0
521-
522static void cubicToHook(qfixed c1x, qfixed c1y,-
523 qfixed c2x, qfixed c2y,-
524 qfixed ex, qfixed ey,-
525 void *data)-
526{-
527 QPdf::Stroker *t = (QPdf::Stroker *)data;-
528 if (!t->cosmeticPen
!t->cosmeticPenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
529 t->matrix.map(c1x, c1y, &c1x, &c1y);-
530 t->matrix.map(c2x, c2y, &c2x, &c2y);-
531 t->matrix.map(ex, ey, &ex, &ey);-
532 }
never executed: end of block
0
533 *t->stream << c1x << c1y-
534 << c2x << c2y-
535 << ex << ey-
536 << "c\n";-
537}
never executed: end of block
0
538-
539QPdf::Stroker::Stroker()-
540 : stream(0),-
541 first(true),-
542 dashStroker(&basicStroker)-
543{-
544 stroker = &basicStroker;-
545 basicStroker.setMoveToHook(moveToHook);-
546 basicStroker.setLineToHook(lineToHook);-
547 basicStroker.setCubicToHook(cubicToHook);-
548 cosmeticPen = true;-
549 basicStroker.setStrokeWidth(.1);-
550}
never executed: end of block
0
551-
552void QPdf::Stroker::setPen(const QPen &pen, QPainter::RenderHints hints)-
553{-
554 if (pen.style() == Qt::NoPen
pen.style() == Qt::NoPenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
555 stroker = 0;-
556 return;
never executed: return;
0
557 }-
558 qreal w = pen.widthF();-
559 bool zeroWidth = w < 0.0001;-
560 cosmeticPen = qt_pen_is_cosmetic(pen, hints);-
561 if (zeroWidth
zeroWidthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
562 w = .1;
never executed: w = .1;
0
563-
564 basicStroker.setStrokeWidth(w);-
565 basicStroker.setCapStyle(pen.capStyle());-
566 basicStroker.setJoinStyle(pen.joinStyle());-
567 basicStroker.setMiterLimit(pen.miterLimit());-
568-
569 QVector<qreal> dashpattern = pen.dashPattern();-
570 if (zeroWidth
zeroWidthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
571 for (int i = 0; i < dashpattern.size()
i < dashpattern.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
572 dashpattern[i] *= 10.;
never executed: dashpattern[i] *= 10.;
0
573 }
never executed: end of block
0
574 if (!dashpattern.isEmpty()
!dashpattern.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
575 dashStroker.setDashPattern(dashpattern);-
576 dashStroker.setDashOffset(pen.dashOffset());-
577 stroker = &dashStroker;-
578 }
never executed: end of block
else {
0
579 stroker = &basicStroker;-
580 }
never executed: end of block
0
581}-
582-
583void QPdf::Stroker::strokePath(const QPainterPath &path)-
584{-
585 if (!stroker
!strokerDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
586 return;
never executed: return;
0
587 first = true;-
588-
589 stroker->strokePath(path, this, cosmeticPen ? matrix : QTransform());-
590 *stream << "h f\n";-
591}
never executed: end of block
0
592-
593QByteArray QPdf::ascii85Encode(const QByteArray &input)-
594{-
595 int isize = input.size()/4*4;-
596 QByteArray output;-
597 output.resize(input.size()*5/4+7);-
598 char *out = output.data();-
599 const uchar *in = (const uchar *)input.constData();-
600 for (int i = 0; i < isize
i < isizeDescription
TRUEnever evaluated
FALSEnever evaluated
; i += 4) {
0
601 uint val = (((uint)in[i])<<24) + (((uint)in[i+1])<<16) + (((uint)in[i+2])<<8) + (uint)in[i+3];-
602 if (val == 0
val == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
603 *out = 'z';-
604 ++out;-
605 }
never executed: end of block
else {
0
606 char base[5];-
607 base[4] = val % 85;-
608 val /= 85;-
609 base[3] = val % 85;-
610 val /= 85;-
611 base[2] = val % 85;-
612 val /= 85;-
613 base[1] = val % 85;-
614 val /= 85;-
615 base[0] = val % 85;-
616 *(out++) = base[0] + '!';-
617 *(out++) = base[1] + '!';-
618 *(out++) = base[2] + '!';-
619 *(out++) = base[3] + '!';-
620 *(out++) = base[4] + '!';-
621 }
never executed: end of block
0
622 }-
623-
624 int remaining = input.size() - isize;-
625 if (remaining
remainingDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
626 uint val = 0;-
627 for (int i = isize; i < input.size()
i < input.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
628 val = (val << 8) + in[i];
never executed: val = (val << 8) + in[i];
0
629 val <<= 8*(4-remaining);-
630 char base[5];-
631 base[4] = val % 85;-
632 val /= 85;-
633 base[3] = val % 85;-
634 val /= 85;-
635 base[2] = val % 85;-
636 val /= 85;-
637 base[1] = val % 85;-
638 val /= 85;-
639 base[0] = val % 85;-
640 for (int i = 0; i < remaining+1
i < remaining+1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
641 *(
never executed: *(out++) = base[i] + '!';
out++) = base[i] + '!';
never executed: *(out++) = base[i] + '!';
0
642 }
never executed: end of block
0
643 *(out++) = '~';-
644 *(out++) = '>';-
645 output.resize(out-output.data());-
646 return
never executed: return output;
output;
never executed: return output;
0
647}-
648-
649const char *QPdf::toHex(ushort u, char *buffer)-
650{-
651 int i = 3;-
652 while (i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
653 ushort hex = (u & 0x000f);-
654 if (hex < 0x0a
hex < 0x0aDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
655 buffer[i] = '0'+hex;
never executed: buffer[i] = '0'+hex;
0
656 else-
657 buffer[i] = 'A'+(hex-0x0a);
never executed: buffer[i] = 'A'+(hex-0x0a);
0
658 u = u >> 4;-
659 i--;-
660 }
never executed: end of block
0
661 buffer[4] = '\0';-
662 return
never executed: return buffer;
buffer;
never executed: return buffer;
0
663}-
664-
665const char *QPdf::toHex(uchar u, char *buffer)-
666{-
667 int i = 1;-
668 while (i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
669 ushort hex = (u & 0x000f);-
670 if (hex < 0x0a
hex < 0x0aDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
671 buffer[i] = '0'+hex;
never executed: buffer[i] = '0'+hex;
0
672 else-
673 buffer[i] = 'A'+(hex-0x0a);
never executed: buffer[i] = 'A'+(hex-0x0a);
0
674 u = u >> 4;-
675 i--;-
676 }
never executed: end of block
0
677 buffer[2] = '\0';-
678 return
never executed: return buffer;
buffer;
never executed: return buffer;
0
679}-
680-
681-
682QPdfPage::QPdfPage()-
683 : QPdf::ByteStream(true)-
684{-
685}
never executed: end of block
0
686-
687void QPdfPage::streamImage(int w, int h, int object)-
688{-
689 *this << w << "0 0 " << -h << "0 " << h << "cm /Im" << object << " Do\n";-
690 if (!images.contains(object)
!images.contains(object)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
691 images.append(object);
never executed: images.append(object);
0
692}
never executed: end of block
0
693-
694-
695QPdfEngine::QPdfEngine(QPdfEnginePrivate &dd)-
696 : QPaintEngine(dd, qt_pdf_decide_features())-
697{-
698}
never executed: end of block
0
699-
700QPdfEngine::QPdfEngine()-
701 : QPaintEngine(*new QPdfEnginePrivate(), qt_pdf_decide_features())-
702{-
703}
never executed: end of block
0
704-
705void QPdfEngine::setOutputFilename(const QString &filename)-
706{-
707 QPdfEnginePrivate * const d = d_func();-
708 d->outputFileName = filename;-
709}
never executed: end of block
0
710-
711-
712void QPdfEngine::drawPoints (const QPointF *points, int pointCount)-
713{-
714 if (!points
!pointsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
715 return;
never executed: return;
0
716-
717 QPdfEnginePrivate * const d = d_func();-
718 QPainterPath p;-
719 for (int i=0; i!=pointCount
i!=pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
;++i) {
0
720 p.moveTo(points[i]);-
721 p.lineTo(points[i] + QPointF(0, 0.001));-
722 }
never executed: end of block
0
723-
724 bool hadBrush = d->hasBrush;-
725 d->hasBrush = false;-
726 drawPath(p);-
727 d->hasBrush = hadBrush;-
728}
never executed: end of block
0
729-
730void QPdfEngine::drawLines (const QLineF *lines, int lineCount)-
731{-
732 if (!lines
!linesDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
733 return;
never executed: return;
0
734-
735 QPdfEnginePrivate * const d = d_func();-
736 QPainterPath p;-
737 for (int i=0; i!=lineCount
i!=lineCountDescription
TRUEnever evaluated
FALSEnever evaluated
;++i) {
0
738 p.moveTo(lines[i].p1());-
739 p.lineTo(lines[i].p2());-
740 }
never executed: end of block
0
741 bool hadBrush = d->hasBrush;-
742 d->hasBrush = false;-
743 drawPath(p);-
744 d->hasBrush = hadBrush;-
745}
never executed: end of block
0
746-
747void QPdfEngine::drawRects (const QRectF *rects, int rectCount)-
748{-
749 if (!rects
!rectsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
750 return;
never executed: return;
0
751-
752 QPdfEnginePrivate * const d = d_func();-
753-
754 if (d->clipEnabled
d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->allClipped
d->allClippedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
755 return;
never executed: return;
0
756 if (!d->hasPen
!d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->hasBrush
!d->hasBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
757 return;
never executed: return;
0
758-
759 QBrush penBrush = d->pen.brush();-
760 if (d->simplePen
d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->hasPen
!d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
761-
762 if(!d->simplePen
!d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->stroker.matrix.isIdentity()
!d->stroker.ma...x.isIdentity()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
763 *
never executed: *d->currentPage << "q\n" << QPdf::generateMatrix(d->stroker.matrix);
d->currentPage << "q\n" << QPdf::generateMatrix(d->stroker.matrix);
never executed: *d->currentPage << "q\n" << QPdf::generateMatrix(d->stroker.matrix);
0
764 for (int i = 0; i < rectCount
i < rectCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
765 *
never executed: *d->currentPage << rects[i].x() << rects[i].y() << rects[i].width() << rects[i].height() << "re\n";
d->currentPage << rects[i].x() << rects[i].y() << rects[i].width() << rects[i].height() << "re\n";
never executed: *d->currentPage << rects[i].x() << rects[i].y() << rects[i].width() << rects[i].height() << "re\n";
0
766 *d->currentPage << (d->hasPen ? (d->hasBrush ? "B\n" : "S\n") : "f\n");-
767 if(!d->simplePen
!d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->stroker.matrix.isIdentity()
!d->stroker.ma...x.isIdentity()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
768 *
never executed: *d->currentPage << "Q\n";
d->currentPage << "Q\n";
never executed: *d->currentPage << "Q\n";
0
769 }
never executed: end of block
else {
0
770 QPainterPath p;-
771 for (int i=0; i!=rectCount
i!=rectCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
772 p.addRect(rects[i]);
never executed: p.addRect(rects[i]);
0
773 drawPath(p);-
774 }
never executed: end of block
0
775}-
776-
777void QPdfEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)-
778{-
779 QPdfEnginePrivate * const d = d_func();-
780-
781 if (!points
!pointsDescription
TRUEnever evaluated
FALSEnever evaluated
|| !pointCount
!pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
782 return;
never executed: return;
0
783-
784 bool hb = d->hasBrush;-
785 QPainterPath p;-
786-
787 switch(mode) {-
788 case
never executed: case OddEvenMode:
OddEvenMode:
never executed: case OddEvenMode:
0
789 p.setFillRule(Qt::OddEvenFill);-
790 break;
never executed: break;
0
791 case
never executed: case ConvexMode:
ConvexMode:
never executed: case ConvexMode:
0
792 case
never executed: case WindingMode:
WindingMode:
never executed: case WindingMode:
0
793 p.setFillRule(Qt::WindingFill);-
794 break;
never executed: break;
0
795 case
never executed: case PolylineMode:
PolylineMode:
never executed: case PolylineMode:
0
796 d->hasBrush = false;-
797 break;
never executed: break;
0
798 default
never executed: default:
:
never executed: default:
0
799 break;
never executed: break;
0
800 }-
801-
802 p.moveTo(points[0]);-
803 for (int i = 1; i < pointCount
i < pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
804 p.lineTo(points[i]);
never executed: p.lineTo(points[i]);
0
805-
806 if (mode != PolylineMode
mode != PolylineModeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
807 p.closeSubpath();
never executed: p.closeSubpath();
0
808 drawPath(p);-
809-
810 d->hasBrush = hb;-
811}
never executed: end of block
0
812-
813void QPdfEngine::drawPath (const QPainterPath &p)-
814{-
815 QPdfEnginePrivate * const d = d_func();-
816-
817 if (d->clipEnabled
d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->allClipped
d->allClippedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
818 return;
never executed: return;
0
819 if (!d->hasPen
!d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->hasBrush
!d->hasBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
820 return;
never executed: return;
0
821-
822 if (d->simplePen
d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
823-
824 *d->currentPage << QPdf::generatePath(p, QTransform(), d->hasBrush ? QPdf::FillAndStrokePath : QPdf::StrokePath);-
825 }
never executed: end of block
else {
0
826 if (d->hasBrush
d->hasBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
827 *
never executed: *d->currentPage << QPdf::generatePath(p, d->stroker.matrix, QPdf::FillPath);
d->currentPage << QPdf::generatePath(p, d->stroker.matrix, QPdf::FillPath);
never executed: *d->currentPage << QPdf::generatePath(p, d->stroker.matrix, QPdf::FillPath);
0
828 if (d->hasPen
d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
829 *d->currentPage << "q\n";-
830 QBrush b = d->brush;-
831 d->brush = d->pen.brush();-
832 setBrush();-
833 d->stroker.strokePath(p);-
834 *d->currentPage << "Q\n";-
835 d->brush = b;-
836 }
never executed: end of block
0
837 }
never executed: end of block
0
838}-
839-
840void QPdfEngine::drawPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr)-
841{-
842 if (sr.isEmpty()
sr.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| rectangle.isEmpty()
rectangle.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| pixmap.isNull()
pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
843 return;
never executed: return;
0
844 QPdfEnginePrivate * const d = d_func();-
845-
846 QBrush b = d->brush;-
847-
848 QRect sourceRect = sr.toRect();-
849 QPixmap pm = sourceRect != pixmap.rect()
sourceRect != pixmap.rect()Description
TRUEnever evaluated
FALSEnever evaluated
? pixmap.copy(sourceRect) : pixmap;
0
850 QImage image = pm.toImage();-
851 bool bitmap = true;-
852 const int object = d->addImage(image, &bitmap, pm.cacheKey());-
853 if (object < 0
object < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
854 return;
never executed: return;
0
855-
856 *d->currentPage << "q\n/GSa gs\n";-
857 *d->currentPage-
858 << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(),-
859 rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix));-
860 if (bitmap
bitmapDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
861-
862 d->brush = d->pen.brush();-
863 }
never executed: end of block
0
864 setBrush();-
865 d->currentPage->streamImage(image.width(), image.height(), object);-
866 *d->currentPage << "Q\n";-
867-
868 d->brush = b;-
869}
never executed: end of block
0
870-
871void QPdfEngine::drawImage(const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags)-
872{-
873 if (sr.isEmpty()
sr.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| rectangle.isEmpty()
rectangle.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
874 return;
never executed: return;
0
875 QPdfEnginePrivate * const d = d_func();-
876-
877 QRect sourceRect = sr.toRect();-
878 QImage im = sourceRect != image.rect()
sourceRect != image.rect()Description
TRUEnever evaluated
FALSEnever evaluated
? image.copy(sourceRect) : image;
0
879 bool bitmap = true;-
880 const int object = d->addImage(im, &bitmap, im.cacheKey());-
881 if (object < 0
object < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
882 return;
never executed: return;
0
883-
884 *d->currentPage << "q\n/GSa gs\n";-
885 *d->currentPage-
886 << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(),-
887 rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix));-
888 setBrush();-
889 d->currentPage->streamImage(im.width(), im.height(), object);-
890 *d->currentPage << "Q\n";-
891}
never executed: end of block
0
892-
893void QPdfEngine::drawTiledPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QPointF &point)-
894{-
895 QPdfEnginePrivate * const d = d_func();-
896-
897 bool bitmap = (pixmap.depth() == 1);-
898 QBrush b = d->brush;-
899 QPointF bo = d->brushOrigin;-
900 bool hp = d->hasPen;-
901 d->hasPen = false;-
902 bool hb = d->hasBrush;-
903 d->hasBrush = true;-
904-
905 d->brush = QBrush(pixmap);-
906 if (bitmap
bitmapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
907-
908 d->brush.setColor(d->pen.color());
never executed: d->brush.setColor(d->pen.color());
0
909-
910 d->brushOrigin = -point;-
911 *d->currentPage << "q\n";-
912 setBrush();-
913-
914 drawRects(&rectangle, 1);-
915 *d->currentPage << "Q\n";-
916-
917 d->hasPen = hp;-
918 d->hasBrush = hb;-
919 d->brush = b;-
920 d->brushOrigin = bo;-
921}
never executed: end of block
0
922-
923void QPdfEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)-
924{-
925 QPdfEnginePrivate * const d = d_func();-
926-
927 if (!d->hasPen
!d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
|| (d->clipEnabled
d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->allClipped
d->allClippedDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
928 return;
never executed: return;
0
929-
930 if (d->stroker.matrix.type() >= QTransform::TxProject
d->stroker.mat...orm::TxProjectDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
931 QPaintEngine::drawTextItem(p, textItem);-
932 return;
never executed: return;
0
933 }-
934-
935 *d->currentPage << "q\n";-
936 if(!d->simplePen
!d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
937 *
never executed: *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
never executed: *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
0
938-
939 bool hp = d->hasPen;-
940 d->hasPen = false;-
941 QBrush b = d->brush;-
942 d->brush = d->pen.brush();-
943 setBrush();-
944-
945 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);-
946 ((!(ti.fontEngine->type() != QFontEngine::Multi)) ? qt_assert("ti.fontEngine->type() != QFontEngine::Multi",__FILE__,998) : qt_noop());-
947 d->drawTextItem(p, ti);-
948 d->hasPen = hp;-
949 d->brush = b;-
950 *d->currentPage << "Q\n";-
951}
never executed: end of block
0
952-
953void QPdfEngine::drawHyperlink(const QRectF &r, const QUrl &url)-
954{-
955 QPdfEnginePrivate * const d = d_func();-
956-
957 const uint annot = d->addXrefEntry(-1);-
958 const QByteArray urlascii = url.toEncoded();-
959 int len = urlascii.size();-
960 QVarLengthArray<char> url_esc;-
961 url_esc.reserve(len + 1);-
962 for (int j = 0; j < len
j < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; j++) {
0
963 if (urlascii[j] == '('
urlascii[j] == '('Description
TRUEnever evaluated
FALSEnever evaluated
|| urlascii[j] == ')'
urlascii[j] == ')'Description
TRUEnever evaluated
FALSEnever evaluated
|| urlascii[j] == '\\'
urlascii[j] == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
964 url_esc.append('\\');
never executed: url_esc.append('\\');
0
965 url_esc.append(urlascii[j]);-
966 }
never executed: end of block
0
967 url_esc.append('\0');-
968-
969 char buf[256];-
970 const QRectF rr = d->pageMatrix().mapRect(r);-
971 d->xprintf("<<\n/Type /Annot\n/Subtype /Link\n/Rect [");-
972 d->xprintf("%s ", qt_real_to_string(rr.left(), buf));-
973 d->xprintf("%s ", qt_real_to_string(rr.top(), buf));-
974 d->xprintf("%s ", qt_real_to_string(rr.right(), buf));-
975 d->xprintf("%s", qt_real_to_string(rr.bottom(), buf));-
976 d->xprintf("]\n/Border [0 0 0]\n/A <<\n");-
977 d->xprintf("/Type /Action\n/S /URI\n/URI (%s)\n", url_esc.constData());-
978 d->xprintf(">>\n>>\n");-
979 d->xprintf("endobj\n");-
980 d->currentPage->annotations.append(annot);-
981}
never executed: end of block
0
982-
983void QPdfEngine::updateState(const QPaintEngineState &state)-
984{-
985 QPdfEnginePrivate * const d = d_func();-
986-
987 QPaintEngine::DirtyFlags flags = state.state();-
988-
989 if (flags & DirtyTransform
flags & DirtyTransformDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
990 d->stroker.matrix = state.transform();
never executed: d->stroker.matrix = state.transform();
0
991-
992 if (flags & DirtyPen
flags & DirtyPenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
993 d->pen = state.pen();-
994 d->hasPen = d->pen.style() != Qt::NoPen;-
995 d->stroker.setPen(d->pen, state.renderHints());-
996 QBrush penBrush = d->pen.brush();-
997 bool oldSimple = d->simplePen;-
998 d->simplePen = (d->hasPen
d->hasPenDescription
TRUEnever evaluated
FALSEnever evaluated
&& (
(penBrush.styl...:SolidPattern)Description
TRUEnever evaluated
FALSEnever evaluated
penBrush.style() == Qt::SolidPattern)
(penBrush.styl...:SolidPattern)Description
TRUEnever evaluated
FALSEnever evaluated
&& penBrush.isOpaque()
penBrush.isOpaque()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->opacity == 1.0
d->opacity == 1.0Description
TRUEnever evaluated
FALSEnever evaluated
);
0
999 if (oldSimple != d->simplePen
oldSimple != d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1000 flags |= DirtyTransform;
never executed: flags |= DirtyTransform;
0
1001 }
never executed: end of block
else if (flags & DirtyHints
flags & DirtyHintsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1002 d->stroker.setPen(d->pen, state.renderHints());-
1003 }
never executed: end of block
0
1004 if (flags & DirtyBrush
flags & DirtyBrushDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1005 d->brush = state.brush();-
1006 if (d->brush.color().alpha() == 0
d->brush.color().alpha() == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& d->brush.style() == Qt::SolidPattern
d->brush.style...::SolidPatternDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1007 d->brush.setStyle(Qt::NoBrush);
never executed: d->brush.setStyle(Qt::NoBrush);
0
1008 d->hasBrush = d->brush.style() != Qt::NoBrush;-
1009 }
never executed: end of block
0
1010 if (flags & DirtyBrushOrigin
flags & DirtyBrushOriginDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1011 d->brushOrigin = state.brushOrigin();-
1012 flags |= DirtyBrush;-
1013 }
never executed: end of block
0
1014 if (flags & DirtyOpacity
flags & DirtyOpacityDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1015 d->opacity = state.opacity();-
1016 if (d->simplePen
d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->opacity != 1.0
d->opacity != 1.0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1017 d->simplePen = false;-
1018 flags |= DirtyTransform;-
1019 }
never executed: end of block
0
1020 }
never executed: end of block
0
1021-
1022 bool ce = d->clipEnabled;-
1023 if (flags & DirtyClipPath
flags & DirtyClipPathDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1024 d->clipEnabled = true;-
1025 updateClipPath(state.clipPath(), state.clipOperation());-
1026 }
never executed: end of block
else if (flags & DirtyClipRegion
flags & DirtyClipRegionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1027 d->clipEnabled = true;-
1028 QPainterPath path;-
1029 QVector<QRect> rects = state.clipRegion().rects();-
1030 for (int i = 0; i < rects.size()
i < rects.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1031 path.addRect(rects.at(i));
never executed: path.addRect(rects.at(i));
0
1032 updateClipPath(path, state.clipOperation());-
1033 flags |= DirtyClipPath;-
1034 }
never executed: end of block
else if (flags & DirtyClipEnabled
flags & DirtyClipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1035 d->clipEnabled = state.isClipEnabled();-
1036 }
never executed: end of block
0
1037-
1038 if (ce != d->clipEnabled
ce != d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1039 flags |= DirtyClipPath;
never executed: flags |= DirtyClipPath;
0
1040 else if (!d->clipEnabled
!d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1041 flags &= ~DirtyClipPath;
never executed: flags &= ~DirtyClipPath;
0
1042-
1043 setupGraphicsState(flags);-
1044}
never executed: end of block
0
1045-
1046void QPdfEngine::setupGraphicsState(QPaintEngine::DirtyFlags flags)-
1047{-
1048 QPdfEnginePrivate * const d = d_func();-
1049 if (flags & DirtyClipPath
flags & DirtyClipPathDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1050 flags |= DirtyTransform|DirtyPen|DirtyBrush;
never executed: flags |= DirtyTransform|DirtyPen|DirtyBrush;
0
1051-
1052 if (flags & DirtyTransform
flags & DirtyTransformDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1053 *d->currentPage << "Q\n";-
1054 flags |= DirtyPen|DirtyBrush;-
1055 }
never executed: end of block
0
1056-
1057 if (flags & DirtyClipPath
flags & DirtyClipPathDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1058 *d->currentPage << "Q q\n";-
1059-
1060 d->allClipped = false;-
1061 if (d->clipEnabled
d->clipEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->clips.isEmpty()
!d->clips.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1062 for (int i = 0; i < d->clips.size()
i < d->clips.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1063 if (d->clips.at(i).isEmpty()
d->clips.at(i).isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1064 d->allClipped = true;-
1065 break;
never executed: break;
0
1066 }-
1067 }
never executed: end of block
0
1068 if (!d->allClipped
!d->allClippedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1069 for (int i = 0; i < d->clips.size()
i < d->clips.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1070 *d->currentPage << QPdf::generatePath(d->clips.at(i), QTransform(), QPdf::ClipPath);-
1071 }
never executed: end of block
0
1072 }
never executed: end of block
0
1073 }
never executed: end of block
0
1074 }
never executed: end of block
0
1075-
1076 if (flags & DirtyTransform
flags & DirtyTransformDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1077 *d->currentPage << "q\n";-
1078 if (d->simplePen
d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->stroker.matrix.isIdentity()
!d->stroker.ma...x.isIdentity()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1079 *
never executed: *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
never executed: *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);
0
1080 }
never executed: end of block
0
1081 if (flags & DirtyBrush
flags & DirtyBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1082 setBrush();
never executed: setBrush();
0
1083 if (d->simplePen
d->simplePenDescription
TRUEnever evaluated
FALSEnever evaluated
&& (
(flags & DirtyPen)Description
TRUEnever evaluated
FALSEnever evaluated
flags & DirtyPen)
(flags & DirtyPen)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1084 setPen();
never executed: setPen();
0
1085}
never executed: end of block
0
1086-
1087extern QPainterPath qt_regionToPath(const QRegion &region);-
1088-
1089void QPdfEngine::updateClipPath(const QPainterPath &p, Qt::ClipOperation op)-
1090{-
1091 QPdfEnginePrivate * const d = d_func();-
1092 QPainterPath path = d->stroker.matrix.map(p);-
1093-
1094-
1095 if (op == Qt::NoClip
op == Qt::NoClipDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1096 d->clipEnabled = false;-
1097 d->clips.clear();-
1098 }
never executed: end of block
else if (op == Qt::ReplaceClip
op == Qt::ReplaceClipDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1099 d->clips.clear();-
1100 d->clips.append(path);-
1101 }
never executed: end of block
else if (op == Qt::IntersectClip
op == Qt::IntersectClipDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1102 d->clips.append(path);-
1103 }
never executed: end of block
else {
0
1104-
1105 path = painter()->clipPath();-
1106 path = d->stroker.matrix.map(path);-
1107 d->clips.clear();-
1108 d->clips.append(path);-
1109 }
never executed: end of block
0
1110}-
1111-
1112void QPdfEngine::setPen()-
1113{-
1114 QPdfEnginePrivate * const d = d_func();-
1115 if (d->pen.style() == Qt::NoPen
d->pen.style() == Qt::NoPenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1116 return;
never executed: return;
0
1117 QBrush b = d->pen.brush();-
1118 ((!(b.style() == Qt::SolidPattern && b.isOpaque())) ? qt_assert("b.style() == Qt::SolidPattern && b.isOpaque()",__FILE__,1170) : qt_noop());-
1119-
1120 QColor rgba = b.color();-
1121 if (d->grayscale
d->grayscaleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1122 qreal gray = qGray(rgba.rgba())/255.;-
1123 *d->currentPage << gray << gray << gray;-
1124 }
never executed: end of block
else {
0
1125 *d->currentPage << rgba.redF()-
1126 << rgba.greenF()-
1127 << rgba.blueF();-
1128 }
never executed: end of block
0
1129 *d->currentPage << "SCN\n";-
1130-
1131 *d->currentPage << d->pen.widthF() << "w ";-
1132-
1133 int pdfCapStyle = 0;-
1134 switch(d->pen.capStyle()) {-
1135 case
never executed: case Qt::FlatCap:
Qt::FlatCap:
never executed: case Qt::FlatCap:
0
1136 pdfCapStyle = 0;-
1137 break;
never executed: break;
0
1138 case
never executed: case Qt::SquareCap:
Qt::SquareCap:
never executed: case Qt::SquareCap:
0
1139 pdfCapStyle = 2;-
1140 break;
never executed: break;
0
1141 case
never executed: case Qt::RoundCap:
Qt::RoundCap:
never executed: case Qt::RoundCap:
0
1142 pdfCapStyle = 1;-
1143 break;
never executed: break;
0
1144 default
never executed: default:
:
never executed: default:
0
1145 break;
never executed: break;
0
1146 }-
1147 *d->currentPage << pdfCapStyle << "J ";-
1148-
1149 int pdfJoinStyle = 0;-
1150 switch(d->pen.joinStyle()) {-
1151 case
never executed: case Qt::MiterJoin:
Qt::MiterJoin:
never executed: case Qt::MiterJoin:
0
1152 case
never executed: case Qt::SvgMiterJoin:
Qt::SvgMiterJoin:
never executed: case Qt::SvgMiterJoin:
0
1153 *d->currentPage << qMax(qreal(1.0), d->pen.miterLimit()) << "M ";-
1154 pdfJoinStyle = 0;-
1155 break;
never executed: break;
0
1156 case
never executed: case Qt::BevelJoin:
Qt::BevelJoin:
never executed: case Qt::BevelJoin:
0
1157 pdfJoinStyle = 2;-
1158 break;
never executed: break;
0
1159 case
never executed: case Qt::RoundJoin:
Qt::RoundJoin:
never executed: case Qt::RoundJoin:
0
1160 pdfJoinStyle = 1;-
1161 break;
never executed: break;
0
1162 default
never executed: default:
:
never executed: default:
0
1163 break;
never executed: break;
0
1164 }-
1165 *d->currentPage << pdfJoinStyle << "j ";-
1166-
1167 *d->currentPage << QPdf::generateDashes(d->pen);-
1168}
never executed: end of block
0
1169-
1170-
1171void QPdfEngine::setBrush()-
1172{-
1173 QPdfEnginePrivate * const d = d_func();-
1174 Qt::BrushStyle style = d->brush.style();-
1175 if (style == Qt::NoBrush
style == Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1176 return;
never executed: return;
0
1177-
1178 bool specifyColor;-
1179 int gStateObject = 0;-
1180 int patternObject = d->addBrushPattern(d->stroker.matrix, &specifyColor, &gStateObject);-
1181 if (!patternObject
!patternObjectDescription
TRUEnever evaluated
FALSEnever evaluated
&& !specifyColor
!specifyColorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1182 return;
never executed: return;
0
1183-
1184 *d->currentPage << (patternObject ? "/PCSp cs " : "/CSp cs ");-
1185 if (specifyColor
specifyColorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1186 QColor rgba = d->brush.color();-
1187 if (d->grayscale
d->grayscaleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1188 qreal gray = qGray(rgba.rgba())/255.;-
1189 *d->currentPage << gray << gray << gray;-
1190 }
never executed: end of block
else {
0
1191 *d->currentPage << rgba.redF()-
1192 << rgba.greenF()-
1193 << rgba.blueF();-
1194 }
never executed: end of block
0
1195 }-
1196 if (patternObject
patternObjectDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1197 *
never executed: *d->currentPage << "/Pat" << patternObject;
d->currentPage << "/Pat" << patternObject;
never executed: *d->currentPage << "/Pat" << patternObject;
0
1198 *d->currentPage << "scn\n";-
1199-
1200 if (gStateObject
gStateObjectDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1201 *
never executed: *d->currentPage << "/GState" << gStateObject << "gs\n";
d->currentPage << "/GState" << gStateObject << "gs\n";
never executed: *d->currentPage << "/GState" << gStateObject << "gs\n";
0
1202 else-
1203 *
never executed: *d->currentPage << "/GSa gs\n";
d->currentPage << "/GSa gs\n";
never executed: *d->currentPage << "/GSa gs\n";
0
1204}-
1205-
1206-
1207bool QPdfEngine::newPage()-
1208{-
1209 QPdfEnginePrivate * const d = d_func();-
1210 if (!isActive()
!isActive()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1211 return
never executed: return false;
false;
never executed: return false;
0
1212 d->newPage();-
1213-
1214 setupGraphicsState(DirtyBrush|DirtyPen|DirtyClipPath);-
1215 QFile *outfile = qobject_cast<QFile*> (d->outDevice);-
1216 if (outfile
outfileDescription
TRUEnever evaluated
FALSEnever evaluated
&& outfile->error() != QFile::NoError
outfile->error...QFile::NoErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1217 return
never executed: return false;
false;
never executed: return false;
0
1218 return
never executed: return true;
true;
never executed: return true;
0
1219}-
1220-
1221QPaintEngine::Type QPdfEngine::type() const-
1222{-
1223 return
never executed: return QPaintEngine::Pdf;
QPaintEngine::Pdf;
never executed: return QPaintEngine::Pdf;
0
1224}-
1225-
1226void QPdfEngine::setResolution(int resolution)-
1227{-
1228 QPdfEnginePrivate * const d = d_func();-
1229 d->resolution = resolution;-
1230}
never executed: end of block
0
1231-
1232int QPdfEngine::resolution() const-
1233{-
1234 const QPdfEnginePrivate * const d = d_func();-
1235 return
never executed: return d->resolution;
d->resolution;
never executed: return d->resolution;
0
1236}-
1237-
1238void QPdfEngine::setPageLayout(const QPageLayout &pageLayout)-
1239{-
1240 QPdfEnginePrivate * const d = d_func();-
1241 d->m_pageLayout = pageLayout;-
1242}
never executed: end of block
0
1243-
1244void QPdfEngine::setPageSize(const QPageSize &pageSize)-
1245{-
1246 QPdfEnginePrivate * const d = d_func();-
1247 d->m_pageLayout.setPageSize(pageSize);-
1248}
never executed: end of block
0
1249-
1250void QPdfEngine::setPageOrientation(QPageLayout::Orientation orientation)-
1251{-
1252 QPdfEnginePrivate * const d = d_func();-
1253 d->m_pageLayout.setOrientation(orientation);-
1254}
never executed: end of block
0
1255-
1256void QPdfEngine::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)-
1257{-
1258 QPdfEnginePrivate * const d = d_func();-
1259 d->m_pageLayout.setUnits(units);-
1260 d->m_pageLayout.setMargins(margins);-
1261}
never executed: end of block
0
1262-
1263QPageLayout QPdfEngine::pageLayout() const-
1264{-
1265 const QPdfEnginePrivate * const d = d_func();-
1266 return
never executed: return d->m_pageLayout;
d->m_pageLayout;
never executed: return d->m_pageLayout;
0
1267}-
1268-
1269-
1270int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const-
1271{-
1272 const QPdfEnginePrivate * const d = d_func();-
1273 int val;-
1274 switch (metricType) {-
1275 case
never executed: case QPaintDevice::PdmWidth:
QPaintDevice::PdmWidth:
never executed: case QPaintDevice::PdmWidth:
0
1276 val = d->m_pageLayout.paintRectPixels(d->resolution).width();-
1277 break;
never executed: break;
0
1278 case
never executed: case QPaintDevice::PdmHeight:
QPaintDevice::PdmHeight:
never executed: case QPaintDevice::PdmHeight:
0
1279 val = d->m_pageLayout.paintRectPixels(d->resolution).height();-
1280 break;
never executed: break;
0
1281 case
never executed: case QPaintDevice::PdmDpiX:
QPaintDevice::PdmDpiX:
never executed: case QPaintDevice::PdmDpiX:
0
1282 case
never executed: case QPaintDevice::PdmDpiY:
QPaintDevice::PdmDpiY:
never executed: case QPaintDevice::PdmDpiY:
0
1283 val = d->resolution;-
1284 break;
never executed: break;
0
1285 case
never executed: case QPaintDevice::PdmPhysicalDpiX:
QPaintDevice::PdmPhysicalDpiX:
never executed: case QPaintDevice::PdmPhysicalDpiX:
0
1286 case
never executed: case QPaintDevice::PdmPhysicalDpiY:
QPaintDevice::PdmPhysicalDpiY:
never executed: case QPaintDevice::PdmPhysicalDpiY:
0
1287 val = 1200;-
1288 break;
never executed: break;
0
1289 case
never executed: case QPaintDevice::PdmWidthMM:
QPaintDevice::PdmWidthMM:
never executed: case QPaintDevice::PdmWidthMM:
0
1290 val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).width());-
1291 break;
never executed: break;
0
1292 case
never executed: case QPaintDevice::PdmHeightMM:
QPaintDevice::PdmHeightMM:
never executed: case QPaintDevice::PdmHeightMM:
0
1293 val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).height());-
1294 break;
never executed: break;
0
1295 case
never executed: case QPaintDevice::PdmNumColors:
QPaintDevice::PdmNumColors:
never executed: case QPaintDevice::PdmNumColors:
0
1296 val = 2147483647;-
1297 break;
never executed: break;
0
1298 case
never executed: case QPaintDevice::PdmDepth:
QPaintDevice::PdmDepth:
never executed: case QPaintDevice::PdmDepth:
0
1299 val = 32;-
1300 break;
never executed: break;
0
1301 case
never executed: case QPaintDevice::PdmDevicePixelRatio:
QPaintDevice::PdmDevicePixelRatio:
never executed: case QPaintDevice::PdmDevicePixelRatio:
0
1302 val = 1;-
1303 break;
never executed: break;
0
1304 case
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
QPaintDevice::PdmDevicePixelRatioScaled:
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
0
1305 val = 1 * QPaintDevice::devicePixelRatioFScale();-
1306 break;
never executed: break;
0
1307 default
never executed: default:
:
never executed: default:
0
1308 QMessageLogger(__FILE__, 1360, __PRETTY_FUNCTION__).warning("QPdfWriter::metric: Invalid metric command");-
1309 return
never executed: return 0;
0;
never executed: return 0;
0
1310 }-
1311 return
never executed: return val;
val;
never executed: return val;
0
1312}-
1313-
1314QPdfEnginePrivate::QPdfEnginePrivate()-
1315 : clipEnabled(false), allClipped(false), hasPen(true), hasBrush(false), simplePen(false),-
1316 outDevice(0), ownsDevice(false),-
1317 embedFonts(true),-
1318 grayscale(false),-
1319 m_pageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(10, 10, 10, 10))-
1320{-
1321 resolution = 1200;-
1322 currentObject = 1;-
1323 currentPage = 0;-
1324 stroker.stream = 0;-
1325-
1326 streampos = 0;-
1327-
1328 stream = new QDataStream;-
1329}
never executed: end of block
0
1330-
1331bool QPdfEngine::begin(QPaintDevice *pdev)-
1332{-
1333 QPdfEnginePrivate * const d = d_func();-
1334 d->pdev = pdev;-
1335-
1336 if (!d->outDevice
!d->outDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1337 if (!d->outputFileName.isEmpty()
!d->outputFileName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1338 QFile *file = new QFile(d->outputFileName);-
1339 if (!file->open(QFile::WriteOnly|QFile::Truncate)
!file->open(QF...ile::Truncate)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1340 delete file;-
1341 return
never executed: return false;
false;
never executed: return false;
0
1342 }-
1343 d->outDevice = file;-
1344 }
never executed: end of block
else {
0
1345 return
never executed: return false;
false;
never executed: return false;
0
1346 }-
1347 d->ownsDevice = true;-
1348 }
never executed: end of block
0
1349-
1350 d->currentObject = 1;-
1351-
1352 d->currentPage = new QPdfPage;-
1353 d->stroker.stream = d->currentPage;-
1354 d->opacity = 1.0;-
1355-
1356 d->stream->setDevice(d->outDevice);-
1357-
1358 d->streampos = 0;-
1359 d->hasPen = true;-
1360 d->hasBrush = false;-
1361 d->clipEnabled = false;-
1362 d->allClipped = false;-
1363-
1364 d->xrefPositions.clear();-
1365 d->pageRoot = 0;-
1366 d->catalog = 0;-
1367 d->info = 0;-
1368 d->graphicsState = 0;-
1369 d->patternColorSpace = 0;-
1370 d->simplePen = false;-
1371-
1372 d->pages.clear();-
1373 d->imageCache.clear();-
1374 d->alphaCache.clear();-
1375-
1376 setActive(true);-
1377 d->writeHeader();-
1378 newPage();-
1379-
1380 return
never executed: return true;
true;
never executed: return true;
0
1381}-
1382-
1383bool QPdfEngine::end()-
1384{-
1385 QPdfEnginePrivate * const d = d_func();-
1386 d->writeTail();-
1387-
1388 d->stream->unsetDevice();-
1389-
1390 qDeleteAll(d->fonts);-
1391 d->fonts.clear();-
1392 delete d->currentPage;-
1393 d->currentPage = 0;-
1394-
1395 if (d->outDevice
d->outDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->ownsDevice
d->ownsDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1396 d->outDevice->close();-
1397 delete d->outDevice;-
1398 d->outDevice = 0;-
1399 }
never executed: end of block
0
1400-
1401 setActive(false);-
1402 return
never executed: return true;
true;
never executed: return true;
0
1403}-
1404-
1405QPdfEnginePrivate::~QPdfEnginePrivate()-
1406{-
1407 qDeleteAll(fonts);-
1408 delete currentPage;-
1409 delete stream;-
1410}
never executed: end of block
0
1411-
1412void QPdfEnginePrivate::writeHeader()-
1413{-
1414 addXrefEntry(0,false);-
1415-
1416 xprintf("%%PDF-1.4\n");-
1417-
1418 writeInfo();-
1419-
1420 catalog = addXrefEntry(-1);-
1421 pageRoot = requestObject();-
1422 xprintf("<<\n"-
1423 "/Type /Catalog\n"-
1424 "/Pages %d 0 R\n"-
1425 ">>\n"-
1426 "endobj\n", pageRoot);-
1427-
1428-
1429 graphicsState = addXrefEntry(-1);-
1430 xprintf("<<\n"-
1431 "/Type /ExtGState\n"-
1432 "/SA true\n"-
1433 "/SM 0.02\n"-
1434 "/ca 1.0\n"-
1435 "/CA 1.0\n"-
1436 "/AIS false\n"-
1437 "/SMask /None"-
1438 ">>\n"-
1439 "endobj\n");-
1440-
1441-
1442 patternColorSpace = addXrefEntry(-1);-
1443 xprintf("[/Pattern /DeviceRGB]\n"-
1444 "endobj\n");-
1445}
never executed: end of block
0
1446-
1447void QPdfEnginePrivate::writeInfo()-
1448{-
1449 info = addXrefEntry(-1);-
1450 xprintf("<<\n/Title ");-
1451 printString(title);-
1452 xprintf("\n/Creator ");-
1453 printString(creator);-
1454 xprintf("\n/Producer ");-
1455 printString(QString::fromLatin1("Qt " "5.7.1"));-
1456 QDateTime now = QDateTime::currentDateTimeUtc();-
1457 QTime t = now.time();-
1458 QDate d = now.date();-
1459 xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",-
1460 d.year(),-
1461 d.month(),-
1462 d.day(),-
1463 t.hour(),-
1464 t.minute(),-
1465 t.second());-
1466 xprintf(">>\n"-
1467 "endobj\n");-
1468}
never executed: end of block
0
1469-
1470void QPdfEnginePrivate::writePageRoot()-
1471{-
1472 addXrefEntry(pageRoot);-
1473-
1474 xprintf("<<\n"-
1475 "/Type /Pages\n"-
1476 "/Kids \n"-
1477 "[\n");-
1478 int size = pages.size();-
1479 for (int i = 0; i < size
i < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1480 xprintf("%d 0 R\n", pages[i]);
never executed: xprintf("%d 0 R\n", pages[i]);
0
1481 xprintf("]\n");-
1482-
1483-
1484 xprintf("/Count %d\n", pages.size());-
1485-
1486 xprintf("/ProcSet [/PDF /Text /ImageB /ImageC]\n"-
1487 ">>\n"-
1488 "endobj\n");-
1489}
never executed: end of block
0
1490-
1491-
1492void QPdfEnginePrivate::embedFont(QFontSubset *font)-
1493{-
1494-
1495 int fontObject = font->object_id;-
1496 QByteArray fontData = font->toTruetype();-
1497 int fontDescriptor = requestObject();-
1498 int fontstream = requestObject();-
1499 int cidfont = requestObject();-
1500 int toUnicode = requestObject();-
1501-
1502 QFontEngine::Properties properties = font->fontEngine->properties();-
1503 QByteArray postscriptName = properties.postscriptName.replace(' ', '_');-
1504-
1505 {-
1506 qreal scale = 1000/properties.emSquare.toReal();-
1507 addXrefEntry(fontDescriptor);-
1508 QByteArray descriptor;-
1509 QPdf::ByteStream s(&descriptor);-
1510 s << "<< /Type /FontDescriptor\n"-
1511 "/FontName /Q";-
1512 int tag = fontDescriptor;-
1513 for (int i = 0; i < 5
i < 5Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1514 s << (char)('A' + (tag % 26));-
1515 tag /= 26;-
1516 }
never executed: end of block
0
1517 s << '+' << postscriptName << "\n"-
1518 "/Flags " << 4 << "\n"-
1519 "/FontBBox ["-
1520 << properties.boundingBox.x()*scale-
1521 << -(properties.boundingBox.y() + properties.boundingBox.height())*scale-
1522 << (properties.boundingBox.x() + properties.boundingBox.width())*scale-
1523 << -properties.boundingBox.y()*scale << "]\n"-
1524 "/ItalicAngle " << properties.italicAngle.toReal() << "\n"-
1525 "/Ascent " << properties.ascent.toReal()*scale << "\n"-
1526 "/Descent " << -properties.descent.toReal()*scale << "\n"-
1527 "/CapHeight " << properties.capHeight.toReal()*scale << "\n"-
1528 "/StemV " << properties.lineWidth.toReal()*scale << "\n"-
1529 "/FontFile2 " << fontstream << "0 R\n"-
1530 ">> endobj\n";-
1531 write(descriptor);-
1532 }-
1533 {-
1534 addXrefEntry(fontstream);-
1535 QByteArray header;-
1536 QPdf::ByteStream s(&header);-
1537-
1538 int length_object = requestObject();-
1539 s << "<<\n"-
1540 "/Length1 " << fontData.size() << "\n"-
1541 "/Length " << length_object << "0 R\n";-
1542 if (do_compress
do_compressDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1543 s << "/Filter /FlateDecode\n";
never executed: s << "/Filter /FlateDecode\n";
0
1544 s << ">>\n"-
1545 "stream\n";-
1546 write(header);-
1547 int len = writeCompressed(fontData);-
1548 write("endstream\n"-
1549 "endobj\n");-
1550 addXrefEntry(length_object);-
1551 xprintf("%d\n"-
1552 "endobj\n", len);-
1553 }-
1554 {-
1555 addXrefEntry(cidfont);-
1556 QByteArray cid;-
1557 QPdf::ByteStream s(&cid);-
1558 s << "<< /Type /Font\n"-
1559 "/Subtype /CIDFontType2\n"-
1560 "/BaseFont /" << postscriptName << "\n"-
1561 "/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>\n"-
1562 "/FontDescriptor " << fontDescriptor << "0 R\n"-
1563 "/CIDToGIDMap /Identity\n"-
1564 << font->widthArray() <<-
1565 ">>\n"-
1566 "endobj\n";-
1567 write(cid);-
1568 }-
1569 {-
1570 addXrefEntry(toUnicode);-
1571 QByteArray touc = font->createToUnicodeMap();-
1572 xprintf("<< /Length %d >>\n"-
1573 "stream\n", touc.length());-
1574 write(touc);-
1575 write("endstream\n"-
1576 "endobj\n");-
1577 }-
1578 {-
1579 addXrefEntry(fontObject);-
1580 QByteArray font;-
1581 QPdf::ByteStream s(&font);-
1582 s << "<< /Type /Font\n"-
1583 "/Subtype /Type0\n"-
1584 "/BaseFont /" << postscriptName << "\n"-
1585 "/Encoding /Identity-H\n"-
1586 "/DescendantFonts [" << cidfont << "0 R]\n"-
1587 "/ToUnicode " << toUnicode << "0 R"-
1588 ">>\n"-
1589 "endobj\n";-
1590 write(font);-
1591 }-
1592}
never executed: end of block
0
1593-
1594-
1595void QPdfEnginePrivate::writeFonts()-
1596{-
1597 for (QHash<QFontEngine::FaceId, QFontSubset *>::iterator it = fonts.begin(); it != fonts.end()
it != fonts.end()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it) {
0
1598 embedFont(*it);-
1599 delete *it;-
1600 }
never executed: end of block
0
1601 fonts.clear();-
1602}
never executed: end of block
0
1603-
1604void QPdfEnginePrivate::writePage()-
1605{-
1606 if (pages.empty()
pages.empty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1607 return;
never executed: return;
0
1608-
1609 *currentPage << "Q Q\n";-
1610-
1611 uint pageStream = requestObject();-
1612 uint pageStreamLength = requestObject();-
1613 uint resources = requestObject();-
1614 uint annots = requestObject();-
1615-
1616 addXrefEntry(pages.constLast());-
1617 xprintf("<<\n"-
1618 "/Type /Page\n"-
1619 "/Parent %d 0 R\n"-
1620 "/Contents %d 0 R\n"-
1621 "/Resources %d 0 R\n"-
1622 "/Annots %d 0 R\n"-
1623 "/MediaBox [0 0 %d %d]\n"-
1624 ">>\n"-
1625 "endobj\n",-
1626 pageRoot, pageStream, resources, annots,-
1627-
1628 currentPage->pageSize.width(), currentPage->pageSize.height());-
1629-
1630 addXrefEntry(resources);-
1631 xprintf("<<\n"-
1632 "/ColorSpace <<\n"-
1633 "/PCSp %d 0 R\n"-
1634 "/CSp /DeviceRGB\n"-
1635 "/CSpg /DeviceGray\n"-
1636 ">>\n"-
1637 "/ExtGState <<\n"-
1638 "/GSa %d 0 R\n",-
1639 patternColorSpace, graphicsState);-
1640-
1641 for (int i = 0; i < currentPage->graphicStates.size()
i < currentPag...cStates.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1642 xprintf("/GState%d %d 0 R\n", currentPage->graphicStates.at(i), currentPage->graphicStates.at(i));
never executed: xprintf("/GState%d %d 0 R\n", currentPage->graphicStates.at(i), currentPage->graphicStates.at(i));
0
1643 xprintf(">>\n");-
1644-
1645 xprintf("/Pattern <<\n");-
1646 for (int i = 0; i < currentPage->patterns.size()
i < currentPag...atterns.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1647 xprintf("/Pat%d %d 0 R\n", currentPage->patterns.at(i), currentPage->patterns.at(i));
never executed: xprintf("/Pat%d %d 0 R\n", currentPage->patterns.at(i), currentPage->patterns.at(i));
0
1648 xprintf(">>\n");-
1649-
1650 xprintf("/Font <<\n");-
1651 for (int i = 0; i < currentPage->fonts.size()
i < currentPage->fonts.size()Description
TRUEnever evaluated
FALSEnever evaluated
;++i)
0
1652 xprintf("/F%d %d 0 R\n", currentPage->fonts[i], currentPage->fonts[i]);
never executed: xprintf("/F%d %d 0 R\n", currentPage->fonts[i], currentPage->fonts[i]);
0
1653 xprintf(">>\n");-
1654-
1655 xprintf("/XObject <<\n");-
1656 for (int i = 0; i<currentPage->images.size()
i<currentPage->images.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1657 xprintf("/Im%d %d 0 R\n", currentPage->images.at(i), currentPage->images.at(i));-
1658 }
never executed: end of block
0
1659 xprintf(">>\n");-
1660-
1661 xprintf(">>\n"-
1662 "endobj\n");-
1663-
1664 addXrefEntry(annots);-
1665 xprintf("[ ");-
1666 for (int i = 0; i<currentPage->annotations.size()
i<currentPage-...tations.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1667 xprintf("%d 0 R ", currentPage->annotations.at(i));-
1668 }
never executed: end of block
0
1669 xprintf("]\nendobj\n");-
1670-
1671 addXrefEntry(pageStream);-
1672 xprintf("<<\n"-
1673 "/Length %d 0 R\n", pageStreamLength);-
1674 if (do_compress
do_compressDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1675 xprintf("/Filter /FlateDecode\n");
never executed: xprintf("/Filter /FlateDecode\n");
0
1676-
1677 xprintf(">>\n");-
1678 xprintf("stream\n");-
1679 QIODevice *content = currentPage->stream();-
1680 int len = writeCompressed(content);-
1681 xprintf("endstream\n"-
1682 "endobj\n");-
1683-
1684 addXrefEntry(pageStreamLength);-
1685 xprintf("%d\nendobj\n",len);-
1686}
never executed: end of block
0
1687-
1688void QPdfEnginePrivate::writeTail()-
1689{-
1690 writePage();-
1691 writeFonts();-
1692 writePageRoot();-
1693 addXrefEntry(xrefPositions.size(),false);-
1694 xprintf("xref\n"-
1695 "0 %d\n"-
1696 "%010d 65535 f \n", xrefPositions.size()-1, xrefPositions[0]);-
1697-
1698 for (int i = 1; i < xrefPositions.size()-1
i < xrefPositions.size()-1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1699 xprintf("%010d 00000 n \n", xrefPositions[i]);
never executed: xprintf("%010d 00000 n \n", xrefPositions[i]);
0
1700-
1701 xprintf("trailer\n"-
1702 "<<\n"-
1703 "/Size %d\n"-
1704 "/Info %d 0 R\n"-
1705 "/Root %d 0 R\n"-
1706 ">>\n"-
1707 "startxref\n%d\n"-
1708 "%%%%EOF\n",-
1709 xrefPositions.size()-1, info, catalog, xrefPositions.constLast());-
1710}
never executed: end of block
0
1711-
1712int QPdfEnginePrivate::addXrefEntry(int object, bool printostr)-
1713{-
1714 if (object < 0
object < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1715 object = requestObject();
never executed: object = requestObject();
0
1716-
1717 if (object>=xrefPositions.size()
object>=xrefPositions.size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1718 xrefPositions.resize(object+1);
never executed: xrefPositions.resize(object+1);
0
1719-
1720 xrefPositions[object] = streampos;-
1721 if (printostr
printostrDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1722 xprintf("%d 0 obj\n",object);
never executed: xprintf("%d 0 obj\n",object);
0
1723-
1724 return
never executed: return object;
object;
never executed: return object;
0
1725}-
1726-
1727void QPdfEnginePrivate::printString(const QString &string) {-
1728-
1729-
1730-
1731 QByteArray array("(\xfe\xff");-
1732 const ushort *utf16 = string.utf16();-
1733-
1734 for (int i=0; i < string.size()
i < string.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1735 char part[2] = {char((*(utf16 + i)) >> 8), char((*(utf16 + i)) & 0xff)};-
1736 for(int j=0; j < 2
j < 2Description
TRUEnever evaluated
FALSEnever evaluated
; ++j) {
0
1737 if (part[j] == '('
part[j] == '('Description
TRUEnever evaluated
FALSEnever evaluated
|| part[j] == ')'
part[j] == ')'Description
TRUEnever evaluated
FALSEnever evaluated
|| part[j] == '\\'
part[j] == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1738 array.append('\\');
never executed: array.append('\\');
0
1739 array.append(part[j]);-
1740 }
never executed: end of block
0
1741 }
never executed: end of block
0
1742 array.append(')');-
1743 write(array);-
1744}
never executed: end of block
0
1745-
1746-
1747-
1748void QPdfEnginePrivate::xprintf(const char* fmt, ...)-
1749{-
1750 if (!stream
!streamDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1751 return;
never executed: return;
0
1752-
1753 const int msize = 10000;-
1754 char buf[msize];-
1755-
1756 va_list args;-
1757 __builtin_va_start(args,fmt);-
1758 int bufsize = qvsnprintf(buf, msize, fmt, args);-
1759-
1760 ((!(bufsize<msize)) ? qt_assert("bufsize<msize",__FILE__,1822) : qt_noop());-
1761-
1762 __builtin_va_end(args);-
1763-
1764 stream->writeRawData(buf, bufsize);-
1765 streampos += bufsize;-
1766}
never executed: end of block
0
1767-
1768int QPdfEnginePrivate::writeCompressed(QIODevice *dev)-
1769{-
1770-
1771 if (do_compress
do_compressDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1772 int size = QPdfPage::chunkSize();-
1773 int sum = 0;-
1774 ::z_stream zStruct;-
1775 zStruct.zalloc = 0;-
1776 zStruct.zfree = 0;-
1777 zStruct.opaque = 0;-
1778 if (::
::deflateInit_..._stream)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
deflateInit_((&zStruct), ((-1)), "1.2.8", (int)sizeof(z_stream)) != 0
::deflateInit_..._stream)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1779 QMessageLogger(__FILE__, 1841, __PRETTY_FUNCTION__).warning("QPdfStream::writeCompressed: Error in deflateInit()");-
1780 return
never executed: return sum;
sum;
never executed: return sum;
0
1781 }-
1782 zStruct.avail_in = 0;-
1783 QByteArray in, out;-
1784 out.resize(size);-
1785 while (!dev->atEnd()
!dev->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
|| zStruct.avail_in != 0
zStruct.avail_in != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1786 if (zStruct.avail_in == 0
zStruct.avail_in == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1787 in = dev->read(size);-
1788 zStruct.avail_in = in.size();-
1789 zStruct.next_in = reinterpret_cast<unsigned char*>(in.data());-
1790 if (in.size() <= 0
in.size() <= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1791 QMessageLogger(__FILE__, 1853, __PRETTY_FUNCTION__).warning("QPdfStream::writeCompressed: Error in read()");-
1792 ::deflateEnd(&zStruct);-
1793 return
never executed: return sum;
sum;
never executed: return sum;
0
1794 }-
1795 }
never executed: end of block
0
1796 zStruct.next_out = reinterpret_cast<unsigned char*>(out.data());-
1797 zStruct.avail_out = out.size();-
1798 if (::
::deflate(&zStruct, 0) != 0Description
TRUEnever evaluated
FALSEnever evaluated
deflate(&zStruct, 0) != 0
::deflate(&zStruct, 0) != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1799 QMessageLogger(__FILE__, 1861, __PRETTY_FUNCTION__).warning("QPdfStream::writeCompressed: Error in deflate()");-
1800 ::deflateEnd(&zStruct);-
1801 return
never executed: return sum;
sum;
never executed: return sum;
0
1802 }-
1803 int written = out.size() - zStruct.avail_out;-
1804 stream->writeRawData(out.constData(), written);-
1805 streampos += written;-
1806 sum += written;-
1807 }
never executed: end of block
0
1808 int ret;-
1809 do {-
1810 zStruct.next_out = reinterpret_cast<unsigned char*>(out.data());-
1811 zStruct.avail_out = out.size();-
1812 ret = ::deflate(&zStruct, 4);-
1813 if (ret != 0
ret != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& ret != 1
ret != 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1814 QMessageLogger(__FILE__, 1876, __PRETTY_FUNCTION__).warning("QPdfStream::writeCompressed: Error in deflate()");-
1815 ::deflateEnd(&zStruct);-
1816 return
never executed: return sum;
sum;
never executed: return sum;
0
1817 }-
1818 int written = out.size() - zStruct.avail_out;-
1819 stream->writeRawData(out.constData(), written);-
1820 streampos += written;-
1821 sum += written;-
1822 }
never executed: end of block
while (ret == 0
ret == 0Description
TRUEnever evaluated
FALSEnever evaluated
);
0
1823-
1824 ::deflateEnd(&zStruct);-
1825-
1826 return
never executed: return sum;
sum;
never executed: return sum;
0
1827 } else-
1828-
1829 {-
1830 QByteArray arr;-
1831 int sum = 0;-
1832 while (!dev->atEnd()
!dev->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1833 arr = dev->read(QPdfPage::chunkSize());-
1834 stream->writeRawData(arr.constData(), arr.size());-
1835 streampos += arr.size();-
1836 sum += arr.size();-
1837 }
never executed: end of block
0
1838 return
never executed: return sum;
sum;
never executed: return sum;
0
1839 }-
1840}-
1841-
1842int QPdfEnginePrivate::writeCompressed(const char *src, int len)-
1843{-
1844-
1845 if(do_compress
do_compressDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1846 uLongf destLen = len + len/100 + 13;-
1847 Bytef* dest = new Bytef[destLen];-
1848 if (0 == ::compress(dest, &destLen, (const Bytef*) src, (uLongf)len)
0 == ::compres..., (uLongf)len)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1849 stream->writeRawData((const char*)dest, destLen);-
1850 }
never executed: end of block
else {
0
1851 QMessageLogger(__FILE__, 1913, __PRETTY_FUNCTION__).warning("QPdfStream::writeCompressed: Error in compress()");-
1852 destLen = 0;-
1853 }
never executed: end of block
0
1854 delete [] dest;-
1855 len = destLen;-
1856 }
never executed: end of block
else
0
1857-
1858 {-
1859 stream->writeRawData(src,len);-
1860 }
never executed: end of block
0
1861 streampos += len;-
1862 return
never executed: return len;
len;
never executed: return len;
0
1863}-
1864-
1865int QPdfEnginePrivate::writeImage(const QByteArray &data, int width, int height, int depth,-
1866 int maskObject, int softMaskObject, bool dct, bool isMono)-
1867{-
1868 int image = addXrefEntry(-1);-
1869 xprintf("<<\n"-
1870 "/Type /XObject\n"-
1871 "/Subtype /Image\n"-
1872 "/Width %d\n"-
1873 "/Height %d\n", width, height);-
1874-
1875 if (depth == 1
depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1876 if (!isMono
!isMonoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1877 xprintf("/ImageMask true\n"-
1878 "/Decode [1 0]\n");-
1879 }
never executed: end of block
else {
0
1880 xprintf("/BitsPerComponent 1\n"-
1881 "/ColorSpace /DeviceGray\n");-
1882 }
never executed: end of block
0
1883 } else {-
1884 xprintf("/BitsPerComponent 8\n"-
1885 "/ColorSpace %s\n", (depth == 32) ? "/DeviceRGB" : "/DeviceGray");-
1886 }
never executed: end of block
0
1887 if (maskObject > 0
maskObject > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1888 xprintf("/Mask %d 0 R\n", maskObject);
never executed: xprintf("/Mask %d 0 R\n", maskObject);
0
1889 if (softMaskObject > 0
softMaskObject > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1890 xprintf("/SMask %d 0 R\n", softMaskObject);
never executed: xprintf("/SMask %d 0 R\n", softMaskObject);
0
1891-
1892 int lenobj = requestObject();-
1893 xprintf("/Length %d 0 R\n", lenobj);-
1894 if (interpolateImages
interpolateImagesDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1895 xprintf("/Interpolate true\n");
never executed: xprintf("/Interpolate true\n");
0
1896 int len = 0;-
1897 if (dct
dctDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1898-
1899 xprintf("/Filter /DCTDecode\n>>\nstream\n");-
1900 write(data);-
1901 len = data.length();-
1902 }
never executed: end of block
else {
0
1903 if (do_compress
do_compressDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1904 xprintf("/Filter /FlateDecode\n>>\nstream\n");
never executed: xprintf("/Filter /FlateDecode\n>>\nstream\n");
0
1905 else-
1906 xprintf(">>\nstream\n");
never executed: xprintf(">>\nstream\n");
0
1907 len = writeCompressed(data);-
1908 }
never executed: end of block
0
1909 xprintf("endstream\n"-
1910 "endobj\n");-
1911 addXrefEntry(lenobj);-
1912 xprintf("%d\n"-
1913 "endobj\n", len);-
1914 return
never executed: return image;
image;
never executed: return image;
0
1915}-
1916-
1917struct QGradientBound {-
1918 qreal start;-
1919 qreal stop;-
1920 int function;-
1921 bool reverse;-
1922};-
1923template<> class QTypeInfo<QGradientBound > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QGradientBound)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QGradientBound >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QGradientBound) }; static inline const char *name() { return "QGradientBound"; } };-
1924-
1925int QPdfEnginePrivate::createShadingFunction(const QGradient *gradient, int from, int to, bool reflect, bool alpha)-
1926{-
1927 QGradientStops stops = gradient->stops();-
1928 if (stops.isEmpty()
stops.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1929 stops << QGradientStop(0, Qt::black);-
1930 stops << QGradientStop(1, Qt::white);-
1931 }
never executed: end of block
0
1932 if (stops.at(0).first > 0
stops.at(0).first > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1933 stops.prepend(QGradientStop(0, stops.at(0).second));
never executed: stops.prepend(QGradientStop(0, stops.at(0).second));
0
1934 if (stops.at(stops.size() - 1).first < 1
stops.at(stops...- 1).first < 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1935 stops.append(QGradientStop(1, stops.at(stops.size() - 1).second));
never executed: stops.append(QGradientStop(1, stops.at(stops.size() - 1).second));
0
1936-
1937 QVector<int> functions;-
1938 const int numStops = stops.size();-
1939 functions.reserve(numStops - 1);-
1940 for (int i = 0; i < numStops - 1
i < numStops - 1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1941 int f = addXrefEntry(-1);-
1942 QByteArray data;-
1943 QPdf::ByteStream s(&data);-
1944 s << "<<\n"-
1945 "/FunctionType 2\n"-
1946 "/Domain [0 1]\n"-
1947 "/N 1\n";-
1948 if (alpha
alphaDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1949 s << "/C0 [" << stops.at(i).second.alphaF() << "]\n"-
1950 "/C1 [" << stops.at(i + 1).second.alphaF() << "]\n";-
1951 }
never executed: end of block
else {
0
1952 s << "/C0 [" << stops.at(i).second.redF() << stops.at(i).second.greenF() << stops.at(i).second.blueF() << "]\n"-
1953 "/C1 [" << stops.at(i + 1).second.redF() << stops.at(i + 1).second.greenF() << stops.at(i + 1).second.blueF() << "]\n";-
1954 }
never executed: end of block
0
1955 s << ">>\n"-
1956 "endobj\n";-
1957 write(data);-
1958 functions << f;-
1959 }
never executed: end of block
0
1960-
1961 QVector<QGradientBound> gradientBounds;-
1962 gradientBounds.reserve((to - from) * (numStops - 1));-
1963-
1964 for (int step = from; step < to
step < toDescription
TRUEnever evaluated
FALSEnever evaluated
; ++step) {
0
1965 if (reflect
reflectDescription
TRUEnever evaluated
FALSEnever evaluated
&& step % 2
step % 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1966 for (int i = numStops - 1; i > 0
i > 0Description
TRUEnever evaluated
FALSEnever evaluated
; --i) {
0
1967 QGradientBound b;-
1968 b.start = step + 1 - qBound(qreal(0.), stops.at(i).first, qreal(1.));-
1969 b.stop = step + 1 - qBound(qreal(0.), stops.at(i - 1).first, qreal(1.));-
1970 b.function = functions.at(i - 1);-
1971 b.reverse = true;-
1972 gradientBounds << b;-
1973 }
never executed: end of block
0
1974 }
never executed: end of block
else {
0
1975 for (int i = 0; i < numStops - 1
i < numStops - 1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1976 QGradientBound b;-
1977 b.start = step + qBound(qreal(0.), stops.at(i).first, qreal(1.));-
1978 b.stop = step + qBound(qreal(0.), stops.at(i + 1).first, qreal(1.));-
1979 b.function = functions.at(i);-
1980 b.reverse = false;-
1981 gradientBounds << b;-
1982 }
never executed: end of block
0
1983 }
never executed: end of block
0
1984 }-
1985-
1986-
1987 qreal bstart = gradientBounds.at(0).start;-
1988 qreal bend = gradientBounds.at(gradientBounds.size() - 1).stop;-
1989 qreal norm = 1./(bend - bstart);-
1990 for (int i = 0; i < gradientBounds.size()
i < gradientBounds.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1991 gradientBounds[i].start = (gradientBounds[i].start - bstart)*norm;-
1992 gradientBounds[i].stop = (gradientBounds[i].stop - bstart)*norm;-
1993 }
never executed: end of block
0
1994-
1995 int function;-
1996 if (gradientBounds.size() > 1
gradientBounds.size() > 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1997 function = addXrefEntry(-1);-
1998 QByteArray data;-
1999 QPdf::ByteStream s(&data);-
2000 s << "<<\n"-
2001 "/FunctionType 3\n"-
2002 "/Domain [0 1]\n"-
2003 "/Bounds [";-
2004 for (int i = 1; i < gradientBounds.size()
i < gradientBounds.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
2005 s << gradientBounds.at(i).start;
never executed: s << gradientBounds.at(i).start;
0
2006 s << "]\n"-
2007 "/Encode [";-
2008 for (int i = 0; i < gradientBounds.size()
i < gradientBounds.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
2009 s << (gradientBounds.at(i).reverse ? "1 0 " : "0 1 ");
never executed: s << (gradientBounds.at(i).reverse ? "1 0 " : "0 1 ");
0
2010 s << "]\n"-
2011 "/Functions [";-
2012 for (int i = 0; i < gradientBounds.size()
i < gradientBounds.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
2013 s << gradientBounds.at(i).function << "0 R ";
never executed: s << gradientBounds.at(i).function << "0 R ";
0
2014 s << "]\n"-
2015 ">>\n";-
2016 write(data);-
2017 }
never executed: end of block
else {
0
2018 function = functions.at(0);-
2019 }
never executed: end of block
0
2020 return
never executed: return function;
function;
never executed: return function;
0
2021}-
2022-
2023int QPdfEnginePrivate::generateLinearGradientShader(const QLinearGradient *gradient, const QTransform &matrix, bool alpha)-
2024{-
2025 QPointF start = gradient->start();-
2026 QPointF stop = gradient->finalStop();-
2027 QPointF offset = stop - start;-
2028 ((!(gradient->coordinateMode() == QGradient::LogicalMode)) ? qt_assert("gradient->coordinateMode() == QGradient::LogicalMode",__FILE__,2090) : qt_noop());-
2029-
2030 int from = 0;-
2031 int to = 1;-
2032 bool reflect = false;-
2033 switch (gradient->spread()) {-
2034 case
never executed: case QGradient::PadSpread:
QGradient::PadSpread:
never executed: case QGradient::PadSpread:
0
2035 break;
never executed: break;
0
2036 case
never executed: case QGradient::ReflectSpread:
QGradient::ReflectSpread:
never executed: case QGradient::ReflectSpread:
0
2037 reflect = true;-
2038-
2039 case
never executed: case QGradient::RepeatSpread:
QGradient::RepeatSpread:
never executed: case QGradient::RepeatSpread:
code before this statement never executed: case QGradient::RepeatSpread:
{
0
2040-
2041 QRectF pageRect = m_pageLayout.fullRectPixels(resolution);-
2042 QTransform inv = matrix.inverted();-
2043 QPointF page_rect[4] = { inv.map(pageRect.topLeft()),-
2044 inv.map(pageRect.topRight()),-
2045 inv.map(pageRect.bottomLeft()),-
2046 inv.map(pageRect.bottomRight()) };-
2047-
2048 qreal length = offset.x()*offset.x() + offset.y()*offset.y();-
2049-
2050-
2051-
2052 from = 2147483647;-
2053 to = (-2147483647 - 1);-
2054 for (int i = 0; i < 4
i < 4Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2055 qreal off = ((page_rect[i].x() - start.x()) * offset.x() + (page_rect[i].y() - start.y()) * offset.y())/length;-
2056 from = qMin(from, qFloor(off));-
2057 to = qMax(to, qCeil(off));-
2058 }
never executed: end of block
0
2059-
2060 stop = start + to * offset;-
2061 start = start + from * offset;-
2062 break;
never executed: break;
0
2063 }-
2064 }-
2065-
2066 int function = createShadingFunction(gradient, from, to, reflect, alpha);-
2067-
2068 QByteArray shader;-
2069 QPdf::ByteStream s(&shader);-
2070 s << "<<\n"-
2071 "/ShadingType 2\n"-
2072 "/ColorSpace " << (alpha ? "/DeviceGray\n" : "/DeviceRGB\n") <<-
2073 "/AntiAlias true\n"-
2074 "/Coords [" << start.x() << start.y() << stop.x() << stop.y() << "]\n"-
2075 "/Extend [true true]\n"-
2076 "/Function " << function << "0 R\n"-
2077 ">>\n"-
2078 "endobj\n";-
2079 int shaderObject = addXrefEntry(-1);-
2080 write(shader);-
2081 return
never executed: return shaderObject;
shaderObject;
never executed: return shaderObject;
0
2082}-
2083-
2084int QPdfEnginePrivate::generateRadialGradientShader(const QRadialGradient *gradient, const QTransform &matrix, bool alpha)-
2085{-
2086 QPointF p1 = gradient->center();-
2087 qreal r1 = gradient->centerRadius();-
2088 QPointF p0 = gradient->focalPoint();-
2089 qreal r0 = gradient->focalRadius();-
2090-
2091 ((!(gradient->coordinateMode() == QGradient::LogicalMode)) ? qt_assert("gradient->coordinateMode() == QGradient::LogicalMode",__FILE__,2153) : qt_noop());-
2092-
2093 int from = 0;-
2094 int to = 1;-
2095 bool reflect = false;-
2096 switch (gradient->spread()) {-
2097 case
never executed: case QGradient::PadSpread:
QGradient::PadSpread:
never executed: case QGradient::PadSpread:
0
2098 break;
never executed: break;
0
2099 case
never executed: case QGradient::ReflectSpread:
QGradient::ReflectSpread:
never executed: case QGradient::ReflectSpread:
0
2100 reflect = true;-
2101-
2102 case
never executed: case QGradient::RepeatSpread:
QGradient::RepeatSpread:
never executed: case QGradient::RepeatSpread:
code before this statement never executed: case QGradient::RepeatSpread:
{
0
2103 ((!(qFuzzyIsNull(r0))) ? qt_assert("qFuzzyIsNull(r0)",__FILE__,2165) : qt_noop());-
2104-
2105 QRectF pageRect = m_pageLayout.fullRectPixels(resolution);-
2106 QTransform inv = matrix.inverted();-
2107 QPointF page_rect[4] = { inv.map(pageRect.topLeft()),-
2108 inv.map(pageRect.topRight()),-
2109 inv.map(pageRect.bottomLeft()),-
2110 inv.map(pageRect.bottomRight()) };-
2111-
2112-
2113 bool done = false;-
2114 while (!done
!doneDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2115 QPointF center = QPointF(p0.x() + to*(p1.x() - p0.x()), p0.y() + to*(p1.y() - p0.y()));-
2116 double radius = r0 + to*(r1 - r0);-
2117 double r2 = radius*radius;-
2118 done = true;-
2119 for (int i = 0; i < 4
i < 4Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2120 QPointF off = page_rect[i] - center;-
2121 if (off.x()*off.x() + off.y()*off.y() > r2
off.x()*off.x(...)*off.y() > r2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2122 ++to;-
2123 done = false;-
2124 break;
never executed: break;
0
2125 }-
2126 }
never executed: end of block
0
2127 }
never executed: end of block
0
2128 p1 = QPointF(p0.x() + to*(p1.x() - p0.x()), p0.y() + to*(p1.y() - p0.y()));-
2129 r1 = r0 + to*(r1 - r0);-
2130 break;
never executed: break;
0
2131 }-
2132 }-
2133-
2134 int function = createShadingFunction(gradient, from, to, reflect, alpha);-
2135-
2136 QByteArray shader;-
2137 QPdf::ByteStream s(&shader);-
2138 s << "<<\n"-
2139 "/ShadingType 3\n"-
2140 "/ColorSpace " << (alpha ? "/DeviceGray\n" : "/DeviceRGB\n") <<-
2141 "/AntiAlias true\n"-
2142 "/Domain [0 1]\n"-
2143 "/Coords [" << p0.x() << p0.y() << r0 << p1.x() << p1.y() << r1 << "]\n"-
2144 "/Extend [true true]\n"-
2145 "/Function " << function << "0 R\n"-
2146 ">>\n"-
2147 "endobj\n";-
2148 int shaderObject = addXrefEntry(-1);-
2149 write(shader);-
2150 return
never executed: return shaderObject;
shaderObject;
never executed: return shaderObject;
0
2151}-
2152-
2153int QPdfEnginePrivate::generateGradientShader(const QGradient *gradient, const QTransform &matrix, bool alpha)-
2154{-
2155 switch (gradient->type()) {-
2156 case
never executed: case QGradient::LinearGradient:
QGradient::LinearGradient:
never executed: case QGradient::LinearGradient:
0
2157 return
never executed: return generateLinearGradientShader(static_cast<const QLinearGradient *>(gradient), matrix, alpha);
generateLinearGradientShader(static_cast<const QLinearGradient *>(gradient), matrix, alpha);
never executed: return generateLinearGradientShader(static_cast<const QLinearGradient *>(gradient), matrix, alpha);
0
2158 case
never executed: case QGradient::RadialGradient:
QGradient::RadialGradient:
never executed: case QGradient::RadialGradient:
0
2159 return
never executed: return generateRadialGradientShader(static_cast<const QRadialGradient *>(gradient), matrix, alpha);
generateRadialGradientShader(static_cast<const QRadialGradient *>(gradient), matrix, alpha);
never executed: return generateRadialGradientShader(static_cast<const QRadialGradient *>(gradient), matrix, alpha);
0
2160 case
never executed: case QGradient::ConicalGradient:
QGradient::ConicalGradient:
never executed: case QGradient::ConicalGradient:
0
2161 QMessageLogger(__FILE__, 2223, __PRETTY_FUNCTION__).warning("Unimplemented code.");-
2162 break;
never executed: break;
0
2163 case
never executed: case QGradient::NoGradient:
QGradient::NoGradient:
never executed: case QGradient::NoGradient:
0
2164 break;
never executed: break;
0
2165 }-
2166 return
never executed: return 0;
0;
never executed: return 0;
0
2167}-
2168-
2169int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QTransform &matrix, int *gStateObject)-
2170{-
2171 const QGradient *gradient = b.gradient();-
2172-
2173 if (!gradient
!gradientDescription
TRUEnever evaluated
FALSEnever evaluated
|| gradient->coordinateMode() != QGradient::LogicalMode
gradient->coor...t::LogicalModeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2174 return
never executed: return 0;
0;
never executed: return 0;
0
2175-
2176 QRectF pageRect = m_pageLayout.fullRectPixels(resolution);-
2177-
2178 QTransform m = b.transform() * matrix;-
2179 int shaderObject = generateGradientShader(gradient, m);-
2180-
2181 QByteArray str;-
2182 QPdf::ByteStream s(&str);-
2183 s << "<<\n"-
2184 "/Type /Pattern\n"-
2185 "/PatternType 2\n"-
2186 "/Shading " << shaderObject << "0 R\n"-
2187 "/Matrix ["-
2188 << m.m11()-
2189 << m.m12()-
2190 << m.m21()-
2191 << m.m22()-
2192 << m.dx()-
2193 << m.dy() << "]\n";-
2194 s << ">>\n"-
2195 "endobj\n";-
2196-
2197 int patternObj = addXrefEntry(-1);-
2198 write(str);-
2199 currentPage->patterns.append(patternObj);-
2200-
2201 if (!b.isOpaque()
!b.isOpaque()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2202 bool ca = true;-
2203 QGradientStops stops = gradient->stops();-
2204 int a = stops.at(0).second.alpha();-
2205 for (int i = 1; i < stops.size()
i < stops.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2206 if (stops.at(i).second.alpha() != a
stops.at(i).se...d.alpha() != aDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2207 ca = false;-
2208 break;
never executed: break;
0
2209 }-
2210 }
never executed: end of block
0
2211 if (ca
caDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2212 *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha());-
2213 }
never executed: end of block
else {
0
2214 int alphaShaderObject = generateGradientShader(gradient, m, true);-
2215-
2216 QByteArray content;-
2217 QPdf::ByteStream c(&content);-
2218 c << "/Shader" << alphaShaderObject << "sh\n";-
2219-
2220 QByteArray form;-
2221 QPdf::ByteStream f(&form);-
2222 f << "<<\n"-
2223 "/Type /XObject\n"-
2224 "/Subtype /Form\n"-
2225 "/BBox [0 0 " << pageRect.width() << pageRect.height() << "]\n"-
2226 "/Group <</S /Transparency >>\n"-
2227 "/Resources <<\n"-
2228 "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n"-
2229 ">>\n";-
2230-
2231 f << "/Length " << content.length() << "\n"-
2232 ">>\n"-
2233 "stream\n"-
2234 << content-
2235 << "endstream\n"-
2236 "endobj\n";-
2237-
2238 int softMaskFormObject = addXrefEntry(-1);-
2239 write(form);-
2240 *gStateObject = addXrefEntry(-1);-
2241 xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n"-
2242 "endobj\n", softMaskFormObject);-
2243 currentPage->graphicStates.append(*gStateObject);-
2244 }
never executed: end of block
0
2245 }-
2246-
2247 return
never executed: return patternObj;
patternObj;
never executed: return patternObj;
0
2248}-
2249-
2250int QPdfEnginePrivate::addConstantAlphaObject(int brushAlpha, int penAlpha)-
2251{-
2252 if (brushAlpha == 255
brushAlpha == 255Description
TRUEnever evaluated
FALSEnever evaluated
&& penAlpha == 255
penAlpha == 255Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2253 return
never executed: return 0;
0;
never executed: return 0;
0
2254 int object = alphaCache.value(QPair<uint, uint>(brushAlpha, penAlpha), 0);-
2255 if (!object
!objectDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2256 object = addXrefEntry(-1);-
2257 QByteArray alphaDef;-
2258 QPdf::ByteStream s(&alphaDef);-
2259 s << "<<\n/ca " << (brushAlpha/qreal(255.)) << '\n';-
2260 s << "/CA " << (penAlpha/qreal(255.)) << "\n>>";-
2261 xprintf("%s\nendobj\n", alphaDef.constData());-
2262 alphaCache.insert(QPair<uint, uint>(brushAlpha, penAlpha), object);-
2263 }
never executed: end of block
0
2264 if (currentPage->graphicStates.indexOf(object) < 0
currentPage->g...Of(object) < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2265 currentPage->graphicStates.append(object);
never executed: currentPage->graphicStates.append(object);
0
2266-
2267 return
never executed: return object;
object;
never executed: return object;
0
2268}-
2269-
2270-
2271int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor, int *gStateObject)-
2272{-
2273 int paintType = 2;-
2274 int w = 8;-
2275 int h = 8;-
2276-
2277 *specifyColor = true;-
2278 *gStateObject = 0;-
2279-
2280 QTransform matrix = m;-
2281 matrix.translate(brushOrigin.x(), brushOrigin.y());-
2282 matrix = matrix * pageMatrix();-
2283-
2284-
2285 Qt::BrushStyle style = brush.style();-
2286 if (style == Qt::LinearGradientPattern
style == Qt::L...radientPatternDescription
TRUEnever evaluated
FALSEnever evaluated
|| style == Qt::RadialGradientPattern
style == Qt::R...radientPatternDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2287 *specifyColor = false;-
2288 return
never executed: return gradientBrush(brush, matrix, gStateObject);
gradientBrush(brush, matrix, gStateObject);
never executed: return gradientBrush(brush, matrix, gStateObject);
0
2289 }-
2290-
2291 if ((!brush.isOpaque()
!brush.isOpaque()Description
TRUEnever evaluated
FALSEnever evaluated
&& brush.style() < Qt::LinearGradientPattern
brush.style() ...radientPatternDescription
TRUEnever evaluated
FALSEnever evaluated
) || opacity != 1.0
opacity != 1.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2292 *
never executed: *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity), qRound(pen.color().alpha() * opacity));
gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity),
never executed: *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity), qRound(pen.color().alpha() * opacity));
0
2293 qRound(pen.color().alpha() * opacity));
never executed: *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity), qRound(pen.color().alpha() * opacity));
0
2294-
2295 int imageObject = -1;-
2296 QByteArray pattern = QPdf::patternForBrush(brush);-
2297 if (pattern.isEmpty()
pattern.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2298 if (brush.style() != Qt::TexturePattern
brush.style() ...TexturePatternDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2299 return
never executed: return 0;
0;
never executed: return 0;
0
2300 QImage image = brush.textureImage();-
2301 bool bitmap = true;-
2302 imageObject = addImage(image, &bitmap, image.cacheKey());-
2303 if (imageObject != -1
imageObject != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2304 QImage::Format f = image.format();-
2305 if (f != QImage::Format_MonoLSB
f != QImage::Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
&& f != QImage::Format_Mono
f != QImage::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2306 paintType = 1;-
2307 *specifyColor = false;-
2308 }
never executed: end of block
0
2309 w = image.width();-
2310 h = image.height();-
2311 QTransform m(w, 0, 0, -h, 0, h);-
2312 QPdf::ByteStream s(&pattern);-
2313 s << QPdf::generateMatrix(m);-
2314 s << "/Im" << imageObject << " Do\n";-
2315 }
never executed: end of block
0
2316 }
never executed: end of block
0
2317-
2318 QByteArray str;-
2319 QPdf::ByteStream s(&str);-
2320 s << "<<\n"-
2321 "/Type /Pattern\n"-
2322 "/PatternType 1\n"-
2323 "/PaintType " << paintType << "\n"-
2324 "/TilingType 1\n"-
2325 "/BBox [0 0 " << w << h << "]\n"-
2326 "/XStep " << w << "\n"-
2327 "/YStep " << h << "\n"-
2328 "/Matrix ["-
2329 << matrix.m11()-
2330 << matrix.m12()-
2331 << matrix.m21()-
2332 << matrix.m22()-
2333 << matrix.dx()-
2334 << matrix.dy() << "]\n"-
2335 "/Resources \n<< ";-
2336 if (imageObject > 0
imageObject > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2337 s << "/XObject << /Im" << imageObject << ' ' << imageObject << "0 R >> ";-
2338 }
never executed: end of block
0
2339 s << ">>\n"-
2340 "/Length " << pattern.length() << "\n"-
2341 ">>\n"-
2342 "stream\n"-
2343 << pattern-
2344 << "endstream\n"-
2345 "endobj\n";-
2346-
2347 int patternObj = addXrefEntry(-1);-
2348 write(str);-
2349 currentPage->patterns.append(patternObj);-
2350 return
never executed: return patternObj;
patternObj;
never executed: return patternObj;
0
2351}-
2352-
2353static inline bool is_monochrome(const QVector<QRgb> &colorTable)-
2354{-
2355 return
never executed: return colorTable.size() == 2 && colorTable.at(0) == QColor(Qt::black).rgba() && colorTable.at(1) == QColor(Qt::white).rgba() ;
colorTable.size() == 2
never executed: return colorTable.size() == 2 && colorTable.at(0) == QColor(Qt::black).rgba() && colorTable.at(1) == QColor(Qt::white).rgba() ;
0
2356 && colorTable.at(0) == QColor(Qt::black).rgba()
never executed: return colorTable.size() == 2 && colorTable.at(0) == QColor(Qt::black).rgba() && colorTable.at(1) == QColor(Qt::white).rgba() ;
0
2357 && colorTable.at(1) == QColor(Qt::white).rgba()
never executed: return colorTable.size() == 2 && colorTable.at(0) == QColor(Qt::black).rgba() && colorTable.at(1) == QColor(Qt::white).rgba() ;
0
2358 ;
never executed: return colorTable.size() == 2 && colorTable.at(0) == QColor(Qt::black).rgba() && colorTable.at(1) == QColor(Qt::white).rgba() ;
0
2359}-
2360-
2361-
2362-
2363-
2364int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_no)-
2365{-
2366 if (img.isNull()
img.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2367 return
never executed: return -1;
-1;
never executed: return -1;
0
2368-
2369 int object = imageCache.value(serial_no);-
2370 if(object
objectDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2371 return
never executed: return object;
object;
never executed: return object;
0
2372-
2373 QImage image = img;-
2374 QImage::Format format = image.format();-
2375 if (image.depth() == 1
image.depth() == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& *
*bitmapDescription
TRUEnever evaluated
FALSEnever evaluated
bitmap
*bitmapDescription
TRUEnever evaluated
FALSEnever evaluated
&& is_monochrome(img.colorTable())
is_monochrome(....colorTable())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2376 if (format == QImage::Format_MonoLSB
format == QIma...Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2377 image = image.convertToFormat(QImage::Format_Mono);
never executed: image = image.convertToFormat(QImage::Format_Mono);
0
2378 format = QImage::Format_Mono;-
2379 }
never executed: end of block
else {
0
2380 *bitmap = false;-
2381 if (format != QImage::Format_RGB32
format != QImage::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
&& format != QImage::Format_ARGB32
format != QIma...:Format_ARGB32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2382 image = image.convertToFormat(QImage::Format_ARGB32);-
2383 format = QImage::Format_ARGB32;-
2384 }
never executed: end of block
0
2385 }
never executed: end of block
0
2386-
2387 int w = image.width();-
2388 int h = image.height();-
2389 int d = image.depth();-
2390-
2391 if (format == QImage::Format_Mono
format == QImage::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2392 int bytesPerLine = (w + 7) >> 3;-
2393 QByteArray data;-
2394 data.resize(bytesPerLine * h);-
2395 char *rawdata = data.data();-
2396 for (int y = 0; y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
; ++y) {
0
2397 memcpy(rawdata, image.constScanLine(y), bytesPerLine);-
2398 rawdata += bytesPerLine;-
2399 }
never executed: end of block
0
2400 object = writeImage(data, w, h, d, 0, 0, false, is_monochrome(img.colorTable()));-
2401 }
never executed: end of block
else {
0
2402 QByteArray softMaskData;-
2403 bool dct = false;-
2404 QByteArray imageData;-
2405 bool hasAlpha = false;-
2406 bool hasMask = false;-
2407-
2408 if (QImageWriter::supportedImageFormats().contains("jpeg")
QImageWriter::...ntains("jpeg")Description
TRUEnever evaluated
FALSEnever evaluated
&& !grayscale
!grayscaleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2409 QBuffer buffer(&imageData);-
2410 QImageWriter writer(&buffer, "jpeg");-
2411 writer.setQuality(94);-
2412 writer.write(image);-
2413 dct = true;-
2414-
2415 if (format != QImage::Format_RGB32
format != QImage::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2416 softMaskData.resize(w * h);-
2417 uchar *sdata = (uchar *)softMaskData.data();-
2418 for (int y = 0; y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
; ++y) {
0
2419 const QRgb *rgb = (const QRgb *)image.constScanLine(y);-
2420 for (int x = 0; x < w
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
; ++x) {
0
2421 uchar alpha = qAlpha(*rgb);-
2422 *sdata++ = alpha;-
2423 hasMask |= (alpha < 255);-
2424 hasAlpha |= (alpha != 0
alpha != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& alpha != 255
alpha != 255Description
TRUEnever evaluated
FALSEnever evaluated
);
0
2425 ++rgb;-
2426 }
never executed: end of block
0
2427 }
never executed: end of block
0
2428 }
never executed: end of block
0
2429 }
never executed: end of block
else {
0
2430 imageData.resize(grayscale ? w * h : 3 * w * h);-
2431 uchar *data = (uchar *)imageData.data();-
2432 softMaskData.resize(w * h);-
2433 uchar *sdata = (uchar *)softMaskData.data();-
2434 for (int y = 0; y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
; ++y) {
0
2435 const QRgb *rgb = (const QRgb *)image.constScanLine(y);-
2436 if (grayscale
grayscaleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2437 for (int x = 0; x < w
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
; ++x) {
0
2438 *(data++) = qGray(*rgb);-
2439 uchar alpha = qAlpha(*rgb);-
2440 *sdata++ = alpha;-
2441 hasMask |= (alpha < 255);-
2442 hasAlpha |= (alpha != 0
alpha != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& alpha != 255
alpha != 255Description
TRUEnever evaluated
FALSEnever evaluated
);
0
2443 ++rgb;-
2444 }
never executed: end of block
0
2445 }
never executed: end of block
else {
0
2446 for (int x = 0; x < w
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
; ++x) {
0
2447 *(data++) = qRed(*rgb);-
2448 *(data++) = qGreen(*rgb);-
2449 *(data++) = qBlue(*rgb);-
2450 uchar alpha = qAlpha(*rgb);-
2451 *sdata++ = alpha;-
2452 hasMask |= (alpha < 255);-
2453 hasAlpha |= (alpha != 0
alpha != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& alpha != 255
alpha != 255Description
TRUEnever evaluated
FALSEnever evaluated
);
0
2454 ++rgb;-
2455 }
never executed: end of block
0
2456 }
never executed: end of block
0
2457 }-
2458 if (format == QImage::Format_RGB32
format == QImage::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2459 hasAlpha = hasMask = false;
never executed: hasAlpha = hasMask = false;
0
2460 }
never executed: end of block
0
2461 int maskObject = 0;-
2462 int softMaskObject = 0;-
2463 if (hasAlpha
hasAlphaDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2464 softMaskObject = writeImage(softMaskData, w, h, 8, 0, 0);-
2465 }
never executed: end of block
else if (hasMask
hasMaskDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2466-
2467-
2468 int bytesPerLine = (w + 7) >> 3;-
2469 QByteArray mask(bytesPerLine * h, 0);-
2470 uchar *mdata = (uchar *)mask.data();-
2471 const uchar *sdata = (const uchar *)softMaskData.constData();-
2472 for (int y = 0; y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
; ++y) {
0
2473 for (int x = 0; x < w
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
; ++x) {
0
2474 if (*
*sdataDescription
TRUEnever evaluated
FALSEnever evaluated
sdata
*sdataDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2475 mdata[x>>3] |= (0x80 >> (x&7));
never executed: mdata[x>>3] |= (0x80 >> (x&7));
0
2476 ++sdata;-
2477 }
never executed: end of block
0
2478 mdata += bytesPerLine;-
2479 }
never executed: end of block
0
2480 maskObject = writeImage(mask, w, h, 1, 0, 0);-
2481 }
never executed: end of block
0
2482 object = writeImage(imageData, w, h, grayscale ? 8 : 32,-
2483 maskObject, softMaskObject, dct);-
2484 }
never executed: end of block
0
2485 imageCache.insert(serial_no, object);-
2486 return
never executed: return object;
object;
never executed: return object;
0
2487}-
2488-
2489void QPdfEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &ti)-
2490{-
2491 QPdfEngine * const q = q_func();-
2492-
2493 if (ti.charFormat.isAnchor()
ti.charFormat.isAnchor()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2494 qreal size = ti.fontEngine->fontDef.pixelSize;-
2495 int synthesized = ti.fontEngine->synthesized();-
2496 qreal stretch = synthesized & QFontEngine::SynthesizedStretch
synthesized & ...hesizedStretchDescription
TRUEnever evaluated
FALSEnever evaluated
? ti.fontEngine->fontDef.stretch/100. : 1.;
0
2497-
2498 QTransform trans;-
2499-
2500-
2501 trans = QTransform(size*stretch, 0, 0, size, 0, 0);-
2502-
2503 trans *= QTransform(1,0,0,-1,p.x(),p.y());-
2504-
2505 trans *= stroker.matrix;-
2506-
2507 trans *= pageMatrix();-
2508 qreal x1, y1, x2, y2;-
2509 trans.map(0, 0, &x1, &y1);-
2510 trans.map(ti.width.toReal()/size, (ti.ascent.toReal()-ti.descent.toReal())/size, &x2, &y2);-
2511-
2512 uint annot = addXrefEntry(-1);-
2513 QByteArray x1s, y1s, x2s, y2s;-
2514 x1s.setNum(static_cast<double>(x1), 'f');-
2515 y1s.setNum(static_cast<double>(y1), 'f');-
2516 x2s.setNum(static_cast<double>(x2), 'f');-
2517 y2s.setNum(static_cast<double>(y2), 'f');-
2518 QByteArray rectData = x1s + ' ' + y1s + ' ' + x2s + ' ' + y2s;-
2519 xprintf("<<\n/Type /Annot\n/Subtype /Link\n/Rect [");-
2520 xprintf(rectData.constData());-
2521-
2522-
2523-
2524 xprintf("]\n/Border [0 0 0]\n/A <<\n");-
2525-
2526 xprintf("/Type /Action\n/S /URI\n/URI (%s)\n",-
2527 ti.charFormat.anchorHref().toLatin1().constData());-
2528 xprintf(">>\n>>\n");-
2529 xprintf("endobj\n");-
2530-
2531 if (!currentPage->annotations.contains(annot)
!currentPage->...ontains(annot)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2532 currentPage->annotations.append(annot);-
2533 }
never executed: end of block
0
2534 }
never executed: end of block
0
2535-
2536 QFontEngine *fe = ti.fontEngine;-
2537-
2538 QFontEngine::FaceId face_id = fe->faceId();-
2539 bool noEmbed = false;-
2540 if (!embedFonts
!embedFontsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2541 || face_id.filename.isEmpty()
face_id.filename.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2542 || fe->fsType & 0x200
fe->fsType & 0x200Description
TRUEnever evaluated
FALSEnever evaluated
0
2543 || fe->fsType == 2
fe->fsType == 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2544 *currentPage << "Q\n";-
2545 q->QPaintEngine::drawTextItem(p, ti);-
2546 *currentPage << "q\n";-
2547 if (face_id.filename.isEmpty()
face_id.filename.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2548 return;
never executed: return;
0
2549 noEmbed = true;-
2550 }
never executed: end of block
0
2551-
2552 QFontSubset *font = fonts.value(face_id, 0);-
2553 if (!font
!fontDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2554 font = new QFontSubset(fe, requestObject());-
2555 font->noEmbed = noEmbed;-
2556 }
never executed: end of block
0
2557 fonts.insert(face_id, font);-
2558-
2559 if (!currentPage->fonts.contains(font->object_id)
!currentPage->...nt->object_id)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2560 currentPage->fonts.append(font->object_id);
never executed: currentPage->fonts.append(font->object_id);
0
2561-
2562 qreal size = ti.fontEngine->fontDef.pixelSize;-
2563-
2564 QVarLengthArray<glyph_t> glyphs;-
2565 QVarLengthArray<QFixedPoint> positions;-
2566 QTransform m = QTransform::fromTranslate(p.x(), p.y());-
2567 ti.fontEngine->getGlyphPositions(ti.glyphs, m, ti.flags,-
2568 glyphs, positions);-
2569 if (glyphs.size() == 0
glyphs.size() == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2570 return;
never executed: return;
0
2571 int synthesized = ti.fontEngine->synthesized();-
2572 qreal stretch = synthesized & QFontEngine::SynthesizedStretch
synthesized & ...hesizedStretchDescription
TRUEnever evaluated
FALSEnever evaluated
? ti.fontEngine->fontDef.stretch/100. : 1.;
0
2573-
2574 *currentPage << "BT\n"-
2575 << "/F" << font->object_id << size << "Tf "-
2576 << stretch << (synthesized & QFontEngine::SynthesizedItalic-
2577 ? "0 .3 -1 0 0 Tm\n"-
2578 : "0 0 -1 0 0 Tm\n");-
2579 qreal last_x = 0.;-
2580 qreal last_y = 0.;-
2581 for (int i = 0; i < glyphs.size()
i < glyphs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2582 qreal x = positions[i].x.toReal();-
2583 qreal y = positions[i].y.toReal();-
2584 if (synthesized & QFontEngine::SynthesizedItalic
synthesized & ...thesizedItalicDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2585 x += .3*y;
never executed: x += .3*y;
0
2586 x /= stretch;-
2587 char buf[5];-
2588 int g = font->addGlyph(glyphs[i]);-
2589 *currentPage << x - last_x << last_y - y << "Td <"-
2590 << QPdf::toHex((ushort)g, buf) << "> Tj\n";-
2591 last_x = x;-
2592 last_y = y;-
2593 }
never executed: end of block
0
2594 if (synthesized & QFontEngine::SynthesizedBold
synthesized & ...ynthesizedBoldDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2595 *currentPage << stretch << (synthesized & QFontEngine::SynthesizedItalic-
2596 ? "0 .3 -1 0 0 Tm\n"-
2597 : "0 0 -1 0 0 Tm\n");-
2598 *currentPage << "/Span << /ActualText <> >> BDC\n";-
2599 last_x = 0.5*fe->lineThickness().toReal();-
2600 last_y = 0.;-
2601 for (int i = 0; i < glyphs.size()
i < glyphs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2602 qreal x = positions[i].x.toReal();-
2603 qreal y = positions[i].y.toReal();-
2604 if (synthesized & QFontEngine::SynthesizedItalic
synthesized & ...thesizedItalicDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2605 x += .3*y;
never executed: x += .3*y;
0
2606 x /= stretch;-
2607 char buf[5];-
2608 int g = font->addGlyph(glyphs[i]);-
2609 *currentPage << x - last_x << last_y - y << "Td <"-
2610 << QPdf::toHex((ushort)g, buf) << "> Tj\n";-
2611 last_x = x;-
2612 last_y = y;-
2613 }
never executed: end of block
0
2614 *currentPage << "EMC\n";-
2615 }
never executed: end of block
0
2616-
2617-
2618 *currentPage << "ET\n";-
2619}
never executed: end of block
0
2620-
2621QTransform QPdfEnginePrivate::pageMatrix() const-
2622{-
2623 qreal scale = 72./resolution;-
2624 QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, m_pageLayout.fullRectPoints().height());-
2625 if (m_pageLayout.mode() != QPageLayout::FullPageMode
m_pageLayout.m...::FullPageModeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2626 QRect r = m_pageLayout.paintRectPixels(resolution);-
2627 tmp.translate(r.left(), r.top());-
2628 }
never executed: end of block
0
2629 return
never executed: return tmp;
tmp;
never executed: return tmp;
0
2630}-
2631-
2632void QPdfEnginePrivate::newPage()-
2633{-
2634 if (currentPage
currentPageDescription
TRUEnever evaluated
FALSEnever evaluated
&& currentPage->pageSize.isEmpty()
currentPage->p...Size.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2635 currentPage->pageSize = m_pageLayout.fullRectPoints().size();
never executed: currentPage->pageSize = m_pageLayout.fullRectPoints().size();
0
2636 writePage();-
2637-
2638 delete currentPage;-
2639 currentPage = new QPdfPage;-
2640 currentPage->pageSize = m_pageLayout.fullRectPoints().size();-
2641 stroker.stream = currentPage;-
2642 pages.append(requestObject());-
2643-
2644 *currentPage << "/GSa gs /CSp cs /CSp CS\n"-
2645 << QPdf::generateMatrix(pageMatrix())-
2646 << "q q\n";-
2647}
never executed: end of block
0
2648-
2649-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9