Subversion Repositories Scribus

Rev

Rev 20009 | Rev 22388 | 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
 
21743 jghali 101
        int fromPDFDocEncoding(int code);
102
 
7328 fschmid 103
        QByteArray EncodeUTF16(const QString &in);
11060 jghali 104
        QString    EncStream(const QString & in, int ObjNum);
105
        QString    EncString(const QString & in, int ObjNum);
106
        QString    EncStringUTF16(const QString & in, int ObjNum);
107
 
11445 jghali 108
        bool       EncodeArrayToStream(const QByteArray& in, int ObjNum);
109
 
12732 fschmid 110
        int     WriteImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray, bool precal);
111
        int     WriteJPEGImageToStream(ScImage& image, const QString& fn, int ObjNum, bool cmyk, bool gray, bool sameFile, bool precal);
112
        int     WriteFlateImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray, bool precal);
11599 jghali 113
 
11060 jghali 114
        void    CalcOwnerKey(const QString & Owner, const QString & User);
115
        void    CalcUserKey(const QString & User, int Permission);
4229 craig 116
        QString FitKey(const QString & pass);
11060 jghali 117
 
8559 subik 118
        QString setStrokeMulti(struct SingleLine *sl);
3133 fschmid 119
        QString SetClipPathArray(FPointArray *ite, bool poly = true);
120
        QString SetClipPathImage(PageItem *ite);
121
        QString SetClipPath(PageItem *ite, bool poly = true);
11333 jghali 122
        QString SetColor(const QString& farbe, double Shade);
123
        QString SetColor(const ScColor& farbe, double Shade);
124
        QString SetGradientColor(const QString& farbe, double Shade);
9920 fschmid 125
        QString putColor(const QString& color, double Shade, bool fill);
4229 craig 126
        QString putColorUncached(const QString& color, int Shade, bool fill);
6562 fschmid 127
        QString Write_TransparencyGroup(double trans, int blend, QString &data);
4241 craig 128
        QString setTextSt(PageItem *ite, uint PNr, const Page* pag);
11060 jghali 129
        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 130
        void    getBleeds(const Page* page, double &left, double &right);
131
        void    getBleeds(const Page* page, double &left, double &right, double &bottom, double& top);
4229 craig 132
 
133
        // Provide a couple of PutDoc implementations to ease transition away from
134
        // QString abuse and to provide fast paths for constant strings.
10397 cbradney 135
        void PutDoc(const QString & in) { outStream.writeRawData(in.toLatin1(), in.length()); }
8559 subik 136
        void PutDoc(const QByteArray & in) { outStream.writeRawData(in, in.size()); }
137
        void PutDoc(const char* in) { outStream.writeRawData(in, strlen(in)); }
138
        void PutDoc(const std::string & in) { outStream.writeRawData(in.c_str(), in.length()); }
4229 craig 139
 
11060 jghali 140
        void       PutPage(const QString & in) { Content += in; }
141
        void       StartObj(int nr);
12080 avox 142
        uint       newObject() { return ObjCounter++; }
143
        uint       WritePDFStream(const QString& cc);
144
        uint       WritePDFString(const QString& cc);
145
        void       writeXObject(uint objNr, QString dictionary, QByteArray stream);
146
        uint       writeObject(QString type, QString dictionary);
147
        uint       writeGState(QString dictionary) { return writeObject("/ExtGState", dictionary); }
12429 fschmid 148
        uint       writeActions(const Annotation&, uint annotationObj);
12080 avox 149
//      QString    PDFEncode(const QString & in);
3829 cbradney 150
        QByteArray ComputeMD5(const QString& in);
11599 jghali 151
        QByteArray ComputeRC4Key(int ObjNum);
20009 jghali 152
 
153
        bool    PDF_ItemIsOnPage(PageItem* item, const Page* page, const QList<PageItem*>& itemList);
154
 
11060 jghali 155
        bool    PDF_ProcessItem(QString& output, PageItem* ite, const Page* pag, uint PNr, bool embedded = false, bool pattern = false);
156
        QString PDF_ProcessTableItem(PageItem* ite, const Page* pag);
13302 fschmid 157
        QString drawArrow(PageItem *ite, QMatrix &arrowTrans, int arrowIndex);
11060 jghali 158
        void    PDF_Bookmark(PageItem *currItem, double ypos);
159
        bool    PDF_Gradient(QString& output, PageItem *currItem);
9803 fschmid 160
        QString PDF_DoLinGradient(PageItem *currItem, QList<double> Stops, QList<double> Trans, const QStringList& Colors, QStringList colorNames, QList<int> colorShades);
5748 fschmid 161
        QString PDF_TransparenzFill(PageItem *currItem);
162
        QString PDF_TransparenzStroke(PageItem *currItem);
11060 jghali 163
        bool    PDF_Annotation(PageItem *ite, uint PNr);
164
        void    PDF_Form(const QString& im);
