X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFormat.cpp;h=1ee64116ff6d0a16772dafa5890326a2c8a96100;hb=889182eb1a19da1cb4d5b5efeea434a5e6592ef0;hp=7e634b48becd98a8d3799ee3b80f47379d88a3d1;hpb=6b2232a29c682d8e62d1d2b963bb1a70bee4330b;p=lyx.git diff --git a/src/Format.cpp b/src/Format.cpp index 7e634b48be..1ee64116ff 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -23,7 +23,7 @@ #include "support/gettext.h" #include "support/lstrings.h" #include "support/os.h" -#include "support/Path.h" +#include "support/PathChanger.h" #include "support/Systemcall.h" #include "support/textutils.h" #include "support/Translator.h" @@ -115,6 +115,10 @@ private: } //namespace anon +bool Format::formatSorter(Format const * lhs, Format const * rhs) +{ + return _(lhs->prettyname()) < _(rhs->prettyname()); +} bool operator<(Format const & a, Format const & b) { @@ -202,7 +206,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) @@ -249,12 +253,11 @@ string guessFormatFromContents(FileName const & fn) 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); @@ -277,6 +280,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"; @@ -332,11 +338,9 @@ string guessFormatFromContents(FileName const & fn) else if (contains(str, "Grace")) format = "agr"; - else if (contains(str, "JFIF")) - format = "jpg"; - else if (contains(str, "%PDF")) - format = "pdf"; + // autodetect pdf format for graphics inclusion + format = "pdf6"; else if (contains(str, "PNG")) format = "png"; @@ -358,9 +362,32 @@ string guessFormatFromContents(FileName const & fn) 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; } @@ -681,7 +708,7 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename, // LinkBack files look like PDF, but have the .linkback extension string const ext = getExtension(filename.absFileName()); - if (format_name == "pdf" && ext == "linkback") { + if (format_name == "pdf6" && ext == "linkback") { #ifdef USE_MACOSX_PACKAGING return editLinkBackFile(filename.absFileName().c_str()); #else