+2002-02-06 Herbert Voss <voss@lyx.org>
+
+ * ControlGraphics.[C] (readBB): search also in
+ g'zipped files. If it is useful than PK and compress
+ should also be supported. use unzipFile() from
+ support/filetools
+
2002-02-06 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* ControlRef.C (getBufferName): new method to get a real buffer
#include "helper_funcs.h" // for browseFile
#include "support/lstrings.h"
#include "support/filetools.h" // for AddName
+#include "support/syscall.h" // for zippedFile()
#include "BufferView.h"
using std::pair;
// end of the file. Than we have in the header a
// %%BoundingBox: (atend)
// In this case we must check until the end.
- std::ifstream is(file.c_str());
- if (!contains(getExtFromContents(file),"ps")) // bb exists?
+ string file_ = file;
+ if (zippedFile(file_))
+ file_ = unzipFile(file_);
+ std::ifstream is(file_.c_str());
+ if (!contains(getExtFromContents(file_),"ps")) // bb exists?
return string();
while (is) {
string s;
+2002-02-07 Herbert Voss <voss@lyx.org>
+
+ * GraphicsCacheItem.C: use unzipFile() from support/filetools
+
2002-01-31 Herbert Voss <voss@lyx.org>
* GraphicsCacheItem.h: handle filetype without the file extension;
#include "debug.h"
#include "support/LAssert.h"
#include "gettext.h"
-#include "support/syscall.h"
#include "lyxfunc.h"
using std::endl;
-----------snip-------------*/
lyxerr << "GetExtension: " << GetExtension(filename_) << endl;
- bool zipped = GetExtension(filename_).compare("gz") == 0;
+ bool const zipped = zippedFile(filename_);
if (zipped)
- filename_ = ChangeExtension(filename_, string()); // snip the ".gz"
+ filename_ = unzipFile(filename_);
string const from = getExtFromContents(filename_); // get the type
lyxerr << "GetExtFromContents: " << from << endl;
string const to = findTargetFormat(from);
if (to.empty())
return false;
// manage zipped files. unzip them first into the tempdir
- if (zipped) {
- tempfile = lyx::tempName(string(), filename_);
- // Run gunzip
- string const command = "gunzip -c "+filename+" > "+tempfile;
- Systemcalls one(Systemcalls::System, command);
- filename_ = tempfile;
- }
if (from == to) {
// No conversion needed!
// Saves more than just time: prevents the deletion of
+2002-02-06 Herbert Voss <voss@lyx.org>
+
+ * insetgraphic.C: prepareFile(): don't convert the file, when
+ it's not viewed in LyX. Saves a lot of time when opening a
+ document!
+
2002-02-05 Herbert Voss <voss@lyx.org>
* insetgraphic.C:
its original size and color, resizing is done in the final output,
but not in the LyX window.
- * EPS figures are not fully detected, they may have a lot of possible
- suffixes so we need to read the file and detect if it's EPS or not.
- [Implemented, need testing]
-
TODO Before initial production release:
* Replace insetfig everywhere
* Search for comments of the form
// before writing it to the output stream.
ostringstream options;
if (!params.bb.empty())
- options << " bb=" << strip(params.bb) << ",%\n";
+ options << " bb=" << strip(params.bb) << ",\n";
if (params.draft)
- options << " draft,%\n";
+ options << " draft,\n";
if (params.clip)
- options << " clip,%\n";
+ options << " clip,\n";
if (params.size_type == InsetGraphicsParams::WH) {
if (!params.width.zero())
- options << " width=" << params.width.asLatexString() << ",%\n";
+ options << " width=" << params.width.asLatexString() << ",\n";
if (!params.height.zero())
- options << " height=" << params.height.asLatexString() << ",%\n";
+ options << " height=" << params.height.asLatexString() << ",\n";
} else if (params.size_type == InsetGraphicsParams::SCALE) {
if (params.scale > 0)
- options << " scale=" << double(params.scale)/100.0 << ",%\n";
+ options << " scale=" << double(params.scale)/100.0 << ",\n";
}
if (params.keepAspectRatio)
- options << " keepaspectratio,%\n";
+ options << " keepaspectratio,\n";
// Make sure it's not very close to zero, a float can be effectively
// zero but not exactly zero.
if (!lyx::float_equal(params.rotateAngle, 0, 0.001) && params.rotate) {
- options << " angle=" << params.rotateAngle << ",%\n";
+ options << " angle=" << params.rotateAngle << ",\n";
if (!params.rotateOrigin.empty()) {
options << " origin=" << params.rotateOrigin[0];
if (contains(params.rotateOrigin,"Top"))
options << 'b';
else if (contains(params.rotateOrigin,"Baseline"))
options << 'B';
- options << ",%\n";
+ options << ",\n";
}
}
if (!params.special.empty())
- options << params.special << ",%\n";
+ options << params.special << ",\n";
string opts = options.str().c_str();
- opts = opts.substr(0,opts.size()-3); // delete last ",%\n"
- return opts;
+ return opts.substr(0,opts.size()-2); // delete last ",\n"
}
namespace {
// convert_place = original file directory
// return original filename without the extension
//
- // Get the extension (format) of the original file.
- // we handle it like a virtual one, so we can have
- // different extensions with the same type.
+ // first check if file is viewed in LyX. First local
+ // than global
+ if ((params.display == InsetGraphicsParams::NONE) ||
+ ((params.display == InsetGraphicsParams::DEFAULT) &&
+ (lyxrc.display_graphics == "no"))) {
+ lyxerr << "InsetGraphics::no converting of: " << params.filename << "\n";
+ return params.filename;
+ }
// if it's a zipped one, than let LaTeX do the rest!!!
- if (zippedFile(params.filename))
+ if (zippedFile(params.filename)) {
+ lyxerr << "InsetGraphics::prepareFilter(zippedFile): return "
+ << params.filename << endl;
return params.filename;
+ }
// now we have unzipped files
+ // Get the extension (format) of the original file.
+ // we handle it like a virtual one, so we can have
+ // different extensions with the same type.
string const extension = getExtFromContents(params.filename);
// Are we creating a PDF or a PS file?
// (Should actually mean, are we usind latex or pdflatex).
+2002-02-06 Herbert Voss <voss@perce.de>
+
+ * filetools.[Ch]: fix sume bugs for detecting zipped files
+ adding unzipFile()
+
2002-02-04 Herbert Voss <voss@perce.de>
* filetools.[Ch]: add ifZippedFile() for zipped
#include <cerrno>
#include "debug.h"
#include "support/lstrings.h"
+#include "support/syscall.h"
#include "filetools.h"
#include "LSubstring.h"
// JPG JFIF
// PDF %PDF-...
// PNG .PNG...
-// PS %!PS-Adobe-2.0
+// PS %!PS-Adobe-2.0 or 1.0, no "EPSF"!
// XBM ... static char ...
// XPM /* XPM */
//
-// GZIP \213\037\008\008... http://www.ietf.org/rfc/rfc1952.txt
+// GZIP \037\213\010\010... http://www.ietf.org/rfc/rfc1952.txt
// ZIP PK... http://www.halyava.ru/document/ind_arch.htm
-// Z \177\037 UNIX compress
+// Z \037\177 UNIX compress
/// return the "extension" which belongs to the contents
string const getExtFromContents(string const & filename) {
if (filename.empty() || !IsFileReadable(filename))
ifstream ifs(filename.c_str());
if (!ifs)
return string(); // Couldn't open file...
- string const gzipStamp = "\213\037\008\008"; // gnuzip
+ string const gzipStamp = "\037\213\010\010"; // gnuzip
string const zipStamp = "PK"; // PKZIP
- string const compressStamp = "\177\037"; // compress
- int const max_count = 50; // Maximum strings to read to attempt recognition
- int count = 0; // Counter of attempts.
+ string const compressStamp = "\037\177"; // compress
+ int const max_count = 50; // Maximum strings to read
+ int count = 0; // Counter of attempts.
string str;
bool zipChecked = false;
for (; count < max_count; ++count) {
if (ifs.eof()) {
- lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)"
+ lyxerr[Debug::INFO] << "filetools(getExtFromContents)"
" End of file reached and it wasn't found to be a known Type!" << endl;
break;
}
return "compress";
zipChecked = true;
}
- if (contains(str,"EPSF"))
- return "eps";
+ if (contains(str,"EPSF")) // dummy, if we have wrong file
+ return "eps"; // description like "%!PS-Adobe-2.0EPSF"
else if (contains(str,"GIF"))
return "gif";
else if (contains(str,"JFIF"))
return "pdf";
else if (contains(str,"PNG"))
return "png";
- else if (contains(str,"%!PS-Adobe-"))
- return "ps"; // eps here no more possible
- else if (contains(str,"static char"))
+ else if (contains(str,"%!PS-Adobe")) { // eps or ps
+ // test if it's ps or eps
+ ifs >> str;
+ if (contains(str,"EPSF"))
+ return "eps";
+ else
+ return "ps";
+ } else if (contains(str,"static char"))
return "xbm";
else if (contains(str,"XPM"))
return "xpm";
}
- lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)"
+ lyxerr[Debug::INFO] << "filetools(getExtFromContents)"
" Couldn't find a known Type!" << endl;
return string();
}
/// check for zipped file
bool zippedFile(string const & name) {
string const type = getExtFromContents(name);
- if (contains("gzip zip",type) && !type.empty())
+ if (contains("gzip zip compress",type) && !type.empty())
return true;
return false;
}
+string const unzipFile(string const & zipped_file)
+{
+ string const file = ChangeExtension(zipped_file, string());
+ string const tempfile = lyx::tempName(string(), file);
+ // Run gunzip
+ string const command = "gunzip -c "+file+" > "+tempfile;
+ Systemcalls one(Systemcalls::System, command);
+ // test that command was executed successfully
+ return tempfile;
+}
+
+
// Creates a nice compact path for displaying
string const
MakeDisplayPath (string const & path, unsigned int threshold)
/// check for zipped file
bool zippedFile(string const & name);
+/// unzip a file
+string const unzipFile(string const & zipped_file);
+
/// Returns true is path is absolute
bool AbsolutePath(string const & path);