Subversion Repositories Scribus

Rev

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