Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 2035 → Rev 2036

/branches/Version13x/Scribus/scribus/pdfoptions.cpp
11,198 → 11,3
// TODO: implement this method
return Verify_NoError;
}
 
 
const int PDFOptionsIO::formatVersion = 1300;
 
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
doc("PDFSettings"),
error()
{
this->opts = &opts;
}
 
// writeTo(QString) is implemented separately to writeTo(QTextStream)
// because we don't want to clobber the output file until we know the
// data has been generated ok, and we can't avoid clobbering the file
// to create a QTextStream().
bool PDFOptionsIO::writeTo(QString outFileName)
{
QString xml = buildXMLString();
if (xml == QString::null)
return false;
QFile f(outFileName);
if (!f.open(IO_WriteOnly|IO_Truncate))
{
error = QObject::tr("Couldn't open output file");
return false;
}
QTextStream ts(&f);
ts.setEncoding(QTextStream::UnicodeUTF8);
ts << xml;
error = QString::null;
return true;
}
 
bool PDFOptionsIO::writeTo(QTextStream& outStream)
{
if (!outStream.device()->isWritable())
{
error = QObject::tr("Output stream not writeable");
return false;
}
QString xml = buildXMLString();
if (xml == QString::null)
return false;
outStream << xml;
error = QString::null;
return true;
}
 
// Construct and return an XML string representing the settings
QString PDFOptionsIO::buildXMLString()
{
// Verify to make sure our settings are sane
QString vrfyError;
PDFOptions::VerifyResults vr = opts->verify(&vrfyError);
if (vr != PDFOptions::Verify_NoError)
{
error = QObject::tr("Verification of settings failed: %1").arg(vrfyError);
return QString::null;
}
// Build the document. Initial implementation uses QDom.
root = doc.createElement("ScribusPDFOpts");
root.setAttribute("version", formatVersion);
doc.appendChild(root);
// Fill the guts of the document
buildSettings();
// We're done - return a string containing the document XML
QString xml = doc.toString();
xml.prepend("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
return xml;
}
 
// Build up the stored settings into the passed DOM objects
void 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);
addList("embedFonts", opts->EmbedList);
addList("subsetFonts", opts->SubsetList);
addElem("mirrorH", opts->MirrorH);
addElem("mirrorV", opts->MirrorV);
addElem("rotateDegrees", opts->RotateDeg);
addElem("presentMode", opts->PresentMode);
// FIXME: Save opts->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);
// FIXME: Save opts->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);
}
 
// 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);
}
 
// Save a QValueList<String> or QStringList as a list of
// <item value=""> elements
void PDFOptionsIO::addList(QString name, QValueList<QString>& value)
{
// List base element has no attributes, only children
QDomElement listbase = doc.createElement(name);
root.appendChild(listbase);
QValueList<QString>::iterator it;
for (it = value.begin(); it != value.end(); ++it)
{
// Each child is of the form <item value="">
QDomElement child = doc.createElement("item");
child.setAttribute("value",*(it));
listbase.appendChild(child);
}
}
 
bool PDFOptionsIO::readFrom(QTextStream& inStream)
{
if (!inStream.device()->isReadable())
return false;
// TODO: implement this method
return false;
}
 
// overload of bool readFrom(QTextStream& inStream)
bool PDFOptionsIO::readFrom(QString inFileName)
{
QTextStream ts(inFileName, IO_ReadOnly);
return readFrom(ts);
}
 
const QString& PDFOptionsIO::lastError() const
{
return error;
}
/branches/Version13x/Scribus/scribus/pdfoptionsio.h
0,0 → 1,115
#ifndef PDFOPTIONSIO_H
#define PDFOPTIONSIO_H
 
#include "pdfoptions.h"
#include "qdom.h"
 
/**
* @file pdfoptionsio.h
* @author Craig Ringer
*/
 
/**
* @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"))
* qDebug("Failed to save settings: %s", io.lastError.utf8());
*
* // Reading:
* PDFOptions opts;
* PDFOptionsIO io(opts);
* if (!io.readFrom("/path/to/file"))
* qDebug("Failed to load settings: %s", io.lastError.utf8());
*
* @sa PDFOptions
*/
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);
 
