X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetgraphics.C;h=1dc04a8530c0eea9948d5443e3762bdede8630ab;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=c5a679d0050673adf4cd89ec072dedd886ef7139;hpb=af7a06dd86fe9d1481629ca43eb24824eecd3c7e;p=lyx.git diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index c5a679d005..1dc04a8530 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -91,36 +91,44 @@ TODO Before initial production release: #include "insets/insetgraphics.h" #include "insets/insetgraphicsParams.h" + #include "graphics/GraphicsCache.h" #include "graphics/GraphicsCacheItem.h" -#include "frontends/Dialogs.h" -#include "frontends/Alert.h" #include "LyXView.h" #include "buffer.h" #include "BufferView.h" #include "converter.h" -#include "frontends/support/LyXImage.h" #include "Painter.h" #include "lyx_gui_misc.h" -#include "support/FileInfo.h" -#include "support/filetools.h" -#include "frontends/controllers/helper_funcs.h" -#include "support/lyxlib.h" #include "lyxtext.h" #include "lyxrc.h" -#include "font.h" // For the lyxfont class. -#include "fstream" // for ifstream in isEPS -#include // For the std::max -#include "support/lyxmanip.h" +#include "font.h" #include "debug.h" #include "gettext.h" +#include "frontends/Dialogs.h" +#include "frontends/Alert.h" +#include "frontends/controllers/helper_funcs.h" +#include "frontends/support/LyXImage.h" + +#include "support/FileInfo.h" +#include "support/filetools.h" +#include "support/lyxlib.h" +#include "support/lyxmanip.h" +#include "support/lyxalgo.h" + +#include +#include + extern string system_tempdir; using std::ifstream; using std::ostream; using std::endl; +using std::max; +using std::vector; + /////////////////////////////////////////////////////////////////////////// int const VersionNumber = 1; @@ -135,9 +143,25 @@ string const RemoveExtension(string const & filename) } +namespace { + +string const unique_id() +{ + static unsigned int seed = 1000; + + ostringstream ost; + ost << "graph" << ++seed; + + // Needed if we use lyxstring. + return ost.str().c_str(); +} + +} // namespace anon + + // Initialize only those variables that do not have a constructor. InsetGraphics::InsetGraphics() - : cacheHandle(0), imageLoaded(false) + : cacheHandle(0), imageLoaded(false), graphic_label(unique_id()) {} @@ -145,6 +169,7 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig, bool same_id) : Inset(), SigC::Object() , cacheHandle(ig.cacheHandle) , imageLoaded(ig.imageLoaded) + , graphic_label(unique_id()) { setParams(ig.getParams()); if (same_id) @@ -227,10 +252,10 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const if (!msg.empty()) { msgFont.setSize(LyXFont::SIZE_TINY); int const msg_width = lyxfont::width(msg, msgFont); - font_width = std::max(font_width, msg_width); + font_width = max(font_width, msg_width); } - return std::max(50, font_width + 15); + return max(50, font_width + 15); } } @@ -339,7 +364,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); lyxerr[Debug::INFO] << "Token: '" << token << '\'' - << std::endl; + << endl; if (token.empty()) { continue; @@ -353,13 +378,13 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) << "This document was created with a newer Graphics widget" ", You should use a newer version of LyX to read this" " file." - << std::endl; + << endl; // TODO: Possibly open up a dialog? } else { if (! params.Read(buf, lex, token)) lyxerr << "Unknown token, " << token << ", skipping." - << std::endl; + << endl; } } } @@ -367,7 +392,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) // FormatVersion < 1.0 (LyX < 1.2) void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) { - std::vector const oldUnits = + vector const oldUnits = getVectorFromString("pt,cm,in,p%,c%"); bool finished = false; // set the display default @@ -501,7 +526,7 @@ 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"; + lyxerr[Debug::INFO] << "decideOutput::lyxrc.pdf_mode = " << lyxrc.pdf_mode << "\n"; if (lyxrc.pdf_mode) { if (contains(suffix,"ps") || suffix == "pdf") return "pdf"; @@ -511,7 +536,7 @@ string decideOutputImageFormat(string const & suffix) return "png"; } // If it's postscript, we always do eps. - lyxerr << "decideOutput: we have PostScript mode\n"; + lyxerr[Debug::INFO] << "decideOutput: we have PostScript mode\n"; if (suffix != "ps") return "eps"; else @@ -534,11 +559,9 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const // convert_place = original file directory // return original filename without the extension // - // first check if file is viewed in LyX. First local - // than global // if it's a zipped one, than let LaTeX do the rest!!! if ((zippedFile(params.filename) && params.noUnzip) || buf->niceFile) { - lyxerr << "don't unzip file or export latex" + lyxerr[Debug::INFO] << "don't unzip file or export latex" << params.filename << endl; return params.filename; } @@ -554,18 +577,19 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const string const image_target = decideOutputImageFormat(extension); if (extension == image_target) // :-) return filename_; - if (!IsFileReadable(filename_)) { // :-( - Alert::alert(_("File") + params.filename, - _("isn't readable or doesn't exists!")); - return filename_; - } +// commented out to check if the "not exist"bug is fixed. +// if (!IsFileReadable(filename_)) { // :-( +// Alert::alert(_("File") + params.filename, +// _("isn't readable or doesn't exists!")); +// return filename_; +// } string outfile; string const temp = AddName(buf->tmppath, filename_); outfile = RemoveExtension(temp); - lyxerr << "tempname = " << temp << "\n"; - lyxerr << "buf::tmppath = " << buf->tmppath << "\n"; - lyxerr << "filename_ = " << filename_ << "\n"; - lyxerr << "outfile = " << outfile << endl; + lyxerr[Debug::INFO] << "tempname = " << temp << "\n"; + lyxerr[Debug::INFO] << "buf::tmppath = " << buf->tmppath << "\n"; + lyxerr[Debug::INFO] << "filename_ = " << filename_ << "\n"; + lyxerr[Debug::INFO] << "outfile = " << outfile << endl; converters.convert(buf, filename_, outfile, extension, image_target); return outfile; } @@ -581,31 +605,32 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os, << _("empty figure path") << "}\n"; return 1; // One end of line marker added to the stream. } - // Keep count of newlines that we issued. -#warning the newlines=0 were in the original code. where is the sense? (Herbert) - int newlines = 0; - // This variables collect all the latex code that should be before and + // These variables collect all the latex code that should be before and // after the actual includegraphics command. string before; string after; // Do we want subcaptions? if (params.subcaption) { before += "\\subfigure[" + params.subcaptionText + "]{"; - after = '}' + after; + after = '}'; } // We never use the starred form, we use the "clip" option instead. - os << before << "\\includegraphics"; + before += "\\includegraphics"; // Write the options if there are any. string const opts = createLatexOptions(); if (!opts.empty()) { - os << "[%\n" << opts << ']'; + before += ("[%\n" + opts +']'); } // Make the filename relative to the lyx file // and remove the extension so the LaTeX will use whatever is // appropriate (when there are several versions in different formats) - string const filename = prepareFile(buf); - os << '{' << filename << '}' << after; + string const latex_str = before + '{' + prepareFile(buf) + '}' + after; + os << latex_str; // Return how many newlines we issued. + int const newlines = + int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1); + // lyxerr << "includegraphics: " << newlines << " lines of text" + // << endl; return newlines; } @@ -632,20 +657,12 @@ int InsetGraphics::linuxdoc(Buffer const *, ostream &) const // For explanation on inserting graphics into DocBook checkout: // http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html // See also the docbook guide at http://www.docbook.org/ -int InsetGraphics::docbook(Buffer const * buf, ostream & os) const +int InsetGraphics::docbook(Buffer const *, ostream & os) const { - // Change the path to be relative to the main file. - string const buffer_dir = buf->filePath(); - string filename = RemoveExtension( - MakeRelPath(params.filename, buffer_dir)); - - if (suffixIs(filename, ".eps")) - filename.erase(filename.length() - 4); - // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will // need to switch to MediaObject. However, for now this is sufficient and // easier to use. - os << ""; + os << ""; return 0; } @@ -656,6 +673,8 @@ void InsetGraphics::validate(LaTeXFeatures & features) const if (params.filename.empty()) return ; + features.includeFile(graphic_label, RemoveExtension(params.filename)); + features.require("graphicx"); if (params.subcaption)