Subversion Repositories Scribus

Rev

Rev 21017 | Rev 21254 | 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>
16258 fschmid 15
#include <QStack>
4265 craig 16
#include <string>
3699 cbradney 17
#include <vector>
3133 fschmid 18
 
13764 jghali 19
class QImage;
20
class QRect;
3133 fschmid 21
class QString;
13764 jghali 22
class QTextCodec;
3133 fschmid 23
class PageItem;
24
class BookMItem;
25
class BookMView;
26
class ScribusDoc;
16729 fschmid 27
class ScPage;
3133 fschmid 28
class PDFOptions;
3252 craig 29
class PrefsContext;
4028 cbradney 30
class MultiProgressDialog;
13873 jghali 31
class ScLayer;
5291 avox 32
class ScText;
3699 cbradney 33
 
19115 avox 34
#include "pdfoptions.h"
20103 avox 35
#include "pdfstructs.h"
3133 fschmid 36
#include "scribusstructs.h"
12892 fschmid 37
#include "scimagestructs.h"
17312 fschmid 38
#include "tableborder.h"
3133 fschmid 39
 
12080 avox 40
#ifdef HAVE_PODOFO
41
#include <podofo/podofo.h>
42
#endif
43
 
20103 avox 44
#include "pdfwriter.h"
12080 avox 45
 
21107 craig 46
class PdfPainter;
47
 
3133 fschmid 48
/**
10054 craig 49
 * PDFLibCore provides Scribus's implementation of PDF export functionality.
50
 *
51
 * This is not public API and is not exported in Scribus's symbol table on supporting
52
 * platforms. Do not include this header, use pdflib.h instead. Including this header
53
 * from anywhere except pdflib.cpp may cause linker errors and other problems,
21017 craig 54
 * and is totally pointless since all the interfaces that are publicly
10054 craig 55
 * visible are presented by PDFlib anyway.
56
 *
57
 *@author Franz Schmid
58
 */
3133 fschmid 59
 
10054 craig 60
class PDFLibCore : public QObject
3133 fschmid 61
{
62
        Q_OBJECT
63
 
21107 craig 64
friend class PdfPainter;
65
 
3133 fschmid 66
public:
10054 craig 67
        explicit PDFLibCore(ScribusDoc & docu);
68
        ~PDFLibCore();
4264 craig 69
        bool doExport(const QString& fn, const QString& nam, int Components,
70
                                  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs);
4223 craig 71
 
11060 jghali 72
        const QString& errorMessage(void) const;
11441 jghali 73
        bool  exportAborted(void) const;
11060 jghali 74
 
4223 craig 75
private:
12080 avox 76
        struct ShIm
77
        {
20103 avox 78
                PdfId ResNum;
12080 avox 79
                int Width;
80
                int Height;
13949 fschmid 81
                int Page;
12080 avox 82
                double reso;
83
                double sxa;
84
                double sya;
85
                double xa;
86
                double ya;
12845 fschmid 87
                double origXsc;
88
                double origYsc;
12892 fschmid 89
                QMap<int, ImageLoadRequest> RequestProps;
12080 avox 90
        };
14043 jghali 91
 
19115 avox 92
        bool PDF_IsPDFX();
93
        bool PDF_IsPDFX(PDFOptions::PDFVersion ver);
94
 
20103 avox 95
        bool PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts, BookMView* vi);
20112 jghali 96
        void PDF_Begin_Catalog();
97
        void PDF_Begin_MetadataAndEncrypt();
98
        QMap<QString, QMap<uint, FPointArray> >
99
             PDF_Begin_FindUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts);
100
        void PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& ReallyUsed);
101
        void PDF_WriteStandardFonts();
102
        PdfFont PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
103
        PdfFont PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
104
 
105
        PdfId PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject);
106
        PdfFont PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
107
        PdfFont PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
108
        PdfFont PDF_EncodeSimpleFont(const QByteArray& fontname, ScFace& face,  const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl);
109
        PdfFont PDF_EncodeCidFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap);
110
        PdfId PDF_EmbedFontObject(const QString& fontName, ScFace &face);
111
        PdfId PDF_EmbedFontObject(const QByteArray& ttf, const QByteArray& subtype);
