r22147 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Sat Aug 26 12:09:45 UTC 2017


Author: jghali
Date: Sat Aug 26 12:09:45 2017
New Revision: 22147

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22147
Log:
14964: Scribus hangs on "Adjusting Colors" when Exporting PDF with "Thumbnails"

Modified:
    trunk/Scribus/scribus/plugins/export/pixmapexport/export.cpp
    trunk/Scribus/scribus/plugins/export/xpsexport/xpsexplugin.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/objimageexport.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusstructs.h
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/scribusview.h

Modified: trunk/Scribus/scribus/plugins/export/pixmapexport/export.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/plugins/export/pixmapexport/export.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/export/pixmapexport/export.cpp	(original)
+++ trunk/Scribus/scribus/plugins/export/pixmapexport/export.cpp	Sat Aug 26 12:09:45 2017
@@ -188,7 +188,10 @@
 	* portrait and user defined sizes.
 	*/
 	double pixmapSize = (page->height() > page->width()) ? page->height() : page->width();
-	QImage im(doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), false, background));
+	PageToPixmapFlags flags;
+	if (background)
+		flags |= Pixmap_DrawBackground;
+	QImage im(doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), flags));
 	if (im.isNull())
 	{
 		ScMessageBox::warning(doc->scMW(), tr("Save as Image"), tr("Insufficient memory for this image size."));

Modified: trunk/Scribus/scribus/plugins/export/xpsexport/xpsexplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/plugins/export/xpsexport/xpsexplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/export/xpsexport/xpsexplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/export/xpsexport/xpsexplugin.cpp	Sat Aug 26 12:09:45 2017
@@ -254,7 +254,7 @@
 		writeCore();
 		writeDocRels();
 		// Write Thumbnail
-		QImage thumb = m_Doc->view()->PageToPixmap(0, 256, false);
+		QImage thumb = m_Doc->view()->PageToPixmap(0, 256, Pixmap_DrawBackground);
 		thumb.save(baseDir + "/docProps/thumbnail.jpeg", "JPG");
 		// Write required DocStructure.struct
 		QFile fts(baseDir + "/Documents/1/Structure/DocStructure.struct");

Modified: trunk/Scribus/scribus/plugins/scriptplugin/objimageexport.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/plugins/scriptplugin/objimageexport.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/objimageexport.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/objimageexport.cpp	Sat Aug 26 12:09:45 2017
@@ -142,16 +142,15 @@
 {
 	if(!checkHaveDocument())
 		return NULL;
+	ScribusDoc*  doc = ScCore->primaryMainWindow()->doc;
+	ScribusView*view = ScCore->primaryMainWindow()->view;
 
 	/* a little magic here - I need to compute the "maxGr" value...
 	* We need to know the right size of the page for landscape,
 	* portrait and user defined sizes.
 	*/
-	double pixmapSize;
-	(ScCore->primaryMainWindow()->doc->pageHeight() > ScCore->primaryMainWindow()->doc->pageWidth())
-			? pixmapSize = ScCore->primaryMainWindow()->doc->pageHeight()
-			: pixmapSize = ScCore->primaryMainWindow()->doc->pageWidth();
-	QImage im = ScCore->primaryMainWindow()->view->PageToPixmap(ScCore->primaryMainWindow()->doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), false);
+	double pixmapSize = (doc->pageHeight() > doc->pageWidth()) ? doc->pageHeight() : doc->pageWidth();
+	QImage im = view->PageToPixmap(doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), Pixmap_DrawBackground);
 	int dpi = qRound(100.0 / 2.54 * self->dpi);
 	im.setDotsPerMeterY(dpi);
 	im.setDotsPerMeterX(dpi);
@@ -174,15 +173,15 @@
 	if (!PyArg_ParseTuple(args, const_cast<char*>("es"), "utf-8", &value))
 		return NULL;
 
+	ScribusDoc*  doc = ScCore->primaryMainWindow()->doc;
+	ScribusView*view = ScCore->primaryMainWindow()->view;
+
 	/* a little magic here - I need to compute the "maxGr" value...
 	* We need to know the right size of the page for landscape,
 	* portrait and user defined sizes.
 	*/
