Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
1972 craig 1
#include "pdfoptions.h"
2
#include "scribusstructs.h"
3
 
2030 craig 4
PDFOptions::VerifyResults PDFOptions::verify()
1972 craig 5
{
2030 craig 6
        return verify(static_cast<QString*>(NULL));
7
}
8
 
9
PDFOptions::VerifyResults PDFOptions::verify(QString* /*problemDescription*/)
10
{
1972 craig 11
        // TODO: implement this method
2031 craig 12
        return Verify_NoError;
1972 craig 13
}
14
 
2030 craig 15
 
16
 
17
 
18
const int PDFOptionsIO::formatVersion = 1300;
19
 
20
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
2031 craig 21
        doc("PDFSettings"),
22
        error()
1972 craig 23
{
2030 craig 24
        this->opts = &opts;
1972 craig 25
}
26
 
2030 craig 27
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
28
bool PDFOptionsIO::writeTo(QString outFileName)
1972 craig 29
{
2031 craig 30
        QFile f(outFileName);
31
        f.open(IO_WriteOnly|IO_Truncate);
32
        QTextStream ts(&f);
2030 craig 33
        return writeTo(ts);
1972 craig 34
}
35
 
2030 craig 36
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
37
bool PDFOptionsIO::writeTo(FILE* outFilePtr)
1972 craig 38
{
39
        QTextStream ts(outFilePtr, IO_WriteOnly|IO_Truncate);
2030 craig 40
        return writeTo(ts);
1972 craig 41
}
42
 
2030 craig 43
bool PDFOptionsIO::writeTo(QTextStream& outStream)
1972 craig 44
{
2030 craig 45
        if (!outStream.device()->isWritable())
2031 craig 46
        {
47
                error = QObject::tr("Output stream not writeable");
2030 craig 48
                return false;
2031 craig 49
        }
2030 craig 50
        // Verify to make sure our settings are sane
51
        PDFOptions::VerifyResults vr = opts->verify();
52
        if (vr != PDFOptions::Verify_NoError)
53
        {
2031 craig 54
                error = QObject::tr("Verification of settings failed: %1").arg(vr);
2030 craig 55
                return false;
56
        }
57
        // Build the document. Initial implementation uses QDom.
58
        root = doc.createElement("ScribusPDFOpts");
59
        root.setAttribute("version", formatVersion);
60
        doc.appendChild(root);
61
        // Fill the guts of the document
2031 craig 62
        buildSettings();
2030 craig 63
        // We're done - save it to the output stream
64
        QString xml = doc.toString();
65
        outStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
66
        outStream << doc.toString();
2031 craig 67
        error = QString::null;
2030 craig 68
        return true;
69
}
70
 
