Subversion Repositories Scribus

Rev

Rev 11908 | Rev 12387 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3133 fschmid 7
 
10054 craig 8
#ifndef PDFLIBCORE_H
9
#define PDFLIBCORE_H
3133 fschmid 10
 
10223 cbradney 11
#include <QFile>
8559 subik 12
#include <QDataStream>
8501 cbradney 13
#include <QPixmap>
9803 fschmid 14
#include <QList>
4265 craig 15
#include <string>
3699 cbradney 16
#include <vector>
3133 fschmid 17
 
18
class QString;
19
class QRect;
20
class QImage;
21
class PageItem;
22
class BookMItem;
23
class BookMView;
24
class ScribusDoc;
25
class Page;
26
class PDFOptions;
3252 craig 27
class PrefsContext;
4028 cbradney 28
class MultiProgressDialog;
5291 avox 29
class ScText;
3699 cbradney 30
 
3133 fschmid 31
#include "scribusstructs.h"
32
 
12080 avox 33
#ifdef HAVE_PODOFO
34
#include <podofo/podofo.h>
35
#endif
36
 
37
 
3133 fschmid 38
/**
10054 craig 39
 * PDFLibCore provides Scribus's implementation of PDF export functionality.
40
 *
41
 * This is not public API and is not exported in Scribus's symbol table on supporting
42
 * platforms. Do not include this header, use pdflib.h instead. Including this header
43
 * from anywhere except pdflib.cpp may cause linker errors and other problems,
44
 * and is totally pointless since all the interfaces that are publically
45
 * visible are presented by PDFlib anyway.
46
 *
47
 *@author Franz Schmid
48
 */
3133 fschmid 49
 
10054 craig 50
class PDFLibCore : public QObject
3133 fschmid 51
{
52
        Q_OBJECT
53
 
54
public:
10054 craig 55
        explicit PDFLibCore(ScribusDoc & docu);
56
        ~PDFLibCore();
4264 craig 57
        bool doExport(const QString& fn, const QString& nam, int Components,
58
                                  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs);
4223 craig 59
 
11060 jghali 60
        const QString& errorMessage(void) const;
11441 jghali 61
        bool  exportAborted(void) const;
11060 jghali 62
 
4223 craig 63
private:
12080 avox 64
        struct ShIm
65
        {
66
                int ResNum;
67
                int Width;
68
                int Height;
69
                double reso;
70
                double sxa;
71
                double sya;
72
                double xa;
73
                double ya;
74
        };
75
 
5387 avox 76
        bool PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, QMap<QString, QMap<uint, FPointArray> > DocFonts, BookMView* vi);
4241 craig 77
        void PDF_Begin_Page(const Page* pag, QPixmap pm = 0);
3133 fschmid 78
        void PDF_End_Page();
11060 jghali 79
        bool PDF_TemplatePage(const Page* pag, bool clip = false);
80
        bool PDF_ProcessPage(const Page* pag, uint PNr, bool clip = false);
3829 cbradney 81
        void PDF_End_Doc(const QString& PrintPr = "", const QString& Name = "", int Components = 0);
4028 cbradney 82
        void closeAndCleanup();
3133 fschmid 83
 
11060 jghali 84
        void PDF_Error(const QString& errorMsg);
85
        void PDF_Error_ImageLoadFailure(const QString& fileName);
11599 jghali 86
        void PDF_Error_ImageWriteFailure(const QString& fileName);
11389 jghali 87
        void PDF_Error_MaskLoadFailure(const QString& fileName);
11060 jghali 88
        void PDF_Error_InsufficientMemory(void);
89
 
7328 fschmid 90
        QByteArray EncodeUTF16(const QString &in);
11060 jghali 91
        QString    EncStream(const QString & in, int ObjNum);
92
        QString    EncString(const QString & in, int ObjNum);
93
        QString    EncStringUTF16(const QString & in, int ObjNum);
94
 
11445 jghali 95
        bool       EncodeArrayToStream(const QByteArray& in, int ObjNum);
96
 
11599 jghali 97
        int     WriteImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray);
98
        int     WriteJPEGImageToStream(ScImage& image, const QString& fn, int ObjNum, bool cmyk, bool gray, bool sameFile);
99
        int     WriteFlateImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray);
100
 
11060 jghali 101
        void    CalcOwnerKey(const QString & Owner, const QString & User);
102
        void    CalcUserKey(const QString & User, int Permission);