12080 avox 165
        void    PDF_xForm(uint objNr, double w, double h, QString im);
15706 jghali 166
        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 167
        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);
168
#if HAVE_PODOFO
169
        void copyPoDoFoObject(const PoDoFo::PdfObject* obj, uint scObjID, QMap<PoDoFo::PdfReference, uint>& importedObjects);
170
        void copyPoDoFoDirect(const PoDoFo::PdfVariant* obj, QList<PoDoFo::PdfReference>& referencedObjects, QMap<PoDoFo::PdfReference, uint>& importedObjects);
171
#endif
172
 
10427 cbradney 173
        int bytesWritten() { return Spool.pos(); }
4229 craig 174
 
11060 jghali 175
 
176
        QString Content;
177
        QString ErrorMessage;
4264 craig 178
        ScribusDoc & doc;
179
        const Page * ActPageP;
180
        const PDFOptions & Options;
3133 fschmid 181
        BookMView* Bvie;
182
        QFile Spool;
183
        int Dokument;
184
        struct Dest
185
        {
186
                QString Name;
187
                int Seite;
188
                QString Act;
189
        };
190
        struct Cata
191
        {
192
                int Outlines;
193
                int PageTree;
194
                int Dest;
195
        }
196
        Catalog;
197
        struct PagT
198
        {
13750 jghali 199
                QMap<int, int> Kids;
3133 fschmid 200
                int Count;
201
        }
202
        PageTree;
203
        struct PagL
204
        {
205
                int ObjNum;
206
                int Thumb;
207
                QMap<QString,int> XObjects;
208
                QMap<QString,int> ImgObjects;
209
                QMap<QString,int> FObjects;
9803 fschmid 210
                QList<int> AObjects;
211
                QList<int> FormObjects;
3133 fschmid 212
        }
213
        Seite;
214
        struct OutL
215
        {
216
                int First;
217
                int Last;
218
                int Count;
219
        }
220
        Outlines;
221
        struct Bead
222
        {
223
                int Parent;
224
                int Next;
225
                int Prev;
226
                int Page;
227
                QRect Recht;
228
        };
229
        struct ICCD
230
        {
231
                int ResNum;
12732 fschmid 232
                int components;
3133 fschmid 233
                QString ResName;
234
                QString ICCArray;
235
        };
236
        struct OCGInfo
237
        {
238
                int ObjNum;
239
                bool visible;
240
                QString Name;
241
        };
242
        struct SpotC
243
        {
244
                int ResNum;
245
                QString ResName;
246
        };
6562 fschmid 247
        struct gData
248
        {
249
                int ResNumG;
250
                int ResNumX;
251
                QString ResNamG;
252
                QString ResNamX;
253
                QString data;
254
        };
3133 fschmid 255
        QMap<QString,ShIm> SharedImages;
9803 fschmid 256
        QList<uint> XRef;
257
        QList<Dest> NamedDest;
258
        QList<int> Threads;
259
        QList<Bead> Beads;
260
        QList<int> CalcFields;
6378 fschmid 261
        QMap<QString,int> Patterns;
3133 fschmid 262
        QMap<QString,int> Shadings;
263
        QMap<QString,int> Transpar;
264
        QMap<QString,ICCD> ICCProfiles;
11908 fschmid 265
        QHash<QString, OCGInfo> OCGEntries;
13765 jghali 266
        QTextCodec* ucs2Codec;
3133 fschmid 267
        int ObjCounter;
268
        QString ResNam;
269
        int ResCount;
270
        QString NDnam;
271
        QString Datum;
272
        int NDnum;
273
        QMap<QString, QString> UsedFontsP;
8454 fschmid 274
        QMap<QString, QString> UsedFontsF;
3133 fschmid 275
        QByteArray KeyGen;
276
        QByteArray OwnerKey;
277
        QByteArray UserKey;
278
        QByteArray FileID;
279
        QByteArray EncryKey;
280
        int Encrypt;
281
        int KeyLen;
282
        QString HTName;
283
        bool BookMinUse;
284
        ColorList colorsToUse;
285
        QMap<QString, SpotC> spotMap;
6925 fschmid 286
        QMap<QString, SpotC> spotMapReg;
3133 fschmid 287
        QString spotNam;
288
        int spotCount;
6407 fschmid 289
        int inPattern;
8559 subik 290
        QDataStream outStream;
4017 fschmid 291
        QMap<QString, QString> StdFonts;
4028 cbradney 292
        MultiProgressDialog* progressDialog;
4223 craig 293
        bool abortExport;
4028 cbradney 294
        bool usingGUI;
8171 fschmid 295
        double bleedDisplacementX;
296
        double bleedDisplacementY;
8469 fschmid 297
        QMap<QString, QMap<uint, uint> > Type3Fonts;
4028 cbradney 298
 
299
protected slots:
300
        void cancelRequested();
3133 fschmid 301
};
302
 
303
#endif
304
 
13815 jghali 305