r22573 by jghali - simplify Ghostscript versions handling by concatenating major and minor versions into a single number

scribus-commit scribus-commit at lists.scribus.net
Sun Jun 3 18:32:04 UTC 2018


Author: jghali
Date: Sun Jun  3 18:32:04 2018
New Revision: 22573

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22573
Log:
simplify Ghostscript versions handling by concatenating major and minor versions into a single number

Modified:
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_ps.cpp
    trunk/Scribus/scribus/ui/preview.cpp
    trunk/Scribus/scribus/ui/preview.h
    trunk/Scribus/scribus/util_ghostscript.cpp
    trunk/Scribus/scribus/util_ghostscript.h

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_ps.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22573&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_ps.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_ps.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_ps.cpp	Sun Jun  3 18:32:04 2018
@@ -754,9 +754,8 @@
 	QString ext = fi.suffix().toLower();
 	QString tmpFile = QDir::toNativeSeparators(ScPaths::tempFileDir() + "sc1.png");
 	int retg;
-	int GsMajor;
-	int GsMinor;
-	getNumericGSVersion(GsMajor, GsMinor);
+	int GsVersion;
+	getNumericGSVersion(GsVersion);
 	ScTextStream ts2(&m_BBox, QIODevice::ReadOnly);
 	double x, y, b, h;
 	ts2 >> x >> y >> b >> h;
@@ -765,7 +764,7 @@
 		args.append("-dEPSCrop");
 	if (m_psMode == 4)
 		args.append("-dGrayValues=256");
-	if ((GsMajor >= 8) && (GsMinor >= 53))
+	if (GsVersion >= 853)
 		args.append("-dNOPSICC");		// prevent GS from applying an embedded ICC profile as it will be applied later on in ScImage.
 	args.append("-r"+QString::number(gsRes));
 	args.append("-sOutputFile=" + tmpFile);

Modified: trunk/Scribus/scribus/ui/preview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22573&path=/trunk/Scribus/scribus/ui/preview.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/preview.cpp	(original)
+++ trunk/Scribus/scribus/ui/preview.cpp	Sun Jun  3 18:32:04 2018
@@ -103,7 +103,7 @@
 	fGray = false;
 	scaleFactor = 1.0;
 	SMode = 1;
-	getNumericGSVersion(GsMajor, GsMinor);
+	getNumericGSVersion(GsVersion);
 	PLayout = new QVBoxLayout(this);
 	PLayout->setMargin(0);
 	PLayout->setSpacing(0);
@@ -567,7 +567,7 @@
 		args.append( "-dTextAlphaBits=4" );
 		args.append( "-dGraphicsAlphaBits=4" );
 	}
-	if ((doc->HasCMS) && (GsMinor >= 0) && (GsMajor >= 9))
+	if ((doc->HasCMS) && (GsVersion >= 900))
 	{
 		args.append("-sDefaultCMYKProfile=" + QDir::toNativeSeparators(doc->DocPrinterProf.profilePath()));
 		if (EnableCMYK->isChecked())
@@ -575,7 +575,7 @@
 		else
 			args.append("-sOutputICCProfile=" + QDir::toNativeSeparators(doc->DocDisplayProf.profilePath()));
 	}
-	else if (ScCore->haveCMS() && (GsMinor >= 0) && (GsMajor >= 9))
+	else if (ScCore->haveCMS() && (GsVersion >= 900))
 	{
 		args.append("-sDefaultCMYKProfile=" + QDir::toNativeSeparators(ScCore->defaultCMYKProfile.profilePath()));
 		if (EnableCMYK->isChecked())
@@ -665,12 +665,12 @@
 		args1.append("-dTextAlphaBits=4");
 		args1.append("-dGraphicsAlphaBits=4");
 	}
-	if ((doc->HasCMS) && (GsMinor >= 0) && (GsMajor >= 9))
+	if ((doc->HasCMS) && (GsVersion >= 900))
 	{
 		args1.append("-sDefaultCMYKProfile=" + QDir::toNativeSeparators(doc->DocPrinterProf.profilePath()));
 		args1.append("-sOutputICCProfile=" + QDir::toNativeSeparators(doc->DocPrinterProf.profilePath()));
 	}
