Subversion Repositories Scribus

Rev

Rev 24826 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14043 jghali 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>
25153 craig 12
#include <QObject>
14043 jghali 13
#include <QPair>
14
#include <QString>
24292 craig 15
#include <QTransform>
14043 jghali 16
#include "scconfig.h"
17
 
18
#ifdef HAVE_PODOFO
19
#include <podofo/podofo.h>
20
#endif
21
 
22
enum PDFContentStreamKeyword
23
{
24
        KW_k,
25
        KW_K,
26
        KW_rg,
27
        KW_RG,
28
        KW_g,
29
        KW_G,
30
        KW_CS,
31
        KW_cs,
32
        KW_SC,
33
        KW_SCN,
34
        KW_sc,
35
        KW_scn,
36
        KW_Do,
37
        KW_BI,
38
        KW_ID,
39
        KW_EI,
40
        KW_gs,
41
        KW_Tf,
42
        KW_cm,
43
        KW_q,
44
        KW_Q,
45
        KW_w,
46
        KW_J,
47
        KW_j,
48
        KW_M,
49
        KW_d,
50
        KW_Undefined
51
};
52
enum PDFColorSpace
53
{
54
        CS_DeviceGray,
55
        CS_DeviceRGB,
56
        CS_DeviceCMYK,
57
        CS_CalGray,
58
        CS_CalRGB,
59
        CS_Lab,
60
        CS_ICCBased,
61
        CS_Pattern,
62
        CS_Indexed,
63
        CS_Separation,
64
        CS_DeviceN,
65
        CS_Unknown
66
};
67
enum PDFFontType
68
{
69
        F_Type1,
70
        F_MMType1,
71
        F_TrueType,
72
        F_Type3,
73
        F_CIDFontType0,
74
        F_CIDFontType2,
75
        F_Unknown
76
};
77
struct PDFFont
78
{
79
        PDFFontType fontType;
80
        bool isEmbedded;
81
        bool isOpenType;
82
        PDFFont()
83
        {
84
                fontType = F_Unknown;
85
                isEmbedded = false;
86
                isOpenType = false;
87
        }
88
};
89
struct PDFGraphicState
90
{
24292 craig 91
        QTransform ctm;
14043 jghali 92
        PDFColorSpace strokeCS;
93
        PDFColorSpace fillCS;
94
        QList<double> strokeColor;
95
        QList<double> fillColor;
96
        double lineWidth;
97
        int lineCap;
98
        int lineJoin;
99
        double miterLimit;
100
        QPair<QList<int>, int> dashPattern;
101
        QPair<PDFFont, double> font;
102
        QList<QString> blendModes;
103
        double fillAlphaConstant;
104
        double strokeAlphaConstant;
105
        PDFGraphicState()
106
        {
107
                strokeCS = CS_DeviceGray;
108
                fillCS = CS_DeviceGray;
109
                strokeColor.append(0);
110
                fillColor.append(0);
111
                lineWidth = 1;
112
                lineCap = 0;
113
                lineJoin = 0;
114
                miterLimit = 10;
115
                QList<int> dashArray;
116
                int dashPhase = 0;
117
                dashPattern.first = dashArray;
118
                dashPattern.second = dashPhase;
119
                blendModes.append("Normal");
120
                fillAlphaConstant = 1;
121
                strokeAlphaConstant = 1;
122
        }
123
};
124
struct PDFImage
125
{
126
        QString imgName;
127
        int dpiX;
128
        int dpiY;
129
};
130
 
131
/**
132
 * PDFAnalyzer provides the facility to report various properties of a PDF.
133
 * At the moment, it can parse/analyze and record used color spaces, the use of transparency,
134
 * used fonts, and existing images in a page of a PDF.
135
 *
136
 * This class will be used by DocumentChecker's class to preflight and report any incompatible
137
 * properties according to a checker's profile.
138
 */
139
class PDFAnalyzer : public QObject
140
{
141
        Q_OBJECT
142
 
143
public:
144
        /**
145
         * Instantiate a new PDFAnalyzer that will operate on the PDF specified by `filename'.
146
         *
147
         * \param filename Path to the PDF being analyzed.
148
         */
149
        PDFAnalyzer(QString& filename);
150
        ~PDFAnalyzer();
151
 
152
        /**
153
         * Perform the actual inspection on one page of the PDF.
154
         *
155
         * \return A boolean is return indicating whether the process is successful.
24665 jghali 156
         * \param pageNum Specifying the page's number (zero-based) in the PDF where the analyzing process is operated on.
14043 jghali 157
         * \param usedColorSpaces List of used color spaces in the page which will be filled while processing.
158
         * \param hasTransparency A boolean which will be set to true after analyzing if the page contains transparency.
159
         * \param usedFonts List of used fonts in the page which will be filled while processing.
160
         * \param imgs List of images that this page contains.
161
         */
162
        bool inspectPDF(int pageNum, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs);
163
#ifdef HAVE_PODOFO
164
private:
165
        // pointer to the PoDoFo Pdf's object
166
        PoDoFo::PdfMemDocument* m_doc;
167
 
23525 jghali 168
        // Path to the analyzed file
169
        QString m_filename;
170
 
14043 jghali 171
        // Call to this method to inspect a PdfCanvas (either a PdfPage or PdfXObject of subtype Form). This method will be called by inspectPDF
172
        // to start inspecting a PDF's page; it could well be called recursively to continue analyzing further in case form XObjects are painted
173
        // onto the page.
174
        bool inspectCanvas(PoDoFo::PdfCanvas* canvas, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs);
175
 
176
        // Helper method to analyze a ColorSpace's array. They all have the form [/csType ...] (section 4.5 in PDF Spec 1.6).
177
        // csObject is a pointer to a PoDoFo's PdfObject which is in fact a PdfArray underneath.
178
        // A color space's type is returned.
179
        PDFColorSpace getCSType(PoDoFo::PdfObject* csObject);
180
 
181
        // Helper method to inspect a graphic state parameter dictionary (ExtGState subdictionary in the resource dictionary; Section 4.3.4 in PDF Spec 1.6).
182
        // Triggered by hitting a gs operator in the content stream.
183
        // extGStateObj is a pointer to a PoDoFo's PdfObject which is in fact a dictionary underneath.
184
        void inspectExtGStateObj(PoDoFo::PdfObject* extGStateObj, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, PDFGraphicState & currGS);
185
 
186
        // Helper method to analyze a font dictionary (section 5.4-5.8 in PDF Spec 1.6)
187
        // A PDFFont struct is returned containing some basic info regarding the specified font.
188
        PDFFont getFontInfo(PoDoFo::PdfObject* fontObj);
189
#endif
190
};
191
#endif