};
-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)
+{
+ return _(lhs->prettyname()) < _(rhs->prettyname());
+}
bool operator<(Format const & a, Format const & b)
{
// FIG #FIG...
// FITS ...BITPIX...
// GIF GIF...
- // JPG JFIF
+ // JPG \377\330... (0xFFD8)
// PDF %PDF-...
// PNG .PNG...
// PBM P1... or P4 (B/W)
string str;
string format;
bool firstLine = true;
+ bool backslash = false;
+ int dollars = 0;
while ((count++ < max_count) && format.empty()) {
- if (ifs.eof()) {
- LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
- << "\tFile type not recognised before EOF!");
+ if (ifs.eof())
break;
- }
getline(ifs, str);
string const stamp = str.substr(0, 2);
} else if (stamp == "BM") {
format = "bmp";
+ } else if (stamp == "\377\330") {
+ format = "jpg";
+
} else if (stamp == "\001\332") {
format = "sgi";
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";
else if (contains(str, "BITPIX"))
format = "fits";
+
+ else if (contains(str, "\\documentclass") ||
+ contains(str, "\\chapter") ||
+ contains(str, "\\section") ||
+ contains(str, "\\begin") ||
+ contains(str, "\\end") ||
+ contains(str, "$$") ||
+ contains(str, "\\[") ||
+ contains(str, "\\]"))
+ format = "latex";
+ else {
+ if (contains(str, '\\'))
+ backslash = true;
+ dollars += count_char(str, '$');
+ }
}
- if (!format.empty()) {
+ if (format.empty() && backslash && dollars > 1)
+ // inline equation
+ format = "latex";
+
+ if (format.empty()) {
+ if (ifs.eof())
+ LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
+ "\tFile type not recognised before EOF!");
+ } else {
LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
return format;
}
<< "\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));
}
-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;
};
+// FIXME THREAD
/// Mapping absolute pathnames of files to their ZippedInfo metadata.
static std::map<std::string, ZippedInfo> zipped_;
FlavorTranslator const & flavorTranslator()
{
- static FlavorTranslator translator = initFlavorTranslator();
+ static FlavorTranslator const translator = initFlavorTranslator();
return translator;
}