71
// Build up the stored settings into the passed DOM objects
2031 craig 72
void PDFOptionsIO::buildSettings()
2030 craig 73
{
74
        addElem("thumbnails", opts->Thumbnails);
75
        addElem("articles", opts->Articles);
76
        addElem("useLayers", opts->useLayers);
77
        addElem("compress", opts->Compress);
78
        addElem("compressMethod", opts->CompressMethod);
79
        addElem("quality", opts->Quality);
80
        addElem("recalcPic", opts->RecalcPic);
81
        addElem("bookmarks", opts->Bookmarks);
82
        addElem("picRes", opts->PicRes);
83
        QString pdfVersString;
84
        switch (opts->Version)
85
        {
86
                case PDFOptions::PDFVersion_X3:
87
                        pdfVersString = "X3";
88
                        break;
89
                default:
90
                        pdfVersString = QString::number(opts->Version);
91
                        break;
92
        }
93
        addElem("pdfVersion", pdfVersString);
94
        addElem("resolution", opts->Resolution);
95
        addElem("binding", opts->Binding);
2031 craig 96
        addList("embedFonts", opts->EmbedList);
97
        addList("subsetFonts", opts->SubsetList);
2030 craig 98
        addElem("mirrorH", opts->MirrorH);
99
        addElem("mirrorV", opts->MirrorV);
100
        addElem("rotateDegrees", opts->RotateDeg);
101
        addElem("presentMode", opts->PresentMode);
2031 craig 102
        // FIXME: Save opts->PresentVals
2030 craig 103
        addElem("filename", opts->Datei);
104
        addElem("isGrayscale", opts->isGrayscale);
105
        addElem("useRGB", opts->UseRGB);
106
        addElem("useProfiles", opts->UseProfiles);
107
        addElem("useProfiles2", opts->UseProfiles2);
108
        addElem("useLPI", opts->UseLPI);
2031 craig 109
        // FIXME: Save opts->LPISettings
2030 craig 110
        addElem("solidProf", opts->SolidProf);
111
        addElem("sComp", opts->SComp);
112
        addElem("imageProf", opts->ImageProf);
113
        addElem("embeddedI", opts->EmbeddedI);
114
        addElem("intent2", opts->Intent2);
115
        addElem("printProf", opts->PrintProf);
116
        addElem("info", opts->Info);
117
        addElem("intent", opts->Intent);
118
        addElem("bleedTop", opts->BleedTop);
119
        addElem("bleedLeft", opts->BleedLeft);
120
        addElem("bleedRight", opts->BleedRight);
121
        addElem("bleedBottom", opts->BleedBottom);
122
        addElem("encrypt", opts->Encrypt);
123
        addElem("passOwner", opts->PassOwner);
124
        addElem("passUser", opts->PassUser);
125
        addElem("permissions", opts->Permissions);
126
}
127
 
128
// Convenience functions to add a single-attribute element
129
// of a particular type to the tree.
130
 
131
void PDFOptionsIO::addElem(QString name, bool value)
132
{
133
        QDomElement elem = doc.createElement(name);
134
        elem.setAttribute("value",value);
135
        root.appendChild(elem);
136
}
137
 
138
void PDFOptionsIO::addElem(QString name, QString value)
139
{
140
        QDomElement elem = doc.createElement(name);
141
        elem.setAttribute("value",value);
142
        root.appendChild(elem);
143
}
144
 
145
void PDFOptionsIO::addElem(QString name, int value)
146
{
147
        QDomElement elem = doc.createElement(name);
148
        elem.setAttribute("value",value);
149
        root.appendChild(elem);
150
}
151
 
152
void PDFOptionsIO::addElem(QString name, double value)
153
{
154
        QDomElement elem = doc.createElement(name);
155
        elem.setAttribute("value",value);
156
        root.appendChild(elem);
157
}
158
 
2031 craig 159
void PDFOptionsIO::addList(QString name, QValueList<QString>& value)
160
{
161
        // Save a QValueList<String> or QStringList as a list of
162
        // <item value=""> elements
163
        // List base element has no attributes, only children
164
        QDomElement listbase = doc.createElement(name);
165
        root.appendChild(listbase);
166
        QValueList<QString>::iterator it;
167
        for (it = value.begin(); it != value.end(); ++it)
168
        {
169
                QDomElement child = doc.createElement("item");
170
                child.setAttribute("value",*(it));
171
                listbase.appendChild(child);
172
        }
173
}
2030 craig 174
 
175
bool PDFOptionsIO::readFrom(QTextStream& inStream)
176
{
1972 craig 177
        if (!inStream.device()->isReadable())
178
                return false;
179
        // TODO: implement this method
180
        return false;
181
}
182
 
183
// overload of bool readFrom(QTextStream& inStream)
2030 craig 184
bool PDFOptionsIO::readFrom(QString inFileName)
1972 craig 185
{
186
        QTextStream ts(inFileName, IO_ReadOnly);
187
        return readFrom(ts);
188
}
189
 
190
// overload of bool readFrom(QTextStream& inStream)
2030 craig 191
bool PDFOptionsIO::readFrom(FILE* inFilePtr)
1972 craig 192
{
193
        QTextStream ts(inFilePtr, IO_ReadOnly);
194
        return readFrom(ts);
195
}
2031 craig 196
 
197
const QString& PDFOptionsIO::lastError() const
198
{
199
        return error;
200
}