Subversion Repositories Scribus

Rev

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