]> git.lyx.org Git - lyx.git/blobdiff - src/Format.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / Format.cpp
index 485715b6e3b23911d622c31897856467f748bd0e..c9e1381992ffd80cb232ad7b179d5bea7910a232 100644 (file)
@@ -100,19 +100,6 @@ private:
 };
 
 
-class FormatPrettyNameEqual : public unary_function<Format, bool> {
-public:
-       FormatPrettyNameEqual(string const & prettyname)
-               : prettyname_(prettyname)
-       {}
-       bool operator()(Format const & f) const
-       {
-               return f.prettyname() == prettyname_;
-       }
-private:
-       string prettyname_;
-};
-
 } //namespace anon
 
 bool Format::formatSorter(Format const * lhs, Format const * rhs)
@@ -206,7 +193,7 @@ string guessFormatFromContents(FileName const & fn)
        // FIG  #FIG...
        // FITS ...BITPIX...
        // GIF  GIF...
-       // JPG  JFIF
+       // JPG  \377\330...     (0xFFD8)
        // PDF  %PDF-...
        // PNG  .PNG...
        // PBM  P1... or P4     (B/W)
@@ -280,6 +267,9 @@ string guessFormatFromContents(FileName const & fn)
                        } else if (stamp == "BM") {
                                format =  "bmp";
 
+                       } else if (stamp == "\377\330") {
+                               format =  "jpg";
+
                        } else if (stamp == "\001\332") {
                                format =  "sgi";
 
@@ -335,9 +325,6 @@ string guessFormatFromContents(FileName const & fn)
                else if (contains(str, "Grace"))
                        format = "agr";
 
-               else if (contains(str, "JFIF"))
-                       format = "jpg";
-
                else if (contains(str, "%PDF"))
                        // autodetect pdf format for graphics inclusion
                        format = "pdf6";
@@ -415,11 +402,19 @@ string Formats::getFormatFromFile(FileName const & filename) const
                                        << "\tCouldn't load magic database - "
                                        << magic_error(magic_cookie));
                        } else {
-                               string mime = magic_file(magic_cookie,
+                               char const * result = magic_file(magic_cookie,
                                        filename.toFilesystemEncoding().c_str());
-                               mime = token(mime, ';', 0);
+                               string mime;
+                               if (result)
+                                       mime = token(result, ';', 0);
+                               else {
+                                       LYXERR(Debug::GRAPHICS, "Formats::getFormatFromFile\n"
+                                               << "\tCouldn't query magic database - "
+                                               << magic_error(magic_cookie));
+                               }
                                // we need our own ps/eps detection
-                               if ((mime != "application/postscript") && (mime != "text/plain")) {
+                               if (!mime.empty() && mime != "application/postscript" &&
+                                   mime != "text/plain") {
                                        Formats::const_iterator cit =
                                                find_if(formatlist.begin(), formatlist.end(),
                                                        FormatMimeEqual(mime));
@@ -473,19 +468,6 @@ string Formats::getFormatFromExtension(string const & ext) const
 }
 
 
-string Formats::getFormatFromPrettyName(string const & prettyname) const
-{
-       if (!prettyname.empty()) {
-               Formats::const_iterator cit =
-                       find_if(formatlist.begin(), formatlist.end(),
-                               FormatPrettyNameEqual(prettyname));
-               if (cit != formats.end())
-                       return cit->name();
-       }
-       return string();
-}
-
-
 /// Used to store last timestamp of file and whether it is (was) zipped
 struct ZippedInfo {
        bool zipped;
@@ -495,6 +477,7 @@ struct ZippedInfo {
 };
 
 
+// FIXME THREAD
 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
 static std::map<std::string, ZippedInfo> zipped_;
 
@@ -814,7 +797,7 @@ FlavorTranslator initFlavorTranslator()
 
 FlavorTranslator const & flavorTranslator()
 {
-       static FlavorTranslator translator = initFlavorTranslator();
+       static FlavorTranslator const translator = initFlavorTranslator();
        return translator;
 }