Remove cached var from RenderPreview. Changes elsewhere to suit.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8669 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-04-19 13:05:36 +00:00
parent 9fd03bf560
commit 005545f281
9 changed files with 112 additions and 54 deletions

View File

@ -1,3 +1,8 @@
2004-04-19 Angus Leeming <leeming@lyx.org>
* scripts/lyxpreview2bitmap.py (extract_metrics_info): make the
regex a little more robust. Now recognizes negative integers.
2004-04-15 Angus Leeming <leeming@lyx.org>
* scripts/lyxpreview2bitmap.sh: removed.

View File

@ -102,7 +102,7 @@ def make_texcolor(hexcolor):
def extract_metrics_info(dvipng_stdout, metrics_file):
metrics = open(metrics_file, 'w')
metrics_re = re.compile("\[([0-9]+) depth=([0-9]+) height=([0-9]+)\]")
metrics_re = re.compile("\[([0-9]+) depth=(-?[0-9]+) height=(-?[0-9]+)")
success = 0
pos = 0

View File

@ -1,3 +1,18 @@
2004-04-19 Angus Leeming <leeming@lyx.org>
* insetexternal.C (priv_dispatch): remove unnecessary invocation of
BufferView::update.
(add_preview): renamed as add_preview_and_start_loading. Invoke
RenderPreview::startLoading.
* insetinclude.C (metrics, draw): changes due to the changed
RenderPreview interface.
* render_preview.C: remove cached pimage_.
(previewReady): removed. Replaced by getPreviewImage(Buffer const &).
(draw): don't call startLoading. That's up to the user of
RenderPreview.
2004-04-16 Angus Leeming <leeming@lyx.org>
* render_graphic.h (checksum_, hasFileChanged): unused, so removed.

View File

