Subversion Repositories Scribus

Rev

Rev 1972 | Rev 2031 | 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
12
        return Verify_OtherError;
13
}
14
 
2030 craig 15
 
16
 
17
 
18
const int PDFOptionsIO::formatVersion = 1300;
19
 
20
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
21
        doc("PDFSettings")
1972 craig 22
{
2030 craig 23
        this->opts = &opts;
1972 craig 24
}
25
 
2030 craig 26
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
27
bool PDFOptionsIO::writeTo(QString outFileName)
1972 craig 28
{
29
        QTextStream ts(outFileName, IO_WriteOnly|IO_Truncate);
2030 craig 30
        return writeTo(ts);
1972 craig 31
}
32
 
2030 craig 33
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
34
bool PDFOptionsIO::writeTo(FILE* outFilePtr)
1972 craig 35
{
36
        QTextStream ts(outFilePtr, IO_WriteOnly|IO_Truncate);
2030 craig 37
        return writeTo(ts);
1972 craig 38
}
39
 
2030 craig 40
bool PDFOptionsIO::writeTo(QTextStream& outStream)
1972 craig 41
{
2030 craig 42
        if (!outStream.device()->isWritable())
43
                return false;
44
        // Verify to make sure our settings are sane
45
        PDFOptions::VerifyResults vr = opts->verify();
46
        if (vr != PDFOptions::Verify_NoError)
47
        {
48
                qDebug("PDFOptionsIO::writeTo(): "
49
                                "verify() failed [%i]", vr);
50
                return false;
51
        }
52
        // Build the document. Initial implementation uses QDom.
53
        root = doc.createElement("ScribusPDFOpts");
54
        root.setAttribute("version", formatVersion);
55
        doc.appendChild(root);
56
        // Fill the guts of the document
57
        if (!buildSettings())
58
        {
59
                qDebug("PDFOptionsIO::writeTo(): "
60
                                "couldn't build settings file");
61
                return false;
62
        }
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();
67
        return true;
68
}
69
 
70
// Build up the stored settings into the passed DOM objects
71
bool PDFOptionsIO::buildSettings()
72
{
73
        addElem("thumbnails", opts->Thumbnails);
74
        addElem("articles", opts->Articles);
75
        addElem("useLayers", opts->useLayers);
76
        addElem("compress", opts->Compress);
77
        addElem("compressMethod", opts->CompressMethod);
78
        addElem("quality", opts->Quality);
79
        addElem("recalcPic", opts->RecalcPic);
80
        addElem("bookmarks", opts->Bookmarks);
81
        addElem("picRes", opts->PicRes);
82
        QString pdfVersString;
83
        switch (opts->Version)
84
        {
85
                case PDFOptions::PDFVersion_X3:
86
                        pdfVersString = "X3";
87
                        break;
88
                default:
89
                        pdfVersString = QString::number(opts->Version);
90
                        break;
91
        }
92
        addElem("pdfVersion", pdfVersString);
93
        addElem("resolution", opts->Resolution);
94
        addElem("binding", opts->Binding);
95
        // EmbedList
96
        // SubsetList
97
        addElem("mirrorH", opts->MirrorH);
98
        addElem("mirrorV", opts->MirrorV);
99
        addElem("rotateDegrees", opts->RotateDeg);
100
        addElem("presentMode", opts->PresentMode);
101
        // PresentVals
102
        addElem("filename", opts->Datei);
103
        addElem("isGrayscale", opts->isGrayscale);
104
        addElem("useRGB", opts->UseRGB);
105
        addElem("useProfiles", opts->UseProfiles);
106
        addElem("useProfiles2", opts->UseProfiles2);
107
        addElem("useLPI", opts->UseLPI);
108
        // LPISettings
109
        addElem("solidProf", opts->SolidProf);
110
        addElem("sComp", opts->SComp);
111
        addElem("imageProf", opts->ImageProf);
112
        addElem("embeddedI", opts->EmbeddedI);
113
        addElem("intent2", opts->Intent2);
114
        addElem("printProf", opts->PrintProf);
115
        addElem("info", opts->Info);
116
        addElem("intent", opts->Intent);
117
        addElem("bleedTop", opts->BleedTop);
118
        addElem("bleedLeft", opts->BleedLeft);
119
        addElem("bleedRight", opts->BleedRight);
120
        addElem("bleedBottom", opts->BleedBottom);
121
        addElem("encrypt", opts->Encrypt);
122
        addElem("passOwner", opts->PassOwner);
123
        addElem("passUser", opts->PassUser);
124
        addElem("permissions", opts->Permissions);
125
        return true;
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
 
159
 
160
bool PDFOptionsIO::readFrom(QTextStream& inStream)
161
{
1972 craig 162
        if (!inStream.device()->isReadable())
163
                return false;
164
        // TODO: implement this method
165
        return false;
166
}
167
 
168
// overload of bool readFrom(QTextStream& inStream)
2030 craig 169
bool PDFOptionsIO::readFrom(QString inFileName)
1972 craig 170
{
171
        QTextStream ts(inFileName, IO_ReadOnly);
172
        return readFrom(ts);
173
}
174
 
175
// overload of bool readFrom(QTextStream& inStream)
2030 craig 176
bool PDFOptionsIO::readFrom(FILE* inFilePtr)
1972 craig 177
{
178
        QTextStream ts(inFilePtr, IO_ReadOnly);
179
        return readFrom(ts);
180
}