4229 craig 103
        QString FitKey(const QString & pass);
11060 jghali 104
 
8559 subik 105
        QString setStrokeMulti(struct SingleLine *sl);
3133 fschmid 106
        QString SetClipPathArray(FPointArray *ite, bool poly = true);
107
        QString SetClipPathImage(PageItem *ite);
108
        QString SetClipPath(PageItem *ite, bool poly = true);
11333 jghali 109
        QString SetColor(const QString& farbe, double Shade);
110
        QString SetColor(const ScColor& farbe, double Shade);
111
        QString SetGradientColor(const QString& farbe, double Shade);
9920 fschmid 112
        QString putColor(const QString& color, double Shade, bool fill);
4229 craig 113
        QString putColorUncached(const QString& color, int Shade, bool fill);
6562 fschmid 114
        QString Write_TransparencyGroup(double trans, int blend, QString &data);
4241 craig 115
        QString setTextSt(PageItem *ite, uint PNr, const Page* pag);
11060 jghali 116
        bool    setTextCh(PageItem *ite, uint PNr, double x, double y, uint d,  QString &tmp, QString &tmp2, const ScText * hl, const ParagraphStyle& pstyle, const Page* pag);
4229 craig 117
 
118
        // Provide a couple of PutDoc implementations to ease transition away from
119
        // QString abuse and to provide fast paths for constant strings.
10397 cbradney 120
        void PutDoc(const QString & in) { outStream.writeRawData(in.toLatin1(), in.length()); }
8559 subik 121
        void PutDoc(const QByteArray & in) { outStream.writeRawData(in, in.size()); }
122
        void PutDoc(const char* in) { outStream.writeRawData(in, strlen(in)); }
123
        void PutDoc(const std::string & in) { outStream.writeRawData(in.c_str(), in.length()); }
4229 craig 124
 
11060 jghali 125
        void       PutPage(const QString & in) { Content += in; }
126
        void       StartObj(int nr);
12080 avox 127
        uint       newObject() { return ObjCounter++; }
128
        uint       WritePDFStream(const QString& cc);
129
        uint       WritePDFString(const QString& cc);
130
        void       writeXObject(uint objNr, QString dictionary, QByteArray stream);
131
        uint       writeObject(QString type, QString dictionary);
132
        uint       writeGState(QString dictionary) { return writeObject("/ExtGState", dictionary); }
133
        uint       writeActions(const Annotation&);
134
//      QString    PDFEncode(const QString & in);
3829 cbradney 135
        QByteArray ComputeMD5(const QString& in);
11599 jghali 136
        QByteArray ComputeRC4Key(int ObjNum);
11060 jghali 137
 
138
        bool    PDF_ProcessItem(QString& output, PageItem* ite, const Page* pag, uint PNr, bool embedded = false, bool pattern = false);
139
        QString PDF_ProcessTableItem(PageItem* ite, const Page* pag);
140
        void    PDF_Bookmark(PageItem *currItem, double ypos);
141
        bool    PDF_Gradient(QString& output, PageItem *currItem);
9803 fschmid 142
        QString PDF_DoLinGradient(PageItem *currItem, QList<double> Stops, QList<double> Trans, const QStringList& Colors, QStringList colorNames, QList<int> colorShades);
5748 fschmid 143
        QString PDF_TransparenzFill(PageItem *currItem);
144
        QString PDF_TransparenzStroke(PageItem *currItem);
11060 jghali 145
        bool    PDF_Annotation(PageItem *ite, uint PNr);
146
        void    PDF_Form(const QString& im);
12080 avox 147
        void    PDF_xForm(uint objNr, double w, double h, QString im);
11060 jghali 148
        bool    PDF_Image(PageItem* c, const QString& fn, double sx, double sy, double x, double y, bool fromAN = false, const QString& Profil = "", bool Embedded = false, int Intent = 1, QString* output = NULL);
12080 avox 149
        bool    PDF_EmbeddedPDF(PageItem* c, const QString& fn, double sx, double sy, double x, double y, bool fromAN, const QString& Profil, bool Embedded, int Intent, ShIm& imgInfo, QString* output = NULL);
150
#if HAVE_PODOFO
151
        void copyPoDoFoObject(const PoDoFo::PdfObject* obj, uint scObjID, QMap<PoDoFo::PdfReference, uint>& importedObjects);
