Subversion Repositories Scribus

Rev

Rev 2032 | Rev 2036 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1972 craig 1
#ifndef PDFOPTIONS_H
2
#define PDFOPTIONS_H
3
 
4
/**
5
 * @file pdfoptions.h
6
 * @author Franz Schmidt
7
 * @author Craig Ringer
8
 * @brief Defines class PDFOptions, used for loading/saving/passing around PDF options
9
 */
10
 
11
#include "qstring.h"
12
#include "qmap.h"
13
#include "qvaluelist.h"
2030 craig 14
#include "qdom.h"
1972 craig 15
 
16
struct LPIData;
17
struct PDFPresentationData;
18
 
19
/**
20
 * @brief PDF Options struture. Capable of saving and loading to/from file and verifying its self.
21
 */
22
class PDFOptions
23
{
24
public:
25
        // Note: A default constructor, copy constructor, and
26
        // assignment operator must be defined so that this class
27
        // can be used as a value.
28
        // The automatically generated ones are quite sufficient.
29
        //PDFOptions();
30
        //PDFOptions(const PDFOptions& other);
31
        //PDFOptions& operator=(const PDFOptions& other);
32
        //~PDFOptions() {};
33
 
34
        enum VerifyResults
35
        {
36
                Verify_NoError = 0,
37
                Verify_OptionConflict,
38
                Verify_OptionOutOfRange,
39
                Verify_OtherError
40
        };
41
 
1973 craig 42
        enum PDFVersion
43
        {
44
                PDFVersion_13 = 13,
45
                PDFVersion_14 = 14,
46
                PDFVersion_15 = 15,
47
                PDFVersion_X3 = 12,
48
        };
49
 
1972 craig 50
        /**
51
         * @author Craig Ringer
52
         * @brief Sanity check the options defined.
53
         *
54
         * Unimplemented, always returns Verify_OtherError
55
         *
56
         * Checks the PDF option structure for conflicts between mututally
57
         * exclusive options, ensures all options are within sane ranges,
58
         * and that there are no nonsensical options values set. If nothing
59
         * is wrong, returns Verify_NoError, otherwise returns error code from
60
         * PDFOptions::VerifyResults. If problemDescription is not NULL,
61
         * it will contain a human-readable description of the error on return.
62
         *
63
         * @warning DO NOT *EVER* TEST THE VALUE OF problemDescription. Rely on the
64
         *                      return code instead. problemDescription is subject to
65
         *                      translation and its contents may change without notice.
66
         *
67
         * @param problemDescription Error description
68
         * @return Verify_NoError for sane options, otherwise error code.
69
         */
70
        PDFOptions::VerifyResults verify(QString* problemDescription);
2030 craig 71
        PDFOptions::VerifyResults verify();
1972 craig 72
 
73
        bool Thumbnails;
74
        bool Articles;
75
        bool useLayers;
76
        bool Compress;
77
        int CompressMethod;
78
        int Quality;
79
        bool RecalcPic;
80
        bool Bookmarks;
81
        int PicRes;
1973 craig 82
        PDFVersion Version;
1972 craig 83
        int Resolution;
84
        int Binding;
85
        QValueList<QString> EmbedList;
86
        QValueList<QString> SubsetList;
87
        bool MirrorH;
88
        bool MirrorV;
89
        int RotateDeg;
90
        bool PresentMode;
91
        QValueList<PDFPresentationData> PresentVals;
92
        QString Datei;
93
        bool isGrayscale;
94
        bool UseRGB;
95
        bool UseProfiles;
96
        bool UseProfiles2;
97
        bool UseLPI;
98
        QMap<QString,LPIData> LPISettings;
99
        QString SolidProf;
100
        int SComp;
101
        QString ImageProf;
102
        bool EmbeddedI;
103
        int Intent2;
104
        QString PrintProf;
105
        QString Info;
106
        int Intent;
107
        double BleedTop;
108
        double BleedLeft;
109
        double BleedRight;
110
        double BleedBottom;
111
        bool Encrypt;
112
        QString PassOwner;
113
        QString PassUser;
114
        int Permissions;
115
};
116
 
2030 craig 117
/*
118
 * @brief Helper class for reading/writing PDFOptions
119
 * @author Craig Ringer
120
 *
121
 * PDFOptionsIO reads and writes PDFOptions to various
122
 * formats. Currently only a custom XML format is
123
 * supported, but support for reading/writing Adobe's
124
 * .joboptions (for example) might be added in future.
125
 *
126
 * Usage:
127
 *    // Writing:
128
 *    // where `opts' is an existing PDFOptions instance
129
 *    PDFOptionsIO io(opts);
130
 *    if (!io.writeTo("/path/to/file"))
2032 craig 131
 *       qDebug("Failed to save settings: %s", io.lastError.utf8());
2030 craig 132
 *
133
 *    // Reading:
134
 *    PDFOptions opts;
135
 *    PDFOptionsIO io(opts);
136
 *    if (!io.readFrom("/path/to/file"))
2032 craig 137
 *       qDebug("Failed to load settings: %s", io.lastError.utf8());
2030 craig 138
 */
139
class PDFOptionsIO
140
{
141
public:
142
        /**
143
         * @brief simple ctor
144
         */
145
        PDFOptionsIO(PDFOptions& opts);
146
 
147
        /**
148
         * @brief Save the PDF settings to a file or other stream
149
         *
150
         * @warning unimplemented, always fails.
151
         *
152
         * @param outStream QTextStream to write output to.
153
         * @return True for success.
154
         */
155
        bool writeTo(QTextStream& outStream);
156
        bool writeTo(QString outFileName);
157
 
158
        /**
159
         * @brief Load the PDF settings from a file or other data stream, overwriting
160
         *        any current settings
161
         *
162
         * @warning unimplemented, always fails
163
         *
164
         * @warning on failure, struct contents are undefined.
165
         *
166
         * @param inStream QTextStream to settings data from.
167
         * @return True for success.
168
         */
169
        bool readFrom(QTextStream& inStream);
170
        bool readFrom(QString inFileName);
171
 
2031 craig 172
        /**
173
         * @brief Return human-readable explanation of last error.
174
         * @warning Do not depend on particular values of this in your code.
175
         */
176
        const QString& lastError() const;
177
 
2030 craig 178
protected:
2033 craig 179
        // Build and return an XML representation of the settings.
180
        // QString::null is returned on failure, in which case
181
        // the error string is set.
182
        QString PDFOptionsIO::buildXMLString();
183
 
2030 craig 184
        // Populate the current DOM tree with the settings from the
185
        // current PDFOptions instance.
2031 craig 186
        void buildSettings();
2030 craig 187
 
188
        // Helper functions. Add elements under the root element
189
        // with a single attribute "value=" set to the passed value.
190
        void addElem(QString name, bool value);
191
        void addElem(QString name, QString value);
192
        void addElem(QString name, int value);
193
        void addElem(QString name, double value);
2031 craig 194
        void addList(QString name, QValueList<QString>& value);
2030 craig 195
 
196
        // The QDomDocument used by the class for all its XML work
197
        QDomDocument doc;
198
        // The root element
199
        QDomElement root;
200
        // The PDFOptions instance we're operating on
201
        PDFOptions* opts;
202
 
203
        // Version, of the form Mmpr: Major, minor, patch, revision
204
        // eg 1300 - 1.3.0r0
205
        static const int formatVersion;
2031 craig 206
 
207
        // Error explanation if a function fails
208
        // For user only, do not depend on particular values of this.
209
        QString error;
2030 craig 210
};
211
 
1972 craig 212
#endif