+2002-01-30 Herbert Voss <voss@lyx.org>
+
+ * configure.m4: add convert-support for ps-files
+
2002-01-29 Herbert Voss <voss@lyx.org>
* ui/default.ui: delete old figure entries
eps_to_xpm="convert EPS:\$\$i XPM:\$\$o"
jpg_to_xpm="convert JPG:\$\$i XPM:\$\$o"
png_to_xpm="convert PNG:\$\$i XPM:\$\$o"
+ ps_to_xpm="convert PS:\$\$i XPM:\$\$o"
fi
SEARCH_PROG([For an EPS -> PDF converter], EPSTOPDF, epstopdf)
+2002-01-30 Herbert Voss <voss@lyx.org>
+
+ * ControlGraphic.[C]: do not search the whole file, when
+ getting the bb
+
2002-01-29 Herbert Voss <voss@lyx.org>
* ControlGraphic.[C]: added a button for document path
using std::pair;
using std::make_pair;
-
using std::ifstream;
ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
// to check a bit more.
// ControlGraphics::bbChanged = false;
std::ifstream is(file.c_str());
- while (is) {
+ int count = 0;
+ int const max_count = 50; // don't search the whole file
+ while (is && (++count < max_count)) {
string s;
is >> s;
if (contains(s,"%%BoundingBox:")) {
+2002-01-31 Herbert Voss <voss@lyx.org>
+
+ * GraphicsCacheItem.h: handle filetype without the file extension;
+ getting type from contents; handle zipped files
+
2002-01-27 Herbert Voss <voss@lyx.org>
* GraphicsCacheItem.h: added Converting to the ImageStatus enum.
* Copyright 1995 Matthias Ettrich.
* Copyright 1995-2001 The LyX Team.
*
- * This file Copyright 2000 Baruch Even
+ * \author Baruch Even
+ * \author Herbert Voss <voss@lyx.org>
* ================================================= */
#include <config.h>
#include "debug.h"
#include "support/LAssert.h"
#include "gettext.h"
+#include "support/syscall.h"
+#include "lyxfunc.h"
using std::endl;
GraphicsCacheItem::getImage() const { return image_.get(); }
-void
-GraphicsCacheItem::imageConverted(bool success)
+void GraphicsCacheItem::imageConverted(bool success)
{
// Debug output
string text = "succeeded";
if (converters.isReachable(from, *iter))
break;
}
-
if (iter == end) {
// We do not know how to convert the image to something loadable.
lyxerr << "ERROR: Do not know how to convert image." << std::endl;
return string();
}
-
return (*iter);
}
} // anon namespace
-bool
-GraphicsCacheItem::convertImage(string const & filename)
+bool GraphicsCacheItem::convertImage(string const & filename)
{
- string const from = GetExtension(filename);
+ setStatus(GraphicsCacheItem::Converting);
+ string filename_ = string(filename);
+ lyxerr << "try to convert image file: " << filename_ << endl;
+// maybe that other zip extensions also be useful, especially the
+// ones that may be declared in texmf/tex/latex/config/graphics.cfg.
+// for example:
+/* -----------snip-------------
+ {\DeclareGraphicsRule{.pz}{eps}{.bb}{}%
+ \DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{}%
+ \DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{}%
+ \DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{}%
+ \DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{}}}%
+ -----------snip-------------*/
+
+ lyxerr << "GetExtension: " << GetExtension(filename_) << endl;
+ bool zipped = GetExtension(filename_).compare("gz") == 0;
+ if (zipped)
+ filename_ = ChangeExtension(filename_, string()); // snip the ".gz"
+ string const from = getExtFromContents(filename_); // get the type
+ lyxerr << "GetExtFromContents: " << from << endl;
string const to = findTargetFormat(from);
+ lyxerr << "from: " << from << " -> " << to << endl;
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
// the "to" file after loading when it's the same as the "from"!
- tempfile = filename;
+ tempfile = filename_;
loadImage();
return true;
}
-
// Take only the filename part of the file, without path or extension.
- string temp = OnlyFilename(filename);
- temp = ChangeExtension(filename, string());
+ string temp = OnlyFilename(filename_);
+ temp = ChangeExtension(filename_, string());
// Add some stuff to have it a unique temp file.
// This tempfile is deleted in loadImage after it is loaded to memory.
tempfile = lyx::tempName(string(), temp);
// Remove the temp file, we only want the name...
lyx::unlink(tempfile);
-
- bool result = converters.convert(0, filename, tempfile, from, to);
+ bool result = converters.convert(0, filename_, tempfile, from, to);
tempfile.append(".xpm");
-
// For now we are synchronous
imageConverted(result);
-
// Cleanup after the conversion.
lyx::unlink(tempfile);
+ if (zipped)
+ lyx::unlink(filename_);
tempfile = string();
-
return true;
}
+2002-01-30 Herbert Voss <voss@lyx.org>
+
+ * insetgraphic.C: get the filetyp from it's contents
+ * insetgraphicparams.C: add token scale and lyxrc.display when
+ creating a new inset
+
2002-01-30 Angus Leeming <a.leeming@ic.ac.uk>
* figinset.C: added using std::ios directive.
* Image format
* from to
* EPS epstopdf
+ * PS ps2pdf
* JPG/PNG direct
* PDF direct
* others PNG
}
-string const
-InsetGraphics::statusMessage() const
+string const InsetGraphics::statusMessage() const
{
string msg;
if (cacheHandle.get()) {
paint.image(old_x + 2, baseline - lascent,
lwidth - 4, lascent + ldescent,
cacheHandle->getImage());
- } else {
-
+ } else {
// Get the image status, default to unknown error.
GraphicsCacheItem::ImageStatus status = GraphicsCacheItem::UnknownError;
- if (lyxrc.display_graphics != "no" && lyxrc.use_gui
- && params.display != InsetGraphicsParams::NONE &&
+ if (lyxrc.use_gui && params.display != InsetGraphicsParams::NONE &&
cacheHandle.get())
status = cacheHandle->getImageStatus();
-
// Check if the image is now ready.
if (status == GraphicsCacheItem::Loaded) {
imageLoaded = true;
-
// Tell BufferView we need to be updated!
bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
return;
}
-
paint.rectangle(old_x + 2, baseline - lascent,
lwidth - 4,
lascent + ldescent);
-
// Print the file name.
LyXFont msgFont(font);
msgFont.setFamily(LyXFont::SANS_FAMILY);
-
string const justname = OnlyFilename (params.filename);
if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
baseline - lyxfont::maxAscent(msgFont) - 4,
justname, msgFont);
}
-
// Print the message.
string const msg = statusMessage();
if (!msg.empty()) {
}
namespace {
-
-enum FileType {
- EPS,
- PNG,
- JPEG,
- GIF,
- PDF,
- UNKNOWN
-};
-
-bool isEPS(string const & filename)
-{
- if (filename.empty() || !IsFileReadable(filename)) return false;
-
- ifstream ifs(filename.c_str());
-
- if (!ifs) return false; // Couldn't open file...
-
- bool is_eps = false; // Have we recognized the file as EPS?
- string to_find = "%!PS-Adobe-"; // The string we use to recognize
- int const max_attempts = 500; // Maximum strings to read to attempt recognition
- int count = 0; // Counter of attempts.
- string str;
- for (; count < max_attempts; ++count) {
- if (ifs.eof()) {
- lyxerr[Debug::INFO] << "InsetGraphics (isEPS)"
- " End of file reached and it wasn't found to be EPS!" << endl;
- break;
- }
-
- ifs >> str;
- if (str.find(to_find)) {
- is_eps = true;
- break;
- }
- }
-
- return is_eps;
-}
-
-enum FileType classifyFileType(string const & filename, string const & suffix)
-{
- if (suffix == "png")
- return PNG;
- else if (suffix == "jpg" || suffix == "jpeg")
- return JPEG;
- else if (suffix == "gif")
- return GIF;
- else if (suffix == "pdf")
- return PDF;
- else if (isEPS(filename))
- return EPS;
-
- return UNKNOWN;
-}
-
-string decideOutputImageFormat(string const & suffix, enum FileType type)
+string decideOutputImageFormat(string const & suffix)
{
// lyxrc.pdf_mode means:
// Are we creating a PDF or a PS file?
// (Should actually mean, are we using latex or pdflatex).
+ lyxerr << "decideOutput::lyxrc.pdf_mode = " << lyxrc.pdf_mode << "\n";
if (lyxrc.pdf_mode) {
- if (type == EPS || type == EPS || type == PDF)
+ if (contains(suffix,"ps") || suffix == "pdf")
return "pdf";
- else if (type == JPEG)
+ else if (suffix == "jpg")
return suffix;
else
return "png";
}
-
// If it's postscript, we always do eps.
- // There are many suffixes that are actually EPS (ask Garst for example)
- // so we detect if it's an EPS by looking in the file, if it is, we return
- // the same suffix of the file so it won't be converted.
- if (type == EPS)
- return suffix;
-
- return "eps";
+ lyxerr << "decideOutput: we have PostScript mode\n";
+ if (suffix != "ps")
+ return "eps";
+ else
+ return "ps";
}
} // Anon. namespace
// do_convert = Do we need to convert the file?
// nice = Do we create a nice version?
// This is used when exporting the latex file only.
- //
// if (!do_convert)
// return original filename
- //
// if (!nice)
// convert_place = temp directory
// return new filename in temp directory
// convert_place = original file directory
// return original filename without the extension
//
-
// Get the extension (format) of the original file.
- string const extension = GetExtension(params.filename);
- FileType type = classifyFileType(params.filename, extension);
-
+ // 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).
- string const image_target = decideOutputImageFormat(extension, type);
-
+ string const image_target = decideOutputImageFormat(extension);
if (extension == image_target)
return params.filename;
-
string outfile;
if (!buf->niceFile) {
string const temp = AddName(buf->tmppath, params.filename);
+ lyxerr << "temp = " << temp << "\n";
outfile = RemoveExtension(temp);
-
- //lyxerr << "buf::tmppath = " << buf->tmppath << "\n";
- //lyxerr << "filename = " << params.filename << "\n";
- //lyxerr << "temp = " << temp << "\n";
- //lyxerr << "outfile = " << outfile << endl;
} else {
string const path = buf->filePath();
string const relname = MakeRelPath(params.filename, path);
outfile = RemoveExtension(relname);
}
+ lyxerr << "buf::tmppath = " << buf->tmppath << "\n";
+ lyxerr << "filename = " << params.filename << "\n";
+ lyxerr << "outfile = " << outfile << endl;
converters.convert(buf, params.filename, outfile, extension, image_target);
return outfile;
}
}
-int InsetGraphics::ascii(Buffer const *, ostream &, int) const
+int InsetGraphics::ascii(Buffer const *, ostream & os, int) const
{
// No graphics in ascii output. Possible to use gifscii to convert
// images to ascii approximation.
-
// 1. Convert file to ascii using gifscii
// 2. Read ascii output file and add it to the output stream.
-
+ // at least we send the filename
+ os << '<' << _("Graphicfile:") << params.filename << ">\n";
return 0;
}
// We do it this way so that in the face of some error, we will still
// be in a valid state.
if (!params.filename.empty() && lyxrc.use_gui
- && lyxrc.display_graphics != "no"
&& params.display != InsetGraphicsParams::NONE) {
temp = gc.addFile(params.filename);
}
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/LOstream.h"
+#include "lyxrc.h"
#include "support/LAssert.h"
bb = string(); // bounding box
draft = false; // draft mode
clip = false; // clip image
- display = MONOCHROME; // LyX-View
+ if (lyxrc.display_graphics == "mono")
+ display = MONOCHROME;
+ else if (lyxrc.display_graphics == "gray")
+ display = GRAYSCALE;
+ else if (lyxrc.display_graphics == "color")
+ display = COLOR;
+ else
+ display = NONE;
subcaption = false; // subfigure
width = LyXLength(); // set to 0pt
height = LyXLength();
lyxwidth = LyXLength(); // for the view in lyx
lyxheight = LyXLength();
scale = 0;
- size_type = DEFAULT_SIZE;
- keepAspectRatio = false;
- rotateOrigin = string(); //
+ size_type = DEFAULT_SIZE; // do nothing
+ keepAspectRatio = false; //
+ rotateOrigin = "center"; //
rotateAngle = 0.0; // in degrees
special = string(); // userdefined stuff
size_type = WH;
} else if (token == "keepAspectRatio") {
keepAspectRatio = true;
+ } else if (token == "scale") {
+ lex.next();
+ scale = lex.getInteger();
} else if (token == "rotateAngle") {
lex.next();
rotateAngle = lex.getFloat();
+2002-01-31 Herbert Voss <voss@perce.de>
+
+ * filetools.[Ch]: add getExtFromContents(), which returns
+ the type of the (graphic) file
+
2002-01-30 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* copy.C (copy): open file in binary mode (for cygwin)
extern string build_lyxdir;
extern string user_lyxdir;
extern string system_tempdir;
+extern string system_packageList;
bool IsLyXFilename(string const & filename)
do {
tmppath = split(tmppath, path_element, ';');
} while (!tmppath.empty() && path_element.empty());
+ tmppath = split(tmppath, path_element, ';');
} else {
notfound = false;
}
return string();
}
+// the different filetypes and what they contain in one of the first lines
+// (dots are any characters). (Herbert 20020131)
+// EPS %!PS-Adobe-3.0 EPSF...
+// GIF GIF...
+// JPG JFIF
+// PDF %PDF-...
+// PNG .PNG...
+// PS %!PS-Adobe-2.0
+// XBM static char ...
+// XPM /* XPM */
+/// return the "extension" which belongs to the contents
+string const getExtFromContents(string const & filename) {
+ if (filename.empty() || !IsFileReadable(filename))
+ return string(); // paranoia check
+ ifstream ifs(filename.c_str());
+ if (!ifs)
+ return string(); // Couldn't open file...
+ int const max_count = 50; // Maximum strings to read to attempt recognition
+ int count = 0; // Counter of attempts.
+ string str;
+ for (; count < max_count; ++count) {
+ if (ifs.eof()) {
+ lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)"
+ " End of file reached and it wasn't found to be a known Type!" << endl;
+ break;
+ }
+ ifs >> str;
+ if (contains(str,"EPSF"))
+ return "eps";
+ else if (contains(str,"GIF"))
+ return "gif";
+ else if (contains(str,"JFIF"))
+ return "jpg";
+ else if (contains(str,"%PDF"))
+ 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"))
+ return "xbm";
+ else if (contains(str,"XPM"))
+ return "xpm";
+ }
+ lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)"
+ " Couldn't find a known Type!" << endl;
+ return string();
+}
+
// Creates a nice compact path for displaying
string const
}
}
}
+
/// Return the extension of the file (not including the .)
string const GetExtension(string const & name);
+/// Return the type of the file as an extension from contents
+///
+string const getExtFromContents(string const & name);
+
/// Returns true is path is absolute
bool AbsolutePath(string const & path);
/// remove the autosave-file and give a Message if it can't be done
void removeAutosaveFile(string const & filename);
+
#endif