152
        void copyPoDoFoDirect(const PoDoFo::PdfVariant* obj, QList<PoDoFo::PdfReference>& referencedObjects, QMap<PoDoFo::PdfReference, uint>& importedObjects);
153
#endif
154
 
10427 cbradney 155
        int bytesWritten() { return Spool.pos(); }
4229 craig 156
 
11060 jghali 157
 
158
        QString Content;
159
        QString ErrorMessage;
4264 craig 160
        ScribusDoc & doc;
161
        const Page * ActPageP;
162
        const PDFOptions & Options;
3133 fschmid 163
        BookMView* Bvie;
164
        QFile Spool;
165
        int Dokument;
166
        struct Dest
167
        {
168
                QString Name;
169
                int Seite;
170
                QString Act;
171
        };
172
        struct Cata
173
        {
174
                int Outlines;
175
                int PageTree;
176
                int Dest;
177
        }
178
        Catalog;
179
        struct PagT
180
        {
9803 fschmid 181
                QList<int> Kids;
3133 fschmid 182
                int Count;
183
        }
184
        PageTree;
185
        struct PagL
186
        {
187
                int ObjNum;
188
                int Thumb;
189
                QMap<QString,int> XObjects;
190
                QMap<QString,int> ImgObjects;
191
                QMap<QString,int> FObjects;
9803 fschmid 192
                QList<int> AObjects;
193
                QList<int> FormObjects;
3133 fschmid 194
        }
195
        Seite;
196
        struct OutL
197
        {
198
                int First;
199
                int Last;
200
                int Count;
201
        }
202
        Outlines;
203
        struct Bead
204
        {
205
                int Parent;
206
                int Next;
207
                int Prev;
208
                int Page;
209
                QRect Recht;
210
        };
211
        struct ICCD
212
        {
213
                int ResNum;
214
                QString ResName;
215
                QString ICCArray;
216
        };
217
        struct OCGInfo
218
        {
219
                int ObjNum;
220
                bool visible;
221
                QString Name;
222
        };
223
        struct SpotC
224
        {
225
                int ResNum;
226
                QString ResName;
227
        };
6562 fschmid 228
        struct gData
229
        {
230
                int ResNumG;
231
                int ResNumX;
232
                QString ResNamG;
233
                QString ResNamX;
234
                QString data;
235
        };
3133 fschmid 236
        QMap<QString,ShIm> SharedImages;
9803 fschmid 237
        QList<uint> XRef;
238
        QList<Dest> NamedDest;
239
        QList<int> Threads;
240
        QList<Bead> Beads;
241
        QList<int> CalcFields;
6378 fschmid 242
        QMap<QString,int> Patterns;
3133 fschmid 243
        QMap<QString,int> Shadings;
244
        QMap<QString,int> Transpar;
245
        QMap<QString,ICCD> ICCProfiles;
11908 fschmid 246
        QHash<QString, OCGInfo> OCGEntries;
3133 fschmid 247
        int ObjCounter;
248
        QString ResNam;
249
        int ResCount;
250
        QString NDnam;
251
        QString Datum;
252
        int NDnum;
253
        QMap<QString, QString> UsedFontsP;
8454 fschmid 254
        QMap<QString, QString> UsedFontsF;
3133 fschmid 255
        QByteArray KeyGen;
256
        QByteArray OwnerKey;
257
        QByteArray UserKey;
258
        QByteArray FileID;
259
        QByteArray EncryKey;
260
        int Encrypt;
261
        int KeyLen;
262
        QString HTName;
263
        bool BookMinUse;
264
        ColorList colorsToUse;
265
        QMap<QString, SpotC> spotMap;
6925 fschmid 266
        QMap<QString, SpotC> spotMapReg;
3133 fschmid 267
        QString spotNam;
268
        int spotCount;
6407 fschmid 269
        int inPattern;
8559 subik 270
        QDataStream outStream;
4017 fschmid 271
        QMap<QString, QString> StdFonts;
4028 cbradney 272
        MultiProgressDialog* progressDialog;
4223 craig 273
        bool abortExport;
4028 cbradney 274
        bool usingGUI;
8171 fschmid 275
        double bleedDisplacementX;
276
        double bleedDisplacementY;
8469 fschmid 277
        QMap<QString, QMap<uint, uint> > Type3Fonts;
4028 cbradney 278
 
279
protected slots:
280
        void cancelRequested();
3133 fschmid 281
};
282
 
283
#endif
284