the next patch to get the file type from it's contents. Especially to Garst, please try.
Herbert -- http://www.lyx.org/help/
Index: src/frontends/controllers/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v retrieving revision 1.128 diff -u -r1.128 ChangeLog --- src/frontends/controllers/ChangeLog 2002/01/30 19:14:09 1.128 +++ src/frontends/controllers/ChangeLog 2002/01/30 20:04:03 @@ -1,3 +1,8 @@ +2002-01-30 Herbert Voss <[EMAIL PROTECTED]> + + * ControlGraphic.[C]: do not search the whole file, when + getting the bb + 2002-01-29 Herbert Voss <[EMAIL PROTECTED]> * ControlGraphic.[C]: added a button for document path Index: src/frontends/controllers/ControlGraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlGraphics.C,v retrieving revision 1.16 diff -u -r1.16 ControlGraphics.C --- src/frontends/controllers/ControlGraphics.C 2002/01/30 19:14:09 1.16 +++ src/frontends/controllers/ControlGraphics.C 2002/01/30 20:04:04 @@ -40,7 +40,6 @@ using std::pair; using std::make_pair; - using std::ifstream; ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d) @@ -107,7 +106,9 @@ // 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:")) { Index: src/insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.299 diff -u -r1.299 ChangeLog --- src/insets/ChangeLog 2002/01/30 18:16:12 1.299 +++ src/insets/ChangeLog 2002/01/30 20:04:06 @@ -1,3 +1,9 @@ +2002-01-30 Herbert Voss <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> * figinset.C: added using std::ios directive. Index: src/insets/insetgraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.68 diff -u -r1.68 insetgraphics.C --- src/insets/insetgraphics.C 2002/01/29 09:26:24 1.68 +++ src/insets/insetgraphics.C 2002/01/30 20:04:06 @@ -81,6 +81,7 @@ * Image format * from to * EPS epstopdf + * PS ps2pdf * JPG/PNG direct * PDF direct * others PNG @@ -161,8 +162,7 @@ } -string const -InsetGraphics::statusMessage() const +string const InsetGraphics::statusMessage() const { string msg; if (cacheHandle.get()) { @@ -258,32 +258,25 @@ 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); @@ -291,7 +284,6 @@ baseline - lyxfont::maxAscent(msgFont) - 4, justname, msgFont); } - // Print the message. string const msg = statusMessage(); if (!msg.empty()) { @@ -500,57 +492,53 @@ namespace { enum FileType { - EPS, - PNG, - JPEG, - GIF, - PDF, +// the different filetypes and what they contain in one of the first lines +// (dots are any characters) + EPS, // EPS %!PS-Adobe-3.0 EPSF... + GIF, // GIF GIF... + JPEG, // JPG JFIF + PDF, // PDF %PDF-... + PNG, // PNG .PNG... + PS, // PS %!PS-Adobe-2.0 + XBM, // XBM static char ... + XPM, // XPM /* XPM */ UNKNOWN }; -bool isEPS(string const & filename) +enum FileType classifyFileType(string const & filename) { - if (filename.empty() || !IsFileReadable(filename)) return false; - + if (filename.empty() || !IsFileReadable(filename)) return UNKNOWN; 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 + if (!ifs) return UNKNOWN; // 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_attempts; ++count) { + for (; count < max_count; ++count) { if (ifs.eof()) { - lyxerr[Debug::INFO] << "InsetGraphics (isEPS)" - " End of file reached and it wasn't found to be EPS!" << endl; + lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)" + " End of file reached and it wasn't found to be a +known Type!" << endl; break; } - ifs >> str; - if (str.find(to_find)) { - is_eps = true; - break; - } + if (contains(str,"EPSF")) + return EPS; + else if (contains(str,"GIF")) + return GIF; + else if (contains(str,"JFIF")) + return JPEG; + 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; } - - 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; - + lyxerr[Debug::INFO] << "InsetGraphics (classifyFiletype)" + " Couldn't find a known Type!" << endl; return UNKNOWN; } @@ -559,22 +547,22 @@ // 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 (type == EPS || type == PS || type == PDF) return "pdf"; else if (type == JPEG) 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. + lyxerr << "decideOutput: we have PostScript mode\n"; if (type == EPS) return suffix; - return "eps"; } @@ -585,10 +573,8 @@ // 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 @@ -596,32 +582,28 @@ // 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); - + FileType type = classifyFileType(params.filename); + lyxerr << "prepareFile::type = " << type << "\n"; // 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); - 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; } @@ -665,14 +647,14 @@ } -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; } @@ -728,7 +710,6 @@ // 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); } Index: src/insets/insetgraphicsParams.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.C,v retrieving revision 1.19 diff -u -r1.19 insetgraphicsParams.C --- src/insets/insetgraphicsParams.C 2002/01/29 09:26:24 1.19 +++ src/insets/insetgraphicsParams.C 2002/01/30 20:04:06 @@ -22,6 +22,7 @@ #include "support/filetools.h" #include "support/lyxlib.h" #include "support/LOstream.h" +#include "lyxrc.h" #include "support/LAssert.h" @@ -98,16 +99,23 @@ 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 @@ -298,6 +306,9 @@ 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();