#include <config.h>
-#include <cctype>
-
-#include <utility>
-#include <fstream>
-
-#include "Lsstream.h"
-
#ifdef __GNUG__
#pragma implementation "filetools.h"
#endif
-#include <cstdlib>
-#include <cstdio>
-#include <fcntl.h>
-#include <cerrno>
#include "debug.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#include "filetools.h"
+#include "lstrings.h"
#include "frontends/Alert.h"
#include "FileInfo.h"
#include "support/path.h" // I know it's OS/2 specific (SMiyata)
#include "lyxlib.h"
#include "os.h"
+#include "Lsstream.h"
+
+#include <cctype>
+#include <cstdlib>
+#include <cstdio>
+#include <fcntl.h>
+#include <cerrno>
+
+#include <utility>
+#include <fstream>
+
+
// Which part of this is still necessary? (JMarc).
#if HAVE_DIRENT_H
# include <dirent.h>
# endif
#endif
+#ifndef CXX_GLOBAL_CSTD
+using std::fgetc;
+using std::isalpha;
+using std::isalnum;
+#endif
+
using std::make_pair;
using std::pair;
using std::endl;
}
+// FIXME: no need for separate method like this ...
int DestroyLyXTmpDir(string const & tmpdir)
{
- return DestroyTmpDir (tmpdir, false); // Why false?
+ return DestroyTmpDir(tmpdir, true);
}
// AGR Grace...
// BMP BM...
// EPS %!PS-Adobe-3.0 EPSF...
+// EPSI like EPS and with
+// %%BeginPreview...
// FITS ...BITPIX...
// GIF GIF...
// JPG JFIF
if (filename.empty() || !IsFileReadable(filename))
return string();
+
ifstream ifs(filename.c_str());
if (!ifs)
// Couldn't open file...
else if (contains(str,"%!PS-Adobe")) {
// eps or ps
ifs >> str;
- if (contains(str,"EPSF"))
+ if (contains(str,"EPSF"))
format = "eps";
else
format = "ps";
}
if (!format.empty()) {
- lyxerr[Debug::GRAPHICS]
- << "Recognised Fileformat: " << format << endl;
- return format;
+ // if we have eps than epsi is also possible
+ // we have to check for a preview
+ if (format == "eps") {
+ lyxerr[Debug::GRAPHICS]
+ << "\teps detected -> test for an epsi ..."
+ << endl;
+ while (count++ < max_count) {
+ if (ifs.eof())
+ break;
+ getline(ifs, str);
+ if (contains(str, "BeginPreview")) {
+ format = "epsi";
+ count = max_count;
+ }
+ }
+ }
+ lyxerr[Debug::GRAPHICS]
+ << "Recognised Fileformat: " << format << endl;
+ return format;
}
string const ext(GetExtension(filename));
}
+void readBB_lyxerrMessage(string const & file, bool & zipped,
+ string const & message)
+{
+ lyxerr[Debug::GRAPHICS] << "[readBB_from_PSFile] "
+ << message << std::endl;
+ if (zipped)
+ lyx::unlink(file);
+}
+
+
string const readBB_from_PSFile(string const & file)
{
// in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
// end of the file. Than we have in the header:
// %%BoundingBox: (atend)
// In this case we must check the end.
- string const file_ = zippedFile(file) ?
+ bool zipped = zippedFile(file);
+ string const file_ = zipped ?
string(unzipFile(file)) : string(file);
string const format = getExtFromContents(file_);
- if (format != "eps" && format != "ps")
+
+ if (format != "eps" && format != "ps") {
+ readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
return string();
+ }
std::ifstream is(file_.c_str());
while (is) {
string s;
getline(is,s);
- if (contains(s,"%%BoundingBox:") && !contains(s,"atend"))
- return (frontStrip(s.substr(14)));
+ if (contains(s,"%%BoundingBox:") && !contains(s,"atend")) {
+ string const bb = frontStrip(s.substr(14));
+ readBB_lyxerrMessage(file_, zipped, bb);
+ return bb;
+ }
}
+ readBB_lyxerrMessage(file_, zipped, "no bb found");
return string();
}