mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 22:06:15 +00:00
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:
parent
9fd03bf560
commit
005545f281
@ -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>
|
2004-04-15 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* scripts/lyxpreview2bitmap.sh: removed.
|
* scripts/lyxpreview2bitmap.sh: removed.
|
||||||
|
@ -102,7 +102,7 @@ def make_texcolor(hexcolor):
|
|||||||
|
|
||||||
def extract_metrics_info(dvipng_stdout, metrics_file):
|
def extract_metrics_info(dvipng_stdout, metrics_file):
|
||||||
metrics = open(metrics_file, 'w')
|
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
|
success = 0
|
||||||
pos = 0
|
pos = 0
|
||||||
|
@ -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>
|
2004-04-16 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* render_graphic.h (checksum_, hasFileChanged): unused, so removed.
|
* render_graphic.h (checksum_, hasFileChanged): unused, so removed.
|
||||||
|
@ -449,8 +449,6 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
|||||||
InsetExternalParams p;
|
InsetExternalParams p;
|
||||||
InsetExternalMailer::string2params(cmd.argument, buffer, p);
|
InsetExternalMailer::string2params(cmd.argument, buffer, p);
|
||||||
setParams(p, buffer);
|
setParams(p, buffer);
|
||||||
#warning is this needed?
|
|
||||||
cur.bv().update();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +565,9 @@ string const getScreenLabel(InsetExternalParams const & params,
|
|||||||
return external::doSubstitution(params, buffer, ptr->guiName);
|
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
|
} // namespace anon
|
||||||
|
|
||||||
@ -621,7 +621,7 @@ void InsetExternal::setParams(InsetExternalParams const & p,
|
|||||||
|
|
||||||
if (preview_ptr->monitoring())
|
if (preview_ptr->monitoring())
|
||||||
preview_ptr->stopMonitoring();
|
preview_ptr->stopMonitoring();
|
||||||
add_preview(*preview_ptr, *this, buffer);
|
add_preview_and_start_loading(*preview_ptr, *this, buffer);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -640,8 +640,7 @@ void InsetExternal::fileChanged() const
|
|||||||
|
|
||||||
Buffer const & buffer = *buffer_ptr;
|
Buffer const & buffer = *buffer_ptr;
|
||||||
ptr->removePreview(buffer);
|
ptr->removePreview(buffer);
|
||||||
add_preview(*ptr, *this, buffer);
|
add_preview_and_start_loading(*ptr, *this, buffer);
|
||||||
ptr->startLoading(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)
|
Buffer const & buffer)
|
||||||
{
|
{
|
||||||
InsetExternalParams const & params = inset.params();
|
InsetExternalParams const & params = inset.params();
|
||||||
if (RenderPreview::activated() && preview_wanted(params)) {
|
|
||||||
|
if (RenderPreview::activated() &&
|
||||||
|
preview_wanted(params)) {
|
||||||
renderer.setAbsFile(params.filename.absFilename());
|
renderer.setAbsFile(params.filename.absFilename());
|
||||||
string const snippet = latex_string(inset, buffer);
|
string const snippet = latex_string(inset, buffer);
|
||||||
renderer.addPreview(snippet, buffer);
|
renderer.addPreview(snippet, buffer);
|
||||||
|
renderer.startLoading(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "frontends/LyXView.h"
|
#include "frontends/LyXView.h"
|
||||||
#include "frontends/Painter.h"
|
#include "frontends/Painter.h"
|
||||||
|
|
||||||
|
#include "graphics/PreviewImage.h"
|
||||||
#include "graphics/PreviewLoader.h"
|
#include "graphics/PreviewLoader.h"
|
||||||
|
|
||||||
#include "insets/render_preview.h"
|
#include "insets/render_preview.h"
|
||||||
@ -568,7 +569,16 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
|
|||||||
|
|
||||||
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
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);
|
preview_->metrics(mi, dim);
|
||||||
} else {
|
} else {
|
||||||
if (!set_label_) {
|
if (!set_label_) {
|
||||||
@ -592,12 +602,19 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
|||||||
{
|
{
|
||||||
setPosCache(pi, x, y);
|
setPosCache(pi, x, y);
|
||||||
|
|
||||||
if (!RenderPreview::activated() || !preview_->previewReady()) {
|
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
|
||||||
button_.draw(pi, x + button_.box().x1, y);
|
|
||||||
return;
|
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);
|
preview_->draw(pi, x + button_.box().x1, y);
|
||||||
|
else
|
||||||
|
button_.draw(pi, x + button_.box().x1, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "insets/inset.h"
|
#include "insets/inset.h"
|
||||||
|
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "dimension.h"
|
#include "dimension.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
@ -45,8 +46,7 @@ bool RenderPreview::activated()
|
|||||||
|
|
||||||
|
|
||||||
RenderPreview::RenderPreview(InsetBase const * inset)
|
RenderPreview::RenderPreview(InsetBase const * inset)
|
||||||
: pimage_(0),
|
: parent_(inset)
|
||||||
parent_(inset)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,6 @@ RenderPreview::RenderPreview(RenderPreview const & other,
|
|||||||
: RenderBase(other),
|
: RenderBase(other),
|
||||||
boost::signals::trackable(),
|
boost::signals::trackable(),
|
||||||
snippet_(other.snippet_),
|
snippet_(other.snippet_),
|
||||||
pimage_(0),
|
|
||||||
parent_(inset)
|
parent_(inset)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -97,12 +96,26 @@ string const statusMessage(BufferView const * bv, string const & snippet)
|
|||||||
} // namespace anon
|
} // 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
|
void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
if (previewReady()) {
|
BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
|
||||||
dim.asc = pimage_->ascent();
|
|
||||||
dim.des = pimage_->descent();
|
graphics::PreviewImage const * const pimage =
|
||||||
dim.wid = pimage_->width();
|
getPreviewImage(*mi.base.bv->buffer());
|
||||||
|
|
||||||
|
if (pimage) {
|
||||||
|
dim.asc = pimage->ascent();
|
||||||
|
dim.des = pimage->descent();
|
||||||
|
dim.wid = pimage->width();
|
||||||
} else {
|
} else {
|
||||||
dim.asc = 50;
|
dim.asc = 50;
|
||||||
dim.des = 0;
|
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
|
void RenderPreview::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
|
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(),
|
pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
|
||||||
*(pimage_->image()));
|
*(pimage->image()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +168,7 @@ void RenderPreview::startLoading(Buffer const & buffer) const
|
|||||||
graphics::Previews & previews = graphics::Previews::get();
|
graphics::Previews & previews = graphics::Previews::get();
|
||||||
graphics::PreviewLoader & loader = previews.loader(buffer);
|
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||||
loader.startLoading();
|
loader.startLoading();
|
||||||
|
lyxerr << "RenderPreview::startLoading: " << snippet_ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,12 +191,10 @@ void RenderPreview::addPreview(string const & latex_snippet,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
snippet_ = support::trim(latex_snippet);
|
snippet_ = support::trim(latex_snippet);
|
||||||
pimage_ = 0;
|
|
||||||
if (snippet_.empty())
|
if (snippet_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pimage_ = ploader.preview(snippet_);
|
if (ploader.preview(snippet_))
|
||||||
if (pimage_)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If this is the first time of calling, connect to the
|
// 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);
|
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||||
loader.remove(snippet_);
|
loader.remove(snippet_);
|
||||||
snippet_.erase();
|
snippet_.erase();
|
||||||
pimage_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool RenderPreview::previewReady() const
|
|
||||||
{
|
|
||||||
return pimage_ ? pimage_->image() : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
|
void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
|
||||||
{
|
{
|
||||||
// Check the current snippet is the same as that previewed.
|
// Check the current snippet is the same as that previewed.
|
||||||
if (snippet_ != pimage.snippet())
|
if (snippet_ == pimage.snippet())
|
||||||
return;
|
|
||||||
|
|
||||||
pimage_ = &pimage;
|
|
||||||
LyX::cref().updateInset(parent_);
|
LyX::cref().updateInset(parent_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +72,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void removePreview(Buffer const &);
|
void removePreview(Buffer const &);
|
||||||
|
|
||||||
/// The preview has been generated and is ready to use.
|
/** \returns a pointer to the PreviewImage associated with this snippet
|
||||||
bool previewReady() const;
|
* of latex.
|
||||||
|
*/
|
||||||
|
lyx::graphics::PreviewImage const *
|
||||||
|
getPreviewImage(Buffer const & buffer) const;
|
||||||
|
|
||||||
/// equivalent to dynamic_cast
|
/// equivalent to dynamic_cast
|
||||||
virtual RenderPreview * asPreview() { return this; }
|
virtual RenderPreview * asPreview() { return this; }
|
||||||
@ -88,9 +91,6 @@ private:
|
|||||||
/// The thing that we're trying to generate a preview of.
|
/// The thing that we're trying to generate a preview of.
|
||||||
std::string snippet_;
|
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
|
/** Store the connection to the preview loader so that we connect
|
||||||
* only once.
|
* only once.
|
||||||
*/
|
*/
|
||||||
|
@ -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>
|
2004-04-13 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* math_hullinset.[Ch]: add a RenderPreview variable.
|
* math_hullinset.[Ch]: add a RenderPreview variable.
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "frontends/Alert.h"
|
#include "frontends/Alert.h"
|
||||||
|
|
||||||
|
#include "graphics/PreviewImage.h"
|
||||||
#include "graphics/PreviewLoader.h"
|
#include "graphics/PreviewLoader.h"
|
||||||
|
|
||||||
#include "support/std_sstream.h"
|
#include "support/std_sstream.h"
|
||||||
@ -228,9 +229,14 @@ char const * MathHullInset::standardFont() const
|
|||||||
|
|
||||||
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
bool const use_preview = (!editing(mi.base.bv) &&
|
BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
|
||||||
RenderPreview::activated() &&
|
|
||||||
preview_->previewReady());
|
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) {
|
if (use_preview) {
|
||||||
preview_->metrics(mi, dim);
|
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
|
void MathHullInset::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
// The previews are drawn only when we're not editing the inset.
|
BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
|
||||||
bool const use_preview = (!editing(pi.base.bv) &&
|
|
||||||
RenderPreview::activated() &&
|
bool use_preview = false;
|
||||||
preview_->previewReady());
|
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) {
|
if (use_preview) {
|
||||||
// one pixel gap in front
|
// one pixel gap in front
|
||||||
|
Loading…
Reference in New Issue
Block a user