-	else if (ScCore->haveCMS() && (GsMinor >= 0) && (GsMajor >= 9))
+	else if (ScCore->haveCMS() && (GsVersion >= 900))
 	{
 		args.append("-sDefaultCMYKProfile=" + QDir::toNativeSeparators(ScCore->defaultCMYKProfile.profilePath()));
 		args.append("-sOutputICCProfile=" + QDir::toNativeSeparators(ScCore->defaultCMYKProfile.profilePath()));
@@ -909,9 +909,9 @@
 			cms.allowColorManagement(false);
 			if (flagsVisible["Cyan"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.tif.Cyan.tif", 1, cms, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.Cyan.tif", 1, cms, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc(Cyan).tif", 1, cms, ScImage::RGBData, 72, &mode);
@@ -927,9 +927,9 @@
 			}
 			if (flagsVisible["Magenta"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.tif.Magenta.tif", 1, cms, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.Magenta.tif", 1, cms, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc(Magenta).tif", 1, cms, ScImage::RGBData, 72, &mode);
@@ -945,9 +945,9 @@
 			}
 			if (flagsVisible["Yellow"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.tif.Yellow.tif", 1, cms, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.Yellow.tif", 1, cms, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc(Yellow).tif", 1, cms, ScImage::RGBData, 72, &mode);
@@ -970,9 +970,9 @@
 					if (checkBox && checkBox->isChecked())
 					{
 						QString fnam;
-						if ((GsMinor < 54) && (GsMajor < 9))
+						if (GsVersion < 854)
 							fnam = QString(ScPaths::tempFileDir()+"/sc.tif.s%1.tif").arg(sepit.value());
-						else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+						else if (GsVersion <= 905)
 							fnam = QString(ScPaths::tempFileDir()+"/sc.s%1.tif").arg(sepit.value());
 						else
 							fnam = QString(ScPaths::tempFileDir()+"/sc(%1).tif").arg(sepit.key());
@@ -992,9 +992,9 @@
 			{
 				CMSettings cms(doc, "", Intent_Perceptual);
 				cms.allowColorManagement(false);
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.tif.Black.tif", 1, cms, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc.Black.tif", 1, cms, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.loadPicture(ScPaths::tempFileDir()+"/sc(Black).tif", 1, cms, ScImage::RGBData, 72, &mode);

Modified: trunk/Scribus/scribus/ui/preview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22573&path=/trunk/Scribus/scribus/ui/preview.h
==============================================================================
--- trunk/Scribus/scribus/ui/preview.h	(original)
+++ trunk/Scribus/scribus/ui/preview.h	Sun Jun  3 18:32:04 2018
@@ -99,8 +99,7 @@
 	int APage;
 	int MPage;
 	int SMode;
-	int GsMajor;
-	int GsMinor;
+	int GsVersion;
 	int inkMax;
 	bool CMode;
 	bool GsAl;

Modified: trunk/Scribus/scribus/util_ghostscript.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22573&path=/trunk/Scribus/scribus/util_ghostscript.cpp
==============================================================================
--- trunk/Scribus/scribus/util_ghostscript.cpp	(original)
+++ trunk/Scribus/scribus/util_ghostscript.cpp	Sun Jun  3 18:32:04 2018
@@ -149,13 +149,13 @@
 	args.append( "-dNOPAUSE" );
 	args.append( "-dPARANOIDSAFER" );
 	args.append( "-dBATCH" );
-	if( level == 2 )
-	{
-		int major = 0, minor = 0;
+	if (level == 2)
+	{
+		int gsVersion = 0;
 		// ps2write cannot be detected with testGSAvailability()
 		// so determine availability according to gs version.
-		getNumericGSVersion(major, minor);
-		if ((major >=8 && minor >= 53) || major > 8)
+		getNumericGSVersion(gsVersion);
+		if (gsVersion >= 853)
 			args.append( "-sDEVICE=ps2write" );
 		else
 		{
@@ -167,7 +167,7 @@
 	else
 	{
 		args.append( "-sDEVICE=pswrite" );
-		if(level <= 3)
+		if (level <= 3)
 			args.append( QString("-dLanguageLevel=%1").arg(level) );
 	}
 	args += opts;
@@ -243,6 +243,18 @@
 	if (proc.exitStatus()==QProcess::NormalExit)
 		gsVer = proc.readAllStandardOutput();
 	return gsVer;
+}
+
+bool getNumericGSVersion(int &version)
+{
+	version = 0;
+	int major(0), minor(0);
+	if (getNumericGSVersion(major, minor))
+	{
+		version = 100 * major + minor;
+		return true;
+	}
+	return false;
 }
 
 // Return the GhostScript major and minor version numbers.
@@ -377,9 +389,9 @@
 				{
 					// We now have GhostScript dll path, but we want gswin32c.exe
 					// Normally gswin32c.exe and gsdll.dll are in the same directory
-					if ( getNumericGSVersion(QString::fromUtf16((const ushort*) regVersion), gsMajor, gsMinor) )
+					if (getNumericGSVersion(QString::fromUtf16((const ushort*) regVersion), gsMajor, gsMinor))
 					{
-						gsNumericVer = gsMajor * 1000 + gsMinor;
+						gsNumericVer = gsMajor * 100 + gsMinor;
 						gsName = QString::fromUtf16((const ushort*) gsPath);
 						size   = gsName.lastIndexOf("\\");
 						if (size > 0)
@@ -402,7 +414,7 @@
 	PrefsManager* prefsManager=PrefsManager::instance();
 	if (getNumericGSVersion(gsMajor, gsMinor))
 	{
-		gsNumericVer = gsMajor * 1000 + gsMinor;
+		gsNumericVer = gsMajor * 100 + gsMinor;
 		gsVersions.insert(gsNumericVer, prefsManager->ghostscriptExecutable());
 	}
 #endif

Modified: trunk/Scribus/scribus/util_ghostscript.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22573&path=/trunk/Scribus/scribus/util_ghostscript.h
==============================================================================
--- trunk/Scribus/scribus/util_ghostscript.h	(original)
+++ trunk/Scribus/scribus/util_ghostscript.h	Sun Jun  3 18:32:04 2018
@@ -49,6 +49,7 @@
  (in which case minor and major have undefined values).
  \retval QString version or false on error */
 QString SCRIBUS_API getGSVersion();
+bool    SCRIBUS_API getNumericGSVersion(int &version);
 bool    SCRIBUS_API getNumericGSVersion(int & major, int & minor);
 bool    SCRIBUS_API getNumericGSVersion(const QString& ver, int&major, int& minor);
 QString SCRIBUS_API getGSDefaultExeName(void);




More information about the scribus-commit mailing list