Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv18589/qt4/src

Modified Files:
        Makefile.am poppler-document.cc poppler-qt4.h 
Added Files:
        poppler-ps-converter.cc 
Log Message:
        * qt4/src/Makefile.am:
        * qt4/src/poppler-document.cc:
        * qt4/src/poppler-ps-converter.cc:
        * qt4/src/poppler-qt4.h: Replace Document::print function with lots of
        arguments with a helper class with lots of functions. Will help
        mantaining BC in case we decide to add more functionality to the
        printing process.


Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/Makefile.am,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Makefile.am 28 Apr 2007 11:16:49 -0000      1.19
+++ Makefile.am 28 Apr 2007 12:00:38 -0000      1.20
@@ -28,6 +28,7 @@
        ../../qt/poppler-page-transition.cc     \
        poppler-sound.cc                        \
        poppler-form.cc                         \
+       poppler-ps-converter.cc                 \
        poppler-annotation-helper.h             \
        poppler-private.h
 

Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- poppler-document.cc 27 Apr 2007 22:41:10 -0000      1.36
+++ poppler-document.cc 28 Apr 2007 12:00:38 -0000      1.37
@@ -24,7 +24,6 @@
 #include <GlobalParams.h>
 #include <Outline.h>
 #include <PDFDoc.h>
-#include <PSOutputDev.h>
 #include <Stream.h>
 #include <Catalog.h>
 
@@ -412,39 +411,6 @@
         return ld;
     }
     
-    bool Document::print(const QString &file, const QString &title, const 
QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int 
paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, 
bool strictMargins, bool forceRasterize)
-    {
-        QByteArray pstitle8Bit = title.toLocal8Bit();
-        char* pstitlechar;
-        if (!title.isEmpty()) pstitlechar = pstitle8Bit.data();
-        else pstitlechar = 0;
-
-        PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), 
m_doc->doc->getXRef(), m_doc->doc->getCatalog(), pstitlechar, 1, 
m_doc->doc->getNumPages(), psModePS, paperWidth, paperHeight, gFalse, 
marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop, 
forceRasterize);
-
-        if (strictMargins)
-        {
-            double xScale = ((double)paperWidth - (double)marginLeft - 
(double)marginRight) / (double)paperWidth;
-            double yScale = ((double)paperHeight - (double)marginBottom - 
(double)marginTop) / (double)paperHeight;
-            psOut->setScale(xScale, yScale);
-        }
-
-        if (psOut->isOk())
-        {
-            foreach(int page, pageList)
-            {
-                m_doc->doc->displayPage(psOut, page, hDPI, vDPI, rotate, 
gFalse, gTrue, gFalse);
-            }
-
-            delete psOut;
-            return true;
-        }
-        else
-        {
-            delete psOut;
-            return false;
-        }
-    }
-    
     void Document::setPaperColor(const QColor &color)
     {
         m_doc->setPaperColor(color);
@@ -499,6 +465,11 @@
         return Document::RenderHints() & m_doc->m_hints;
     }
 