/**
* @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);
 
/**
* @brief Return human-readable explanation of last error.
* @warning Do not depend on particular values of this in your code.
*/
const QString& lastError() const;
 
protected:
// Build and return an XML representation of the settings.
// QString::null is returned on failure, in which case
// the error string is set.
QString PDFOptionsIO::buildXMLString();
 
// Populate the current DOM tree with the settings from the
// current PDFOptions instance.
void buildSettings();
 
// Helper functions. Add elements under the root element
// with a single attribute "value=" set to the passed value.
void addElem(QDomElement& addTo, QString name, bool value);
void addElem(QDomElement& addTo, QString name, QString value);
void addElem(QDomElement& addTo, QString name, int value);
void addElem(QDomElement& addTo, QString name, double value);
void addList(QDomElement& addTo, QString name, QValueList<QString>& value);
 
// Helper: add the PresentVals data to the document
void addPresentationData();
// Helper: Add the LPI settings to the document
void addLPISettings();
 
 
// 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;
 
// Error explanation if a function fails
// For user only, do not depend on particular values of this.
QString error;
};
 
#endif
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: branches/Version13x/Scribus/scribus/pdfoptions.h
===================================================================
--- branches/Version13x/Scribus/scribus/pdfoptions.h (revision 2035)
+++ branches/Version13x/Scribus/scribus/pdfoptions.h (revision 2036)
@@ -11,25 +11,19 @@
#include "qstring.h"
#include "qmap.h"
#include "qvaluelist.h"
-#include "qdom.h"
struct LPIData;
struct PDFPresentationData;
/**
- * @brief PDF Options struture. Capable of saving and loading to/from file and verifying its self.
+ * @brief PDF Options struture. Capable of verifying its self, but otherwise largely
+ * a dumb struct.
+ *
+ * @sa PDFOptionsIO
*/
class PDFOptions
{
public:
- // Note: A default constructor, copy constructor, and
- // assignment operator must be defined so that this class
- // can be used as a value.
- // The automatically generated ones are quite sufficient.
- //PDFOptions();
- //PDFOptions(const PDFOptions& other);
- //PDFOptions& operator=(const PDFOptions& other);
- //~PDFOptions() {};
enum VerifyResults
{
@@ -51,7 +45,7 @@
* @author Craig Ringer
* @brief Sanity check the options defined.
*
- * Unimplemented, always returns Verify_OtherError
+ * Unimplemented, always returns Verify_NoError
*
* Checks the PDF option structure for conflicts between mututally
* exclusive options, ensures all options are within sane ranges,
@@ -61,8 +55,8 @@
* it will contain a human-readable description of the error on return.
*
* @warning DO NOT *EVER* TEST THE VALUE OF problemDescription. Rely on the
- * return code instead. problemDescription is subject to
- * translation and its contents may change without notice.
+ * return code instead. problemDescription is subject to
+ * translation and its contents may change without notice.
*
* @param problemDescription Error description
* @return Verify_NoError for sane options, otherwise error code.
@@ -114,99 +108,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"))
- * qDebug("Failed to save settings: %s", io.lastError.utf8());
- *
- * // Reading:
- * PDFOptions opts;
- * PDFOptionsIO io(opts);
- * if (!io.readFrom("/path/to/file"))
- * qDebug("Failed to load settings: %s", io.lastError.utf8());
- */
-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);
-
- /**
- * @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);
-
- /**
- * @brief Return human-readable explanation of last error.
- * @warning Do not depend on particular values of this in your code.
- */
- const QString& lastError() const;
-
-protected:
- // Build and return an XML representation of the settings.
- // QString::null is returned on failure, in which case
- // the error string is set.
- QString PDFOptionsIO::buildXMLString();
-
- // Populate the current DOM tree with the settings from the
- // current PDFOptions instance.
- void 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);
- void addList(QString name, QValueList<QString>& 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;
-
- // Error explanation if a function fails
- // For user only, do not depend on particular values of this.
- QString error;
-};
-
#endif
/branches/Version13x/Scribus/scribus/pdfoptionsio.cpp
0,0 → 1,263
#include "pdfoptionsio.h"
#include "scribusstructs.h"
 
