2 * \file insetgraphics.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 * What advanced features the users want to do?
16 Implement them in a non latex dependent way, but a logical way.
17 LyX should translate it to latex or any other fitting format.
18 * Add a way to roll the image file into the file format.
19 * When loading, if the image is not found in the expected place, try
20 to find it in the clipart, or in the same directory with the image.
21 * The image choosing dialog could show thumbnails of the image formats
22 it knows of, thus selection based on the image instead of based on
24 * Add support for the 'picins' package.
25 * Add support for the 'picinpar' package.
26 * Improve support for 'subfigure' - Allow to set the various options
32 * The filename is kept in the lyx file in a relative way, so as to allow
33 * moving the document file and its images with no problem.
37 * Postscript output means EPS figures.
39 * PDF output is best done with PDF figures if it's a direct conversion
40 * or PNG figures otherwise.
52 #include "insets/insetgraphics.h"
53 #include "insets/render_graphic.h"
56 #include "BufferView.h"
57 #include "converter.h"
60 #include "dispatchresult.h"
63 #include "funcrequest.h"
64 #include "FuncStatus.h"
66 #include "LaTeXFeatures.h"
68 #include "lyxlength.h"
70 #include "metricsinfo.h"
72 #include "outputparams.h"
75 #include "frontends/Alert.h"
76 #include "frontends/LyXView.h"
78 #include "support/convert.h"
79 #include "support/filetools.h"
80 #include "support/lyxalgo.h" // lyx::count
81 #include "support/lyxlib.h" // lyx::sum
82 #include "support/lstrings.h"
83 #include "support/os.h"
84 #include "support/systemcall.h"
86 #include <boost/bind.hpp>
87 #include <boost/tuple/tuple.hpp>
91 namespace support = lyx::support;
93 using lyx::support::AbsolutePath;
94 using lyx::support::bformat;
95 using lyx::support::ChangeExtension;
96 using lyx::support::compare_timestamps;
97 using lyx::support::contains;
98 using lyx::support::FileName;
99 using lyx::support::float_equal;
100 using lyx::support::GetExtension;
101 using lyx::support::IsFileReadable;
102 using lyx::support::latex_path;
103 using lyx::support::OnlyFilename;
104 using lyx::support::rtrim;
105 using lyx::support::subst;
106 using lyx::support::Systemcall;
107 using lyx::support::unzipFile;
108 using lyx::support::unzippedFileName;
110 namespace os = lyx::support::os;
115 using std::istringstream;
117 using std::ostringstream;
122 // This function is a utility function
123 // ... that should be with ChangeExtension ...
125 string const RemoveExtension(string const & filename)
127 return ChangeExtension(filename, string());
131 string findTargetFormat(string const & format, OutputParams const & runparams)
133 // Are we using latex or pdflatex?
134 if (runparams.flavor == OutputParams::PDFLATEX) {
135 lyxerr[Debug::GRAPHICS] << "findTargetFormat: PDF mode" << endl;
136 // Convert postscript to pdf
137 if (format == "eps" || format == "ps")
139 // pdflatex can use jpeg, png and pdf directly
140 if (format == "jpg" || format == "pdf")
142 // Convert everything else to png
145 // If it's postscript, we always do eps.
146 lyxerr[Debug::GRAPHICS] << "findTargetFormat: PostScript mode" << endl;
148 // any other than ps is changed to eps
157 InsetGraphics::InsetGraphics()
158 : graphic_label(sgml::uniqueID("graph")),
159 graphic_(new RenderGraphic(this))
163 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
165 boost::signals::trackable(),
166 graphic_label(sgml::uniqueID("graph")),
167 graphic_(new RenderGraphic(*ig.graphic_, this))
169 setParams(ig.params());
173 auto_ptr<InsetBase> InsetGraphics::doClone() const
175 return auto_ptr<InsetBase>(new InsetGraphics(*this));
179 InsetGraphics::~InsetGraphics()
181 InsetGraphicsMailer(*this).hideDialog();
185 void InsetGraphics::doDispatch(LCursor & cur, FuncRequest & cmd)
187 switch (cmd.action) {
188 case LFUN_GRAPHICS_EDIT: {
189 Buffer const & buffer = *cur.bv().buffer();
190 InsetGraphicsParams p;
191 InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
192 editGraphics(p, buffer);
196 case LFUN_INSET_MODIFY: {
197 Buffer const & buffer = cur.buffer();
198 InsetGraphicsParams p;
199 InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
200 if (!p.filename.empty()) {
207 case LFUN_INSET_DIALOG_UPDATE:
208 InsetGraphicsMailer(*this).updateDialog(&cur.bv());
211 case LFUN_MOUSE_RELEASE:
212 InsetGraphicsMailer(*this).showDialog(&cur.bv());
216 InsetBase::doDispatch(cur, cmd);
222 bool InsetGraphics::getStatus(LCursor & cur, FuncRequest const & cmd,
223 FuncStatus & flag) const
225 switch (cmd.action) {
226 case LFUN_GRAPHICS_EDIT:
227 case LFUN_INSET_MODIFY:
228 case LFUN_INSET_DIALOG_UPDATE:
233 return InsetBase::getStatus(cur, cmd, flag);
238 void InsetGraphics::edit(LCursor & cur, bool)
240 InsetGraphicsMailer(*this).showDialog(&cur.bv());
244 void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
246 graphic_->metrics(mi, dim);
251 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
253 setPosCache(pi, x, y);
254 graphic_->draw(pi, x, y);
258 InsetBase::EDITABLE InsetGraphics::editable() const
264 void InsetGraphics::write(Buffer const & buf, ostream & os) const
267 params().Write(os, buf.filePath());
271 void InsetGraphics::read(Buffer const & buf, LyXLex & lex)
273 string const token = lex.getString();
275 if (token == "Graphics")
276 readInsetGraphics(lex, buf.filePath());
278 lyxerr[Debug::GRAPHICS] << "Not a Graphics inset!" << endl;
280 graphic_->update(params().as_grfxParams());
284 void InsetGraphics::readInsetGraphics(LyXLex & lex, string const & bufpath)
286 bool finished = false;
288 while (lex.isOK() && !finished) {
291 string const token = lex.getString();
292 lyxerr[Debug::GRAPHICS] << "Token: '" << token << '\''
297 } else if (token == "\\end_inset") {
300 if (!params_.Read(lex, token, bufpath))
301 lyxerr << "Unknown token, " << token << ", skipping."
308 string const InsetGraphics::createLatexOptions() const
310 // Calculate the options part of the command, we must do it to a string
311 // stream since we might have a trailing comma that we would like to remove
312 // before writing it to the output stream.
313 ostringstream options;
314 if (!params().bb.empty())
315 options << "bb=" << rtrim(params().bb) << ',';
320 double const scl = convert<double>(params().scale);
321 if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
322 if (!float_equal(scl, 100.0, 0.05))
323 options << "scale=" << scl / 100.0 << ',';
325 if (!params().width.zero())
326 options << "width=" << params().width.asLatexString() << ',';
327 if (!params().height.zero())
328 options << "height=" << params().height.asLatexString() << ',';
329 if (params().keepAspectRatio)
330 options << "keepaspectratio,";
333 // Make sure rotation angle is not very close to zero;
334 // a float can be effectively zero but not exactly zero.
335 if (!params().rotateAngle.empty()
336 && !float_equal(convert<double>(params().rotateAngle), 0.0, 0.001)) {
337 options << "angle=" << params().rotateAngle << ',';
338 if (!params().rotateOrigin.empty()) {
339 options << "origin=" << params().rotateOrigin[0];
340 if (contains(params().rotateOrigin,"Top"))
342 else if (contains(params().rotateOrigin,"Bottom"))
344 else if (contains(params().rotateOrigin,"Baseline"))
350 if (!params().special.empty())
351 options << params().special << ',';
353 string opts = options.str();
355 return opts.substr(0, opts.size() - 1);
359 string const InsetGraphics::toDocbookLength(LyXLength const & len) const
361 ostringstream result;
362 switch (len.unit()) {
363 case LyXLength::SP: // Scaled point (65536sp = 1pt) TeX's smallest unit.
364 result << len.value() * 65536.0 * 72 / 72.27 << "pt";
366 case LyXLength::PT: // Point = 1/72.27in = 0.351mm
367 result << len.value() * 72 / 72.27 << "pt";
369 case LyXLength::BP: // Big point (72bp = 1in), also PostScript point
370 result << len.value() << "pt";
372 case LyXLength::DD: // Didot point = 1/72 of a French inch, = 0.376mm
373 result << len.value() * 0.376 << "mm";
375 case LyXLength::MM: // Millimeter = 2.845pt
376 result << len.value() << "mm";
378 case LyXLength::PC: // Pica = 12pt = 4.218mm
379 result << len.value() << "pc";
381 case LyXLength::CC: // Cicero = 12dd = 4.531mm
382 result << len.value() * 4.531 << "mm";
384 case LyXLength::CM: // Centimeter = 10mm = 2.371pc
385 result << len.value() << "cm";
387 case LyXLength::IN: // Inch = 25.4mm = 72.27pt = 6.022pc
388 result << len.value() << "in";
390 case LyXLength::EX: // Height of a small "x" for the current font.
391 // Obviously we have to compromise here. Any better ratio than 1.5 ?
392 result << len.value() / 1.5 << "em";
394 case LyXLength::EM: // Width of capital "M" in current font.
395 result << len.value() << "em";
397 case LyXLength::MU: // Math unit (18mu = 1em) for positioning in math mode
398 result << len.value() * 18 << "em";
400 case LyXLength::PTW: // Percent of TextWidth
401 case LyXLength::PCW: // Percent of ColumnWidth
402 case LyXLength::PPW: // Percent of PageWidth
403 case LyXLength::PLW: // Percent of LineWidth
404 case LyXLength::PTH: // Percent of TextHeight
405 case LyXLength::PPH: // Percent of Paper
406 // Sigh, this will go wrong.
407 result << len.value() << "%";
410 result << len.asString();
416 string const InsetGraphics::createDocBookAttributes() const
418 // Calculate the options part of the command, we must do it to a string
419 // stream since we copied the code from createLatexParams() ;-)
421 // FIXME: av: need to translate spec -> Docbook XSL spec (http://www.sagehill.net/docbookxsl/ImageSizing.html)
422 // Right now it only works with my version of db2latex :-)
424 ostringstream options;
425 double const scl = convert<double>(params().scale);
426 if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
427 if (!float_equal(scl, 100.0, 0.05))
428 options << " scale=\""
429 << static_cast<int>( (scl) + 0.5 )
432 if (!params().width.zero()) {
433 options << " width=\"" << toDocbookLength(params().width) << "\" ";
435 if (!params().height.zero()) {
436 options << " depth=\"" << toDocbookLength(params().height) << "\" ";
438 if (params().keepAspectRatio) {
439 // This will be irrelevant unless both width and height are set
440 options << "scalefit=\"1\" ";
445 if (!params().special.empty())
446 options << params().special << " ";
448 string opts = options.str();
449 // trailing blanks are ok ...
464 std::pair<CopyStatus, string> const
465 copyFileIfNeeded(string const & file_in, string const & file_out)
467 BOOST_ASSERT(AbsolutePath(file_in));
468 BOOST_ASSERT(AbsolutePath(file_out));
470 unsigned long const checksum_in = support::sum(file_in);
471 unsigned long const checksum_out = support::sum(file_out);
473 if (checksum_in == checksum_out)
475 return std::make_pair(IDENTICAL_CONTENTS, file_out);
477 Mover const & mover = movers(formats.getFormatFromFile(file_in));
478 bool const success = mover.copy(file_in, file_out);
480 lyxerr[Debug::GRAPHICS]
481 << support::bformat(_("Could not copy the file\n%1$s\n"
482 "into the temporary directory."),
487 CopyStatus status = success ? SUCCESS : FAILURE;
488 return std::make_pair(status, file_out);
492 std::pair<CopyStatus, string> const
493 copyToDirIfNeeded(string const & file_in, string const & dir, bool zipped)
495 using support::rtrim;
497 BOOST_ASSERT(AbsolutePath(file_in));
499 string const only_path = support::OnlyPath(file_in);
500 if (rtrim(support::OnlyPath(file_in) , "/") == rtrim(dir, "/"))
501 return std::make_pair(IDENTICAL_PATHS, file_in);
503 string mangled = FileName(file_in).mangledFilename();
505 // We need to change _eps.gz to .eps.gz. The mangled name is
506 // still unique because of the counter in mangledFilename().
507 // We can't just call mangledFilename() with the zip
508 // extension removed, because base.eps and base.eps.gz may
509 // have different content but would get the same mangled
510 // name in this case.
511 string const base = RemoveExtension(unzippedFileName(file_in));
512 string::size_type const ext_len = file_in.length() - base.length();
513 mangled[mangled.length() - ext_len] = '.';
515 string const file_out = support::MakeAbsPath(mangled, dir);
517 return copyFileIfNeeded(file_in, file_out);
521 string const stripExtension(string const & file)
523 // Remove the extension so the LaTeX will use whatever
524 // is appropriate (when there are several versions in
525 // different formats)
526 // This works only if the filename contains no dots besides
527 // the just removed one. We can fool here by replacing all
528 // dots with a macro whose definition is just a dot ;-)
529 return subst(RemoveExtension(file), ".", "\\lyxdot ");
533 string const stripExtensionIfPossible(string const & file, string const & to)
535 // No conversion is needed. LaTeX can handle the graphic file as is.
536 // This is true even if the orig_file is compressed.
537 string const to_format = formats.getFormat(to)->extension();
538 string const file_format = GetExtension(file);
539 // for latex .ps == .eps
540 if (to_format == file_format ||
541 (to_format == "eps" && file_format == "ps") ||
542 (to_format == "ps" && file_format == "eps"))
543 return stripExtension(file);
550 string const InsetGraphics::prepareFile(Buffer const & buf,
551 OutputParams const & runparams) const
553 // The following code depends on non-empty filenames
554 if (params().filename.empty())
557 string const orig_file = params().filename.absFilename();
558 string const rel_file = params().filename.relFilename(buf.filePath());
560 // If the file is compressed and we have specified that it
561 // should not be uncompressed, then just return its name and
562 // let LaTeX do the rest!
563 bool const zipped = params().filename.isZipped();
565 // temp_file will contain the file for LaTeX to act on if, for example,
566 // we move it to a temp dir or uncompress it.
567 string temp_file = orig_file;
569 // The master buffer. This is useful when there are multiple levels
571 Buffer const * m_buffer = buf.getMasterBuffer();
573 // Return the output name if the file does not exist.
574 // We are not going to change the extension or using the name of the
575 // temporary file, the code is already complicated enough.
576 if (!IsFileReadable(orig_file))
577 return params().filename.outputFilename(m_buffer->filePath());
579 // We place all temporary files in the master buffer's temp dir.
580 // This is possible because we use mangled file names.
581 // This is necessary for DVI export.
582 string const temp_path = m_buffer->temppath();
585 boost::tie(status, temp_file) =
586 copyToDirIfNeeded(orig_file, temp_path, zipped);
588 if (status == FAILURE)
591 // a relative filename should be relative to the master
593 // "nice" means that the buffer is exported to LaTeX format but not
594 // run through the LaTeX compiler.
595 string const output_file = os::external_path(runparams.nice ?
596 params().filename.outputFilename(m_buffer->filePath()) :
597 OnlyFilename(temp_file));
598 string const source_file = runparams.nice ? orig_file : temp_file;
601 if (params().noUnzip) {
602 // We don't know whether latex can actually handle
603 // this file, but we can't check, because that would
604 // mean to unzip the file and thereby making the
605 // noUnzip parameter meaningless.
606 lyxerr[Debug::GRAPHICS]
607 << "\tpass zipped file to LaTeX.\n";
609 string const bb_orig_file = ChangeExtension(orig_file, "bb");
610 if (runparams.nice) {
611 runparams.exportdata->addExternalFile("latex",
613 ChangeExtension(output_file, "bb"));
615 // LaTeX needs the bounding box file in the
617 string bb_file = ChangeExtension(temp_file, "bb");
618 boost::tie(status, bb_file) =
619 copyFileIfNeeded(bb_orig_file, bb_file);
620 if (status == FAILURE)
622 runparams.exportdata->addExternalFile("latex",
625 runparams.exportdata->addExternalFile("latex",
626 source_file, output_file);
627 runparams.exportdata->addExternalFile("dvi",
628 source_file, output_file);
629 // We can't strip the extension, because we don't know
630 // the unzipped file format
634 string const unzipped_temp_file = unzippedFileName(temp_file);
635 if (compare_timestamps(unzipped_temp_file, temp_file) > 0) {
636 // temp_file has been unzipped already and
637 // orig_file has not changed in the meantime.
638 temp_file = unzipped_temp_file;
639 lyxerr[Debug::GRAPHICS]
640 << "\twas already unzipped to " << temp_file
643 // unzipped_temp_file does not exist or is too old
644 temp_file = unzipFile(temp_file);
645 lyxerr[Debug::GRAPHICS]
646 << "\tunzipped to " << temp_file << endl;
650 string const from = formats.getFormatFromFile(temp_file);
652 lyxerr[Debug::GRAPHICS]
653 << "\tCould not get file format." << endl;
656 string const to = findTargetFormat(from, runparams);
657 string const ext = formats.extension(to);
658 lyxerr[Debug::GRAPHICS]
659 << "\t we have: from " << from << " to " << to << '\n';
661 // We're going to be running the exported buffer through the LaTeX
662 // compiler, so must ensure that LaTeX can cope with the graphics
665 lyxerr[Debug::GRAPHICS]
666 << "\tthe orig file is: " << orig_file << endl;
669 // The extension of temp_file might be != ext!
670 runparams.exportdata->addExternalFile("latex", source_file,
672 runparams.exportdata->addExternalFile("dvi", source_file,
674 return stripExtensionIfPossible(output_file, to);
677 string const to_file = ChangeExtension(temp_file, ext);
678 string const output_to_file = ChangeExtension(output_file, ext);
680 // Do we need to perform the conversion?
681 // Yes if to_file does not exist or if temp_file is newer than to_file
682 if (compare_timestamps(temp_file, to_file) < 0) {
683 lyxerr[Debug::GRAPHICS]
684 << bformat(_("No conversion of %1$s is needed after all"),
687 runparams.exportdata->addExternalFile("latex", to_file,
689 runparams.exportdata->addExternalFile("dvi", to_file,
691 return stripExtension(output_file);
694 lyxerr[Debug::GRAPHICS]
695 << "\tThe original file is " << orig_file << "\n"
696 << "\tA copy has been made and convert is to be called with:\n"
697 << "\tfile to convert = " << temp_file << '\n'
698 << "\t from " << from << " to " << to << '\n';
700 if (converters.convert(&buf, temp_file, temp_file, from, to, true)) {
701 runparams.exportdata->addExternalFile("latex",
702 to_file, output_to_file);
703 runparams.exportdata->addExternalFile("dvi",
704 to_file, output_to_file);
707 return stripExtension(output_file);
711 int InsetGraphics::latex(Buffer const & buf, ostream & os,
712 OutputParams const & runparams) const
714 // If there is no file specified or not existing,
715 // just output a message about it in the latex output.
716 lyxerr[Debug::GRAPHICS]
717 << "insetgraphics::latex: Filename = "
718 << params().filename.absFilename() << endl;
720 string const relative_file =
721 params().filename.relFilename(buf.filePath());
723 string const file_ = params().filename.absFilename();
724 bool const file_exists = !file_.empty() && IsFileReadable(file_);
725 string const message = file_exists ?
726 string() : string("bb = 0 0 200 100, draft, type=eps");
727 // if !message.empty() then there was no existing file
728 // "filename" found. In this case LaTeX
729 // draws only a rectangle with the above bb and the
730 // not found filename in it.
731 lyxerr[Debug::GRAPHICS]
732 << "\tMessage = \"" << message << '\"' << endl;
734 // These variables collect all the latex code that should be before and
735 // after the actual includegraphics command.
738 // Do we want subcaptions?
739 if (params().subcaption) {
740 before += "\\subfigure[" + params().subcaptionText + "]{";
743 // We never use the starred form, we use the "clip" option instead.
744 before += "\\includegraphics";
746 // Write the options if there are any.
747 string const opts = createLatexOptions();
748 lyxerr[Debug::GRAPHICS] << "\tOpts = " << opts << endl;
750 if (!opts.empty() && !message.empty())
751 before += ('[' + opts + ',' + message + ']');
752 else if (!opts.empty() || !message.empty())
753 before += ('[' + opts + message + ']');
755 lyxerr[Debug::GRAPHICS]
756 << "\tBefore = " << before
757 << "\n\tafter = " << after << endl;
759 string latex_str = before + '{';
760 // Convert the file if necessary.
761 // Remove the extension so LaTeX will use whatever is appropriate
762 // (when there are several versions in different formats)
763 latex_str += latex_path(prepareFile(buf, runparams));
764 latex_str += '}' + after;
767 lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n"
768 << latex_str << endl;
769 // Return how many newlines we issued.
770 return int(lyx::count(latex_str.begin(), latex_str.end(),'\n'));
774 int InsetGraphics::plaintext(Buffer const &, ostream & os,
775 OutputParams const &) const
777 // No graphics in ascii output. Possible to use gifscii to convert
778 // images to ascii approximation.
779 // 1. Convert file to ascii using gifscii
780 // 2. Read ascii output file and add it to the output stream.
781 // at least we send the filename
782 os << '<' << bformat(_("Graphics file: %1$s"),
783 params().filename.absFilename()) << ">\n";
788 int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os,
789 OutputParams const & runparams) const
791 string const file_name = runparams.nice ?
792 params().filename.relFilename(buf.filePath()):
793 params().filename.absFilename();
795 runparams.exportdata->addExternalFile("linuxdoc",
796 params().filename.absFilename());
797 os << "<eps file=\"" << file_name << "\">\n";
798 os << "<img src=\"" << file_name << "\">";
805 int writeImageObject(char * format, ostream& os, OutputParams const & runparams,
806 string const graphic_label, string const attributes)
808 if (runparams.flavor != OutputParams::XML) {
809 os << "<![ %output.print." << format << "; [" << std::endl;
811 os <<"<imageobject><imagedata fileref=\"&"
812 << graphic_label << ";." << format << "\" " << attributes ;
813 if (runparams.flavor == OutputParams::XML) {
814 os << " role=\"" << format << "\"/>" ;
817 os << " format=\"" << format << "\">" ;
819 os << "</imageobject>";
820 if (runparams.flavor != OutputParams::XML) {
821 os << std::endl << "]]>" ;
823 return runparams.flavor == OutputParams::XML ? 0 : 2;
825 // end anonymous namespace
829 // For explanation on inserting graphics into DocBook checkout:
830 // http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
831 // See also the docbook guide at http://www.docbook.org/
832 int InsetGraphics::docbook(Buffer const &, ostream & os,
833 OutputParams const & runparams) const
835 // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
836 // need to switch to MediaObject. However, for now this is sufficient and
838 if (runparams.flavor == OutputParams::XML) {
839 runparams.exportdata->addExternalFile("docbook-xml",
840 params().filename.absFilename());
842 runparams.exportdata->addExternalFile("docbook",
843 params().filename.absFilename());
845 os << "<inlinemediaobject>";
848 string attributes = createDocBookAttributes();
849 r += writeImageObject("png", os, runparams, graphic_label, attributes);
850 r += writeImageObject("pdf", os, runparams, graphic_label, attributes);
851 r += writeImageObject("eps", os, runparams, graphic_label, attributes);
852 r += writeImageObject("bmp", os, runparams, graphic_label, attributes);
854 os << "</inlinemediaobject>";
859 void InsetGraphics::validate(LaTeXFeatures & features) const
861 // If we have no image, we should not require anything.
862 if (params().filename.empty())
865 features.includeFile(graphic_label,
866 RemoveExtension(params().filename.absFilename()));
868 features.require("graphicx");
870 if (features.nice()) {
871 Buffer const * m_buffer = features.buffer().getMasterBuffer();
873 params().filename.outputFilename(m_buffer->filePath());
874 basename = RemoveExtension(basename);
875 if(params().filename.isZipped())
876 basename = RemoveExtension(basename);
877 if (contains(basename, "."))
878 features.require("lyxdot");
881 if (params().subcaption)
882 features.require("subfigure");
886 bool InsetGraphics::setParams(InsetGraphicsParams const & p)
888 // If nothing is changed, just return and say so.
889 if (params() == p && !p.filename.empty())
892 // Copy the new parameters.
895 // Update the display using the new parameters.
896 graphic_->update(params().as_grfxParams());
898 // We have changed data, report it.
903 InsetGraphicsParams const & InsetGraphics::params() const
909 void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
910 Buffer const & buffer) const
912 string const file_with_path = p.filename.absFilename();
913 formats.edit(buffer, file_with_path,
914 formats.getFormatFromFile(file_with_path));
918 string const InsetGraphicsMailer::name_("graphics");
920 InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
925 string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
927 return params2string(inset_.params(), buffer);
931 void InsetGraphicsMailer::string2params(string const & in,
932 Buffer const & buffer,
933 InsetGraphicsParams & params)
935 params = InsetGraphicsParams();
939 istringstream data(in);
945 if (!lex || name != name_)
946 return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
949 inset.readInsetGraphics(lex, buffer.filePath());
950 params = inset.params();
955 InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
956 Buffer const & buffer)
959 data << name_ << ' ';
960 params.Write(data, buffer.filePath());
961 data << "\\end_inset\n";