112
        PdfId PDF_EmbedType1AsciiFontObject(const QByteArray& fontData);
113
        PdfId PDF_EmbedType1BinaryFontObject(const QByteArray& fontData);
114
        void PDF_Begin_Colors();
115
        void PDF_Begin_Layers();
116
 
18194 fschmid 117
        void PDF_Begin_Page(const ScPage* pag, QPixmap pm);
15444 craig 118
        void PDF_End_Page(int physPage);
16729 fschmid 119
        bool PDF_TemplatePage(const ScPage* pag, bool clip = false);
120
        bool PDF_ProcessPage(const ScPage* pag, uint PNr, bool clip = false);
121
        bool PDF_ProcessMasterElements(const ScLayer& layer, const ScPage* page, uint PNr);
122
        bool PDF_ProcessPageElements(const ScLayer& layer, const ScPage* page, uint PNr);
20112 jghali 123
 
12387 jghali 124
        bool PDF_End_Doc(const QString& PrintPr = "", const QString& Name = "", int Components = 0);
20112 jghali 125
        void PDF_End_Bookmarks();
126
        void PDF_End_Resources();
127
        void PDF_End_Outlines();
128
        void PDF_End_PageTree();
129
        void PDF_End_NamedDests();
130
        void PDF_End_FormObjects();
131
        void PDF_End_JavaScripts();
132
        void PDF_End_Articles();
133
        void PDF_End_Layers();
134
        void PDF_End_OutputProfile(const QString& PrintPr, const QString& Name, int Components);
135
        void PDF_End_Metadata();
136
        bool PDF_End_XRefAndTrailer();
137
        bool closeAndCleanup();
3133 fschmid 138
 
11060 jghali 139
        void PDF_Error(const QString& errorMsg);
12387 jghali 140
        void PDF_Error_WriteFailure(void);
11060 jghali 141
        void PDF_Error_ImageLoadFailure(const QString& fileName);
11599 jghali 142
        void PDF_Error_ImageWriteFailure(const QString& fileName);
11389 jghali 143
        void PDF_Error_MaskLoadFailure(const QString& fileName);
11060 jghali 144
        void PDF_Error_InsufficientMemory(void);
145
 
20103 avox 146
//      QByteArray EncodeUTF16(const QString &in);
147
        QByteArray EncStream(const QByteArray & in, PdfId ObjNum);
148
        QByteArray EncString(const QByteArray & in, PdfId ObjNum);
149
        QByteArray EncStringUTF16(const QString & in, PdfId ObjNum);
19114 avox 150
 
20103 avox 151
        bool       EncodeArrayToStream(const QByteArray& in, PdfId ObjNum);
19114 avox 152
 
20103 avox 153
        int     WriteImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal);
154
        int     WriteJPEGImageToStream(ScImage& image, const QString& fn, PdfId ObjNum, int quality, ColorSpaceEnum format, bool sameFile, bool precal);
155
        int     WriteFlateImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal);
11599 jghali 156
 
20103 avox 157
//      void    CalcOwnerKey(const QString & Owner, const QString & User);
158
//      void    CalcUserKey(const QString & User, int Permission);
159
//      QString FitKey(const QString & pass);
19114 avox 160
 
20103 avox 161
        QByteArray SetClipPath(PageItem *ite, bool poly = true);
162
        QByteArray SetClipPathArray(FPointArray *ite, bool poly = true);
163
        QByteArray SetClipPathImage(PageItem *ite);
18734 jghali 164
 
20103 avox 165
        QByteArray SetImagePathAndClip(PageItem *item);
166
        QByteArray SetPathAndClip(PageItem *item);
167
        QByteArray SetPathAndClip(PageItem *item, bool fillRule);
18734 jghali 168
 
20103 avox 169
        QByteArray setStrokeMulti(struct SingleLine *sl);
170
        QByteArray SetColor(const QString& farbe, double Shade);
171
        QByteArray SetColor(const ScColor& farbe, double Shade);
172
        QByteArray SetGradientColor(const QString& farbe, double Shade);
173
        QByteArray putColor(const QString& color, double Shade, bool fill);
174
        QByteArray putColorUncached(const QString& color, int Shade, bool fill);
