r17880 by fschmid - Fixed Bug #1094: Importing multipage PDFs must give options for importing a selection of pages

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 18 09:40:26 UTC 2012


Author: fschmid
Date: Sun Nov 18 09:40:26 2012
New Revision: 17880

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17880
Log:
Fixed Bug #1094: Importing multipage PDFs must give options for importing a selection of pages

Added:
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui
Modified:
    trunk/Scribus/scribus/plugins/import/pdf/CMakeLists.txt
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.h
    trunk/Scribus/scribus/ui/pageselector.h

Modified: trunk/Scribus/scribus/plugins/import/pdf/CMakeLists.txt
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17880&path=/trunk/Scribus/scribus/plugins/import/pdf/CMakeLists.txt
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/CMakeLists.txt (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/CMakeLists.txt Sun Nov 18 09:40:26 2012
@@ -4,14 +4,21 @@
 ${POPPLER_INCLUDE_DIR}
 )
 
+
+SET(IMPORTPDF_PLUGIN_UI_SRC
+pdfimportoptions.ui
+)
+
 SET(IMPORTPDF_PLUGIN_MOC_CLASSES
   importpdf.h
   importpdfplugin.h
+  pdfimportoptions.h
 )
 
 SET(IMPORTPDF_PLUGIN_SOURCES
   importpdf.cpp
   importpdfplugin.cpp
+  pdfimportoptions.cpp
   slaoutput.cpp
 )
 
@@ -24,9 +31,10 @@
 
 SET(SCRIBUS_IMPORTPDF_PLUGIN "importpdf")
 
+QT4_WRAP_UI(IMPORTPDF_PLUGIN_UI_SOURCES ${IMPORTPDF_PLUGIN_UI_SRC} )
 QT4_WRAP_CPP(IMPORTPDF_PLUGIN_MOC_SOURCES ${IMPORTPDF_PLUGIN_MOC_CLASSES})
 
-ADD_LIBRARY(${SCRIBUS_IMPORTPDF_PLUGIN} MODULE ${IMPORTPDF_PLUGIN_SOURCES} ${IMPORTPDF_PLUGIN_MOC_SOURCES})
+ADD_LIBRARY(${SCRIBUS_IMPORTPDF_PLUGIN} MODULE ${IMPORTPDF_PLUGIN_SOURCES} ${IMPORTPDF_PLUGIN_MOC_SOURCES} ${IMPORTPDF_PLUGIN_UI_SOURCES})
 
 LINK_DIRECTORIES( /usr/local/lib )
 TARGET_LINK_LIBRARIES(${SCRIBUS_IMPORTPDF_PLUGIN} ${PLUGIN_LIBRARIES} ${POPPLER_LIBRARY})

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17880&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp Sun Nov 18 09:40:26 2012
@@ -31,6 +31,7 @@
 #include "commonstrings.h"
 #include "loadsaveplugin.h"
 #include "pagesize.h"
+#include "pdfimportoptions.h"
 #include "pdfoptions.h"
 #include "prefscontext.h"
 #include "prefsfile.h"
@@ -66,6 +67,7 @@
 	importerFlags = flags;
 	interactive = (flags & LoadSavePlugin::lfInteractive);
 	progressDialog = NULL;
+	m_pdfDoc = NULL;
 }
 
 QImage PdfPlug::readThumbnail(QString fName)
@@ -415,10 +417,37 @@
 			}
 			if (pdfDoc->isOk())
 			{
+				std::vector<int> pageNs;
+				QString pageString = "*";
+				m_pdfDoc = pdfDoc;
 				double hDPI = 72.0;
 				double vDPI = 72.0;
 				int firstPage = 1;
 				int lastPage = pdfDoc->getNumPages();
+				if ((interactive) || (importerFlags & LoadSavePlugin::lfCreateDoc))
+				{
+					if (progressDialog)
+						progressDialog->hide();
+					qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+					PdfImportOptions *optImp = new PdfImportOptions(ScCore->primaryMainWindow());
+					optImp->setUpOptions(firstPage, lastPage, interactive, this);
+					if (!optImp->exec())
+					{
+						if (progressDialog)
+							progressDialog->close();
+						delete optImp;
+						delete pdfDoc;
+						delete globalParams;
+						return false;
+					}
+					pageString = optImp->getPagesString();
+					delete optImp;
+					qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+					if (progressDialog)
+						progressDialog->show();
+				}
+				parsePagesString(pageString, &pageNs, lastPage);
+				firstPage = pageNs[0];
 				SlaOutputDev *dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags);
 				if (dev->isOk())
 				{
@@ -568,8 +597,8 @@
 							}
 						}
 						info.free();
-						m_Doc->setPageHeight(pdfDoc->getPageMediaHeight(1));
-						m_Doc->setPageWidth(pdfDoc->getPageMediaWidth(1));
+						m_Doc->setPageHeight(pdfDoc->getPageMediaHeight(pageNs[0]));
+						m_Doc->setPageWidth(pdfDoc->getPageMediaWidth(pageNs[0]));
 						m_Doc->setPageSize("Custom");
 					/*	PDFRectangle *mediaBox = pdfDoc->getPage(1)->getMediaBox();
 						PDFRectangle *cropBox = pdfDoc->getPage(1)->getCropBox();
@@ -587,17 +616,18 @@
 						qDebug() << "Bleed Box" << bleedRect << "Area" << bleedRect.width() * bleedRect.height();
 						qDebug() << "Art Box" << artRect << "Area" << artRect.width() * artRect.height(); */
 						m_Doc->pdfOptions().PresentVals.clear();