const int PDFOptionsIO::formatVersion = 1300;
 
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
doc("PDFSettings"),
error()
{
this->opts = &opts;
}
 
// writeTo(QString) is implemented separately to writeTo(QTextStream)
// because we don't want to clobber the output file until we know the
// data has been generated ok, and we can't avoid clobbering the file
// to create a QTextStream().
bool PDFOptionsIO::writeTo(QString outFileName)
{
QString xml = buildXMLString();
if (xml == QString::null)
return false;
QFile f(outFileName);
if (!f.open(IO_WriteOnly|IO_Truncate))
{
error = QObject::tr("Couldn't open output file");
return false;
}
QTextStream ts(&f);
ts.setEncoding(QTextStream::UnicodeUTF8);
ts << xml;
error = QString::null;
return true;
}
 
bool PDFOptionsIO::writeTo(QTextStream& outStream)
{
if (!outStream.device()->isWritable())
{
error = QObject::tr("Output stream not writeable");
return false;
}
QString xml = buildXMLString();
if (xml == QString::null)
return false;
outStream << xml;
error = QString::null;
return true;
}
 
// Construct and return an XML string representing the settings
QString PDFOptionsIO::buildXMLString()
{
// Verify to make sure our settings are sane
QString vrfyError;
PDFOptions::VerifyResults vr = opts->verify(&vrfyError);
if (vr != PDFOptions::Verify_NoError)
{
error = QObject::tr("Verification of settings failed: %1").arg(vrfyError);
return QString::null;
}
// Build the document. Initial implementation uses QDom.
root = doc.createElement("ScribusPDFOpts");
root.setAttribute("version", formatVersion);
doc.appendChild(root);
// Fill the guts of the document
buildSettings();
// We're done - return a string containing the document XML
QString xml = doc.toString();
xml.prepend("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
return xml;
}
 
// Build up the stored settings into the passed DOM objects
void PDFOptionsIO::buildSettings()
{
addElem(root, "thumbnails", opts->Thumbnails);
addElem(root, "articles", opts->Articles);
addElem(root, "useLayers", opts->useLayers);
addElem(root, "compress", opts->Compress);
addElem(root, "compressMethod", opts->CompressMethod);
addElem(root, "quality", opts->Quality);
addElem(root, "recalcPic", opts->RecalcPic);
addElem(root, "bookmarks", opts->Bookmarks);
addElem(root, "picRes", opts->PicRes);
QString pdfVersString;
switch (opts->Version)
{
case PDFOptions::PDFVersion_X3:
pdfVersString = "X3";
break;
default:
pdfVersString = QString::number(opts->Version);
break;
}
addElem(root, "pdfVersion", pdfVersString);
addElem(root, "resolution", opts->Resolution);
addElem(root, "binding", opts->Binding);
addList(root, "embedFonts", opts->EmbedList);
addList(root, "subsetFonts", opts->SubsetList);
addElem(root, "mirrorH", opts->MirrorH);
addElem(root, "mirrorV", opts->MirrorV);
addElem(root, "rotateDegrees", opts->RotateDeg);
addElem(root, "presentMode", opts->PresentMode);
addPresentationData();
addElem(root, "filename", opts->Datei);
addElem(root, "isGrayscale", opts->isGrayscale);
addElem(root, "useRGB", opts->UseRGB);
addElem(root, "useProfiles", opts->UseProfiles);
addElem(root, "useProfiles2", opts->UseProfiles2);
addElem(root, "useLPI", opts->UseLPI);
addLPISettings();
addElem(root, "solidProf", opts->SolidProf);
addElem(root, "sComp", opts->SComp);
addElem(root, "imageProf", opts->ImageProf);
addElem(root, "embeddedI", opts->EmbeddedI);
addElem(root, "intent2", opts->Intent2);
addElem(root, "printProf", opts->PrintProf);
addElem(root, "info", opts->Info);
addElem(root, "intent", opts->Intent);
addElem(root, "bleedTop", opts->BleedTop);
addElem(root, "bleedLeft", opts->BleedLeft);
addElem(root, "bleedRight", opts->BleedRight);
addElem(root, "bleedBottom", opts->BleedBottom);
addElem(root, "encrypt", opts->Encrypt);
addElem(root, "passOwner", opts->PassOwner);
addElem(root, "passUser", opts->PassUser);
addElem(root, "permissions", opts->Permissions);
}
 
// Convenience functions to add a single-attribute element
// of a particular type to the tree at a given point.
 
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, bool value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
addTo.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, QString value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
addTo.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, int value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
addTo.appendChild(elem);
}
 
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, double value)
{
QDomElement elem = doc.createElement(name);
elem.setAttribute("value",value);
addTo.appendChild(elem);
}
 
