4 #include "support/systemcall.h"
5 #include "graphics/GraphicsTypes.h"
6 #include "graphics/GraphicsImage.h"
7 #include "graphics/GraphicsCache.h"
8 #include "graphics/GraphicsImage.h"
9 #include "graphics/GraphicsParams.h"
10 #include "graphics/GraphicsCacheItem.h"
15 #include <boost/utility.hpp>
16 #include <boost/bind.hpp>
21 // built some unique filename
22 string canonical_name(string const & str)
25 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
26 os << char('A' + (*it & 15)) << char('a' + (*it >> 4));
31 bool preview(string const & str, grfx::GraphicPtr & graphic)
33 string base = canonical_name(str);
34 string dir = "/tmp/lyx/";
35 string file = dir + base + ".eps";
36 cerr << "writing '" << str << "' to '" << file << "'\n";
39 grfx::GCache & gc = grfx::GCache::get();
42 if (gc.inCache(file)) {
44 // it's already in there. Get hold of it.
45 grfx::GraphicPtr gr = grfx::GraphicPtr(gc.graphic(file));
47 // is it already loaded?
48 if (gr->status() == grfx::Loaded) {
49 cerr << "file '" << file << "' ready for display\n";
52 bool const res = graphic->image()->setPixmap(pars);
56 // otherwise we have to wait again
57 cerr << "file '" << file << "' not finished loading\n";
61 // The real work starts.
62 string const texfile = dir + base + ".tex";
63 std::ofstream of(texfile.c_str());
65 << "\\documentclass{article}"
66 << "\\usepackage{amssymb}"
67 << "\\thispagestyle{empty}"
69 << "\\begin{document}"
71 << "\\end{document}\n";
75 // "latex " + base + ".tex ; " + "
76 // "dvips -x 2500 -R -E -o " + base + ".eps " + base + ".dvi ";
77 // Herbert says this is faster
78 "pdflatex --interaction batchmode " + base + "; " +
79 "dvips -x 2000 -R -E -o " + base + ".eps " + base + ".dvi ";
80 //cerr << "calling: '" << "(cd " + dir + "; " + cmd + ")\n";
82 sc.startscript(Systemcall::Wait, "(cd " + dir + "; " + cmd + ")");
84 // now we are done, add the file to the cache
86 gc.graphic(file)->startLoading();
88 // This might take a while. Wait for the next round.
89 cerr << "file '" << file << "' registered\n";