r17869 by fschmid - PDF-Importer: do the thumbnail rendering with poppler now.

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 10 19:34:20 UTC 2012


Author: fschmid
Date: Sat Nov 10 19:34:20 2012
New Revision: 17869

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17869
Log:
PDF-Importer: do the thumbnail rendering with poppler now.

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
    trunk/Scribus/scribus/scribuscore.cpp
    trunk/Scribus/scribus/scribuscore.h
    trunk/Scribus/scribus/ui/customfdialog.cpp
    trunk/Scribus/scribus/ui/splash.cpp
    trunk/Scribus/scribus/ui/splash.h

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&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 Sat Nov 10 19:34:20 2012
@@ -16,11 +16,13 @@
 #include <QStack>
 #include <QDebug>
 #include "slaoutput.h"
-#include <ErrorCodes.h>
-#include <GlobalParams.h>
-#include <PageTransition.h>
-#include <ViewerPreferences.h>
-#include <poppler-config.h>
+#include <poppler/ErrorCodes.h>
+#include <poppler/GlobalParams.h>
+#include <poppler/PageTransition.h>
+#include <poppler/ViewerPreferences.h>
+#include <poppler/poppler-config.h>
+#include <poppler/SplashOutputDev.h>
+#include <poppler/splash/SplashBitmap.h>
 
 #include "importpdf.h"
 
@@ -68,6 +70,88 @@
 
 QImage PdfPlug::readThumbnail(QString fName)
 {
+	QString pdfFile = QDir::toNativeSeparators(fName);
+	globalParams = new GlobalParams();
+	if (globalParams)
+	{
+		GooString *fname = new GooString(QFile::encodeName(pdfFile).data());
+		globalParams->setErrQuiet(gTrue);
+		PDFDoc *pdfDoc = new PDFDoc(fname, NULL, NULL, NULL);
+		if (pdfDoc)
+		{
+			if (pdfDoc->getErrorCode() == errEncrypted)
+			{
+				delete pdfDoc;
+				delete globalParams;
+				return QImage();
+			}
+			if (pdfDoc->isOk())
+			{
+				double h = pdfDoc->getPageMediaHeight(1);
+				double w = pdfDoc->getPageMediaWidth(1);
+				double scale = qMin(500.0 / h, 500.0 / 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(pdfDoc);
+				pdfDoc->displayPage(dev, 1, hDPI, vDPI, 0, gTrue, gFalse, gFalse);
+				SplashBitmap *bitmap = dev->getBitmap();
+				int bw = bitmap->getWidth();
+				int bh = bitmap->getHeight();
+				if (bitmap->convertToXBGR())
+				{
+					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;
+					delete pdfDoc;
+					delete globalParams;
+					return image;
+				}
+				else
+				{
+					delete dev;
+					delete pdfDoc;
+					delete globalParams;
+					return QImage();
+				}
+			}
+			else
+			{
+				delete pdfDoc;
+				delete globalParams;
+				return QImage();
+			}
+		}
+		else
+			return QImage();
+	}
+	return QImage();
+}
+/*	Old Code to be backed up
 	QString tmp, cmd1, cmd2;
 	QString pdfFile = QDir::toNativeSeparators(fName);
 	QString tmpFile = QDir::toNativeSeparators(ScPaths::getTempFileDir() + "sc.png");
@@ -90,7 +174,7 @@
 		return image;
 	}
 	return QImage();
-}
+*/
 
 bool PdfPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
 {
@@ -497,6 +581,21 @@
 						m_Doc->setPageHeight(pdfDoc->getPageMediaHeight(1));
 						m_Doc->setPageWidth(pdfDoc->getPageMediaWidth(1));
 						m_Doc->setPageSize("Custom");
+						PDFRectangle *mediaBox = pdfDoc->getPage(1)->getMediaBox();
+						PDFRectangle *cropBox = pdfDoc->getPage(1)->getCropBox();
+						PDFRectangle *trimBox = pdfDoc->getPage(1)->getTrimBox();
+						PDFRectangle *bleedBox = pdfDoc->getPage(1)->getBleedBox();
+						PDFRectangle *artBox = pdfDoc->getPage(1)->getArtBox();
+						QRectF mediaRect = QRectF(QPointF(mediaBox->x1, mediaBox->y1), QPointF(mediaBox->x2, mediaBox->y2)).normalized();
+						QRectF cropRect = QRectF(QPointF(cropBox->x1, cropBox->y1), QPointF(cropBox->x2, cropBox->y2)).normalized();
+						QRectF trimRect = QRectF(QPointF(trimBox->x1, trimBox->y1), QPointF(trimBox->x2, trimBox->y2)).normalized();
+						QRectF bleedRect = QRectF(QPointF(bleedBox->x1, bleedBox->y1), QPointF(bleedBox->x2, bleedBox->y2)).normalized();
+						QRectF artRect = QRectF(QPointF(artBox->x1, artBox->y1), QPointF(artBox->x2, artBox->y2)).normalized();
+						qDebug() << "Media Box" << mediaRect << "Area" << mediaRect.width() * mediaRect.height();
+						qDebug() << "Crop Box" << cropRect << "Area" << cropRect.width() * cropRect.height();
+						qDebug() << "Trim Box" << trimRect << "Area" << trimRect.width() * trimRect.height();
+						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++)
 						{

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp Sat Nov 10 19:34:20 2012
@@ -1127,6 +1127,14 @@
 							double dx = sing->xPos() - ite->xPos();
 							double dy = sing->yPos() - ite->yPos();
 							sing->PoLine.translate(dx, dy);
+							if (sing->isGroup())
+							{
+								QList<PageItem*> allItems = sing->asGroupFrame()->getItemList();
+								for (int si = 0; si < allItems.count(); si++)
+								{
+									allItems[si]->moveBy(dx, dy, true);
+								}
+							}
 							QPainterPath input1 = sing->PoLine.toQPainterPath(true);
 							if (sing->fillEvenOdd())
 								input1.setFillRule(Qt::OddEvenFill);
@@ -1140,8 +1148,12 @@
 							QPainterPath result = input1.intersected(input2);
 							sing->setXYPos(ite->xPos(), ite->yPos(), true);
 							sing->setWidthHeight(ite->width(), ite->height(), true);
+							sing->groupWidth = ite->width();
+							sing->groupHeight = ite->height();
 							sing->PoLine.fromQPainterPath(result);
 							m_doc->AdjustItemSize(sing);
+							if (sing->isGroup())
+								sing->asGroupFrame()->adjustXYPosition();
 						}
 						delete ite;
 					}

