X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetGraphics.cpp;h=b41d72bc70083d132742ee48ef3b851aeb576251;hb=83074c431c97f5447ddbfd8394c97c1118c93693;hp=c20f0314abd27ca559e244a2be56d4960fa32431;hpb=d5a5fbb8ee87d4a8ae1c55f9ba72819251bb6fb7;p=lyx.git diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index c20f0314ab..b41d72bc70 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -68,6 +68,7 @@ TODO #include "OutputParams.h" #include "output_xhtml.h" #include "sgml.h" +#include "texstream.h" #include "TocBackend.h" #include "frontends/alert.h" @@ -84,10 +85,9 @@ TODO #include "support/os.h" #include "support/Systemcall.h" -#include - #include #include +#include using namespace std; using namespace lyx::support; @@ -139,7 +139,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams) } -void readInsetGraphics(Lexer & lex, string const & bufpath, +void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin, InsetGraphicsParams & params) { bool finished = false; @@ -156,7 +156,7 @@ void readInsetGraphics(Lexer & lex, string const & bufpath, if (token == "\\end_inset") { finished = true; } else { - if (!params.Read(lex, token, bufpath)) + if (!params.Read(lex, token, buf, allowOrigin)) lyxerr << "Unknown token, " << token << ", skipping." @@ -299,7 +299,7 @@ void InsetGraphics::read(Lexer & lex) { lex.setContext("InsetGraphics::read"); //lex >> "Graphics"; - readInsetGraphics(lex, buffer().originFilePath(), params_); + readInsetGraphics(lex, buffer(), true, params_); graphic_->update(params().as_grfxParams()); } @@ -438,7 +438,7 @@ docstring InsetGraphics::createDocBookAttributes() const if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) { if (!float_equal(scl, 100.0, 0.05)) options << " scale=\"" - << static_cast( (scl) + 0.5 ) + << support::iround(scl) << "\" "; } else { if (!params().width.zero()) { @@ -595,8 +595,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const // we move it to a temp dir or uncompress it. FileName temp_file; GraphicsCopyStatus status; - boost::tie(status, temp_file) = - copyToDirIfNeeded(params().filename, temp_path); + tie(status, temp_file) = copyToDirIfNeeded(params().filename, temp_path); if (status == FAILURE) return orig_file; @@ -873,15 +872,13 @@ string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const if (params().filename.empty()) return string(); - string const orig_file = params().filename.absFileName(); + if (!params().filename.isReadableFile()) + return string(); // The master buffer. This is useful when there are multiple levels // of include files Buffer const * masterBuffer = buffer().masterBuffer(); - if (!params().filename.isReadableFile()) - return string(); - // We place all temporary files in the master buffer's temp dir. // This is possible because we use mangled file names. // FIXME We may want to put these files in some special temporary @@ -891,20 +888,21 @@ string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const // Copy to temporary directory. FileName temp_file; GraphicsCopyStatus status; - boost::tie(status, temp_file) = - copyToDirIfNeeded(params().filename, temp_path); + tie(status, temp_file) = copyToDirIfNeeded(params().filename, temp_path); if (status == FAILURE) return string(); - string output_file = onlyFileName(temp_file.absFileName()); - string const from = formats.getFormatFromFile(temp_file); - if (from.empty()) + if (from.empty()) { LYXERR(Debug::GRAPHICS, "\tCould not get file format."); + return string(); + } string const to = findTargetFormat(from, runparams); string const ext = formats.extension(to); + string const orig_file = params().filename.absFileName(); + string output_file = onlyFileName(temp_file.absFileName()); LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to); LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file); @@ -964,10 +962,20 @@ docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const // really be better to do width and height conversion, rather than to output // these parameters here. string imgstyle; - if (!params().width.zero()) - imgstyle += "width:" + params().width.asHTMLString() + ";"; - if (!params().height.zero()) - imgstyle += " height:" + params().height.asHTMLString() + ";"; + bool const havewidth = !params().width.zero(); + bool const haveheight = !params().height.zero(); + if (havewidth || haveheight) { + if (havewidth) + imgstyle += "width:" + params().width.asHTMLString() + ";"; + if (haveheight) + imgstyle += " height:" + params().height.asHTMLString() + ";"; + } else if (params().scale != "100") { + // Note that this will not have the same effect as in LaTeX export: + // There, the image will be scaled from its original size. Here, the + // percentage will be interpreted by the browser, and the image will + // be scaled to a percentage of the window size. + imgstyle = "width:" + params().scale + "%;"; + } if (!imgstyle.empty()) imgstyle = "style='" + imgstyle + "' "; @@ -1028,11 +1036,13 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p) const void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active, - UpdateType) const + UpdateType, TocBackend & backend) const { //FIXME UNICODE docstring const str = from_utf8(params_.filename.onlyFileName()); - buffer().tocBackend().toc("graphics")->push_back(TocItem(cpit, 0, str, output_active)); + TocBuilder & b = backend.builder("graphics"); + b.pushItem(cpit, str, output_active); + b.pop(); } @@ -1054,7 +1064,7 @@ void InsetGraphics::string2params(string const & in, Buffer const & buffer, lex.setContext("InsetGraphics::string2params"); lex >> "graphics"; params = InsetGraphicsParams(); - readInsetGraphics(lex, buffer.filePath(), params); + readInsetGraphics(lex, buffer, false, params); }