]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.C
Force redraw of row if we changed (John's patch fix for #268)
[lyx.git] / src / insets / insetgraphics.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995-2002 the LyX Team.
7  *           
8  * \author Baruch Even
9  * \author Herbert Voss <voss@lyx.org>
10  * ====================================================== */
11
12 /*
13 Known BUGS:
14     
15     * If the image is from the clipart, and the document is moved to another
16        directory, the user is screwed. Need a way to handle it.
17        This amounts to a problem of when to use relative or absolute file paths
18        We should probably use what the user asks to use... but when he chooses
19        by the file dialog we normally get an absolute path and this may not be 
20        what the user meant.
21        [Note that browseRelFile in helper_funcs.* provides a file name
22         which is relative if it is at reference path (here puffer path)
23         level or below, and an absolute path if the file name is not a
24         `natural' relative file name. In any case,
25             MakeAbsPath(filename, buf->filePath())
26         is guaranteed to provide the correct absolute path. This is what is
27         done know for include insets. Feel free to ask me -- JMarc
28         14/01/2002]
29         
30         * If we are trying to create a file in a read-only directory and there
31                 are graphics that need converting, the converting will fail because
32                 it is done in-place, into the same directory as the original image.
33                 This needs to be fixed in the src/converter.C file
34                 [ This is presumed to be fixed, needs testing.]
35
36         * We do not dither or resize the image in a WYSIWYM way, we load it at
37                 its original size and color, resizing is done in the final output,
38                 but not in the LyX window.
39
40 TODO Before initial production release:
41     * Replace insetfig everywhere
42         * Search for comments of the form
43             // INSET_GRAPHICS: remove this when InsetFig is thrown.
44           And act upon them. Make sure not to remove InsetFig code for the 
45                   1.2.0 release, only afterwards, after deployment shows InsetGraphics
46                   to be ok.
47         * What advanced features the users want to do?
48             Implement them in a non latex dependent way, but a logical way.
49             LyX should translate it to latex or any other fitting format.
50     * Add a way to roll the image file into the file format.
51     * When loading, if the image is not found in the expected place, try
52        to find it in the clipart, or in the same directory with the image.
53     * Keep a tab on the image file, if it changes, update the lyx view.
54         * The image choosing dialog could show thumbnails of the image formats
55           it knows of, thus selection based on the image instead of based on
56           filename.
57         * Add support for the 'picins' package.
58         * Add support for the 'picinpar' package.
59         * Improve support for 'subfigure' - Allow to set the various options
60                 that are possible.
61  */
62
63 /* NOTES:
64  * Fileformat:
65  * Current version is 1 (inset file format version), when changing it
66  * it should be changed in the Write() function when writing in one place
67  * and when reading one should change the version check and the error message.
68  * The filename is kept in  the lyx file in a relative way, so as to allow
69  * moving the document file and its images with no problem.
70  * 
71  *
72  * Conversions:
73  *   Postscript output means EPS figures.
74  *
75  *   PDF output is best done with PDF figures if it's a direct conversion
76  *   or PNG figures otherwise.
77  *      Image format
78  *      from        to
79  *      EPS         epstopdf
80  *      PS          ps2pdf
81  *      JPG/PNG     direct
82  *      PDF         direct
83  *      others      PNG
84  */
85
86 #include <config.h> 
87
88 #ifdef __GNUG__
89 #pragma implementation
90 #endif 
91
92 #include "insets/insetgraphics.h"
93 #include "insets/insetgraphicsParams.h"
94
95 #include "graphics/GraphicsCache.h"
96 #include "graphics/GraphicsImage.h"
97
98 #include "LyXView.h"
99 #include "lyxtext.h"
100 #include "buffer.h"
101 #include "BufferView.h"
102 #include "converter.h"
103 #include "Painter.h"
104 #include "lyxrc.h"
105 #include "font.h"    // For the lyxfont class.
106 #include "debug.h"
107 #include "gettext.h"
108 #include "LaTeXFeatures.h"
109
110 #include "frontends/Dialogs.h"
111 #include "frontends/controllers/helper_funcs.h" // getVectorFromString
112
113 #include "support/LAssert.h"
114 #include "support/filetools.h"
115 #include "support/lyxalgo.h" // lyx::count
116
117 #include <algorithm> // For the std::max
118
119 extern string system_tempdir;
120
121 using std::ostream;
122 using std::endl;
123
124 ///////////////////////////////////////////////////////////////////////////
125 int const VersionNumber = 1;
126 ///////////////////////////////////////////////////////////////////////////
127
128 namespace {
129
130 // This function is a utility function
131 // ... that should be with ChangeExtension ...
132 inline
133 string const RemoveExtension(string const & filename)
134 {
135         return ChangeExtension(filename, string());
136 }
137  
138 } // namespace anon
139
140
141 namespace {
142
143 string const unique_id()
144 {
145         static unsigned int seed = 1000;
146
147         ostringstream ost;
148         ost << "graph" << ++seed;
149
150         // Needed if we use lyxstring.
151         return ost.str().c_str();
152 }
153
154 } // namespace anon
155
156
157 InsetGraphics::InsetGraphics()
158         : graphic_label(unique_id()),
159           cached_status_(grfx::ErrorUnknown), cache_filled_(false), old_asc(0)
160           
161 {}
162
163
164 InsetGraphics::InsetGraphics(InsetGraphics const & ig, bool same_id)
165         : Inset(ig, same_id),
166           SigC::Object(),
167           graphic_label(unique_id()),
168           cached_status_(grfx::ErrorUnknown), cache_filled_(false), old_asc(0)
169 {
170         setParams(ig.params());
171         if (same_id)
172                 id_ = ig.id_;
173 }
174
175
176 InsetGraphics::~InsetGraphics()
177 {
178         cached_image_.reset(0);
179         grfx::GCache & gc = grfx::GCache::get();
180         gc.remove(*this);
181
182         // Emits the hide signal to the dialog connected (if any)
183         hideDialog();
184 }
185
186
187 string const InsetGraphics::statusMessage() const
188 {
189         string msg;
190
191         switch (cached_status_) {
192         case grfx::WaitingToLoad:
193                 msg = _("Waiting for draw request to start loading...");
194                 break;
195         case grfx::Loading:
196                 msg = _("Loading...");
197                 break;
198         case grfx::Converting:
199                 msg = _("Converting to loadable format...");
200                 break;
201         case grfx::ScalingEtc:
202                 msg = _("Loaded. Scaling etc...");
203                 break;
204         case grfx::ErrorNoFile:
205                 msg = _("No file found!");
206                 break;
207         case grfx::ErrorLoading:
208                 msg = _("Error loading file into memory");
209                 break;
210         case grfx::ErrorConverting:
211                 msg = _("Error converting to loadable format");
212                 break;
213         case grfx::ErrorScalingEtc:
214                 msg = _("Error scaling etc");
215                 break;
216         case grfx::ErrorUnknown:
217                 msg = _("No image associated with this inset is in the cache!");
218                 break;
219         case grfx::Loaded:
220                 msg = _("Loaded but not displaying");
221                 break;
222         }
223
224         return msg;
225 }
226
227
228 void InsetGraphics::setCache() const
229 {
230         if (cache_filled_)
231                 return;
232
233         grfx::GCache & gc = grfx::GCache::get();
234         cached_status_ = gc.status(*this);
235         cached_image_  = gc.image(*this);
236 }
237
238
239 bool InsetGraphics::drawImage() const
240 {
241         setCache();
242         Pixmap const pixmap =
243                 (cached_status_ == grfx::Loaded && cached_image_.get() != 0) ?
244                 cached_image_->getPixmap() : 0;
245
246         return pixmap != 0;
247 }
248
249         
250 int InsetGraphics::ascent(BufferView *, LyXFont const &) const
251 {
252         old_asc = 50;
253         if (drawImage())
254                 old_asc = cached_image_->getHeight();
255         return old_asc;
256 }
257
258
259 int InsetGraphics::descent(BufferView *, LyXFont const &) const
260 {
261         return 0;
262 }
263
264
265 int InsetGraphics::width(BufferView *, LyXFont const & font) const
266 {
267         if (drawImage())
268                 return cached_image_->getWidth();
269         else {
270                 int font_width = 0;
271
272                 LyXFont msgFont(font);
273                 msgFont.setFamily(LyXFont::SANS_FAMILY);
274
275                 string const justname = OnlyFilename (params().filename);
276                 if (!justname.empty()) {
277                         msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
278                         font_width = lyxfont::width(justname, msgFont);
279                 }
280
281                 string const msg = statusMessage();
282                 if (!msg.empty()) {
283                         msgFont.setSize(LyXFont::SIZE_TINY);
284                         int const msg_width = lyxfont::width(msg, msgFont);
285                         font_width = std::max(font_width, msg_width);
286                 }
287                 
288                 return std::max(50, font_width + 15);
289         }
290 }
291
292
293 void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
294                          int baseline, float & x, bool) const
295 {
296         int oasc = old_asc;
297         
298         int ldescent = descent(bv, font);
299         int lascent  = ascent(bv, font);
300         int lwidth   = width(bv, font);
301
302         // we may have changed while someone other was drawing us so better
303         // to not draw anything as we surely call to redraw ourself soon.
304         // This is not a nice thing to do and should be fixed properly somehow.
305         // But I still don't know the best way to go. So let's do this like this
306         // for now (Jug 20020311)
307         if (lascent != oasc) {
308 //              lyxerr << "IG(" << this << "): " << x << endl;
309                 return;
310         }
311
312         // Make sure now that x is updated upon exit from this routine
313         int old_x = int(x);
314         x += lwidth;
315
316         // Initiate the loading of the graphics file
317         if (cached_status_ == grfx::WaitingToLoad) {
318                 grfx::GCache & gc = grfx::GCache::get();
319                 gc.startLoading(*this);
320         }
321
322         // This will draw the graphics. If the graphics has not been loaded yet,
323         // we draw just a rectangle.
324         Painter & paint = bv->painter();
325         grfx::ImageStatus old_status_ = cached_status_;
326         
327         if (drawImage()) {
328 //              lyxerr << "IG(" << this << "): " << old_x << endl;
329                 paint.image(old_x + 2, baseline - lascent,
330                             lwidth - 4, lascent + ldescent,
331                             *cached_image_.get());
332
333         } else {
334
335                 paint.rectangle(old_x + 2, baseline - lascent,
336                                 lwidth - 4,
337                                 lascent + ldescent);
338
339                 // Print the file name.
340                 LyXFont msgFont(font);
341                 msgFont.setFamily(LyXFont::SANS_FAMILY);
342                 string const justname = OnlyFilename (params().filename);
343                 if (!justname.empty()) {
344                         msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
345                         paint.text(old_x + 8, 
346                                    baseline - lyxfont::maxAscent(msgFont) - 4,
347                                    justname, msgFont);
348                 }
349
350                 // Print the message.
351                 string const msg = statusMessage();
352                 if (!msg.empty()) {
353                         msgFont.setSize(LyXFont::SIZE_TINY);
354                         paint.text(old_x + 8, baseline - 4, msg, msgFont);
355                 }
356         }
357
358         // the status message may mean we changed size, so indicate
359         // we need a row redraw
360         if (old_status_ != cached_status_) {
361                 bv->getLyXText()->status(bv, LyXText::CHANGED_IN_DRAW);
362         }
363  
364         // Reset the cache, ready for the next draw request
365         cached_status_ = grfx::ErrorUnknown;
366         cached_image_.reset(0);
367         cache_filled_ = false;
368 }
369
370
371 // Update the inset after parameters changed (read from file or changed in
372 // dialog. The grfx::GCache makes the decisions about whether or not to draw
373 // (interogates lyxrc, ascertains whether file exists etc)
374 void InsetGraphics::updateInset() const
375 {
376         grfx::GCache & gc = grfx::GCache::get();
377         gc.update(*this);
378 }
379
380
381 void InsetGraphics::edit(BufferView *bv, int, int, unsigned int)
382 {
383         bv->owner()->getDialogs()->showGraphics(this);
384 }
385
386
387 void InsetGraphics::edit(BufferView * bv, bool)
388 {
389         edit(bv, 0, 0, 0);
390 }
391
392
393 Inset::EDITABLE InsetGraphics::editable() const
394 {
395         return IS_EDITABLE;
396 }
397
398
399 void InsetGraphics::write(Buffer const * buf, ostream & os) const
400 {
401         os << "Graphics FormatVersion " << VersionNumber << '\n';
402         params().Write(buf, os);
403 }
404
405
406 void InsetGraphics::read(Buffer const * buf, LyXLex & lex)
407 {
408         string const token = lex.getString();
409
410         if (token == "Graphics")
411                 readInsetGraphics(buf, lex);
412         else if (token == "Figure") // Compatibility reading of FigInset figures.
413                 readFigInset(buf, lex);
414         else
415                 lyxerr[Debug::GRAPHICS] << "Not a Graphics or Figure inset!\n";
416
417         updateInset();
418 }
419
420 void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
421 {
422         bool finished = false;
423
424         while (lex.isOK() && !finished) {
425                 lex.next();
426
427                 string const token = lex.getString();
428                 lyxerr[Debug::GRAPHICS] << "Token: '" << token << '\'' 
429                                     << std::endl;
430
431                 if (token.empty()) {
432                         continue;
433                 } else if (token == "\\end_inset") {
434                         finished = true;
435                 } else if (token == "FormatVersion") {
436                         lex.next();
437                         int version = lex.getInteger();
438                         if (version > VersionNumber)
439                                 lyxerr
440                                 << "This document was created with a newer Graphics widget"
441                                 ", You should use a newer version of LyX to read this"
442                                 " file."
443                                 << std::endl;
444                         // TODO: Possibly open up a dialog?
445                 }
446                 else {
447                         if (! params_.Read(buf, lex, token))
448                                 lyxerr << "Unknown token, " << token << ", skipping." 
449                                         << std::endl;
450                 }
451         }
452 }
453
454 // FormatVersion < 1.0  (LyX < 1.2)
455 void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
456 {
457         std::vector<string> const oldUnits =
458                 getVectorFromString("pt,cm,in,p%,c%");
459         bool finished = false;
460         // set the display default      
461         if (lyxrc.display_graphics == "mono") 
462             params_.display = InsetGraphicsParams::MONOCHROME;
463         else if (lyxrc.display_graphics == "gray") 
464             params_.display = InsetGraphicsParams::GRAYSCALE;
465         else if (lyxrc.display_graphics == "color") 
466             params_.display = InsetGraphicsParams::COLOR;
467         else
468             params_.display = InsetGraphicsParams::NONE;
469         while (lex.isOK() && !finished) {
470                 lex.next();
471
472                 string const token = lex.getString();
473                 lyxerr[Debug::GRAPHICS] << "Token: " << token << endl;
474                 
475                 if (token.empty())
476                         continue;
477                 else if (token == "\\end_inset") {
478                         finished = true;
479                 } else if (token == "file") {
480                         if (lex.next()) {
481                                 string const name = lex.getString();
482                                 string const path = buf->filePath();
483                                 params_.filename = MakeAbsPath(name, path);
484                         }
485                 } else if (token == "extra") {
486                         if (lex.next());
487                         // kept for backwards compability. Delete in 0.13.x
488                 } else if (token == "subcaption") {
489                         if (lex.eatLine())
490                                 params_.subcaptionText = lex.getString();
491                         params_.subcaption = true;
492                 } else if (token == "label") {
493                         if (lex.next());
494                         // kept for backwards compability. Delete in 0.13.x
495                 } else if (token == "angle") {
496                         if (lex.next())
497                                 params_.rotate = true;
498                                 params_.rotateAngle = lex.getFloat();
499                 } else if (token == "size") {
500                         if (lex.next())
501                                 params_.lyxwidth = LyXLength(lex.getString()+"pt");
502                         if (lex.next())
503                                 params_.lyxheight = LyXLength(lex.getString()+"pt");
504                 } else if (token == "flags") {
505                         if (lex.next())
506                                 switch (lex.getInteger()) {
507                                 case 1: params_.display = InsetGraphicsParams::MONOCHROME; 
508                                     break;
509                                 case 2: params_.display = InsetGraphicsParams::GRAYSCALE; 
510                                     break;
511                                 case 3: params_.display = InsetGraphicsParams::COLOR; 
512                                     break;
513                                 }
514                 } else if (token == "subfigure") {
515                         params_.subcaption = true;
516                 } else if (token == "width") {
517                     if (lex.next()) {
518                         int i = lex.getInteger();
519                         if (lex.next()) {
520                             if (i == 5) {
521                                 params_.scale = lex.getInteger();
522                                 params_.size_type = InsetGraphicsParams::SCALE;
523                             } else {
524                                 params_.width = LyXLength(lex.getString()+oldUnits[i]);
525                                 params_.size_type = InsetGraphicsParams::WH;
526                             }
527                         }
528                     }
529                 } else if (token == "height") {
530                     if (lex.next()) {
531                         int i = lex.getInteger();
532                         if (lex.next()) {
533                             params_.height = LyXLength(lex.getString()+oldUnits[i]);
534                             params_.size_type = InsetGraphicsParams::WH;
535                         }
536                     }
537                 }
538         }
539 }
540
541 string const InsetGraphics::createLatexOptions() const
542 {
543         // Calculate the options part of the command, we must do it to a string
544         // stream since we might have a trailing comma that we would like to remove
545         // before writing it to the output stream.
546         ostringstream options;
547         if (!params().bb.empty())
548             options << "  bb=" << strip(params().bb) << ",\n";
549         if (params().draft)
550             options << "  draft,\n";
551         if (params().clip)
552             options << "  clip,\n";
553         if (params().size_type == InsetGraphicsParams::WH) {
554             if (!params().width.zero())
555                 options << "  width=" << params().width.asLatexString() << ",\n";
556             if (!params().height.zero())
557                 options << "  height=" << params().height.asLatexString() << ",\n";
558         } else if (params().size_type == InsetGraphicsParams::SCALE) {
559             if (params().scale > 0)
560                 options << "  scale=" << double(params().scale)/100.0 << ",\n";
561         }
562         if (params().keepAspectRatio)
563             options << "  keepaspectratio,\n";
564         // Make sure it's not very close to zero, a float can be effectively
565         // zero but not exactly zero.
566         if (!lyx::float_equal(params().rotateAngle, 0, 0.001) && params().rotate) {
567             options << "  angle=" << params().rotateAngle << ",\n";
568             if (!params().rotateOrigin.empty()) {
569                 options << "  origin=" << params().rotateOrigin[0];
570                 if (contains(params().rotateOrigin,"Top"))
571                     options << 't';
572                 else if (contains(params().rotateOrigin,"Bottom"))
573                     options << 'b';
574                 else if (contains(params().rotateOrigin,"Baseline"))
575                     options << 'B';
576                 options << ",\n";
577             }
578         }
579         if (!params().special.empty())
580             options << params().special << ",\n";
581         string opts = options.str().c_str();
582         return opts.substr(0,opts.size()-2);    // delete last ",\n"
583 }
584
585 namespace {
586 string findTargetFormat(string const & suffix)
587 {
588         // lyxrc.pdf_mode means:
589         // Are we creating a PDF or a PS file?
590         // (Should actually mean, are we using latex or pdflatex).      
591         lyxerr[Debug::GRAPHICS] << "decideOutput: lyxrc.pdf_mode = "
592                             << lyxrc.pdf_mode << std::endl;
593         if (lyxrc.pdf_mode) {
594                 if (contains(suffix,"ps") || suffix == "pdf")
595                         return "pdf";
596                 else if (suffix == "jpg")
597                         return suffix;
598                 else
599                         return "png";
600         }
601         // If it's postscript, we always do eps.
602         lyxerr[Debug::GRAPHICS] << "decideOutput: we have PostScript mode\n";
603         if (suffix != "ps")
604             return "eps";
605         else
606             return "ps";
607 }
608
609 } // Anon. namespace
610
611
612 string const InsetGraphics::prepareFile(Buffer const *buf) const
613 {
614         // do_convert = Do we need to convert the file?
615         // nice = Do we create a nice version?
616         //        This is used when exporting the latex file only.
617         // if (!do_convert)
618         //   return original filename
619         // if (!nice)
620         //   convert_place = temp directory
621         //   return new filename in temp directory
622         // else
623         //   convert_place = original file directory
624         //   return original filename without the extension
625         //
626         // if it's a zipped one, than let LaTeX do the rest!!!
627         string filename_  = params().filename;
628         bool const zipped = zippedFile(filename_);
629
630         if ((zipped && params().noUnzip) || buf->niceFile) {
631                 lyxerr[Debug::GRAPHICS] << "don't unzip file or export latex" 
632                                     << filename_ << endl;
633                 return filename_;
634         }
635
636         if (zipped)
637                 filename_ = unzipFile(filename_);
638
639         string const from = getExtFromContents(filename_);
640         string const to   = findTargetFormat(from);
641
642         if (from == to) {
643                 // No conversion needed!
644                 return filename_;
645         }
646
647         string const temp = AddName(buf->tmppath, filename_);
648         string const outfile_base = RemoveExtension(temp);
649
650         lyxerr[Debug::GRAPHICS] << "tempname = " << temp << "\n";
651         lyxerr[Debug::GRAPHICS] << "buf::tmppath = " << buf->tmppath << "\n";
652         lyxerr[Debug::GRAPHICS] << "filename_ = " << filename_ << "\n";
653         lyxerr[Debug::GRAPHICS] << "outfile_base = " << outfile_base << endl;
654
655         converters.convert(buf, filename_, outfile_base, from, to);
656         return outfile_base;
657 }
658
659
660 int InsetGraphics::latex(Buffer const *buf, ostream & os,
661                          bool /*fragile*/, bool/*fs*/) const
662 {
663         // If there is no file specified, just output a message about it in
664         // the latex output.
665         if (params().filename.empty()) {
666                 os  << "\\fbox{\\rule[-0.5in]{0pt}{1in}"
667                         << _("empty figure path") << "}\n";
668                 return 1; // One end of line marker added to the stream.
669         }
670         // These variables collect all the latex code that should be before and
671         // after the actual includegraphics command.
672         string before;
673         string after;
674         // Do we want subcaptions?
675         if (params().subcaption) {
676                 before += "\\subfigure[" + params().subcaptionText + "]{";
677                 after = '}';
678         }
679         // We never use the starred form, we use the "clip" option instead.
680         before += "\\includegraphics";
681         // Write the options if there are any.
682         string const opts = createLatexOptions();
683         if (!opts.empty()) {
684                 before += ("[%\n" + opts +']');
685         }
686         // Make the filename relative to the lyx file
687         // and remove the extension so the LaTeX will use whatever is
688         // appropriate (when there are several versions in different formats)
689         string const latex_str = before + '{' + prepareFile(buf) + '}' + after;
690         os << latex_str;
691
692         // Return how many newlines we issued.
693         int const newlines =
694                 int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1);
695                 
696         // lyxerr << "includegraphics: " << newlines << " lines of text"
697         //        << endl; 
698         return newlines;
699 }
700
701
702 int InsetGraphics::ascii(Buffer const *, ostream & os, int) const
703 {
704         // No graphics in ascii output. Possible to use gifscii to convert
705         // images to ascii approximation.
706         // 1. Convert file to ascii using gifscii
707         // 2. Read ascii output file and add it to the output stream.
708         // at least we send the filename
709         os << '<' << _("Graphicfile:") << params().filename << ">\n";
710         return 0;
711 }
712
713
714 int InsetGraphics::linuxdoc(Buffer const *, ostream &) const
715 {
716         // No graphics in LinuxDoc output. Should check how/what to add.
717         return 0;
718 }
719
720
721 // For explanation on inserting graphics into DocBook checkout:
722 // http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html
723 // See also the docbook guide at http://www.docbook.org/
724 int InsetGraphics::docbook(Buffer const *, ostream & os) const
725 {
726         // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will 
727         // need to switch to MediaObject. However, for now this is sufficient and 
728         // easier to use.
729         os << "<graphic fileref=\"&" << graphic_label << ";\">";
730         return 0;
731 }
732
733
734 void InsetGraphics::validate(LaTeXFeatures & features) const
735 {
736         // If we have no image, we should not require anything.
737         if (params().filename.empty())
738                 return ;
739
740         features.includeFile(graphic_label, RemoveExtension(params_.filename));
741
742         features.require("graphicx");
743
744         if (params().subcaption)
745                 features.require("subfigure");
746 }
747
748
749 bool InsetGraphics::setParams(InsetGraphicsParams const & p)
750 {
751         // If nothing is changed, just return and say so.
752         if (params() == p && !p.filename.empty()) {
753                 return false;
754         }
755
756         // Copy the new parameters.
757         params_ = p;
758
759         // Update the inset with the new parameters.
760         updateInset();
761
762         // We have changed data, report it.
763         return true;
764 }
765
766
767 InsetGraphicsParams const & InsetGraphics::params() const
768 {
769         return params_;
770 }
771
772
773 Inset * InsetGraphics::clone(Buffer const &, bool same_id) const
774 {
775         return new InsetGraphics(*this, same_id);
776 }