| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QtGui/qprintengine.h>
|
|---|
| 43 |
|
|---|
| 44 | #include <qiodevice.h>
|
|---|
| 45 | #include <qpainter.h>
|
|---|
| 46 | #include <qbitmap.h>
|
|---|
| 47 | #include <qpainterpath.h>
|
|---|
| 48 | #include <qpaintdevice.h>
|
|---|
| 49 | #include <qfile.h>
|
|---|
| 50 | #include <qdebug.h>
|
|---|
| 51 | #include <qimagewriter.h>
|
|---|
| 52 | #include <qbuffer.h>
|
|---|
| 53 | #include <qdatetime.h>
|
|---|
| 54 |
|
|---|
| 55 | #ifndef QT_NO_PRINTER
|
|---|
| 56 | #include <limits.h>
|
|---|
| 57 | #include <math.h>
|
|---|
| 58 | #ifndef QT_NO_COMPRESS
|
|---|
| 59 | #include <zlib.h>
|
|---|
| 60 | #endif
|
|---|
| 61 |
|
|---|
| 62 | #if defined(Q_OS_WINCE)
|
|---|
| 63 | #include "qwinfunctions_wince.h"
|
|---|
| 64 | #endif
|
|---|
| 65 |
|
|---|
| 66 | #include "qprintengine_pdf_p.h"
|
|---|
| 67 | #include "private/qdrawhelper_p.h"
|
|---|
| 68 |
|
|---|
| 69 | QT_BEGIN_NAMESPACE
|
|---|
| 70 |
|
|---|
| 71 | extern qint64 qt_pixmap_id(const QPixmap &pixmap);
|
|---|
| 72 | extern qint64 qt_image_id(const QImage &image);
|
|---|
| 73 |
|
|---|
| 74 | //#define FONT_DUMP
|
|---|
| 75 |
|
|---|
| 76 | // might be helpful for smooth transforms of images
|
|---|
| 77 | // Can't use it though, as gs generates completely wrong images if this is true.
|
|---|
| 78 | static const bool interpolateImages = false;
|
|---|
| 79 |
|
|---|
| 80 | #ifdef QT_NO_COMPRESS
|
|---|
| 81 | static const bool do_compress = false;
|
|---|
| 82 | #else
|
|---|
| 83 | static const bool do_compress = true;
|
|---|
| 84 | #endif
|
|---|
| 85 |
|
|---|
| 86 | QPdfPage::QPdfPage()
|
|---|
| 87 | : QPdf::ByteStream(true) // Enable file backing
|
|---|
| 88 | {
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void QPdfPage::streamImage(int w, int h, int object)
|
|---|
| 92 | {
|
|---|
| 93 | *this << w << "0 0 " << -h << "0 " << h << "cm /Im" << object << " Do\n";
|
|---|
| 94 | if (!images.contains(object))
|
|---|
| 95 | images.append(object);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features()
|
|---|
| 100 | {
|
|---|
| 101 | QPaintEngine::PaintEngineFeatures f = QPaintEngine::AllFeatures;
|
|---|
| 102 | f &= ~(QPaintEngine::PorterDuff | QPaintEngine::PerspectiveTransform
|
|---|
| 103 | | QPaintEngine::ObjectBoundingModeGradients
|
|---|
| 104 | #ifndef USE_NATIVE_GRADIENTS
|
|---|
| 105 | | QPaintEngine::LinearGradientFill
|
|---|
| 106 | #endif
|
|---|
| 107 | | QPaintEngine::RadialGradientFill
|
|---|
| 108 | | QPaintEngine::ConicalGradientFill);
|
|---|
| 109 | return f;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | QPdfEngine::QPdfEngine(QPrinter::PrinterMode m)
|
|---|
| 113 | : QPdfBaseEngine(*new QPdfEnginePrivate(m), qt_pdf_decide_features())
|
|---|
| 114 | {
|
|---|
| 115 | state = QPrinter::Idle;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | QPdfEngine::~QPdfEngine()
|
|---|
| 119 | {
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | bool QPdfEngine::begin(QPaintDevice *pdev)
|
|---|
| 123 | {
|
|---|
| 124 | Q_D(QPdfEngine);
|
|---|
| 125 |
|
|---|
|
|---|