Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 2030 → Rev 2029

/branches/Version13x/Scribus/scribus/pdfoptions.h
11,7 → 11,6
#include "qstring.h"
#include "qmap.h"
#include "qvaluelist.h"
#include "qdom.h"
 
struct LPIData;
struct PDFPresentationData;
68,8 → 67,36
* @return Verify_NoError for sane options, otherwise error code.
*/
PDFOptions::VerifyResults verify(QString* problemDescription);
PDFOptions::VerifyResults verify();
 
/**
* @author Craig Ringer
* @brief Save the PDF settings to a file or other stream
*
* @warning unimplemented, always fails.
*
* @param outStream QTextStream to write output to.
* @return True for success.
*/
bool saveTo(QTextStream& outStream) const;
bool saveTo(QString outFileName) const;
bool saveTo(FILE* outFilePtr) const;
 
/**
* @author Craig Ringer
* @brief Load the PDF settings from a file or other data stream, overwriting
* any current settings
*
* @warning unimplemented, always fails
*
* @warning on failure, struct contents are undefined.
*
* @param inStream QTextStream to settings data from.
* @return True for success.
*/
bool readFrom(QTextStream& inStream);
bool readFrom(QString inFileName);
bool readFrom(FILE* inFilePtr);
 
bool Thumbnails;
bool Articles;
bool useLayers;
114,87 → 141,4
int Permissions;
};
 
/*
* @brief Helper class for reading/writing PDFOptions
* @author Craig Ringer
*
* PDFOptionsIO reads and writes PDFOptions to various
* formats. Currently only a custom XML format is
* supported, but support for reading/writing Adobe's
* .joboptions (for example) might be added in future.
*
* Usage:
* // Writing:
* // where `opts' is an existing PDFOptions instance
* PDFOptionsIO io(opts);
* if (!io.writeTo("/path/to/file"))
* // handle error. Not like this:
* qDebug("Darn, it didn't work.");
*
* // Reading:
* PDFOptions opts;
* PDFOptionsIO io(opts);
* if (!io.readFrom("/path/to/file"))
* // handle error. Not like this:
* qDebug("incomprehensible gibberish");
*/
class PDFOptionsIO
{
public:
/**
* @brief simple ctor
*/
PDFOptionsIO(PDFOptions& opts);
 
/**
* @brief Save the PDF settings to a file or other stream
*
* @warning unimplemented, always fails.
*
* @param outStream QTextStream to write output to.
* @return True for success.
*/
bool writeTo(QTextStream& outStream);
bool writeTo(QString outFileName);
bool writeTo(FILE* outFilePtr);
 
/**
* @brief Load the PDF settings from a file or other data stream, overwriting
* any current settings
*
* @warning unimplemented, always fails
*
* @warning on failure, struct contents are undefined.
*
* @param inStream QTextStream to settings data from.
* @return True for success.
*/
bool readFrom(QTextStream& inStream);
bool readFrom(QString inFileName);
bool readFrom(FILE* inFilePtr);
 
protected:
// Populate the current DOM tree with the settings from the
// current PDFOptions instance.
bool buildSettings();
 
// Helper functions. Add elements under the root element
// with a single attribute "value=" set to the passed value.
void addElem(QString name, bool value);
void addElem(QString name, QString value);
void addElem(QString name, int value);
void addElem(QString name, double value);
 
// The QDomDocument used by the class for all its XML work
QDomDocument doc;
// The root element
QDomElement root;
// The PDFOptions instance we're operating on
PDFOptions* opts;
 
// Version, of the form Mmpr: Major, minor, patch, revision
// eg 1300 - 1.3.0r0
static const int formatVersion;
};
 
#endif
/branches/Version13x/Scribus/scribus/pdfoptions.cpp
1,164 → 1,36
#include "pdfoptions.h"
#include "scribusstructs.h"
 
PDFOptions::VerifyResults PDFOptions::verify()
PDFOptions::VerifyResults PDFOptions::verify(QString* problemDescription)
{
return verify(static_cast<QString*>(NULL));
}
 
PDFOptions::VerifyResults PDFOptions::verify(QString* /*problemDescription*/)
{
// TODO: implement this method
return Verify_OtherError;
}
 
 
 
 
const int PDFOptionsIO::formatVersion = 1300;
 
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
doc("PDFSettings")
bool PDFOptions::saveTo(QTextStream& outStream) const
{
this->opts = &opts;
if (!outStream.device()->isWritable())
return false;
// TODO: implement this method
return false;
}
 
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
bool PDFOptionsIO::writeTo(QString outFileName)
// overload of bool PDFOptions::saveTo(QTextStream& outStream) const
bool PDFOptions::saveTo(QString outFileName) const
{
QTextStream ts(outFileName, IO_WriteOnly|IO_Truncate);
return writeTo(ts);
return saveTo(ts);
}
 