Modified: trunk/Scribus/scribus/scribuscore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/scribuscore.cpp
==============================================================================
--- trunk/Scribus/scribus/scribuscore.cpp (original)
+++ trunk/Scribus/scribus/scribuscore.cpp Sat Nov 10 19:34:20 2012
@@ -221,7 +221,7 @@
 	if (showSplash)
 	{
         QPixmap pix = loadIcon("Splash.png", true);
-        m_SplashScreen = new SplashScreen(pix, Qt::WindowStaysOnTopHint);
+		m_SplashScreen = new ScSplashScreen(pix, Qt::WindowStaysOnTopHint);
         if (m_SplashScreen != NULL)
             m_SplashScreen->show();
 		if (m_SplashScreen != NULL && m_SplashScreen->isVisible())

Modified: trunk/Scribus/scribus/scribuscore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/scribuscore.h
==============================================================================
--- trunk/Scribus/scribus/scribuscore.h (original)
+++ trunk/Scribus/scribus/scribuscore.h Sat Nov 10 19:34:20 2012
@@ -32,7 +32,7 @@
 class QWidget;
 class FileWatcher;
 class PluginManager;
-class SplashScreen;
+class ScSplashScreen;
 class ScribusMainWindow;
 class PrefsManager;
 class UndoManager;
@@ -56,7 +56,7 @@
 	ScribusCore();
 	~ScribusCore();
 	
-	SplashScreen* splash() {return m_SplashScreen;};
+	ScSplashScreen* splash() {return m_SplashScreen;};
 	/*
 	int exportToPDF() {return 0;}
 	int exportToEPS() {return 0;}
@@ -131,7 +131,7 @@
 	QList<ScribusMainWindow*> ScMWList;
 	int m_currScMW;
 	
-	SplashScreen *m_SplashScreen;
+	ScSplashScreen *m_SplashScreen;
 	UndoManager *undoManager;
 	PrefsManager *prefsManager;
 	bool m_ScribusInitialized;

Modified: trunk/Scribus/scribus/ui/customfdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/ui/customfdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.cpp (original)
+++ trunk/Scribus/scribus/ui/customfdialog.cpp Sat Nov 10 19:34:20 2012
@@ -147,6 +147,7 @@
 	QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::IMAGESIMGFRAME, 1));
  	QStringList formats = formatD.split("|");
 	formats.append("pat");
+	formats.removeAll("pdf");
 	
 	QStringList allFormatsV = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
 	if (ext.isEmpty())

Modified: trunk/Scribus/scribus/ui/splash.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/ui/splash.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/splash.cpp (original)
+++ trunk/Scribus/scribus/ui/splash.cpp Sat Nov 10 19:34:20 2012
@@ -19,12 +19,12 @@
 #include "util_icon.h"
 
 
-SplashScreen::SplashScreen( const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen( pixmap, f)
+ScSplashScreen::ScSplashScreen( const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen( pixmap, f)
 {
 
 }
 
-void SplashScreen::setStatus( const QString &message )
+void ScSplashScreen::setStatus( const QString &message )
 {
 	static QRegExp rx("&\\S*");	
 	QString tmp(message);

Modified: trunk/Scribus/scribus/ui/splash.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17869&path=/trunk/Scribus/scribus/ui/splash.h
==============================================================================
--- trunk/Scribus/scribus/ui/splash.h (original)
+++ trunk/Scribus/scribus/ui/splash.h Sat Nov 10 19:34:20 2012
@@ -14,15 +14,15 @@
 
 
 //! \brief Scribus splash screen
-class SCRIBUS_API SplashScreen : public QSplashScreen
+class SCRIBUS_API ScSplashScreen : public QSplashScreen
 {
 public:
 	/*!
 	\author Franz Schmid
 	\brief Constructor for SplashScreen
 	 */
-    SplashScreen ( const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0 );
-	~SplashScreen() {};
+	ScSplashScreen ( const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0 );
+	~ScSplashScreen() {};
 	/*!
 	\author Franz Schmid
 	\brief Sets new status on SplashScreen and calls for a SplashScreen::repaint afterwards.




More information about the scribus-commit mailing list