X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetgraphics.C;h=b4f7f7cd5ea4255c4f5d571a557725c3b0ba559f;hb=b922cdd796f9e4b9a46a79808cdee596e04903eb;hp=7630dc4a139e9146949fdc287837bf301d0b5ff7;hpb=2e5de574e172417d1a530414d5bb438ea6aa98ed;p=lyx.git diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 7630dc4a13..b4f7f7cd5e 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -28,10 +28,7 @@ Known BUGS: We should probably use what the user asks to use... but when he chooses by the file dialog we normally get an absolute path and this may not be what the user meant. - * Bug in FileDlg class (src/filedlg.[hC]) when selecting a file and then - pressing ok, it counts as if no real selection done. Apparently - when choosing a file it doesn't update the select file input line. - + * If we are trying to create a file in a read-only directory and there are graphics that need converting, the converting will fail because it is done in-place, into the same directory as the original image. @@ -168,6 +165,7 @@ using std::endl; // This function is a utility function +// ... that should be with ChangeExtension ... inline string const RemoveExtension(string const & filename) { @@ -256,11 +254,23 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const if (cacheHandle.get() && (pixmap = cacheHandle->getImage())) return pixmap->getWidth(); else { - string const msg = statusMessage(); int font_width = 0; - - if (!msg.empty()) - font_width = lyxfont::width(msg, font); + + LyXFont msgFont(font); + msgFont.setFamily(LyXFont::SANS_FAMILY); + + string const justname = OnlyFilename (params.filename); + if (!justname.empty()) { + msgFont.setSize(LyXFont::SIZE_FOOTNOTE); + font_width = lyxfont::width(justname, msgFont); + } + + string const msg = statusMessage(); + if (!msg.empty()) { + msgFont.setSize(LyXFont::SIZE_TINY); + int const msg_width = lyxfont::width(msg, msgFont); + font_width = std::max(font_width, msg_width); + } return std::max(50, font_width + 15); } @@ -291,7 +301,9 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, // Get the image status, default to unknown error. GraphicsCacheItem::ImageStatus status = GraphicsCacheItem::UnknownError; - if (cacheHandle.get()) + if (lyxrc.display_graphics != "no" && + params.display != InsetGraphicsParams::NONE && + cacheHandle.get()) status = cacheHandle->getImageStatus(); // Check if the image is now ready. @@ -303,22 +315,25 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, return; } - paint.rectangle(old_x + 2, baseline - lascent, lwidth - 4, lascent + ldescent); - string const msg = statusMessage(); - if (!msg.empty()) { - // Print the message. - LyXFont msgFont(font); - msgFont.setFamily(LyXFont::SANS_FAMILY); + // 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); - string const justname = OnlyFilename (params.filename); paint.text(old_x + 8, - baseline - lyxfont::maxAscent(msgFont) - 4, - justname, msgFont); + baseline - lyxfont::maxAscent(msgFont) - 4, + justname, msgFont); + } + // Print the message. + string const msg = statusMessage(); + if (!msg.empty()) { msgFont.setSize(LyXFont::SIZE_TINY); paint.text(old_x + 8, baseline - 4, msg, msgFont); } @@ -354,7 +369,7 @@ void InsetGraphics::write(Buffer const * buf, ostream & os) const void InsetGraphics::read(Buffer const * buf, LyXLex & lex) { - string const token = lex.GetString(); + string const token = lex.getString(); if (token == "Graphics") readInsetGraphics(buf, lex); @@ -370,10 +385,10 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) { bool finished = false; - while (lex.IsOK() && !finished) { + while (lex.isOK() && !finished) { lex.next(); - string const token = lex.GetString(); + string const token = lex.getString(); lyxerr[Debug::INFO] << "Token: '" << token << '\'' << std::endl; @@ -383,7 +398,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) finished = true; } else if (token == "FormatVersion") { lex.next(); - int version = lex.GetInteger(); + int version = lex.getInteger(); if (version > 1) lyxerr << "This document was created with a newer Graphics widget" @@ -405,10 +420,10 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) { bool finished = false; - while (lex.IsOK() && !finished) { + while (lex.isOK() && !finished) { lex.next(); - string const token = lex.GetString(); + string const token = lex.getString(); lyxerr[Debug::INFO] << "Token: " << token << endl; if (token.empty()) @@ -417,7 +432,7 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) finished = true; } else if (token == "file") { if (lex.next()) { - string const name = lex.GetString(); + string const name = lex.getString(); string const path = OnlyPath(buf->fileName()); params.filename = MakeAbsPath(name, path); } @@ -425,25 +440,27 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) if (lex.next()); // kept for backwards compability. Delete in 0.13.x } else if (token == "subcaption") { - if (lex.EatLine()) - params.subcaptionText = lex.GetString(); + if (lex.eatLine()) + params.subcaptionText = lex.getString(); } else if (token == "label") { if (lex.next()); // kept for backwards compability. Delete in 0.13.x } else if (token == "angle") { if (lex.next()) - params.rotateAngle = lex.GetFloat(); + params.rotateAngle = lex.getFloat(); } else if (token == "size") { // Size of image on screen is ignored in InsetGraphics, just eat // the input. - if (lex.next()) - lex.GetInteger(); - if (lex.next()) - lex.GetInteger(); + if (lex.next()) { + lex.getInteger(); + } + if (lex.next()) { + lex.getInteger(); + } } else if (token == "flags") { InsetGraphicsParams::DisplayType tmp = InsetGraphicsParams::COLOR; if (lex.next()) - switch (lex.GetInteger()) { + switch (lex.getInteger()) { case 1: tmp = InsetGraphicsParams::MONOCHROME; break; case 2: tmp = InsetGraphicsParams::GRAYSCALE; break; } @@ -451,15 +468,19 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) } else if (token == "subfigure") { params.subcaption = true; } else if (token == "width") { - if (lex.next()) - params.widthResize = static_cast(lex.GetInteger()); - if (lex.next()) - params.widthSize = lex.GetFloat(); + if (lex.next()) { + params.widthResize = static_cast(lex.getInteger()); + } + if (lex.next()) { + params.widthSize = lex.getFloat(); + } } else if (token == "height") { - if (lex.next()) - params.heightResize = static_cast(lex.GetInteger()); - if (lex.next()) - params.heightSize = lex.GetFloat(); + if (lex.next()) { + params.heightResize = static_cast(lex.getInteger()); + } + if (lex.next()) { + params.heightSize = lex.getFloat(); + } } } } @@ -491,7 +512,7 @@ void formatResize(ostream & os, string const & key, break; case InsetGraphicsParams::SCALE: - os << "scale" << '=' << size << ','; + os << "scale" << '=' << size/100 << ','; } } @@ -511,7 +532,7 @@ InsetGraphics::createLatexOptions() const // 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)) { + if (!lyx::float_equal(params.rotateAngle, 0, 0.001)) { options << "angle=" << params.rotateAngle << ','; } @@ -740,7 +761,7 @@ 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 * buf, ostream & os) const { // Change the path to be relative to the main file. string const buffer_dir = OnlyPath(buf->fileName()); @@ -761,10 +782,10 @@ void InsetGraphics::validate(LaTeXFeatures & features) const if (params.filename.empty()) return ; - features.graphicx = true; + features.require("graphicx"); if (params.subcaption) - features.subfigure = true; + features.require("subfigure"); } @@ -777,7 +798,9 @@ void InsetGraphics::updateInset() const // 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()) { + if (!params.filename.empty() && + lyxrc.display_graphics != "no" && + params.display != InsetGraphicsParams::NONE) { temp = gc.addFile(params.filename); }