// overload of bool PDFOptions::writeTo(QTextStream& outStream)
bool PDFOptionsIO::writeTo(FILE* outFilePtr)
// overload of bool PDFOptions::saveTo(QTextStream& outStream) const
bool PDFOptions::saveTo(FILE* outFilePtr) const
{
QTextStream ts(outFilePtr, IO_WriteOnly|IO_Truncate);
return writeTo(ts);
return saveTo(ts);
}
 
bool PDFOptionsIO::writeTo(QTextStream& outStream)
bool readFrom(QTextStream& inStream)
{
if (!outStream.device()->isWritable())
return false;
// Verify to make sure our settings are sane
PDFOptions::VerifyResults vr = opts->verify();
if (vr != PDFOptions::Verify_NoError)
{
qDebug("PDFOptionsIO::writeTo(): "
"verify() failed [%i]", vr);
return false;
}
// Build the document. Initial implementation uses QDom.
root = doc.createElement("ScribusPDFOpts");
root.setAttribute("version", formatVersion);
doc.appendChild(root);
// Fill the guts of the document
if (!buildSettings())
{
qDebug("PDFOptionsIO::writeTo(): "
"couldn't build settings file");
return false;
}
// We're done - save it to the output stream
QString xml = doc.toString();
outStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
outStream << doc.toString();
return true;
}
 
// Build up the stored settings into the passed DOM objects
bool PDFOptionsIO::buildSettings()
{
addElem("thumbnails", opts->Thumbnails);
addElem("articles", opts->Articles);
addElem("useLayers", opts->useLayers);
addElem("compress", opts->Compress);
addElem("compressMethod", opts->CompressMethod);
addElem("quality", opts->Quality);
addElem("recalcPic", opts->RecalcPic);
addElem("bookmarks", opts->Bookmarks);
addElem("picRes", opts->PicRes);
QString pdfVersString;
switch (opts->Version)
{
case PDFOptions::PDFVersion_X3:
pdfVersString = "X3";
break;
default:
pdfVersString = QString::number(opts->Version);
break;
}
addElem("pdfVersion", pdfVersString);
addElem("resolution", opts->Resolution);
addElem("binding", opts->Binding);
// EmbedList
// SubsetList
addElem("mirrorH", opts->MirrorH);
addElem("mirrorV", opts->MirrorV);
addElem("rotateDegrees", opts->RotateDeg);
addElem("presentMode", opts->PresentMode);
// PresentVals
addElem("filename", opts->Datei);
addElem("isGrayscale", opts->isGrayscale);
addElem("useRGB", opts->UseRGB);
addElem("useProfiles", opts->UseProfiles);
addElem("useProfiles2", opts->UseProfiles2);
addElem("useLPI", opts->UseLPI);
// LPISettings
addElem("solidProf", opts->SolidProf);
addElem("sComp", opts->SComp);
addElem("imageProf", opts->ImageProf);
addElem("embeddedI", opts->EmbeddedI);
addElem("intent2", opts->Intent2);
addElem("printProf", opts->PrintProf);
addElem("info", opts->Info);
addElem("intent", opts->Intent);
addElem("bleedTop", opts->BleedTop);
addElem("bleedLeft", opts->BleedLeft);
addElem("bleedRight", opts->BleedRight);
addElem("bleedBottom", opts->BleedBottom);
addElem("encrypt", opts->Encrypt);
addElem("passOwner", opts->PassOwner);
addElem("passUser", opts->PassUser);
addElem("permissions", opts->Permissions);
return true;
}
 
// Convenience functions to add a single-attribute element
// of a particular type to the tree.
 
void PDFOptionsIO::addElem(QString name, bool value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
root.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QString name, QString value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
root.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QString name, int value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
root.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QString name, double value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
root.appendChild(elem);
}
 
 
bool PDFOptionsIO::readFrom(QTextStream& inStream)
{
if (!inStream.device()->isReadable())
return false;
// TODO: implement this method
166,7 → 38,7
}
 
// overload of bool readFrom(QTextStream& inStream)
bool PDFOptionsIO::readFrom(QString inFileName)
bool readFrom(QString inFileName)
{
QTextStream ts(inFileName, IO_ReadOnly);
return readFrom(ts);
173,7 → 45,7
}
 
// overload of bool readFrom(QTextStream& inStream)
bool PDFOptionsIO::readFrom(FILE* inFilePtr)
bool readFrom(FILE* inFilePtr)
{
QTextStream ts(inFilePtr, IO_ReadOnly);
return readFrom(ts);