diff options
author | Albert Astals Cid <aacid@kde.org> | 2007-09-08 10:40:17 +0000 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2007-09-08 10:40:17 +0000 |
commit | 31bbc8c727cfecc79bd8da962ad8d99a0d1d3d33 (patch) | |
tree | ae27bda36332635b3c2dd1410a5d13d042e74005 | |
parent | b3d63d03c310f01cc5b23d00ffd2103c6891fef2 (diff) |
* qt4/src/poppler-qt4.h:
* qt4/src/poppler-ps-converter.cc:
Add PSConverter::setOutputDevice() to set a QIODevice where
writing the resulting PS.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | qt4/src/poppler-ps-converter.cc | 51 | ||||
-rw-r--r-- | qt4/src/poppler-qt4.h | 5 |
3 files changed, 58 insertions, 5 deletions
@@ -1,3 +1,10 @@ +2007-09-07 Pino Toscano <pino@kde.org> + + * qt4/src/poppler-qt4.h: + * qt4/src/poppler-ps-converter.cc: + Add PSConverter::setOutputDevice() to set a QIODevice where + writing the resulting PS. + 2007-09-05 Albert Astals Cid <aacid@kde.org> * poppler/PSOutputDev.cc: Fix printing of second parameter diff --git a/qt4/src/poppler-ps-converter.cc b/qt4/src/poppler-ps-converter.cc index 02d8fa87..fb082b5e 100644 --- a/qt4/src/poppler-ps-converter.cc +++ b/qt4/src/poppler-ps-converter.cc @@ -21,6 +21,13 @@ #include "PSOutputDev.h" +#include <QtCore/QFile> + +static void outputToQIODevice(void *stream, char *data, int len) +{ + static_cast<QIODevice*>(stream)->write(data, len); +} + namespace Poppler { class PSConverterData @@ -28,6 +35,8 @@ class PSConverterData public: DocumentData *document; QString outputFileName; + QIODevice *iodev; + bool ownIodev; QList<int> pageList; QString title; double hDPI; @@ -47,6 +56,8 @@ PSConverter::PSConverter(DocumentData *document) { m_data = new PSConverterData(); m_data->document = document; + m_data->iodev = 0; + m_data->ownIodev = true; m_data->hDPI = 72; m_data->vDPI = 72; m_data->rotate = 0; @@ -70,6 +81,12 @@ void PSConverter::setOutputFileName(const QString &outputFileName) m_data->outputFileName = outputFileName; } +void PSConverter::setOutputDevice(QIODevice *device) +{ + m_data->iodev = device; + m_data->ownIodev = false; +} + void PSConverter::setPageList(const QList<int> &pageList) { m_data->pageList = pageList; @@ -137,7 +154,22 @@ void PSConverter::setForceRasterize(bool forceRasterize) bool PSConverter::convert() { - Q_ASSERT(!m_data->outputFileName.isEmpty()); + if (!m_data->iodev) + { + Q_ASSERT(!m_data->outputFileName.isEmpty()); + QFile *f = new QFile(m_data->outputFileName); + m_data->iodev = f; + m_data->ownIodev = true; + } + Q_ASSERT(m_data->iodev); + if (!m_data->iodev->isOpen()) + { + if (!m_data->iodev->open(QIODevice::ReadWrite)) + { + return false; + } + } + Q_ASSERT(!m_data->pageList.isEmpty()); Q_ASSERT(m_data->paperWidth != -1); Q_ASSERT(m_data->paperHeight != -1); @@ -147,10 +179,10 @@ bool PSConverter::convert() if (!m_data->title.isEmpty()) pstitlechar = pstitle8Bit.data(); else pstitlechar = 0; - PSOutputDev *psOut = new PSOutputDev(m_data->outputFileName.toLatin1().data(), + PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, m_data->iodev, + pstitlechar, m_data->document->doc->getXRef(), m_data->document->doc->getCatalog(), - pstitlechar, 1, m_data->document->doc->getNumPages(), psModePS, @@ -176,13 +208,24 @@ bool PSConverter::convert() { m_data->document->doc->displayPage(psOut, page, m_data->hDPI, m_data->vDPI, m_data->rotate, gFalse, gTrue, gFalse); } - delete psOut; + if (m_data->ownIodev) + { + m_data->iodev->close(); + delete m_data->iodev; + m_data->iodev = 0; + } return true; } else { delete psOut; + if (m_data->ownIodev) + { + m_data->iodev->close(); + delete m_data->iodev; + m_data->iodev = 0; + } return false; } } diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index 6ed2d1ce..3b61c2c2 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -847,9 +847,12 @@ height = dummy.height(); */ ~PSConverter(); - /** Sets the output file name. Mandatory. */ + /** Sets the output file name. You must set this or the output device. */ void setOutputFileName(const QString &outputFileName); + /** Sets the output device. You must set this or the output file name. */ + void setOutputDevice(QIODevice *device); + /** Sets the list of pages to print. Mandatory. */ void setPageList(const QList<int> &pageList); |