// Save a QValueList<String> or QStringList as a list of
// <item value=""> elements
void PDFOptionsIO::addList(QDomElement& addTo, QString name, QValueList<QString>& value)
{
// List base element has no attributes, only children
QDomElement listbase = doc.createElement(name);
addTo.appendChild(listbase);
QValueList<QString>::iterator it;
for (it = value.begin(); it != value.end(); ++it)
addElem(listbase, "item", *(it));
}
 
// save PDFOptions::PresentVals
void PDFOptionsIO::addPresentationData()
{
// PDFOptions::PresentVals is a QValueList<PDFPresentationData>
//
// XML structure will be like this:
// <presentationSettings>
// <presentationSettingsEntry>
// <pageEffectDuration value="0"/>
// <pageViewDuration value="0"/>
// <effectType value="0"/>
// <dm value="0"/>
// <m value="0"/>
// <di value="0"/>
// </presentationSettingsEntry>
// <presentationSettingsEntry>
// ...
// </presentationSettingsEntry>
// ...
// </presentationSettings>
QDomElement presentationSettings = doc.createElement("presentationSettings");
root.appendChild(presentationSettings);
QValueList<PDFPresentationData>::iterator it;
for (it = opts->PresentVals.begin(); it != opts->PresentVals.end(); ++it)
{
// Settings entry has no attributes, only children
QDomElement psEntry = doc.createElement("presentationSettingsEntry");
presentationSettings.appendChild(psEntry);
// Children:
addElem(psEntry, "pageEffectDuration", (*it).pageEffectDuration);
addElem(psEntry, "pageViewDuration", (*it).pageViewDuration);
addElem(psEntry, "effectType", (*it).effectType);
addElem(psEntry, "dm", (*it).Dm);
addElem(psEntry, "m", (*it).M);
addElem(psEntry, "di", (*it).Di);
}
}
 
// Save PDFOptions::LPISettings
void PDFOptionsIO::addLPISettings()
{
// PDFOptions::LPISettings is a QMap<QString,LPIData>
//
// XML structure will be like this:
// <lpiSettings>
// <lpiSettingsEntry name="blah">
// <frequency value="0">
// <angle value="0">
// <spotFunc value="0">
// </lpiSettingsEntry>
// <lpiSettingsEntry name="blah2">
// ...
// </lpiSettingsEntry>
// ...
// </lpiSettings>
QDomElement lpiSettings = doc.createElement("lpiSettings");
root.appendChild(lpiSettings);
QMap<QString,LPIData>::iterator it;
for (it = opts->LPISettings.begin(); it != opts->LPISettings.end(); ++it)
{
// Settings entry has no attributes, only children
QDomElement lpiEntry = doc.createElement("lpiSettingsEntry");
lpiEntry.setAttribute("name", it.key());
lpiSettings.appendChild(lpiEntry);
// Children:
addElem(lpiEntry, "frequency", (*it).Frequency);
addElem(lpiEntry, "angle", (*it).Angle);
addElem(lpiEntry, "spotFunc", (*it).SpotFunc);
}
 
}
 
bool PDFOptionsIO::readFrom(QTextStream& inStream)
{
if (!inStream.device()->isReadable())
return false;
// TODO: implement this method
return false;
}
 
// overload of bool readFrom(QTextStream& inStream)
bool PDFOptionsIO::readFrom(QString inFileName)
{
QTextStream ts(inFileName, IO_ReadOnly);
return readFrom(ts);
}
 
const QString& PDFOptionsIO::lastError() const
{
return error;
}
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property