Scribus
Open source desktop publishing at your fingertips
pdf_analyzer.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 PDFANALYZER_H
9 #define PDFANALYZER_H
10 
11 #include <QList>
12 #include <QPair>
13 #include <QString>
14 #include <QMatrix>
15 #include "scconfig.h"
16 
17 #ifdef HAVE_PODOFO
18 #include <podofo/podofo.h>
19 #endif
20 
21 enum PDFContentStreamKeyword
22 {
23  KW_k,
24  KW_K,
25  KW_rg,
26  KW_RG,
27  KW_g,
28  KW_G,
29  KW_CS,
30  KW_cs,
31  KW_SC,
32  KW_SCN,
33  KW_sc,
34  KW_scn,
35  KW_Do,
36  KW_BI,
37  KW_ID,
38  KW_EI,
39  KW_gs,
40  KW_Tf,
41  KW_cm,
42  KW_q,
43  KW_Q,
44  KW_w,
45  KW_J,
46  KW_j,
47  KW_M,
48  KW_d,
49  KW_Undefined
50 };
51 enum PDFColorSpace
52 {
53  CS_DeviceGray,
54  CS_DeviceRGB,
55  CS_DeviceCMYK,
56  CS_CalGray,
57  CS_CalRGB,
58  CS_Lab,
59  CS_ICCBased,
60  CS_Pattern,
61  CS_Indexed,
62  CS_Separation,
63  CS_DeviceN,
64  CS_Unknown
65 };
66 enum PDFFontType
67 {
68  F_Type1,
69  F_MMType1,
70  F_TrueType,
71  F_Type3,
72  F_CIDFontType0,
73  F_CIDFontType2,
74  F_Unknown
75 };
76 struct PDFFont
77 {
78  PDFFontType fontType;
79  bool isEmbedded;
80  bool isOpenType;
81  PDFFont()
82  {
83  fontType = F_Unknown;
84  isEmbedded = false;
85  isOpenType = false;
86  }
87 };
89 {
90  QMatrix ctm;
91  PDFColorSpace strokeCS;
92  PDFColorSpace fillCS;
93  QList<double> strokeColor;
94  QList<double> fillColor;
95  double lineWidth;
96  int lineCap;
97  int lineJoin;
98  double miterLimit;
99  QPair<QList<int>, int> dashPattern;
100  QPair<PDFFont, double> font;
101  QList<QString> blendModes;
102  double fillAlphaConstant;
103  double strokeAlphaConstant;
105  {
106  strokeCS = CS_DeviceGray;
107  fillCS = CS_DeviceGray;
108  strokeColor.append(0);
109  fillColor.append(0);
110  lineWidth = 1;
111  lineCap = 0;
112  lineJoin = 0;
113  miterLimit = 10;
114  QList<int> dashArray;
115  int dashPhase = 0;
116  dashPattern.first = dashArray;
117  dashPattern.second = dashPhase;
118  blendModes.append("Normal");
119  fillAlphaConstant = 1;
120  strokeAlphaConstant = 1;
121  }
122 };
123 struct PDFImage
124 {
125  QString imgName;
126  int dpiX;
127  int dpiY;
128 };
129 
138 class PDFAnalyzer : public QObject
139 {
140  Q_OBJECT
141 
142 public:
148  PDFAnalyzer(QString& filename);
149  ~PDFAnalyzer();
150 
161  bool inspectPDF(int pageNum, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs);
162 #ifdef HAVE_PODOFO
163 private:
164  // pointer to the PoDoFo Pdf's object
165  PoDoFo::PdfMemDocument* m_doc;
166 
167  // Call to this method to inspect a PdfCanvas (either a PdfPage or PdfXObject of subtype Form). This method will be called by inspectPDF
168  // to start inspecting a PDF's page; it could well be called recursively to continue analyzing further in case form XObjects are painted
169  // onto the page.
170  bool inspectCanvas(PoDoFo::PdfCanvas* canvas, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs);
171 
172  // Helper method to analyze a ColorSpace's array. They all have the form [/csType ...] (section 4.5 in PDF Spec 1.6).
173  // csObject is a pointer to a PoDoFo's PdfObject which is in fact a PdfArray underneath.
174  // A color space's type is returned.
175  PDFColorSpace getCSType(PoDoFo::PdfObject* csObject);
176 
177  // Helper method to inspect a graphic state parameter dictionary (ExtGState subdictionary in the resource dictionary; Section 4.3.4 in PDF Spec 1.6).
178  // Triggered by hitting a gs operator in the content stream.
179  // extGStateObj is a pointer to a PoDoFo's PdfObject which is in fact a dictionary underneath.
180  void inspectExtGStateObj(PoDoFo::PdfObject* extGStateObj, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, PDFGraphicState & currGS);
181 
182  // Helper method to analyze a font dictionary (section 5.4-5.8 in PDF Spec 1.6)
183  // A PDFFont struct is returned containing some basic info regarding the specified font.
184  PDFFont getFontInfo(PoDoFo::PdfObject* fontObj);
185 #endif
186 };
187 #endif
bool inspectPDF(int pageNum, QList< PDFColorSpace > &usedColorSpaces, bool &hasTransparency, QList< PDFFont > &usedFonts, QList< PDFImage > &imgs)
Definition: pdf_analyzer.cpp:824
Definition: pdf_analyzer.h:123
Definition: pdf_analyzer.h:88
PDFAnalyzer(QString &filename)
Definition: pdf_analyzer.cpp:818
Definition: pdf_analyzer.h:76
Definition: pdf_analyzer.h:138