-						for (int pp = 0; pp < lastPage; pp++)
+						for (uint ap = 0; ap < pageNs.size(); ++ap)
 						{
+							int pp = pageNs[ap];
 							m_Doc->setActiveLayer(baseLayer);
 							if (firstPg)
 								firstPg = false;
 							else
-								m_Doc->addPage(pp);
-							m_Doc->currentPage()->setInitialHeight(pdfDoc->getPageMediaHeight(pp + 1));
-							m_Doc->currentPage()->setInitialWidth(pdfDoc->getPageMediaWidth(pp + 1));
-							m_Doc->currentPage()->setHeight(pdfDoc->getPageMediaHeight(pp + 1));
-							m_Doc->currentPage()->setWidth(pdfDoc->getPageMediaWidth(pp + 1));
+								m_Doc->addPage(ap);
+							m_Doc->currentPage()->setInitialHeight(pdfDoc->getPageMediaHeight(pp));
+							m_Doc->currentPage()->setInitialWidth(pdfDoc->getPageMediaWidth(pp));
+							m_Doc->currentPage()->setHeight(pdfDoc->getPageMediaHeight(pp));
+							m_Doc->currentPage()->setWidth(pdfDoc->getPageMediaWidth(pp));
 							m_Doc->currentPage()->MPageNam = CommonStrings::trMasterPageNormal;
 							m_Doc->currentPage()->m_pageSize = "Custom";
 							m_Doc->reformPages(true);
@@ -612,13 +642,13 @@
 								//	pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing);
 								//	oc->setState(OptionalContentGroup::Off);
 								}
-								pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing, NULL, NULL, dev->annotations_callback, dev);
+								pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, NULL, NULL, dev->annotations_callback, dev);
 							}
 							else
-								pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing, NULL, NULL, dev->annotations_callback, dev);
+								pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, NULL, NULL, dev->annotations_callback, dev);
 							PDFPresentationData ef;
 							Object trans;
-							Object *transi = pdfDoc->getPage(pp + 1)->getTrans(&trans);
+							Object *transi = pdfDoc->getPage(pp)->getTrans(&trans);
 							if (transi->isDict())
 							{
 								m_Doc->pdfOptions().PresentMode = true;
@@ -778,6 +808,51 @@
 	return true;
 }
 
+QImage PdfPlug::readPreview(int pgNum, int width, int height)
+{
+	if (!m_pdfDoc)
+		return QImage();
+	double h = m_pdfDoc->getPageMediaHeight(pgNum);
+	double w = m_pdfDoc->getPageMediaWidth(pgNum);
+	double scale = qMin(height / h, width / w);
+	double hDPI = 72.0 * scale;
+	double vDPI = 72.0 * scale;
+	SplashColor bgColor;
+	bgColor[0] = 255;
+	bgColor[1] = 255;
+	bgColor[2] = 255;
+	SplashOutputDev *dev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, bgColor, gTrue, gTrue);
+	dev->setVectorAntialias(gTrue);
+	dev->setFreeTypeHinting(gTrue, gFalse);
+	dev->startDoc(m_pdfDoc);
+	m_pdfDoc->displayPage(dev, pgNum, hDPI, vDPI, 0, gTrue, gFalse, gFalse);
+	SplashBitmap *bitmap = dev->getBitmap();
+	int bw = bitmap->getWidth();
+	int bh = bitmap->getHeight();
+	SplashColorPtr dataPtr = bitmap->getDataPtr();
+	if (QSysInfo::BigEndian == QSysInfo::ByteOrder)
+	{
+		uchar c;
+		int count = bw * bh * 4;
+		for (int k = 0; k < count; k += 4)
+		{
+			c = dataPtr[k];
+			dataPtr[k] = dataPtr[k+3];
+			dataPtr[k+3] = c;
+			c = dataPtr[k+1];
+			dataPtr[k+1] = dataPtr[k+2];
+			dataPtr[k+2] = c;
+		}
+	}
+	// construct a qimage SHARING the raw bitmap data in memory
+	QImage tmpimg( dataPtr, bw, bh, QImage::Format_ARGB32 );
+	QImage image = tmpimg.copy();
+	image.setText("XSize", QString("%1").arg(w));
+	image.setText("YSize", QString("%1").arg(h));
+	delete dev;
+	return image;
+}
+
 QString PdfPlug::UnicodeParsedString(GooString *s1)
 {
 	if ( !s1 || s1->getLength() == 0 )

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17880&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.h (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.h Sun Nov 18 09:40:26 2012
@@ -36,7 +36,7 @@
 class TransactionSettings;
 
 class GooString;
-
+class PDFDoc;
 
 //! \brief PDF importer plugin
 class PdfPlug : public QObject
@@ -68,6 +68,7 @@
 	 */
 	bool import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
 	QImage readThumbnail(QString fn);
+	QImage readPreview(int pgNum, int width, int height);
 
 private:
 	bool convert(QString fn);
@@ -89,6 +90,7 @@
 	int importerFlags;
 	int oldDocItemCount;
 	QString baseFile;
+	PDFDoc *m_pdfDoc;
 
 public slots:
 	void cancelRequested() { cancel = true; }

Modified: trunk/Scribus/scribus/ui/pageselector.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17880&path=/trunk/Scribus/scribus/ui/pageselector.h
==============================================================================
--- trunk/Scribus/scribus/ui/pageselector.h (original)
+++ trunk/Scribus/scribus/ui/pageselector.h Sun Nov 18 09:40:26 2012
@@ -27,7 +27,7 @@
 	Q_OBJECT
 
 public:
-	PageSelector( QWidget* parent, int maxPg );
+	PageSelector( QWidget* parent, int maxPg = 0 );
 	~PageSelector() {};
 	
 	virtual void changeEvent(QEvent *e);




More information about the scribus-commit mailing list