Scribus
Open source desktop publishing at your fingertips
pdflib_core.h
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 */
7 
8 #ifndef PDFLIBCORE_H
9 #define PDFLIBCORE_H
10 
11 #include <QFile>
12 #include <QDataStream>
13 #include <QPixmap>
14 #include <QList>
15 #include <QStack>
16 #include <string>
17 #include <vector>
18 
19 class QImage;
20 class QRect;
21 class QString;
22 class QTextCodec;
23 class PageItem;
24 class BookMItem;
25 class BookMView;
26 class ScribusDoc;
27 class ScPage;
28 class PDFOptions;
29 class PrefsContext;
30 class MultiProgressDialog;
31 class ScLayer;
32 class ScText;
33 
34 #include "pdfoptions.h"
35 #include "pdfstructs.h"
36 #include "scribusstructs.h"
37 #include "scimagestructs.h"
38 #include "tableborder.h"
39 
40 #ifdef HAVE_PODOFO
41 #include <podofo/podofo.h>
42 #endif
43 
44 #include "pdfwriter.h"
45 
58 class PDFLibCore : public QObject
59 {
60  Q_OBJECT
61 
62 public:
63  explicit PDFLibCore(ScribusDoc & docu);
64  ~PDFLibCore();
65  bool doExport(const QString& fn, const QString& nam, int Components,
66  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs);
67 
68  const QString& errorMessage(void) const;
69  bool exportAborted(void) const;
70 
71 private:
72  struct ShIm
73  {
74  PdfId ResNum;
75  int Width;
76  int Height;
77  int Page;
78  double reso;
79  double sxa;
80  double sya;
81  double xa;
82  double ya;
83  double origXsc;
84  double origYsc;
85  QMap<int, ImageLoadRequest> RequestProps;
86  };
87 
88  bool PDF_IsPDFX();
89  bool PDF_IsPDFX(PDFOptions::PDFVersion ver);
90 
91  bool PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts, BookMView* vi);
92  void PDF_Begin_Catalog();
93  void PDF_Begin_MetadataAndEncrypt();
94  QMap<QString, QMap<uint, FPointArray> >
95  PDF_Begin_FindUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts);
96  void PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& ReallyUsed);
97  void PDF_WriteStandardFonts();
98  PdfFont PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
99  PdfFont PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
100 
101  PdfId PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject);
102  PdfFont PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
103  PdfFont PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
104  PdfFont PDF_EncodeSimpleFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl);
105  PdfFont PDF_EncodeCidFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap);
106  PdfId PDF_EmbedFontObject(const QString& fontName, ScFace &face);
107  PdfId PDF_EmbedFontObject(const QByteArray& ttf, const QByteArray& subtype);
108  PdfId PDF_EmbedType1AsciiFontObject(const QByteArray& fontData);
109  PdfId PDF_EmbedType1BinaryFontObject(const QByteArray& fontData);
110  void PDF_Begin_Colors();
111  void PDF_Begin_Layers();
112 
113  void PDF_Begin_Page(const ScPage* pag, QPixmap pm);
114  void PDF_End_Page(int physPage);
115  bool PDF_TemplatePage(const ScPage* pag, bool clip = false);
116  bool PDF_ProcessPage(const ScPage* pag, uint PNr, bool clip = false);
117  bool PDF_ProcessMasterElements(const ScLayer& layer, const ScPage* page, uint PNr);
118  bool PDF_ProcessPageElements(const ScLayer& layer, const ScPage* page, uint PNr);
119 
120  bool PDF_End_Doc(const QString& PrintPr = "", const QString& Name = "", int Components = 0);
121  void PDF_End_Bookmarks();
122  void PDF_End_Resources();
123  void PDF_End_Outlines();
124  void PDF_End_PageTree();
125  void PDF_End_NamedDests();
126  void PDF_End_FormObjects();
127  void PDF_End_JavaScripts();
128  void PDF_End_Articles();
129  void PDF_End_Layers();
130  void PDF_End_OutputProfile(const QString& PrintPr, const QString& Name, int Components);
131  void PDF_End_Metadata();
132  bool PDF_End_XRefAndTrailer();
133  bool closeAndCleanup();
134 
135  void PDF_Error(const QString& errorMsg);
136  void PDF_Error_WriteFailure(void);
137  void PDF_Error_ImageLoadFailure(const QString& fileName);
138  void PDF_Error_ImageWriteFailure(const QString& fileName);
139  void PDF_Error_MaskLoadFailure(const QString& fileName);
140  void PDF_Error_InsufficientMemory(void);
141 
142 // QByteArray EncodeUTF16(const QString &in);
143  QByteArray EncStream(const QByteArray & in, PdfId ObjNum);
144  QByteArray EncString(const QByteArray & in, PdfId ObjNum);
145  QByteArray EncStringUTF16(const QString & in, PdfId ObjNum);
146 
147  bool EncodeArrayToStream(const QByteArray& in, PdfId ObjNum);
148 
149  int WriteImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal);
150  int WriteJPEGImageToStream(ScImage& image, const QString& fn, PdfId ObjNum, int quality, ColorSpaceEnum format, bool sameFile, bool precal);
151  int WriteFlateImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal);
152 
153 // void CalcOwnerKey(const QString & Owner, const QString & User);
154 // void CalcUserKey(const QString & User, int Permission);
155 // QString FitKey(const QString & pass);
156 
157  QByteArray SetClipPath(PageItem *ite, bool poly = true);
158  QByteArray SetClipPathArray(FPointArray *ite, bool poly = true);
159  QByteArray SetClipPathImage(PageItem *ite);
160 
161  QByteArray SetImagePathAndClip(PageItem *item);
162  QByteArray SetPathAndClip(PageItem *item);
163  QByteArray SetPathAndClip(PageItem *item, bool fillRule);
164 
165  QByteArray setStrokeMulti(struct SingleLine *sl);
166  QByteArray SetColor(const QString& farbe, double Shade);
167  QByteArray SetColor(const ScColor& farbe, double Shade);
168  QByteArray SetGradientColor(const QString& farbe, double Shade);
169  QByteArray putColor(const QString& color, double Shade, bool fill);
170  QByteArray putColorUncached(const QString& color, int Shade, bool fill);
171  QByteArray Write_FormXObject(QByteArray &data, PageItem *controlItem = 0);
172  QByteArray Write_TransparencyGroup(double trans, int blend, QByteArray &data, PageItem *controlItem = 0);
173  QByteArray setTextSt(PageItem *ite, uint PNr, const ScPage* pag);
174  bool setTextCh(PageItem *ite, uint PNr, double x, double y, uint d, QByteArray &tmp, QByteArray &tmp2, const CharStyle& cstyle, GlyphLayout *glyphs, PathData* pdata, const ParagraphStyle& pstyle, const ScPage* pag);
175  void getBleeds(const ScPage* page, double &left, double &right);
176  void getBleeds(const ScPage* page, double &left, double &right, double &bottom, double& top);
177 
178 // // Provide a couple of PutDoc implementations to ease transition away from
179 // // QString abuse and to provide fast paths for constant strings.
180 // void PutDoc(const QString & in) { outStream.writeRawData(in.toLatin1(), in.length()); }
181 // void PutDoc(const QByteArray & in) { outStream.writeRawData(in, in.size()); }
182 // void PutDoc(const char* in) { outStream.writeRawData(in, strlen(in)); }
183 // void PutDoc(const std::string & in) { outStream.writeRawData(in.c_str(), in.length()); }
184 
185  void PutPage(const QByteArray & in) { Content += in; }
186 // void StartObj(PdfId nr);
187 // uint newObject() { return ObjCounter++; }
188  uint WritePDFStream(const QByteArray& cc);
189  uint WritePDFString(const QString& cc);
190  void writeXObject(uint objNr, QByteArray dictionary, QByteArray stream);
191  uint writeObject(QByteArray type, QByteArray dictionary);
192  uint writeGState(QByteArray dictionary) { return writeObject("/ExtGState", dictionary); }
193  uint writeActions(const Annotation&, uint annotationObj);
194 // QString PDFEncode(const QString & in);
195 // QByteArray ComputeMD5(const QString& in);
196 // QByteArray ComputeRC4Key(PdfId ObjNum);
197 
198  QByteArray PDF_PutSoftShadow(PageItem* ite, const ScPage* pag);
199  bool PDF_ProcessItem(QByteArray& output, PageItem* ite, const ScPage* pag, uint PNr, bool embedded = false, bool pattern = false);
200  void PDF_Bookmark(PageItem *currItem, double ypos);
201  bool PDF_HatchFill(QByteArray& output, PageItem *currItem);
202  bool PDF_PatternFillStroke(QByteArray& output, PageItem *currItem, int kind = 0, bool forArrow = false);
203  bool PDF_MeshGradientFill(QByteArray& output, PageItem *currItem);
204  bool PDF_PatchMeshGradientFill(QByteArray& output, PageItem *c);
205  bool PDF_DiamondGradientFill(QByteArray& output, PageItem *currItem);
206  bool PDF_TensorGradientFill(QByteArray& output, PageItem *currItem);
207  bool PDF_GradientFillStroke(QByteArray& output, PageItem *currItem, bool stroke = false, bool forArrow = false);
208  QByteArray PDF_TransparenzFill(PageItem *currItem);
209  QByteArray PDF_TransparenzStroke(PageItem *currItem);
210 #ifdef HAVE_OSG
211  bool PDF_3DAnnotation(PageItem *ite, uint PNr);
212 #endif
213  void PDF_RadioButtons();
214  uint PDF_RadioButton(PageItem *ite, uint parent, QString parentName);
215  bool PDF_Annotation(PageItem *ite, uint PNr);
216  void PDF_Form(const QByteArray& im);
217  void PDF_xForm(uint objNr, double w, double h, QByteArray im);
218  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);
219  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);
220 #if HAVE_PODOFO
221  void copyPoDoFoObject(const PoDoFo::PdfObject* obj, uint scObjID, QMap<PoDoFo::PdfReference, uint>& importedObjects);
222  void copyPoDoFoDirect(const PoDoFo::PdfVariant* obj, QList<PoDoFo::PdfReference>& referencedObjects, QMap<PoDoFo::PdfReference, uint>& importedObjects);
223 #endif
224 
225  quint32 encode32dVal(double val);
226  quint16 encode16dVal(double val);
227  void encodeColor(QDataStream &vs, QString colName, int colShade, QStringList &spotColorSet, bool spotMode);
228 
229  QByteArray drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex);
230  QByteArray createBorderAppearance(PageItem *ite);
231  QByteArray paintBorder(const TableBorder& border, const QPointF& start, const QPointF& end, const QPointF& startOffsetFactors, const QPointF& endOffsetFactors);
232  QByteArray handleBrushPattern(PageItem* ite, QPainterPath &path, const ScPage* pag, uint PNr);
233 
234  void generateXMP(const QString& timeStamp);
235 // int bytesWritten() { return Spool.pos(); }
236 
237  PdfCatalog Catalog;
238  PdfPageData pageData;
239  PdfPageTree PageTree;
240  PdfOutlines Outlines;
241  Pdf::Writer writer;
242  QString baseDir;
243 
244  QByteArray Content;
245  QString ErrorMessage;
246  ScribusDoc & doc;
247  const ScPage * ActPageP;
248  const PDFOptions & Options;
249  BookMView* Bvie;
250  //int Dokument;
251  QMap<QString,ShIm> SharedImages;
252  QList<PdfDest> NamedDest;
253  QList<PdfId> Threads;
254  QList<PdfBead> Beads;
255  QList<PdfId> CalcFields;
256  Pdf::ResourceMap Patterns;
257  Pdf::ResourceMap Shadings;
258  Pdf::ResourceMap Transpar;
259  QMap<QString,PdfICCD> ICCProfiles;
260  QHash<QString, PdfOCGInfo> OCGEntries;
261  QTextCodec* ucs2Codec;
262  QByteArray ResNam;
263  int ResCount;
264  QByteArray NDnam;
265  QByteArray Datum;
266  int NDnum;
267  QMap<QString, PdfFont> UsedFontsP;
268  QMap<QString, PdfFont> UsedFontsF;
269 // QByteArray KeyGen;
270 // QByteArray OwnerKey;
271 // QByteArray UserKey;
272 // QByteArray FileID;
273 // QByteArray EncryKey;
274 // PdfId Encrypt;
275 // int KeyLen;
276  QByteArray HTName;
277  bool BookMinUse;
278  ColorList colorsToUse;
279  QMap<QString, PdfSpotC> spotMap;
280  QMap<QString, PdfSpotC> spotMapReg;
281  QByteArray spotNam;
282  int spotCount;
283  int inPattern;
284  QMap<QString, QString> StdFonts;
285  MultiProgressDialog* progressDialog;
286  bool abortExport;
287  bool usingGUI;
288  double bleedDisplacementX;
289  double bleedDisplacementY;
290  QByteArray xmpPacket;
291  QStack<QPointF> groupStackPos;
292  QStack<QPointF> patternStackPos;
293 
294 protected slots:
295  void cancelRequested();
296 };
297 
298 #endif
299 
300 
301 
Definition: sccolor.h:51
Definition: charstyle.h:78
Definition: pdfstructs.h:69
Definition: scribusstructs.h:120
Definition: sctextstruct.h:109
Definition: scpage.h:46
Tree widget item for PDF Bookmarks. Secret items like Pare, First, Last etc. are PDF Outlines attribu...
Definition: bookmwin.h:40
Definition: tableborder.h:86
Definition: scimage.h:36
Definition: pdfstructs.h:54
Definition: paragraphstyle.h:27
Definition: sccolor.h:155
the Document Class
Definition: scribusdoc.h:90
Definition: pdfstructs.h:62
Definition: pdfwriter.h:146
Definition: pdflib_core.h:58
Definition: pdfstructs.h:156
Base Class ScFace : This is a total rewrite of the old Foi class.
Definition: scface.h:73
Definition: sclayer.h:17
Definition: prefscontext.h:40
PDF Options struture. Capable of verifying its self, but otherwise largely a dumb struct...
Definition: pdfoptions.h:37
Tree widget for PDF Bookmarks. It's a minimal tree implementation with D'n'D handled in Qt4 itself...
Definition: bookmwin.h:75
Definition: pageitem.h:92
Definition: pdfstructs.h:82
Definition: annotation.h:35
Definition: textlayout.h:44
Definition: fpointarray.h:42
Defines class PDFOptions, used for loading/saving/passing around PDF options.
Definition: sctextstruct.h:54
Main class SCFonts. Subclass of QDict. This class replaces the previous SCFonts typedef...
Definition: scfonts.h:36