175
    QByteArray Write_FormXObject(QByteArray &data, PageItem *controlItem = 0);
176
        QByteArray Write_TransparencyGroup(double trans, int blend, QByteArray &data, PageItem *controlItem = 0);
177
        QByteArray setTextSt(PageItem *ite, uint PNr, const ScPage* pag);
16729 fschmid 178
        void    getBleeds(const ScPage* page, double &left, double &right);
179
        void    getBleeds(const ScPage* page, double &left, double &right, double &bottom, double& top);
4229 craig 180
 
20103 avox 181
//      // Provide a couple of PutDoc implementations to ease transition away from
182
//      // QString abuse and to provide fast paths for constant strings.
183
//      void PutDoc(const QString & in) { outStream.writeRawData(in.toLatin1(), in.length()); }
184
//      void PutDoc(const QByteArray & in) { outStream.writeRawData(in, in.size()); }
185
//      void PutDoc(const char* in) { outStream.writeRawData(in, strlen(in)); }
186
//      void PutDoc(const std::string & in) { outStream.writeRawData(in.c_str(), in.length()); }
4229 craig 187
 
20103 avox 188
        void       PutPage(const QByteArray & in) { Content += in; }
189
//      void       StartObj(PdfId nr);
190
//      uint       newObject() { return ObjCounter++; }
191
        uint       WritePDFStream(const QByteArray& cc);
19114 avox 192
        uint       WritePDFString(const QString& cc);
20103 avox 193
        void       writeXObject(uint objNr, QByteArray dictionary, QByteArray stream);
194
        uint       writeObject(QByteArray type, QByteArray dictionary);
195
        uint       writeGState(QByteArray dictionary) { return writeObject("/ExtGState", dictionary); }
12429 fschmid 196
        uint       writeActions(const Annotation&, uint annotationObj);
12080 avox 197
//      QString    PDFEncode(const QString & in);
20103 avox 198
//      QByteArray ComputeMD5(const QString& in);
199
//      QByteArray ComputeRC4Key(PdfId ObjNum);
14043 jghali 200
 
20103 avox 201
        QByteArray PDF_PutSoftShadow(PageItem* ite, const ScPage* pag);
202
        bool    PDF_ProcessItem(QByteArray& output, PageItem* ite, const ScPage* pag, uint PNr, bool embedded = false, bool pattern = false);
11060 jghali 203
        void    PDF_Bookmark(PageItem *currItem, double ypos);
20103 avox 204
        bool    PDF_HatchFill(QByteArray& output, PageItem *currItem);
205
        bool    PDF_PatternFillStroke(QByteArray& output, PageItem *currItem, int kind = 0, bool forArrow = false);
206
        bool    PDF_MeshGradientFill(QByteArray& output, PageItem *currItem);
207
        bool    PDF_PatchMeshGradientFill(QByteArray& output, PageItem *c);
208
        bool    PDF_DiamondGradientFill(QByteArray& output, PageItem *currItem);
209
        bool    PDF_TensorGradientFill(QByteArray& output, PageItem *currItem);
210
        bool    PDF_GradientFillStroke(QByteArray& output, PageItem *currItem, bool stroke = false, bool forArrow = false);
211
        QByteArray PDF_TransparenzFill(PageItem *currItem);
212
        QByteArray PDF_TransparenzStroke(PageItem *currItem);
13839 fschmid 213
#ifdef HAVE_OSG
214
        bool    PDF_3DAnnotation(PageItem *ite, uint PNr);
215
#endif
17952 fschmid 216
        void    PDF_RadioButtons();
17963 fschmid 217
        uint    PDF_RadioButton(PageItem *ite, uint parent, QString parentName);
17952 fschmid 218
        bool    PDF_Annotation(PageItem *ite, uint PNr);
20103 avox 219
        void    PDF_Form(const QByteArray& im);
220
        void    PDF_xForm(uint objNr, double w, double h, QByteArray im);
221
        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, QByteArray* output = NULL);
222
        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, QByteArray* output = NULL);
12080 avox 223
#if HAVE_PODOFO
224
        void copyPoDoFoObject(const PoDoFo::PdfObject* obj, uint scObjID, QMap<PoDoFo::PdfReference, uint>& importedObjects);
