Vincent van Ravesteijn wrote:

> In any case, the logic is a bit strange. The icon names are defined
> with the extension {png,svgz} so that any one matched, and getPixmap
> checks whether the file can be loaded or not. However, iconName then
> already decides on whether it is png or svgz just based on existence,
> not on whether it can be loaded.
> 
> So, either we make QtSvg a "required" dependency, and cmake/autotools
> should check for it, or we improve the logic to decide whether we lood
> the png or svgz variant.

For 2.2 I'd prefer to improve the logic, since it is the first release which 
includes the svg icons. For 2.3 we can get rid of the .pngs.

Does the attached patch help?


Georg
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index 5e213e6..661a540 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -156,12 +156,20 @@ using namespace std;
 using namespace lyx::support;
 
 
+static bool enableSVG = false;
 static void initializeResources()
 {
 	static bool initialized = false;
 	if (!initialized) {
 		Q_INIT_RESOURCE(Resources);
 		initialized = true;
+		QList<QByteArray> qt_formats = QImageReader::supportedImageFormats();
+		for (QList<QByteArray>::const_iterator it = qt_formats.begin();
+		     it != qt_formats.end() && !enableSVG; ++it) {
+			string format = ascii_lowercase((const char *) *it);
+			if (format == "svg")
+				enableSVG = true;
+		}
 	}
 }
 
@@ -520,13 +528,14 @@ QString iconName(FuncRequest const & f, bool unknown)
 	QStringList imagedirs;
 	imagedirs << "images/" << "images/ipa/";
 	search_mode mode = theGuiApp()->imageSearchMode();
+	QString const formats = (enableSVG ? "svgz,png" : "png");
 	for (int i = 0; i < imagedirs.size(); ++i) {
 		QString imagedir = imagedirs.at(i) + path;
-		FileName fname = imageLibFileSearch(imagedir, name1, "svgz,png", mode);
+		FileName fname = imageLibFileSearch(imagedir, name1, formats, mode);
 		if (fname.exists())
 			return toqstr(fname.absFileName());
 
-		fname = imageLibFileSearch(imagedir, name2, "svgz,png", mode);
+		fname = imageLibFileSearch(imagedir, name2, formats, mode);
 		if (fname.exists())
 			return toqstr(fname.absFileName());
 	}
@@ -537,12 +546,12 @@ QString iconName(FuncRequest const & f, bool unknown)
 		LYXERR0("Directory " << path << " not found in resource!");
 		return QString();
 	}
-	if (res.exists(name1 + ".svgz"))
+	if (enableSVG && res.exists(name1 + ".svgz"))
 		return path + name1 + ".svgz";
 	else if (res.exists(name1 + ".png"))
 		return path + name1 + ".png";
 
-	if (res.exists(name2 + ".svgz"))
+	if (enableSVG && res.exists(name2 + ".svgz"))
 		return path + name2 + ".svgz";
 	else if (res.exists(name2 + ".png"))
 		return path + name2 + ".png";
@@ -557,7 +566,7 @@ QString iconName(FuncRequest const & f, bool unknown)
 
 	if (unknown) {
 		QString imagedir = "images/";
-		FileName fname = imageLibFileSearch(imagedir, "unknown", "svgz,png", mode);
+		FileName fname = imageLibFileSearch(imagedir, "unknown", formats, mode);
 		if (fname.exists())
 			return toqstr(fname.absFileName());
 		return QString(":/images/unknown.png");
@@ -587,17 +596,19 @@ bool getPixmap(QPixmap & pixmap, QString const & path)
 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext)
 {
 	QString imagedir = path;
-	FileName fname = imageLibFileSearch(imagedir, name, ext, theGuiApp()->imageSearchMode());
-	QString fpath = toqstr(fname.absFileName());
-	QPixmap pixmap = QPixmap();
-
-	if (getPixmap(pixmap, fpath)) {
-		return pixmap;
-	}
-	
 	QStringList exts = ext.split(",");
-	fpath = ":/" + path + name + ".";
 	for (int i = 0; i < exts.size(); ++i) {
+		if (!enableSVG && (exts.at(i) == "svg" || exts.at(i) == "svgz"))
+			continue;
+		FileName fname = imageLibFileSearch(imagedir, name, ext.at(i),
+		                                    theGuiApp()->imageSearchMode());
+		QString fpath = toqstr(fname.absFileName());
+		QPixmap pixmap = QPixmap();
+
+		if (getPixmap(pixmap, fpath))
+			return pixmap;
+
+		fpath = ":/" + path + name + ".";
 		if (getPixmap(pixmap, fpath + exts.at(i))) {
 			return pixmap;
 		}

Reply via email to