]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewLoader.cpp
7d1cb5466c46878940e4fe609f7bf931eab39015
[lyx.git] / src / graphics / PreviewLoader.cpp
1 /**
2  * \file PreviewLoader.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "PreviewLoader.h"
14 #include "PreviewImage.h"
15 #include "GraphicsCache.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Converter.h"
20 #include "Encoding.h"
21 #include "Format.h"
22 #include "InsetIterator.h"
23 #include "LaTeXFeatures.h"
24 #include "LyXRC.h"
25 #include "output.h"
26 #include "OutputParams.h"
27 #include "TexRow.h"
28
29 #include "frontends/Application.h" // hexName
30
31 #include "insets/Inset.h"
32
33 #include "support/convert.h"
34 #include "support/debug.h"
35 #include "support/FileName.h"
36 #include "support/filetools.h"
37 #include "support/ForkedCalls.h"
38 #include "support/lstrings.h"
39
40 #include "support/bind.h"
41 #include "support/TempFile.h"
42
43 #include <sstream>
44 #include <fstream>
45 #include <iomanip>
46
47 using namespace std;
48 using namespace lyx::support;
49
50
51
52 namespace {
53
54 typedef pair<string, FileName> SnippetPair;
55
56 // A list of all snippets to be converted to previews
57 typedef list<string> PendingSnippets;
58
59 // Each item in the vector is a pair<snippet, image file name>.
60 typedef vector<SnippetPair> BitmapFile;
61
62
63 FileName const unique_tex_filename(FileName const & bufferpath)
64 {
65         TempFile tempfile(bufferpath, "lyxpreviewXXXXXX.tex");
66         tempfile.setAutoRemove(false);
67         return tempfile.name();
68 }
69
70
71 lyx::Converter const * setConverter(string const & from)
72 {
73         typedef vector<string> FmtList;
74         typedef lyx::graphics::Cache GCache;
75         FmtList const & loadableFormats = GCache::get().loadableFormats();
76         FmtList::const_iterator it = loadableFormats.begin();
77         FmtList::const_iterator const end = loadableFormats.end();
78
79         for (; it != end; ++it) {
80                 string const to = *it;
81                 if (from == to)
82                         continue;
83
84                 lyx::Converter const * ptr = lyx::theConverters().getConverter(from, to);
85                 if (ptr)
86                         return ptr;
87         }
88
89         // FIXME THREAD
90         static bool first = true;
91         if (first) {
92                 first = false;
93                 LYXERR0("PreviewLoader::startLoading()\n"
94                         << "No converter from \"" << from << "\" format has been defined.");
95         }
96         return 0;
97 }
98
99
100 void setAscentFractions(vector<double> & ascent_fractions,
101                         FileName const & metrics_file)
102 {
103         // If all else fails, then the images will have equal ascents and
104         // descents.
105         vector<double>::iterator it  = ascent_fractions.begin();
106         vector<double>::iterator end = ascent_fractions.end();
107         fill(it, end, 0.5);
108
109         ifstream in(metrics_file.toFilesystemEncoding().c_str());
110         if (!in.good()) {
111                 LYXERR(lyx::Debug::GRAPHICS, "setAscentFractions(" << metrics_file << ")\n"
112                         << "Unable to open file!");
113                 return;
114         }
115
116         bool error = false;
117
118         int snippet_counter = 1;
119         while (!in.eof() && it != end) {
120                 string snippet;
121                 int id;
122                 double ascent_fraction;
123
124                 in >> snippet >> id >> ascent_fraction;
125
126                 if (!in.good())
127                         // eof after all
128                         break;
129
130                 error = snippet != "Snippet";
131                 if (error)
132                         break;
133
134                 error = id != snippet_counter;
135                 if (error)
136                         break;
137
138                 *it = ascent_fraction;
139
140                 ++snippet_counter;
141                 ++it;
142         }
143
144         if (error) {
145                 LYXERR(lyx::Debug::GRAPHICS, "setAscentFractions(" << metrics_file << ")\n"
146                         << "Error reading file!\n");
147         }
148 }
149
150
151 class FindFirst
152 {
153 public:
154         FindFirst(string const & comp) : comp_(comp) {}
155         bool operator()(SnippetPair const & sp) const { return sp.first == comp_; }
156 private:
157         string const comp_;
158 };
159
160
161 /// Store info on a currently executing, forked process.
162 class InProgress {
163 public:
164         ///
165         InProgress() : pid(0) {}
166         ///
167         InProgress(string const & filename_base,
168                    PendingSnippets const & pending,
169                    string const & to_format);
170         /// Remove any files left lying around and kill the forked process.
171         void stop() const;
172
173         ///
174         pid_t pid;
175         ///
176         string command;
177         ///
178         FileName metrics_file;
179         ///
180         BitmapFile snippets;
181 };
182
183 typedef map<pid_t, InProgress>  InProgressProcesses;
184
185 typedef InProgressProcesses::value_type InProgressProcess;
186
187 } // namespace anon
188
189
190
191 namespace lyx {
192 namespace graphics {
193
194 class PreviewLoader::Impl : public boost::signals::trackable {
195 public:
196         ///
197         Impl(PreviewLoader & p, Buffer const & b);
198         /// Stop any InProgress items still executing.
199         ~Impl();
200         ///
201         PreviewImage const * preview(string const & latex_snippet) const;
202         ///
203         PreviewLoader::Status status(string const & latex_snippet) const;
204         ///
205         void add(string const & latex_snippet);
206         ///
207         void remove(string const & latex_snippet);
208         /// \p wait whether to wait for the process to complete or, instead,
209         /// to do it in the background.
210         void startLoading(bool wait = false);
211
212         /// Emit this signal when an image is ready for display.
213         boost::signal<void(PreviewImage const &)> imageReady;
214
215         Buffer const & buffer() const { return buffer_; }
216
217 private:
218         /// Called by the ForkedCall process that generated the bitmap files.
219         void finishedGenerating(pid_t, int);
220         ///
221         void dumpPreamble(otexstream &, OutputParams::FLAVOR) const;
222         ///
223         void dumpData(odocstream &, BitmapFile const &) const;
224
225         /** cache_ allows easy retrieval of already-generated images
226          *  using the LaTeX snippet as the identifier.
227          */
228         typedef shared_ptr<PreviewImage> PreviewImagePtr;
229         ///
230         typedef map<string, PreviewImagePtr> Cache;
231         ///
232         Cache cache_;
233
234         /** pending_ stores the LaTeX snippets in anticipation of them being
235          *  sent to the converter.
236          */
237         PendingSnippets pending_;
238
239         /** in_progress_ stores all forked processes so that we can proceed
240          *  thereafter.
241             The map uses the conversion commands as its identifiers.
242          */
243         InProgressProcesses in_progress_;
244
245         ///
246         PreviewLoader & parent_;
247         ///
248         Buffer const & buffer_;
249         ///
250         mutable int font_scaling_factor_;
251
252         /// We don't own this
253         static lyx::Converter const * pconverter_;
254 };
255
256
257 lyx::Converter const * PreviewLoader::Impl::pconverter_;
258
259
260 //
261 // The public interface, defined in PreviewLoader.h
262 //
263
264 PreviewLoader::PreviewLoader(Buffer const & b)
265         : pimpl_(new Impl(*this, b))
266 {}
267
268
269 PreviewLoader::~PreviewLoader()
270 {
271         delete pimpl_;
272 }
273
274
275 PreviewImage const * PreviewLoader::preview(string const & latex_snippet) const
276 {
277         return pimpl_->preview(latex_snippet);
278 }
279
280
281 PreviewLoader::Status PreviewLoader::status(string const & latex_snippet) const
282 {
283         return pimpl_->status(latex_snippet);
284 }
285
286
287 void PreviewLoader::add(string const & latex_snippet) const
288 {
289         pimpl_->add(latex_snippet);
290 }
291
292
293 void PreviewLoader::remove(string const & latex_snippet) const
294 {
295         pimpl_->remove(latex_snippet);
296 }
297
298
299 void PreviewLoader::startLoading(bool wait) const
300 {
301         pimpl_->startLoading(wait);
302 }
303
304
305 boost::signals::connection PreviewLoader::connect(slot_type const & slot) const
306 {
307         return pimpl_->imageReady.connect(slot);
308 }
309
310
311 void PreviewLoader::emitSignal(PreviewImage const & pimage) const
312 {
313         pimpl_->imageReady(pimage);
314 }
315
316
317 Buffer const & PreviewLoader::buffer() const
318 {
319         return pimpl_->buffer();
320 }
321
322 } // namespace graphics
323 } // namespace lyx
324
325
326 // The details of the Impl
327 // =======================
328
329 namespace {
330
331 class IncrementedFileName {
332 public:
333         IncrementedFileName(string const & to_format,
334                             string const & filename_base)
335                 : to_format_(to_format), base_(filename_base), counter_(1)
336         {}
337
338         SnippetPair const operator()(string const & snippet)
339         {
340                 ostringstream os;
341                 os << base_ << counter_++ << '.' << to_format_;
342                 string const file = os.str();
343
344                 return make_pair(snippet, FileName(file));
345         }
346
347 private:
348         string const & to_format_;
349         string const & base_;
350         int counter_;
351 };
352
353
354 InProgress::InProgress(string const & filename_base,
355                        PendingSnippets const & pending,
356                        string const & to_format)
357         : pid(0),
358           metrics_file(filename_base + ".metrics"),
359           snippets(pending.size())
360 {
361         PendingSnippets::const_iterator pit  = pending.begin();
362         PendingSnippets::const_iterator pend = pending.end();
363         BitmapFile::iterator sit = snippets.begin();
364
365         transform(pit, pend, sit,
366                        IncrementedFileName(to_format, filename_base));
367 }
368
369
370 void InProgress::stop() const
371 {
372         if (pid)
373                 ForkedCallsController::kill(pid, 0);
374
375         if (!metrics_file.empty())
376                 metrics_file.removeFile();
377
378         BitmapFile::const_iterator vit  = snippets.begin();
379         BitmapFile::const_iterator vend = snippets.end();
380         for (; vit != vend; ++vit) {
381                 if (!vit->second.empty())
382                         vit->second.removeFile();
383         }
384 }
385
386 } // namespace anon
387
388
389 namespace lyx {
390 namespace graphics {
391
392 PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
393         : parent_(p), buffer_(b)
394 {
395         font_scaling_factor_ = int(buffer_.fontScalingFactor());
396         if (!pconverter_)
397                 pconverter_ = setConverter("lyxpreview");
398 }
399
400
401 PreviewLoader::Impl::~Impl()
402 {
403         InProgressProcesses::iterator ipit  = in_progress_.begin();
404         InProgressProcesses::iterator ipend = in_progress_.end();
405
406         for (; ipit != ipend; ++ipit)
407                 ipit->second.stop();
408 }
409
410
411 PreviewImage const *
412 PreviewLoader::Impl::preview(string const & latex_snippet) const
413 {
414         int fs = int(buffer_.fontScalingFactor());
415         if (font_scaling_factor_ != fs) {
416                 // Refresh all previews on zoom changes
417                 font_scaling_factor_ = fs;
418                 Cache::const_iterator cit = cache_.begin();
419                 Cache::const_iterator cend = cache_.end();
420                 while (cit != cend)
421                         parent_.remove((cit++)->first);
422                 buffer_.updatePreviews();
423         }
424         Cache::const_iterator it = cache_.find(latex_snippet);
425         return (it == cache_.end()) ? 0 : it->second.get();
426 }
427
428
429 namespace {
430
431 class FindSnippet {
432 public:
433         FindSnippet(string const & s) : snippet_(s) {}
434         bool operator()(InProgressProcess const & process) const
435         {
436                 BitmapFile const & snippets = process.second.snippets;
437                 BitmapFile::const_iterator beg  = snippets.begin();
438                 BitmapFile::const_iterator end = snippets.end();
439                 return find_if(beg, end, FindFirst(snippet_)) != end;
440         }
441
442 private:
443         string const snippet_;
444 };
445
446 } // namespace anon
447
448 PreviewLoader::Status
449 PreviewLoader::Impl::status(string const & latex_snippet) const
450 {
451         Cache::const_iterator cit = cache_.find(latex_snippet);
452         if (cit != cache_.end())
453                 return Ready;
454
455         PendingSnippets::const_iterator pit  = pending_.begin();
456         PendingSnippets::const_iterator pend = pending_.end();
457
458         pit = find(pit, pend, latex_snippet);
459         if (pit != pend)
460                 return InQueue;
461
462         InProgressProcesses::const_iterator ipit  = in_progress_.begin();
463         InProgressProcesses::const_iterator ipend = in_progress_.end();
464
465         ipit = find_if(ipit, ipend, FindSnippet(latex_snippet));
466         if (ipit != ipend)
467                 return Processing;
468
469         return NotFound;
470 }
471
472
473 void PreviewLoader::Impl::add(string const & latex_snippet)
474 {
475         if (!pconverter_ || status(latex_snippet) != NotFound)
476                 return;
477
478         string const snippet = trim(latex_snippet);
479         if (snippet.empty())
480                 return;
481
482         LYXERR(Debug::GRAPHICS, "adding snippet:\n" << snippet);
483
484         pending_.push_back(snippet);
485 }
486
487
488 namespace {
489
490 class EraseSnippet {
491 public:
492         EraseSnippet(string const & s) : snippet_(s) {}
493         void operator()(InProgressProcess & process)
494         {
495                 BitmapFile & snippets = process.second.snippets;
496                 BitmapFile::iterator it  = snippets.begin();
497                 BitmapFile::iterator end = snippets.end();
498
499                 it = find_if(it, end, FindFirst(snippet_));
500                 if (it != end)
501                         snippets.erase(it, it+1);
502         }
503
504 private:
505         string const & snippet_;
506 };
507
508 } // namespace anon
509
510
511 void PreviewLoader::Impl::remove(string const & latex_snippet)
512 {
513         Cache::iterator cit = cache_.find(latex_snippet);
514         if (cit != cache_.end())
515                 cache_.erase(cit);
516
517         PendingSnippets::iterator pit  = pending_.begin();
518         PendingSnippets::iterator pend = pending_.end();
519
520         pending_.erase(std::remove(pit, pend, latex_snippet), pend);
521
522         InProgressProcesses::iterator ipit  = in_progress_.begin();
523         InProgressProcesses::iterator ipend = in_progress_.end();
524
525         for_each(ipit, ipend, EraseSnippet(latex_snippet));
526
527         while (ipit != ipend) {
528                 InProgressProcesses::iterator curr = ipit++;
529                 if (curr->second.snippets.empty())
530                         in_progress_.erase(curr);
531         }
532 }
533
534
535 void PreviewLoader::Impl::startLoading(bool wait)
536 {
537         if (pending_.empty() || !pconverter_)
538                 return;
539
540         // Only start the process off after the buffer is loaded from file.
541         if (!buffer_.isFullyLoaded())
542                 return;
543
544         LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()");
545
546         // As used by the LaTeX file and by the resulting image files
547         FileName const directory(buffer_.temppath());
548
549         FileName const latexfile = unique_tex_filename(directory);
550         string const filename_base = removeExtension(latexfile.absFileName());
551
552         // Create an InProgress instance to place in the map of all
553         // such processes if it starts correctly.
554         InProgress inprogress(filename_base, pending_, pconverter_->to());
555
556         // clear pending_, so we're ready to start afresh.
557         pending_.clear();
558
559         // Output the LaTeX file.
560         // we use the encoding of the buffer
561         Encoding const & enc = buffer_.params().encoding();
562         ofdocstream of;
563         try { of.reset(enc.iconvName()); }
564         catch (iconv_codecvt_facet_exception const & e) {
565                 LYXERR0("Caught iconv exception: " << e.what()
566                         << "\nUnable to create LaTeX file: " << latexfile);
567                 return;
568         }
569
570         TexRow texrow;
571         otexstream os(of, texrow);
572         OutputParams runparams(&enc);
573         LaTeXFeatures features(buffer_, buffer_.params(), runparams);
574
575         if (!openFileWrite(of, latexfile))
576                 return;
577
578         if (!of) {
579                 LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
580                                         << "Unable to create LaTeX file\n" << latexfile);
581                 return;
582         }
583         of << "\\batchmode\n";
584
585         LYXERR(Debug::LATEX, "Format = " << buffer_.params().getDefaultOutputFormat());
586         string latexparam = "";
587         bool docformat = !buffer_.params().default_output_format.empty()
588                         && buffer_.params().default_output_format != "default";
589         // Use LATEX flavor if the document does not specify a specific
590         // output format (see bug 9371).
591         OutputParams::FLAVOR flavor = docformat
592                                         ? buffer_.params().getOutputFlavor()
593                                         : OutputParams::LATEX;
594         if (buffer_.params().encoding().package() == Encoding::japanese) {
595                 latexparam = " --latex=platex";
596                 flavor = OutputParams::LATEX;
597         }
598         else if (buffer_.params().useNonTeXFonts) {
599                 if (flavor == OutputParams::LUATEX)
600                         latexparam = " --latex=lualatex";
601                 else {
602                         flavor = OutputParams::XETEX;
603                         latexparam = " --latex=xelatex";
604                 }
605         }
606         else {
607                 switch (flavor) {
608                         case OutputParams::PDFLATEX:
609                                 latexparam = " --latex=pdflatex";
610                                 break;
611                         case OutputParams::XETEX:
612                                 latexparam = " --latex=xelatex";
613                                 break;
614                         case OutputParams::LUATEX:
615                                 latexparam = " --latex=lualatex";
616                                 break;
617                         case OutputParams::DVILUATEX:
618                                 latexparam = " --latex=dvilualatex";
619                                 break;
620                         default:
621                                 flavor = OutputParams::LATEX;
622                 }
623         }
624         dumpPreamble(os, flavor);
625         // handle inputenc etc.
626         // I think, this is already hadled by dumpPreamble(): Kornel
627         // buffer_.params().writeEncodingPreamble(os, features);
628         of << "\n\\begin{document}\n";
629         dumpData(of, inprogress.snippets);
630         of << "\n\\end{document}\n";
631         of.close();
632         if (of.fail()) {
633                 LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
634                                          << "File was not closed properly.");
635                 return;
636         }
637
638         // The conversion command.
639         ostringstream cs;
640         cs << pconverter_->command()
641            << " " << quoteName(latexfile.toFilesystemEncoding())
642            << " --dpi " << font_scaling_factor_;
643
644         // FIXME XHTML 
645         // The colors should be customizable.
646         if (!buffer_.isExporting()) {
647                 ColorCode const fg = PreviewLoader::foregroundColor();
648                 ColorCode const bg = PreviewLoader::backgroundColor();
649                 cs << " --fg " << theApp()->hexName(fg) 
650                    << " --bg " << theApp()->hexName(bg);
651         }
652
653         cs << latexparam;
654         if (buffer_.params().bibtex_command != "default")
655                 cs << " --bibtex=" << quoteName(buffer_.params().bibtex_command);
656         else if (buffer_.params().encoding().package() == Encoding::japanese)
657                 cs << " --bibtex=" << quoteName(lyxrc.jbibtex_command);
658         else
659                 cs << " --bibtex=" << quoteName(lyxrc.bibtex_command);
660         if (buffer_.params().bufferFormat() == "lilypond-book")
661                 cs << " --lilypond";
662
663         string const command = cs.str();
664
665         if (wait) {
666                 ForkedCall call(buffer_.filePath());
667                 int ret = call.startScript(ForkedProcess::Wait, command);
668                 // FIXME THREAD
669                 static int fake = (2^20) + 1;
670                 int pid = fake++;
671                 inprogress.pid = pid;
672                 inprogress.command = command;
673                 in_progress_[pid] = inprogress;
674                 finishedGenerating(pid, ret);
675                 return;
676         }
677
678         // Initiate the conversion from LaTeX to bitmap images files.
679         ForkedCall::SignalTypePtr
680                 convert_ptr(new ForkedCall::SignalType);
681         convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));
682
683         ForkedCall call(buffer_.filePath());
684         int ret = call.startScript(command, convert_ptr);
685
686         if (ret != 0) {
687                 LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
688                                         << "Unable to start process\n" << command);
689                 return;
690         }
691
692         // Store the generation process in a list of all such processes
693         inprogress.pid = call.pid();
694         inprogress.command = command;
695         in_progress_[inprogress.pid] = inprogress;
696 }
697
698
699 double PreviewLoader::displayPixelRatio() const
700 {
701         return buffer().params().display_pixel_ratio;
702 }
703
704 void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
705 {
706         // Paranoia check!
707         InProgressProcesses::iterator git = in_progress_.find(pid);
708         if (git == in_progress_.end()) {
709                 lyxerr << "PreviewLoader::finishedGenerating(): unable to find "
710                         "data for PID " << pid << endl;
711                 return;
712         }
713
714         string const command = git->second.command;
715         string const status = retval > 0 ? "failed" : "succeeded";
716         LYXERR(Debug::GRAPHICS, "PreviewLoader::finishedInProgress("
717                                 << retval << "): processing " << status
718                                 << " for " << command);
719         if (retval > 0)
720                 return;
721
722         // Read the metrics file, if it exists
723         vector<double> ascent_fractions(git->second.snippets.size());
724         setAscentFractions(ascent_fractions, git->second.metrics_file);
725
726         // Add these newly generated bitmap files to the cache and
727         // start loading them into LyX.
728         BitmapFile::const_iterator it  = git->second.snippets.begin();
729         BitmapFile::const_iterator end = git->second.snippets.end();
730
731         list<PreviewImagePtr> newimages;
732
733         int metrics_counter = 0;
734         for (; it != end; ++it, ++metrics_counter) {
735                 string const & snip = it->first;
736                 FileName const & file = it->second;
737                 double af = ascent_fractions[metrics_counter];
738
739                 // Add the image to the cache only if it's actually present
740                 // and not empty (an empty image is signaled by af < 0)
741                 if (af >= 0 && file.isReadableFile()) {
742                         PreviewImagePtr ptr(new PreviewImage(parent_, snip, file, af));
743                         cache_[snip] = ptr;
744
745                         newimages.push_back(ptr);
746                 }
747
748         }
749
750         // Remove the item from the list of still-executing processes.
751         in_progress_.erase(git);
752
753         // Tell the outside world
754         list<PreviewImagePtr>::const_reverse_iterator
755                 nit  = newimages.rbegin();
756         list<PreviewImagePtr>::const_reverse_iterator
757                 nend = newimages.rend();
758         for (; nit != nend; ++nit) {
759                 imageReady(*nit->get());
760         }
761 }
762
763
764 void PreviewLoader::Impl::dumpPreamble(otexstream & os, OutputParams::FLAVOR flavor) const
765 {
766         // Dump the preamble only.
767         LYXERR(Debug::LATEX, "dumpPreamble, flavor == " << flavor);
768         OutputParams runparams(&buffer_.params().encoding());
769         runparams.flavor = flavor;
770         runparams.nice = true;
771         runparams.moving_arg = true;
772         runparams.free_spacing = true;
773         runparams.is_child = buffer_.parent();
774         buffer_.writeLaTeXSource(os, buffer_.filePath(), runparams, Buffer::OnlyPreamble);
775
776         // FIXME! This is a HACK! The proper fix is to control the 'true'
777         // passed to WriteStream below:
778         // int InsetMathNest::latex(Buffer const &, odocstream & os,
779         //                          OutputParams const & runparams) const
780         // {
781         //      WriteStream wi(os, runparams.moving_arg, true);
782         //      par_->write(wi);
783         //      return wi.line();
784         // }
785         os << "\n"
786            << "\\def\\lyxlock{}\n"
787            << "\n";
788
789         // All equation labels appear as "(#)" + preview.sty's rendering of
790         // the label name
791         if (lyxrc.preview_hashed_labels)
792                 os << "\\renewcommand{\\theequation}{\\#}\n";
793
794         // Use the preview style file to ensure that each snippet appears on a
795         // fresh page.
796         // Also support PDF output (automatically generated e.g. when
797         // \usepackage[pdftex]{hyperref} is used and XeTeX.
798         os << "\n"
799            << "\\usepackage[active,delayed,showlabels,lyx]{preview}\n"
800            << "\n";
801 }
802
803
804 void PreviewLoader::Impl::dumpData(odocstream & os,
805                                    BitmapFile const & vec) const
806 {
807         if (vec.empty())
808                 return;
809
810         BitmapFile::const_iterator it  = vec.begin();
811         BitmapFile::const_iterator end = vec.end();
812
813         for (; it != end; ++it) {
814                 // FIXME UNICODE
815                 os << "\\begin{preview}\n"
816                    << from_utf8(it->first)
817                    << "\n\\end{preview}\n\n";
818         }
819 }
820
821 } // namespace graphics
822 } // namespace lyx