225
        void copyPoDoFoDirect(const PoDoFo::PdfVariant* obj, QList<PoDoFo::PdfReference>& referencedObjects, QMap<PoDoFo::PdfReference, uint>& importedObjects);
226
#endif
14043 jghali 227
 
18734 jghali 228
        quint32 encode32dVal(double val);
229
        quint16 encode16dVal(double val);
230
        void    encodeColor(QDataStream &vs, QString colName, int colShade, QStringList &spotColorSet, bool spotMode);
231
 
20103 avox 232
        QByteArray drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex);
233
        QByteArray createBorderAppearance(PageItem *ite);
234
        QByteArray paintBorder(const TableBorder& border, const QPointF& start, const QPointF& end, const QPointF& startOffsetFactors, const QPointF& endOffsetFactors);
235
        QByteArray handleBrushPattern(PageItem* ite, QPainterPath &path, const ScPage* pag, uint PNr);
18734 jghali 236
 
19114 avox 237
        void generateXMP(const QString& timeStamp);
20103 avox 238
//      int bytesWritten() { return Spool.pos(); }
4229 craig 239
 
20112 jghali 240
        PdfCatalog Catalog;
241
        PdfPageData pageData;
242
        PdfPageTree PageTree;
243
        PdfOutlines Outlines;
244
        Pdf::Writer writer;
245
        QString baseDir;
246
 
20103 avox 247
        QByteArray Content;
11060 jghali 248
        QString ErrorMessage;
4264 craig 249
        ScribusDoc & doc;
16729 fschmid 250
        const ScPage * ActPageP;
4264 craig 251
        const PDFOptions & Options;
3133 fschmid 252
        BookMView* Bvie;
20103 avox 253
        //int Dokument;
3133 fschmid 254
        QMap<QString,ShIm> SharedImages;
20103 avox 255
        QList<PdfDest> NamedDest;
256
        QList<PdfId> Threads;
257
        QList<PdfBead> Beads;
258
        QList<PdfId> CalcFields;
20112 jghali 259
        Pdf::ResourceMap Patterns;
20103 avox 260
        Pdf::ResourceMap Shadings;
261
        Pdf::ResourceMap Transpar;
262
        QMap<QString,PdfICCD> ICCProfiles;
263
        QHash<QString, PdfOCGInfo> OCGEntries;
19114 avox 264
        QTextCodec* ucs2Codec;
20103 avox 265
        QByteArray ResNam;
3133 fschmid 266
        int ResCount;
20103 avox 267
        QByteArray NDnam;
268
        QByteArray Datum;
3133 fschmid 269
        int NDnum;
20103 avox 270
        QMap<QString, PdfFont> UsedFontsP;
271
        QMap<QString, PdfFont> UsedFontsF;
272
//      QByteArray KeyGen;
273
//      QByteArray OwnerKey;
274
//      QByteArray UserKey;
275
//      QByteArray FileID;
276
//      QByteArray EncryKey;
277
//      PdfId Encrypt;
278
//      int KeyLen;
279
        QByteArray HTName;
3133 fschmid 280
        bool BookMinUse;
281
        ColorList colorsToUse;
20103 avox 282
        QMap<QString, PdfSpotC> spotMap;
283
        QMap<QString, PdfSpotC> spotMapReg;
284
        QByteArray spotNam;
3133 fschmid 285
        int spotCount;
6407 fschmid 286
        int inPattern;
4017 fschmid 287
        QMap<QString, QString> StdFonts;
4028 cbradney 288
        MultiProgressDialog* progressDialog;
4223 craig 289
        bool abortExport;
4028 cbradney 290
        bool usingGUI;
8171 fschmid 291
        double bleedDisplacementX;
292
        double bleedDisplacementY;
20112 jghali 293
        QByteArray xmpPacket;
16258 fschmid 294
        QStack<QPointF> groupStackPos;
17889 fschmid 295
        QStack<QPointF> patternStackPos;
14043 jghali 296
 
4028 cbradney 297
protected slots:
298
        void cancelRequested();
3133 fschmid 299
};
300
 
301
#endif
302
 
13816 jghali 303
 
14043 jghali 304