+    PSConverter *Document::psConverter() const
+    {
+        return new PSConverter(m_doc);
+    }
+
     QDateTime convertDate( char *dateString )
     {
         int year;

--- NEW FILE: poppler-ps-converter.cc ---
/* poppler-document.cc: qt interface to poppler
 * Copyright (C) 2007, Albert Astals Cid <[EMAIL PROTECTED]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "poppler-qt4.h"
#include "poppler-private.h"

#include "PSOutputDev.h"

namespace Poppler {

class PSConverterData
{
        public:
                DocumentData *document;
                QString outputFileName;
                QList<int> pageList;
                QString title;
                double hDPI;
                double vDPI;
                int rotate;
                int paperWidth;
                int paperHeight;
                int marginRight;
                int marginBottom;
                int marginLeft;
                int marginTop;
                bool strictMargins;
                bool forceRasterize;
};

PSConverter::PSConverter(DocumentData *document)
{
        m_data = new PSConverterData();
        m_data->document = document;
        m_data->hDPI = 72;
        m_data->vDPI = 72;
        m_data->rotate = 0;
        m_data->paperWidth = -1;
        m_data->paperHeight = -1;
        m_data->marginRight = 0;
        m_data->marginBottom = 0;
        m_data->marginLeft = 0;
        m_data->marginTop = 0;
        m_data->strictMargins = false;
        m_data->forceRasterize = false;
}

PSConverter::~PSConverter()
{
        delete m_data;
}

void PSConverter::setOutputFileName(const QString &outputFileName)
{
        m_data->outputFileName = outputFileName;
}

void PSConverter::setPageList(const QList<int> &pageList)
{
        m_data->pageList = pageList;
}

void PSConverter::setTitle(const QString &title)
{
        m_data->title = title;
}

void PSConverter::setHDPI(double hDPI)
{
        m_data->hDPI = hDPI;
}

void PSConverter::setVDPI(double vDPI)
{
        m_data->vDPI = vDPI;
}

void PSConverter::setRotate(int rotate)
{
        m_data->rotate = rotate;
}

void PSConverter::setPaperWidth(int paperWidth)
{
        m_data->paperWidth = paperWidth;
}

void PSConverter::setPaperHeight(int paperHeight)
{
        m_data->paperHeight = paperHeight;
}

void PSConverter::setRightMargin(int marginRight)
{
        m_data->marginRight = marginRight;
}

void PSConverter::setBottomMargin(int marginBottom)
{
        m_data->marginBottom = marginBottom;
}

void PSConverter::setLeftMargin(int marginLeft)
{
        m_data->marginLeft = marginLeft;
}

void PSConverter::setTopMargin(int marginTop)
{
        m_data->marginTop = marginTop;
}

void PSConverter::setStrictMargins(bool strictMargins)
{
        m_data->strictMargins = strictMargins;
}

void PSConverter::setForceRasterize(bool forceRasterize)
{
        m_data->forceRasterize = forceRasterize;
}

bool PSConverter::convert()
{
        Q_ASSERT(!m_data->outputFileName.isEmpty());
        Q_ASSERT(!m_data->pageList.isEmpty());
        Q_ASSERT(m_data->paperWidth != -1);
        Q_ASSERT(m_data->paperHeight != -1);
        
        QByteArray pstitle8Bit = m_data->title.toLocal8Bit();
        char* pstitlechar;
        if (!m_data->title.isEmpty()) pstitlechar = pstitle8Bit.data();
        else pstitlechar = 0;
        
        PSOutputDev *psOut = new 
PSOutputDev(m_data->outputFileName.toLatin1().data(),
                                             m_data->document->doc->getXRef(),
                                             
m_data->document->doc->getCatalog(),
                                             pstitlechar,
                                             1,
                                             
m_data->document->doc->getNumPages(),
                                             psModePS,
                                             m_data->paperWidth,
                                             m_data->paperHeight,
                                             gFalse,
                                             m_data->marginRight,
                                             m_data->marginBottom,
                                             m_data->paperWidth - 
m_data->marginLeft,
                                             m_data->paperHeight - 
m_data->marginTop,
                                             m_data->forceRasterize);
        
        if (m_data->strictMargins)
        {
                double xScale = ((double)m_data->paperWidth - 
(double)m_data->marginLeft - (double)m_data->marginRight) / 
(double)m_data->paperWidth;
                double yScale = ((double)m_data->paperHeight - 
(double)m_data->marginBottom - (double)m_data->marginTop) / 
(double)m_data->paperHeight;
                psOut->setScale(xScale, yScale);
        }
        
        if (psOut->isOk())
        {
                foreach(int page, m_data->pageList)
                {
                        m_data->document->doc->displayPage(psOut, page, 
m_data->hDPI, m_data->vDPI, m_data->rotate, gFalse, gTrue, gFalse);
                }
                
                delete psOut;
                return true;
        }
        else
        {
                delete psOut;
                return false;
        }
}

}

Index: poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- poppler-qt4.h       28 Apr 2007 11:34:14 -0000      1.51
+++ poppler-qt4.h       28 Apr 2007 12:00:38 -0000      1.52
@@ -47,6 +47,8 @@
 
     class TextBoxData;
 
+    class PSConverter;
+
     /**
         Describes the physical location of text on a document page
        
@@ -714,24 +716,6 @@
        LinkDestination *linkDestination( const QString &name );
        
        /**
-         Prints the document to the PostScript file \p fileName
-         Sizes have to be in Points (1/72 inch)
-         \param strictMargins defines if margins have to be scrictly
-                              followed (even if that means changing aspect 
ratio) or
-                              if the margins can be adapted to keep aspect 
ratio
-
-         If you are using QPrinter you can get paper size by doing:
-         \code
-QPrinter dummy(QPrinter::PrinterResolution);
-dummy.setFullPage(true);
-dummy.setPageSize(myPageSize);
-width = dummy.width();
-height = dummy.height();
-         \endcode
-       */
-       bool print(const QString &fileName, const QString &title, const 
QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int 
paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, 
bool strictMargins, bool forceRasterize);
-       
-       /**
          Sets the paper color
 
          \param color the new paper color
@@ -772,6 +756,11 @@
          The currently set render hints.
         */
        RenderHints renderHints() const;
+       
+       /**
+         Gets a PS converter of this document. The pointer has to be freed by 
the calling application.
+        */
+       PSConverter *psConverter() const;
 
        ~Document();
   
@@ -781,6 +770,100 @@
        Document(DocumentData *dataA);
        static Document *checkDocument(DocumentData *doc);
     };