-	double pixmapSize;
-	(ScCore->primaryMainWindow()->doc->pageHeight() > ScCore->primaryMainWindow()->doc->pageWidth())
-			? pixmapSize = ScCore->primaryMainWindow()->doc->pageHeight()
-			: pixmapSize = ScCore->primaryMainWindow()->doc->pageWidth();
-	QImage im = ScCore->primaryMainWindow()->view->PageToPixmap(ScCore->primaryMainWindow()->doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), false);
+	double pixmapSize = (doc->pageHeight() > doc->pageWidth()) ? doc->pageHeight() : doc->pageWidth();
+	QImage im = view->PageToPixmap(doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), Pixmap_DrawBackground);
 	int dpi = qRound(100.0 / 2.54 * self->dpi);
 	im.setDotsPerMeterY(dpi);
 	im.setDotsPerMeterX(dpi);

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Sat Aug 26 12:09:45 2017
@@ -7200,14 +7200,44 @@
 		QString pageString(dia.getPagesString());
 		std::vector<int> pageNs;
 		uint pageNumbersSize;
-		QMap<int,QPixmap> thumbs;
-		int components=dia.colorSpaceComponents();
+		QMap<int,QPixmap> allThumbs, thumbs;
+		int components = dia.colorSpaceComponents();
 		QString nam(dia.cmsDescriptor());
 		QString fileName = doc->pdfOptions().fileName;
 		QString errorMsg;
 		parsePagesString(pageString, &pageNs, doc->DocPages.count());
 		if (doc->pdfOptions().useDocBleeds)
 			doc->pdfOptions().bleeds = *doc->bleeds();