@ -449,8 +449,6 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd)
InsetExternalParams p;
InsetExternalMailer::string2params(cmd.argument, buffer, p);
setParams(p, buffer);
#warning is this needed?
cur.bv().update();
break;
}
@ -567,7 +565,9 @@ string const getScreenLabel(InsetExternalParams const & params,
return external::doSubstitution(params, buffer, ptr->guiName);
}
void add_preview(RenderMonitoredPreview &, InsetExternal const &, Buffer const &);
void add_preview_and_start_loading(RenderMonitoredPreview &,
InsetExternal const &,
Buffer const &);
} // namespace anon
@ -621,7 +621,7 @@ void InsetExternal::setParams(InsetExternalParams const & p,
if (preview_ptr->monitoring())
preview_ptr->stopMonitoring();
add_preview(*preview_ptr, *this, buffer);
add_preview_and_start_loading(*preview_ptr, *this, buffer);
break;
}
@ -640,8 +640,7 @@ void InsetExternal::fileChanged() const
Buffer const & buffer = *buffer_ptr;
ptr->removePreview(buffer);
add_preview(*ptr, *this, buffer);
ptr->startLoading(buffer);
add_preview_and_start_loading(*ptr, *this, buffer);
}
@ -774,14 +773,18 @@ string const latex_string(InsetExternal const & inset, Buffer const & buffer)
}
void add_preview(RenderMonitoredPreview & renderer, InsetExternal const & inset,
void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
InsetExternal const & inset,
Buffer const & buffer)
{
InsetExternalParams const & params = inset.params();
if (RenderPreview::activated() && preview_wanted(params)) {
if (RenderPreview::activated() &&
preview_wanted(params)) {
renderer.setAbsFile(params.filename.absFilename());
string const snippet = latex_string(inset, buffer);
renderer.addPreview(snippet, buffer);
renderer.startLoading(buffer);
}
}

View File

@ -32,6 +32,7 @@
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
#include "insets/render_preview.h"
@ -568,7 +569,16 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (RenderPreview::activated() && preview_->previewReady()) {
BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
bool use_preview = false;
if (RenderPreview::activated()) {
lyx::graphics::PreviewImage const * pimage =
preview_->getPreviewImage(*mi.base.bv->buffer());
use_preview = pimage && pimage->image();
}
if (use_preview) {
preview_->metrics(mi, dim);
} else {
if (!set_label_) {
@ -592,12 +602,19 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
if (!RenderPreview::activated() || !preview_->previewReady()) {
button_.draw(pi, x + button_.box().x1, y);
return;
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
bool use_preview = false;
if (RenderPreview::activated()) {
lyx::graphics::PreviewImage const * pimage =
preview_->getPreviewImage(*pi.base.bv->buffer());
use_preview = pimage && pimage->image();
}
if (use_preview)
preview_->draw(pi, x + button_.box().x1, y);
else
button_.draw(pi, x + button_.box().x1, y);
}

View File

@ -14,6 +14,7 @@
#include "insets/inset.h"
#include "BufferView.h"
#include "debug.h"
#include "dimension.h"
#include "gettext.h"
#include "LColor.h"
@ -45,8 +46,7 @@ bool RenderPreview::activated()
RenderPreview::RenderPreview(InsetBase const * inset)
: pimage_(0),
parent_(inset)
: parent_(inset)
{}
@ -55,7 +55,6 @@ RenderPreview::RenderPreview(RenderPreview const & other,
: RenderBase(other),
boost::signals::trackable(),
snippet_(other.snippet_),
pimage_(0),
parent_(inset)
{}
@ -97,12 +96,26 @@ string const statusMessage(BufferView const * bv, string const & snippet)
} // namespace anon
graphics::PreviewImage const *
RenderPreview::getPreviewImage(Buffer const & buffer) const
{
graphics::Previews & previews = graphics::Previews::get();
graphics::PreviewLoader & loader = previews.loader(buffer);
return loader.preview(snippet_);
}
void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (previewReady()) {
dim.asc = pimage_->ascent();
dim.des = pimage_->descent();
dim.wid = pimage_->width();
BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
graphics::PreviewImage const * const pimage =
getPreviewImage(*mi.base.bv->buffer());
if (pimage) {
dim.asc = pimage->ascent();
dim.des = pimage->descent();
dim.wid = pimage->width();
} else {
dim.asc = 50;
dim.des = 0;
@ -122,12 +135,13 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
void RenderPreview::draw(PainterInfo & pi, int x, int y) const
{
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
Buffer const & buffer = *pi.base.bv->buffer();
startLoading(buffer);
if (previewReady()) {
graphics::PreviewImage const * const pimage =
getPreviewImage(*pi.base.bv->buffer());
if (pimage && pimage->image()) {
pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
*(pimage_->image()));
*(pimage->image()));
return;
}
@ -154,6 +168,7 @@ void RenderPreview::startLoading(Buffer const & buffer) const
graphics::Previews & previews = graphics::Previews::get();
graphics::PreviewLoader & loader = previews.loader(buffer);
loader.startLoading();
lyxerr << "RenderPreview::startLoading: " << snippet_ << std::endl;
}
@ -176,12 +191,10 @@ void RenderPreview::addPreview(string const & latex_snippet,
return;
snippet_ = support::trim(latex_snippet);
pimage_ = 0;
if (snippet_.empty())
return;
pimage_ = ploader.preview(snippet_);
if (pimage_)
if (ploader.preview(snippet_))
return;
// If this is the first time of calling, connect to the
@ -205,23 +218,13 @@ void RenderPreview::removePreview(Buffer const & buffer)
graphics::PreviewLoader & loader = previews.loader(buffer);
loader.remove(snippet_);
snippet_.erase();
pimage_ = 0;
}
bool RenderPreview::previewReady() const
{
return pimage_ ? pimage_->image() : false;
}
void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
{
// Check the current snippet is the same as that previewed.
if (snippet_ != pimage.snippet())
return;
pimage_ = &pimage;
if (snippet_ == pimage.snippet())
LyX::cref().updateInset(parent_);
}

View File

@ -72,8 +72,11 @@ public:
*/
void removePreview(Buffer const &);
/// The preview has been generated and is ready to use.
bool previewReady() const;
/** \returns a pointer to the PreviewImage associated with this snippet
* of latex.
*/
lyx::graphics::PreviewImage const *
getPreviewImage(Buffer const & buffer) const;
/// equivalent to dynamic_cast
virtual RenderPreview * asPreview() { return this; }
@ -88,9 +91,6 @@ private:
/// The thing that we're trying to generate a preview of.
std::string snippet_;
/// We don't own this. Cached for efficiency reasons.
lyx::graphics::PreviewImage const * pimage_;
/** Store the connection to the preview loader so that we connect
* only once.
*/

View File

@ -1,3 +1,8 @@
2004-04-19 Angus Leeming <leeming@lyx.org>
* math_hullinset.C (metrics, draw): changes due to the changed
RenderPreview interface.
2004-04-13 Angus Leeming <leeming@lyx.org>
* math_hullinset.[Ch]: add a RenderPreview variable.

View File

@ -37,6 +37,7 @@
#include "frontends/Alert.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
#include "support/std_sstream.h"
@ -228,9 +229,14 @@ char const * MathHullInset::standardFont() const
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
{
bool const use_preview = (!editing(mi.base.bv) &&
RenderPreview::activated() &&
preview_->previewReady());
BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
bool use_preview = false;
if (!editing(mi.base.bv) && RenderPreview::activated()) {
lyx::graphics::PreviewImage const * pimage =
preview_->getPreviewImage(*mi.base.bv->buffer());
use_preview = pimage && pimage->image();
}
if (use_preview) {
preview_->metrics(mi, dim);
@ -276,10 +282,14 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
void MathHullInset::draw(PainterInfo & pi, int x, int y) const
{
// The previews are drawn only when we're not editing the inset.
bool const use_preview = (!editing(pi.base.bv) &&
RenderPreview::activated() &&
preview_->previewReady());
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
bool use_preview = false;
if (!editing(pi.base.bv) && RenderPreview::activated()) {
lyx::graphics::PreviewImage const * pimage =
preview_->getPreviewImage(*pi.base.bv->buffer());
use_preview = pimage && pimage->image();
}
if (use_preview) {
// one pixel gap in front