]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsCache.cpp
C++11 supports thread-safe initialization of statics
[lyx.git] / src / graphics / GraphicsCache.cpp
index 89c5053cb6617e51511aa674524a9844fb6aa234..a51f2322fd6b112bcab0f68f33b8c9a0ea62cebd 100644 (file)
 #include "GraphicsCacheItem.h"
 #include "GraphicsImage.h"
 
+#include "Format.h"
+
+#include "frontends/Application.h"
+
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
@@ -59,9 +63,41 @@ Cache::~Cache()
 }
 
 
-vector<string> Cache::loadableFormats() const
+vector<string> const & Cache::loadableFormats() const
 {
-       return Image::loadableFormats();
+       static vector<string> fmts;
+
+       if (!fmts.empty())
+               return fmts;
+
+       // The formats recognised by LyX
+       Formats::const_iterator begin = formats.begin();
+       Formats::const_iterator end   = formats.end();
+
+       // The formats natively loadable.
+       vector<string> nformat = frontend::loadableImageFormats();
+       
+       vector<string>::const_iterator it = nformat.begin();
+       for (; it != nformat.end(); ++it) {
+               for (Formats::const_iterator fit = begin; fit != end; ++fit) {
+                       if (fit->extension() == *it) {
+                               fmts.push_back(fit->name());
+                               break;
+                       }
+               }
+       }
+
+       if (lyxerr.debugging()) {
+               LYXERR(Debug::GRAPHICS, "LyX recognises the following image formats:");
+
+               vector<string>::const_iterator fbegin = fmts.begin();
+               vector<string>::const_iterator fend = fmts.end();
+               for (vector<string>::const_iterator fit = fbegin; fit != fend; ++fit) {
+                       LYXERR(Debug::GRAPHICS, *fit << ',');
+               }
+       }
+
+       return fmts;
 }