+    
+    /**
+       Converts a PDF to PS
+
+       Sizes have to be in Points (1/72 inch)
+
+       If you are using QPrinter you can get paper size by doing:
+       \code
+           QPrinter dummy(QPrinter::PrinterResolution);
+           dummy.setFullPage(true);
+           dummy.setPageSize(myPageSize);
+           width = dummy.width();
+           height = dummy.height();
+       \endcode
+    */
+    class PSConverterData;
+    class PSConverter
+    {
+        friend class Document;
+        public:
+            ~PSConverter();
+
+            /** Sets the output file name. Mandatory. */
+            void setOutputFileName(const QString &outputFileName);
+
+            /** Sets the list of pages to print. Mandatory. */
+            void setPageList(const QList<int> &pageList);
+
+            /**
+              Sets the title of the PS Document. Optional
+            */
+            void setTitle(const QString &title);
+
+            /**
+              Sets the horizontal DPI. Defaults to 72.0
+            */
+            void setHDPI(double hDPI);
+
+            /**
+              Sets the vertical DPI. Defaults to 72.0
+            */
+            void setVDPI(double vDPI);
+
+            /**
+              Sets the rotate. Defaults to not rotated
+            */
+            void setRotate(int rotate);
+
+            /**
+              Sets the output paper width. Has to be set.
+            */
+            void setPaperWidth(int paperWidth);
+
+            /**
+              Sets the output paper height. Has to be set.
+            */
+            void setPaperHeight(int paperHeight);
+
+            /**
+              Sets the output right margin. Defaults to 0
+            */
+            void setRightMargin(int marginRight);
+
+            /**
+              Sets the output bottom margin. Defaults to 0
+            */
+            void setBottomMargin(int marginBottom);
+
+            /**
+              Sets the output left margin. Defaults to 0
+            */
+            void setLeftMargin(int marginLeft);
+
+            /**
+              Sets the output top margin. Defaults to 0
+            */
+            void setTopMargin(int marginTop);
+
+            /** Defines if margins have to be scrictly
+                followed (even if that means changing aspect ratio) or
+                if the margins can be adapted to keep aspect ratio. Defaults 
to false. */
+            void setStrictMargins(bool strictMargins);
+
+            /** Defines if the page will be rasterized to an image before 
printing. Defaults to false */
+            void setForceRasterize(bool forceRasterize);
+
+            /** Does the conversion */
+            bool convert();
+
+        private:
+            PSConverter(DocumentData *document);
+
+            PSConverterData *m_data;
+    };
 
     /**
        Conversion from PDF date string format to QDateTime

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to