mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-07 17:55:30 +00:00
first shot at preview. It crashes. Don't know why. To see it work a bit, change
formula.C:191, to see it crash remove the comment further down. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4482 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7ab5764176
commit
6aa8d56bdd
@ -43,6 +43,8 @@
|
|||||||
#include "textpainter.h"
|
#include "textpainter.h"
|
||||||
#include "preview.h"
|
#include "preview.h"
|
||||||
|
|
||||||
|
#include "graphics/GraphicsCacheItem.h"
|
||||||
|
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
using std::istream;
|
using std::istream;
|
||||||
@ -190,8 +192,11 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
|
|||||||
ostringstream os;
|
ostringstream os;
|
||||||
WriteStream wi(os, false, false);
|
WriteStream wi(os, false, false);
|
||||||
par_->write(wi);
|
par_->write(wi);
|
||||||
if (grfx::ImagePtr image = preview(os.str()))
|
if (preview(os.str(), preview_) && preview_.get()) {
|
||||||
pain.image(x, y, w, h, *image);
|
cerr << "image could be drawn\n";
|
||||||
|
// LyX crashes if we try that. Why? Andre'
|
||||||
|
//pi.pain.image(x, y, w, h, *(preview_->image()));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
xx += par_->width();
|
xx += par_->width();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "formulabase.h"
|
#include "formulabase.h"
|
||||||
#include "math_defs.h"
|
#include "math_defs.h"
|
||||||
#include "math_atom.h"
|
#include "math_atom.h"
|
||||||
|
#include "graphics/GraphicsTypes.h"
|
||||||
|
|
||||||
class MathHullInset;
|
class MathHullInset;
|
||||||
|
|
||||||
@ -89,7 +90,9 @@ private:
|
|||||||
///
|
///
|
||||||
void handleExtern(string const & arg);
|
void handleExtern(string const & arg);
|
||||||
|
|
||||||
///
|
/// contents
|
||||||
MathAtom par_;
|
MathAtom par_;
|
||||||
|
/// LaTeX preview
|
||||||
|
mutable grfx::GraphicPtr preview_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,71 +1,63 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "formula.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "frontends/Painter.h"
|
|
||||||
#include "support/systemcall.h"
|
#include "support/systemcall.h"
|
||||||
#include "graphics/GraphicsTypes.h"
|
#include "graphics/GraphicsTypes.h"
|
||||||
#include "graphics/GraphicsImage.h"
|
#include "graphics/GraphicsImage.h"
|
||||||
#include "graphics/GraphicsImageXPM.h"
|
|
||||||
#include "graphics/GraphicsCacheItem.h"
|
|
||||||
#include "graphics/GraphicsCache.h"
|
#include "graphics/GraphicsCache.h"
|
||||||
|
#include "graphics/GraphicsCacheItem.h"
|
||||||
|
#include "Lsstream.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
|
#include <boost/utility.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
// built some unique filename
|
||||||
|
string canonical_name(string const & str)
|
||||||
typedef map<string, grfx::ImagePtr> previews_map;
|
{
|
||||||
|
ostringstream os;
|
||||||
// cache for computed previews
|
for (string::const_iterator it = str.begin(); it != str.end(); ++it)
|
||||||
previews_map thePreviews;
|
os << char('A' + (*it & 15)) << char('a' + (*it >> 4));
|
||||||
|
return os.str();
|
||||||
// cache for scheduled previews
|
|
||||||
vector<string> theSchedule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
bool preview(string const & str, grfx::GraphicPtr & graphic)
|
||||||
class PreviewCallbackLoaded {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
PreviewCallbackLoaded(string const & filename)
|
|
||||||
: image_(grfx::GImageXPM::newImage())
|
|
||||||
{
|
|
||||||
lyxerr[Debug::GRAPHICS] << "Loading image." << endl;
|
|
||||||
|
|
||||||
grfx::GImage::SignalTypePtr s(new grfx::GImage::SignalType(&PreviewCallbackLoaded::imageLoaded));
|
|
||||||
image_->load(filename, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
void imageLoaded(bool result)
|
|
||||||
{
|
|
||||||
lyxerr << "Image loaded with result: " << result << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
grfx::ImagePtr image_;
|
|
||||||
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
grfx::ImagePtr preview(string const & str)
|
|
||||||
{
|
{
|
||||||
// do we already have access to a rendered version?
|
string base = canonical_name(str);
|
||||||
previews_map::const_iterator it = thePreviews.find(str);
|
string dir = "/tmp/lyx/";
|
||||||
if (it != thePreviews.end())
|
string file = dir + base + ".ps";
|
||||||
return it->second;
|
cerr << "writing '" << str << "' to '" << file << "'\n";
|
||||||
|
|
||||||
// constructing new item
|
// get the cache
|
||||||
//grfx::ImagePtr & im = thePreviews[str];
|
grfx::GCache & gc = grfx::GCache::get();
|
||||||
|
|
||||||
lyxerr << "writing: " << str << endl;
|
// look up the file
|
||||||
std::ofstream of("/tmp/previewlyx.tex");
|
if (gc.inCache(file)) {
|
||||||
|
|
||||||
|
// it's already in there. Get hold of it.
|
||||||
|
grfx::GraphicPtr gr = grfx::GraphicPtr(gc.graphic(file));
|
||||||
|
|
||||||
|
// is it already loaded?
|
||||||
|
if (gr->status() == grfx::Loaded) {
|
||||||
|
cerr << "file '" << file << "' ready for display\n";
|
||||||
|
cerr << "im: " << graphic.get() << " " << gr.get() << "\n";
|
||||||
|
graphic = gr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise we have to wait again
|
||||||
|
cerr << "file '" << file << "' not finished loading\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The real work starts.
|
||||||
|
string const texfile = dir + base + ".tex";
|
||||||
|
std::ofstream of(texfile.c_str());
|
||||||
of << "\\documentclass{article}"
|
of << "\\documentclass{article}"
|
||||||
<< "\\usepackage{amssymb}"
|
<< "\\usepackage{amssymb}"
|
||||||
<< "\\thispagestyle{empty}"
|
<< "\\thispagestyle{empty}"
|
||||||
@ -74,58 +66,17 @@ grfx::ImagePtr preview(string const & str)
|
|||||||
<< "\\end{document}\n";
|
<< "\\end{document}\n";
|
||||||
of.close();
|
of.close();
|
||||||
|
|
||||||
Systemcall sc1;
|
string const cmd =
|
||||||
sc1.startscript(Systemcall::Wait,
|
"latex " + base + ".tex ; dvips -o " + base + ".ps " + base + ".dvi ";
|
||||||
"(cd /tmp ; latex previewlyx.tex ; dvips previewlyx.dvi)");
|
//cerr << "calling: '" << "(cd " + dir + "; " + cmd + ")\n";
|
||||||
|
Systemcall sc;
|
||||||
|
sc.startscript(Systemcall::Wait, "(cd " + dir + "; " + cmd + ")");
|
||||||
|
|
||||||
Systemcall sc2;
|
// now we are done, add the file to the cache
|
||||||
sc2.startscript(Systemcall::Wait,
|
gc.add(file);
|
||||||
"(cd /tmp ; convert previewlyx.ps previewlyx.xpm)");
|
gc.graphic(file)->startLoading();
|
||||||
|
|
||||||
//PreviewCallbackLoaded cb("/tmp/previewlyx.xpm");
|
// This might take a while. Wait for the next round.
|
||||||
|
cerr << "file '" << file << "' registered\n";
|
||||||
#if 0
|
return false;
|
||||||
//grfx::SignalLoadTypePtr on_finish;
|
|
||||||
//on_finish.reset(new SignalLoadType);
|
|
||||||
//on_finish->connect(SigC::slot(this, &imageLoaded));
|
|
||||||
|
|
||||||
// load image
|
|
||||||
XpmImage * xpm_image = new XpmImage;
|
|
||||||
int const success =
|
|
||||||
XpmReadFileToXpmImage("/tmp/previewlyx.ps", xpm_image, 0);
|
|
||||||
|
|
||||||
switch (success) {
|
|
||||||
case XpmOpenFailed:
|
|
||||||
lyxerr[Debug::GRAPHICS]
|
|
||||||
<< "No XPM image file found." << std::endl;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case XpmFileInvalid:
|
|
||||||
lyxerr[Debug::GRAPHICS]
|
|
||||||
<< "File format is invalid" << std::endl;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case XpmNoMemory:
|
|
||||||
lyxerr[Debug::GRAPHICS]
|
|
||||||
<< "Insufficient memory to read in XPM file"
|
|
||||||
<< std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success != XpmSuccess) {
|
|
||||||
XpmFreeXpmImage(xpm_image);
|
|
||||||
delete xpm_image;
|
|
||||||
|
|
||||||
lyxerr[Debug::GRAPHICS]
|
|
||||||
<< "Error reading XPM file '"
|
|
||||||
<< XpmGetErrorString(success) << "'"
|
|
||||||
<< std::endl;
|
|
||||||
} else {
|
|
||||||
//grfx::GImageXPM * xim = static_cast<grfx::GImageXPM *>(im.get());
|
|
||||||
//xim->image_.reset(*xpm_image);
|
|
||||||
}
|
|
||||||
|
|
||||||
return im;
|
|
||||||
#endif
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
#include "LString.h"
|
#include "LString.h"
|
||||||
#include "graphics/GraphicsTypes.h"
|
#include "graphics/GraphicsTypes.h"
|
||||||
|
|
||||||
grfx::ImagePtr preview(string const & str);
|
bool preview(string const & str, grfx::GraphicPtr & graphic);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user