source: wkhtmltox/trunk/fuentes/src/lib/pdfconverter_p.hh @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 5.4 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21#ifndef __PDFCONVERTER_P_HH__
22#define __PDFCONVERTER_P_HH__
23
24#include "converter_p.hh"
25#include "multipageloader.hh"
26#include "outline.hh"
27#include "pdfconverter.hh"
28#include "pdfsettings.hh"
29#include "tempfile.hh"
30#include <QAtomicInt>
31#include <QFile>
32#include <QMutex>
33#include <QPainter>
34#include <QPrinter>
35#include <QRegExp>
36#include <QWaitCondition>
37#include <QWebPage>
38#include <qnetworkreply.h>
39#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
40#include <QWebElement>
41#endif
42
43#include "dllbegin.inc"
44namespace wkhtmltopdf {
45
46class DLL_LOCAL PageObject {
47public:
48        static QMap<QWebPage *, PageObject *> webPageToObject;
49
50        settings::PdfObject settings;
51        LoaderObject * loaderObject;
52        QWebPage * page;
53        QString data;
54        int number;
55
56#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
57        QHash<QString, QWebElement> anchors;
58        QVector< QPair<QWebElement,QString> > localLinks;
59        QVector< QPair<QWebElement,QString> > externalLinks;
60    // height length to reserve for header when printing page
61    double headerReserveHeight;
62    // height length to reserve for footer when printing page
63    double footerReserveHeight;
64    // keeps preloaded header to calculate header height
65    QWebPage * measuringHeader;
66    // keeps preloaded footer to calculate header height
67    QWebPage * measuringFooter;
68#endif
69
70        int firstPageNumber;
71        QList<QWebPage *> headers;
72        QList<QWebPage *> footers;
73        int pageCount;
74        TempFile tocFile;
75
76        void clear() {
77#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
78                anchors.clear();
79                localLinks.clear();
80                externalLinks.clear();
81#endif
82                headers.clear();
83                footers.clear();
84                webPageToObject.remove(page);
85                page=0;
86                tocFile.removeAll();
87        }
88
89        PageObject(const settings::PdfObject & set, const QString * d=NULL):
90                settings(set), loaderObject(0), page(0)
91#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
92                , headerReserveHeight(0), footerReserveHeight(0), measuringHeader(0), measuringFooter(0)
93#endif
94        {
95                if (d) data=*d;
96        };
97
98        ~PageObject() {
99                clear();
100        }
101
102};
103
104class DLL_LOCAL PdfConverterPrivate: public ConverterPrivate {
105        Q_OBJECT
106public:
107        PdfConverterPrivate(settings::PdfGlobal & s, PdfConverter & o);
108        ~PdfConverterPrivate();
109
110        settings::PdfGlobal & settings;
111
112        MultiPageLoader pageLoader;
113
114private:
115        PdfConverter & out;
116        void clearResources();
117        TempFile tempOut;
118        QByteArray outputData;
119
120        QList<PageObject> objects;
121        QSize viewportSize;
122        QPrinter * printer;
123        QPainter * painter;
124        QString lout;
125        QString title;
126        int currentObject;
127        int actualPages;
128        int pageCount;
129        int tocPages;
130        bool tocChanged;
131        int actualPage;
132        int pageNumber;
133#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
134        QWebPrinter * webPrinter;
135        int objectPage;
136
137
138        QHash<int, QHash<QString, QWebElement> > pageAnchors;
139        QHash<int, QVector< QPair<QWebElement,QString> > > pageLocalLinks;
140        QHash<int, QVector< QPair<QWebElement,QString> > > pageExternalLinks;
141        QHash<int, QVector<QWebElement> > pageFormElements;
142        bool pageHasHeaderFooter;
143       
144    // loader for measuringHeader and measuringFooter
145    MultiPageLoader measuringHFLoader;
146
147        MultiPageLoader hfLoader;
148        MultiPageLoader tocLoader1;
149        MultiPageLoader tocLoader2;
150
151        MultiPageLoader * tocLoader;
152        MultiPageLoader * tocLoaderOld;
153
154        QHash<QString, PageObject *> urlToPageObj;
155
156        Outline * outline;
157        void findLinks(QWebFrame * frame, QVector<QPair<QWebElement, QString> > & local, QVector<QPair<QWebElement, QString> > & external, QHash<QString, QWebElement> & anchors);
158        void endPage(PageObject & object, bool hasHeaderFooter, int objectPage,  int pageNumber);
159        void fillParms(QHash<QString, QString> & parms, int page, const PageObject & object);
160        QString hfreplace(const QString & q, const QHash<QString, QString> & parms);
161        QWebPage * loadHeaderFooter(QString url, const QHash<QString, QString> & parms, const settings::PdfObject & ps);
162    qreal calculateHeaderHeight(PageObject & object, QWebPage & header);
163
164#endif
165        QWebPage * currentHeader;
166        QWebPage * currentFooter;
167    QPrinter * createPrinter(const QString & tempFile);
168
169#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
170        void handleTocPage(PageObject & obj);
171        void preprocessPage(PageObject & obj);
172        void spoolPage(int page);
173        void spoolTo(int page);
174        void handleHeader(QWebPage * frame, int page);
175        void handleFooter(QWebPage * frame, int page);
176        void beginPrintObject(PageObject & obj);
177        void endPrintObject(PageObject & obj);
178#endif
179
180        void loadTocs();
181        void loadHeaders();
182public slots:
183    void measuringHeadersLoaded(bool ok);
184    void pagesLoaded(bool ok);
185        void tocLoaded(bool ok);
186        void headersLoaded(bool ok);
187
188        void printDocument();
189
190        void beginConvert();
191
192        friend class PdfConverter;
193
194        virtual Converter & outer();
195};
196
197}
198#include "dllend.inc"
199#endif //__PDFCONVERTER_P_HH__
Note: See TracBrowser for help on using the repository browser.