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

scribus-commit scribus-commit at lists.scribus.net
Sun Aug 12 11:36:52 UTC 2018


Author: jghali
Date: Sun Aug 12 11:36:52 2018
New Revision: 22624

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

Modified:
    branches/Version14x/Scribus/scribus/preview.cpp
    branches/Version14x/Scribus/scribus/preview.h
    branches/Version14x/Scribus/scribus/scimgdataloader_ps.cpp
    branches/Version14x/Scribus/scribus/util_ghostscript.cpp
    branches/Version14x/Scribus/scribus/util_ghostscript.h

Modified: branches/Version14x/Scribus/scribus/preview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22624&path=/branches/Version14x/Scribus/scribus/preview.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/preview.cpp	(original)
+++ branches/Version14x/Scribus/scribus/preview.cpp	Sun Aug 12 11:36:52 2018
@@ -105,7 +105,7 @@
 	fGray = false;
 	scaleFactor = 1.0;
 	SMode = 1;
-	getNumericGSVersion(GsMajor, GsMinor);
+	getNumericGSVersion(GsVersion);
 	PLayout = new QVBoxLayout(this);
 	PLayout->setMargin(0);
 	PLayout->setSpacing(0);
@@ -627,7 +627,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() && HaveTiffSep)
@@ -635,7 +635,7 @@
 		else
 			args.append("-sOutputICCProfile=" + QDir::toNativeSeparators(doc->DocOutputProf.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() && HaveTiffSep)
@@ -727,12 +727,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))
 	{
 		args1.append("-sDefaultCMYKProfile=" + QDir::toNativeSeparators(ScCore->defaultCMYKProfile.profilePath()));
 		args1.append("-sOutputICCProfile=" + QDir::toNativeSeparators(ScCore->defaultCMYKProfile.profilePath()));
@@ -965,9 +965,9 @@
 			CMSettings cms(doc, "", Intent_Perceptual);
 			if (flagsVisible["Cyan"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Cyan.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Cyan.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc(Cyan).tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
@@ -983,9 +983,9 @@
 			}
 			if (flagsVisible["Magenta"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Magenta.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Magenta.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc(Magenta).tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
@@ -1001,9 +1001,9 @@
 			}
 			if (flagsVisible["Yellow"]->isChecked())
 			{
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Yellow.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Yellow.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc(Yellow).tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
@@ -1026,9 +1026,9 @@
 					if (checkBox && checkBox->isChecked())
 					{
 						QString fnam;
-						if ((GsMinor < 54) && (GsMajor < 9))
+						if (GsVersion < 854)
 							fnam = QString(ScPaths::getTempFileDir()+"/sc.tif.s%1.tif").arg(sepit.value());
-						else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+						else if (GsVersion <= 905)
 							fnam = QString(ScPaths::getTempFileDir()+"/sc.s%1.tif").arg(sepit.value());
 						else
 							fnam = QString(ScPaths::getTempFileDir()+"/sc(%1).tif").arg(sepit.key());
@@ -1047,9 +1047,9 @@
 			if (flagsVisible["Black"]->isChecked())
 			{
 				CMSettings cms(doc, "", Intent_Perceptual);
-				if ((GsMinor < 54) && (GsMajor < 9))
+				if (GsVersion < 854)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.tif.Black.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
-				else if ((GsMajor < 9) || ((GsMajor == 9) && (GsMinor <= 5)))
+				else if (GsVersion <= 905)
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc.Black.tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);
 				else
 					loaderror = im.LoadPicture(ScPaths::getTempFileDir()+"/sc(Black).tif", 1, cms, false, false, ScImage::RGBData, 72, &mode);

Modified: branches/Version14x/Scribus/scribus/preview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22624&path=/branches/Version14x/Scribus/scribus/preview.h
==============================================================================
--- branches/Version14x/Scribus/scribus/preview.h	(original)
+++ branches/Version14x/Scribus/scribus/preview.h	Sun Aug 12 11:36:52 2018
@@ -103,8 +103,7 @@
 	int APage;
 	int MPage;
 	int SMode;
-	int GsMajor;
-	int GsMinor;
+	int GsVersion;
 	int inkMax;
 	bool CMode;
 	bool GsAl;

Modified: branches/Version14x/Scribus/scribus/scimgdataloader_ps.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22624&path=/branches/Version14x/Scribus/scribus/scimgdataloader_ps.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scimgdataloader_ps.cpp	(original)
+++ branches/Version14x/Scribus/scribus/scimgdataloader_ps.cpp	Sun Aug 12 11:36:52 2018
@@ -727,9 +727,8 @@
 	QString ext = fi.suffix().toLower();
 	QString tmpFile = QDir::toNativeSeparators(ScPaths::getTempFileDir() + "sc1.png");
 	int retg;
-	int GsMajor;
-	int GsMinor;
-	getNumericGSVersion(GsMajor, GsMinor);
+	int GsVersion;
+	getNumericGSVersion(GsVersion);
 	ScTextStream ts2(&BBox, QIODevice::ReadOnly);
 	ts2 >> x >> y >> b >> h;
 	h = h * gsRes / 72.0;
@@ -737,7 +736,7 @@
 		args.append("-dEPSCrop");
 	if (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: branches/Version14x/Scribus/scribus/util_ghostscript.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22624&path=/branches/Version14x/Scribus/scribus/util_ghostscript.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/util_ghostscript.cpp	(original)
+++ branches/Version14x/Scribus/scribus/util_ghostscript.cpp	Sun Aug 12 11:36:52 2018
@@ -148,25 +148,24 @@
 	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
 		{
 			args.append( "-sDEVICE=pswrite" );
 			args.append( QString("-dLanguageLevel=%1").arg(level) );
-		}
-			
+		}	
 	}
 	else
 	{
 		args.append( "-sDEVICE=pswrite" );
-		if(level <= 3)
+		if (level <= 3)
 			args.append( QString("-dLanguageLevel=%1").arg(level) );
 	}
 	args += opts;
@@ -242,6 +241,18 @@
 	if (proc.exitStatus()==QProcess::NormalExit)
 		gsVer = proc.readAllStandardOutput();
 	return gsVer;
+}
+
+bool getNumericGSVersion(int &version)
+{
+	int gsMajor(0), gsMinor(0);
+	version = 0;
+	if (getNumericGSVersion(gsMajor, gsMinor))
+	{
+		version = 100 * gsMajor + gsMinor;
+		return true;
+	}
+	return false;
 }
 
 // Return the GhostScript major and minor version numbers.
@@ -376,9 +387,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)
@@ -401,7 +412,7 @@
 	PrefsManager* prefsManager=PrefsManager::instance();
 	if (getNumericGSVersion(gsMajor, gsMinor))
 	{
-		gsNumericVer = gsMajor * 1000 + gsMinor;
+		gsNumericVer = gsMajor * 100 + gsMinor;
 		gsVersions.insert(gsNumericVer, prefsManager->ghostscriptExecutable());
 	}
 #endif

Modified: branches/Version14x/Scribus/scribus/util_ghostscript.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22624&path=/branches/Version14x/Scribus/scribus/util_ghostscript.h
==============================================================================
--- branches/Version14x/Scribus/scribus/util_ghostscript.h	(original)
+++ branches/Version14x/Scribus/scribus/util_ghostscript.h	Sun Aug 12 11:36:52 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