6 #include "frontends/Painter.h"
7 #include "support/systemcall.h"
8 #include "graphics/GraphicsTypes.h"
9 #include "graphics/GraphicsImage.h"
10 #include "graphics/GraphicsImageXPM.h"
21 typedef map<string, grfx::ImagePtr> previews_map;
23 // cache for computed previews
24 previews_map thePreviews;
26 // cache for scedule previews
27 vector<string> theSchedule;
36 grfx::ImagePtr preview(string const & str)
38 // do we already have access to a rendered version?
39 previews_map::const_iterator it = thePreviews.find(str);
40 if (it != thePreviews.end())
43 // constructing new item
44 grfx::ImagePtr & im = thePreviews[str];
46 lyxerr << "writing: " << str << endl;
47 std::ofstream of("/tmp/previewlyx.tex");
48 of << "\\documentclass{article}"
49 << "\\usepackage{amssymb}"
50 << "\\thispagestyle{empty}"
51 << "\\begin{document}"
53 << "\\end{document}\n";
57 sc1.startscript(Systemcall::Wait,
58 "(cd /tmp ; latex previewlyx.tex ; dvips previewlyx.dvi)");
61 sc2.startscript(Systemcall::Wait,
62 "(cd /tmp ; convert previewlyx.ps previewlyx.xpm)");
64 //grfx::SignalLoadTypePtr on_finish;
65 //on_finish.reset(new SignalLoadType);
66 //on_finish->connect(SigC::slot(this, &imageLoaded));
69 XpmImage * xpm_image = new XpmImage;
71 XpmReadFileToXpmImage("/tmp/previewlyx.ps", xpm_image, 0);
75 lyxerr[Debug::GRAPHICS]
76 << "No XPM image file found." << std::endl;
80 lyxerr[Debug::GRAPHICS]
81 << "File format is invalid" << std::endl;
85 lyxerr[Debug::GRAPHICS]
86 << "Insufficient memory to read in XPM file"
91 if (success != XpmSuccess) {
92 XpmFreeXpmImage(xpm_image);
95 lyxerr[Debug::GRAPHICS]
96 << "Error reading XPM file '"
97 << XpmGetErrorString(success) << "'"
100 //grfx::GImageXPM * xim = static_cast<grfx::GImageXPM *>(im.get());
101 //xim->image_.reset(*xpm_image);