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"
65 #include "LaTeXFeatures.h"
67 #include "lyxlength.h"
69 #include "metricsinfo.h"
71 #include "outputparams.h"
74 #include "frontends/Alert.h"
75 #include "frontends/LyXView.h"
77 #include "support/filetools.h"
78 #include "support/lyxalgo.h" // lyx::count
79 #include "support/lyxlib.h" // float_equal
80 #include "support/os.h"
81 #include "support/systemcall.h"
83 #include <boost/bind.hpp>
84 #include <boost/tuple/tuple.hpp>
88 namespace support = lyx::support;
90 using lyx::support::AbsolutePath;
91 using lyx::support::bformat;
92 using lyx::support::ChangeExtension;
93 using lyx::support::compare_timestamps;
94 using lyx::support::contains;
95 using lyx::support::FileName;
96 using lyx::support::float_equal;
97 using lyx::support::GetExtension;
98 using lyx::support::getFormatFromContents;
99 using lyx::support::IsFileReadable;
100 using lyx::support::LibFileSearch;
101 using lyx::support::OnlyFilename;
102 using lyx::support::rtrim;
103 using lyx::support::subst;
104 using lyx::support::Systemcall;
105 using lyx::support::unzipFile;
106 using lyx::support::unzippedFileName;
108 namespace os = lyx::support::os;
113 using std::istringstream;
115 using std::ostringstream;
120 // This function is a utility function
121 // ... that should be with ChangeExtension ...
123 string const RemoveExtension(string const & filename)
125 return ChangeExtension(filename, string());
129 string findTargetFormat(string const & format, OutputParams const & runparams)
131 // Are we using latex or pdflatex?
132 if (runparams.flavor == OutputParams::PDFLATEX) {
133 lyxerr[Debug::GRAPHICS] << "findTargetFormat: PDF mode" << endl;
134 // Convert postscript to pdf
135 if (format == "eps" || format == "ps")
137 // pdflatex can use jpeg, png and pdf directly
138 if (format == "jpg" || format == "pdf")
140 // Convert everything else to png
143 // If it's postscript, we always do eps.
144 lyxerr[Debug::GRAPHICS] << "findTargetFormat: PostScript mode" << endl;
146 // any other than ps is changed to eps
155 InsetGraphics::InsetGraphics()
156 : graphic_label(sgml::uniqueID("graph")),
157 graphic_(new RenderGraphic(this))
161 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
163 boost::signals::trackable(),
164 graphic_label(sgml::uniqueID("graph")),
165 graphic_(new RenderGraphic(*ig.graphic_, this))
167 setParams(ig.params());
171 auto_ptr<InsetBase> InsetGraphics::clone() const
173 return auto_ptr<InsetBase>(new InsetGraphics(*this));
177 InsetGraphics::~InsetGraphics()
179 InsetGraphicsMailer(*this).hideDialog();
183 void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd)
185 switch (cmd.action) {
186 case LFUN_GRAPHICS_EDIT: {
187 Buffer const & buffer = *cur.bv().buffer();
188 InsetGraphicsParams p;
189 InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
190 editGraphics(p, buffer);
194 case LFUN_INSET_MODIFY: {
195 Buffer const & buffer = cur.buffer();
196 InsetGraphicsParams p;
197 InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
198 if (!p.filename.empty()) {
205 case LFUN_INSET_DIALOG_UPDATE:
206 InsetGraphicsMailer(*this).updateDialog(&cur.bv());
209 case LFUN_MOUSE_RELEASE:
210 InsetGraphicsMailer(*this).showDialog(&cur.bv());
214 InsetOld::priv_dispatch(cur, cmd);
220 void InsetGraphics::edit(LCursor & cur, bool)
222 InsetGraphicsMailer(*this).showDialog(&cur.bv());
226 void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
228 graphic_->metrics(mi, dim);
233 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
235 setPosCache(pi, x, y);
236 graphic_->draw(pi, x, y);
240 InsetOld::EDITABLE InsetGraphics::editable() const
246 void InsetGraphics::write(Buffer const & buf, ostream & os) const
249 params().Write(os, buf.filePath());
253 void InsetGraphics::read(Buffer const & buf, LyXLex & lex)
255 string const token = lex.getString();
257 if (token == "Graphics")
258 readInsetGraphics(lex, buf.filePath());
260 lyxerr[Debug::GRAPHICS] << "Not a Graphics inset!" << endl;
262 graphic_->update(params().as_grfxParams());
266 void InsetGraphics::readInsetGraphics(LyXLex & lex, string const & bufpath)
268 bool finished = false;
270 while (lex.isOK() && !finished) {
273 string const token = lex.getString();
274 lyxerr[Debug::GRAPHICS] << "Token: '" << token << '\''
279 } else if (token == "\\end_inset") {
282 if (!params_.Read(lex, token, bufpath))
283 lyxerr << "Unknown token, " << token << ", skipping."
290 string const InsetGraphics::createLatexOptions() const
292 // Calculate the options part of the command, we must do it to a string
293 // stream since we might have a trailing comma that we would like to remove
294 // before writing it to the output stream.
295 ostringstream options;
296 if (!params().bb.empty())
297 options << " bb=" << rtrim(params().bb) << ",\n";
299 options << " draft,\n";
301 options << " clip,\n";
302 if (!float_equal(params().scale, 0.0, 0.05)) {
303 if (!float_equal(params().scale, 100.0, 0.05))
304 options << " scale=" << params().scale / 100.0
307 if (!params().width.zero())
308 options << " width=" << params().width.asLatexString() << ",\n";
309 if (!params().height.zero())
310 options << " height=" << params().height.asLatexString() << ",\n";
311 if (params().keepAspectRatio)
312 options << " keepaspectratio,\n";
315 // Make sure rotation angle is not very close to zero;
316 // a float can be effectively zero but not exactly zero.
317 if (!float_equal(params().rotateAngle, 0, 0.001)) {
318 options << " angle=" << params().rotateAngle << ",\n";
319 if (!params().rotateOrigin.empty()) {
320 options << " origin=" << params().rotateOrigin[0];
321 if (contains(params().rotateOrigin,"Top"))
323 else if (contains(params().rotateOrigin,"Bottom"))
325 else if (contains(params().rotateOrigin,"Baseline"))
331 if (!params().special.empty())
332 options << params().special << ",\n";
334 string opts = options.str();
336 return opts.substr(0, opts.size() - 2);
340 string const InsetGraphics::toDocbookLength(LyXLength const & len) const
342 ostringstream result;
343 switch (len.unit()) {
344 case LyXLength::SP: // Scaled point (65536sp = 1pt) TeX's smallest unit.
345 result << len.value() * 65536.0 * 72 / 72.27 << "pt";
347 case LyXLength::PT: // Point = 1/72.27in = 0.351mm
348 result << len.value() * 72 / 72.27 << "pt";
350 case LyXLength::BP: // Big point (72bp = 1in), also PostScript point
351 result << len.value() << "pt";
353 case LyXLength::DD: // Didot point = 1/72 of a French inch, = 0.376mm
354 result << len.value() * 0.376 << "mm";
356 case LyXLength::MM: // Millimeter = 2.845pt
357 result << len.value() << "mm";
359 case LyXLength::PC: // Pica = 12pt = 4.218mm
360 result << len.value() << "pc";
362 case LyXLength::CC: // Cicero = 12dd = 4.531mm
363 result << len.value() * 4.531 << "mm";
365 case LyXLength::CM: // Centimeter = 10mm = 2.371pc
366 result << len.value() << "cm";
368 case LyXLength::IN: // Inch = 25.4mm = 72.27pt = 6.022pc
369 result << len.value() << "in";
371 case LyXLength::EX: // Height of a small "x" for the current font.
372 // Obviously we have to compromise here. Any better ratio than 1.5 ?
373 result << len.value() / 1.5 << "em";
375 case LyXLength::EM: // Width of capital "M" in current font.
376 result << len.value() << "em";
378 case LyXLength::MU: // Math unit (18mu = 1em) for positioning in math mode
379 result << len.value() * 18 << "em";
381 case LyXLength::PTW: // Percent of TextWidth
382 case LyXLength::PCW: // Percent of ColumnWidth
383 case LyXLength::PPW: // Percent of PageWidth
384 case LyXLength::PLW: // Percent of LineWidth
385 case LyXLength::PTH: // Percent of TextHeight
386 case LyXLength::PPH: // Percent of Paper
387 // Sigh, this will go wrong.
388 result << len.value() << "%";
391 result << len.asString();
397 string const InsetGraphics::createDocBookAttributes() const
399 // Calculate the options part of the command, we must do it to a string
400 // stream since we copied the code from createLatexParams() ;-)
402 // FIXME: av: need to translate spec -> Docbook XSL spec (http://www.sagehill.net/docbookxsl/ImageSizing.html)
403 // Right now it only works with my version of db2latex :-)
405 ostringstream options;
406 if (!float_equal(params().scale, 0.0, 0.05)) {
407 if (!float_equal(params().scale, 100.0, 0.05))
408 options << " scale=\"" << static_cast<int>( (params().scale) + 0.5 )
411 if (!params().width.zero()) {
412 options << " width=\"" << toDocbookLength(params().width) << "\" ";
414 if (!params().height.zero()) {
415 options << " depth=\"" << toDocbookLength(params().height) << "\" ";
417 if (params().keepAspectRatio) {
418 // This will be irrelevant unless both width and height are set
419 options << "scalefit=\"1\" ";
424 if (!params().special.empty())
425 options << params().special << " ";
427 string opts = options.str();
428 // trailing blanks are ok ...
443 std::pair<CopyStatus, string> const
444 copyFileIfNeeded(string const & file_in, string const & file_out)
446 BOOST_ASSERT(AbsolutePath(file_in));
447 BOOST_ASSERT(AbsolutePath(file_out));
449 unsigned long const checksum_in = support::sum(file_in);
450 unsigned long const checksum_out = support::sum(file_out);
452 if (checksum_in == checksum_out)
454 return std::make_pair(IDENTICAL_CONTENTS, file_out);
456 Mover const & mover = movers(getFormatFromContents(file_in));
457 bool const success = mover.copy(file_in, file_out);
459 lyxerr[Debug::GRAPHICS]
460 << support::bformat(_("Could not copy the file\n%1$s\n"
461 "into the temporary directory."),
466 CopyStatus status = success ? SUCCESS : FAILURE;
467 return std::make_pair(status, file_out);
471 std::pair<CopyStatus, string> const
472 copyToDirIfNeeded(string const & file_in, string const & dir, bool zipped)
474 using support::rtrim;
476 BOOST_ASSERT(AbsolutePath(file_in));
478 string const only_path = support::OnlyPath(file_in);
479 if (rtrim(support::OnlyPath(file_in) , "/") == rtrim(dir, "/"))
480 return std::make_pair(IDENTICAL_PATHS, file_in);
482 string mangled = FileName(file_in).mangledFilename();
484 // We need to change _eps.gz to .eps.gz. The mangled name is
485 // still unique because of the counter in mangledFilename().
486 // We can't just call mangledFilename() with the zip
487 // extension removed, because base.eps and base.eps.gz may
488 // have different content but would get the same mangled
489 // name in this case.
490 string const base = RemoveExtension(unzippedFileName(file_in));
491 string::size_type const ext_len = file_in.length() - base.length();
492 mangled[mangled.length() - ext_len] = '.';
494 string const file_out = support::MakeAbsPath(mangled, dir);
496 return copyFileIfNeeded(file_in, file_out);
500 string const stripExtension(string const & file)
502 // Remove the extension so the LaTeX will use whatever
503 // is appropriate (when there are several versions in
504 // different formats)
505 // This works only if the filename contains no dots besides
506 // the just removed one. We can fool here by replacing all
507 // dots with a macro whose definition is just a dot ;-)
508 return subst(RemoveExtension(file), ".", "\\lyxdot ");
512 string const stripExtensionIfPossible(string const & file, string const & to)
514 // No conversion is needed. LaTeX can handle the graphic file as is.
515 // This is true even if the orig_file is compressed.
516 string const to_format = formats.getFormat(to)->extension();
517 string const file_format = GetExtension(file);
518 // for latex .ps == .eps
519 if (to_format == file_format ||
520 (to_format == "eps" && file_format == "ps") ||
521 (to_format == "ps" && file_format == "eps"))
522 return stripExtension(file);
529 string const InsetGraphics::prepareFile(Buffer const & buf,
530 OutputParams const & runparams) const
532 // We assume that the file exists (the caller checks this)
533 string const orig_file = params().filename.absFilename();
534 string const rel_file = params().filename.relFilename(buf.filePath());
536 // If the file is compressed and we have specified that it
537 // should not be uncompressed, then just return its name and
538 // let LaTeX do the rest!
539 bool const zipped = params().filename.isZipped();
541 // temp_file will contain the file for LaTeX to act on if, for example,
542 // we move it to a temp dir or uncompress it.
543 string temp_file = orig_file;
545 // The master buffer. This is useful when there are multiple levels
547 Buffer const * m_buffer = buf.getMasterBuffer();
549 // We place all temporary files in the master buffer's temp dir.
550 // This is possible because we use mangled file names.
551 // This is necessary for DVI export.
552 string const temp_path = m_buffer->temppath();
555 boost::tie(status, temp_file) =
556 copyToDirIfNeeded(orig_file, temp_path, zipped);
558 if (status == FAILURE)
561 // a relative filename should be relative to the master
563 // "nice" means that the buffer is exported to LaTeX format but not
564 // run through the LaTeX compiler.
565 string const output_file = os::external_path(runparams.nice ?
566 params().filename.outputFilename(m_buffer->filePath()) :
567 OnlyFilename(temp_file));
568 string const source_file = runparams.nice ? orig_file : temp_file;
571 if (params().noUnzip) {
572 // We don't know whether latex can actually handle
573 // this file, but we can't check, because that would
574 // mean to unzip the file and thereby making the
575 // noUnzip parameter meaningless.
576 lyxerr[Debug::GRAPHICS]
577 << "\tpass zipped file to LaTeX.\n";
579 string const bb_orig_file = ChangeExtension(orig_file, "bb");
580 if (runparams.nice) {
581 runparams.exportdata->addExternalFile("latex",
583 ChangeExtension(output_file, "bb"));
585 // LaTeX needs the bounding box file in the
587 string bb_file = ChangeExtension(temp_file, "bb");
588 boost::tie(status, bb_file) =
589 copyFileIfNeeded(bb_orig_file, bb_file);
590 if (status == FAILURE)
592 runparams.exportdata->addExternalFile("latex",
595 runparams.exportdata->addExternalFile("latex",
596 source_file, output_file);
597 runparams.exportdata->addExternalFile("dvi",
598 source_file, output_file);
599 // We can't strip the extension, because we don't know
600 // the unzipped file format
604 string const unzipped_temp_file = unzippedFileName(temp_file);
605 if (compare_timestamps(unzipped_temp_file, temp_file) > 0) {
606 // temp_file has been unzipped already and
607 // orig_file has not changed in the meantime.
608 temp_file = unzipped_temp_file;
609 lyxerr[Debug::GRAPHICS]
610 << "\twas already unzipped to " << temp_file
613 // unzipped_temp_file does not exist or is too old
614 temp_file = unzipFile(temp_file);
615 lyxerr[Debug::GRAPHICS]
616 << "\tunzipped to " << temp_file << endl;
620 string const from = getFormatFromContents(temp_file);
621 string const to = findTargetFormat(from, runparams);
622 string const ext = formats.extension(to);
623 lyxerr[Debug::GRAPHICS]
624 << "\t we have: from " << from << " to " << to << '\n';
626 // We're going to be running the exported buffer through the LaTeX
627 // compiler, so must ensure that LaTeX can cope with the graphics
630 lyxerr[Debug::GRAPHICS]
631 << "\tthe orig file is: " << orig_file << endl;
634 // The extension of temp_file might be != ext!
635 runparams.exportdata->addExternalFile("latex", source_file,
637 runparams.exportdata->addExternalFile("dvi", source_file,
639 return stripExtensionIfPossible(output_file, to);
642 string const to_file = ChangeExtension(temp_file, ext);
643 string const output_to_file = ChangeExtension(output_file, ext);
645 // Do we need to perform the conversion?
646 // Yes if to_file does not exist or if temp_file is newer than to_file
647 if (compare_timestamps(temp_file, to_file) < 0) {
648 lyxerr[Debug::GRAPHICS]
649 << bformat(_("No conversion of %1$s is needed after all"),
652 runparams.exportdata->addExternalFile("latex", to_file,
654 runparams.exportdata->addExternalFile("dvi", to_file,
656 return stripExtension(output_file);
659 lyxerr[Debug::GRAPHICS]
660 << "\tThe original file is " << orig_file << "\n"
661 << "\tA copy has been made and convert is to be called with:\n"
662 << "\tfile to convert = " << temp_file << '\n'
663 << "\t from " << from << " to " << to << '\n';
665 // if no special converter defined, then we take the default one
666 // from ImageMagic: convert from:inname.from to:outname.to
667 if (!converters.convert(&buf, temp_file, temp_file, from, to)) {
668 string const command =
669 "sh " + LibFileSearch("scripts", "convertDefault.sh") +
670 ' ' + formats.extension(from) + ':' + temp_file +
671 ' ' + ext + ':' + to_file;
672 lyxerr[Debug::GRAPHICS]
673 << "No converter defined! I use convertDefault.sh:\n\t"
676 one.startscript(Systemcall::Wait, command);
677 if (IsFileReadable(to_file)) {
678 runparams.exportdata->addExternalFile("latex",
679 to_file, output_to_file);
680 runparams.exportdata->addExternalFile("dvi",
681 to_file, output_to_file);
683 string str = bformat(_("No information for converting %1$s "
684 "format files to %2$s.\n"
685 "Try defining a convertor in the preferences."), from, to);
686 Alert::error(_("Could not convert image"), str);
690 return stripExtension(output_file);
694 int InsetGraphics::latex(Buffer const & buf, ostream & os,
695 OutputParams const & runparams) const
697 // If there is no file specified or not existing,
698 // just output a message about it in the latex output.
699 lyxerr[Debug::GRAPHICS]
700 << "insetgraphics::latex: Filename = "
701 << params().filename.absFilename() << endl;
703 string const relative_file =
704 params().filename.relFilename(buf.filePath());
706 string const file_ = params().filename.absFilename();
707 bool const file_exists = !file_.empty() && IsFileReadable(file_);
708 string const message = file_exists ?
709 string() : string("bb = 0 0 200 100, draft, type=eps");
710 // if !message.empty() then there was no existing file
711 // "filename" found. In this case LaTeX
712 // draws only a rectangle with the above bb and the
713 // not found filename in it.
714 lyxerr[Debug::GRAPHICS]
715 << "\tMessage = \"" << message << '\"' << endl;
717 // These variables collect all the latex code that should be before and
718 // after the actual includegraphics command.
721 // Do we want subcaptions?
722 if (params().subcaption) {
723 before += "\\subfigure[" + params().subcaptionText + "]{";
726 // We never use the starred form, we use the "clip" option instead.
727 before += "\\includegraphics";
729 // Write the options if there are any.
730 string const opts = createLatexOptions();
731 lyxerr[Debug::GRAPHICS] << "\tOpts = " << opts << endl;
733 if (!opts.empty() && !message.empty())
734 before += ("[%\n" + opts + ',' + message + ']');
735 else if (!opts.empty() || !message.empty())
736 before += ("[%\n" + opts + message + ']');
738 lyxerr[Debug::GRAPHICS]
739 << "\tBefore = " << before
740 << "\n\tafter = " << after << endl;
743 string latex_str = before + '{';
745 // Convert the file if necessary.
746 // Remove the extension so the LaTeX will use whatever
747 // is appropriate (when there are several versions in
748 // different formats)
749 latex_str += prepareFile(buf, runparams);
751 latex_str += relative_file + " not found!";
753 latex_str += '}' + after;
756 lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n"
757 << latex_str << endl;
758 // Return how many newlines we issued.
759 return int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1);
763 int InsetGraphics::plaintext(Buffer const &, ostream & os,
764 OutputParams const &) const
766 // No graphics in ascii output. Possible to use gifscii to convert
767 // images to ascii approximation.
768 // 1. Convert file to ascii using gifscii
769 // 2. Read ascii output file and add it to the output stream.
770 // at least we send the filename
771 os << '<' << bformat(_("Graphics file: %1$s"),
772 params().filename.absFilename()) << ">\n";
777 int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os,
778 OutputParams const & runparams) const
780 string const file_name = runparams.nice ?
781 params().filename.relFilename(buf.filePath()):
782 params().filename.absFilename();
784 runparams.exportdata->addExternalFile("linuxdoc",
785 params().filename.absFilename());
786 os << "<eps file=\"" << file_name << "\">\n";
787 os << "<img src=\"" << file_name << "\">";
794 int writeImageObject(char * format, ostream& os, OutputParams const & runparams,
795 string const graphic_label, string const attributes)
797 if (runparams.flavor != OutputParams::XML) {
798 os << "<![ %output.print." << format << "; [" << std::endl;
800 os <<"<imageobject><imagedata fileref=\"&"
801 << graphic_label << ";." << format << "\" " << attributes ;
802 if (runparams.flavor == OutputParams::XML) {
803 os << " role=\"" << format << "\"/>" ;
806 os << " format=\"" << format << "\">" ;
808 os << "</imageobject>";
809 if (runparams.flavor != OutputParams::XML) {
810 os << std::endl << "]]>" ;
812 return runparams.flavor == OutputParams::XML ? 0 : 2;
814 // end anonymous namespace
818 // For explanation on inserting graphics into DocBook checkout:
819 // http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
820 // See also the docbook guide at http://www.docbook.org/
821 int InsetGraphics::docbook(Buffer const &, ostream & os,
822 OutputParams const & runparams) const
824 // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
825 // need to switch to MediaObject. However, for now this is sufficient and
827 if (runparams.flavor == OutputParams::XML) {
828 runparams.exportdata->addExternalFile("docbook-xml",
829 params().filename.absFilename());
831 runparams.exportdata->addExternalFile("docbook",
832 params().filename.absFilename());
834 os << "<inlinemediaobject>";
837 string attributes = createDocBookAttributes();
838 r += writeImageObject("png", os, runparams, graphic_label, attributes);
839 r += writeImageObject("pdf", os, runparams, graphic_label, attributes);
840 r += writeImageObject("eps", os, runparams, graphic_label, attributes);
841 r += writeImageObject("bmp", os, runparams, graphic_label, attributes);
843 os << "</inlinemediaobject>";
848 void InsetGraphics::validate(LaTeXFeatures & features) const
850 // If we have no image, we should not require anything.
851 if (params().filename.empty())
854 features.includeFile(graphic_label,
855 RemoveExtension(params().filename.absFilename()));
857 features.require("graphicx");
859 if (features.nice()) {
860 Buffer const * m_buffer = features.buffer().getMasterBuffer();
862 params().filename.outputFilename(m_buffer->filePath());
863 basename = RemoveExtension(basename);
864 if(params().filename.isZipped())
865 basename = RemoveExtension(basename);
866 if (contains(basename, "."))
867 features.require("lyxdot");
870 if (params().subcaption)
871 features.require("subfigure");
875 bool InsetGraphics::setParams(InsetGraphicsParams const & p)
877 // If nothing is changed, just return and say so.
878 if (params() == p && !p.filename.empty())
881 // Copy the new parameters.
884 // Update the display using the new parameters.
885 graphic_->update(params().as_grfxParams());
887 // We have changed data, report it.
892 InsetGraphicsParams const & InsetGraphics::params() const
898 void InsetGraphics::editGraphics(InsetGraphicsParams const & p, Buffer const & buffer) const
900 string const file_with_path = p.filename.absFilename();
901 formats.edit(buffer, file_with_path, getFormatFromContents(file_with_path));
905 string const InsetGraphicsMailer::name_("graphics");
907 InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
912 string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
914 return params2string(inset_.params(), buffer);
918 void InsetGraphicsMailer::string2params(string const & in,
919 Buffer const & buffer,
920 InsetGraphicsParams & params)
922 params = InsetGraphicsParams();
926 istringstream data(in);
932 if (!lex || name != name_)
933 return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
936 inset.readInsetGraphics(lex, buffer.filePath());
937 params = inset.params();
942 InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
943 Buffer const & buffer)
946 data << name_ << ' ';
947 params.Write(data, buffer.filePath());
948 data << "\\end_inset\n";