+
+		// If necssary, generate thumbnails in one go : if color management is enabled
+		// we gain lots of time by avoiding multiple color management settings change
+		// and hence multiple reloading of images
+		bool cmsCorr = false;
+		if (doc->pdfOptions().Thumbnails &&
+			doc->cmsSettings().CMSinUse &&
+			doc->cmsSettings().GamutCheck)
+		{
+			cmsCorr = true;
+			doc->cmsSettings().GamutCheck = false;
+			doc->enableCMS(true);
+		}
+		pageNumbersSize = pageNs.size();
+		for (uint i = 0; i < pageNumbersSize; ++i)
+		{
+			QPixmap pm(10, 10);
+			if (doc->pdfOptions().Thumbnails)
+			{
+				// No need to load full res images for drawing small thumbnail
+				PageToPixmapFlags flags = Pixmap_DontReloadImages;
+				pm = QPixmap::fromImage(view->PageToPixmap(pageNs[i] - 1, 100, flags));
+			}
+			allThumbs.insert(pageNs[i], pm);
+		}
+		if (cmsCorr)
+		{
+			doc->cmsSettings().GamutCheck = true;
+			doc->enableCMS(true);
+		}
 
 		if (doc->pdfOptions().doMultiFile)
 		{
@@ -7226,7 +7256,7 @@
 				pageNumbersSize = pageNs2.size();
 				QPixmap pm(10,10);
 				if (doc->pdfOptions().Thumbnails)
-					pm=QPixmap::fromImage(view->PageToPixmap(pageNs[aa]-1, 100));
+					pm = allThumbs[pageNs[aa]];
 				thumbs.insert(1, pm);
 				QString realName = QDir::toNativeSeparators(path+"/"+name+ tr("-Page%1").arg(pageNs[aa], 3, 10, QChar('0'))+"."+ext);
 				if (!getPDFDriver(realName, nam, components, pageNs2, thumbs, errorMsg, &cancelled))
@@ -7243,15 +7273,7 @@
 		}
 		else
 		{
-			pageNumbersSize = pageNs.size();
-			for (uint ap = 0; ap < pageNumbersSize; ++ap)
-			{
-				QPixmap pm(10,10);
-				if (doc->pdfOptions().Thumbnails)
-					pm=QPixmap::fromImage(view->PageToPixmap(pageNs[ap]-1, 100));
-				thumbs.insert(pageNs[ap], pm);
-			}
-			if (!getPDFDriver(fileName, nam, components, pageNs, thumbs, errorMsg))
+			if (!getPDFDriver(fileName, nam, components, pageNs, allThumbs, errorMsg))
 			{
 				qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 				QString message = tr("Cannot write the file: \n%1").arg(doc->pdfOptions().fileName);

Modified: trunk/Scribus/scribus/scribusstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/scribusstructs.h
==============================================================================
--- trunk/Scribus/scribus/scribusstructs.h	(original)
+++ trunk/Scribus/scribus/scribusstructs.h	Sat Aug 26 12:09:45 2017
@@ -14,6 +14,7 @@
 #include <QAction>
 #include <QByteArray>
 #include <QDebug>
+#include <QFlags>
 #include <QKeySequence>
 #include <QList>
 #include <QPolygon>
@@ -305,6 +306,19 @@
 	customPage = 30
 };
 
+/**
+* Flags for ScribusView PageToPixmap()
+*/
+enum PageToPixmapFlag {
+	Pixmap_NoFlags = 0,
+	Pixmap_DrawFrame = 1 << 0,
+	Pixmap_DrawBackground = 1 << 1,
+	Pixmap_DontReloadImages = 1 << 2,
+};
+
+Q_DECLARE_FLAGS(PageToPixmapFlags, PageToPixmapFlag);
+Q_DECLARE_OPERATORS_FOR_FLAGS(PageToPixmapFlags);
+
 enum UpdateRequests
 {
 	reqColorsUpdate = 1,

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Sat Aug 26 12:09:45 2017
@@ -2733,7 +2733,7 @@
 	return im;
 }
 
-QImage ScribusView::PageToPixmap(int Nr, int maxGr, bool drawFrame, bool drawBackground)
+QImage ScribusView::PageToPixmap(int Nr, int maxGr, PageToPixmapFlags flags)
 {
 	QImage im;
 	double sx = maxGr / Doc->DocPages.at(Nr)->width();
@@ -2777,11 +2777,11 @@
 	Doc->setLoading(true);
 	Doc->setCurrentPage(Doc->DocPages.at(Nr));
 	ScPainter *painter = new ScPainter(&im, im.width(), im.height(), 1.0, 0);
-	if (drawBackground)
+	if (flags & Pixmap_DrawBackground)
 		painter->clear(Doc->paperColor());
 	painter->translate(-clipx, -clipy);
 	painter->setFillMode(ScPainter::Solid);
-	if (drawFrame)
+	if (flags & Pixmap_DrawFrame)
 	{
 		painter->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 		painter->setBrush(Doc->paperColor());
@@ -2793,7 +2793,7 @@
 	QList<QPair<PageItem*, int> > changedList;
 	ScPage* page = Doc->DocPages.at(Nr);
 	PageItem* currItem;
-	if (page->FromMaster.count() != 0)
+	if ((page->FromMaster.count() != 0) && !flags.testFlag(Pixmap_DontReloadImages))
 	{
 		QList<PageItem*> itemList = page->FromMaster;
 		while (itemList.count() > 0)
@@ -2821,7 +2821,7 @@
 			currItem->setImageYOffset(imgY);
 		}
 	}
-	if (Doc->Items->count() != 0)
+	if ((Doc->Items->count() != 0) && !flags.testFlag(Pixmap_DontReloadImages))
 	{
 		FPoint orig = m_canvas->localToCanvas(QPoint(clipx, clipy));
 		QRectF cullingArea = QRectF(orig.x(), orig.y(), qRound(clipw / sc + 0.5), qRound(cliph / sc + 0.5));

Modified: trunk/Scribus/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22147&path=/trunk/Scribus/scribus/scribusview.h
==============================================================================
--- trunk/Scribus/scribus/scribusview.h	(original)
+++ trunk/Scribus/scribus/scribusview.h	Sat Aug 26 12:09:45 2017
@@ -161,7 +161,7 @@
 	void hideSymbolPage();
 	void showInlinePage(int id);
 	void hideInlinePage();
-	QImage PageToPixmap(int Nr, int maxGr, bool drawFrame = true, bool drawBackground = true);
+	QImage PageToPixmap(int Nr, int maxGr, PageToPixmapFlags flags = Pixmap_DrawFrame | Pixmap_DrawBackground);
 	QImage MPageToPixmap(QString name, int maxGr, bool drawFrame = true);
 	void RecalcPicturesRes();
 	/**




More information about the scribus-commit mailing list